aboutsummaryrefslogtreecommitdiff
path: root/js/lib/geom
diff options
context:
space:
mode:
authorhwc4872012-05-25 17:02:43 -0700
committerhwc4872012-05-25 17:02:43 -0700
commit08e9abf8db06f714a95f0490d65c7337bed648b8 (patch)
treefa080c186bd924f74d862920f416c923a8283100 /js/lib/geom
parent725c2175f20b5e0829518f725fd26cc077748bdf (diff)
downloadninja-08e9abf8db06f714a95f0490d65c7337bed648b8.tar.gz
Added mesh refinement to circles.
Diffstat (limited to 'js/lib/geom')
-rwxr-xr-xjs/lib/geom/circle.js44
1 files changed, 32 insertions, 12 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js
index 4a369844..b2709ce4 100755
--- a/js/lib/geom/circle.js
+++ b/js/lib/geom/circle.js
@@ -295,39 +295,39 @@ exports.Circle = Object.create(GeomObj, {
295 if(this._strokeWidth > 0) { 295 if(this._strokeWidth > 0) {
296 var numStrokes = 1; 296 var numStrokes = 1;
297 if(this._innerRadius !== 0) { 297 if(this._innerRadius !== 0) {
298 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles); 298 strokeMaterial0 = this.makeStrokeMaterial();
299 strokePrim0 = this.generateOvalRing(x, y, reverseRotMat, innerStrokeScaleMat, innerRadiusScaleMat, nTriangles, strokeMaterial0);
299 } 300 }
300 301
301 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles); 302 strokeMaterial2 = this.makeStrokeMaterial();
303 strokePrim1 = this.generateOvalRing(x, y, reverseRotMat, fillScaleMat, strokeScaleMat, nTriangles, strokeMaterial2);
302 } 304 }
303 305
304 ///////////////////////////////////////////////////////////// 306 /////////////////////////////////////////////////////////////
305 // Fill 307 // Fill
308 fillMaterial = this.makeFillMaterial();
306 if(this._innerRadius === 0) { 309 if(this._innerRadius === 0) {
307 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles); 310 fillPrim = this.generateOval(x, y, mat, fillScaleMat, nTriangles, fillMaterial);
308 } else { 311 } else {
309 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles); 312 fillPrim = this.generateOvalRing(x, y, reverseRotMat, innerRadiusScaleMat, fillScaleMat, nTriangles, fillMaterial);
310 } 313 }
311 314
312 if (fillPrim) { 315 if (fillPrim) {
313 fillMaterial = this.makeFillMaterial(); 316 fillMaterial.fitToPrimitive( fillPrim );
314 fillMaterial.fitToPrimitive( fillPrim );
315 317
316 this._primArray.push( fillPrim ); 318 this._primArray.push( fillPrim );
317 this._materialNodeArray.push( fillMaterial.getMaterialNode() ); 319 this._materialNodeArray.push( fillMaterial.getMaterialNode() );
318 } 320 }
319 321
320 if (strokePrim0) { 322 if (strokePrim0) {
321 strokeMaterial0 = this.makeStrokeMaterial(); 323 strokeMaterial0.fitToPrimitive( strokePrim0 );
322 strokeMaterial0.fitToPrimitive( strokePrim0 );
323 324
324 this._primArray.push( strokePrim0 ); 325 this._primArray.push( strokePrim0 );
325 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() ); 326 this._materialNodeArray.push( strokeMaterial0.getMaterialNode() );
326 } 327 }
327 328
328 if (strokePrim1) { 329 if (strokePrim1) {
329 strokeMaterial2 = this.makeStrokeMaterial(); 330 strokeMaterial2.fitToPrimitive( strokePrim1 );
330 strokeMaterial2.fitToPrimitive( strokePrim1 );
331 331
332 this._primArray.push( strokePrim1 ); 332 this._primArray.push( strokePrim1 );
333 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() ); 333 this._materialNodeArray.push( strokeMaterial2.getMaterialNode() );
@@ -338,7 +338,7 @@ exports.Circle = Object.create(GeomObj, {
338 }, 338 },
339 339
340 generateOval: { 340 generateOval: {
341 value: function(xOff, yOff, rotationMat, scaleMat, nTriangles) { 341 value: function(xOff, yOff, rotationMat, scaleMat, nTriangles, material) {
342 var pt = [1.0, 0.0, 0.0]; 342 var pt = [1.0, 0.0, 0.0];
343 //var pts = scaleMat.multiply(pt); 343 //var pts = scaleMat.multiply(pt);
344 var pts = glmat4.multiplyVec3( scaleMat, pt, []); 344 var pts = glmat4.multiplyVec3( scaleMat, pt, []);
@@ -392,12 +392,21 @@ exports.Circle = Object.create(GeomObj, {
392 392
393 this.recalcTexMapCoords( vrts, uvs ); 393 this.recalcTexMapCoords( vrts, uvs );
394 394
395 //refine the mesh for vertex deformations
396 if (material) {
397 if (material.hasVertexDeformation()) {
398 var paramRange = material.getVertexDeformationRange();
399 var tolerance = material.getVertexDeformationTolerance();
400 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, vrts.length/3, paramRange, tolerance );
401 }
402 }
403
395 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index); 404 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLES, index);
396 } 405 }
397 }, 406 },
398 407
399 generateOvalRing: { 408 generateOvalRing: {
400 value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles) { 409 value: function(xOff, yOff, rotationMat, innerScaleMat, outerScaleMat, nTriangles, material) {
401 var pt = [1.0, 0.0, 0.0]; 410 var pt = [1.0, 0.0, 0.0];
402 411
403 var z = 0; 412 var z = 0;
@@ -451,6 +460,17 @@ exports.Circle = Object.create(GeomObj, {
451 460
452 this.recalcTexMapCoords( vrts, uvs ); 461 this.recalcTexMapCoords( vrts, uvs );
453 462
463 /*
464 //refine the mesh for vertex deformations
465 if (material) {
466 if (material.hasVertexDeformation()) {
467 var paramRange = material.getVertexDeformationRange();
468 var tolerance = material.getVertexDeformationTolerance();
469 ShapePrimitive.refineMesh( vrts, nrms, uvs, indices, indices.length, paramRange, tolerance );
470 }
471 }
472 */
473
454 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length); 474 return ShapePrimitive.create(vrts, nrms, uvs, indices, RDGE.globals.engine.getContext().renderer.TRIANGLE_STRIP, indices.length);
455 } 475 }
456 }, 476 },