aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/taper-material.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/rdge/materials/taper-material.js')
-rw-r--r--js/lib/rdge/materials/taper-material.js401
1 files changed, 171 insertions, 230 deletions
diff --git a/js/lib/rdge/materials/taper-material.js b/js/lib/rdge/materials/taper-material.js
index 15b7b2b0..356087d6 100644
--- a/js/lib/rdge/materials/taper-material.js
+++ b/js/lib/rdge/materials/taper-material.js
@@ -1,252 +1,193 @@
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 TaperMaterial() 12function TaperMaterial() {
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 = "TaperMaterial";
21 this._name = "TaperMaterial"; 21 this._shaderName = "taper";
22 this._shaderName = "taper"; 22
23 23 this._color = [1, 0, 0, 1];
24 this._color = [1,0,0,1]; 24
25 25 this._deltaTime = 0.0;
26 this._deltaTime = 0.0; 26
27 27 ///////////////////////////////////////////////////////////////////////
28 /////////////////////////////////////////////////////////////////////// 28 // Property Accessors
29 // Property Accessors 29 ///////////////////////////////////////////////////////////////////////
30 /////////////////////////////////////////////////////////////////////// 30 this.getColor = function () { return this._color; };
31 this.getColor = function() { return this._color; } 31 this.getShaderName = function () { return this._shaderName; };
32 this.getShaderName = function() { return this._shaderName; } 32
33 33 this.isAnimated = function () { return true; };
34 this.isAnimated = function() { return true; } 34 this.hasVertexDeformation = function () { return this._hasVertexDeformation; };
35 this.hasVertexDeformation = function() { return this._hasVertexDeformation; } 35 this._hasVertexDeformation = true;
36 this._hasVertexDeformation = true; 36 this._vertexDeformationTolerance = 0.02; // should be a property
37 this._vertexDeformationTolerance = 0.02; // should be a property 37
38 38 ///////////////////////////////////////////////////////////////////////
39 /////////////////////////////////////////////////////////////////////// 39 // Methods
40 // Methods 40 ///////////////////////////////////////////////////////////////////////
41 /////////////////////////////////////////////////////////////////////// 41 // duplcate method requirde
42 // duplcate method requirde 42 this.dup = function () { return new TaperMaterial(); };
43 this.dup = function() { return new TaperMaterial(); } 43
44 44 this.init = function (world) {
45 this.init = function( world ) 45 this.setWorld(world);
46 { 46
47 this.setWorld( world ); 47 // set up the shader
48 48 this._shader = new RDGE.jshader();
49 // set up the shader 49 this._shader.def = taperShaderDef;
50 this._shader = new jshader(); 50 this._shader.init();
51 this._shader.def = taperShaderDef; 51
52 this._shader.init(); 52 // set the defaults
53 53 this._shader.colorMe.color.set(this.getColor());
54 // set the defaults 54
55 this._shader.colorMe.color.set( this.getColor() ); 55 // set up the material node
56 56 this._materialNode = RDGE.createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID());
57 // set up the material node 57 this._materialNode.setShader(this._shader);
58 this._materialNode = createMaterialNode("taperMaterial" + "_" + world.generateUniqueNodeID()); 58
59 this._materialNode.setShader(this._shader); 59 // initialize the taper properties
60 60 this.updateShaderValues();
61 // initialize the taper properties 61 };
62 this.updateShaderValues(); 62
63 } 63
64 64 ///////////////////////////////////////////////////////////////////////
65 65 // Material Property Accessors
66 /////////////////////////////////////////////////////////////////////// 66 ///////////////////////////////////////////////////////////////////////
67 // Material Property Accessors 67 this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount"];
68 /////////////////////////////////////////////////////////////////////// 68 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"];
69 this._propNames = ["color", "u_limit1", "u_limit2", "u_limit3", "u_minVal", "u_maxVal", "u_center", "u_taperAmount" ]; 69 this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"];
70 this._propLabels = ["Color", "Minimum Parameter Value", "Center Paramater Value", "Maximum Parameter Value", "Minimum Data Bounds", "Maximum Data Bounds", "Center", "Taper Amount"]; 70 this._propValues = [];
71 this._propTypes = ["color", "float", "float", "float", "float", "float", "float", "float"]; 71
72 this._propValues = []; 72 // initialize the property values
73 73 this._propValues[this._propNames[0]] = this._color.slice();
74 // initialize the property values 74 this._propValues[this._propNames[1]] = 0.25;
75 this._propValues[ this._propNames[0] ] = this._color.slice(); 75 this._propValues[this._propNames[2]] = 0.50;
76 this._propValues[ this._propNames[1] ] = 0.25; 76 this._propValues[this._propNames[3]] = 0.75;
77 this._propValues[ this._propNames[2] ] = 0.50; 77 this._propValues[this._propNames[4]] = -1;
78 this._propValues[ this._propNames[3] ] = 0.75; 78 this._propValues[this._propNames[5]] = 1;
79 this._propValues[ this._propNames[4] ] = -1; 79 this._propValues[this._propNames[6]] = 0.0;
80 this._propValues[ this._propNames[5] ] = 1; 80 this._propValues[this._propNames[7]] = 0.9;
81 this._propValues[ this._propNames[6] ] = 0.0; 81
82 this._propValues[ this._propNames[7] ] = 0.9; 82 this.setProperty = function (prop, value) {
83 83 // make sure we have legitimate input
84 this.setProperty = function( prop, value ) 84 if (this.validateProperty(prop, value)) {
85 { 85 switch (prop) {
86 // make sure we have legitimate input 86 case "color": this._propValues[prop] = value.slice(); break;
87 if (this.validateProperty( prop, value )) 87 default: this._propValues[prop] = value; break;
88 }
89
90 this.updateShaderValues();
91 }
92 };
93 ///////////////////////////////////////////////////////////////////////
94 this.exportJSON = function () {
95 var jObj =
88 { 96 {
89 switch (prop) 97 'material': this.getShaderName(),
90 { 98 'name': this.getName(),
91 case "color": this._propValues[prop] = value.slice(); break; 99 'color': this._propValues["color"]
92 default: this._propValues[prop] = value; break;
93 }
94
95 this.updateShaderValues();
96 }
97 }
98 ///////////////////////////////////////////////////////////////////////
99 this.exportJSON = function()
100 {
101 var jObj =
102 {
103 'material' : this.getShaderName(),
104 'name' : this.getName(),
105 'color' : this._propValues["color"]
106 }; 100 };
107 101
108 return jObj; 102 return jObj;
109 } 103 };
110 104
111 this.importJSON = function( jObj ) 105 this.importJSON = function (jObj) {
112 { 106 if (this.getShaderName() != jObj.material) throw new Error("ill-formed material");
113 if (this.getShaderName() != jObj.material) throw new Error( "ill-formed material" ); 107 this.setName(jObj.name);
114 this.setName( jObj.name ); 108
115 109 try {
116 try 110 var color = jObj.color;
117 { 111 this.setProperty("color", color);
118 var color = jObj.color; 112 }
119 this.setProperty( "color", color); 113 catch (e) {
120 } 114 throw new Error("could not import material: " + jObj);
121 catch (e) 115 }
122 { 116 };
123 throw new Error( "could not import material: " + jObj ); 117
124 } 118 this.update = function (time) {
125 } 119 //var speed = 0.01;
126 120 //time *= speed;
127 this.export = function() 121 this._deltaTime += 0.01;
128 { 122
129 // this function should be overridden by subclasses 123 if (this._shader && this._shader.colorMe) {
130 var exportStr = "material: " + this.getShaderName() + "\n"; 124 var t3 = this._propValues[this._propNames[3]] - this._deltaTime;
131 exportStr += "name: " + this.getName() + "\n"; 125 if (t3 < 0) {
132 126 this._deltaTime = this._propValues[this._propNames[1]] - 1.0;
133 if (this._shader) 127 t3 = this._propValues[this._propNames[3]] - this._deltaTime;
134 exportStr += "color: " + this._shader.colorMe.color + "\n"; 128 }
135 else 129 var t1 = this._propValues[this._propNames[1]] - this._deltaTime,
136 exportStr += "color: " + this.getColor() + "\n"; 130 t2 = this._propValues[this._propNames[2]] - this._deltaTime;
137 exportStr += "endMaterial\n"; 131
138 132
139 return exportStr;