aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/RDGE/GLMaterial.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes/RDGE/GLMaterial.js')
-rwxr-xr-xjs/helper-classes/RDGE/GLMaterial.js308
1 files changed, 0 insertions, 308 deletions
diff --git a/js/helper-classes/RDGE/GLMaterial.js b/js/helper-classes/RDGE/GLMaterial.js
deleted file mode 100755
index 642fab05..00000000
--- a/js/helper-classes/RDGE/GLMaterial.js
+++ /dev/null
@@ -1,308 +0,0 @@
1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<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.
5</copyright> */
6
7///////////////////////////////////////////////////////////////////////
8// Class GLMaterial
9// GL representation of a material.
10///////////////////////////////////////////////////////////////////////
11function GLMaterial( world )
12{
13 ///////////////////////////////////////////////////////////////////////
14 // Instance variables
15 ///////////////////////////////////////////////////////////////////////
16 this._name = "GLMaterial";
17 this._shaderName = "undefined";
18
19 // keep a reference to the owning GLWorld
20 this._world = null;
21 if(world)
22 {
23 this._world = world;
24 }
25
26 this._shininess = 60;
27
28 this._ambient = [0.0, 0.0, 0.0, 1.0];
29 this._diffuse = [0.0, 0.0, 0.0, 1.0];
30 this._specular = [0.0, 0.0, 0.0, 1.0];
31
32 this._texture;
33
34 // vertex deformation variables
35 this._hasVertexDeformation = false;
36 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
37 this._vertexDeformationTolerance = 0.1;
38
39 // RDGE variables
40 this._shader;
41 this._materialNode;
42
43 ///////////////////////////////////////////////////////////////////////
44 // Property Accessors
45 ///////////////////////////////////////////////////////////////////////
46 this.getShininess = function() { return this._shininess; }
47 this.setShininess = function(s) { this._shininess = s; }
48
49 this.setName = function(n) { this._name = n; }
50 this.getName = function() { return this._name; }
51
52 this.setShaderName = function(n) { this._shaderName = n; }
53 this.getShaderName = function() { return this._shaderName; }
54
55 this.setWorld = function(world) { this._world = world; }
56 this.getWorld = function() { return this._world; }
57
58 this.setAmbient = function(r, g, b, a) { this._ambient = [r, g, b, a]; }
59 this.getAmbient = function() { return [this._ambient[0], this._ambient[1], this._ambient[2], this._ambient[3]]; }
60
61 this.setDiffuse = function(r, g, b, a) { this._diffuse = [r, g, b, a]; }
62 this.getDiffuse = function() { return [this._diffuse[0], this._diffuse[1], this._diffuse[2], this._diffuse[3]]; }
63
64 this.setSpecular = function(r, g, b, a) { this._specular = [r, g, b, a]; }
65 this.getSpecular = function() { return [this._specular[0], this._specular[1], this._specular[2], this._specular[3]]; }
66
67 this.getShader = function() { return this._shader; }
68 this.getMaterialNode = function() { return this._materialNode; }
69
70 // a material can be animated or not. default is not.
71 // Any material needing continuous rendering should override this method
72 this.isAnimated = function() { return false; }
73
74 // the vertex shader can apply deformations requiring refinement in
75 // certain areas.
76 this.hasVertexDeformation = function() { return this._hasVertexDeformation; }
77 this.getVertexDeformationRange = function() { return this._vertexDeformationRange.slice(); }
78 this.getVertexDeformationTolerance = function() { return this._vertexDeformationTolerance; }
79
80
81 ///////////////////////////////////////////////////////////////////////
82 // Common Material Methods
83 ///////////////////////////////////////////////////////////////////////
84 this.getProperty = function( propName )
85 {
86 return this._propValues[propName];
87 }
88
89 this.getPropertyCount = function()
90 {
91 return this._propNames.length;
92 }
93
94 this.getPropertyAtIndex = function( index )
95 {
96 var rtnArr = [];
97 if ((index < 0) || (index >= this.getPropertyCount()))
98 throw new Error( "property index " + index + " is out of range for material" );
99
100 var rtnArr = [ this._propNames[index], this._propLabels[index], this._propTypes[index], this._propValues[index] ];
101 return rtnArr;
102 }
103
104 this.getAllProperties = function( propNames, propValues, propTypes, propLabels)
105 {
106 // clear all the input arrays if there is junk in them
107 propNames.length = 0;
108 propValues.length = 0;
109 propTypes.length = 0;
110 propLabels.length = 0;
111
112 var nProps = this._propNames.length;
113 for (var i=0; i<nProps; i++)
114 {
115 propNames[i] = this._propNames[i];
116 propValues[i] = this._propValues[this._propNames[i]];
117 propTypes[i] = this._propTypes[i];
118 propLabels[i] = this._propLabels[i];
119 }
120 }
121
122 this.validateProperty = function( prop, value )
123 {
124 var rtnVal = false;
125 try
126 {
127 //if (!this._propValues[prop]) return false;
128
129 // find the index of the property
130 var n = this._propNames.length;
131 var valType = typeof value;
132 for (var i=0; i<n; i++)
133 {
134 if (this._propNames[i] == prop)
135 {
136 switch (this._propTypes[i])
137 {
138 case "color":
139 rtnVal = ((valType == "object") && (value.length >= 4));
140 break;
141
142 case "vector2d":
143 rtnVal = ((valType == "object") && (value.length >= 2));
144 break;
145
146 case "vector3d":
147 rtnVal = ((valType == "object") && (value.length >= 3));
148 break;
149
150 case "float":
151 rtnVal = (valType == "number");
152 break;
153
154 case "file":
155 rtnVal = ((valType == "string") || !value);
156 break;
157 }
158 break;
159 }
160 }
161 }
162 catch(e) {
163 console.log( "setting invalid material property: " + prop + ", value: " + value );
164 }
165
166 if (!rtnVal)
167 console.log( "invalid material property: " + prop + " : " + value );
168
169 return rtnVal;
170 }
171 ///////////////////////////////////////////////////////////////////////
172
173 ///////////////////////////////////////////////////////////////////////
174 // Methods
175 ///////////////////////////////////////////////////////////////////////
176 // duplcate method required by sub class
177 this.dup = function()
178 {
179 throw new Error( "Material.dup() must be overridden by subclass" );
180 }
181
182 this.init = function( world )
183 {
184 throw new Error( "Material.init() must be overridden by subclass" );
185 }
186
187 this.update = function( time )
188 {
189 // animated materials should implement the update method
190 }
191
192 this.registerTexture = function( texture )
193 {
194 // the world needs to know about the texture map
195 var world = this.getWorld();
196 if (!world)
197 console.log( "**** world not defined for registering texture map: " + texture.lookUpName );
198 else
199 world.textureToLoad( texture );
200 }
201
202 this.loadTexture = function( texMapName, wrap, mips )
203 {
204 var tex;
205 var world = this.getWorld();
206 if (!world)
207 console.log( "world not defined for material with texture map" );
208 else
209 {
210 var renderer = world.getRenderer();
211 tex = renderer.getTextureByName(texMapName, wrap, mips );
212 this.registerTexture( tex );
213 }
214 return tex;
215 }
216
217 this.export = function()
218 {
219 // this function should be overridden by subclasses
220 var exportStr = "material: " + this.getShaderName() + "\n" + "endMaterial\n";
221 return exportStr;