diff options
author | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
---|---|---|
committer | Nivesh Rajbhandari | 2012-04-16 16:06:24 -0700 |
commit | c253192a08b499ea7be46fa5438d273e51f7ec5a (patch) | |
tree | 18a1f0e3679c0eb993a9dedb537035d3861f49ac /js/lib/geom/rectangle.js | |
parent | e19376c54eedd1f1c457ba405b2f110be376a559 (diff) | |
parent | 4b900ea5cd6bb77eb30cec8c03b9ec9fa662c1e9 (diff) | |
download | ninja-c253192a08b499ea7be46fa5438d273e51f7ec5a.tar.gz |
Merge branch 'refs/heads/ninja-internal' into WebGLFixes
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 170 |
1 files changed, 60 insertions, 110 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index a47295e0..91b1d426 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -7,7 +7,6 @@ | |||
7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | 8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; |
9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
10 | var FlatMaterial = require("js/lib/rdge/materials/flat-material").FlatMaterial; | ||
11 | /////////////////////////////////////////////////////////////////////// | 10 | /////////////////////////////////////////////////////////////////////// |
12 | // Class GLRectangle | 11 | // Class GLRectangle |
13 | // GL representation of a rectangle. | 12 | // GL representation of a rectangle. |
@@ -71,16 +70,14 @@ var Rectangle = function GLRectangle() { | |||
71 | if(strokeMaterial) { | 70 | if(strokeMaterial) { |
72 | this._strokeMaterial = strokeMaterial; | 71 | this._strokeMaterial = strokeMaterial; |
73 | } else { | 72 | } else { |
74 | this._strokeMaterial = MaterialsModel.exportFlatMaterial(); | 73 | this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
75 | } | 74 | } |
76 | 75 | ||
77 | if(fillMaterial) { | 76 | if(fillMaterial) { |
78 | this._fillMaterial = fillMaterial; | 77 | this._fillMaterial = fillMaterial; |
79 | } else { | 78 | } else { |
80 | this._fillMaterial = MaterialsModel.exportFlatMaterial(); | 79 | this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
81 | } | 80 | } |
82 | |||
83 | this.exportMaterials(); | ||
84 | }; | 81 | }; |
85 | 82 | ||
86 | /////////////////////////////////////////////////////////////////////// | 83 | /////////////////////////////////////////////////////////////////////// |
@@ -190,113 +187,66 @@ var Rectangle = function GLRectangle() { | |||
190 | /////////////////////////////////////////////////////////////////////// | 187 | /////////////////////////////////////////////////////////////////////// |
191 | // Methods | 188 | // Methods |
192 | /////////////////////////////////////////////////////////////////////// | 189 | /////////////////////////////////////////////////////////////////////// |
193 | this.export = function() { | 190 | // JSON export |
194 | var rtnStr = "type: " + this.geomType() + "\n"; | 191 | this.exportJSON = function() |
195 | 192 | { | |
196 | ///////////////////////////////////////////////////////////////////////// | 193 | var jObj = |
197 | // | 194 | { |
198 | // world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, | 195 | 'type' : this.geomType(), |
199 | // tlRadius, trRadius, blRadius, brRadius, strokeMaterial, fillMaterial, strokeStyle | 196 | 'xoff' : this._xOffset, |
200 | // | 197 | 'yoff' : this._yOffset, |
201 | ///////////////////////////////////////////////////////////////////////////// | 198 | 'width' : this._width, |
202 | 199 | 'height' : this._height, | |
203 | rtnStr += "xoff: " + this._xOffset + "\n"; | 200 | 'strokeWidth' : this._strokeWidth, |
204 | rtnStr += "yoff: " + this._yOffset + "\n"; | 201 | 'strokeColor' : this._strokeColor, |
205 | rtnStr += "width: " + this._width + "\n"; | 202 | 'fillColor' : this._fillColor, |
206 | rtnStr += "height: " + this._height + "\n"; | 203 | 'tlRadius' : this._tlRadius, |
207 | rtnStr += "strokeWidth: " + this._strokeWidth + "\n"; | 204 | 'trRadius' : this._trRadius, |
208 | 205 | 'blRadius' : this._blRadius, | |
209 | if(this._strokeColor.gradientMode) { | 206 | 'brRadius' : this._brRadius, |
210 | rtnStr += "strokeGradientMode: " + this._strokeColor.gradientMode + "\n"; | 207 | 'innerRadius' : this._innerRadius, |
211 | rtnStr += "strokeColor: " + this.gradientToString(this._strokeColor.color) + "\n"; | 208 | 'strokeStyle' : this._strokeStyle, |
212 | } else { | 209 | 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), |
213 | rtnStr += "strokeColor: " + String(this._strokeColor) + "\n"; | 210 | 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), |
214 | } | 211 | 'materials' : this.exportMaterialsJSON() |
215 | 212 | }; | |
216 | if(this._fillColor.gradientMode) { | 213 | |
217 | rtnStr += "fillGradientMode: " + this._fillColor.gradientMode + "\n"; | 214 | return jObj; |
218 | rtnStr += "fillColor: " + this.gradientToString(this._fillColor.color) + "\n"; | ||
219 | } else { | ||
220 | rtnStr += "fillColor: " + String(this._fillColor) + "\n"; | ||
221 | } | ||
222 | rtnStr += "tlRadius: " + this._tlRadius + "\n"; | ||
223 | rtnStr += "trRadius: " + this._trRadius + "\n"; | ||
224 | rtnStr += "blRadius: " + this._blRadius + "\n"; | ||
225 | rtnStr += "brRadius: " + this._brRadius + "\n"; | ||
226 | rtnStr += "innerRadius: " + this._innerRadius + "\n"; | ||
227 | rtnStr += "strokeStyle: " + this._strokeStyle + "\n"; | ||
228 | |||
229 | rtnStr += "strokeMat: "; | ||
230 | if (this._strokeMaterial) { | ||
231 | rtnStr += this._strokeMaterial.getName(); | ||
232 | } else { | ||
233 | rtnStr += "flatMaterial"; | ||
234 | } | ||
235 | rtnStr += "\n"; | ||
236 | |||
237 | rtnStr += "fillMat: "; | ||
238 | if (this._fillMaterial) { | ||
239 | rtnStr += this._fillMaterial.getName(); | ||
240 | } else { | ||
241 | rtnStr += "flatMaterial"; | ||
242 | } | ||
243 | rtnStr += "\n"; | ||
244 | |||
245 | rtnStr += this.exportMaterials(); | ||
246 | |||
247 | return rtnStr; | ||
248 | }; | 215 | }; |
249 | 216 | ||
250 | this.import = function( importStr ) { | 217 | this.importJSON = function( jObj ) |
251 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | 218 | { |
252 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | 219 | this._xOffset = jObj.xoff; |
253 | this._width = Number( this.getPropertyFromString( "width: ", importStr ) ); | 220 | this._yOffset = jObj.yoff; |
254 | this._height = Number( this.getPropertyFromString( "height: ", importStr ) ); | 221 | this._width = jObj.width; |
255 | this._strokeWidth = Number( this.getPropertyFromString( "strokeWidth: ", importStr ) ); | 222 | this._height = jObj.height; |
256 | this._innerRadius = Number( this.getPropertyFromString( "innerRadius: ", importStr ) ); | 223 | this._strokeWidth = jObj.strokeWidth; |
257 | this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); | 224 | this._strokeColor = jObj.strokeColor; |
258 | var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); | 225 | this._fillColor = jObj.fillColor; |
259 | var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); | 226 | this._tlRadius = jObj.tlRadius; |
260 | this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); | 227 | this._trRadius = jObj.trRadius; |
261 | 228 | this._blRadius = jObj.blRadius; | |
262 | if(importStr.indexOf("fillGradientMode: ") < 0) { | 229 | this._brRadius = jObj.brRadius; |
263 | this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); | 230 | this._innerRadius = jObj.innerRadius; |
264 | } else { | 231 | this._strokeStyle = jObj.strokeStyle; |
265 | this._fillColor = {}; | 232 | var strokeMaterialName = jObj.strokeMat; |
266 | this._fillColor.gradientMode = this.getPropertyFromString( "fillGradientMode: ", importStr ); | 233 | var fillMaterialName = jObj.fillMat; |
267 | this._fillColor.color = this.stringToGradient(this.getPropertyFromString( "fillColor: ", importStr )); | 234 | |
235 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
236 | if (!strokeMat) { | ||
237 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
238 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
268 | } | 239 | } |
240 | this._strokeMaterial = strokeMat; | ||
269 | 241 | ||
270 | if(importStr.indexOf("strokeGradientMode: ") < 0) | 242 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); |
271 | { | 243 | if (!fillMat) { |
272 | this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); | 244 | console.log( "object material not found in library: " + fillMaterialName ); |
273 | } else { | 245 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
274 | this._strokeColor = {}; | ||
275 | this._strokeColor.gradientMode = this.getPropertyFromString( "strokeGradientMode: ", importStr ); | ||
276 | this._strokeColor.color = this.stringToGradient(this.getPropertyFromString( "strokeColor: ", importStr )); | ||
277 | } | 246 | } |
247 | this._fillMaterial = fillMat; | ||
278 | 248 | ||
279 | this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); | 249 | this.importMaterialsJSON( jObj.materials ); |
280 | this._trRadius = Number( this.getPropertyFromString( "trRadius: ", importStr ) ); | ||
281 | this._blRadius = Number( this.getPropertyFromString( "blRadius: ", importStr ) ); | ||
282 | this._brRadius = Number( this.getPropertyFromString( "brRadius: ", importStr ) ); | ||
283 | |||
284 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
285 | if (!strokeMat) { | ||
286 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
287 | strokeMat = MaterialsModel.exportFlatMaterial(); | ||
288 | } | ||
289 | |||
290 | this._strokeMaterial = strokeMat; | ||
291 | |||
292 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
293 | if (!fillMat) { | ||
294 | console.log( "object material not found in library: " + fillMaterialName ); | ||
295 | fillMat = MaterialsModel.exportFlatMaterial(); | ||
296 | } | ||
297 | this._fillMaterial = fillMat; | ||
298 | |||
299 | this.importMaterials( importStr ); | ||
300 | }; | 250 | }; |
301 | 251 | ||
302 | this.buildBuffers = function() { | 252 | this.buildBuffers = function() { |
@@ -307,7 +257,7 @@ var Rectangle = function GLRectangle() { | |||
307 | if (!world._useWebGL) return; | 257 | if (!world._useWebGL) return; |
308 | 258 | ||
309 | // make sure RDGE has the correct context | 259 | // make sure RDGE has the correct context |
310 | g_Engine.setContext( world.getCanvas().rdgeid ); | 260 | RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); |
311 | 261 | ||
312 | // create the gl buffer | 262 | // create the gl buffer |
313 | var gl = world.getGLContext(); | 263 | var gl = world.getGLContext(); |
@@ -907,7 +857,7 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
907 | // } | 857 | // } |
908 | 858 | ||
909 | // create the RDGE primitive | 859 | // create the RDGE primitive |
910 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); | 860 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices); |
911 | }; | 861 | }; |
912 | 862 | ||
913 | RectangleFill.pushVertex = function( x, y, z ) { | 863 | RectangleFill.pushVertex = function( x, y, z ) { |
@@ -1139,7 +1089,7 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, | |||
1139 | // } | 1089 | // } |
1140 | 1090 | ||
1141 | // create the RDGE primitive | 1091 | // create the RDGE primitive |
1142 | return ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); |