diff options
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 286 |
1 files changed, 180 insertions, 106 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 6a6ede4d..ea12385f 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -351,98 +351,105 @@ exports.Rectangle = Object.create(GeomObj, { | |||
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, |
384 | strokeSizeNDC = 2*this._strokeWidth/vpw, | 384 | strokeSizeNDC = 2*this._strokeWidth/vpw, |
385 | tlRadiusNDC = 2*tlRadius/vpw, yTLRadiusNDC = 2*tlRadius/vph, | 385 | tlRadiusNDC = 2*tlRadius/vpw, yTLRadiusNDC = 2*tlRadius/vph, |
386 | trRadiusNDC = 2*trRadius/vpw, yTRRadiusNDC = 2*trRadius/vph, | 386 | trRadiusNDC = 2*trRadius/vpw, yTRRadiusNDC = 2*trRadius/vph, |
387 | blRadiusNDC = 2*blRadius/vpw, yBLRadiusNDC = 2*blRadius/vph, | 387 | blRadiusNDC = 2*blRadius/vpw, yBLRadiusNDC = 2*blRadius/vph, |
388 | brRadiusNDC = 2*brRadius/vpw, yBRRadiusNDC = 2*brRadius/vph; | 388 | brRadiusNDC = 2*brRadius/vpw, yBRRadiusNDC = 2*brRadius/vph; |
389 | 389 | ||
390 | var aspect = world.getAspect(); | 390 | var aspect = world.getAspect(); |
391 | var zn = world.getZNear(), zf = world.getZFar(); | 391 | var zn = world.getZNear(), zf = world.getZFar(); |
392 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), | 392 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), |
393 | b = -t, | 393 | b = -t, |
394 | r = aspect*t, | 394 | r = aspect*t, |
395 | l = -r; | 395 | l = -r; |
396 | |||
397 | // calculate the object coordinates from their NDC coordinates | ||
398 | var z = -world.getViewDistance(); | ||
399 | |||
400 | // get the position of the origin | ||
401 | var x = -z*(r-l)/(2.0*zn)*xNDC, | ||
402 | y = -z*(t-b)/(2.0*zn)*yNDC; | ||
403 | |||
404 | // get the x and y fill | ||
405 | var xFill = -z*(r-l)/(2.0*zn)*xFillNDC, | ||
406 | yFill = -z*(t-b)/(2.0*zn)*yFillNDC; | ||
407 | |||
408 | // keep some variables giving the overall dimensions of the | ||
409 | // rectangle. These values are used to calculate consistent | ||
410 | // texture map coordinates across all pieces. | ||
411 | this._rectWidth = xFill; this._rectHeight = yFill; | ||
412 | |||
413 | // get the stroke size | ||
414 | var strokeSize = -z*(r-l)/(2.0*zn)*strokeSizeNDC; | ||
415 | |||
416 | // get the absolute corner radii | ||
417 | tlRadius = -z*(r-l)/(2.0*zn)*tlRadiusNDC, | ||
418 | trRadius = -z*(r-l)/(2.0*zn)*trRadiusNDC, | ||
419 | blRadius = -z*(r-l)/(2.0*zn)*blRadiusNDC, | ||
420 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | ||
421 | |||
422 | // stroke | ||
423 | var i; | ||
424 | var strokeMaterial = this.makeStrokeMaterial(); | ||
425 | var strokePrimArray = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | ||
426 | strokeMaterial.fitToPrimitiveArray( strokePrimArray ); | ||
427 | for (i=0; i<strokePrimArray.length; i++) | ||
428 | { | ||
429 | this._primArray.push( strokePrimArray[i] ); | ||
430 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | ||
431 | } | ||
396 | 432 | ||
397 | // calculate the object coordinates from their NDC coordinates | 433 | // fill |
398 | var z = -world.getViewDistance(); | 434 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; |
435 | blRadius -= strokeSize; if (blRadius < 0) blRadius = 0.0; | ||
436 | brRadius -= strokeSize; if (brRadius < 0) brRadius = 0.0; | ||
437 | trRadius -= strokeSize; if (trRadius < 0) trRadius = 0.0; | ||
438 | xFill -= strokeSize; | ||
439 | yFill -= strokeSize; | ||
440 | var fillMaterial = this.makeFillMaterial(); | ||
441 | //console.log( "fillMaterial: " + fillMaterial.getName() ); | ||
442 | var fillPrimArray = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); | ||
443 | fillMaterial.fitToPrimitiveArray( fillPrimArray ); | ||
444 | for (i=0; i<fillPrimArray.length; i++) | ||
445 | { | ||
446 | this._primArray.push( fillPrimArray[i] ); | ||
447 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | ||
448 | } | ||
399 | 449 | ||
400 | // get the position of the origin | 450 | world.updateObject(this); |
401 | var x = -z*(r-l)/(2.0*zn)*xNDC, | 451 | } |
402 | y = -z*(t-b)/(2.0*zn)*yNDC; | 452 | }, |
403 | |||
404 | // get the x and y fill | ||
405 | var xFill = -z*(r-l)/(2.0*zn)*xFillNDC, | ||
406 | yFill = -z*(t-b)/(2.0*zn)*yFillNDC; | ||
407 | |||
408 | // keep some variables giving the overall dimensions of the | ||
409 | // rectangle. These values are used to calculate consistent | ||
410 | // texture map coordinates across all pieces. | ||
411 | this._rectWidth = xFill; this._rectHeight = yFill; | ||
412 | |||
413 | // get the stroke size | ||
414 | var strokeSize = -z*(r-l)/(2.0*zn)*strokeSizeNDC; | ||
415 | |||
416 | // get the absolute corner radii | ||
417 | tlRadius = -z*(r-l)/(2.0*zn)*tlRadiusNDC, | ||
418 | trRadius = -z*(r-l)/(2.0*zn)*trRadiusNDC, | ||
419 | blRadius = -z*(r-l)/(2.0*zn)*blRadiusNDC, | ||
420 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | ||
421 | |||
422 | // stroke | ||
423 | var strokeMaterial = this.makeStrokeMaterial(); | ||
424 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | ||
425 | strokeMaterial.fitToPrimitive( strokePrim ); | ||
426 | this._primArray.push( strokePrim ); | ||
427 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | ||
428 | |||
429 | // fill | ||
430 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; | ||
431 | blRadius -= strokeSize; if (blRadius < 0) blRadius = 0.0; | ||
432 | brRadius -= strokeSize; if (brRadius < 0) brRadius = 0.0; | ||
433 | trRadius -= strokeSize; if (trRadius < 0) trRadius = 0.0; | ||
434 | xFill -= strokeSize; | ||
435 | yFill -= strokeSize; | ||
436 | var fillMaterial = this.makeFillMaterial(); | ||
437 | //console.log( "fillMaterial: " + fillMaterial.getName() ); | ||
438 | var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); | ||
439 | fillMaterial.fitToPrimitive( fillPrim ); | ||
440 | this._primArray.push( fillPrim ); | ||
441 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | ||
442 | |||
443 | world.updateObject(this); | ||
444 | } | ||
445 | }, | ||
446 | 453 | ||
447 | renderQuadraticBezier: { | 454 | renderQuadraticBezier: { |
448 | value: function(bPts, ctx) { | 455 | value: function(bPts, ctx) { |
@@ -658,15 +665,17 @@ exports.Rectangle = Object.create(GeomObj, { | |||
658 | value: function(ctr, width, height, tlRad, blRad, brRad, trRad, material) { | 665 | value: function(ctr, width, height, tlRad, blRad, brRad, trRad, material) { |
659 | // create the geometry | 666 | // create the geometry |
660 | // special the (common) case of no rounded corners | 667 | // special the (common) case of no rounded corners |
661 | var prim; | 668 | var primArray; |
662 | 669 | ||
663 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { | 670 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { |
664 | prim = RectangleGeometry.create( ctr, width, height, material ); | 671 | primArray = RectangleGeometry.create( ctr, width, height, material ); |
665 | } else { | 672 | } else { |
666 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); | 673 | primArray = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); |
667 | } | 674 | } |
668 | 675 | ||
669 | return prim; | 676 | console.log( "rectangle produced " + primArray.length + " fill primitives" ); |
677 | |||
678 | return primArray; | ||
670 | } | 679 | } |
671 | }, | 680 | }, |
672 | 681 | ||
@@ -988,17 +997,44 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
988 | j++; | 997 | j++; |
989 | } | 998 | } |
990 | 999 | ||
991 | //refine the mesh for vertex deformations | 1000 | // refine the mesh for vertex deformations |
992 | if (material) { | 1001 | var rtnArray; |
993 | if (material.hasVertexDeformation()) { | 1002 | if (material) |
1003 | { | ||
1004 | if (material.hasVertexDeformation()) | ||
1005 | { | ||
994 | var paramRange = material.getVertexDeformationRange(); | 1006 | var paramRange = material.getVertexDeformationRange(); |
995 | var tolerance = material.getVertexDeformationTolerance(); | 1007 | var tolerance = material.getVertexDeformationTolerance(); |
996 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 1008 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
1009 | |||
1010 | var subdividedParts = ShapePrimitive.subdivideOversizedMesh( this.vertices, this.normals, this.uvs, this.indices ); | ||
1011 | |||
1012 | rtnArray = []; | ||
1013 | if (subdividedParts) | ||
1014 | { | ||
1015 |