diff options
Diffstat (limited to 'js/lib/rdge/materials/taper-material.js')
-rw-r--r-- | js/lib/rdge/materials/taper-material.js | 131 |
1 files changed, 43 insertions, 88 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index 356087d6..f6aa782c 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js | |||
@@ -4,33 +4,36 @@ 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 | /////////////////////////////////////////////////////////////////////// |
18 | // Instance variables | 21 | // Instance variables |
19 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
20 | this._name = "TaperMaterial"; | 23 | this._name = "Taper"; |
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 | this.getTechniqueName = function() { return 'colorMe' }; | ||
36 | |||
34 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; | 37 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; |
35 | this._hasVertexDeformation = true; | 38 | this._hasVertexDeformation = true; |
36 | this._vertexDeformationTolerance = 0.02; // should be a property | 39 | this._vertexDeformationTolerance = 0.02; // should be a property |
@@ -38,9 +41,6 @@ function TaperMaterial() { | |||
38 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
39 | // Methods | 42 | // Methods |
40 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
41 | // duplcate method requirde | ||
42 | this.dup = function () { return new TaperMaterial(); }; | ||
43 | |||
44 | this.init = function (world) { | 44 | this.init = function (world) { |
45 | this.setWorld(world); | 45 | this.setWorld(world); |
46 | 46 | ||
@@ -49,104 +49,56 @@ function TaperMaterial() { | |||
49 | this._shader.def = taperShaderDef; | 49 | this._shader.def = taperShaderDef; |
50 | this._shader.init(); | 50 | this._shader.init(); |
51 | 51 | ||
52 | // set the defaults | ||
53 | this._shader.colorMe.color.set(this.getColor()); | ||
54 | |||
55 | // set up the material node | 52 | // set up the material node |
56 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); | 53 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); |
57 | this._materialNode.setShader(this._shader); | 54 | this._materialNode.setShader(this._shader); |
55 | |||
56 | this._time = 0; | ||
57 | if (this._shader && this._shader['default']) { | ||
58 | this._shader['default'].u_time.set([this._time]); | ||
59 | } | ||
58 | 60 | ||
59 | // initialize the taper properties | 61 | // initialize the taper properties |
60 | this.updateShaderValues(); | 62 | this.setShaderValues(); |
61 | }; | 63 | }; |
62 | 64 | ||
63 | 65 | ||
64 | /////////////////////////////////////////////////////////////////////// | 66 | /////////////////////////////////////////////////////////////////////// |
65 | // Material Property Accessors | 67 | // Material Property Accessors |
66 | /////////////////////////////////////////////////////////////////////// | 68 | /////////////////////////////////////////////////////////////////////// |
67 | this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount"]; | 69 | 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"]; | 70 | 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"]; | 71 | this._propTypes = [ "float", "float", "float", "float", "float", "float", "float", "float" ]; |
70 | this._propValues = []; | 72 | this._propValues = []; |
71 | 73 | ||
72 | // initialize the property values | 74 | // initialize the property values |
73 | this._propValues[this._propNames[0]] = this._color.slice(); | 75 | this._propValues[this._propNames[0]] = 0.25; |
74 | this._propValues[this._propNames[1]] = 0.25; | 76 | this._propValues[this._propNames[1]] = 0.50; |
75 | this._propValues[this._propNames[2]] = 0.50; | 77 | this._propValues[this._propNames[2]] = 0.75; |
76 | this._propValues[this._propNames[3]] = 0.75; | 78 | this._propValues[this._propNames[3]] = -1; |
77 | this._propValues[this._propNames[4]] = -1; | 79 | this._propValues[this._propNames[4]] = 1; |
78 | this._propValues[this._propNames[5]] = 1; | 80 | this._propValues[this._propNames[5]] = 0.0; |
79 | this._propValues[this._propNames[6]] = 0.0; | 81 | this._propValues[this._propNames[6]] = 0.9; |
80 | this._propValues[this._propNames[7]] = 0.9; | 82 | 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 | 83 | ||
118 | this.update = function (time) { | 84 | this.update = function (time) { |
119 | //var speed = 0.01; | 85 | var speed = this._propValues["u_speed"]; |
120 | //time *= speed; | 86 | this._deltaTime += 0.01 * speed; |
121 | this._deltaTime += 0.01; | ||
122 | 87 | ||
123 | if (this._shader && this._shader.colorMe) { | 88 | if (this._shader && this._shader.colorMe) { |
124 | var t3 = this._propValues[this._propNames[3]] - this._deltaTime; | 89 | var t3 = this._propValues["u_limit3"] - this._deltaTime; |
125 | if (t3 < 0) { | 90 | if (t3 < 0) { |
126 | this._deltaTime = this._propValues[this._propNames[1]] - 1.0; | 91 | this._deltaTime = this._propValues["u_limit1"] - 1.0; |
127 | t3 = this._propValues[this._propNames[3]] - this._deltaTime; | 92 | t3 = this._propValues["u_limit3"] - this._deltaTime; |
128 | } | 93 | } |
129 | var t1 = this._propValues[this._propNames[1]] - this._deltaTime, | ||
130 | t2 = this._propValues[this._propNames[2]] - this._deltaTime; | ||
131 | 94 | ||
95 | var t1 = this._propValues["u_limit1"] - this._deltaTime, | ||
96 | t2 = this._propValues["u_limit2"] - this._deltaTime; | ||
132 | 97 | ||
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 | 98 | ||
139 | this.updateShaderValues = function () { | 99 | this._shader.colorMe["u_limit1"].set([t1]); |
140 | if (this._shader && this._shader.colorMe) { | 100 | this._shader.colorMe["u_limit2"].set([t2]); |
141 | var nProps = this._propNames.length; | 101 | 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 | } | 102 | } |
151 | }; | 103 | }; |
152 | }; | 104 | }; |
@@ -176,18 +128,21 @@ taperShaderDef = { | |||
176 | // attributes | 128 | // attributes |
177 | 'params': | 129 | 'params': |
178 | { | 130 | { |
179 | 'color': { 'type': 'vec4' }, | ||
180 | |||
181 | 'u_limit1': { 'type': 'float' }, | 131 | 'u_limit1': { 'type': 'float' }, |
182 | 'u_limit2': { 'type': 'float' }, | 132 | 'u_limit2': { 'type': 'float' }, |
183 | 'u_limit3': { 'type': 'float' }, | 133 |