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.js1248
1 files changed, 624 insertions, 624 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js
index ea12385f..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
@@ -121,12 +121,12 @@ exports.Rectangle = Object.create(GeomObj, {
121 this._fillMaterial.setProperty( "color", this._fillColor ); 121 this._fillMaterial.setProperty( "color", this._fillColor );
122 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) { 122 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) {
123 this._fillMaterial.setGradientData(this._fillColor.color); 123 this._fillMaterial.setGradientData(this._fillColor.color);
124 } 124 }
125 } 125 }
126 } 126 }
127 }, 127 },
128 128
129 /////////////////////////////////////////////////////////////////////// 129 ///////////////////////////////////////////////////////////////////////
130 // Property Accessors 130 // Property Accessors
131 /////////////////////////////////////////////////////////////////////// 131 ///////////////////////////////////////////////////////////////////////
132 // TODO - Use getters/setters in the future 132 // TODO - Use getters/setters in the future
@@ -165,7 +165,7 @@ exports.Rectangle = Object.create(GeomObj, {
165 this._fillMaterial = m; 165 this._fillMaterial = m;
166 } 166 }
167 }, 167 },
168 /////////////////////////////////////////////////////////////////////// 168 ///////////////////////////////////////////////////////////////////////
169 // update the "color of the material 169 // update the "color of the material
170 getFillColor: { 170 getFillColor: {
171 value: function() { 171 value: function() {
@@ -280,31 +280,31 @@ exports.Rectangle = Object.create(GeomObj, {
280 } 280 }
281 }, 281 },
282 282
283 /////////////////////////////////////////////////////////////////////// 283 ///////////////////////////////////////////////////////////////////////
284 // Methods 284 // Methods
285 /////////////////////////////////////////////////////////////////////// 285 ///////////////////////////////////////////////////////////////////////
286 // JSON export 286 // JSON export
287 exportJSON: { 287 exportJSON: {
288 value: function() { 288 value: function() {
289 var jObj = 289 var jObj =
290 { 290 {
291 'type' : this.geomType(), 291 'type' : this.geomType(),
292 'xoff' : this._xOffset, 292 'xoff' : this._xOffset,
293 'yoff' : this._yOffset, 293 'yoff' : this._yOffset,
294 'width' : this._width, 294 'width' : this._width,
295 'height' : this._height, 295 'height' : this._height,
296 'strokeWidth' : this._strokeWidth, 296 'strokeWidth' : this._strokeWidth,
297 'strokeColor' : this._strokeColor, 297 'strokeColor' : this._strokeColor,
298 'fillColor' : this._fillColor, 298 'fillColor' : this._fillColor,
299 'tlRadius' : this._tlRadius, 299 'tlRadius' : this._tlRadius,
300 'trRadius' : this._trRadius, 300 'trRadius' : this._trRadius,
301 'blRadius' : this._blRadius, 301 'blRadius' : this._blRadius,
302 'brRadius' : this._brRadius, 302 'brRadius' : this._brRadius,
303 'innerRadius' : this._innerRadius, 303 'innerRadius' : this._innerRadius,
304 'strokeStyle' : this._strokeStyle, 304 'strokeStyle' : this._strokeStyle,
305 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 305 'strokeMat' : this._strokeMaterial ? this._strokeMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
306 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(), 306 'fillMat' : this._fillMaterial ? this._fillMaterial.getName() : MaterialsModel.getDefaultMaterialName(),
307 'materials' : this.exportMaterialsJSON() 307 'materials' : this.exportMaterialsJSON()
308 }; 308 };
309 309
310 return jObj; 310 return jObj;
@@ -313,21 +313,21 @@ exports.Rectangle = Object.create(GeomObj, {
313 313
314 importJSON: { 314 importJSON: {
315 value: function(jObj) { 315 value: function(jObj) {
316 this._xOffset = jObj.xoff; 316 this._xOffset = jObj.xoff;
317 this._yOffset = jObj.yoff; 317 this._yOffset = jObj.yoff;
318 this._width = jObj.width; 318 this._width = jObj.width;
319 this._height = jObj.height; 319 this._height = jObj.height;
320 this._strokeWidth = jObj.strokeWidth; 320 this._strokeWidth = jObj.strokeWidth;
321 this._strokeColor = jObj.strokeColor; 321 this._strokeColor = jObj.strokeColor;
322 this._fillColor = jObj.fillColor; 322 this._fillColor = jObj.fillColor;
323 this._tlRadius = jObj.tlRadius; 323 this._tlRadius = jObj.tlRadius;
324 this._trRadius = jObj.trRadius; 324 this._trRadius = jObj.trRadius;
325 this._blRadius = jObj.blRadius; 325 this._blRadius = jObj.blRadius;
326 this._brRadius = jObj.brRadius; 326 this._brRadius = jObj.brRadius;
327 this._innerRadius = jObj.innerRadius; 327 this._innerRadius = jObj.innerRadius;
328 this._strokeStyle = jObj.strokeStyle; 328 this._strokeStyle = jObj.strokeStyle;
329 var strokeMaterialName = jObj.strokeMat; 329 var strokeMaterialName = jObj.strokeMat;
330 var fillMaterialName = jObj.fillMat; 330 var fillMaterialName = jObj.fillMat;
331 331
332 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup(); 332 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup();
333 if (!strokeMat) { 333 if (!strokeMat) {
@@ -335,8 +335,8 @@ exports.Rectangle = Object.create(GeomObj, {
335 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 335 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
336 } 336 }
337 this._strokeMaterial = strokeMat; 337 this._strokeMaterial = strokeMat;
338 if (this._strokeMaterial.hasProperty( 'color' )) 338 if (this._strokeMaterial.hasProperty( 'color' ))
339 this._strokeMaterial.setProperty( 'color', this._strokeColor ); 339 this._strokeMaterial.setProperty( 'color', this._strokeColor );
340 340
341 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup(); 341 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup();
342 if (!fillMat) { 342 if (!fillMat) {
@@ -344,112 +344,112 @@ exports.Rectangle = Object.create(GeomObj, {
344 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 344 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
345 } 345 }
346 this._fillMaterial = fillMat; 346 this._fillMaterial = fillMat;
347 if (this._fillMaterial.hasProperty( 'color' )) 347 if (this._fillMaterial.hasProperty( 'color' ))
348 this._fillMaterial.setProperty( 'color', this._fillColor ); 348 this._fillMaterial.setProperty( 'color', this._fillColor );
349 349
350 this.importMaterialsJSON( jObj.materials ); 350 this.importMaterialsJSON( jObj.materials );
351 } 351 }
352 }, 352 },
353 353
354 buildBuffers: { 354 buildBuffers: {
355 value: function() { 355 value: function() {
356 // get the world 356 // get the world
357 var world = this.getWorld(); 357 var world = this.getWorld();
358 if (!world) throw( "null world in buildBuffers" ); 358 if (!world) throw( "null world in buildBuffers" );
359 //console.log( "GLRectangle.buildBuffers " + world._worldCount ); 359 //console.log( "GLRectangle.buildBuffers " + world._worldCount );
360 if (!world._useWebGL) return; 360 if (!world._useWebGL) return;
361 361
362 // make sure RDGE has the correct context 362 // make sure RDGE has the correct context
363 RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); 363 RDGE.globals.engine.setContext( world.getCanvas().rdgeid );
364 364
365 // create the gl buffer 365 // create the gl buffer
366 var gl = world.getGLContext(); 366 var gl = world.getGLContext();
367 367
368 var tlRadius = this._tlRadius; //top-left radius 368 var tlRadius = this._tlRadius; //top-left radius
369 var trRadius = this._trRadius; 369 var trRadius = this._trRadius;
370 var blRadius = this._blRadius; 370 var blRadius = this._blRadius;
371 var brRadius = this._brRadius; 371 var brRadius = this._brRadius;
372 372
373 // declare the arrays to hold the parts 373 // declare the arrays to hold the parts
374 this._primArray = []; 374 this._primArray = [];
375 this._materialArray = []; 375 this._materialArray = [];
376 this._materialTypeArray = []; 376 this._materialTypeArray = [];
377 this._materialNodeArray = []; 377 this._materialNodeArray = [];
378 378
379 // get the normalized device coordinates (NDC) for 379 // get the normalized device coordinates (NDC) for
380 // all position and dimensions. 380 // all position and dimensions.
381 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 381 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
382 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, 382 var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph,
383 xFillNDC = this._width/vpw, yFillNDC = this._height/vph, 383 xFillNDC = this._width/vpw, yFillNDC = this._height/vph,