diff options
Diffstat (limited to 'js/lib/rdge/materials/flat-material.js')
-rwxr-xr-x | js/lib/rdge/materials/flat-material.js | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index bc612476..e1363c06 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js | |||
@@ -36,8 +36,13 @@ var FlatMaterial = function FlatMaterial() { | |||
36 | // duplcate method requirde | 36 | // duplcate method requirde |
37 | this.dup = function() { return new FlatMaterial(); } ; | 37 | this.dup = function() { return new FlatMaterial(); } ; |
38 | 38 | ||
39 | this.init = function() | 39 | this.init = function( world ) |
40 | { | 40 | { |
41 | // save the world | ||
42 | if (world) | ||
43 | { | ||
44 | this.setWorld( world ); | ||
45 | |||
41 | // set up the shader | 46 | // set up the shader |
42 | this._shader = new RDGE.jshader(); | 47 | this._shader = new RDGE.jshader(); |
43 | this._shader.def = flatShaderDef; | 48 | this._shader.def = flatShaderDef; |
@@ -47,8 +52,11 @@ var FlatMaterial = function FlatMaterial() { | |||
47 | this._shader.colorMe.color.set( this.getColor() ); | 52 | this._shader.colorMe.color.set( this.getColor() ); |
48 | 53 | ||
49 | // set up the material node | 54 | // set up the material node |
50 | this._materialNode = RDGE.createMaterialNode("flatMaterial"); | 55 | this._materialNode = RDGE.createMaterialNode("flatMaterial_" + world.generateUniqueNodeID() ); |
51 | this._materialNode.setShader(this._shader); | 56 | this._materialNode.setShader(this._shader); |
57 | } | ||
58 | else | ||
59 | throw new Error( "GLWorld not supplied to material initialization" ); | ||
52 | }; | 60 | }; |
53 | 61 | ||
54 | 62 | ||
@@ -73,15 +81,12 @@ var FlatMaterial = function FlatMaterial() { | |||
73 | }; | 81 | }; |
74 | /////////////////////////////////////////////////////////////////////// | 82 | /////////////////////////////////////////////////////////////////////// |
75 | 83 | ||
76 | this.export = function() { | 84 | this.export = function() |
85 | { | ||
77 | // this function should be overridden by subclasses | 86 | // this function should be overridden by subclasses |
78 | var exportStr = "material: " + this.getShaderName() + "\n"; | 87 | var exportStr = "material: " + this.getShaderName() + "\n"; |
79 | exportStr += "name: " + this.getName() + "\n"; | 88 | exportStr += "name: " + this.getName() + "\n"; |
80 | 89 | exportStr += "color: " + String(this._propValues["color"]) + "\n"; | |
81 | if (this._shader) | ||
82 | exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; | ||
83 | else | ||
84 | exportStr += "color: " + this.getColor() + "\n"; | ||
85 | exportStr += "endMaterial\n"; | 90 | exportStr += "endMaterial\n"; |
86 | 91 | ||
87 | return exportStr; | 92 | return exportStr; |
@@ -97,13 +102,7 @@ var FlatMaterial = function FlatMaterial() { | |||
97 | try | 102 | try |
98 | { | 103 | { |
99 | var color = eval( "[" + pu.nextValue( "color: " ) + "]" ); | 104 | var color = eval( "[" + pu.nextValue( "color: " ) + "]" ); |
100 | |||
101 | this.setProperty( "color", color); | 105 | this.setProperty( "color", color); |
102 | |||
103 | var endKey = "endMaterial\n"; | ||
104 | var index = importStr.indexOf( endKey ); | ||
105 | index += endKey.length; | ||
106 | rtnStr = importStr.substr( index ); | ||
107 | } | 106 | } |
108 | catch (e) | 107 | catch (e) |
109 | { | 108 | { |
@@ -113,6 +112,27 @@ var FlatMaterial = function FlatMaterial() { | |||
113 | return rtnStr; | 112 | return rtnStr; |
114 | }; | 113 | }; |
115 | 114 | ||
115 | this.exportJSON = function() | ||
116 | { | ||
117 | var jObj = | ||
118 | { | ||
119 | 'material' : this.getShaderName(), | ||
120 | 'name' : this.getName(), | ||
121 | 'color' : this._propValues["color"] | ||
122 | }; | ||
123 | |||
124 | return jObj; | ||
125 | } | ||
126 | |||
127 | this.importJSON = function( jObj ) | ||
128 | { | ||
129 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); | ||
130 | this.setName( jObj.name ); | ||
131 | |||
132 | var color = jObj.color; | ||
133 | this.setProperty( "color", color); | ||
134 | } | ||
135 | |||
116 | this.update = function( time ) | 136 | this.update = function( time ) |
117 | { | 137 | { |
118 | }; | 138 | }; |