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