Fixed material reading with new prefixedName in MatParam
git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7657 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
447fd87d2c
commit
bc2de8626d
@ -29,7 +29,6 @@
|
|||||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.jme3.material;
|
package com.jme3.material;
|
||||||
|
|
||||||
import com.jme3.asset.TextureKey;
|
import com.jme3.asset.TextureKey;
|
||||||
@ -67,7 +66,7 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Create a new material parameter. For internal use only.
|
* Create a new material parameter. For internal use only.
|
||||||
*/
|
*/
|
||||||
public MatParam(VarType type, String name, Object value, FixedFuncBinding ffBinding){
|
public MatParam(VarType type, String name, Object value, FixedFuncBinding ffBinding) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.prefixedName = "m_" + name;
|
this.prefixedName = "m_" + name;
|
||||||
@ -78,7 +77,7 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Serialization only. Do not use.
|
* Serialization only. Do not use.
|
||||||
*/
|
*/
|
||||||
public MatParam(){
|
public MatParam() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,7 +102,7 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
* Returns the name of the material parameter.
|
* Returns the name of the material parameter.
|
||||||
* @return the name of the material parameter.
|
* @return the name of the material parameter.
|
||||||
*/
|
*/
|
||||||
public String getName(){
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,13 +114,14 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
public String getPrefixedName() {
|
public String getPrefixedName() {
|
||||||
return prefixedName;
|
return prefixedName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used internally
|
* Used internally
|
||||||
* @param name
|
* @param name
|
||||||
*/
|
*/
|
||||||
void setName(String name) {
|
void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
this.prefixedName = "m_" + name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +132,7 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
*
|
*
|
||||||
* @return the value of this material parameter.
|
* @return the value of this material parameter.
|
||||||
*/
|
*/
|
||||||
public Object getValue(){
|
public Object getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,7 +144,7 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
*
|
*
|
||||||
* @param value the value of this material parameter.
|
* @param value the value of this material parameter.
|
||||||
*/
|
*/
|
||||||
public void setValue(Object value){
|
public void setValue(Object value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,11 +153,11 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
if (techDef.isUsingShaders()) {
|
if (techDef.isUsingShaders()) {
|
||||||
technique.updateUniformParam(getPrefixedName(), getVarType(), getValue(), true);
|
technique.updateUniformParam(getPrefixedName(), getVarType(), getValue(), true);
|
||||||
}
|
}
|
||||||
if (ffBinding != null && r instanceof GL1Renderer){
|
if (ffBinding != null && r instanceof GL1Renderer) {
|
||||||
((GL1Renderer)r).setFixedFuncBinding(ffBinding, getValue());
|
((GL1Renderer) r).setFixedFuncBinding(ffBinding, getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the material parameter value as it would appear in a J3M
|
* Returns the material parameter value as it would appear in a J3M
|
||||||
* file. E.g.<br/>
|
* file. E.g.<br/>
|
||||||
@ -171,8 +171,8 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
* <br/><br/>
|
* <br/><br/>
|
||||||
* @return material parameter value as it would appear in a J3M file.
|
* @return material parameter value as it would appear in a J3M file.
|
||||||
*/
|
*/
|
||||||
public String getValueAsString(){
|
public String getValueAsString() {
|
||||||
switch (type){
|
switch (type) {
|
||||||
case Boolean:
|
case Boolean:
|
||||||
case Float:
|
case Float:
|
||||||
case Int:
|
case Int:
|
||||||
@ -185,19 +185,19 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
return v3.getX() + " " + v3.getY() + " " + v3.getZ();
|
return v3.getX() + " " + v3.getY() + " " + v3.getZ();
|
||||||
case Vector4:
|
case Vector4:
|
||||||
// can be either ColorRGBA, Vector4f or Quaternion
|
// can be either ColorRGBA, Vector4f or Quaternion
|
||||||
if (value instanceof Vector4f){
|
if (value instanceof Vector4f) {
|
||||||
Vector4f v4 = (Vector4f) value;
|
Vector4f v4 = (Vector4f) value;
|
||||||
return v4.getX() + " " + v4.getY() + " " +
|
return v4.getX() + " " + v4.getY() + " "
|
||||||
v4.getZ() + " " + v4.getW();
|
+ v4.getZ() + " " + v4.getW();
|
||||||
}else if (value instanceof ColorRGBA){
|
} else if (value instanceof ColorRGBA) {
|
||||||
ColorRGBA color = (ColorRGBA) value;
|
ColorRGBA color = (ColorRGBA) value;
|
||||||
return color.getRed() + " " + color.getGreen() + " " +
|
return color.getRed() + " " + color.getGreen() + " "
|
||||||
color.getBlue() + " " + color.getAlpha();
|
+ color.getBlue() + " " + color.getAlpha();
|
||||||
}else if (value instanceof Quaternion){
|
} else if (value instanceof Quaternion) {
|
||||||
Quaternion quat = (Quaternion) value;
|
Quaternion quat = (Quaternion) value;
|
||||||
return quat.getX() + " " + quat.getY() + " " +
|
return quat.getX() + " " + quat.getY() + " "
|
||||||
quat.getZ() + " " + quat.getW();
|
+ quat.getZ() + " " + quat.getW();
|
||||||
}else{
|
} else {
|
||||||
throw new UnsupportedOperationException("Unexpected Vector4 type: " + value);
|
throw new UnsupportedOperationException("Unexpected Vector4 type: " + value);
|
||||||
}
|
}
|
||||||
case Texture2D:
|
case Texture2D:
|
||||||
@ -208,10 +208,12 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
Texture texVal = (Texture) value;
|
Texture texVal = (Texture) value;
|
||||||
TextureKey texKey = (TextureKey) texVal.getKey();
|
TextureKey texKey = (TextureKey) texVal.getKey();
|
||||||
String ret = "";
|
String ret = "";
|
||||||
if (texKey.isFlipY())
|
if (texKey.isFlipY()) {
|
||||||
ret += "Flip ";
|
ret += "Flip ";
|
||||||
if (texVal.getWrap(Texture.WrapAxis.S) == WrapMode.Repeat)
|
}
|
||||||
|
if (texVal.getWrap(Texture.WrapAxis.S) == WrapMode.Repeat) {
|
||||||
ret += "Repeat ";
|
ret += "Repeat ";
|
||||||
|
}
|
||||||
|
|
||||||
return ret + texKey.getName();
|
return ret + texKey.getName();
|
||||||
default:
|
default:
|
||||||
@ -220,41 +222,41 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MatParam clone(){
|
public MatParam clone() {
|
||||||
try{
|
try {
|
||||||
MatParam param = (MatParam) super.clone();
|
MatParam param = (MatParam) super.clone();
|
||||||
return param;
|
return param;
|
||||||
}catch (CloneNotSupportedException ex){
|
} catch (CloneNotSupportedException ex) {
|
||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JmeExporter ex) throws IOException{
|
public void write(JmeExporter ex) throws IOException {
|
||||||
OutputCapsule oc = ex.getCapsule(this);
|
OutputCapsule oc = ex.getCapsule(this);
|
||||||
oc.write(type, "varType", null);
|
oc.write(type, "varType", null);
|
||||||
oc.write(name, "name", null);
|
oc.write(name, "name", null);
|
||||||
oc.write(ffBinding, "ff_binding", null);
|
oc.write(ffBinding, "ff_binding", null);
|
||||||
if (value instanceof Savable){
|
if (value instanceof Savable) {
|
||||||
Savable s = (Savable) value;
|
Savable s = (Savable) value;
|
||||||
oc.write(s, "value_savable", null);
|
oc.write(s, "value_savable", null);
|
||||||
}else if (value instanceof Float){
|
} else if (value instanceof Float) {
|
||||||
Float f = (Float) value;
|
Float f = (Float) value;
|
||||||
oc.write(f.floatValue(), "value_float", 0f);
|
oc.write(f.floatValue(), "value_float", 0f);
|
||||||
}else if (value instanceof Integer){
|
} else if (value instanceof Integer) {
|
||||||
Integer i = (Integer) value;
|
Integer i = (Integer) value;
|
||||||
oc.write(i.intValue(), "value_int", 0);
|
oc.write(i.intValue(), "value_int", 0);
|
||||||
}else if (value instanceof Boolean){
|
} else if (value instanceof Boolean) {
|
||||||
Boolean b = (Boolean) value;
|
Boolean b = (Boolean) value;
|
||||||
oc.write(b.booleanValue(), "value_bool", false);
|
oc.write(b.booleanValue(), "value_bool", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void read(JmeImporter im) throws IOException{
|
public void read(JmeImporter im) throws IOException {
|
||||||
InputCapsule ic = im.getCapsule(this);
|
InputCapsule ic = im.getCapsule(this);
|
||||||
type = ic.readEnum("varType", VarType.class, null);
|
type = ic.readEnum("varType", VarType.class, null);
|
||||||
name = ic.readString("name", null);
|
name = ic.readString("name", null);
|
||||||
ffBinding = ic.readEnum("ff_binding", FixedFuncBinding.class, null);
|
ffBinding = ic.readEnum("ff_binding", FixedFuncBinding.class, null);
|
||||||
switch (getVarType()){
|
switch (getVarType()) {
|
||||||
case Boolean:
|
case Boolean:
|
||||||
value = ic.readBoolean("value_bool", false);
|
value = ic.readBoolean("value_bool", false);
|
||||||
break;
|
break;
|
||||||
@ -271,13 +273,14 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other){
|
public boolean equals(Object other) {
|
||||||
if (!(other instanceof MatParam))
|
if (!(other instanceof MatParam)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
MatParam otherParam = (MatParam) other;
|
MatParam otherParam = (MatParam) other;
|
||||||
return otherParam.type == type &&
|
return otherParam.type == type
|
||||||
otherParam.name.equals(name);
|
&& otherParam.name.equals(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -289,8 +292,7 @@ public class MatParam implements Savable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return type.name() + " " + name + " : " + getValueAsString();
|
return type.name() + " " + name + " : " + getValueAsString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user