aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/twist-vert-material.js
diff options
context:
space:
mode:
authorEric Guzman2012-04-05 18:42:40 -0700
committerEric Guzman2012-04-05 18:42:40 -0700
commit8ff9dde2053e41d85bb27d9c91808a30e551a138 (patch)
tree8eec67d632d82d3052ed470096eda13fd50a55c8 /js/lib/rdge/materials/twist-vert-material.js
parent4631d54ffb4942378835689e9f5d70ed95610822 (diff)
parent7656b6eac7aec59697c6cddbe2a507fe9e4aa187 (diff)
downloadninja-8ff9dde2053e41d85bb27d9c91808a30e551a138.tar.gz
Merge branch 'refs/heads/master' into CSSPanelUpdates
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, 193 insertions, 255 deletions
<
diff --git a/js/lib/rdge/materials/twist-vert-material.js b/js/lib/rdge/materials/twist-vert-material.js
index 2d2cdcc5..54e5168f 100644
--- a/js/lib/rdge/materials/twist-vert-material.js
+++ b/js/lib/rdge/materials/twist-vert-material.js
@@ -1,278 +1,216 @@
1/* <copyright> 1/* <copyright>
2 This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2This 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/> 3No 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
7var MaterialParser = require("js/lib/rdge/materials/material-parser").MaterialParser; 7var 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///////////////////////////////////////////////////////////////////////
12function TwistVertMaterial() 12function 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.exportJSON = function()
106 {
107 var jObj =
108 { 102 {
109 'material' : this.getShaderName(), 103 'material': this.getShaderName(),
110 'name' : this.getName(), 104 'name': this.getName(),
111 'color' : this._propValues["color"] 105 'color': this._propValues["color"]
112 }; 106 };
113 107
114 return jObj; 108 return jObj;
115 } 109 };
116 110
117 this.importJSON = function( jObj ) 111 this.importJSON = function (jObj) {
118 { 112 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
119 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); 113 this.setName(jObj.name);
120 this.setName( jObj.name ); 114
121 115 try {
122 try 116 var color = jObj.color;
123 { 117 this.setProperty("color", color);
124 var color = jObj.color; 118 }
125 this.setProperty( "color", color); 119 catch (e) {
126 } 120 throw new Error("could not import material: " + importStr);
127 catch (e) 121 }
128 { 122 };
129 throw new Error( "could not import material: " + importStr ); 123
130 } 124 this.update = function (time) {
131 } 125 if (this._shader && this._shader.twistMe) {
132 126 var angle = this._angle;
133 this.export = function() 127