aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom/circle.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom/circle.js')
-rwxr-xr-xjs/lib/geom/circle.js298
1 files changed, 181 insertions, 117 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 39cde514..53847631 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -31,14 +31,14 @@ POSSIBILITY OF SUCH DAMAGE.
31var GeomObj = require("js/lib/geom/geom-obj").GeomObj; 31var GeomObj = require("js/lib/geom/geom-obj").GeomObj;
32var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; 32var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive;
33var MaterialsModel = require("js/models/materials-model").MaterialsModel; 33var MaterialsModel = require("js/models/materials-model").MaterialsModel;
34var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; 34var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils;
35var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 35var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
36 36
37/////////////////////////////////////////////////////////////////////// 37///////////////////////////////////////////////////////////////////////
38// Class GLCircle 38// Class GLCircle
39// GL representation of a circle. 39// GL representation of a circle.
40// Derived from class GLGeomObj 40// Derived from class GLGeomObj
41// The position and dimensions of the stroke, fill, and inner Radius should be in pixels 41// The position and dimensions of the stroke, fill, and inner Radius should be in pixels
42/////////////////////////////////////////////////////////////////////// 42///////////////////////////////////////////////////////////////////////
43exports.Circle = Object.create(GeomObj, { 43exports.Circle = Object.create(GeomObj, {
44 44
@@ -57,7 +57,7 @@ exports.Circle = Object.create(GeomObj, {
57 _strokeStyle: { value : "Solid", writable: true }, 57 _strokeStyle: { value : "Solid", writable: true },
58 _aspectRatio: { value : 1.0, writable: true }, 58 _aspectRatio: { value : 1.0, writable: true },
59 59
60 init: { 60 init: {
61 value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) { 61 value: function(world, xOffset, yOffset, width, height, strokeSize, strokeColor, fillColor, innerRadius, strokeMaterial, fillMaterial, strokeStyle) {
62 if(arguments.length > 0) { 62 if(arguments.length > 0) {
63 this._width = width; 63 this._width = width;
@@ -85,14 +85,28 @@ exports.Circle = Object.create(GeomObj, {
85 } else { 85 } else {
86 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 86 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
87 } 87 }
88 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor ); 88
89 if(strokeColor) {
90 if(this._strokeMaterial.hasProperty("color")) {
91 this._strokeMaterial.setProperty( "color", this._strokeColor );
92 } else if (this._strokeMaterial && (this._strokeMaterial.gradientType === this._strokeColor.gradientMode)) {
93 this._strokeMaterial.setGradientData(this._strokeColor.color);
94 }
95 }
89 96
90 if(fillMaterial) { 97 if(fillMaterial) {
91 this._fillMaterial = fillMaterial.dup(); 98 this._fillMaterial = fillMaterial.dup();
92 } else { 99 } else {
93 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup(); 100 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
94 } 101 }
95 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor ); 102
103 if(fillColor) {
104 if(this._fillMaterial.hasProperty("color")) {
105 this._fillMaterial.setProperty( "color", this._fillColor );
106 } else if (this._fillMaterial && (this._fillMaterial.gradientType === this._fillColor.gradientMode)) {
107 this._fillMaterial.setGradientData(this._fillColor.color);
108 }
109 }
96 } 110 }
97 }, 111 },
98 112
@@ -203,7 +217,7 @@ exports.Circle = Object.create(GeomObj, {
203 }, 217 },
204 218
205 /////////////////////////////////////////////////////////////////////// 219 ///////////////////////////////////////////////////////////////////////
206 // update the "color of the material 220 // update the "color of the material
207 getFillColor: { 221 getFillColor: {
208 value: function() { 222 value: function() {
209 return this._fillColor; 223 return this._fillColor;
@@ -251,15 +265,15 @@ exports.Circle = Object.create(GeomObj, {
251 265
252 // get the normalized device coordinates (NDC) for 266 // get the normalized device coordinates (NDC) for
253 // all position and dimensions. 267 // all position and dimensions.
254 var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); 268 var vpw = world.getViewportWidth(), vph = world.getViewportHeight();
255 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph, 269 var xNDC = 2*this._xOffset/vpw, yNDC = -2*this._yOffset/vph,
256 xRadNDC = this._width/vpw, yRadNDC = this._height/vph, 270 xRadNDC = this._width/vpw, yRadNDC = this._height/vph,
257 xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph, 271 xStrokeNDC = 2*this._strokeWidth/vpw, yStrokeNDC = 2*this._strokeWidth/vph,
258 xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC; 272 xInnRadNDC = this._innerRadius*xRadNDC, yInnRadNDC = this._innerRadius*yRadNDC;
259 273
260 var aspect = world.getAspect(); 274 var aspect = world.getAspect();
261 var zn = world.getZNear(), zf = world.getZFar(); 275 var zn = world.getZNear(), zf = world.getZFar();
262 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), 276 var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0),
263 b = -t, 277 b = -t,
264 r = aspect*t, 278 r = aspect*t,
265 l = -r; 279 l = -r;
@@ -308,7 +322,8 @@ exports.Circle = Object.create(GeomObj, {
308 innerStrokeScaleMat[0] = xInnRad - xStroke; 322 innerStrokeScaleMat[0] = xInnRad - xStroke;
309 innerStrokeScaleMat[5] = yInnRad - yStroke; 323 innerStrokeScaleMat[5] = yInnRad - yStroke;
310 324
311 var fillPrim, strokePrim0, strokePrim1; 325 var i;
326 var fillPrimArray, strokePrim0Array, strokePrim1Array;
312 var fillMaterial, strokeMaterial0, strokeMaterial2; 327 var fillMaterial, strokeMaterial0, strokeMaterial2;
313 328
314 this._primArray = []; 329 this._primArray = [];
@@ -321,43 +336,49 @@ exports.Circle = Object.create(GeomObj, {
321 if(this._strokeWidth > 0) { 336 if(this._strokeWidth > 0) {
322 var numStrokes = 1; 337 var numStrokes = 1;
323 if(this._innerRadius !== 0) { 338 if(this._innerRadius !== 0) {
324 strokeMaterial0 = this.makeStrokeMaterial(); 339 strokeMaterial0 = this.makeStrokeMaterial();
325 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0); 340 strokePrim0Array = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0);
326 } 341 }
327 342
328 strokeMaterial2 = this.makeStrokeMaterial(); 343 strokeMaterial2 = this.makeStrokeMaterial();
329 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2); 344 strokePrim1Array = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2);
330 } 345 }
331 346
332 if (strokePrim0) { 347 if (strokePrim0Array) {
333 strokeMaterial0.fitToPrimitive( strokePrim0 ); 348 strokeMaterial0.fitToPrimitiveArray( strokePrim0Array );
334 349 for (i=0; i<strokePrim0Array.length; i++)
335 this._primArray.push( strokePrim0 ); 350 {
351 this._primArray.push( strokePrim0Array[i] );
336 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); 352 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() );
337 } 353 }
354 }
338 355
339 if (strokePrim1) { 356 if (strokePrim1Array) {
340 strokeMaterial2.fitToPrimitive( strokePrim1 ); 357 strokeMaterial2.fitToPrimitiveArray( strokePrim1Array );
341 358 for (i=0; i<strokePrim1Array.length; i++)
342 this._primArray.push( strokePrim1 ); 359 {
360 this._primArray.push( strokePrim1Array[i] );
343 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); 361 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() );
344 } 362 }
363 }
345 364
346 ///////////////////////////////////////////////////////////// 365 /////////////////////////////////////////////////////////////
347 // Fill 366 // Fill
348 fillMaterial = this.makeFillMaterial(); 367 fillMaterial = this.makeFillMaterial();
349 if(this._innerRadius === 0) { 368 if(this._innerRadius === 0) {
350 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial); 369 fillPrimArray = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial);
351 } else { 370 } else {
352 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial); 371 fillPrimArray = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial);
353 } 372 }
354 373
355 if (fillPrim) { 374 if (fillPrimArray) {
356 fillMaterial.fitToPrimitive( fillPrim ); 375 fillMaterial.fitToPrimitiveArray( fillPrimArray );
357 376 for (i=0; i<fillPrimArray.length; i++)
358 this._primArray.push( fillPrim ); 377 {
378 this._primArray.push( fillPrimArray[i] );
359 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 379 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
360 } 380 }
381 }
361 382
362 world.updateObject(this); 383 world.updateObject(this);
363 } 384 }
@@ -371,7 +392,7 @@ exports.Circle = Object.create(GeomObj, {
371 var x = pts[0], y = pts[1], z = 0; 392 var x = pts[0], y = pts[1], z = 0;
372 var xs = scaleMat[0], ys = scaleMat[4]; 393 var xs = scaleMat[0], ys = scaleMat[4];
373 394
374 var vrts = [], nrms = [], uvs = [], indices = []; 395 var vrts = [], nrms = [], uvs = [], indices = [];
375 var index = 0; 396 var index = 0;
376 for (var i=0; i<nTriangles; i++) { 397 for (var i=0; i<nTriangles; i++) {
377 //pt = rotationMat.multiply( pt ); 398 //pt = rotationMat.multiply( pt );
@@ -418,16 +439,38 @@ exports.Circle = Object.create(GeomObj, {
418 439
419 this.recalcTexMapCoords( vrts, uvs ); 440 this.recalcTexMapCoords( vrts, uvs );
420 441
421 //refine the mesh for vertex deformations 442 //refine the mesh for vertex deformations
422 if (material) { 443 var rtnArray;
423 if (material.hasVertexDeformation()) { 444 if (material)
424 var paramRange = material.getVertexDeformationRange(); 445 {
425 var tolerance = material.getVertexDeformationTolerance(); 446 if (material.hasVertexDeformation())
426 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance ); 447 {
448 var paramRange = material.getVertexDeformationRange();
449 var tolerance = material.getVertexDeformationTolerance();
450 var nVertices = vrts.length/3
451 nVertices = ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, nVertices, paramRange, tolerance );
452 var subdividedParts = ShapePrimitive.subdivideOversizedMesh( vrts, nrms, uvs, indices );
453
454 rtnArray = [];
455 if (subdividedParts)
456 {
457 for (var i=0; i<subdividedParts.length; i++)
458 {
459 var obj = subdividedParts[i];
460 rtnArray.push( ShapePrimitive.create(obj.vertices, obj.normals, obj.uvs, obj.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, obj.vertices.length/3) );
461 }
462 }
463 else
464 rtnArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().re