From 22cbc9644b79df60b3f6336f9563debd47fb3ea1 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 28 Jun 2012 11:44:15 -0700 Subject: Added capability to split a mesh into multiiple parts to avoid buffer overflow situations. --- js/lib/geom/rectangle.js | 284 +++++++++++++++++++++++++++++------------------ 1 file changed, 179 insertions(+), 105 deletions(-) (limited to 'js/lib/geom/rectangle.js') 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, { } }, - buildBuffers: { - value: function() { - // get the world - var world = this.getWorld(); - if (!world) throw( "null world in buildBuffers" ); - //console.log( "GLRectangle.buildBuffers " + world._worldCount ); - if (!world._useWebGL) return; - - // make sure RDGE has the correct context - RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); - - // create the gl buffer - var gl = world.getGLContext(); - - var tlRadius = this._tlRadius; //top-left radius - var trRadius = this._trRadius; - var blRadius = this._blRadius; - var brRadius = this._brRadius; - - // declare the arrays to hold the parts - this._primArray = []; - this._materialArray = []; - this._materialTypeArray = []; - this._materialNodeArray = []; - - // get the normalized device coordinates (NDC) for - // all position and dimensions. - var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); - var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, - xFillNDC = this._width/vpw, yFillNDC = this._height/vph, - strokeSizeNDC = 2*this._strokeWidth/vpw, - tlRadiusNDC = 2*tlRadius/vpw, yTLRadiusNDC = 2*tlRadius/vph, - trRadiusNDC = 2*trRadius/vpw, yTRRadiusNDC = 2*trRadius/vph, - blRadiusNDC = 2*blRadius/vpw, yBLRadiusNDC = 2*blRadius/vph, - brRadiusNDC = 2*brRadius/vpw, yBRRadiusNDC = 2*brRadius/vph; - - var aspect = world.getAspect(); - var zn = world.getZNear(), zf = world.getZFar(); - var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), - b = -t, - r = aspect*t, - l = -r; + buildBuffers: { + value: function() { + // get the world + var world = this.getWorld(); + if (!world) throw( "null world in buildBuffers" ); + //console.log( "GLRectangle.buildBuffers " + world._worldCount ); + if (!world._useWebGL) return; + + // make sure RDGE has the correct context + RDGE.globals.engine.setContext( world.getCanvas().rdgeid ); + + // create the gl buffer + var gl = world.getGLContext(); + + var tlRadius = this._tlRadius; //top-left radius + var trRadius = this._trRadius; + var blRadius = this._blRadius; + var brRadius = this._brRadius; + + // declare the arrays to hold the parts + this._primArray = []; + this._materialArray = []; + this._materialTypeArray = []; + this._materialNodeArray = []; + + // get the normalized device coordinates (NDC) for + // all position and dimensions. + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + xFillNDC = this._width/vpw, yFillNDC = this._height/vph, + strokeSizeNDC = 2*this._strokeWidth/vpw, + tlRadiusNDC = 2*tlRadius/vpw, yTLRadiusNDC = 2*tlRadius/vph, + trRadiusNDC = 2*trRadius/vpw, yTRRadiusNDC = 2*trRadius/vph, + blRadiusNDC = 2*blRadius/vpw, yBLRadiusNDC = 2*blRadius/vph, + brRadiusNDC = 2*brRadius/vpw, yBRRadiusNDC = 2*brRadius/vph; + + var aspect = world.getAspect(); + var zn = world.getZNear(), zf = world.getZFar(); + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + b = -t, + r = aspect*t, + l = -r; + + // calculate the object coordinates from their NDC coordinates + var z = -world.getViewDistance(); + + // get the position of the origin + var x = -z*(r-l)/(2.0*zn)*xNDC, + y = -z*(t-b)/(2.0*zn)*yNDC; + + // get the x and y fill + var xFill = -z*(r-l)/(2.0*zn)*xFillNDC, + yFill = -z*(t-b)/(2.0*zn)*yFillNDC; + + // keep some variables giving the overall dimensions of the + // rectangle. These values are used to calculate consistent + // texture map coordinates across all pieces. + this._rectWidth = xFill; this._rectHeight = yFill; + + // get the stroke size + var strokeSize = -z*(r-l)/(2.0*zn)*strokeSizeNDC; + + // get the absolute corner radii + tlRadius = -z*(r-l)/(2.0*zn)*tlRadiusNDC, + trRadius = -z*(r-l)/(2.0*zn)*trRadiusNDC, + blRadius = -z*(r-l)/(2.0*zn)*blRadiusNDC, + brRadius = -z*(r-l)/(2.0*zn)*brRadiusNDC; + + // stroke + var i; + var strokeMaterial = this.makeStrokeMaterial(); + var strokePrimArray = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial); + strokeMaterial.fitToPrimitiveArray( strokePrimArray ); + for (i=0; i minDimen) brRad = minDimen; if (trRad > minDimen) trRad = minDimen; - var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; - var world = this.getWorld(); - viewUtils.pushViewportObj( world.getCanvas() ); - var cop = viewUtils.getCenterOfProjection(); - viewUtils.popViewportObj(); - var xCtr = cop[0] + this._xOffset, yCtr = cop[1] - this._yOffset; - var xLeft = xCtr - 0.5*this.getWidth(), yTop = yCtr - 0.5*this.getHeight(); - var xDist = cop[0] - xLeft, yDist = cop[1] - yTop; - var xOff = 0.5*world.getViewportWidth() - xDist, yOff = 0.5*world.getViewportHeight() - yDist; + var viewUtils = require("js/helper-classes/3D/view-utils").ViewUtils; + var world = this.getWorld(); + viewUtils.pushViewportObj( world.getCanvas() ); + var cop = viewUtils.getCenterOfProjection(); + viewUtils.popViewportObj(); + var xCtr = cop[0] + this._xOffset, yCtr = cop[1] - this._yOffset; + var xLeft = xCtr - 0.5*this.getWidth(), yTop = yCtr - 0.5*this.getHeight(); + var xDist = cop[0] - xLeft, yDist = cop[1] - yTop; + var xOff = 0.5*world.getViewportWidth() - xDist, yOff = 0.5*world.getViewportHeight() - yDist; if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { - ctx.rect(pt[0]+xOff, pt[1]+yOff, width - 2*inset, height - 2*inset); + ctx.rect(pt[0]+xOff, pt[1]+yOff, width - 2*inset, height - 2*inset); } else { // get the top left point rad = tlRad - inset; if (rad < 0) rad = 0; pt[1] += rad; if (MathUtils.fpSign(rad) == 0) pt[1] = inset; - ctx.moveTo( pt[0]+xOff, pt[1]+yOff ); + ctx.moveTo( pt[0]+xOff, pt[1]+yOff ); // get the bottom left point pt = [inset, height - inset]; rad = blRad - inset; if (rad < 0) rad = 0; pt[1] -= rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); // get the bottom left curve if (MathUtils.fpSign(rad) > 0) { - ctx.quadraticCurveTo( inset+xOff, height-inset+yOff, inset+rad+xOff, height-inset+yOff ); + ctx.quadraticCurveTo( inset+xOff, height-inset+yOff, inset+rad+xOff, height-inset+yOff ); } // do the bottom of the rectangle @@ -505,11 +505,11 @@ exports.Rectangle = Object.create(GeomObj, { rad = brRad - inset; if (rad < 0) rad = 0; pt[0] -= rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); // get the bottom right arc if (MathUtils.fpSign(rad) > 0) { - ctx.quadraticCurveTo( width-inset+xOff, height-inset+yOff, width-inset+xOff, height-inset-rad+yOff ); + ctx.quadraticCurveTo( width-inset+xOff, height-inset+yOff, width-inset+xOff, height-inset-rad+yOff ); } // get the right of the rectangle @@ -517,11 +517,11 @@ exports.Rectangle = Object.create(GeomObj, { rad = trRad - inset; if (rad < 0) rad = 0; pt[1] += rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); // do the top right corner if (MathUtils.fpSign(rad) > 0) { - ctx.quadraticCurveTo( width-inset+xOff, inset+yOff, width-inset-rad+xOff, inset+yOff ); + ctx.quadraticCurveTo( width-inset+xOff, inset+yOff, width-inset-rad+xOff, inset+yOff ); } // do the top of the rectangle @@ -529,116 +529,116 @@ exports.Rectangle = Object.create(GeomObj, { rad = tlRad - inset; if (rad < 0) rad = 0; pt[0] += rad; - ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); + ctx.lineTo( pt[0]+xOff, pt[1]+yOff ); // do the top left corner if (MathUtils.fpSign(rad) > 0) { - ctx.quadraticCurveTo( inset+xOff, inset+yOff, inset+xOff, inset+rad+yOff ); + ctx.quadraticCurveTo( inset+xOff, inset+yOff, inset+xOff, inset+rad+yOff ); } else { - ctx.lineTo( inset+xOff, 2*inset+yOff ); + ctx.lineTo( inset+xOff, 2*inset+yOff ); } } } }, - render: { - value: function() { - // get the world - var world = this.getWorld(); - if (!world) throw( "null world in rectangle render" ); - - // get the context - var ctx = world.get2DContext(); - if (!ctx) return; - - // get some dimensions - var lw = this._strokeWidth; - var w = world.getViewportWidth(), - h = world.getViewportHeight(); - - var c, - inset, - gradient, - colors, - len, - n, - position, - cs; - // render the fill - ctx.beginPath(); - if (this._fillColor) { - inset = Math.ceil( lw ) - 0.5; - - if(this._fillColor.gradientMode) { - if(this._fillColor.gradientMode === "radial") { - var ww = w - 2*lw, hh = h - 2*lw; - gradient = ctx.createRadialGradient(w/2, h/2, 0, w/2, h/2, Math.max(ww, hh)/2); - } else { - gradient = ctx.createLinearGradient(inset, h/2, w-inset, h/2); - } - colors = this._fillColor.color; - - len = colors.length; - - for(n=0; n (this._yOffset + this._height)) return false; return true; - } + } }, containsPoint: { @@ -687,8 +687,8 @@ exports.Rectangle = Object.create(GeomObj, { // get the normalized device coordinates (NDC) for // the position and radii. - var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); - var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, xRadNDC = this._width/vpw, yRadNDC = this._height/vph; var projMat = world.makePerspectiveMatrix(); var z = -world.getViewDistance(); @@ -731,8 +731,8 @@ exports.Rectangle = Object.create(GeomObj, { // get the normalized device coordinates (NDC) for // the position and radii. - var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); - var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, hwNDC = this._width/vpw, hhNDC = this._height/vph; var projMat = world.makePerspectiveMatrix(); var z = -world.getViewDistance(); @@ -777,7 +777,7 @@ exports.Rectangle = Object.create(GeomObj, { x = minPt[0]; y = minPt[1]; var aspect = world.getAspect(); var zn = world.getZNear(), zf = world.getZFar(); - var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), b = -t, r = aspect*t, l = -r; @@ -810,8 +810,8 @@ exports.Rectangle = Object.create(GeomObj, { // get the normalized device coordinates (NDC) for // the position and radii. - var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); - var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, + var vpw = world.getViewportWidth(), vph = world.getViewportHeight(); + var xNDC = 2*this._xOffset/vpw, yNDC = 2*this._yOffset/vph, hwNDC = this._width/vpw, hhNDC = this._height/vph; var projMat = world.makePerspectiveMatrix(); var z = -world.getViewDistance(); @@ -864,7 +864,7 @@ exports.Rectangle = Object.create(GeomObj, { x = minPt[0]; y = minPt[1]; var aspect = world.getAspect(); var zn = world.getZNear(), zf = world.getZFar(); - var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), + var t = zn * Math.tan(world.getFOV() * Math.PI / 360.0), b = -t, r = aspect*t, l = -r; @@ -896,455 +896,455 @@ exports.Rectangle = Object.create(GeomObj, { var RectangleFill = {}; RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad, material) { - var x = rectCtr[0], y = rectCtr[1], z = 0.0; - var hw = 0.5*width, hh = 0.5*height; - - // limit the radii to half the rectangle dimension - var minDimen = hw < hh ? hw : hh; - if (tlRad > minDimen) tlRad = minDimen; - if (blRad > minDimen) blRad = minDimen; - if (brRad > minDimen) brRad = minDimen; - if (trRad > minDimen) trRad = minDimen; - - // define some local variables - this.vertices = []; - this.normals = []; - this.uvs = []; - this.indices = []; - - // the center of the rectangle is the first vertex - RectangleFill.pushVertex( x, y, z ); - - // traverse the perimiter of the rectangle - - // push the starting point - RectangleFill.pushVertex( x-hw, y+hh-tlRad, z); - - // do the left side - var ctr; - if (blRad <= 0){ - RectangleFill.pushVertex( x-hw, y-hh, z); + var x = rectCtr[0], y = rectCtr[1], z = 0.0; + var hw = 0.5*width, hh = 0.5*height; + + // limit the radii to half the rectangle dimension + var minDimen = hw < hh ? hw : hh; + if (tlRad > minDimen) tlRad = minDimen; + if (blRad > minDimen) blRad = minDimen; + if (brRad > minDimen) brRad = minDimen; + if (trRad > minDimen) trRad = minDimen; + + // define some local variables + this.vertices = []; + this.normals = []; + this.uvs = []; + this.indices = []; + + // the center of the rectangle is the first vertex + RectangleFill.pushVertex( x, y, z ); + + // traverse the perimiter of the rectangle + + // push the starting point + RectangleFill.pushVertex( x-hw, y+hh-tlRad, z); + + // do the left side + var ctr; + if (blRad <= 0){ + RectangleFill.pushVertex( x-hw, y-hh, z); } else { - ctr = [x - hw + blRad, y - hh + blRad, z]; - RectangleFill.getRoundedCorner( ctr, [x-hw, y-hh+blRad, z], this.vertices ); - } + ctr = [x - hw + blRad, y - hh + blRad, z]; + RectangleFill.getRoundedCorner( ctr, [x-hw, y-hh+blRad, z], this.vertices ); + } - // do the bottom - if (brRad <= 0) { - RectangleFill.pushVertex( x+hw, y-hh, z); + // do the bottom + if (brRad <= 0) { + RectangleFill.pushVertex( x+hw, y-hh, z); } else { - ctr = [x + hw - brRad, y - hh + brRad, z]; - RectangleFill.getRoundedCorner( ctr, [x+hw-brRad, y-hh, z], this.vertices ); - } + ctr = [x + hw - brRad, y - hh + brRad, z]; + RectangleFill.getRoundedCorner( ctr, [x+hw-brRad, y-hh, z], this.vertices ); + } - // do the right - if (trRad <= 0) { - RectangleFill.pushVertex( x+hw, y+hh, z); + // do the right + if (trRad <= 0) { + RectangleFill.pushVertex( x+hw, y+hh, z); } else { - ctr = [x + hw - trRad, y + hh - trRad, z]; - RectangleFill.getRoundedCorner( ctr, [x+hw, y+hh-trRad, z], this.vertices ); - } + ctr = [x + hw - trRad, y + hh - trRad, z]; + RectangleFill.getRoundedCorner( ctr, [x+hw, y+hh-trRad, z], this.vertices ); + } - // do the top - if (tlRad <= 0) { - RectangleFill.pushVertex( x-hw, y+hh, z); + // do the top + if (tlRad <= 0) { + RectangleFill.pushVertex( x-hw, y+hh, z); } else { - ctr = [x - hw + tlRad, y + hh - tlRad, z]; - RectangleFill.getRoundedCorner( ctr, [x-hw+tlRad, y+hh, z], this.vertices ); - } - - // get the normals and uvs - var vrt, uv; - var xMin = x - hw, - yMin = y - hh; - var n = [0, 0, 1]; - var nVertices = this.vertices.length / 3; - for (var i=0; i minDimen) tlRad = minDimen; - if (blRad > minDimen) blRad = minDimen; - if (brRad > minDimen) brRad = minDimen; - if (trRad > minDimen) trRad = minDimen; - - // define some local variables - this.vertices = []; - this.normals = []; - this.uvs = []; - this.indices = []; - - // get the starting points - if (tlRad == 0) { - RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); - RectangleStroke.pushVertex( x-hw, y+hh, z); - } else { - if (tlRad > sw) { - RectangleStroke.pushVertex( x-hw+sw, y+hh-tlRad, z); - RectangleStroke.pushVertex( x-hw, y+hh-tlRad, z); - } else { - RectangleStroke.pushVertex( x-hw+tlRad, y+hh-tlRad, z); - RectangleStroke.pushVertex( x-hw, y+hh-tlRad, z); - RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); - RectangleStroke.pushVertex( x-hw, y+hh-sw, z); - } - } - - // get the left side - if (blRad == 0) { - RectangleStroke.pushVertex( x-hw+sw, y-hh+sw, z); - RectangleStroke.pushVertex( x-hw, y-hh, z); - } else { - if (blRad >= sw) { - RectangleStroke.pushVertex( x-hw+sw, y-hh+blRad, z); - RectangleStroke.pushVertex( x-hw, y-hh+blRad, z); - var ctr = [x-hw+blRad, y-hh+blRad, z], - insidePt = [x-hw+sw, y-hh+blRad, z], - outsidePt = [x-hw, y-hh+blRad, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - } else { - RectangleStroke.pushVertex( x-hw+sw, y-hh+sw, z); - RectangleStroke.pushVertex( x-hw, y-hh+blRad, z); - var ctr = [x-hw+blRad, y-hh+blRad, z], - insidePt = [x-hw+blRad, y-hh+blRad, z], - outsidePt = [x-hw, y-hh+blRad, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - - RectangleStroke.pushVertex( x-hw+sw, y-hh+sw, z); - RectangleStroke.pushVertex( x-hw+sw, y-hh, z); - } - } - - // get the bottom - if (brRad == 0) { - RectangleStroke.pushVertex( x+hw-sw, y-hh+sw, z); - RectangleStroke.pushVertex( x+hw, y-hh, z); - } else { - RectangleStroke.pushVertex( x+hw-brRad, y-hh+sw, z); - RectangleStroke.pushVertex( x+hw-brRad, y-hh, z); - if (brRad >= sw) { - var ctr = [x+hw-brRad, y-hh+brRad, z], - insidePt = [x+hw-brRad, y-hh+sw, z], - outsidePt = [x+hw-brRad, y-hh, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - } else { - RectangleStroke.pushVertex( x+hw-sw, y-hh+sw, z); - RectangleStroke.pushVertex( x+hw-brRad, y-hh, z); - var ctr = [x+hw-brRad, y-hh+brRad, z], - insidePt = [x+hw-brRad, y-hh+brRad, z], - outsidePt = [x+hw-brRad, y-hh, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - RectangleStroke.pushVertex( x+hw-sw, y-hh+sw, z); - RectangleStroke.pushVertex( x+hw, y-hh+sw, z); - } - } - - // get the right - if (trRad == 0) { - RectangleStroke.pushVertex( x+hw-sw, y+hh-sw, z); - RectangleStroke.pushVertex( x+hw, y+hh, z); - } else { - if (trRad >= sw) { - RectangleStroke.pushVertex( x+hw-sw, y+hh-trRad, z); - RectangleStroke.pushVertex( x+hw, y+hh-trRad, z); - var ctr = [x+hw-trRad, y+hh-trRad, z], - insidePt = [x+hw-sw, y+hh-trRad, z], - outsidePt = [x+hw, y+hh-trRad, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - } else { - RectangleStroke.pushVertex( x+hw-sw, y+hh-sw, z); - RectangleStroke.pushVertex( x+hw, y+hh-trRad, z); - var ctr = [x+hw-trRad, y+hh-trRad, z], - insidePt = [x+hw-trRad, y+hh-trRad, z], - outsidePt = [x+hw, y+hh-trRad, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - RectangleStroke.pushVertex( x+hw-sw, y+hh-sw, z); - RectangleStroke.pushVertex( x+hw-sw, y+hh, z); - } - } - - // get the top - if (tlRad == 0) { - RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); - RectangleStroke.pushVertex( x-hw, y+hh, z); - } else { - if (tlRad >= sw) { - RectangleStroke.pushVertex( x-hw+tlRad, y+hh-sw, z); - RectangleStroke.pushVertex( x-hw+tlRad, y+hh, z); - var ctr = [x-hw+tlRad, y+hh-tlRad, z], - insidePt = [x-hw+tlRad, y+hh-sw, z], - outsidePt = [x-hw+tlRad, y+hh, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - } else { - RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); - RectangleStroke.pushVertex( x-hw+tlRad, y+hh, z); - var ctr = [x-hw+tlRad, y+hh-tlRad, z], - insidePt = [x-hw+tlRad, y+hh-tlRad, z], - outsidePt = [x-hw+tlRad, y+hh, z]; - RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); - } - } - - // get the normals and uvs - var vrt, uv; - var xMin = x - hw, - yMin = y - hh; - var n = [0, 0, 1]; - var nVertices = this.vertices.length / 3; - for (var i=0; i minDimen) tlRad = minDimen; + if (blRad > minDimen) blRad = minDimen; + if (brRad > minDimen) brRad = minDimen; + if (trRad > minDimen) trRad = minDimen; + + // define some local variables + this.vertices = []; + this.normals = []; + this.uvs = []; + this.indices = []; + + // get the starting points + if (tlRad == 0) { + RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); + RectangleStroke.pushVertex( x-hw, y+hh, z); + } else { + if (tlRad > sw) { + RectangleStroke.pushVertex( x-hw+sw, y+hh-tlRad, z); + RectangleStroke.pushVertex( x-hw, y+hh-tlRad, z); + } else { + RectangleStroke.pushVertex( x-hw+tlRad, y+hh-tlRad, z); + RectangleStroke.pushVertex( x-hw, y+hh-tlRad, z); + RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); + RectangleStroke.pushVertex( x-hw, y+hh-sw, z); + } + } + + // get the left side + if (blRad == 0) { + RectangleStroke.pushVertex( x-hw+sw, y-hh+sw, z); + RectangleStroke.pushVertex( x-hw, y-hh, z); + } else { + if (blRad >= sw) { + RectangleStroke.pushVertex( x-hw+sw, y-hh+blRad, z); + RectangleStroke.pushVertex( x-hw, y-hh+blRad, z); + var ctr = [x-hw+blRad, y-hh+blRad, z], + insidePt = [x-hw+sw, y-hh+blRad, z], + outsidePt = [x-hw, y-hh+blRad, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + } else { + RectangleStroke.pushVertex( x-hw+sw, y-hh+sw, z); + RectangleStroke.pushVertex( x-hw, y-hh+blRad, z); + var ctr = [x-hw+blRad, y-hh+blRad, z], + insidePt = [x-hw+blRad, y-hh+blRad, z], + outsidePt = [x-hw, y-hh+blRad, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + + RectangleStroke.pushVertex( x-hw+sw, y-hh+sw, z); + RectangleStroke.pushVertex( x-hw+sw, y-hh, z); + } + } + + // get the bottom + if (brRad == 0) { + RectangleStroke.pushVertex( x+hw-sw, y-hh+sw, z); + RectangleStroke.pushVertex( x+hw, y-hh, z); + } else { + RectangleStroke.pushVertex( x+hw-brRad, y-hh+sw, z); + RectangleStroke.pushVertex( x+hw-brRad, y-hh, z); + if (brRad >= sw) { + var ctr = [x+hw-brRad, y-hh+brRad, z], + insidePt = [x+hw-brRad, y-hh+sw, z], + outsidePt = [x+hw-brRad, y-hh, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + } else { + RectangleStroke.pushVertex( x+hw-sw, y-hh+sw, z); + RectangleStroke.pushVertex( x+hw-brRad, y-hh, z); + var ctr = [x+hw-brRad, y-hh+brRad, z], + insidePt = [x+hw-brRad, y-hh+brRad, z], + outsidePt = [x+hw-brRad, y-hh, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + RectangleStroke.pushVertex( x+hw-sw, y-hh+sw, z); + RectangleStroke.pushVertex( x+hw, y-hh+sw, z); + } + } + + // get the right + if (trRad == 0) { + RectangleStroke.pushVertex( x+hw-sw, y+hh-sw, z); + RectangleStroke.pushVertex( x+hw, y+hh, z); + } else { + if (trRad >= sw) { + RectangleStroke.pushVertex( x+hw-sw, y+hh-trRad, z); + RectangleStroke.pushVertex( x+hw, y+hh-trRad, z); + var ctr = [x+hw-trRad, y+hh-trRad, z], + insidePt = [x+hw-sw, y+hh-trRad, z], + outsidePt = [x+hw, y+hh-trRad, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + } else { + RectangleStroke.pushVertex( x+hw-sw, y+hh-sw, z); + RectangleStroke.pushVertex( x+hw, y+hh-trRad, z); + var ctr = [x+hw-trRad, y+hh-trRad, z], + insidePt = [x+hw-trRad, y+hh-trRad, z], + outsidePt = [x+hw, y+hh-trRad, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + RectangleStroke.pushVertex( x+hw-sw, y+hh-sw, z); + RectangleStroke.pushVertex( x+hw-sw, y+hh, z); + } + } + + // get the top + if (tlRad == 0) { + RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); + RectangleStroke.pushVertex( x-hw, y+hh, z); + } else { + if (tlRad >= sw) { + RectangleStroke.pushVertex( x-hw+tlRad, y+hh-sw, z); + RectangleStroke.pushVertex( x-hw+tlRad, y+hh, z); + var ctr = [x-hw+tlRad, y+hh-tlRad, z], + insidePt = [x-hw+tlRad, y+hh-sw, z], + outsidePt = [x-hw+tlRad, y+hh, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); } else { - RectangleStroke.pushIndices( i, j, k ); + RectangleStroke.pushVertex( x-hw+sw, y+hh-sw, z); + RectangleStroke.pushVertex( x-hw+tlRad, y+hh, z); + var ctr = [x-hw+tlRad, y+hh-tlRad, z], + insidePt = [x-hw+tlRad, y+hh-tlRad, z], + outsidePt = [x-hw+tlRad, y+hh, z]; + RectangleStroke.getRoundedCorner( ctr, insidePt, outsidePt, this.vertices ); + } + } + + // get the normals and uvs + var vrt, uv; + var xMin = x - hw, + yMin = y - hh; + var n = [0, 0, 1]; + var nVertices = this.vertices.length / 3; + for (var i=0; i