aboutsummaryrefslogtreecommitdiff
path: root/js/lib/rdge/materials/material.js
diff options
context:
space:
mode:
authorJonathan Duran2012-03-06 11:38:39 -0800
committerJonathan Duran2012-03-06 11:38:39 -0800
commit342fb451bd251358068a0dcb10e9dc218b79a176 (patch)
treeaa0195d581c3934fb6dc09981506b3c070002806 /js/lib/rdge/materials/material.js
parent2815adfd7c19b3dff89dc3e1bda9af8d30dca8d6 (diff)
downloadninja-342fb451bd251358068a0dcb10e9dc218b79a176.tar.gz
Squashed commit of the following:
commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez <kgq387@motorola.com> Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito <valerio@motorola.com> Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito <valerio@motorola.com> commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito <valerio@motorola.com> Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran <jduran@motorola.com> commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman <ericg@motorola.com> Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran <jduran@motorola.com> Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran <jduran@motorola.com> commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari <mqg734@motorola.com> Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com> Signed-off-by: Jonathan Duran <jduran@motorola.com>
Diffstat (limited to 'js/lib/rdge/materials/material.js')
-rwxr-xr-xjs/lib/rdge/materials/material.js346
1 files changed, 346 insertions, 0 deletions
diff --git a/js/lib/rdge/materials/material.js b/js/lib/rdge/materials/material.js
new file mode 100755
index 00000000..c1d13b15
--- /dev/null
+++ b/js/lib/rdge/materials/material.js
@@ -0,0 +1,346 @@
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///////////////////////////////////////////////////////////////////////
11var Material = function GLMaterial( world ) {
12 ///////////////////////////////////////////////////////////////////////
13 // Instance variables
14 ///////////////////////////////////////////////////////////////////////
15 this._name = "GLMaterial";
16 this._shaderName = "undefined";
17
18 // keep a reference to the owning GLWorld
19 this._world = null;
20 if(world) {
21 this._world = world;
22 }
23
24 this._shininess = 60;
25
26 this._ambient = [0.0, 0.0, 0.0, 1.0];
27 this._diffuse = [0.0, 0.0, 0.0, 1.0];
28 this._specular = [0.0, 0.0, 0.0, 1.0];
29
30 this._texture = null;
31
32 // vertex deformation variables
33 this._hasVertexDeformation = false;
34 this._vertexDeformationRange = [0, 0, 1, 1]; // (xMin, yMin, xMax, yMax)
35 this._vertexDeformationTolerance = 0.1;
36
37 // RDGE variables
38 this._shader = null;
39 this._materialNode = null;
40
41 ///////////////////////////////////////////////////////////////////////
42 // Property Accessors
43 ///////////////////////////////////////////////////////////////////////
44 this.getShininess = function() {
45 return this._shininess;
46 };
47
48 this.setShininess = function(s) {
49 this._shininess = s;
50 };
51
52 this.setName = function(n) {
53 this._name = n;
54 };
55
56 this.getName = function() {
57 return this._name;
58 };
59
60 this.setShaderName = function(n) {
61 this._shaderName = n;
62 };
63
64 this.getShaderName = function() {
65 return this._shaderName;
66 };
67
68 this.setWorld = function(world) {
69 this._world = world;
70 };
71
72 this.getWorld = function() {
73 return this._world;
74 };
75
76 this.setAmbient = function(r, g, b, a) {
77 this._ambient = [r, g, b, a];
78 };
79
80 this.getAmbient = function() {
81 return [this._ambient[0], this._ambient[1], this._ambient[2], this._ambient[3]];
82 };
83
84 this.setDiffuse = function(r, g, b, a) {
85 this._diffuse = [r, g, b, a];
86 };
87
88 this.getDiffuse = function() {
89 return [this._diffuse[0], this._diffuse[1], this._diffuse[2], this._diffuse[3]];
90 };
91
92 this.setSpecular = function(r, g, b, a) {
93 this._specular = [r, g, b, a];
94 };
95
96 this.getSpecular = function() {
97 return [this._specular[0], this._specular[1], this._specular[2], this._specular[3]];
98 };
99
100 this.getShader = function() {
101 return this._shader;
102 };
103
104 this.getMaterialNode = function() {
105 return this._materialNode;
106 };
107
108 // a material can be animated or not. default is not.
109 // Any material needing continuous rendering should override this method
110 this.isAnimated = function() {
111 return false;
112 };
113
114 // the vertex shader can apply deformations requiring refinement in
115 // certain areas.
116 this.hasVertexDeformation = function() {
117 return this._hasVertexDeformation;
118 };
119
120 this.getVertexDeformationRange = function() {
121 return this._vertexDeformationRange.slice();
122 };
123
124 this.getVertexDeformationTolerance = function() {
125 return this._vertexDeformationTolerance;
126 };
127
128 ///////////////////////////////////////////////////////////////////////
129 // Common Material Methods
130 ///////////////////////////////////////////////////////////////////////
131 this.getProperty = function( propName ) {
132 return this._propValues[propName];
133 };
134
135 this.getPropertyCount = function() {
136 return this._propNames.length;
137 };
138
139 this.getPropertyAtIndex = function( index ) {
140 var rtnArr = [];
141 if ((index < 0) || (index >= this.getPropertyCount())) {
142 throw new Error( "property index " + index + " is out of range for material" );
143 }
144
145 return [ this._propNames[index], this._propLabels[index], this._propTypes[index], this._propValues[index] ];
146 };
147
148 this.getAllProperties = function( propNames, propValues, propTypes, propLabels) {
149 // clear all the input arrays if there is junk in them
150 propNames.length = 0;
151 propValues.length = 0;
152 propTypes.length = 0;
153 propLabels.length = 0;
154
155 var nProps = this._propNames.length;
156 for (var i=0; i<nProps; i++) {
157 propNames[i] = this._propNames[i];
158 propValues[i] = this._propValues[this._propNames[i]];
159 propTypes[i] = this._propTypes[i];
160 propLabels[i] = this._propLabels[i];
161 }
162 };
163
164 this.validateProperty = function( prop, value ) {
165 var rtnVal = false;
166 try
167 {
168 //if (!this._propValues[prop]) return false;
169
170 // find the index of the property
171 var n = this._propNames.length;
172 var valType = typeof value;
173 for (var i=0; i<n; i++) {
174 if (this._propNames[i] == prop) {
175
176 switch (this._propTypes[i])
177 {
178 case "color":
179 rtnVal = ((valType == "object") && (value.length >= 4));
180 break;
181
182 case "vector2d":
183 rtnVal = ((valType == "object") && (value.length >= 2));
184 break;
185
186 case "vector3d":
187 rtnVal = ((valType == "object") && (value.length >= 3));
188 break;
189
190 case "float":
191 rtnVal = (valType == "number");
192 break;
193
194 case "file":
195 rtnVal = ((valType == "string") || !value);
196 break;
197 }
198
199 break;
200 }
201 }
202 }
203 catch(e) {
204 console.log( "setting invalid material property: " + prop + ", value: " + value );
205 }
206
207 if (!rtnVal) {
208 console.log( "invalid material property: " + prop + " : " + value );
209 }
210
211 return rtnVal;
<