diff options
author | hwc487 | 2012-03-16 12:26:30 -0700 |
---|---|---|
committer | hwc487 | 2012-03-16 12:26:30 -0700 |
commit | a0d23354802ebc6b437698acb4b18d3395d47cd1 (patch) | |
tree | a0081c079c9fc557e10a828db9adeed5a91d5a72 /js/lib/geom/rectangle.js | |
parent | 57d4a82977a1f0e809511fe894886f88581d9615 (diff) | |
download | ninja-a0d23354802ebc6b437698acb4b18d3395d47cd1.tar.gz |
Conversion to JSON based file IO for canvas2D and WebGL rendering
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 87 |
1 files changed, 75 insertions, 12 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 370bb257..51fa3fd6 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,13 +70,13 @@ 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 | 81 | ||
83 | this.exportMaterials(); | 82 | this.exportMaterials(); |
@@ -218,7 +217,7 @@ var Rectangle = function GLRectangle() { | |||
218 | if (this._strokeMaterial) { | 217 | if (this._strokeMaterial) { |
219 | rtnStr += this._strokeMaterial.getName(); | 218 | rtnStr += this._strokeMaterial.getName(); |
220 | } else { | 219 | } else { |
221 | rtnStr += "flatMaterial"; | 220 | rtnStr += MaterialsModel.getDefaultMaterialName(); |
222 | } | 221 | } |
223 | rtnStr += "\n"; | 222 | rtnStr += "\n"; |
224 | 223 | ||
@@ -226,7 +225,7 @@ var Rectangle = function GLRectangle() { | |||
226 | if (this._fillMaterial) { | 225 | if (this._fillMaterial) { |
227 | rtnStr += this._fillMaterial.getName(); | 226 | rtnStr += this._fillMaterial.getName(); |
228 | } else { | 227 | } else { |
229 | rtnStr += "flatMaterial"; | 228 | rtnStr += MaterialsModel.getDefaultMaterialName(); |
230 | } | 229 | } |
231 | rtnStr += "\n"; | 230 | rtnStr += "\n"; |
232 | 231 | ||
@@ -235,6 +234,71 @@ var Rectangle = function GLRectangle() { | |||
235 | return rtnStr; | 234 | return rtnStr; |
236 | }; | 235 | }; |
237 | 236 | ||
237 | // JSON export | ||
238 | this.exportJSON = function() | ||
239 | { | ||
240 | var jObj = | ||
241 | { | ||
242 | 'type' : this.geomType(), | ||
243 | 'xoff' : this._xOffset, | ||
244 | 'yoff' : this._yOffset, | ||
245 | 'width' : this._width, | ||
246 | 'height' : this._height, | ||
247 | 'strokeWidth' : this._strokeWidth, | ||
248 | 'strokeColor' : this._strokeColor, | ||
249 | 'fillColor' : this._fillColor, | ||
250 | 'tlRadius' : this._tlRadius, | ||
251 | 'trRadius' : this._trRadius, | ||
252 | 'blRadius' : this._blRadius, | ||
253 | 'brRadius' : this._brRadius, | ||
254 | 'innerRadius' : this._innerRadius, | ||
255 | 'strokeStyle' : this._strokeStyle, | ||
256 | 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
257 | 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
258 | 'materials' : this.exportMaterialsJSON() | ||
259 | }; | ||
260 | |||
261 | return jObj; | ||
262 | }; | ||
263 | |||
264 | this.importJSON = function( jObj ) | ||
265 | { | ||
266 | this._xOffset = jObj.xoff; | ||
267 | this._yOffset = jObj.yoff; | ||
268 | this._width = jObj.width; | ||
269 | this._height = jObj.height; | ||
270 | this._strokeWidth = jObj.strokeWidth; | ||
271 | this._strokeColor = jObj.strokeColor; | ||
272 | this._fillColor = jObj.fillColor; | ||
273 | this._tlRadius = jObj.tlRadius; | ||
274 | this._trRadius = jObj.trRadius; | ||
275 | this._blRadius = jObj.blRadius; | ||
276 | this._brRadius = jObj.brRadius; | ||
277 | this._innerRadius = jObj.innerRadius; | ||
278 | this._strokeStyle = jObj.strokeStyle; | ||
279 | var strokeMaterialName = jObj.strokeMat; | ||
280 | var fillMaterialName = jObj.fillMat; | ||
281 | this.importMaterialsJSON( jObj.materials ); | ||
282 | |||
283 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
284 | if (!strokeMat) { | ||
285 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
286 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
287 | } | ||
288 | else | ||
289 | strokeMat = strokeMat.dup(); | ||
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.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
296 | } | ||
297 | else | ||
298 | fillMat = fillMat.dup(); | ||
299 | this._fillMaterial = fillMat; | ||
300 | }; | ||
301 | |||
238 | this.import = function( importStr ) { | 302 | this.import = function( importStr ) { |
239 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | 303 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); |
240 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | 304 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); |
@@ -256,15 +320,14 @@ var Rectangle = function GLRectangle() { | |||
256 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | 320 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); |
257 | if (!strokeMat) { | 321 | if (!strokeMat) { |
258 | console.log( "object material not found in library: " + strokeMaterialName ); | 322 | console.log( "object material not found in library: " + strokeMaterialName ); |
259 | strokeMat = MaterialsModel.exportFlatMaterial(); | 323 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
260 | } | 324 | } |
261 | |||
262 | this._strokeMaterial = strokeMat; | 325 | this._strokeMaterial = strokeMat; |
263 | 326 | ||
264 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | 327 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); |
265 | if (!fillMat) { | 328 | if (!fillMat) { |
266 | console.log( "object material not found in library: " + fillMaterialName ); | 329 | console.log( "object material not found in library: " + fillMaterialName ); |
267 | fillMat = MaterialsModel.exportFlatMaterial(); | 330 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
268 | } | 331 | } |
269 | this._fillMaterial = fillMat; | 332 | this._fillMaterial = fillMat; |
270 | 333 | ||
@@ -339,10 +402,10 @@ var Rectangle = function GLRectangle() { | |||
339 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | 402 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; |
340 | 403 | ||
341 | // stroke | 404 | // stroke |
342 | var strokeMaterial = this.makeStrokeMaterial(); | 405 | // var strokeMaterial = this.makeStrokeMaterial(); |
343 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | 406 | // var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); |
344 | this._primArray.push( strokePrim ); | 407 | // this._primArray.push( strokePrim ); |
345 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 408 | // this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
346 | 409 | ||
347 | // fill | 410 | // fill |
348 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; | 411 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; |