diff options
author | Nivesh Rajbhandari | 2012-03-29 15:52:08 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-03-29 17:04:06 -0700 |
commit | 5b4f6b1618cf571a6bce5a631f976a008e04a64e (patch) | |
tree | d073038b08d14884f87c7776e9e192256d414cfb /js/lib/geom | |
parent | 6b61de58f0733b40f64ed996933ac89927e922a1 (diff) | |
download | ninja-5b4f6b1618cf571a6bce5a631f976a008e04a64e.tar.gz |
Updated shapes to always check for its stroke and fill colors and materials instead of relying on the shapeModel cache because it can get out of sync.
Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-x | js/lib/geom/circle.js | 15 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 82 | ||||
-rwxr-xr-x | js/lib/geom/line.js | 8 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 15 |
4 files changed, 80 insertions, 40 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index d48bf98b..ee3e2abd 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -633,6 +633,21 @@ var Circle = function GLCircle() { | |||
633 | this._strokeStyle = jObj.strokeStyle; | 633 | this._strokeStyle = jObj.strokeStyle; |
634 | var strokeMaterialName = jObj.strokeMat; | 634 | var strokeMaterialName = jObj.strokeMat; |
635 | var fillMaterialName = jObj.fillMat; | 635 | var fillMaterialName = jObj.fillMat; |
636 | |||
637 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
638 | if (!strokeMat) { | ||
639 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
640 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
641 | } | ||
642 | this._strokeMaterial = strokeMat; | ||
643 | |||
644 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
645 | if (!fillMat) { | ||
646 | console.log( "object material not found in library: " + fillMaterialName ); | ||
647 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
648 | } | ||
649 | this._fillMaterial = fillMat; | ||
650 | |||
636 | this.importMaterialsJSON( jObj.materials ); | 651 | this.importMaterialsJSON( jObj.materials ); |
637 | }; | 652 | }; |
638 | 653 | ||
diff --git a/js/lib/geom/geom-obj.js b/js/lib/geom/geom-obj.js index 3c4e4bbf..df4a018d 100755 --- a/js/lib/geom/geom-obj.js +++ b/js/lib/geom/geom-obj.js | |||
@@ -141,54 +141,56 @@ var GeomObj = function GLGeomObj() { | |||
141 | this.setMaterialColor = function(c, type) { | 141 | this.setMaterialColor = function(c, type) { |
142 | var i = 0, | 142 | var i = 0, |
143 | nMats = 0; | 143 | nMats = 0; |
144 | if(c.gradientMode) { | 144 | if(c) { |
145 | // Gradient support | 145 | if(c.gradientMode) { |
146 | if (this._materialArray && this._materialTypeArray) { | 146 | // Gradient support |
147 | nMats = this._materialArray.length; | 147 | if (this._materialArray && this._materialTypeArray) { |
148 | } | 148 | nMats = this._materialArray.length; |
149 | } | ||
149 | 150 | ||
150 | var stops = [], | 151 | var stops = [], |
151 | colors = c.color; | 152 | colors = c.color; |
152 | 153 | ||
153 | var len = colors.length; | 154 | var len = colors.length; |
154 | // TODO - Current shaders only support 4 color stops | 155 | // TODO - Current shaders only support 4 color stops |
155 | if(len > 4) { | 156 | if(len > 4) { |
156 | len = 4; | 157 | len = 4; |
157 | } | 158 | } |
158 | 159 | ||
159 | for(var n=0; n<len; n++) { | 160 | for(var n=0; n<len; n++) { |
160 | var position = colors[n].position/100; | 161 | var position = colors[n].position/100; |
161 | var cs = colors[n].value; | 162 | var cs = colors[n].value; |
162 | var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; | 163 | var stop = [cs.r/255, cs.g/255, cs.b/255, cs.a]; |
163 | stops.push(stop); | 164 | stops.push(stop); |
164 | 165 | ||
165 | if (nMats === this._materialTypeArray.length) { | 166 | if (nMats === this._materialTypeArray.length) { |
166 | for (i=0; i<nMats; i++) { | 167 | for (i=0; i<nMats; i++) { |
167 | if (this._materialTypeArray[i] == type) { | 168 | if (this._materialTypeArray[i] == type) { |
168 | this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) ); | 169 | this._materialArray[i].setProperty( "color"+(n+1), stop.slice(0) ); |
169 | this._materialArray[i].setProperty( "colorStop"+(n+1), position ); | 170 | this._materialArray[i].setProperty( "colorStop"+(n+1), position ); |
171 | } | ||
170 | } | 172 | } |
171 | } | 173 | } |
172 | } | 174 | } |
173 | } | 175 | if (type === "fill") { |
174 | if (type === "fill") { | 176 | this._fillColor = c; |
175 | this._fillColor = c; | 177 | } else { |
176 | } else { | 178 | this._strokeColor = c; |
177 | this._strokeColor = c; | 179 | } |
178 | } | ||
179 | } else { | ||
180 | if (type === "fill") { | ||
181 | this._fillColor = c.slice(0); | ||
182 | } else { | 180 | } else { |
183 | this._strokeColor = c.slice(0); | 181 | if (type === "fill") { |
184 | } | 182 | this._fillColor = c.slice(0); |
183 | } else { | ||
184 | this._strokeColor = c.slice(0); | ||
185 | } | ||
185 | 186 | ||
186 | if (this._materialArray && this._materialTypeArray) { | 187 | if (this._materialArray && this._materialTypeArray) { |
187 | nMats = this._materialArray.length; | 188 | nMats = this._materialArray.length; |
188 | if (nMats === this._materialTypeArray.length) { | 189 | if (nMats === this._materialTypeArray.length) { |
189 | for (i=0; i<nMats; i++) { | 190 | for (i=0; i<nMats; i++) { |
190 | if (this._materialTypeArray[i] == type) { | 191 | if (this._materialTypeArray[i] == type) { |
191 | this._materialArray[i].setProperty( "color", c.slice(0) ); | 192 | this._materialArray[i].setProperty( "color", c.slice(0) ); |
193 | } | ||
192 | } | 194 | } |
193 | } | 195 | } |
194 | } | 196 | } |
diff --git a/js/lib/geom/line.js b/js/lib/geom/line.js index e839e229..2b2434f5 100755 --- a/js/lib/geom/line.js +++ b/js/lib/geom/line.js | |||
@@ -137,6 +137,14 @@ var Line = function GLLine( world, xOffset, yOffset, width, height, slope, strok | |||
137 | this._strokeStyle = jObj.strokeStyle; | 137 | this._strokeStyle = jObj.strokeStyle; |
138 | this._strokeColor = jObj.strokeColor; | 138 | this._strokeColor = jObj.strokeColor; |
139 | var strokeMaterialName = jObj.strokeMat; | 139 | var strokeMaterialName = jObj.strokeMat; |
140 | |||
141 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
142 | if (!strokeMat) { | ||
143 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
144 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
145 | } | ||
146 | this._strokeMaterial = strokeMat; | ||
147 | |||
140 | this.importMaterialsJSON( jObj.materials ); | 148 | this.importMaterialsJSON( jObj.materials ); |
141 | }; | 149 | }; |
142 | 150 | ||
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index e511d5f4..b01aea53 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -290,6 +290,21 @@ var Rectangle = function GLRectangle() { | |||
290 | this._strokeStyle = jObj.strokeStyle; | 290 | this._strokeStyle = jObj.strokeStyle; |
291 | var strokeMaterialName = jObj.strokeMat; | 291 | var strokeMaterialName = jObj.strokeMat; |
292 | var fillMaterialName = jObj.fillMat; | 292 | var fillMaterialName = jObj.fillMat; |
293 | |||
294 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
295 | if (!strokeMat) { | ||
296 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
297 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
298 | } | ||
299 | this._strokeMaterial = strokeMat; | ||
300 | |||
301 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
302 | if (!fillMat) { | ||
303 | console.log( "object material not found in library: " + fillMaterialName ); | ||
304 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
305 | } | ||
306 | this._fillMaterial = fillMat; | ||
307 | |||
293 | this.importMaterialsJSON( jObj.materials ); | 308 | this.importMaterialsJSON( jObj.materials ); |
294 | }; | 309 | }; |
295 | 310 | ||