diff options
Diffstat (limited to 'js/lib/rdge/materials/taper-material.js')
-rw-r--r-- | js/lib/rdge/materials/taper-material.js | 396 |
1 files changed, 169 insertions, 227 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js index efba3807..7938336b 100644 --- a/js/lib/rdge/materials/taper-material.js +++ b/js/lib/rdge/materials/taper-material.js | |||
@@ -1,8 +1,8 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | 2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> |
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | 3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> |
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 Material = require("js/lib/rdge/materials/material").Material; | 7 | var Material = require("js/lib/rdge/materials/material").Material; |
8 | var Texture = require("js/lib/rdge/texture").Texture; | 8 | var Texture = require("js/lib/rdge/texture").Texture; |
@@ -13,243 +13,185 @@ var Texture = require("js/lib/rdge/texture").Texture; | |||
13 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
14 | var TaperMaterial = function TaperMaterial() | 14 | var TaperMaterial = function TaperMaterial() |
15 | { | 15 | { |
16 | // initialize the inherited members | 16 | // initialize the inherited members |
17 | this.inheritedFrom = Material; | 17 | this.inheritedFrom = Material; |
18 | this.inheritedFrom(); | 18 | this.inheritedFrom(); |
19 | 19 | ||
20 | /////////////////////////////////////////////////////////////////////// | 20 | /////////////////////////////////////////////////////////////////////// |
21 | // Instance variables | 21 | // Instance variables |
22 | /////////////////////////////////////////////////////////////////////// | 22 | /////////////////////////////////////////////////////////////////////// |
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]; | 26 | this._color = [1, 0, 0, 1]; |
27 | 27 | ||
28 | this._deltaTime = 0.0; | 28 | this._deltaTime = 0.0; |
29 | 29 | ||
30 | /////////////////////////////////////////////////////////////////////// | 30 | /////////////////////////////////////////////////////////////////////// |
31 | // Property Accessors | 31 | // Property Accessors |
32 | /////////////////////////////////////////////////////////////////////// | 32 | /////////////////////////////////////////////////////////////////////// |
33 | this.getColor = function() { return this._color; } | 33 | this.getColor = function () { return this._color; }; |
34 | this.getShaderName = function() { return this._shaderName; } | 34 | this.getShaderName = function () { return this._shaderName; }; |
35 | 35 | ||
36 | this.isAnimated = function() { return true; } | 36 | this.isAnimated = function () { return true; }; |
37 | this.hasVertexDeformation = function() { return this._hasVertexDeformation; } | 37 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; |
38 | this._hasVertexDeformation = true; | 38 | this._hasVertexDeformation = true; |
39 | this._vertexDeformationTolerance = 0.02; // should be a property | 39 | this._vertexDeformationTolerance = 0.02; // should be a property |
40 | 40 | ||
41 | /////////////////////////////////////////////////////////////////////// | 41 | /////////////////////////////////////////////////////////////////////// |
42 | // Methods | 42 | // Methods |
43 | /////////////////////////////////////////////////////////////////////// | 43 | /////////////////////////////////////////////////////////////////////// |
44 | // duplcate method requirde | 44 | // duplcate method requirde |
45 | this.dup = function() { return new TaperMaterial(); } | 45 | this.dup = function () { return new TaperMaterial(); }; |
46 | 46 | ||
47 | this.init = function( world ) | 47 | this.init = function (world) { |
48 | { | 48 | this.setWorld(world); |
49 | this.setWorld( world ); | 49 | |
50 | 50 | // set up the shader | |
51 | // set up the shader | 51 | this._shader = new RDGE.jshader(); |
52 | this._shader = new jshader(); | 52 | this._shader.def = taperShaderDef; |
53 | this._shader.def = taperShaderDef; | 53 | this._shader.init(); |
54 | this._shader.init(); | 54 | |
55 | 55 | // set the defaults | |
56 | // set the defaults | 56 | this._shader.colorMe.color.set(this.getColor()); |
57 | this._shader.colorMe.color.set( this.getColor() ); | 57 | |
58 | 58 | // set up the material node | |
59 | // set up the material node | 59 | this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); |
60 | this._materialNode = createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); | 60 | this._materialNode.setShader(this._shader); |
61 | this._materialNode.setShader(this._shader); | 61 | |
62 | 62 | // initialize the taper properties | |
63 | // initialize the taper properties | 63 | this.updateShaderValues(); |
64 | this.updateShaderValues(); | 64 | }; |
65 | } | 65 | |
66 | 66 | ||
67 | 67 | /////////////////////////////////////////////////////////////////////// | |
68 | /////////////////////////////////////////////////////////////////////// | 68 | // Material Property Accessors |
69 | // Material Property Accessors | 69 | /////////////////////////////////////////////////////////////////////// |
70 | /////////////////////////////////////////////////////////////////////// | 70 | this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount"]; |
71 | this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount" ]; | 71 | this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"]; |
72 | this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"]; | 72 | this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"]; |
73 | this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"]; | 73 | this._propValues = []; |
74 | this._propValues = []; | 74 | |
75 | 75 | // initialize the property values | |
76 | // initialize the property values | 76 | this._propValues[this._propNames[0]] = this._color.slice(); |
77 | this._propValues[ this._propNames[0] ] = this._color.slice(); | 77 | this._propValues[this._propNames[1]] = 0.25; |
78 | this._propValues[ this._propNames[1] ] = 0.25; | 78 | this._propValues[this._propNames[2]] = 0.50; |
79 | this._propValues[ this._propNames[2] ] = 0.50; | 79 | this._propValues[this._propNames[3]] = 0.75; |
80 | this._propValues[ this._propNames[3] ] = 0.75; | 80 | this._propValues[this._propNames[4]] = -1; |
81 | this._propValues[ this._propNames[4] ] = -1; | 81 | this._propValues[this._propNames[5]] = 1; |
82 | this._propValues[ this._propNames[5] ] = 1; | 82 | this._propValues[this._propNames[6]] = 0.0; |
83 | this._propValues[ this._propNames[6] ] = 0.0; | 83 | this._propValues[this._propNames[7]] = 0.9; |
84 | this._propValues[ this._propNames[7] ] = 0.9; | 84 | |
85 | 85 | this.setProperty = function (prop, value) { | |
86 | this.setProperty = function( prop, value ) | 86 | // make sure we have legitimate input |
87 | { | 87 | if (this.validateProperty(prop, value)) { |
88 | // make sure we have legitimate input | 88 | switch (prop) { |
89 | if (this.validateProperty( prop, value )) | 89 | case "color": this._propValues[prop] = value.slice(); break; |
90 | default: this._propValues[prop] = value; break; | ||
91 | } | ||
92 | |||
93 | this.updateShaderValues(); | ||
94 | } | ||
95 | }; | ||
96 | /////////////////////////////////////////////////////////////////////// | ||
97 | this.exportJSON = function () { | ||
98 | var jObj = | ||
90 | { | 99 | { |
91 | switch (prop) | 100 | 'material': this.getShaderName(), |
92 | { | 101 | 'name': this.getName(), |
93 | case "color": this._propValues[prop] = value.slice(); break; | 102 | 'color': this._propValues["color"] |
94 | default: this._propValues[prop] = value; break; | ||
95 | } | ||
96 | |||
97 | this.updateShaderValues(); | ||
98 | } | ||
99 | } | ||
100 | /////////////////////////////////////////////////////////////////////// | ||
101 | this.exportJSON = function() | ||
102 | { | ||
103 | var jObj = | ||
104 | { | ||
105 | 'material' : this.getShaderName(), | ||
106 | 'name' : this.getName(), | ||
107 | 'color' : this._propValues["color"] | ||
108 | }; | 103 | }; |
109 | 104 | ||
110 | return jObj; | 105 | return jObj; |
111 | } | 106 | }; |
112 | 107 | ||
113 | this.importJSON = function( jObj ) | 108 | this.importJSON = function (jObj) { |
114 | { | 109 | if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); |
115 | if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); | 110 | this.setName(jObj.name); |
116 | this.setName( jObj.name ); | 111 | |
117 | 112 | try { | |
118 | try | 113 | var color = jObj.color; |
119 | { | 114 | this.setProperty("color", color); |
120 | var color = jObj.color; | 115 | } |
121 | this.setProperty( "color", color); | 116 | catch (e) { |
122 | } | 117 | throw new Error("could not import material: " + jObj); |
123 | catch (e) | 118 | } |
124 | { | 119 | }; |
125 | throw new Error( "could not import material: " + jObj ); | 120 | |
126 | } | 121 | this.update = function (time) { |
127 | } | 122 | //var speed = 0.01; |
128 | 123 | //time *= speed; | |
129 | this.export = function() | 124 | this._deltaTime += 0.01; |
130 | { | 125 | |
131 | // this function should be overridden by subclasses | 126 | if (this._shader && this._shader.colorMe) { |
132 | var exportStr = "material: " + this.getShaderName() + "\n"; | 127 | var t3 = this._propValues[this._propNames[3]] - this._deltaTime; |
133 | exportStr += "name: " + this.getName() + "\n"; | 128 | if (t3 < 0) { |
134 | 129 | this._deltaTime = this._propValues[this._propNames[1]] - 1.0; | |
135 | if (this._shader) | 130 | t3 = this._propValues[this._propNames[3]] - this._deltaTime; |
136 | exportStr += "color: " + this._shader.colorMe.color + "\n"; | 131 | } |
137 | else | 132 | var t1 = this._propValues[this._propNames[1]] - this._deltaTime, |
138 | exportStr += "color: " + this.getColor() + "\n"; | 133 | t2 = this._propValues[this._propNames[2]] - this._deltaTime; |
139 | exportStr += "endMaterial\n"; | 134 | |
140 | 135 | ||
141 | return exportStr; | 136 | this._shader.colorMe[this._propNames[1]].set([t1]); |
142 | } | 137 | this._shader.colorMe[thi |