diff options
Diffstat (limited to 'js/lib/rdge/materials/taper-material.js')
-rw-r--r-- | js/lib/rdge/materials/taper-material.js | 127 |
1 files changed, 40 insertions, 87 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index 356087d6..a44314b6 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js | |||
@@ -4,14 +4,17 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; | 7 | var Material = require("js/lib/rdge/materials/material").Material; |
8 | var Texture = require("js/lib/rdge/texture").Texture; | ||
9 | |||
8 | /////////////////////////////////////////////////////////////////////// | 10 | /////////////////////////////////////////////////////////////////////// |
9 | // Class GLMaterial | 11 | // Class GLMaterial |
10 | // RDGE representation of a material. | 12 | // RDGE representation of a material. |
11 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
12 | function TaperMaterial() { | 14 | var TaperMaterial = function TaperMaterial() |
15 | { | ||
13 | // initialize the inherited members | 16 | // initialize the inherited members |
14 | this.inheritedFrom = GLMaterial; | 17 | this.inheritedFrom = Material; |
15 | this.inheritedFrom(); | 18 | this.inheritedFrom(); |
16 | 19 | ||
17 | /////////////////////////////////////////////////////////////////////// | 20 | /////////////////////////////////////////////////////////////////////// |
@@ -20,17 +23,16 @@ function TaperMaterial() { | |||
20 | this._name = "TaperMaterial"; | 23 | this._name = "TaperMaterial"; |
21 | this._shaderName = "taper"; | 24 | this._shaderName = "taper"; |
22 | 25 | ||
23 | this._color = [1, 0, 0, 1]; | ||
24 | |||
25 | this._deltaTime = 0.0; | 26 | this._deltaTime = 0.0; |
26 | 27 | ||
27 | /////////////////////////////////////////////////////////////////////// | 28 | /////////////////////////////////////////////////////////////////////// |
28 | // Property Accessors | 29 | // Property Accessors |
29 | /////////////////////////////////////////////////////////////////////// | 30 | /////////////////////////////////////////////////////////////////////// |
30 | this.getColor = function () { return this._color; }; | ||
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,9 +40,6 @@ function TaperMaterial() { | |||
38 | /////////////////////////////////////////////////////////////////////// | 40 | /////////////////////////////////////////////////////////////////////// |
39 | // Methods | 41 | // Methods |
40 | /////////////////////////////////////////////////////////////////////// | 42 | /////////////////////////////////////////////////////////////////////// |
41 | // duplcate method requirde | ||
42 | this.dup = function () { return new TaperMaterial(); }; | ||
43 | |||
44 | this.init = function (world) { | 43 | this.init = function (world) { |
45 | this.setWorld(world); | 44 | this.setWorld(world); |
46 | 45 | ||
@@ -49,104 +48,56 @@ function TaperMaterial() { | |||
49 | this._shader.def = taperShaderDef; | 48 | this._shader.def = taperShaderDef; |
50 | this._shader.init(); | 49 | this._shader.init(); |
51 | 50 | ||
52 | // set the defaults | ||
53 | this._shader.colorMe.color.set(this.getColor()); | ||
54 | |||
55 | // set up the material node | 51 | // set up the material node |
56 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); | 52 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); |
57 | 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); | ||
58 | 59 | ||
59 | // initialize the taper properties | 60 | // initialize the taper properties |
60 | this.updateShaderValues(); | 61 | this.setShaderValues(); |
61 | }; | 62 | }; |
62 | 63 | ||
63 | 64 | ||
64 | /////////////////////////////////////////////////////////////////////// | 65 | /////////////////////////////////////////////////////////////////////// |
65 | // Material Property Accessors | 66 | // Material Property Accessors |
66 | /////////////////////////////////////////////////////////////////////// | 67 | /////////////////////////////////////////////////////////////////////// |
67 | this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount"]; | 68 | this._propNames = [ "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount", "u_speed" ]; |
68 | this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"]; | 69 | this._propLabels = [ "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount", "Speed" ]; |
69 | this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"]; | 70 | this._propTypes = [ "float", "float", "float", "float", "float", "float", "float", "float" ]; |
70 | this._propValues = []; | 71 | this._propValues = []; |
71 | 72 | ||
72 | // initialize the property values | 73 | // initialize the property values |
73 | this._propValues[this._propNames[0]] = this._color.slice(); | 74 | this._propValues[this._propNames[0]] = 0.25; |
74 | this._propValues[this._propNames[1]] = 0.25; | 75 | this._propValues[this._propNames[1]] = 0.50; |
75 | this._propValues[this._propNames[2]] = 0.50; | 76 | this._propValues[this._propNames[2]] = 0.75; |
76 | this._propValues[this._propNames[3]] = 0.75; | 77 | this._propValues[this._propNames[3]] = -1; |
77 | this._propValues[this._propNames[4]] = -1; | 78 | this._propValues[this._propNames[4]] = 1; |
78 | this._propValues[this._propNames[5]] = 1; | 79 | this._propValues[this._propNames[5]] = 0.0; |
79 | this._propValues[this._propNames[6]] = 0.0; | 80 | this._propValues[this._propNames[6]] = 0.9; |
80 | this._propValues[this._propNames[7]] = 0.9; | 81 | this._propValues[this._propNames[7]] = 1.0; |
81 | |||
82 | this.setProperty = function (prop, value) { | ||
83 | // make sure we have legitimate input | ||
84 | if (this.validateProperty(prop, value)) { | ||
85 | switch (prop) { | ||
86 | case "color": this._propValues[prop] = value.slice(); break; | ||
87 | default: this._propValues[prop] = value; break; | ||
88 | } | ||
89 | |||
90 | this.updateShaderValues(); | ||
91 | } | ||
92 | }; | ||
93 | /////////////////////////////////////////////////////////////////////// | ||
94 | this.exportJSON = function () { | ||
95 | var jObj = | ||
96 | { | ||
97 | 'material': this.getShaderName(), | ||
98 | 'name': this.getName(), | ||
99 | 'color': this._propValues["color"] | ||
100 | }; | ||
101 | |||
102 | return jObj; | ||
103 | }; | ||
104 | |||
105 | this.importJSON = function (jObj) { | ||
106 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); | ||
107 | this.setName(jObj.name); | ||
108 | |||
109 | try { | ||
110 | var color = jObj.color; | ||
111 | this.setProperty("color", color); | ||
112 | } | ||
113 | catch (e) { | ||
114 | throw new Error("could not import material: " + jObj); | ||
115 | } | ||
116 | }; | ||
117 | 82 | ||
118 | this.update = function (time) { | 83 | this.update = function (time) { |
119 | //var speed = 0.01; | 84 | var speed = this._propValues["u_speed"]; |
120 | //time *= speed; | 85 | this._deltaTime += 0.01 * speed; |
121 | this._deltaTime += 0.01; | ||
122 | 86 | ||
123 | if (this._shader && this._shader.colorMe) { | 87 | if (this._shader && this._shader.colorMe) { |
124 | var t3 = this._propValues[this._propNames[3]] - this._deltaTime; | 88 | var t3 = this._propValues["u_limit3"] - this._deltaTime; |
125 | if (t3 < 0) { | 89 | if (t3 < 0) { |
126 | this._deltaTime = this._propValues[this._propNames[1]] - 1.0; | 90 | this._deltaTime = this._propValues["u_limit1"] - 1.0; |
127 | t3 = this._propValues[this._propNames[3]] - this._deltaTime; | 91 | t3 = this._propValues["u_limit3"] - this._deltaTime; |
128 | } | 92 | } |
129 | var t1 = this._propValues[this._propNames[1]] - this._deltaTime, | ||
130 | t2 = this._propValues[this._propNames[2]] - this._deltaTime; | ||
131 | 93 | ||
94 | var t1 = this._propValues["u_limit1"] - this._deltaTime, | ||
95 | t2 = this._propValues["u_limit2"] - this._deltaTime; | ||
132 | 96 | ||
133 | this._shader.colorMe[this._propNames[1]].set([t1]); | ||
134 | this._shader.colorMe[this._propNames[2]].set([t2]); | ||
135 | this._shader.colorMe[this._propNames[3]].set([t3]); | ||
136 | } | ||
137 | }; | ||
138 | 97 | ||
139 | this.updateShaderValues = function () { | 98 | this._shader.colorMe["u_limit1"].set([t1]); |
140 | if (this._shader && this._shader.colorMe) { | 99 | this._shader.colorMe["u_limit2"].set([t2]); |
141 | var nProps = this._propNames.length; | 100 | this._shader.colorMe["u_limit3"].set([t3]); |
142 | for (var i = 0; i < nProps; i++) { | ||
143 | var propName = this._propNames[i]; | ||
144 | var propValue = this._propValues[propName]; | ||
145 | switch (propName) { | ||
146 | case "color": this._shader.colorMe[propName].set(propValue); break; | ||
147 | default: this._shader.colorMe[propName].set([propValue]); break; | ||
148 | } | ||
149 | } | ||
150 | } | 101 | } |
151 | }; | 102 | }; |
152 | }; | 103 | }; |
@@ -176,8 +127,6 @@ taperShaderDef = { | |||
176 | // attributes | 127 | // attributes |
177 | 'params': | 128 | 'params': |
178 | { | 129 | { |
179 | 'color': { 'type': 'vec4' }, | ||
180 | |||
181 | 'u_limit1': { 'type': 'float' }, | 130 | 'u_limit1': { 'type': 'float' }, |
182 | 'u_limit2': { 'type': 'float' }, | 131 | 'u_limit2': { 'type': 'float' }, |
183 | 'u_limit3': { 'type': 'float' }, | 132 | 'u_limit3': { 'type': 'float' }, |
@@ -191,3 +140,7 @@ taperShaderDef = { | |||
191 | } |