diff options
Diffstat (limited to 'js/lib/rdge/materials/flat-material.js')
-rwxr-xr-x | js/lib/rdge/materials/flat-material.js | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/js/lib/rdge/materials/flat-material.js b/js/lib/rdge/materials/flat-material.js index be8bf2b8..fff0e68e 100755 --- a/js/lib/rdge/materials/flat-material.js +++ b/js/lib/rdge/materials/flat-material.js | |||
@@ -36,19 +36,27 @@ 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 | // set up the shader | 41 | // save the world |
42 | this._shader = new jshader(); | 42 | if (world) |
43 | this._shader.def = flatShaderDef; | 43 | { |
44 | this._shader.init(); | 44 | this.setWorld( world ); |
45 | 45 | ||
46 | // set the defaults | 46 | // set up the shader |
47 | this._shader.colorMe.color.set( this.getColor() ); | 47 | this._shader = new jshader(); |
48 | 48 | this._shader.def = flatShaderDef; | |
49 | // set up the material node | 49 | this._shader.init(); |
50 | this._materialNode = createMaterialNode("flatMaterial"); | 50 | |
51 | this._materialNode.setShader(this._shader); | 51 | // set the defaults |
52 | this._shader.colorMe.color.set( this.getColor() ); | ||
53 | |||
54 | // set up the material node | ||
55 | this._materialNode = createMaterialNode("flatMaterial_" + world.generateUniqueNodeID() ); | ||
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 | { |