diff options
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 a47295e0..c6bc2d88 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(); |
@@ -230,7 +229,7 @@ var Rectangle = function GLRectangle() { | |||
230 | if (this._strokeMaterial) { | 229 | if (this._strokeMaterial) { |
231 | rtnStr += this._strokeMaterial.getName(); | 230 | rtnStr += this._strokeMaterial.getName(); |
232 | } else { | 231 | } else { |
233 | rtnStr += "flatMaterial"; | 232 | rtnStr += MaterialsModel.getDefaultMaterialName(); |
234 | } | 233 | } |
235 | rtnStr += "\n"; | 234 | rtnStr += "\n"; |
236 | 235 | ||
@@ -238,7 +237,7 @@ var Rectangle = function GLRectangle() { | |||
238 | if (this._fillMaterial) { | 237 | if (this._fillMaterial) { |
239 | rtnStr += this._fillMaterial.getName(); | 238 | rtnStr += this._fillMaterial.getName(); |
240 | } else { | 239 | } else { |
241 | rtnStr += "flatMaterial"; | 240 | rtnStr += MaterialsModel.getDefaultMaterialName(); |
242 | } | 241 | } |
243 | rtnStr += "\n"; | 242 | rtnStr += "\n"; |
244 | 243 | ||
@@ -247,6 +246,71 @@ var Rectangle = function GLRectangle() { | |||
247 | return rtnStr; | 246 | return rtnStr; |
248 | }; | 247 | }; |
249 | 248 | ||
249 | // JSON export | ||
250 | this.exportJSON = function() | ||
251 | { | ||
252 | var jObj = | ||
253 | { | ||
254 | 'type' : this.geomType(), | ||
255 | 'xoff' : this._xOffset, | ||
256 | 'yoff' : this._yOffset, | ||
257 | 'width' : this._width, | ||
258 | 'height' : this._height, | ||
259 | 'strokeWidth' : this._strokeWidth, | ||
260 | 'strokeColor' : this._strokeColor, | ||
261 | 'fillColor' : this._fillColor, | ||
262 | 'tlRadius' : this._tlRadius, | ||
263 | 'trRadius' : this._trRadius, | ||
264 | 'blRadius' : this._blRadius, | ||
265 | 'brRadius' : this._brRadius, | ||
266 | 'innerRadius' : this._innerRadius, | ||
267 | 'strokeStyle' : this._strokeStyle, | ||
268 | 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
269 | 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), | ||
270 | 'materials' : this.exportMaterialsJSON() | ||
271 | }; | ||
272 | |||
273 | return jObj; | ||
274 | }; | ||
275 | |||
276 | this.importJSON = function( jObj ) | ||
277 | { | ||
278 | this._xOffset = jObj.xoff; | ||
279 | this._yOffset = jObj.yoff; | ||
280 | this._width = jObj.width; | ||
281 | this._height = jObj.height; | ||
282 | this._strokeWidth = jObj.strokeWidth; | ||
283 | this._strokeColor = jObj.strokeColor; | ||
284 | this._fillColor = jObj.fillColor; | ||
285 | this._tlRadius = jObj.tlRadius; | ||
286 | this._trRadius = jObj.trRadius; | ||
287 | this._blRadius = jObj.blRadius; | ||
288 | this._brRadius = jObj.brRadius; | ||
289 | this._innerRadius = jObj.innerRadius; | ||
290 | this._strokeStyle = jObj.strokeStyle; | ||
291 | var strokeMaterialName = jObj.strokeMat; | ||
292 | var fillMaterialName = jObj.fillMat; | ||
293 | this.importMaterialsJSON( jObj.materials ); | ||
294 | |||
295 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | ||
296 | if (!strokeMat) { | ||
297 | console.log( "object material not found in library: " + strokeMaterialName ); | ||
298 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
299 | } | ||
300 | else | ||
301 | strokeMat = strokeMat.dup(); | ||
302 | this._strokeMaterial = strokeMat; | ||
303 | |||
304 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | ||
305 | if (!fillMat) { | ||
306 | console.log( "object material not found in library: " + fillMaterialName ); | ||
307 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); | ||
308 | } | ||
309 | else | ||
310 | fillMat = fillMat.dup(); | ||
311 | this._fillMaterial = fillMat; | ||
312 | }; | ||
313 | |||
250 | this.import = function( importStr ) { | 314 | this.import = function( importStr ) { |
251 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); | 315 | this._xOffset = Number( this.getPropertyFromString( "xoff: ", importStr ) ); |
252 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); | 316 | this._yOffset = Number( this.getPropertyFromString( "yoff: ", importStr ) ); |
@@ -284,15 +348,14 @@ var Rectangle = function GLRectangle() { | |||
284 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); | 348 | var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); |
285 | if (!strokeMat) { | 349 | if (!strokeMat) { |
286 | console.log( "object material not found in library: " + strokeMaterialName ); | 350 | console.log( "object material not found in library: " + strokeMaterialName ); |
287 | strokeMat = MaterialsModel.exportFlatMaterial(); | 351 | strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
288 | } | 352 | } |
289 | |||
290 | this._strokeMaterial = strokeMat; | 353 | this._strokeMaterial = strokeMat; |
291 | 354 | ||
292 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); | 355 | var fillMat = MaterialsModel.getMaterial( fillMaterialName ); |
293 | if (!fillMat) { | 356 | if (!fillMat) { |
294 | console.log( "object material not found in library: " + fillMaterialName ); | 357 | console.log( "object material not found in library: " + fillMaterialName ); |
295 | fillMat = MaterialsModel.exportFlatMaterial(); | 358 | fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); |
296 | } | 359 | } |
297 | this._fillMaterial = fillMat; | 360 | this._fillMaterial = fillMat; |
298 | 361 | ||
@@ -367,10 +430,10 @@ var Rectangle = function GLRectangle() { | |||
367 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | 430 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; |
368 | 431 | ||
369 | // stroke | 432 | // stroke |
370 | var strokeMaterial = this.makeStrokeMaterial(); | 433 | // var strokeMaterial = this.makeStrokeMaterial(); |
371 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | 434 | // var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); |
372 | this._primArray.push( strokePrim ); | 435 | // this._primArray.push( strokePrim ); |
373 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | 436 | // this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); |
374 | 437 | ||
375 | // fill | 438 | // fill |
376 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; | 439 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; |