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