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.js74
1 files changed, 9 insertions, 65 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js
index c491fe61..a44314b6 100644
--- a/js/lib/rdge/materials/taper-material.js
+++ b/js/lib/rdge/materials/taper-material.js
@@ -31,6 +31,8 @@ var TaperMaterial = function TaperMaterial()
31 this.getShaderName = function () { return this._shaderName; }; 31 this.getShaderName = function () { return this._shaderName; };
32 32
33 this.isAnimated = function () { return true; }; 33 this.isAnimated = function () { return true; };
34 this.getShaderDef = function() { return taperShaderDef; };
35
34 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 36 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
35 this._hasVertexDeformation = true; 37 this._hasVertexDeformation = true;
36 this._vertexDeformationTolerance = 0.02; // should be a property 38 this._vertexDeformationTolerance = 0.02; // should be a property
@@ -38,8 +40,6 @@ var TaperMaterial = function TaperMaterial()
38 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
39 // Methods 41 // Methods
40 /////////////////////////////////////////////////////////////////////// 42 ///////////////////////////////////////////////////////////////////////
41 // duplcate method requirde
42
43 this.init = function (world) { 43 this.init = function (world) {
44 this.setWorld(world); 44 this.setWorld(world);
45 45
@@ -50,10 +50,15 @@ var TaperMaterial = function TaperMaterial()
50 50
51 // set up the material node 51 // set up the material node
52 this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); 52 this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID());
53 this._materialNode.setShader(this._shader); 53
54 this._time = 0;
55 if (this._shader && this._shader['default']) {
56 this._shader['default'].u_time.set([this._time]);
57 }
58 this._materialNode.setShader(this._shader);
54 59
55 // initialize the taper properties 60 // initialize the taper properties
56 this.updateShaderValues(); 61 this.setShaderValues();
57 }; 62 };
58 63
59 64
@@ -75,54 +80,6 @@ var TaperMaterial = function TaperMaterial()
75 this._propValues[this._propNames[6]] = 0.9; 80 this._propValues[this._propNames[6]] = 0.9;
76 this._propValues[this._propNames[7]] = 1.0; 81 this._propValues[this._propNames[7]] = 1.0;
77 82
78 this.setProperty = function (prop, value)
79 {
80 // make sure we have legitimate input
81 if (this.validateProperty(prop, value))
82 this._propValues[prop] = value;
83
84 this.updateShaderValues();
85 };
86
87 this.exportJSON = function () {
88 var jObj =
89 {
90 'material': this.getShaderName(),
91 'name': this.getName()
92 };
93
94 var n = this._propNames.length;
95 for (var i=0; i<n; i++)
96 {
97 var prop = this._propNames[i],
98 val = this._propValues[prop];
99
100 jObj[prop] = val;
101 }
102
103 return jObj;
104 };
105
106 this.importJSON = function (jObj) {
107 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
108 this.setName(jObj.name);
109
110 try
111 {
112 for ( var prop in jObj)
113 {
114 if ((prop != 'material') && (prop != 'name'))
115 {
116 var value = jObj[prop];
117 this.setProperty( prop, value );
118 }
119 }
120 }
121 catch (e) {
122 throw new Error("could not import material: " + jObj);
123 }
124 };
125
126 this.update = function (time) { 83 this.update = function (time) {
127 var speed = this._propValues["u_speed"]; 84 var speed = this._propValues["u_speed"];
128 this._deltaTime += 0.01 * speed; 85 this._deltaTime += 0.01 * speed;
@@ -143,19 +100,6 @@ var TaperMaterial = function TaperMaterial()
143 this._shader.colorMe["u_limit3"].set([t3]); 100 this._shader.colorMe["u_limit3"].set([t3]);
144 } 101 }
145 }; 102 };
146
147 this.updateShaderValues = function () {
148 if (this._shader && this._shader.colorMe) {
149 var nProps = this._propNames.length;
150 for (var i = 0; i < nProps; i++) {
151 var propName = this._propNames[i];
152 var propValue = this._propValues[propName];
153
154 if (this._shader.colorMe[propName])
155 this._shader.colorMe[propName].set([propValue]);
156 }
157 }
158 };
159}; 103};
160 104
161/////////////////////////////////////////////////////////////////////////////////////// 105///////////////////////////////////////////////////////////////////////////////////////