diff options
Diffstat (limited to 'js/helper-classes/RDGE/Materials/FlatMaterial.js')
-rw-r--r-- | js/helper-classes/RDGE/Materials/FlatMaterial.js | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js index 5177a8a0..a5c079a8 100644 --- a/js/helper-classes/RDGE/Materials/FlatMaterial.js +++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js | |||
@@ -63,11 +63,12 @@ function FlatMaterial() | |||
63 | 63 | ||
64 | this.setProperty = function( prop, value ) | 64 | this.setProperty = function( prop, value ) |
65 | { | 65 | { |
66 | // make sure we have legitimate imput | 66 | // make sure we have legitimate input |
67 | if (this.validateProperty( prop, value )) | 67 | if (this.validateProperty( prop, value )) |
68 | { | 68 | { |
69 | this._color = value.slice(0); | 69 | this._propValues[prop] = value; |
70 | this._shader.colorMe[prop].set(value); | 70 | if (this._shader && this._shader.colorMe) |
71 | this._shader.colorMe[prop].set(value); | ||
71 | } | 72 | } |
72 | } | 73 | } |
73 | /////////////////////////////////////////////////////////////////////// | 74 | /////////////////////////////////////////////////////////////////////// |
@@ -76,7 +77,7 @@ function FlatMaterial() | |||
76 | { | 77 | { |
77 | // this function should be overridden by subclasses | 78 | // this function should be overridden by subclasses |
78 | var exportStr = "material: " + this.getShaderName() + "\n"; | 79 | var exportStr = "material: " + this.getShaderName() + "\n"; |
79 | exportStr = "name: " + this.getName() + "\n"; | 80 | exportStr += "name: " + this.getName() + "\n"; |
80 | 81 | ||
81 | if (this._shader) | 82 | if (this._shader) |
82 | exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; | 83 | exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; |
@@ -87,19 +88,32 @@ function FlatMaterial() | |||
87 | return exportStr; | 88 | return exportStr; |
88 | } | 89 | } |
89 | 90 | ||
90 | this.import = function( importStr ) | 91 | this.import = function( importStr ) |
91 | { | 92 | { |
92 | var pu = new ParseUtils( importStr ); | 93 | var pu = new ParseUtils( importStr ); |
93 | var material = pu.nextValue( "material: " ); | 94 | var material = pu.nextValue( "material: " ); |
94 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); | 95 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); |
95 | this.setName( pu.nextValue( "material: ") ); | 96 | this.setName( pu.nextValue( "name: ") ); |
96 | var color = pu.nextValue( "color: " ); | 97 | |
97 | 98 | var rtnStr; | |
98 | var endKey = "endMaterial\n"; | 99 | try |
99 | var index = importStr.indexOf( endKey ) + endKey.len; | 100 | { |
100 | var rtnStr = importStr.substr( index ); | 101 | var color = eval( "[" + pu.nextValue( "color: " ) + "]" ); |
101 | return rtnStr; | 102 | |
102 | } | 103 | this.setProperty( "color", color); |
104 | |||
105 | var endKey = "endMaterial\n"; | ||
106 | var index = importStr.indexOf( endKey ); | ||
107 | index += endKey.length; | ||
108 | rtnStr = importStr.substr( index ); | ||
109 | } | ||
110 | catch (e) | ||
111 | { | ||
112 | throw new Error( "could not import material: " + importStr ); | ||
113 | } | ||
114 | |||
115 | return rtnStr; | ||
116 | } | ||
103 | } | 117 | } |
104 | 118 | ||
105 | // used to create unique names | 119 | // used to create unique names |