From 93308146eaaca234182440ecf85f79cadf861325 Mon Sep 17 00:00:00 2001 From: "nor..67" Date: Tue, 5 Apr 2011 11:40:03 +0000 Subject: [PATCH] - fix Color and Texture2D values in j3m creation using regex - load and apply created j3m material to model when created git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7191 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/gde/materials/MaterialProperties.java | 2 +- .../com/jme3/gde/materials/MaterialProperty.java | 14 ++++++++++++-- .../jme3/gde/materials/MaterialPropertyEditor.java | 9 ++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java index ed497f167..fedd1de2b 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperties.java @@ -479,7 +479,7 @@ public class MaterialProperties { 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())); + additionalRenderStates.put("PolyOffset", new MaterialProperty("Float,Float", "PolyOffset", mat.getAdditionalRenderState().getPolyOffsetUnits() + " " + mat.getAdditionalRenderState().getPolyOffsetFactor())); parseMatDef(); setAsText(getUpdatedContent()); } diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java index bc59d57ee..e5af20d59 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialProperty.java @@ -5,6 +5,8 @@ package com.jme3.gde.materials; import com.jme3.material.MatParam; +import com.jme3.math.ColorRGBA; +import com.jme3.texture.Texture2D; /** * @@ -28,9 +30,17 @@ public class MaterialProperty { public MaterialProperty(MatParam param) { this.type = param.getVarType().name(); this.name = param.getName(); -// param.getVarType(). + Object obj = param.getValue(); + this.value = obj.toString(); //TODO: change to correct string - this.value = param.getValue().toString(); + if(obj instanceof ColorRGBA){ + value = value.replaceAll("Color\\[([^\\]]*)\\]", "$1"); + value = value.replaceAll(",", ""); + } + else if(obj instanceof Texture2D) + { + value = value.replaceAll("Texture2D\\[name=([^,]*)\\,([^\\]]*)]", "$1"); + } } /** diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java index fbb19897e..cbe948b1b 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/MaterialPropertyEditor.java @@ -107,7 +107,6 @@ public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerProp 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) { @@ -118,14 +117,18 @@ public class MaterialPropertyEditor implements PropertyEditor, SceneExplorerProp MaterialProperties properties = new MaterialProperties(newFile, pm); material.setAssetName(pm.getRelativeAssetPath(newFile.getPath())); properties.setAsMaterial(material); - notifyListeners(old, material); currentFolder.refresh(); + applyMaterial(material.getAssetName()); } catch (IOException ex) { Exceptions.printStackTrace(ex); return; } - return; + }else{ + applyMaterial(text); } + } + + private void applyMaterial(final String text) { try { Material old = material; SceneApplication.getApplication().enqueue(new Callable() {