diff options
Diffstat (limited to 'js/lib/geom/rectangle.js')
-rwxr-xr-x | js/lib/geom/rectangle.js | 284 |
1 files changed, 179 insertions, 105 deletions
diff --git a/js/lib/geom/rectangle.js b/js/lib/geom/rectangle.js index 81a8556d..ac8e6c70 100755 --- a/js/lib/geom/rectangle.js +++ b/js/lib/geom/rectangle.js | |||
@@ -314,98 +314,105 @@ exports.Rectangle = Object.create(GeomObj, { | |||
314 | } | 314 | } |
315 | }, | 315 | }, |
316 | 316 | ||
317 | buildBuffers: { | 317 | buildBuffers: { |
318 | value: function() { | 318 | value: function() { |
319 | // get the world | 319 | // get the world |
320 | var world = this.getWorld(); | 320 | var world = this.getWorld(); |
321 | if (!world) throw( "null world in buildBuffers" ); | 321 | if (!world) throw( "null world in buildBuffers" ); |
322 | //console.log( "GLRectangle.buildBuffers " + world._worldCount ); | 322 | //console.log( "GLRectangle.buildBuffers " + world._worldCount ); |
323 | if (!world._useWebGL) return; | 323 | if (!world._useWebGL) return; |
324 | 324 | ||
325 | // make sure RDGE has the correct context | 325 | // make sure RDGE has the correct context |
326 | RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); | 326 | RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); |
327 | 327 | ||
328 | // create the gl buffer | 328 | // create the gl buffer |
329 | var gl = world.getGLContext(); | 329 | var gl = world.getGLContext(); |
330 | 330 | ||
331 | var tlRadius = this._tlRadius; //top-left radius | 331 | var tlRadius = this._tlRadius; //top-left radius |
332 | var trRadius = this._trRadius; | 332 | var trRadius = this._trRadius; |
333 | var blRadius = this._blRadius; | 333 | var blRadius = this._blRadius; |
334 | var brRadius = this._brRadius; | 334 | var brRadius = this._brRadius; |
335 | 335 | ||
336 | // declare the arrays to hold the parts | 336 | // declare the arrays to hold the parts |
337 | this._primArray = []; | 337 | this._primArray = []; |
338 | this._materialArray = []; | 338 | this._materialArray = []; |
339 | this._materialTypeArray = []; | 339 | this._materialTypeArray = []; |
340 | this._materialNodeArray = []; | 340 | this._materialNodeArray = []; |
341 | 341 | ||
342 | // get the normalized device coordinates (NDC) for | 342 | // get the normalized device coordinates (NDC) for |
343 | // all position and dimensions. | 343 | // all position and dimensions. |
344 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); | 344 | var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); |
345 | var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, | 345 | var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, |
346 | xFillNDC = this._width/vpw, yFillNDC = this._height/vph, | 346 | xFillNDC = this._width/vpw, yFillNDC = this._height/vph, |
347 | strokeSizeNDC = 2*this._strokeWidth/vpw, | 347 | strokeSizeNDC = 2*this._strokeWidth/vpw, |
348 | tlRadiusNDC = 2*tlRadius/vpw, yTLRadiusNDC = 2*tlRadius/vph, | 348 | tlRadiusNDC = 2*tlRadius/vpw, yTLRadiusNDC = 2*tlRadius/vph, |
349 | trRadiusNDC = 2*trRadius/vpw, yTRRadiusNDC = 2*trRadius/vph, | 349 | trRadiusNDC = 2*trRadius/vpw, yTRRadiusNDC = 2*trRadius/vph, |
350 | blRadiusNDC = 2*blRadius/vpw, yBLRadiusNDC = 2*blRadius/vph, | 350 | blRadiusNDC = 2*blRadius/vpw, yBLRadiusNDC = 2*blRadius/vph, |
351 | brRadiusNDC = 2*brRadius/vpw, yBRRadiusNDC = 2*brRadius/vph; | 351 | brRadiusNDC = 2*brRadius/vpw, yBRRadiusNDC = 2*brRadius/vph; |
352 | 352 | ||
353 | var aspect = world.getAspect(); | 353 | var aspect = world.getAspect(); |
354 | var zn = world.getZNear(), zf = world.getZFar(); | 354 | var zn = world.getZNear(), zf = world.getZFar(); |
355 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), | 355 | var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), |
356 | b = -t, | 356 | b = -t, |
357 | r = aspect*t, | 357 | r = aspect*t, |
358 | l = -r; | 358 | l = -r; |
359 | |||
360 | // calculate the object coordinates from their NDC coordinates | ||
361 | var z = -world.getViewDistance(); | ||
362 | |||
363 | // get the position of the origin | ||
364 | var x = -z*(r-l)/(2.0*zn)*xNDC, | ||
365 | y = -z*(t-b)/(2.0*zn)*yNDC; | ||
366 | |||
367 | // get the x and y fill | ||
368 | var xFill = -z*(r-l)/(2.0*zn)*xFillNDC, | ||
369 | yFill = -z*(t-b)/(2.0*zn)*yFillNDC; | ||
370 | |||
371 | // keep some variables giving the overall dimensions of the | ||
372 | // rectangle. These values are used to calculate consistent | ||
373 | // texture map coordinates across all pieces. | ||
374 | this._rectWidth = xFill; this._rectHeight = yFill; | ||
375 | |||
376 | // get the stroke size | ||
377 | var strokeSize = -z*(r-l)/(2.0*zn)*strokeSizeNDC; | ||
378 | |||
379 | // get the absolute corner radii | ||
380 | tlRadius = -z*(r-l)/(2.0*zn)*tlRadiusNDC, | ||
381 | trRadius = -z*(r-l)/(2.0*zn)*trRadiusNDC, | ||
382 | blRadius = -z*(r-l)/(2.0*zn)*blRadiusNDC, | ||
383 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | ||
384 | |||
385 | // stroke | ||
386 | var i; | ||
387 | var strokeMaterial = this.makeStrokeMaterial(); | ||
388 | var strokePrimArray = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | ||
389 | strokeMaterial.fitToPrimitiveArray( strokePrimArray ); | ||
390 | for (i=0; i<strokePrimArray.length; i++) | ||
391 | { | ||
392 | this._primArray.push( strokePrimArray[i] ); | ||
393 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | ||
394 | } | ||
359 | 395 | ||
360 | // calculate the object coordinates from their NDC coordinates | 396 | // fill |
361 | var z = -world.getViewDistance(); | 397 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; |
398 | blRadius -= strokeSize; if (blRadius < 0) blRadius = 0.0; | ||
399 | brRadius -= strokeSize; if (brRadius < 0) brRadius = 0.0; | ||
400 | trRadius -= strokeSize; if (trRadius < 0) trRadius = 0.0; | ||
401 | xFill -= strokeSize; | ||
402 | yFill -= strokeSize; | ||
403 | var fillMaterial = this.makeFillMaterial(); | ||
404 | //console.log( "fillMaterial: " + fillMaterial.getName() ); | ||
405 | var fillPrimArray = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); | ||
406 | fillMaterial.fitToPrimitiveArray( fillPrimArray ); | ||
407 | for (i=0; i<fillPrimArray.length; i++) | ||
408 | { | ||
409 | this._primArray.push( fillPrimArray[i] ); | ||
410 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | ||
411 | } | ||
362 | 412 | ||
363 | // get the position of the origin | 413 | world.updateObject(this); |
364 | var x = -z*(r-l)/(2.0*zn)*xNDC, | 414 | } |
365 | y = -z*(t-b)/(2.0*zn)*yNDC; | 415 | }, |
366 | |||
367 | // get the x and y fill | ||
368 | var xFill = -z*(r-l)/(2.0*zn)*xFillNDC, | ||
369 | yFill = -z*(t-b)/(2.0*zn)*yFillNDC; | ||
370 | |||
371 | // keep some variables giving the overall dimensions of the | ||
372 | // rectangle. These values are used to calculate consistent | ||
373 | // texture map coordinates across all pieces. | ||
374 | this._rectWidth = xFill; this._rectHeight = yFill; | ||
375 | |||
376 | // get the stroke size | ||
377 | var strokeSize = -z*(r-l)/(2.0*zn)*strokeSizeNDC; | ||
378 | |||
379 | // get the absolute corner radii | ||
380 | tlRadius = -z*(r-l)/(2.0*zn)*tlRadiusNDC, | ||
381 | trRadius = -z*(r-l)/(2.0*zn)*trRadiusNDC, | ||
382 | blRadius = -z*(r-l)/(2.0*zn)*blRadiusNDC, | ||
383 | brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; | ||
384 | |||
385 | // stroke | ||
386 | var strokeMaterial = this.makeStrokeMaterial(); | ||
387 | var strokePrim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); | ||
388 | strokeMaterial.fitToPrimitive( strokePrim ); | ||
389 | this._primArray.push( strokePrim ); | ||
390 | this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); | ||
391 | |||
392 | // fill | ||
393 | tlRadius -= strokeSize; if (tlRadius < 0) tlRadius = 0.0; | ||
394 | blRadius -= strokeSize; if (blRadius < 0) blRadius = 0.0; | ||
395 | brRadius -= strokeSize; if (brRadius < 0) brRadius = 0.0; | ||
396 | trRadius -= strokeSize; if (trRadius < 0) trRadius = 0.0; | ||
397 | xFill -= strokeSize; | ||
398 | yFill -= strokeSize; | ||
399 | var fillMaterial = this.makeFillMaterial(); | ||
400 | //console.log( "fillMaterial: " + fillMaterial.getName() ); | ||
401 | var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); | ||
402 | fillMaterial.fitToPrimitive( fillPrim ); | ||
403 | this._primArray.push( fillPrim ); | ||
404 | this._materialNodeArray.push( fillMaterial.getMaterialNode() ); | ||
405 | |||
406 | world.updateObject(this); | ||
407 | } | ||
408 | }, | ||
409 | 416 | ||
410 | renderQuadraticBezier: { | 417 | renderQuadraticBezier: { |
411 | value: function(bPts, ctx) { | 418 | value: function(bPts, ctx) { |
@@ -621,15 +628,17 @@ exports.Rectangle = Object.create(GeomObj, { | |||
621 | value: function(ctr, width, height, tlRad, blRad, brRad, trRad, material) { | 628 | value: function(ctr, width, height, tlRad, blRad, brRad, trRad, material) { |
622 | // create the geometry | 629 | // create the geometry |
623 | // special the (common) case of no rounded corners | 630 | // special the (common) case of no rounded corners |
624 | var prim; | 631 | var primArray; |
625 | 632 | ||
626 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { | 633 | if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { |
627 | prim = RectangleGeometry.create( ctr, width, height, material ); | 634 | primArray = RectangleGeometry.create( ctr, width, height, material ); |
628 | } else { | 635 | } else { |
629 | prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); | 636 | primArray = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); |
630 | } | 637 | } |
631 | 638 | ||
632 | return prim; | 639 | console.log( "rectangle produced " + primArray.length + " fill primitives" ); |
640 | |||
641 | return primArray; | ||
633 | } | 642 | } |
634 | }, | 643 | }, |
635 | 644 | ||
@@ -951,17 +960,44 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, | |||
951 | j++; | 960 | j++; |
952 | } | 961 | } |
953 | 962 | ||
954 | //refine the mesh for vertex deformations | 963 | // refine the mesh for vertex deformations |
955 | if (material) { | 964 | var rtnArray; |
956 | if (material.hasVertexDeformation()) { | 965 | if (material) |
966 | { | ||
967 | if (material.hasVertexDeformation()) | ||
968 | { | ||
957 | var paramRange = material.getVertexDeformationRange(); | 969 | var paramRange = material.getVertexDeformationRange(); |
958 | var tolerance = material.getVertexDeformationTolerance(); | 970 | var tolerance = material.getVertexDeformationTolerance(); |
959 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); | 971 | nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); |
972 | |||
973 | var subdividedParts = ShapePrimitive.subdivideOversizedMesh( this.vertices, this.normals, this.uvs, this.indices ); | ||
974 | |||
975 | rtnArray = []; | ||
976 | if (subdividedParts) | ||