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