MaterialDef is now savable
This commit is contained in:
parent
d1fc89e155
commit
0e064e2d6a
@ -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);
|
||||
}
|
||||
}
|
@ -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<TechniqueDef> 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<String, SavableListWrapper> wrapper = new HashMap<String, SavableListWrapper>();
|
||||
|
||||
for (String key : techniques.keySet()) {
|
||||
List<TechniqueDef> 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<String, MatParam>)in.readStringSavableMap("matPrams", null);
|
||||
Map<String, SavableListWrapper> wrapper = (Map<String, SavableListWrapper>)in.readStringSavableMap("techniques", null);
|
||||
techniques = new HashMap<String, List<TechniqueDef>>();
|
||||
for (String key : wrapper.keySet()) {
|
||||
SavableListWrapper w = wrapper.get(key);
|
||||
techniques.put(key, w.defs);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper to be able to save a List<TechniqueDef> to save the Map<String, List<TechniqueDefs>>
|
||||
*/
|
||||
public static class SavableListWrapper implements Savable{
|
||||
List<TechniqueDef> defs;
|
||||
|
||||
public SavableListWrapper(List<TechniqueDef> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user