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.js102
1 files changed, 52 insertions, 50 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js
index 7938336b..c491fe61 100644
--- a/js/lib/rdge/materials/taper-material.js
+++ b/js/lib/rdge/materials/taper-material.js
@@ -23,14 +23,11 @@ var TaperMaterial = function TaperMaterial()
23 this._name = "TaperMaterial"; 23 this._name = "TaperMaterial";
24 this._shaderName = "taper"; 24 this._shaderName = "taper";
25 25
26 this._color = [1, 0, 0, 1];
27
28 this._deltaTime = 0.0; 26 this._deltaTime = 0.0;
29 27
30 /////////////////////////////////////////////////////////////////////// 28 ///////////////////////////////////////////////////////////////////////
31 // Property Accessors 29 // Property Accessors
32 /////////////////////////////////////////////////////////////////////// 30 ///////////////////////////////////////////////////////////////////////
33 this.getColor = function () { return this._color; };
34 this.getShaderName = function () { return this._shaderName; }; 31 this.getShaderName = function () { return this._shaderName; };
35 32
36 this.isAnimated = function () { return true; }; 33 this.isAnimated = function () { return true; };
@@ -42,7 +39,6 @@ var TaperMaterial = function TaperMaterial()
42 // Methods 39 // Methods
43 /////////////////////////////////////////////////////////////////////// 40 ///////////////////////////////////////////////////////////////////////
44 // duplcate method requirde 41 // duplcate method requirde
45 this.dup = function () { return new TaperMaterial(); };
46 42
47 this.init = function (world) { 43 this.init = function (world) {
48 this.setWorld(world); 44 this.setWorld(world);
@@ -52,9 +48,6 @@ var TaperMaterial = function TaperMaterial()
52 this._shader.def = taperShaderDef; 48 this._shader.def = taperShaderDef;
53 this._shader.init(); 49 this._shader.init();
54 50
55 // set the defaults
56 this._shader.colorMe.color.set(this.getColor());
57
58 // set up the material node 51 // set up the material node
59 this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); 52 this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID());
60 this._materialNode.setShader(this._shader); 53 this._materialNode.setShader(this._shader);
@@ -67,41 +60,46 @@ var TaperMaterial = function TaperMaterial()
67 /////////////////////////////////////////////////////////////////////// 60 ///////////////////////////////////////////////////////////////////////
68 // Material Property Accessors 61 // Material Property Accessors
69 /////////////////////////////////////////////////////////////////////// 62 ///////////////////////////////////////////////////////////////////////
70 this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount"]; 63 this._propNames = [ "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount", "u_speed" ];
71 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"]; 64 this._propLabels = [ "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount", "Speed" ];
72 this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"]; 65 this._propTypes = [ "float", "float", "float", "float", "float", "float", "float", "float" ];
73 this._propValues = []; 66 this._propValues = [];
74 67
75 // initialize the property values 68 // initialize the property values
76 this._propValues[this._propNames[0]] = this._color.slice(); 69 this._propValues[this._propNames[0]] = 0.25;
77 this._propValues[this._propNames[1]] = 0.25; 70 this._propValues[this._propNames[1]] = 0.50;
78 this._propValues[this._propNames[2]] = 0.50; 71 this._propValues[this._propNames[2]] = 0.75;
79 this._propValues[this._propNames[3]] = 0.75; 72 this._propValues[this._propNames[3]] = -1;
80 this._propValues[this._propNames[4]] = -1; 73 this._propValues[this._propNames[4]] = 1;
81 this._propValues[this._propNames[5]] = 1; 74 this._propValues[this._propNames[5]] = 0.0;
82 this._propValues[this._propNames[6]] = 0.0; 75 this._propValues[this._propNames[6]] = 0.9;
83 this._propValues[this._propNames[7]] = 0.9; 76 this._propValues[this._propNames[7]] = 1.0;
84 77
85 this.setProperty = function (prop, value) { 78 this.setProperty = function (prop, value)
79 {
86 // make sure we have legitimate input 80 // make sure we have legitimate input
87 if (this.validateProperty(prop, value)) { 81 if (this.validateProperty(prop, value))
88 switch (prop) { 82 this._propValues[prop] = value;
89 case "color": this._propValues[prop] = value.slice(); break;
90 default: this._propValues[prop] = value; break;
91 }
92 83
93 this.updateShaderValues(); 84 this.updateShaderValues();
94 }
95 }; 85 };
96 /////////////////////////////////////////////////////////////////////// 86
97 this.exportJSON = function () { 87 this.exportJSON = function () {
98 var jObj = 88 var jObj =
99 { 89 {
100 'material': this.getShaderName(), 90 'material': this.getShaderName(),
101 'name': this.getName(), 91 'name': this.getName()
102 'color': this._propValues["color"]
103 }; 92 };
104 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
105 return jObj; 103 return jObj;
106 }; 104 };
107 105
@@ -109,9 +107,16 @@ var TaperMaterial = function TaperMaterial()
109 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); 107 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
110 this.setName(jObj.name); 108 this.setName(jObj.name);
111 109
112 try { 110 try
113 var color = jObj.color; 111 {
114 this.setProperty("color", color); 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 }
115 } 120 }
116 catch (e) { 121 catch (e) {
117 throw new Error("could not import material: " + jObj); 122 throw new Error("could not import material: " + jObj);
@@ -119,23 +124,23 @@ var TaperMaterial = function TaperMaterial()
119 }; 124 };
120 125
121 this.update = function (time) { 126 this.update = function (time) {
122 //var speed = 0.01; 127 var speed = this._propValues["u_speed"];
123 //time *= speed; 128 this._deltaTime += 0.01 * speed;
124 this._deltaTime += 0.01;
125 129
126 if (this._shader && this._shader.colorMe) { 130 if (this._shader && this._shader.colorMe) {
127 var t3 = this._propValues[this._propNames[3]] - this._deltaTime; 131 var t3 = this._propValues["u_limit3"] - this._deltaTime;
128 if (t3 < 0) { 132 if (t3 < 0) {
129 this._deltaTime = this._propValues[this._propNames[1]] - 1.0; 133 this._deltaTime = this._propValues["u_limit1"] - 1.0;
130 t3 = this._propValues[this._propNames[3]] - this._deltaTime; 134 t3 = this._propValues["u_limit3"] - this._deltaTime;
131 } 135 }
132 var t1 = this._propValues[this._propNames[1]] - this._deltaTime,
133 t2 = this._propValues[this._propNames[2]] - this._deltaTime;
134 136
137 var t1 = this._propValues["u_limit1"] - this._deltaTime,
138 t2 = this._propValues["u_limit2"] - this._deltaTime;
135 139
136 this._shader.colorMe[this._propNames[1]].set([t1]); 140
137 this._shader.colorMe[this._propNames[2]].set([t2]); 141 this._shader.colorMe["u_limit1"].set([t1]);
138 this._shader.colorMe[this._propNames[3]].set([t3]); 142 this._shader.colorMe["u_limit2"].set([t2]);
143 this._shader.colorMe["u_limit3"].set([t3]);
139 } 144 }
140 }; 145 };
141 146
@@ -145,10 +150,9 @@ var TaperMaterial = function TaperMaterial()
145 for (var i = 0; i < nProps; i++) { 150 for (var i = 0; i < nProps; i++) {
146 var propName = this._propNames[i]; 151 var propName = this._propNames[i];
147 var propValue = this._propValues[propName]; 152 var propValue = this._propValues[propName];
148 switch (propName) { 153
149 case "color": this._shader.colorMe[propName].set(propValue); break; 154 if (this._shader.colorMe[propName])
150 default: this._shader.colorMe[propName].set([propValue]); break; 155 this._shader.colorMe[propName].set([propValue]);
151 }
152 } 156 }
153 } 157 }
154 }; 158 };
@@ -179,8 +183,6 @@ taperShaderDef = {
179 // attributes 183 // attributes
180 'params': 184 'params':
181 { 185 {
182 'color': { 'type': 'vec4' },
183
184 'u_limit1': { 'type': 'float' }, 186 'u_limit1': { 'type': 'float' },
185 'u_limit2': { 'type': 'float' }, 187 'u_limit2': { 'type': 'float' },
186 'u_limit3': { 'type': 'float' }, 188 'u_limit3': { 'type': 'float' },