diff --git a/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java b/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java index cb800e75b..4fffd1616 100644 --- a/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java +++ b/jme3-core/src/main/java/com/jme3/material/MatParamTexture.java @@ -95,6 +95,8 @@ public class MatParamTexture extends MatParam { OutputCapsule oc = ex.getCapsule(this); oc.write(0, "texture_unit", -1); oc.write(texture, "texture", null); // For backwards compatibility + + oc.write(colorSpace, "colorSpace", null); } @Override @@ -102,5 +104,6 @@ public class MatParamTexture extends MatParam { super.read(im); InputCapsule ic = im.getCapsule(this); texture = (Texture) value; + colorSpace = (ColorSpace) ic.readEnum("colorSpace", ColorSpace.class, null); } } \ No newline at end of file diff --git a/jme3-core/src/main/java/com/jme3/material/MaterialDef.java b/jme3-core/src/main/java/com/jme3/material/MaterialDef.java index fa205460e..92f31a93c 100644 --- a/jme3-core/src/main/java/com/jme3/material/MaterialDef.java +++ b/jme3-core/src/main/java/com/jme3/material/MaterialDef.java @@ -32,9 +32,12 @@ package com.jme3.material; import com.jme3.asset.AssetManager; +import com.jme3.export.*; import com.jme3.renderer.Caps; import com.jme3.shader.VarType; import com.jme3.texture.image.ColorSpace; + +import java.io.IOException; import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; @@ -44,7 +47,7 @@ import java.util.logging.Logger; * * @author Kirill Vainer */ -public class MaterialDef { +public class MaterialDef implements Savable{ private static final Logger logger = Logger.getLogger(MaterialDef.class.getName()); @@ -185,4 +188,58 @@ public class MaterialDef { public List getTechniqueDefs(String name) { return techniques.get(name); } + + @Override + public void write(JmeExporter ex) throws IOException { + OutputCapsule out = ex.getCapsule(this); + out.write(name, "name" , null); + out.writeStringSavableMap(matParams, "matParams", null); + + Map wrapper = new HashMap(); + + for (String key : techniques.keySet()) { + List defs = techniques.get(key); + wrapper.put(key, new SavableListWrapper(defs)); + } + + out.writeStringSavableMap(wrapper, "techniques", null); + + } + + @Override + public void read(JmeImporter im) throws IOException { + InputCapsule in = im.getCapsule(this); + name = in.readString("name", null); + matParams = (Map)in.readStringSavableMap("matPrams", null); + Map wrapper = (Map)in.readStringSavableMap("techniques", null); + techniques = new HashMap>(); + for (String key : wrapper.keySet()) { + SavableListWrapper w = wrapper.get(key); + techniques.put(key, w.defs); + } + } + + /** + * A wrapper to be able to save a List to save the Map> + */ + public static class SavableListWrapper implements Savable{ + List defs; + + public SavableListWrapper(List defs) { + this.defs = defs; + } + + @Override + public void write(JmeExporter ex) throws IOException { + OutputCapsule out = ex.getCapsule(this); + out.writeSavableArrayList((ArrayList)defs, "defs", null); + + } + + @Override + public void read(JmeImporter im) throws IOException { + InputCapsule in = im.getCapsule(this); + defs = in.readSavableArrayList("defs", null); + } + } }