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.js448
1 files changed, 266 insertions, 182 deletions
</
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 54e5168f..cc232444 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -4,173 +4,256 @@ 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._glTex0;
28 this._angle = 0.0; 30 this._glTex1;
29 this._deltaTime = 0.01; 31
30 32 this._angle = 0.0;
31 /////////////////////////////////////////////////////////////////////// 33 this._deltaTime = 0.01;
32 // Property Accessors 34 this._speed = 1.0;
33 /////////////////////////////////////////////////////////////////////// 35
34 this.getColor = function () { return this._color; }; 36 ///////////////////////////////////////////////////////////////////////
35 this.getShaderName = function () { return this._shaderName; }; 37 // Property Accessors
36 38 ///////////////////////////////////////////////////////////////////////
37 this.isAnimated = function () { return true; }; 39 this.getShaderName = function () { return this._shaderName; };
38 this.hasVertexDeformation = function () { return this._hasVertexDeformation; }; 40
39 this._hasVertexDeformation = true; 41 this.isAnimated = function () { return true; };
40 this._vertexDeformationTolerance = 0.02; // should be a property 42
41 43 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
42 /////////////////////////////////////////////////////////////////////// 44 this._hasVertexDeformation = true;
43 // Methods 45 this._vertexDeformationTolerance = 0.02; // should be a property
44 /////////////////////////////////////////////////////////////////////// 46
45 // duplcate method requirde 47 ///////////////////////////////////////////////////////////////////////
46 this.dup = function () { return new TwistVertMaterial(); }; 48 // Methods
47 49 ///////////////////////////////////////////////////////////////////////
48 this.init = function (world) { 50 // duplcate method requirde
49 this.setWorld(world); 51 this.dup = function() {
50 52 // get the current values;
51 // set up the shader 53 var propNames = [], propValues = [], propTypes = [], propLabels = [];
52 this._shader = new RDGE.jshader(); 54 this.getAllProperties(propNames, propValues, propTypes, propLabels);
53 this._shader.def = twistVertShaderDef; 55
54 this._shader.init(); 56 // allocate a new material
55 57 var newMat = new TwistVertMaterial();
56 // set the defaults 58
57 this._shader.twistMe.color.set(this.getColor()); 59 // copy over the current values;
58 60 var n = propNames.length;
59 // set up the material node 61 for (var i = 0; i < n; i++)
60 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID()); 62 newMat.setProperty(propNames[i], propValues[i]);
61 this._materialNode.setShader(this._shader); 63
62 64 return newMat;
63 // initialize the twist vert properties 65 };
64 this.updateShaderValues(); 66
65 }; 67 this.init = function (world)
66 68 {
67 69 this.setWorld(world);
68 /////////////////////////////////////////////////////////////////////// 70
69 // Material Property Accessors 71 // set up the shader
70 /////////////////////////////////////////////////////////////////////// 72 this._shader = new RDGE.jshader();
71 this._propNames = ["color", "u_limit1", "u_limit2", "u_center", "u_twistAmount", "u_tex0", "u_tex1"]; 73 this._shader.def = twistVertShaderDef;
72 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Center", "Twist Amount", "Front facing texture map", "Back facing texture map"]; 74 this._shader.init();
73 this._propTypes = ["color", "float", "float", "float", "float", "file", "file"]; 75
74 this._propValues = []; 76 // set up the material node
75 77 this._materialNode = RDGE.createMaterialNode("twistVertMaterial" + "_" + world.generateUniqueNodeID());
76 // initialize the property values 78 this._materialNode.setShader(this._shader);
77 this._propValues[this._propNames[0]] = this._color.slice(); 79
78 this._propValues[this._propNames[1]] = 0.25; 80 // set up the texture maps
79 this._propValues[this._propNames[2]] = 0.75; 81 this.updateTextures();
80 this._propValues[this._propNames[3]] = 0.0; 82
81 this._propValues[this._propNames[4]] = 2.0 * Math.PI; 83 // initialize the twist vert properties
82 this._propValues[this._propNames[5]] = this._tex0.slice(); 84 this.updateShaderValues();
83 this._propValues[this._propNames[6]] = this._tex1.slice(); 85 };
84 86
85 this.setProperty = function (prop, value) { 87
86 // make sure we have legitimate input 88 ///////////////////////////////////////////////////////////////////////
87 if (this.validateProperty(prop, value)) { 89 // Material Property Accessors
88 switch (prop) { 90 ///////////////////////////////////////////////////////////////////////
89 case "color": 91 this._propNames = [ "u_limit1", "u_limit2", "u_twistAmount", "speed", "u_tex0", "u_tex1"];
90 case "u_tex1": 92 this._propLabels = [ "Start Parameter", "End Paramater", "Twist Amount", "Speed", "Front facing texture map", "Back facing texture map"];
91 case "u_tex0": this._propValues[prop] = value.slice(); break; 93 this._propTypes = [ "float", "float", "angle", "float", "file", "file"];
92 default: this._propValues[prop] = value; break; 94 this._propValues = [];
93 } 95
94 96 // initialize the property values
95 this.updateShaderValues(); 97 this._propValues[this._propNames[0]] = 0.0;
96 } 98 this._propValues[this._propNames[1]] = 1.0;
97 }; 99 this._propValues[this._propNames[2]] = 2.0 * Math.PI;
98 /////////////////////////////////////////////////////////////////////// 100 this._propValues[this._propNames[3]] = this._speed;
99 101 this._propValues[this._propNames[4]] = this._tex0.slice();
100 this.exportJSON = function () { 102 this._propValues[this._propNames[5]] = this._tex1.slice();
101 var jObj = 103
104 this.setProperty = function (prop, value)
105 {
106 // make sure we have legitimate input
107 if (this.validateProperty(prop, value))
102 { 108 {
103 'material': this.getShaderName(), 109 switch (prop) {
104 'name': this.getName(), 110 case "u_tex1":
105 'color': this._propValues["color"] 111 case "u_tex0": this._propValues[prop] = value ? value.slice() : null;
106 }; 112 this.updateTextures();
107 113 break;
108 return jObj; 114
109 }; 115 default:
110 116 this._propValues[prop] = value;
111 this.importJSON = function (jObj) { 117 break;
112 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material"); 118 }
113 this.setName(jObj.name); 119
114 120 this.updateShaderValues();
115 try { 121 }
116 var color = jObj.color; 122 };
117 this.setProperty("color", color); 123 ///////////////////////////////////////////////////////////////////////
118 } 124
119 catch (e) { 125 this.exportJSON = function () {
120 throw new Error("could not import material: " + importStr); 126 var jObj =
121 } 127 {
122 }; 128 'material' : this.getShaderName(),
123 129 'name' : this.getName(),
124 this.update = function (time) { 130
125 if (this._shader && this._shader.twistMe) { 131 'tex0' : this._propValues[this._propNames[4]],
126 var angle = this._angle; 132 'tex1' : this._propValues[this._propNames[5]],
127 angle += this._deltaTime; 133
128 if (angle > this._propValues["u_twistAmount"]) { 134 'speed' : this._propValues[this._propNames[3]],
129 angle = this._propValues["u_twistAmount"]; 135
130 this._deltaTime = -this._deltaTime; 136 'limit1' : this._propValues[this._propNames[0]],
131 } 137 'limit2' : this._propValues[this._propNames[1]],
132 else if (angle < 0.0) { 138 'angle' : this._propValues[this._propNames[2]]
133 angle = 0; 139 }
134 this._deltaTime = -this._deltaTime; 140
135 } 141 return jObj;