diff options
Diffstat (limited to 'js/lib/rdge/materials/twist-vert-material.js')
-rw-r--r-- | js/lib/rdge/materials/twist-vert-material.js | 424 |
1 files changed, 195 insertions, 229 deletions
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js index 05172a1b..54e5168f 100644 --- a/js/lib/rdge/materials/twist-vert-material.js +++ b/js/lib/rdge/materials/twist-vert-material.js | |||
@@ -1,250 +1,216 @@ | |||
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 TwistVertMaterial() | 12 | function TwistVertMaterial() { |
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 = "TwistVertMaterial"; |
21 | this._name = "TwistVertMaterial"; | 21 | this._shaderName = "twistVert"; |
22 | this._shaderName = "twistVert"; | 22 | |
23 | 23 | this._color = [1, 0, 0, 1]; | |
24 | this._color = [1,0,0,1]; | 24 | |
25 | 25 | this._tex0 = 'assets/images/rocky-normal.jpg'; | |
26 | this._tex0 = 'assets/images/rocky-normal.jpg'; | 26 | this._tex1 = 'assets/images/metal.png'; |
27 | this._tex1 = 'assets/images/metal.png'; | 27 | |
28 | 28 | this._angle = 0.0; | |
29 | this._angle = 0.0; | 29 | this._deltaTime = 0.01; |
30 | this._deltaTime = 0.01; | 30 | |
31 | 31 | /////////////////////////////////////////////////////////////////////// | |
32 | /////////////////////////////////////////////////////////////////////// | 32 | // Property Accessors |
33 | // Property Accessors | 33 | /////////////////////////////////////////////////////////////////////// |
34 | /////////////////////////////////////////////////////////////////////// | 34 | this.getColor = function () { return this._color; }; |
35 | this.getColor = function() { return this._color; } | 35 | this.getShaderName = function () { return this._shaderName; }; |
36 | this.getShaderName = function() { return this._shaderName; } | 36 | |
37 | 37 | this.isAnimated = function () { return true; }; | |
38 | this.isAnimated = function() { return true; } | 38 | this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; |
39 | this.hasVertexDeformation = function() { return this._hasVertexDeformation; } | 39 | this._hasVertexDeformation = true; |
40 | this._hasVertexDeformation = true; | 40 | this._vertexDeformationTolerance = 0.02; // should be a property |
41 | this._vertexDeformationTolerance = 0.02; // should be a property | 41 | |
42 | 42 | /////////////////////////////////////////////////////////////////////// | |
43 | /////////////////////////////////////////////////////////////////////// | 43 | // Methods |
44 | // Methods | 44 | /////////////////////////////////////////////////////////////////////// |
45 | /////////////////////////////////////////////////////////////////////// | 45 | // duplcate method requirde |
46 | // duplcate method requirde | 46 | this.dup = function () { return new TwistVertMaterial(); }; |
47 | this.dup = function() { return new TwistVertMaterial(); } | 47 | |
48 | 48 | this.init = function (world) { | |
49 | this.init = function( world ) | 49 | this.setWorld(world); |
50 | { | 50 | |
51 | this.setWorld( world ); | 51 | // set up the shader |
52 | 52 | this._shader = new RDGE.jshader(); | |
53 | // set up the shader | 53 | this._shader.def = twistVertShaderDef; |
54 | this._shader = new jshader(); | 54 | this._shader.init(); |
55 | this._shader.def = twistVertShaderDef; | 55 | |
56 | this._shader.init(); | 56 | // set the defaults |
57 | 57 | this._shader.twistMe.color.set(this.getColor()); | |
58 | // set the defaults | 58 | |
59 | this._shader.twistMe.color.set( this.getColor() ); | 59 | // set up the material node |
60 | 60 | this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); | |
61 | // set up the material node | 61 | this._materialNode.setShader(this._shader); |
62 | this._materialNode = createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); | 62 | |
63 | this._materialNode.setShader(this._shader); | 63 | // initialize the twist vert properties |
64 | 64 | this.updateShaderValues(); | |
65 | // initialize the twist vert properties | 65 | }; |
66 | this.updateShaderValues(); | 66 | |
67 | } | 67 | |
68 | 68 | /////////////////////////////////////////////////////////////////////// | |
69 | 69 | // Material Property Accessors | |
70 | /////////////////////////////////////////////////////////////////////// | 70 | /////////////////////////////////////////////////////////////////////// |
71 | // Material Property Accessors | 71 | this._propNames = ["color", "u_limit1", "u_limit2", "u_center", "u_twistAmount", "u_tex0", "u_tex1"]; |
72 | /////////////////////////////////////////////////////////////////////// | 72 | this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Center", "Twist Amount", "Front facing texture map", "Back facing texture map"]; |
73 | this._propNames = ["color", "u_limit1", "u_limit2", "u_center", "u_twistAmount", "u_tex0", "u_tex1" ]; | 73 | this._propTypes = ["color", "float", "float", "float", "float", "file", "file"]; |
74 | this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Center", "Twist Amount", "Front facing texture map", "Back facing texture map"]; | 74 | this._propValues = []; |
75 | this._propTypes = ["color", "float", "float", "float", "float", "file", "file"]; | 75 | |
76 | this._propValues = []; | 76 | // initialize the property values |
77 | 77 | this._propValues[this._propNames[0]] = this._color.slice(); | |
78 | // initialize the property values | 78 | this._propValues[this._propNames[1]] = 0.25; |
79 | this._propValues[ this._propNames[0] ] = this._color.slice(); | 79 | this._propValues[this._propNames[2]] = 0.75; |
80 | this._propValues[ this._propNames[1] ] = 0.25; | 80 | this._propValues[this._propNames[3]] = 0.0; |
81 | this._propValues[ this._propNames[2] ] = 0.75; | 81 | this._propValues[this._propNames[4]] = 2.0 * Math.PI; |
82 | this._propValues[ this._propNames[3] ] = 0.0; | 82 | this._propValues[this._propNames[5]] = this._tex0.slice(); |
83 | this._propValues[ this._propNames[4] ] = 2.0*Math.PI; | 83 | this._propValues[this._propNames[6]] = this._tex1.slice(); |
84 | this._propValues[ this._propNames[5] ] = this._tex0.slice(); | 84 | |
85 | this._propValues[ this._propNames[6] ] = this._tex1.slice(); | 85 | this.setProperty = function (prop, value) { |
86 | 86 | // make sure we have legitimate input | |
87 | this.setProperty = function( prop, value ) | 87 | if (this.validateProperty(prop, value)) { |
88 | { | 88 | switch (prop) { |
89 | // make sure we have legitimate input | 89 | case "color": |
90 | if (this.validateProperty( prop, value )) | 90 | case "u_tex1": |
91 | { | 91 | case "u_tex0": this._propValues[prop] = value.slice(); break; |
92 | switch (prop) | 92 | default: this._propValues[prop] = value; break; |
93 | { | 93 | } |
94 | case "color": | 94 | |
95 | case "u_tex1": | 95 | this.updateShaderValues(); |
96 | case "u_tex0": this._propValues[prop] = value.slice(); break; | 96 | } |
97 | default: this._propValues[prop] = value; break; | 97 | }; |
98 | } | 98 | /////////////////////////////////////////////////////////////////////// |
99 | 99 | ||
100 | this.updateShaderValues(); | 100 | this.exportJSON = function () { |
101 | } | 101 | var jObj = |
102 | } | ||
103 | /////////////////////////////////////////////////////////////////////// | ||
104 | |||
105 | this.export = function() | ||
106 | { | ||
107 | // this function should be overridden by subclasses | ||
108 | var exportStr = "material: " + this.getShaderName() + "\n"; | ||
109 | exportStr += "name: " + this.getName() + "\n"; | ||
110 | |||
111 | if (this._shader) | ||
112 | exportStr += "color: " + String(this._shader.twistMe.color) + "\n"; | ||
113 | else | ||
114 | exportStr += "color: " + this.getColor() + "\n"; | ||
115 | exportStr += "endMaterial\n"; | ||
116 | |||
117 | return exportStr; | ||
118 | } | ||
119 | |||
120 | this.import = function( importStr ) | ||
121 | { | ||
122 | var pu = new MaterialParser( importStr ); | ||
123 | var material = pu.nextValue( "material: " ); | ||
124 | if (material != this.getShaderName()) throw new Error( "ill-formed material" ); | ||
125 | this.setName( pu.nextValue( "name: ") ); | ||
126 | |||
127 | var rtnStr; | ||
128 | try | ||
129 | { | ||
130 | var color = eval( "[" + pu.nextValue( "color: " ) + "]" ); | ||
131 | |||
132 | this.setProperty( "color", color); | ||
133 | |||
134 | var endKey = "endMaterial\n"; | ||
135 | var index = importStr.indexOf( endKey ); | ||
136 | index += endKey.length; | ||
137 | rtnStr = importStr.substr( index ); | ||
138 | } | ||
139 | catch (e) | ||
140 | { | ||
141 | throw new Error( "could not import material: " + importStr ); | ||
142 | } | ||
143 | |||
144 | return rtnStr; | ||
145 | } | ||
146 | |||
147 | this.update = function( time ) | ||
148 | { | ||
149 | if (this._shader && this._shader.twistMe) | ||
150 | { | 102 | { |
151 | var angle = this._angle; | 103 | 'material': this.getShaderName(), |
152 | angle += this._deltaTime; | 104 | 'name': this.getName(), |
153 |