diff --git a/sdk/jme3-materialeditor/nbproject/genfiles.properties b/sdk/jme3-materialeditor/nbproject/genfiles.properties index b63baa0da..2b4d6d1c6 100644 --- a/sdk/jme3-materialeditor/nbproject/genfiles.properties +++ b/sdk/jme3-materialeditor/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=3c35bd02 +build.xml.data.CRC32=5c252103 build.xml.script.CRC32=f284e28d -build.xml.stylesheet.CRC32=a56c6a5b@2.49.1 +build.xml.stylesheet.CRC32=a56c6a5b@2.50.1 # 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. -nbproject/build-impl.xml.data.CRC32=3c35bd02 +nbproject/build-impl.xml.data.CRC32=5c252103 nbproject/build-impl.xml.script.CRC32=56cee44d -nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.49.1 +nbproject/build-impl.xml.stylesheet.CRC32=238281d1@2.50.1 diff --git a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java index d798be6d0..cfbf2b9d3 100644 --- a/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java +++ b/sdk/jme3-materialeditor/src/com/jme3/gde/materials/EditableMaterialFile.java @@ -4,9 +4,12 @@ */ package com.jme3.gde.materials; +import com.jme3.asset.TextureKey; import com.jme3.gde.core.assets.ProjectAssetManager; +import com.jme3.gde.core.util.Beans; import com.jme3.gde.materials.wizards.StoreTextureWizardWizardAction; import com.jme3.material.MatParam; +import com.jme3.material.MatParamTexture; import com.jme3.material.Material; import com.jme3.texture.Image; import com.jme3.texture.Texture; @@ -494,11 +497,7 @@ public class EditableMaterialFile { setMatDefName(mat.getMaterialDef().getAssetName()); createBaseMaterialFile(); materialParameters.clear(); - Collection params = mat.getParams(); - for (Iterator it = params.iterator(); it.hasNext();) { - MatParam matParam = it.next(); - checkPackedTextureProps(mat, matParam); - } + checkPackedTextureProps(mat); 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")); @@ -518,43 +517,59 @@ public class EditableMaterialFile { * @param mat * @param param */ - private void checkPackedTextureProps(Material mat, MatParam param) { - MaterialProperty prop = new MaterialProperty(param); - materialParameters.put(param.getName(), prop); - if (prop.getValue() == null) { - switch (param.getVarType()) { - case Texture2D: - case Texture3D: - case TextureArray: - case TextureBuffer: - case TextureCubeMap: - try { - Texture tex = mat.getTextureParam(param.getName()).getTextureValue(); - Image img = tex.getImage(); - if (img == null) { - logger.log(Level.INFO, "No image found"); - return; + private void checkPackedTextureProps(Material mat) { + Collection params = mat.getParams(); + for (Iterator it = new ArrayList(params).iterator(); it.hasNext();) { + MatParam param = it.next(); + MaterialProperty prop = new MaterialProperty(param); + if (prop.getValue() == null) { + switch (param.getVarType()) { + case Texture2D: + case Texture3D: + case TextureArray: + case TextureBuffer: + case TextureCubeMap: + try { + MatParamTexture texParam = mat.getTextureParam(param.getName()); + Texture tex = texParam.getTextureValue(); + Image img = tex.getImage(); + if (img == null) { + logger.log(Level.INFO, "No image found"); + return; + } + BufferedImage image = ImageToAwt.convert(img, false, false, 0); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + ImageWriter imgWrtr = ImageIO.getImageWritersByFormatName("png").next(); + ImageOutputStream imgOutStrm; + imgOutStrm = ImageIO.createImageOutputStream(out); + imgWrtr.setOutput(imgOutStrm); + ImageWriteParam jpgWrtPrm = imgWrtr.getDefaultWriteParam(); + imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm); + imgOutStrm.close(); + out.close(); + String texturePath = material.getName(); + texturePath = "Textures/" + texturePath + "-" + param.getName() + ".png"; + StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), texturePath); + act.actionPerformed(null); + texturePath = act.getName(); + TextureKey texKey = new TextureKey(texturePath); + TextureKey oldKey = (TextureKey)tex.getKey(); + if(oldKey!=null){ + Beans.copyProperties(texKey, oldKey); + } + //TODO: seems like flip is removed due to ImageToAwt + texKey.setFlipY(false); + Texture texture = manager.loadTexture(texKey); + MatParamTexture newParam = new MatParamTexture(texParam.getVarType(), texParam.getName(), texture, texParam.getUnit()); + materialParameters.put(newParam.getName(), new MaterialProperty(newParam)); + } catch (Exception ex) { + Exceptions.printStackTrace(ex); } - BufferedImage image = ImageToAwt.convert(img, false, false, 0); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - ImageWriter imgWrtr = ImageIO.getImageWritersByFormatName("png").next(); - ImageOutputStream imgOutStrm; - imgOutStrm = ImageIO.createImageOutputStream(out); - imgWrtr.setOutput(imgOutStrm); - ImageWriteParam jpgWrtPrm = imgWrtr.getDefaultWriteParam(); - imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm); - imgOutStrm.close(); - out.close(); - String name = material.getName(); - name = "Textures/" + name + "-" + param.getName() + ".png"; - StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), name); - act.actionPerformed(null); - prop.setValue(act.getName()); - } catch (Exception ex) { - Exceptions.printStackTrace(ex); - } - break; - default: + break; + default: + } + } else { + materialParameters.put(param.getName(), prop); } } }