|
|
@ -4,9 +4,12 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package com.jme3.gde.materials; |
|
|
|
package com.jme3.gde.materials; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.jme3.asset.TextureKey; |
|
|
|
import com.jme3.gde.core.assets.ProjectAssetManager; |
|
|
|
import com.jme3.gde.core.assets.ProjectAssetManager; |
|
|
|
|
|
|
|
import com.jme3.gde.core.util.Beans; |
|
|
|
import com.jme3.gde.materials.wizards.StoreTextureWizardWizardAction; |
|
|
|
import com.jme3.gde.materials.wizards.StoreTextureWizardWizardAction; |
|
|
|
import com.jme3.material.MatParam; |
|
|
|
import com.jme3.material.MatParam; |
|
|
|
|
|
|
|
import com.jme3.material.MatParamTexture; |
|
|
|
import com.jme3.material.Material; |
|
|
|
import com.jme3.material.Material; |
|
|
|
import com.jme3.texture.Image; |
|
|
|
import com.jme3.texture.Image; |
|
|
|
import com.jme3.texture.Texture; |
|
|
|
import com.jme3.texture.Texture; |
|
|
@ -494,11 +497,7 @@ public class EditableMaterialFile { |
|
|
|
setMatDefName(mat.getMaterialDef().getAssetName()); |
|
|
|
setMatDefName(mat.getMaterialDef().getAssetName()); |
|
|
|
createBaseMaterialFile(); |
|
|
|
createBaseMaterialFile(); |
|
|
|
materialParameters.clear(); |
|
|
|
materialParameters.clear(); |
|
|
|
Collection<MatParam> params = mat.getParams(); |
|
|
|
checkPackedTextureProps(mat); |
|
|
|
for (Iterator<MatParam> it = params.iterator(); it.hasNext();) { |
|
|
|
|
|
|
|
MatParam matParam = it.next(); |
|
|
|
|
|
|
|
checkPackedTextureProps(mat, matParam); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
additionalRenderStates.put("Wireframe", new MaterialProperty("OnOff", "Wireframe", mat.getAdditionalRenderState().isWireframe() ? "On" : "Off")); |
|
|
|
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("DepthWrite", new MaterialProperty("OnOff", "DepthWrite", mat.getAdditionalRenderState().isDepthWrite() ? "On" : "Off")); |
|
|
|
additionalRenderStates.put("DepthTest", new MaterialProperty("OnOff", "DepthTest", mat.getAdditionalRenderState().isDepthTest() ? "On" : "Off")); |
|
|
|
additionalRenderStates.put("DepthTest", new MaterialProperty("OnOff", "DepthTest", mat.getAdditionalRenderState().isDepthTest() ? "On" : "Off")); |
|
|
@ -518,9 +517,11 @@ public class EditableMaterialFile { |
|
|
|
* @param mat |
|
|
|
* @param mat |
|
|
|
* @param param |
|
|
|
* @param param |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void checkPackedTextureProps(Material mat, MatParam param) { |
|
|
|
private void checkPackedTextureProps(Material mat) { |
|
|
|
|
|
|
|
Collection<MatParam> params = mat.getParams(); |
|
|
|
|
|
|
|
for (Iterator<MatParam> it = new ArrayList<MatParam>(params).iterator(); it.hasNext();) { |
|
|
|
|
|
|
|
MatParam param = it.next(); |
|
|
|
MaterialProperty prop = new MaterialProperty(param); |
|
|
|
MaterialProperty prop = new MaterialProperty(param); |
|
|
|
materialParameters.put(param.getName(), prop); |
|
|
|
|
|
|
|
if (prop.getValue() == null) { |
|
|
|
if (prop.getValue() == null) { |
|
|
|
switch (param.getVarType()) { |
|
|
|
switch (param.getVarType()) { |
|
|
|
case Texture2D: |
|
|
|
case Texture2D: |
|
|
@ -529,7 +530,8 @@ public class EditableMaterialFile { |
|
|
|
case TextureBuffer: |
|
|
|
case TextureBuffer: |
|
|
|
case TextureCubeMap: |
|
|
|
case TextureCubeMap: |
|
|
|
try { |
|
|
|
try { |
|
|
|
Texture tex = mat.getTextureParam(param.getName()).getTextureValue(); |
|
|
|
MatParamTexture texParam = mat.getTextureParam(param.getName()); |
|
|
|
|
|
|
|
Texture tex = texParam.getTextureValue(); |
|
|
|
Image img = tex.getImage(); |
|
|
|
Image img = tex.getImage(); |
|
|
|
if (img == null) { |
|
|
|
if (img == null) { |
|
|
|
logger.log(Level.INFO, "No image found"); |
|
|
|
logger.log(Level.INFO, "No image found"); |
|
|
@ -545,17 +547,30 @@ public class EditableMaterialFile { |
|
|
|
imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm); |
|
|
|
imgWrtr.write(null, new IIOImage(image, null, null), jpgWrtPrm); |
|
|
|
imgOutStrm.close(); |
|
|
|
imgOutStrm.close(); |
|
|
|
out.close(); |
|
|
|
out.close(); |
|
|
|
String name = material.getName(); |
|
|
|
String texturePath = material.getName(); |
|
|
|
name = "Textures/" + name + "-" + param.getName() + ".png"; |
|
|
|
texturePath = "Textures/" + texturePath + "-" + param.getName() + ".png"; |
|
|
|
StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), name); |
|
|
|
StoreTextureWizardWizardAction act = new StoreTextureWizardWizardAction(manager, out.toByteArray(), texturePath); |
|
|
|
act.actionPerformed(null); |
|
|
|
act.actionPerformed(null); |
|
|
|
prop.setValue(act.getName()); |
|
|
|
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) { |
|
|
|
} catch (Exception ex) { |
|
|
|
Exceptions.printStackTrace(ex); |
|
|
|
Exceptions.printStackTrace(ex); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
materialParameters.put(param.getName(), prop); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|