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