- add "last selected" available via SceneExplorer
- add API for external variable type editors - first version of "create j3m" function for materials (WIP - parameter values are only toString() versions atm) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7187 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
916f4f203c
commit
b9870753fc
@ -6,4 +6,4 @@ nbm.homepage=http://www.jmonkeyengine.com
|
|||||||
nbm.module.author=Normen Hansen
|
nbm.module.author=Normen Hansen
|
||||||
nbm.needs.restart=true
|
nbm.needs.restart=true
|
||||||
project.license=jme
|
project.license=jme
|
||||||
spec.version.base=0.12.0
|
spec.version.base=0.12.1
|
||||||
|
@ -76,6 +76,7 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
|
|||||||
private SceneRequest request;
|
private SceneRequest request;
|
||||||
private final Result<AbstractSceneExplorerNode> nodeSelectionResult;
|
private final Result<AbstractSceneExplorerNode> nodeSelectionResult;
|
||||||
private AbstractSceneExplorerNode selectedSpatial;
|
private AbstractSceneExplorerNode selectedSpatial;
|
||||||
|
private AbstractSceneExplorerNode lastSelected;
|
||||||
|
|
||||||
public SceneExplorerTopComponent() {
|
public SceneExplorerTopComponent() {
|
||||||
initComponents();
|
initComponents();
|
||||||
@ -250,6 +251,7 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
|
|||||||
Object object = it.next();
|
Object object = it.next();
|
||||||
if (object instanceof AbstractSceneExplorerNode) {
|
if (object instanceof AbstractSceneExplorerNode) {
|
||||||
selectedSpatial = (AbstractSceneExplorerNode) object;
|
selectedSpatial = (AbstractSceneExplorerNode) object;
|
||||||
|
lastSelected = (AbstractSceneExplorerNode) object;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,4 +275,11 @@ public final class SceneExplorerTopComponent extends TopComponent implements Exp
|
|||||||
|
|
||||||
public void previewRequested(PreviewRequest request) {
|
public void previewRequested(PreviewRequest request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the selectedSpatial
|
||||||
|
*/
|
||||||
|
public AbstractSceneExplorerNode getLastSelected() {
|
||||||
|
return lastSelected;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,12 @@ public class SceneExplorerProperty<T> extends PropertySupport.Reflection<T> {
|
|||||||
setPropertyEditorClass(Matrix3fPropertyEditor.class);
|
setPropertyEditorClass(Matrix3fPropertyEditor.class);
|
||||||
} else if (valueType == ColorRGBA.class) {
|
} else if (valueType == ColorRGBA.class) {
|
||||||
setPropertyEditorClass(ColorRGBAPropertyEditor.class);
|
setPropertyEditorClass(ColorRGBAPropertyEditor.class);
|
||||||
} else if (valueType == Material.class) {
|
|
||||||
setPropertyEditorClass(MaterialPropertyEditor.class);
|
|
||||||
} else if (valueType == EmitterShape.class) {
|
} else if (valueType == EmitterShape.class) {
|
||||||
setPropertyEditorClass(EmitterShapePropertyEditor.class);
|
setPropertyEditorClass(EmitterShapePropertyEditor.class);
|
||||||
}
|
}
|
||||||
|
for (SceneExplorerPropertyEditor di : Lookup.getDefault().lookupAll(SceneExplorerPropertyEditor.class)) {
|
||||||
|
di.setEditor(valueType, this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2009-2010 jMonkeyEngine
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||||
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.jme3.gde.core.sceneexplorer.nodes.properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author normenhansen
|
||||||
|
*/
|
||||||
|
public interface SceneExplorerPropertyEditor {
|
||||||
|
public void setEditor(Class valueType, SceneExplorerProperty prop);
|
||||||
|
}
|
@ -1,8 +1,8 @@
|
|||||||
build.xml.data.CRC32=3a4f0982
|
build.xml.data.CRC32=6e7dc984
|
||||||
build.xml.script.CRC32=f284e28d
|
build.xml.script.CRC32=f284e28d
|
||||||
build.xml.stylesheet.CRC32=a56c6a5b@1.42.2
|
build.xml.stylesheet.CRC32=a56c6a5b@1.42.2
|
||||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
nbproject/build-impl.xml.data.CRC32=3a4f0982
|
nbproject/build-impl.xml.data.CRC32=6e7dc984
|
||||||
nbproject/build-impl.xml.script.CRC32=56cee44d
|
nbproject/build-impl.xml.script.CRC32=56cee44d
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.42.2
|
nbproject/build-impl.xml.stylesheet.CRC32=238281d1@1.42.2
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<compile-dependency/>
|
<compile-dependency/>
|
||||||
<run-dependency>
|
<run-dependency>
|
||||||
<release-version>1</release-version>
|
<release-version>1</release-version>
|
||||||
<specification-version>0.12</specification-version>
|
<specification-version>0.12.1</specification-version>
|
||||||
</run-dependency>
|
</run-dependency>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
package com.jme3.gde.materials;
|
package com.jme3.gde.materials;
|
||||||
|
|
||||||
import com.jme3.gde.core.assets.ProjectAssetManager;
|
import com.jme3.gde.core.assets.ProjectAssetManager;
|
||||||
|
import com.jme3.material.MatParam;
|
||||||
|
import com.jme3.material.Material;
|
||||||
import com.jme3.system.JmeSystem;
|
import com.jme3.system.JmeSystem;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -12,6 +14,7 @@ import java.io.OutputStream;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@ -389,6 +392,15 @@ public class MaterialProperties {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createBaseMaterialFile() throws IOException {
|
||||||
|
OutputStreamWriter out = new OutputStreamWriter(material.getOutputStream());
|
||||||
|
out.write("Material MyMaterial : " + matDefName + " {\n");
|
||||||
|
out.write(" MaterialParameters {\n");
|
||||||
|
out.write(" }\n");
|
||||||
|
out.write("}\n");
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trims a line and removes comments
|
* trims a line and removes comments
|
||||||
* @param line
|
* @param line
|
||||||
@ -444,6 +456,34 @@ public class MaterialProperties {
|
|||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the data from a material
|
||||||
|
* @param mat
|
||||||
|
*/
|
||||||
|
public void setAsMaterial(Material mat) throws IOException {
|
||||||
|
assert (mat.getMaterialDef().getAssetName() != null);
|
||||||
|
setName("MyMaterial");
|
||||||
|
setMatDefName(mat.getMaterialDef().getAssetName());
|
||||||
|
createBaseMaterialFile();
|
||||||
|
materialParameters.clear();
|
||||||
|
Collection<MatParam> params=mat.getParams();
|
||||||
|
for (Iterator<MatParam> it = params.iterator(); it.hasNext();) {
|
||||||
|
MatParam matParam = it.next();
|
||||||
|
materialParameters.put(matParam.getName(), new MaterialProperty(matParam));
|
||||||
|
}
|
||||||
|
additionalRenderStates.put("Wireframe", new MaterialProperty("OnOff", "Wireframe", mat.getAdditionalRenderState().isWireframe() ? "On" : "Off"));
|
||||||
|
additionalRenderStates.put("DepthWrite", new MaterialProperty("OnOff", "DepthWrite", mat.getAdditionalRenderState().isDepthWrite() ? "On" : "Off"));
|
||||||
|
additionalRenderStates.put("DepthTest", new MaterialProperty("OnOff", "DepthTest", mat.getAdditionalRenderState().isDepthTest() ? "On" : "Off"));
|
||||||
|
additionalRenderStates.put("ColorWrite", new MaterialProperty("OnOff", "ColorWrite", mat.getAdditionalRenderState().isColorWrite() ? "On" : "Off"));
|
||||||
|
additionalRenderStates.put("PointSprite", new MaterialProperty("OnOff", "PointSprite", mat.getAdditionalRenderState().isPointSprite() ? "On" : "Off"));
|
||||||
|
additionalRenderStates.put("FaceCull", new MaterialProperty("FaceCullMode", "FaceCull", mat.getAdditionalRenderState().getFaceCullMode().name()));
|
||||||
|
additionalRenderStates.put("Blend", new MaterialProperty("BlendMode", "Blend", mat.getAdditionalRenderState().getBlendMode().name()));
|
||||||
|
additionalRenderStates.put("AlphaTestFalloff", new MaterialProperty("Float", "AlphaTestFalloff", mat.getAdditionalRenderState().getAlphaFallOff() + ""));
|
||||||
|
additionalRenderStates.put("PolyOffset", new MaterialProperty("Float,Float", "PolyOffset", mat.getAdditionalRenderState().getPolyOffsetUnits() + ", " + mat.getAdditionalRenderState().getPolyOffsetFactor()));
|
||||||
|
parseMatDef();
|
||||||
|
setAsText(getUpdatedContent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the matDefName
|
* @return the matDefName
|
||||||
*/
|
*/
|
||||||
@ -456,6 +496,7 @@ public class MaterialProperties {
|
|||||||
*/
|
*/
|
||||||
public void setMatDefName(String matDefName) {
|
public void setMatDefName(String matDefName) {
|
||||||
this.matDefName = matDefName;
|
this.matDefName = matDefName;
|
||||||
|
assert (matDefName != null);
|
||||||
initMatDef();
|
initMatDef();
|
||||||
parseMatDef();
|
parseMatDef();
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,16 @@
|
|||||||
* To change this template, choose Tools | Templates
|
* To change this template, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.jme3.gde.materials;
|
package com.jme3.gde.materials;
|
||||||
|
|
||||||
|
import com.jme3.material.MatParam;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author normenhansen
|
* @author normenhansen
|
||||||
*/
|
*/
|
||||||
public class MaterialProperty {
|
public class MaterialProperty {
|
||||||
|
|
||||||
private String type;
|
private String type;
|
||||||
private String name;
|
private String name;
|
||||||
private String value;
|
private String value;
|
||||||
@ -17,13 +19,19 @@ public class MaterialProperty {
|
|||||||
public MaterialProperty() {
|
public MaterialProperty() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public MaterialProperty(String type, String name, String value) {
|
public MaterialProperty(String type, String name, String value) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MaterialProperty(MatParam param) {
|
||||||
|
this.type = param.getVarType().name();
|
||||||
|
this.name = param.getName();
|
||||||
|
// param.getVarType().
|
||||||
|
//TODO: change to correct string
|
||||||
|
this.value = param.getValue().toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the type
|
* @return the type
|
||||||
@ -66,5 +74,4 @@ public class MaterialProperty {
|
|||||||
public void setValue(String value) {
|
public void setValue(String value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -29,31 +29,39 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
package com.jme3.gde.core.sceneexplorer.nodes.properties;
|
package com.jme3.gde.materials;
|
||||||
|
|
||||||
import com.jme3.asset.AssetKey;
|
import com.jme3.asset.AssetKey;
|
||||||
import com.jme3.asset.DesktopAssetManager;
|
import com.jme3.asset.DesktopAssetManager;
|
||||||
|
import com.jme3.gde.core.assets.ProjectAssetManager;
|
||||||
import com.jme3.gde.core.scene.SceneApplication;
|
import com.jme3.gde.core.scene.SceneApplication;
|
||||||
import com.jme3.gde.core.scene.SceneRequest;
|
import com.jme3.gde.core.scene.SceneRequest;
|
||||||
|
import com.jme3.gde.core.sceneexplorer.SceneExplorerTopComponent;
|
||||||
|
import com.jme3.gde.core.sceneexplorer.nodes.AbstractSceneExplorerNode;
|
||||||
|
import com.jme3.gde.core.sceneexplorer.nodes.properties.SceneExplorerProperty;
|
||||||
|
import com.jme3.gde.core.sceneexplorer.nodes.properties.SceneExplorerPropertyEditor;
|
||||||
import com.jme3.material.Material;
|
import com.jme3.material.Material;
|
||||||
import com.jme3.math.Quaternion;
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.beans.PropertyChangeEvent;
|
import java.beans.PropertyChangeEvent;
|
||||||
import java.beans.PropertyChangeListener;
|
import java.beans.PropertyChangeListener;
|
||||||
import java.beans.PropertyEditor;
|
import java.beans.PropertyEditor;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import org.openide.filesystems.FileObject;
|
||||||
|
import org.openide.loaders.DataObject;
|
||||||
import org.openide.util.Exceptions;
|
import org.openide.util.Exceptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author normenhansen
|
* @author normenhansen
|
||||||
*/
|
*/
|
||||||
public class MaterialPropertyEditor implements PropertyEditor {
|
@org.openide.util.lookup.ServiceProvider(service = SceneExplorerPropertyEditor.class)
|
||||||
|
public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerPropertyEditor {
|
||||||
|
|
||||||
private LinkedList<PropertyChangeListener> listeners = new LinkedList<PropertyChangeListener>();
|
private LinkedList<PropertyChangeListener> listeners = new LinkedList<PropertyChangeListener>();
|
||||||
private Material material = new Material();
|
private Material material = new Material();
|
||||||
@ -83,12 +91,41 @@ public class MaterialPropertyEditor implements PropertyEditor {
|
|||||||
public String getAsText() {
|
public String getAsText() {
|
||||||
String name = material.getAssetName();
|
String name = material.getAssetName();
|
||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = "stored in file";
|
name = "create j3m file";
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAsText(final String text) throws IllegalArgumentException {
|
public void setAsText(final String text) throws IllegalArgumentException {
|
||||||
|
if ("create j3m file".equals(text)) {
|
||||||
|
AbstractSceneExplorerNode geom = SceneExplorerTopComponent.findInstance().getLastSelected();
|
||||||
|
assert (geom != null);
|
||||||
|
ProjectAssetManager pm = geom.getLookup().lookup(ProjectAssetManager.class);
|
||||||
|
assert (pm != null);
|
||||||
|
DataObject obj = geom.getLookup().lookup(DataObject.class);
|
||||||
|
assert (obj != null);
|
||||||
|
FileObject currentFile = obj.getPrimaryFile();
|
||||||
|
FileObject currentFolder = currentFile.getParent();
|
||||||
|
try {
|
||||||
|
Material old = material.clone();
|
||||||
|
int i = 1;
|
||||||
|
FileObject newFile = currentFolder.getFileObject(currentFile.getName() + "_" + i, "j3m");
|
||||||
|
while (newFile != null) {
|
||||||
|
i++;
|
||||||
|
newFile = currentFolder.getFileObject(currentFile.getName() + "_" + i, "j3m");
|
||||||
|
}
|
||||||
|
newFile = currentFolder.createData(currentFile.getName() + "_" + i, "j3m");
|
||||||
|
MaterialProperties properties = new MaterialProperties(newFile, pm);
|
||||||
|
material.setAssetName(pm.getRelativeAssetPath(newFile.getPath()));
|
||||||
|
properties.setAsMaterial(material);
|
||||||
|
notifyListeners(old, material);
|
||||||
|
currentFolder.refresh();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
Exceptions.printStackTrace(ex);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Material old = material;
|
Material old = material;
|
||||||
SceneApplication.getApplication().enqueue(new Callable<Void>() {
|
SceneApplication.getApplication().enqueue(new Callable<Void>() {
|
||||||
@ -116,8 +153,18 @@ public class MaterialPropertyEditor implements PropertyEditor {
|
|||||||
if (request == null) {
|
if (request == null) {
|
||||||
return new String[]{};
|
return new String[]{};
|
||||||
}
|
}
|
||||||
String[] mats = request.getManager().getMaterials();
|
if (material.getAssetName() == null) {
|
||||||
return mats;
|
String[] materials = request.getManager().getMaterials();
|
||||||
|
String[] mats = new String[materials.length + 1];
|
||||||
|
mats[0] = ("create j3m file");
|
||||||
|
for (int i = 0; i < materials.length; i++) {
|
||||||
|
String string = materials[i];
|
||||||
|
mats[i + 1] = string;
|
||||||
|
}
|
||||||
|
return mats;
|
||||||
|
} else {
|
||||||
|
return request.getManager().getMaterials();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component getCustomEditor() {
|
public Component getCustomEditor() {
|
||||||
@ -143,4 +190,10 @@ public class MaterialPropertyEditor implements PropertyEditor {
|
|||||||
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, null, before, after));
|
propertyChangeListener.propertyChange(new PropertyChangeEvent(this, null, before, after));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEditor(Class valueType, SceneExplorerProperty prop) {
|
||||||
|
if (valueType == Material.class) {
|
||||||
|
prop.setPropertyEditorClass(MaterialPropertyEditor.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user