aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/rectangle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-xjs/lib/geom/rectangle.js1187
1 files changed, 637 insertions, 550 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index 0d302d50..cfa6aae5 100755
--- a/js/lib/geom/rectangle.js
+++ b/js/lib/geom/rectangle.js
@@ -38,15 +38,15 @@ var MaterialsModel = require("js/models/materials-model").MaterialsModel;
38// Derived from class GeomObj 38// Derived from class GeomObj
39/////////////////////////////////////////////////////////////////////// 39///////////////////////////////////////////////////////////////////////
40exports.Rectangle = Object.create(GeomObj, { 40exports.Rectangle = Object.create(GeomObj, {
41 // CONSTANTS 41 // CONSTANTS
42 N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove? 42 N_TRIANGLES: { value : 15, writable: false }, // TODO - This is not being used anywhere. Remove?
43 43
44 //if (!MaterialsModel) 44 //if (!MaterialsModel)
45 // MaterialsModel = require("js/models/materials-model").MaterialsModel; 45 // MaterialsModel = require("js/models/materials-model").MaterialsModel;
46 46
47 /////////////////////////////////////////////////////////////////////// 47 ///////////////////////////////////////////////////////////////////////
48 // Instance variables 48 // Instance variables
49 /////////////////////////////////////////////////////////////////////// 49 ///////////////////////////////////////////////////////////////////////
50 _width: { value : 2.0, writable: true }, 50 _width: { value : 2.0, writable: true },
51 _height: { value : 2.0, writable: true }, 51 _height: { value : 2.0, writable: true },
52 _xOffset: { value : 0, writable: true }, 52 _xOffset: { value : 0, writable: true },
@@ -82,7 +82,7 @@ exports.Rectangle = Object.create(GeomObj, {
82 82
83 this._strokeStyle = strokeStyle; 83 this._strokeStyle = strokeStyle;
84 84
85 this._matrix = Matrix.I(4); 85 this._matrix = Matrix.I(4);
86 } 86 }
87 87
88 // the overall radius includes the fill and the stroke. separate the two based on the stroke width 88 // the overall radius includes the fill and the stroke. separate the two based on the stroke width
@@ -101,19 +101,32 @@ exports.Rectangle = Object.create(GeomObj, {
101 } else { 101 } else {
102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 102 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
103 } 103 }
104 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor );
105 104
105 if(strokeColor) {
106 if(this._strokeMaterial.hasProperty("color")) {
107 this._strokeMaterial.setProperty( "color", this._strokeColor );
108 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
109 this._strokeMaterial.setGradientData(this._strokeColor.color);
110 }
111 }
106 112
107 if(fillMaterial) { 113 if(fillMaterial) {
108 this._fillMaterial = fillMaterial.dup(); 114 this._fillMaterial = fillMaterial.dup();
109 } else { 115 } else {
110 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 116 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
111 } 117 }
112 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); 118
119 if(fillColor) {
120 if(this._fillMaterial.hasProperty("color")) {
121 this._fillMaterial.setProperty( "color", this._fillColor );
122 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) {
123 this._fillMaterial.setGradientData(this._fillColor.color);
124 }
125 }
113 } 126 }
114 }, 127 },
115 128
116 /////////////////////////////////////////////////////////////////////// 129 ///////////////////////////////////////////////////////////////////////
117 // Property Accessors 130 // Property Accessors
118 /////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////
119 // TODO - Use getters/setters in the future 132 // TODO - Use getters/setters in the future
@@ -152,7 +165,7 @@ exports.Rectangle = Object.create(GeomObj, {
152 this._fillMaterial = m; 165 this._fillMaterial = m;
153 } 166 }
154 }, 167 },
155 /////////////////////////////////////////////////////////////////////// 168 ///////////////////////////////////////////////////////////////////////
156 // update the "color of the material 169 // update the "color of the material
157 getFillColor: { 170 getFillColor: {
158 value: function() { 171 value: function() {
@@ -267,31 +280,31 @@ exports.Rectangle = Object.create(GeomObj, {
267 } 280 }
268 }, 281 },
269 282
270 /////////////////////////////////////////////////////////////////////// 283 ///////////////////////////////////////////////////////////////////////
271 // Methods 284 // Methods
272 /////////////////////////////////////////////////////////////////////// 285 ///////////////////////////////////////////////////////////////////////
273 // JSON export 286 // JSON export
274 exportJSON: { 287 exportJSON: {
275 value: function() { 288 value: function() {
276 var jObj = 289 var jObj =
277 { 290 {
278 'type' : this.geomType(), 291 'type' : this.geomType(),
279 'xoff' : this._xOffset, 292 'xoff' : this._xOffset,
280 'yoff' : this._yOffset, 293 'yoff' : this._yOffset,
281 'width' : this._width, 294 'width' : this._width,
282 'height' : this._height, 295 'height' : this._height,
283 'strokeWidth' : this._strokeWidth, 296 'strokeWidth' : this._strokeWidth,
284 'strokeColor' : this._strokeColor, 297 'strokeColor' : this._strokeColor,
285 'fillColor' : this._fillColor, 298 'fillColor' : this._fillColor,
286 'tlRadius' : this._tlRadius, 299 'tlRadius' : this._tlRadius,
287 'trRadius' : this._trRadius, 300 'trRadius' : this._trRadius,
288 'blRadius' : this._blRadius, 301 'blRadius' : this._blRadius,
289 'brRadius' : this._brRadius, 302 'brRadius' : this._brRadius,
290 'innerRadius' : this._innerRadius, 303 'innerRadius' : this._innerRadius,
291 'strokeStyle' : this._strokeStyle, 304 'strokeStyle' : this._strokeStyle,
292 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 305 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
293 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 306 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
294 'materials' : this.exportMaterialsJSON() 307 'materials' : this.exportMaterialsJSON()
295 }; 308 };
296 309
297 return jObj; 310 return jObj;
@@ -300,21 +313,21 @@ exports.Rectangle = Object.create(GeomObj, {
300 313
301 importJSON: { 314 importJSON: {
302 value: function(jObj) { 315 value: function(jObj) {
303 this._xOffset = jObj.xoff; 316 this._xOffset = jObj.xoff;
304 this._yOffset = jObj.yoff; 317 this._yOffset = jObj.yoff;
305 this._width = jObj.width; 318 this._width = jObj.width;
306 this._height = jObj.height; 319 this._height = jObj.height;
307 this._strokeWidth = jObj.strokeWidth; 320 this._strokeWidth = jObj.strokeWidth;
308 this._strokeColor = jObj.strokeColor; 321 this._strokeColor = jObj.strokeColor;
309 this._fillColor = jObj.fillColor; 322 this._fillColor = jObj.fillColor;
310 this._tlRadius = jObj.tlRadius; 323 this._tlRadius = jObj.tlRadius;
311 this._trRadius = jObj.trRadius; 324 this._trRadius = jObj.trRadius;
312 this._blRadius = jObj.blRadius; 325 this._blRadius = jObj.blRadius;
313 this._brRadius = jObj.brRadius; 326 this._brRadius = jObj.brRadius;
314 this._innerRadius = jObj.innerRadius; 327 this._innerRadius = jObj.innerRadius;
315 this._strokeStyle = jObj.strokeStyle; 328 this._strokeStyle = jObj.strokeStyle;
316 var strokeMaterialName = jObj.strokeMat; 329 var strokeMaterialName = jObj.strokeMat;
317 var fillMaterialName = jObj.fillMat; 330 var fillMaterialName = jObj.fillMat;
318 331
319 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); 332 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup();
320 if (!strokeMat) { 333 if (!strokeMat) {
@@ -322,8 +335,8 @@ exports.Rectangle = Object.create(GeomObj, {
322 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 335 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
323 } 336 }
324 this._strokeMaterial = strokeMat; 337 this._strokeMaterial = strokeMat;
325 if (this._strokeMaterial.hasProperty( 'color' )) 338 if (this._strokeMaterial.hasProperty( 'color' ))
326 this._strokeMaterial.setProperty( 'color', this._strokeColor ); 339 this._strokeMaterial.setProperty( 'color', this._strokeColor );
327 340
328 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); 341 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup();
329 if (!fillMat) { 342 if (!fillMat) {
@@ -331,8 +344,8 @@ exports.Rectangle = Object.create(GeomObj, {
331 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 344 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
332 } 345 }
333 this._fillMaterial = fillMat; 346 this._fillMaterial = fillMat;
334 if (this._fillMaterial.hasProperty( 'color' )) 347 if (this._fillMaterial.hasProperty( 'color' ))
335 this._fillMaterial.setProperty( 'color', this._fillColor ); 348 this._fillMaterial.setProperty( 'color', this._fillColor );
336 349
337 this.importMaterialsJSON( jObj.materials ); 350 this.importMaterialsJSON( jObj.materials );
338 } 351 }
@@ -407,11 +420,15 @@ exports.Rectangle = Object.create(GeomObj, {
407 brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; 420 brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC;
408 421
409 // stroke 422 // stroke
423 var i;
410 var strokeMaterial = this.makeStrokeMaterial(); 424 var strokeMaterial = this.makeStrokeMaterial();
411 var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); 425 var strokePrimArray = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial);
412 strokeMaterial.fitToPrimitive( strokePrim ); 426 strokeMaterial.fitToPrimitiveArray( strokePrimArray );
413 this._primArray.push( strokePrim ); 427 for (i=0; i<strokePrimArray.length; i++)
428 {
429 this._primArray.push( strokePrimArray[i] );
414 this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); 430 this._materialNodeArray.push( strokeMaterial.getMaterialNode() );
431 }
415 432
416 // fill 433 // fill
417 tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; 434 tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0;
@@ -422,10 +439,13 @@ exports.Rectangle = Object.create(GeomObj, {
422 yFill -= strokeSize; 439 yFill -= strokeSize;
423 var fillMaterial = this.makeFillMaterial(); 440 var fillMaterial = this.makeFillMaterial();
424 //console.log( "fillMaterial: " + fillMaterial.getName() ); 441 //console.log( "fillMaterial: " + fillMaterial.getName() );
425 var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); 442 var fillPrimArray = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial);
426 fillMaterial.fitToPrimitive( fillPrim ); 443 fillMaterial.fitToPrimitiveArray( fillPrimArray );
427