aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/taper-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/taper-material.js')
-rw-r--r--js/lib/rdge/materials/taper-material.js35
1 files changed, 32 insertions, 3 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js
index 7feea79a..e59b6112 100644
--- a/js/lib/rdge/materials/taper-material.js
+++ b/js/lib/rdge/materials/taper-material.js
@@ -42,8 +42,10 @@ function TaperMaterial()
42 // duplcate method requirde 42 // duplcate method requirde
43 this.dup = function() { return new TaperMaterial(); } 43 this.dup = function() { return new TaperMaterial(); }
44 44
45 this.init = function() 45 this.init = function( world )
46 { 46 {
47 this.setWorld( world );
48
47 // set up the shader 49 // set up the shader
48 this._shader = new RDGE.jshader(); 50 this._shader = new RDGE.jshader();
49 this._shader.def = taperShaderDef; 51 this._shader.def = taperShaderDef;
@@ -53,7 +55,7 @@ function TaperMaterial()
53 this._shader.colorMe.color.set( this.getColor() ); 55 this._shader.colorMe.color.set( this.getColor() );
54 56
55 // set up the material node 57 // set up the material node
56 this._materialNode = RDGE.createMaterialNode("taperMaterial"); 58 this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID());
57 this._materialNode.setShader(this._shader); 59 this._materialNode.setShader(this._shader);
58 60
59 // initialize the taper properties 61 // initialize the taper properties
@@ -94,6 +96,33 @@ function TaperMaterial()
94 } 96 }
95 } 97 }
96 /////////////////////////////////////////////////////////////////////// 98 ///////////////////////////////////////////////////////////////////////
99 this.exportJSON = function()
100 {
101 var jObj =
102 {
103 'material' : this.getShaderName(),
104 'name' : this.getName(),
105 'color' : this._propValues["color"]
106 };
107
108 return jObj;
109 }
110
111 this.importJSON = function( jObj )
112 {
113 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" );
114 this.setName( jObj.name );
115
116 try
117 {
118 var color = jObj.color;
119 this.setProperty( "color", color);
120 }
121 catch (e)
122 {
123 throw new Error( "could not import material: " + jObj );
124 }
125 }
97 126
98 this.export = function() 127 this.export = function()
99 { 128 {
@@ -102,7 +131,7 @@ function TaperMaterial()
102 exportStr += "name: " + this.getName() + "\n"; 131 exportStr += "name: " + this.getName() + "\n";
103 132
104 if (this._shader) 133 if (this._shader)
105 exportStr += "color: " + String(this._shader.colorMe.color) + "\n"; 134 exportStr += "color: " + this._shader.colorMe.color + "\n";
106 else 135 else
107 exportStr += "color: " + this.getColor() + "\n"; 136 exportStr += "color: " + this.getColor() + "\n";
108 exportStr += "endMaterial\n"; 137 exportStr += "endMaterial\n";