aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/circle.js128
-rwxr-xr-xjs/lib/geom/geom-obj.js25
-rwxr-xr-xjs/lib/geom/line.js57
-rwxr-xr-xjs/lib/geom/rectangle.js131
-rw-r--r--js/lib/geom/shape-primitive.js181
5 files changed, 440 insertions, 82 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index e691f458..53847631 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -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
@@ -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 = [];
@@ -322,42 +337,48 @@ exports.Circle = Object.create(GeomObj, {
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 }
@@ -419,15 +440,37 @@ exports.Circle = Object.create(GeomObj, {
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)
445 {
446 if (material.hasVertexDeformation())
447 {
424 var paramRange = material.getVertexDeformationRange(); 448 var paramRange = material.getVertexDeformationRange();
425 var tolerance = material.getVertexDeformationTolerance(); 449 var tolerance = material.getVertexDeformationTolerance();
426 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance ); 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) );
427 } 461 }
428 } 462 }
429 463 else
430 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); 464 rtnArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
465 }
466 else
467 {
468 // create the RDGE primitive
469 rtnArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
470 }
471 }
472
473 return rtnArray;
431 } 474 }
432 }, 475 },
433 476
@@ -486,18 +529,39 @@ exports.Circle = Object.create(GeomObj, {
486 529
487 this.recalcTexMapCoords( vrts, uvs ); 530 this.recalcTexMapCoords( vrts, uvs );
488 531
489 /*
490 //refine the mesh for vertex deformations 532 //refine the mesh for vertex deformations
491 if (material) { 533 var rtnArray;
492 if (material.hasVertexDeformation()) { 534 if (material)
535 {
536 if (material.hasVertexDeformation())
537 {
493 var paramRange = material.getVertexDeformationRange(); 538 var paramRange = material.getVertexDeformationRange();
494 var tolerance = material.getVertexDeformationTolerance(); 539 var tolerance = material.getVertexDeformationTolerance();
495 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance ); 540 var nVertices = indices.length;
541 indices = ShapePrimitive.convertTriangleStripToTriangles( indices );
542 nVertices = ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, nVertices, paramRange, tolerance );
543 var subdividedParts = ShapePrimitive.subdivideOversizedMesh( vrts, nrms, uvs, indices );
544
545 rtnArray = [];
546 if (subdividedParts)
547 {
548 for (var i=0; i<subdividedParts.length; i++)
549 {
550 var obj = subdividedParts[i];
551 rtnArray.push( ShapePrimitive.create(obj.vertices, obj.normals, obj.uvs, obj.indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, obj.vertices.length/3) );
496 } 552 }
497 } 553 }
498 */ 554 else
499 555 rtnArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, nVertices) ];
500 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); 556 }
557 else
558 {
559 // create the RDGE primitive
560 rtnArray = [ ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length) ];
561 }
562 }
563
564 return rtnArray;
501 } 565 }
502 }, 566 },
503 567
@@ -883,7 +947,7 @@ exports.Circle = Object.create(GeomObj, {
883 if (uvs[iuv] > uMax) uMax = uvs[iuv]; 947 if (uvs[iuv] > uMax) uMax = uvs[iuv];
884 948
885 iuv++; ivrt++; 949 iuv++; ivrt++;
886 uvs[iuv] = (vrts[ivrt]-yMin)/ovalHeight; 950 uvs[iuv] = 1.0 - (vrts[ivrt]-yMin)/ovalHeight;
887