aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/geom-obj.js
diff options
context:
space:
mode:
authorJonathan Duran2012-04-10 08:13:00 -0700
committerJonathan Duran2012-04-10 08:13:00 -0700
commit58e049b68e03abbacde93206d2666361022c0858 (patch)
treef1ce6b8a378674d4abcac68acd0bcca93b838a39 /js/lib/geom/geom-obj.js
parenta9050f96d814469f420bcf3630d16d576b62258e (diff)
parentbd43ce383b050d03b0f92cc923c517febc66ca28 (diff)
downloadninja-58e049b68e03abbacde93206d2666361022c0858.tar.gz
Merge branch 'refs/heads/NINJAmaster' into TimelineUber
Diffstat (limited to 'js/lib/geom/geom-obj.js')
-rwxr-xr-xjs/lib/geom/geom-obj.js128
1 files changed, 74 insertions, 54 deletions
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js
index bb5b4a9a..2cde8a75 100755
--- a/js/lib/geom/geom-obj.js
+++ b/js/lib/geom/geom-obj.js
@@ -1,8 +1,8 @@
1/* <copyright> 1/* <copyright>
2This file contains proprietary software owned by Motorola Mobility, Inc.<br/> 2 This 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/> 3 No 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 MaterialsModel = require("js/models/materials-model").MaterialsModel; 7var MaterialsModel = require("js/models/materials-model").MaterialsModel;
8 8
@@ -144,46 +144,65 @@ var GeomObj = function GLGeomObj() {
144 this.setMaterialColor = function (c, type) { 144 this.setMaterialColor = function (c, type) {
145 var i = 0, 145 var i = 0,
146 nMats = 0; 146 nMats = 0;
147 if (c.gradientMode) { 147 if (c) {
148 // Gradient support 148 if (c.gradientMode) {
149 if (this._materialArray && this._materialTypeArray) { 149 // Gradient support
150 nMats = this._materialArray.length; 150 if (this._materialArray && this._materialTypeArray) {
151 } 151 nMats = this._materialArray.length;
152 152 }
153 var stops = [],
154 colors = c.color;
155 153
156 var len = colors.length; 154 var stops = [],
157 // TODO - Current shaders only support 4 color stops 155 colors = c.color;
158 if (len > 4) {
159 len = 4;
160 }
161 156
162 for (var n = 0; n < len; n++) { 157 var len = colors.length;
163 var position = colors[n].position / 100; 158 // TODO - Current shaders only support 4 color stops
164 var cs = colors[n].value; 159 if (len > 4) {
165 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a]; 160 len = 4;
166 stops.push(stop); 161 }
167 162
168 if (nMats === this._materialTypeArray.length) { 163 for (var n = 0; n < len; n++) {
169 for (i = 0; i < nMats; i++) { 164 var position = colors[n].position / 100;
170 if (this._materialTypeArray[i] == type) { 165 var cs = colors[n].value;
171 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0)); 166 var stop = [cs.r / 255, cs.g / 255, cs.b / 255, cs.a];
172 this._materialArray[i].setProperty("colorStop" + (n + 1), position); 167 stops.push(stop);
168
169 if (nMats === this._materialTypeArray.length) {
170 for (i = 0; i < nMats; i++) {
171 if (this._materialTypeArray[i] == type) {
172 this._materialArray[i].setProperty("color" + (n + 1), stop.slice(0));
173 this._materialArray[i].setProperty("colorStop" + (n + 1), position);
174 }
173 } 175 }
174 } 176 }
175 } 177 }
176 } 178 if (type === "fill") {
177 if (type === "fill") { 179 this._fillColor = c;
178 this._fillColor = c; 180 } else {
181 this._strokeColor = c;
182 }
179 } else { 183 } else {
180 this._strokeColor = c; 184 if (type === "fill") {
185 this._fillColor = c.slice(0);
186 } else {
187 this._strokeColor = c.slice(0);
188 }
189
190 if (this._materialArray && this._materialTypeArray) {
191 nMats = this._materialArray.length;
192 if (nMats === this._materialTypeArray.length) {
193 for (i = 0; i < nMats; i++) {
194 if (this._materialTypeArray[i] == type) {
195 this._materialArray[i].setProperty("color", c.slice(0));
196 }
197 }
198 }
199 }
181 } 200 }
182 } else { 201 } else {
183 if (type === "fill") { 202 if (type === "fill") {
184 this._fillColor = c.slice(0); 203 this._fillColor = null;
185 } else { 204 } else {
186 this._strokeColor = c.slice(0); 205 this._strokeColor = null;
187 } 206 }
188 207
189 if (this._materialArray && this._materialTypeArray) { 208 if (this._materialArray && this._materialTypeArray) {
@@ -191,7 +210,8 @@ var GeomObj = function GLGeomObj() {
191 if (nMats === this._materialTypeArray.length) { 210 if (nMats === this._materialTypeArray.length) {
192 for (i = 0; i < nMats; i++) { 211 for (i = 0; i < nMats; i++) {
193 if (this._materialTypeArray[i] == type) { 212 if (this._materialTypeArray[i] == type) {
194 this._materialArray[i].setProperty("color", c.slice(0)); 213 // TODO - Not sure how to set color to null values in shaders
214 this._materialArray[i].setProperty("color", [0, 0, 0, 0]);
195 } 215 }
196 } 216 }
197 } 217 }
@@ -257,19 +277,19 @@ var GeomObj = function GLGeomObj() {
257 277
258 for (var i = 0; i < nMats; i++) { 278 for (var i = 0; i < nMats; i++) {
259 var matObj = 279 var matObj =
260 { 280 {
261 'materialNodeName': this._materialNodeArray[i].name, 281 'materialNodeName':this._materialNodeArray[i].name,
262 'material': this._materialArray[i].exportJSON(), 282 'material':this._materialArray[i].exportJSON(),
263 'type': this._materialTypeArray[i] 283 'type':this._materialTypeArray[i]
264 } 284 }
265 arr.push(matObj); 285 arr.push(matObj);
266 } 286 }
267 287
268 jObj = 288 jObj =
269 { 289 {
270 'nMaterials': nMats, 290 'nMaterials':nMats,
271 'materials': arr 291 'materials':arr
272 }; 292 };
273 } 293 }
274 } 294 }
275 295
@@ -280,7 +300,7 @@ var GeomObj = function GLGeomObj() {
280 this._materialArray = []; 300 this._materialArray = [];
281 this._materialTypeArray = []; 301 this._materialTypeArray = [];
282 302
283 if (!jObj) return; 303 if (!jObj) return;
284 304
285 var nMaterials = jObj.nMaterials; 305 var nMaterials = jObj.nMaterials;
286 var matArray = jObj.materials; 306 var matArray = jObj.materials;
@@ -312,7 +332,7 @@ var GeomObj = function GLGeomObj() {
312 case "radialBlur": 332 case "radialBlur":
313 case "pulse": 333 case "pulse":
314 mat = MaterialsModel.getMaterialByShader(shaderName); 334 mat = MaterialsModel.getMaterialByShader(shaderName);
315 if (mat) mat = mat.dup(); 335 if (mat) mat = mat.dup();
316 break; 336 break;
317 337
318 default: 338 default:
@@ -325,8 +345,8 @@ var GeomObj = function GLGeomObj() {
325 this._materialArray.push(mat); 345 this._materialArray.push(mat);
326 this._materialTypeArray.push(matObj.type); 346 this._materialTypeArray.push(matObj.type);
327 var type = matArray[i].type; 347 var type = matArray[i].type;
328 if (type == "fill") this._fillMaterial = mat; 348 if (type == "fill") this._fillMaterial = mat;
329 else this._strokeMaterial = mat; 349 else this._strokeMaterial = mat;
330 } 350 }
331 } 351 }
332 }; 352 };
@@ -381,7 +401,7 @@ var GeomObj = function GLGeomObj() {
381 401
382 this.getPropertyFromString = function (prop, str) { 402 this.getPropertyFromString = function (prop, str) {
383 var index = str.indexOf(prop); 403 var index = str.indexOf(prop);
384 if (index < 0) throw new Error("property " + prop + " not found in string: " + str); 404 if (index < 0) throw new Error("property " + prop + " not found in string: " + str);
385 405
386 var rtnStr = str.substr(index + prop.length); 406 var rtnStr = str.substr(index + prop.length);
387 index = rtnStr.indexOf("\n"); 407 index = rtnStr.indexOf("\n");
@@ -428,18 +448,18 @@ var GeomObj = function GLGeomObj() {
428 for (i = 0; i < len; i++) { 448 for (i = 0; i < len; i++) {
429 stop = stops[i].split("@"); 449 stop = stops[i].split("@");
430 c = stop[0].split(","); 450 c = stop[0].split(",");
431 rtnArr.push({ position: Number(stop[1]), value: { r: Number(c[0]), g: Number(c[1]), b: Number(c[2]), a: Number(c[3])} }); 451 rtnArr.push({ position:Number(stop[1]), value:{r:Number(c[0]), g:Number(c[1]), b:Number(c[2]), a:Number(c[3])} });
432 } 452 }
433 453
434 return rtnArr; 454 return rtnArr;
435 }; 455 };
436 456
437 /* 457 /*
438 this.export = function() { 458 this.export = function() {
439 var rtnStr; 459 var rtnStr;
440 return rtnStr; 460 return rtnStr;
441 } 461 }
442 */ 462 */
443}; 463};
444 464
445if (typeof exports === "object") { 465if (typeof exports === "object") {