use of com.jme3.shader.VarType in project jmonkeyengine by jMonkeyEngine.
the class J3MOutputCapsule method formatMatParam.
private String formatMatParam(MatParam param) {
VarType type = param.getVarType();
Object val = param.getValue();
switch(type) {
case Boolean:
case Float:
case Int:
return val.toString();
case Vector2:
Vector2f v2 = (Vector2f) val;
return v2.getX() + " " + v2.getY();
case Vector3:
Vector3f v3 = (Vector3f) val;
return v3.getX() + " " + v3.getY() + " " + v3.getZ();
case Vector4:
// can be either ColorRGBA, Vector4f or Quaternion
if (val instanceof Vector4f) {
Vector4f v4 = (Vector4f) val;
return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
} else if (val instanceof ColorRGBA) {
ColorRGBA color = (ColorRGBA) val;
return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
} else if (val instanceof Quaternion) {
Quaternion quat = (Quaternion) val;
return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
} else {
throw new UnsupportedOperationException("Unexpected Vector4 type: " + val);
}
default:
// parameter type not supported in J3M
return null;
}
}
use of com.jme3.shader.VarType in project jmonkeyengine by jMonkeyEngine.
the class MaterialMatParamTest method uniform.
private Uniform uniform(String name, VarType type, Object value) {
Uniform u = new Uniform();
u.setName("m_" + name);
u.setValue(type, value);
return u;
}
use of com.jme3.shader.VarType in project jmonkeyengine by jMonkeyEngine.
the class MaterialMatParamTest method outDefines.
private void outDefines(Define... expectedDefinesArray) {
StringBuilder expectedDefineSource = new StringBuilder();
for (Define define : expectedDefinesArray) {
expectedDefineSource.append(define.toString());
}
if (!evaluated) {
evaluateTechniqueDef();
}
Material mat = geometry.getMaterial();
Technique tech = mat.getActiveTechnique();
TechniqueDef def = tech.getDef();
DefineList actualDefines = tech.getDynamicDefines();
String[] defineNames = def.getDefineNames();
VarType[] defineTypes = def.getDefineTypes();
String actualDefineSource = actualDefines.generateSource(Arrays.asList(defineNames), Arrays.asList(defineTypes));
assertEquals(expectedDefineSource.toString(), actualDefineSource);
}
Aggregations