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.js66
1 files changed, 46 insertions, 20 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 4a369844..6627b4b7 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -57,16 +57,18 @@ exports.Circle = Object.create(GeomObj, {
57 this.m_world = world; 57 this.m_world = world;
58 58
59 if(strokeMaterial) { 59 if(strokeMaterial) {
60 this._strokeMaterial = strokeMaterial; 60 this._strokeMaterial = strokeMaterial.dup();
61 } else { 61 } else {
62 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 62 this._strokeMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
63 } 63 }
64 if (strokeColor && this._strokeMaterial.hasProperty( "color" )) this._strokeMaterial.setProperty( "color", this._strokeColor );
64 65
65 if(fillMaterial) { 66 if(fillMaterial) {
66 this._fillMaterial = fillMaterial; 67 this._fillMaterial = fillMaterial.dup();
67 } else { 68 } else {
68 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 69 this._fillMaterial = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
69 } 70 }
71 if (fillColor && this._fillMaterial.hasProperty( "color" )) this._fillMaterial.setProperty( "color", this._fillColor );
70 } 72 }
71 }, 73 },
72 74
@@ -295,39 +297,39 @@ exports.Circle = Object.create(GeomObj, {
295 if(this._strokeWidth > 0) { 297 if(this._strokeWidth > 0) {
296 var numStrokes = 1; 298 var numStrokes = 1;
297 if(this._innerRadius !== 0) { 299 if(this._innerRadius !== 0) {
298 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles); 300 strokeMaterial0 = this.makeStrokeMaterial();
301 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0);
299 } 302 }
300 303
301 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles); 304 strokeMaterial2 = this.makeStrokeMaterial();
305 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2);
302 } 306 }
303 307
304 ///////////////////////////////////////////////////////////// 308 /////////////////////////////////////////////////////////////
305 // Fill 309 // Fill
310 fillMaterial = this.makeFillMaterial();
306 if(this._innerRadius === 0) { 311 if(this._innerRadius === 0) {
307 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles); 312 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial);
308 } else { 313 } else {
309 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles); 314 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial);
310 } 315 }
311 316
312 if (fillPrim) { 317 if (fillPrim) {
313 fillMaterial = this.makeFillMaterial(); 318 fillMaterial.fitToPrimitive( fillPrim );
314 fillMaterial.fitToPrimitive( fillPrim );
315 319
316 this._primArray.push( fillPrim ); 320 this._primArray.push( fillPrim );
317 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 321 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
318 } 322 }
319 323
320 if (strokePrim0) { 324 if (strokePrim0) {
321 strokeMaterial0 = this.makeStrokeMaterial(); 325 strokeMaterial0.fitToPrimitive( strokePrim0 );
322 strokeMaterial0.fitToPrimitive( strokePrim0 );
323 326
324 this._primArray.push( strokePrim0 ); 327 this._primArray.push( strokePrim0 );
325 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); 328 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() );
326 } 329 }
327 330
328 if (strokePrim1) { 331 if (strokePrim1) {
329 strokeMaterial2 = this.makeStrokeMaterial(); 332 strokeMaterial2.fitToPrimitive( strokePrim1 );
330 strokeMaterial2.fitToPrimitive( strokePrim1 );
331 333
332 this._primArray.push( strokePrim1 ); 334 this._primArray.push( strokePrim1 );
333 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); 335 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() );
@@ -338,7 +340,7 @@ exports.Circle = Object.create(GeomObj, {
338 }, 340 },
339 341
340 generateOval: { 342 generateOval: {
341 value: function(xOff, yOff, rotationMat, scaleMat, nTriangles) { 343 value: function(xOff, yOff, rotationMat, scaleMat, nTriangles, material) {
342 var pt = [1.0, 0.0, 0.0]; 344 var pt = [1.0, 0.0, 0.0];
343 //var pts = scaleMat.multiply(pt); 345 //var pts = scaleMat.multiply(pt);
344 var pts = glmat4.multiplyVec3( scaleMat, pt, []); 346 var pts = glmat4.multiplyVec3( scaleMat, pt, []);
@@ -392,12 +394,21 @@ exports.Circle = Object.create(GeomObj, {
392 394
393 this.recalcTexMapCoords( vrts, uvs ); 395 this.recalcTexMapCoords( vrts, uvs );
394 396
397 //refine the mesh for vertex deformations
398 if (material) {
399 if (material.hasVertexDeformation()) {
400 var paramRange = material.getVertexDeformationRange();
401 var tolerance = material.getVertexDeformationTolerance();
402 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance );
403 }
404 }
405
395 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); 406 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index);
396 } 407 }
397 }, 408 },
398 409
399 generateOvalRing: { 410 generateOvalRing: {
400 value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { 411 value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles, material) {
401 var pt = [1.0, 0.0, 0.0]; 412 var pt = [1.0, 0.0, 0.0];
402 413
403 var z = 0; 414 var z = 0;
@@ -451,6 +462,17 @@ exports.Circle = Object.create(GeomObj, {
451 462
452 this.recalcTexMapCoords( vrts, uvs ); 463 this.recalcTexMapCoords( vrts, uvs );
453 464
465 /*
466 //refine the mesh for vertex deformations
467 if (material) {
468 if (material.hasVertexDeformation()) {
469 var paramRange = material.getVertexDeformationRange();
470 var tolerance = material.getVertexDeformationTolerance();
471 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance );
472 }
473 }
474 */
475
454 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); 476 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length);
455 } 477 }
456 }, 478 },
@@ -682,19 +704,23 @@ exports.Circle = Object.create(GeomObj, {
682 var strokeMaterialName = jObj.strokeMat; 704 var strokeMaterialName = jObj.strokeMat;
683 var fillMaterialName = jObj.fillMat; 705 var fillMaterialName = jObj.fillMat;
684 706
685 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ); 707 var strokeMat = MaterialsModel.getMaterial( strokeMaterialName ).dup();
686 if (!strokeMat) { 708 if (!strokeMat) {
687 console.log( "object material not found in library: " + strokeMaterialName ); 709 console.log( "object material not found in library: " + strokeMaterialName );
688 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 710 strokeMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
689 } 711 }
690 this._strokeMaterial = strokeMat; 712 this._strokeMaterial = strokeMat;
713 if (this._strokeMaterial.hasProperty( 'color' ))
714 this._strokeMaterial.setProperty( 'color', this._strokeColor );
691 715
692 var fillMat = MaterialsModel.getMaterial( fillMaterialName ); 716 var fillMat = MaterialsModel.getMaterial( fillMaterialName ).dup();
693 if (!fillMat) { 717 if (!fillMat) {
694 console.log( "object material not found in library: " + fillMaterialName ); 718 console.log( "object material not found in library: " + fillMaterialName );
695 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ); 719 fillMat = MaterialsModel.getMaterial( MaterialsModel.getDefaultMaterialName() ).dup();
696 } 720 }
697 this._fillMaterial = fillMat; 721 this._fillMaterial = fillMat;
722 if (this._fillMaterial.hasProperty( 'color' ))
723 this._fillMaterial.setProperty( 'color', this._fillColor );
698 724
699 this.importMaterialsJSON( jObj.materials ); 725 this.importMaterialsJSON( jObj.materials );
700 } 726 }