From 3a754133dbc138390503341fd2e9beba3e43aa4b Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Fri, 27 Jan 2012 12:05:17 -0800 Subject: Merged old FileIO --- js/helper-classes/RDGE/GLRectangle.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 js/helper-classes/RDGE/GLRectangle.js (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js old mode 100644 new mode 100755 -- cgit v1.2.3 From 3d5b5f7c5efb25b5e605d5d120b57f2dde33fd23 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 3 Feb 2012 15:18:45 -0800 Subject: Added a counter to the renderer that tracks the number of unloaded texture maps. Started vertex deformations. --- js/helper-classes/RDGE/GLRectangle.js | 148 ++++++++++++++++++++++++++++++++-- 1 file changed, 140 insertions(+), 8 deletions(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 1bb4bcac..e72b4488 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -280,7 +280,7 @@ function GLRectangle() // stroke var strokeMaterial = this.makeStrokeMaterial(); - prim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius, strokeMaterial) + prim = this.createStroke([x,y], 2*xFill, 2*yFill, strokeSize, tlRadius, blRadius, brRadius, trRadius); this._primArray.push( prim ); this._materialNodeArray.push( strokeMaterial.getMaterialNode() ); @@ -486,7 +486,7 @@ function GLRectangle() this.createStroke = function(ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) { // create the geometry - var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) + var prim = RectangleStroke.create( ctr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) return prim; } @@ -496,9 +496,9 @@ function GLRectangle() // special the (common) case of no rounded corners var prim if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) - prim = RectangleGeometry.create( ctr, width, height ); + prim = RectangleGeometry.create( ctr, width, height, material ); else - prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad); + prim = RectangleFill.create( ctr, width, height, tlRad, blRad, brRad, trRad, material); return prim; } @@ -747,7 +747,7 @@ function GLRectangle() } RectangleFill = {}; -RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, trRad) +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; @@ -834,6 +834,17 @@ RectangleFill.create = function( rectCtr, width, height, tlRad, blRad, brRad, j++; } + //refine the mesh for vertex deformations + if (material) + { + if (material.hasVertexDeformation()) + { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + } + } + // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); return prim; @@ -906,7 +917,7 @@ RectangleFill.getRoundedCorner = function(ctr, startPt, vertices) RectangleStroke = {}; -RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad) +RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, blRad, brRad, trRad, material) { var x = rectCtr[0], y = rectCtr[1], z = 0.0; var hw = 0.5*width, hh = 0.5*height, sw = strokeWidth; @@ -1097,6 +1108,17 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, k++; } + //refine the mesh for vertex deformations + if (material) + { + if (material.hasVertexDeformation()) + { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + } + } + // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); return prim; @@ -1141,7 +1163,7 @@ RectangleStroke.getUV = RectangleFill.getUV; // Helper function for generating Three.js geometry RectangleGeometry = {}; -RectangleGeometry.create = function( ctr, width, height ) +RectangleGeometry.create = function( ctr, width, height, material ) { var x = ctr[0], y = ctr[1], z = 0.0; var hw = 0.5*width, hh = 0.5*height; @@ -1179,6 +1201,17 @@ RectangleGeometry.create = function( ctr, width, height ) RectangleGeometry.pushIndices( 2, 1, 0 ); RectangleGeometry.pushIndices( 0, 3, 2 ); + //refine the mesh for vertex deformations + if (material) + { + if (material.hasVertexDeformation()) + { + var paramRange = material.getVertexDeformationRange(); + var tolerance = material.getVertexDeformationTolerance(); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + } + } + // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); return prim; @@ -1249,4 +1282,103 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver renderer.createPrimitive(prim, vertexCount); return prim; -} \ No newline at end of file +} + + +ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) +{ + // get the param range + var pUMin = paramRange[0], pVMin = paramRange[1], + pUMax = paramRange[2], pVMax = paramRange[3]; + var iTriangle = 0; + var nTriangles = indices.length/3; + var index = 0; + while (iTriangle < nTriangles) + { + // get the indices of the 3 vertices + var i0 = indices[index], + i1 = indices[index+1], + i2 = indices[index+2]; + + // get the uv values + var vrtIndex = 3*iTriangle; + var iuv0 = 2 * i0, + iuv1 = 2 * i1, + iuv2 = 2 * i2; + var u0 = uvs[iuv0], v0 = uvs[iuv0+1], + u1 = uvs[iuv1], v1 = uvs[iuv1+1], + u2 = uvs[iuv2], v2 = uvs[iuv2+1]; + + // find the u and v range + var uMin = u0, vMin = v0; + if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1; + if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2; + var uMax = u0, vMax = v0; + if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1; + if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2; + + // if the parameter range of the triangle is outside the + // desired parameter range, advance to the next polygon and continue + if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin)) + { + // go to the next triangle + iTriangle++; + index += 3; + } + else + { + // check thesize of the triangle in uv space. If small enough, advance + // to the next triangle. If not small enough, split the triangle into 3; + var du = uMax - uMin, dv = vMax - vMin; + if ((du < tolerance) && (dv < tolerance)) + { + iTriangle++; + index += 3; + } + else // split the triangle + { + //calculate the position of the new vertex + var iPt0 = 3 * i0, + iPt1 = 3 * i1, + iPt2 = 3 * i2; + var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], + x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], + x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; + var xMid = (x0 + x1 + x2)/3.0, + yMid = (y0 + y1 + y2)/3.0, + zMid = (z0 + z1 + z2)/3.0; + + // calculate the uv value of the new coordinate + var uMid = (u0 + u1 + u2)/3.0, + vMid = (v0 + v1 + v2)/3.0; + + // calculate the normal for the new coordinate + var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], + nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], + nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; + var nxMid = (nx0 + nx1 + nx2), + nyMid = (ny0 + ny1 + ny2), + nzMid = (nz0 + nz1 + nz2); + var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); + + // push the new vertex + verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); + uvs.push(uMid), uvs.push(vMid); + norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); + var iMidVrt = nVertices; + nVertices++; + + // split the current triangle into 3 + indices[index+2] = iMidVrt; + indices.push(i1); indices.push(i2); indices.push(iMidVrt); nTriangles++; + indices.push(i2); indices.push(i0); indices.push(iMidVrt); nTriangles++; + + // by not advancing 'index', we examine the first of the 3 triangles generated above + } + } + } + return nVertices; +} + + + -- cgit v1.2.3 From 2d4da18a778471b02e188ad668752e331ee76127 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 7 Feb 2012 14:35:55 -0800 Subject: test code for deformation shader --- js/helper-classes/RDGE/GLRectangle.js | 64 ++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 27 deletions(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index e72b4488..7fe03022 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -1121,6 +1121,7 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); + //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1214,6 +1215,7 @@ RectangleGeometry.create = function( ctr, width, height, material ) // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); + //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1301,7 +1303,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa i2 = indices[index+2]; // get the uv values - var vrtIndex = 3*iTriangle; + //var vrtIndex = 3*iTriangle; var iuv0 = 2 * i0, iuv1 = 2 * i1, iuv2 = 2 * i2; @@ -1335,7 +1337,7 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa iTriangle++; index += 3; } - else // split the triangle + else // split the triangle into 4 parts { //calculate the position of the new vertex var iPt0 = 3 * i0, @@ -1344,34 +1346,42 @@ ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, pa var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; - var xMid = (x0 + x1 + x2)/3.0, - yMid = (y0 + y1 + y2)/3.0, - zMid = (z0 + z1 + z2)/3.0; - - // calculate the uv value of the new coordinate - var uMid = (u0 + u1 + u2)/3.0, - vMid = (v0 + v1 + v2)/3.0; - - // calculate the normal for the new coordinate + + // calculate the midpoints of the edges + var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0, + xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0, + xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0; + + // calculate the uv values of the new coordinates + var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0, + uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0, + uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0; + + // calculate the normals for the new points var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; - var nxMid = (nx0 + nx1 + nx2), - nyMid = (ny0 + ny1 + ny2), - nzMid = (nz0 + nz1 + nz2); - var nrm = VecUtils.vecNormalize(3, [nxMid, nyMid, nzMid], 1.0 ); - - // push the new vertex - verts.push(nrm[0]); verts.push(nrm[1]); verts.push(nrm[2]); - uvs.push(uMid), uvs.push(vMid); - norms.push(nrm[0]); norms.push(nrm[1]); norms.push(nrm[2]); - var iMidVrt = nVertices; - nVertices++; - - // split the current triangle into 3 - indices[index+2] = iMidVrt; - indices.push(i1); indices.push(i2); indices.push(iMidVrt); nTriangles++; - indices.push(i2); indices.push(i0); indices.push(iMidVrt); nTriangles++; + var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ), + nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ), + nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 ); + + // push everything + verts.push(xA); verts.push(yA); verts.push(zA); + verts.push(xB); verts.push(yB); verts.push(zB); + verts.push(xC); verts.push(yC); verts.push(zC); + uvs.push(uA), uvs.push(vA); + uvs.push(uB), uvs.push(vB); + uvs.push(uC), uvs.push(vC); + norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]); + norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]); + norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]); + + // split the current triangle into 4 + indices[index+1] = nVertices; indices[index+2] = nVertices+2; + indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++; + indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++; + indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++; + nVertices += 3; // by not advancing 'index', we examine the first of the 3 triangles generated above } -- cgit v1.2.3 From 064d74fb2694318615f513c83772276cec34bb86 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 8 Feb 2012 13:41:52 -0800 Subject: Fixed context switching problems in rdge --- js/helper-classes/RDGE/GLRectangle.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index f6f5a899..595a5b48 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -210,8 +210,11 @@ function GLRectangle() // 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 + g_Engine.setContext( world.getCanvas().uuid ); // create the gl buffer var gl = world.getGLContext(); @@ -284,6 +287,7 @@ function GLRectangle() xFill -= strokeSize; yFill -= strokeSize; var fillMaterial = this.makeFillMaterial(); + //console.log( "fillMaterial: " + fillMaterial.getName() ); var fillPrim = this.createFill([x,y], 2*xFill, 2*yFill, tlRadius, blRadius, brRadius, trRadius, fillMaterial); this._primArray.push( fillPrim ); this._materialNodeArray.push( fillMaterial.getMaterialNode() ); -- cgit v1.2.3 From 170236c258e971331fc28747532a720d4cfb63cc Mon Sep 17 00:00:00 2001 From: hwc487 Date: Wed, 8 Feb 2012 17:18:23 -0800 Subject: Changed the rendering for canvas 2D rectangle. --- js/helper-classes/RDGE/GLRectangle.js | 135 +++++++++++++++------------------- 1 file changed, 61 insertions(+), 74 deletions(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index e34532d2..d24ade2b 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -317,72 +317,71 @@ function GLRectangle() var width = Math.round(this.getWidth()), height = Math.round(this.getHeight()); - // get the top left point pt = [inset, inset]; // top left corner - rad = this.getTLRadius() - inset; - if (rad < 0) rad = 0; - pt[1] += rad; - if (MathUtils.fpSign(rad) == 0) pt[1] = 0; - ctx.moveTo( pt[0], pt[1] ); - - // get the bottom left point - pt = [inset, height - inset]; - rad = this.getBLRadius() - inset; - if (rad < 0) rad = 0; - pt[1] -= rad; - ctx.lineTo( pt[0], pt[1] ); - - // get the bottom left arc - if (MathUtils.fpSign(rad) > 0) - { - ctr = [ this.getBLRadius(), height - this.getBLRadius() ]; - //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx ); - ctx.arc( ctr[0], ctr[1], rad, Math.PI, 0.5*Math.PI, true ); - } - - // do the bottom of the rectangle - pt = [width - inset, height - inset]; - rad = this.getBRRadius() - inset; - if (rad < 0) rad = 0; - pt[0] -= rad; - ctx.lineTo( pt[0], pt[1] ); - - // get the bottom right arc - if (MathUtils.fpSign(rad) > 0) - { - ctr = [width - this.getBRRadius(), height - this.getBRRadius()]; - //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx ); - ctx.arc( ctr[0], ctr[1], rad, 0.5*Math.PI, 0.0, true ); - } - // get the right of the rectangle - pt = [width - inset, inset]; - rad = this.getTRRadius() - inset; - if (rad < 0) rad = 0; - pt[1] += rad; - ctx.lineTo( pt[0], pt[1] ); + var tlRad = this._tlRadius; //top-left radius + var trRad = this._trRadius; + var blRad = this._blRadius; + var brRad = this._brRadius; - // do the top right corner - if (MathUtils.fpSign(rad) > 0) + if ((tlRad <= 0) && (blRad <= 0) && (brRad <= 0) && (trRad <= 0)) { - ctr = [width - this.getTRRadius(), this.getTRRadius()]; - //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx ); - ctx.arc( ctr[0], ctr[1], rad, 0.0, -0.5*Math.PI, true ); + ctx.rect(pt[0], pt[1], width - 2*inset, height - 2*inset); } - - // do the top of the rectangle - pt = [inset, inset] - rad = this.getTLRadius() - inset; - if (rad < 0) rad = 0; - pt[0] += rad; - ctx.lineTo( pt[0], pt[1] ); - - // do the top left corner - if (MathUtils.fpSign(rad) > 0) + else { - ctr = [this.getTLRadius(), this.getTLRadius()]; - //this.renderQuadraticBezier( MathUtils.circularArcToBezier( ctr, pt, -0.5*Math.PI ), ctx ); - ctx.arc( ctr[0], ctr[1], rad, -0.5*Math.PI, Math.PI, true ); + // 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], pt[1] ); + + // get the bottom left point + pt = [inset, height - inset]; + rad = blRad - inset; + if (rad < 0) rad = 0; + pt[1] -= rad; + ctx.lineTo( pt[0], pt[1] ); + + // get the bottom left curve + if (MathUtils.fpSign(rad) > 0) + ctx.quadraticCurveTo( inset, height-inset, inset+rad, height-inset ); + + // do the bottom of the rectangle + pt = [width - inset, height - inset]; + rad = brRad - inset; + if (rad < 0) rad = 0; + pt[0] -= rad; + ctx.lineTo( pt[0], pt[1] ); + + // get the bottom right arc + if (MathUtils.fpSign(rad) > 0) + ctx.quadraticCurveTo( width-inset, height-inset, width-inset, height-inset-rad ); + + // get the right of the rectangle + pt = [width - inset, inset]; + rad = trRad - inset; + if (rad < 0) rad = 0; + pt[1] += rad; + ctx.lineTo( pt[0], pt[1] ); + + // do the top right corner + if (MathUtils.fpSign(rad) > 0) + ctx.quadraticCurveTo( width-inset, inset, width-inset-rad, inset ); + + // do the top of the rectangle + pt = [inset, inset] + rad = tlRad - inset; + if (rad < 0) rad = 0; + pt[0] += rad; + ctx.lineTo( pt[0], pt[1] ); + + // do the top left corner + if (MathUtils.fpSign(rad) > 0) + ctx.quadraticCurveTo( inset, inset, inset, inset+rad ); + else + ctx.lineTo( inset, 2*inset ); } } @@ -401,32 +400,20 @@ function GLRectangle() var w = world.getViewportWidth(), h = world.getViewportHeight(); - // draw the fill + // set the fill ctx.beginPath(); ctx.fillStyle = "#990000"; - //ctx.strokeStyle = "#0000ff"; if (this._fillColor) ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); - //ctx.lineWidth = 0; - //ctx.rect( lw, lw, w - 2*lw, h- 2*lw ); - //this.renderPath( lw, ctx ) - //ctx.fill(); - //ctx.closePath(); - - // draw the stroke - //ctx.beginPath(); - //ctx.fillStyle = "#990000"; + // set the stroke ctx.strokeStyle = "#0000ff"; if (this._strokeColor) ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); ctx.lineWidth = lw; - //ctx.rect( 0.5*lw, 0.5*lw, w-lw, h-lw ); var inset = Math.ceil( 0.5*lw ) + 0.5; -// console.log( "linewidth: " + lw + ", inset: " + inset+ ", width: " + Math.round(this.getWidth()) + ", height: " + Math.round(this.getHeight()) ); this.renderPath( inset, ctx ); - //this.renderPath( lw, ctx ); ctx.fill(); ctx.stroke(); ctx.closePath(); -- cgit v1.2.3 From 9e40945a5bf4330d1088b56b8011ee625b1adab9 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Fri, 10 Feb 2012 10:23:48 -0800 Subject: Support export/import of GLLine data. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLRectangle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index d24ade2b..4216fe53 100644 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -180,7 +180,7 @@ function GLRectangle() this._strokeStyle = Number( this.getPropertyFromString( "strokeStyle: ", importStr ) ); var strokeMaterialName = this.getPropertyFromString( "strokeMat: ", importStr ); var fillMaterialName = this.getPropertyFromString( "fillMat: ", importStr ); - this._strokeStyle = Number( this.getPropertyFromString( "strokeColor: ", importStr ) ); + this._strokeStyle = this.getPropertyFromString( "strokeStyle: ", importStr ); this._fillColor = eval( "[" + this.getPropertyFromString( "fillColor: ", importStr ) + "]" ); this._strokeColor = eval( "[" + this.getPropertyFromString( "strokeColor: ", importStr ) + "]" ); this._tlRadius = Number( this.getPropertyFromString( "tlRadius: ", importStr ) ); -- cgit v1.2.3 From 96a0a8c916533eb5625816192ed38488f639326d Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 22 Feb 2012 11:00:20 -0800 Subject: Integrating canvas-2d drawing and WebGL fixes, including adding back WebGL materials. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLRectangle.js | 117 +++------------------------------- 1 file changed, 10 insertions(+), 107 deletions(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 4216fe53..5b6ff94f 100755 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -404,12 +404,18 @@ function GLRectangle() ctx.beginPath(); ctx.fillStyle = "#990000"; if (this._fillColor) - ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); + { + var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; + ctx.fillStyle = c; + } // set the stroke ctx.strokeStyle = "#0000ff"; if (this._strokeColor) - ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); + { + var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; + ctx.strokeStyle = c; + } ctx.lineWidth = lw; var inset = Math.ceil( 0.5*lw ) + 0.5; @@ -1051,13 +1057,12 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); - nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); } } // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); - //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1145,7 +1150,7 @@ RectangleGeometry.create = function( ctr, width, height, material ) { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); - nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); } } @@ -1223,108 +1228,6 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver } -ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) -{ - // get the param range - var pUMin = paramRange[0], pVMin = paramRange[1], - pUMax = paramRange[2], pVMax = paramRange[3]; - var iTriangle = 0; - var nTriangles = indices.length/3; - var index = 0; - while (iTriangle < nTriangles) - { - // get the indices of the 3 vertices - var i0 = indices[index], - i1 = indices[index+1], - i2 = indices[index+2]; - - // get the uv values - //var vrtIndex = 3*iTriangle; - var iuv0 = 2 * i0, - iuv1 = 2 * i1, - iuv2 = 2 * i2; - var u0 = uvs[iuv0], v0 = uvs[iuv0+1], - u1 = uvs[iuv1], v1 = uvs[iuv1+1], - u2 = uvs[iuv2], v2 = uvs[iuv2+1]; - - // find the u and v range - var uMin = u0, vMin = v0; - if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1; - if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2; - var uMax = u0, vMax = v0; - if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1; - if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2; - - // if the parameter range of the triangle is outside the - // desired parameter range, advance to the next polygon and continue - if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin)) - { - // go to the next triangle - iTriangle++; - index += 3; - } - else - { - // check thesize of the triangle in uv space. If small enough, advance - // to the next triangle. If not small enough, split the triangle into 3; - var du = uMax - uMin, dv = vMax - vMin; - if ((du < tolerance) && (dv < tolerance)) - { - iTriangle++; - index += 3; - } - else // split the triangle into 4 parts - { - //calculate the position of the new vertex - var iPt0 = 3 * i0, - iPt1 = 3 * i1, - iPt2 = 3 * i2; - var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], - x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], - x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; - - // calculate the midpoints of the edges - var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0, - xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0, - xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0; - - // calculate the uv values of the new coordinates - var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0, - uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0, - uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0; - - // calculate the normals for the new points - var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], - nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], - nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; - var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ), - nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ), - nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 ); - - // push everything - verts.push(xA); verts.push(yA); verts.push(zA); - verts.push(xB); verts.push(yB); verts.push(zB); - verts.push(xC); verts.push(yC); verts.push(zC); - uvs.push(uA), uvs.push(vA); - uvs.push(uB), uvs.push(vB); - uvs.push(uC), uvs.push(vC); - norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]); - norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]); - norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]); - - // split the current triangle into 4 - indices[index+1] = nVertices; indices[index+2] = nVertices+2; - indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++; - indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++; - indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++; - nVertices += 3; - - // by not advancing 'index', we examine the first of the 3 triangles generated above - } - } - } - return nVertices; -} -- cgit v1.2.3 From f775fb752cac57a0c1f6c42c8c60f5ff329eab32 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 22 Feb 2012 11:36:19 -0800 Subject: Revert "Integrating canvas-2d drawing and WebGL fixes, including adding back WebGL materials." This reverts commit 96a0a8c916533eb5625816192ed38488f639326d. --- js/helper-classes/RDGE/GLRectangle.js | 117 +++++++++++++++++++++++++++++++--- 1 file changed, 107 insertions(+), 10 deletions(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 5b6ff94f..4216fe53 100755 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -404,18 +404,12 @@ function GLRectangle() ctx.beginPath(); ctx.fillStyle = "#990000"; if (this._fillColor) - { - var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; - ctx.fillStyle = c; - } + ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); // set the stroke ctx.strokeStyle = "#0000ff"; if (this._strokeColor) - { - var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; - ctx.strokeStyle = c; - } + ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); ctx.lineWidth = lw; var inset = Math.ceil( 0.5*lw ) + 0.5; @@ -1057,12 +1051,13 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); - //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); } } // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); + //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1150,7 +1145,7 @@ RectangleGeometry.create = function( ctr, width, height, material ) { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); - //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); } } @@ -1228,6 +1223,108 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver } +ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) +{ + // get the param range + var pUMin = paramRange[0], pVMin = paramRange[1], + pUMax = paramRange[2], pVMax = paramRange[3]; + var iTriangle = 0; + var nTriangles = indices.length/3; + var index = 0; + while (iTriangle < nTriangles) + { + // get the indices of the 3 vertices + var i0 = indices[index], + i1 = indices[index+1], + i2 = indices[index+2]; + + // get the uv values + //var vrtIndex = 3*iTriangle; + var iuv0 = 2 * i0, + iuv1 = 2 * i1, + iuv2 = 2 * i2; + var u0 = uvs[iuv0], v0 = uvs[iuv0+1], + u1 = uvs[iuv1], v1 = uvs[iuv1+1], + u2 = uvs[iuv2], v2 = uvs[iuv2+1]; + + // find the u and v range + var uMin = u0, vMin = v0; + if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1; + if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2; + var uMax = u0, vMax = v0; + if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1; + if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2; + + // if the parameter range of the triangle is outside the + // desired parameter range, advance to the next polygon and continue + if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin)) + { + // go to the next triangle + iTriangle++; + index += 3; + } + else + { + // check thesize of the triangle in uv space. If small enough, advance + // to the next triangle. If not small enough, split the triangle into 3; + var du = uMax - uMin, dv = vMax - vMin; + if ((du < tolerance) && (dv < tolerance)) + { + iTriangle++; + index += 3; + } + else // split the triangle into 4 parts + { + //calculate the position of the new vertex + var iPt0 = 3 * i0, + iPt1 = 3 * i1, + iPt2 = 3 * i2; + var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], + x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], + x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; + + // calculate the midpoints of the edges + var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0, + xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0, + xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0; + + // calculate the uv values of the new coordinates + var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0, + uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0, + uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0; + + // calculate the normals for the new points + var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], + nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], + nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; + var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ), + nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ), + nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 ); + + // push everything + verts.push(xA); verts.push(yA); verts.push(zA); + verts.push(xB); verts.push(yB); verts.push(zB); + verts.push(xC); verts.push(yC); verts.push(zC); + uvs.push(uA), uvs.push(vA); + uvs.push(uB), uvs.push(vB); + uvs.push(uC), uvs.push(vC); + norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]); + norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]); + norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]); + + // split the current triangle into 4 + indices[index+1] = nVertices; indices[index+2] = nVertices+2; + indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++; + indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++; + indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++; + nVertices += 3; + + // by not advancing 'index', we examine the first of the 3 triangles generated above + } + } + } + return nVertices; +} -- cgit v1.2.3 From d5b216d9d6d2b8cb93106e8f8ca351089d05b41d Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Wed, 22 Feb 2012 11:52:31 -0800 Subject: Integrating canvas-2d and WebGL drawing fixes. Also adding back WebGL materials. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/RDGE/GLRectangle.js | 117 +++------------------------------- 1 file changed, 10 insertions(+), 107 deletions(-) (limited to 'js/helper-classes/RDGE/GLRectangle.js') diff --git a/js/helper-classes/RDGE/GLRectangle.js b/js/helper-classes/RDGE/GLRectangle.js index 4216fe53..5b6ff94f 100755 --- a/js/helper-classes/RDGE/GLRectangle.js +++ b/js/helper-classes/RDGE/GLRectangle.js @@ -404,12 +404,18 @@ function GLRectangle() ctx.beginPath(); ctx.fillStyle = "#990000"; if (this._fillColor) - ctx.fillStyle = MathUtils.colorToHex( this._fillColor ); + { + var c = "rgba(" + 255*this._fillColor[0] + "," + 255*this._fillColor[1] + "," + 255*this._fillColor[2] + "," + this._fillColor[3] + ")"; + ctx.fillStyle = c; + } // set the stroke ctx.strokeStyle = "#0000ff"; if (this._strokeColor) - ctx.strokeStyle = MathUtils.colorToHex( this._strokeColor ); + { + var c = "rgba(" + 255*this._strokeColor[0] + "," + 255*this._strokeColor[1] + "," + 255*this._strokeColor[2] + "," + this._strokeColor[3] + ")"; + ctx.strokeStyle = c; + } ctx.lineWidth = lw; var inset = Math.ceil( 0.5*lw ) + 0.5; @@ -1051,13 +1057,12 @@ RectangleStroke.create = function( rectCtr, width, height, strokeWidth, tlRad, { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); - nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); } } // create the RDGE primitive var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.TRIANGLES, nVertices); - //var prim = ShapePrimitive.create(this.vertices, this.normals, this.uvs, this.indices, g_Engine.getContext().renderer.LINES, nVertices); return prim; } @@ -1145,7 +1150,7 @@ RectangleGeometry.create = function( ctr, width, height, material ) { var paramRange = material.getVertexDeformationRange(); var tolerance = material.getVertexDeformationTolerance(); - nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); + //nVertices = ShapePrimitive.refineMesh( this.vertices, this.normals, this.uvs, this.indices, nVertices, paramRange, tolerance ); } } @@ -1223,108 +1228,6 @@ ShapePrimitive.create = function(coords, normals, uvs, indices, primType, ver } -ShapePrimitive.refineMesh = function( verts, norms, uvs, indices, nVertices, paramRange, tolerance ) -{ - // get the param range - var pUMin = paramRange[0], pVMin = paramRange[1], - pUMax = paramRange[2], pVMax = paramRange[3]; - var iTriangle = 0; - var nTriangles = indices.length/3; - var index = 0; - while (iTriangle < nTriangles) - { - // get the indices of the 3 vertices - var i0 = indices[index], - i1 = indices[index+1], - i2 = indices[index+2]; - - // get the uv values - //var vrtIndex = 3*iTriangle; - var iuv0 = 2 * i0, - iuv1 = 2 * i1, - iuv2 = 2 * i2; - var u0 = uvs[iuv0], v0 = uvs[iuv0+1], - u1 = uvs[iuv1], v1 = uvs[iuv1+1], - u2 = uvs[iuv2], v2 = uvs[iuv2+1]; - - // find the u and v range - var uMin = u0, vMin = v0; - if (u1 < uMin) uMin = u1; if (v1 < vMin) vMin = v1; - if (u2 < uMin) uMin = u2; if (v2 < vMin) vMin = v2; - var uMax = u0, vMax = v0; - if (u1 > uMax) uMax = u1; if (v1 > vMax) vMax = v1; - if (u2 > uMax) uMax = u2; if (v2 > vMax) vMax = v2; - - // if the parameter range of the triangle is outside the - // desired parameter range, advance to the next polygon and continue - if ((uMin > pUMax) || (uMax < pUMin) || (vMin > pVMax) || (vMax < pVMin)) - { - // go to the next triangle - iTriangle++; - index += 3; - } - else - { - // check thesize of the triangle in uv space. If small enough, advance - // to the next triangle. If not small enough, split the triangle into 3; - var du = uMax - uMin, dv = vMax - vMin; - if ((du < tolerance) && (dv < tolerance)) - { - iTriangle++; - index += 3; - } - else // split the triangle into 4 parts - { - //calculate the position of the new vertex - var iPt0 = 3 * i0, - iPt1 = 3 * i1, - iPt2 = 3 * i2; - var x0 = verts[iPt0], y0 = verts[iPt0+1], z0 = verts[iPt0+2], - x1 = verts[iPt1], y1 = verts[iPt1+1], z1 = verts[iPt1+2], - x2 = verts[iPt2], y2 = verts[iPt2+1], z2 = verts[iPt2+2]; - - // calculate the midpoints of the edges - var xA = (x0 + x1)/2.0, yA = (y0 + y1)/2.0, zA = (z0 + z1)/2.0, - xB = (x1 + x2)/2.0, yB = (y1 + y2)/2.0, zB = (z1 + z2)/2.0, - xC = (x2 + x0)/2.0, yC = (y2 + y0)/2.0, zC = (z2 + z0)/2.0; - - // calculate the uv values of the new coordinates - var uA = (u0 + u1)/2.0, vA = (v0 + v1)/2.0, - uB = (u1 + u2)/2.0, vB = (v1 + v2)/2.0, - uC = (u2 + u0)/2.0, vC = (v2 + v0)/2.0; - - // calculate the normals for the new points - var nx0 = norms[iPt0], ny0 = norms[iPt0+1], nz0 = norms[iPt0+2], - nx1 = norms[iPt1], ny1 = norms[iPt1+1], nz1 = norms[iPt1+2], - nx2 = norms[iPt2], ny2 = norms[iPt2+1], nz2 = norms[iPt2+2]; - var nxA = (nx0 + nx1), nyA = (ny0 + ny1), nzA = (nz0 + nz1); var nrmA = VecUtils.vecNormalize(3, [nxA, nyA, nzA], 1.0 ), - nxB = (nx1 + nx2), nyB = (ny1 + ny2), nzB = (nz1 + nz2); var nrmB = VecUtils.vecNormalize(3, [nxB, nyB, nzB], 1.0 ), - nxC = (nx2 + nx0), nyC = (ny2 + ny0), nzC = (nz2 + nz0); var nrmC = VecUtils.vecNormalize(3, [nxC, nyC, nzC], 1.0 ); - - // push everything - verts.push(xA); verts.push(yA); verts.push(zA); - verts.push(xB); verts.push(yB); verts.push(zB); - verts.push(xC); verts.push(yC); verts.push(zC); - uvs.push(uA), uvs.push(vA); - uvs.push(uB), uvs.push(vB); - uvs.push(uC), uvs.push(vC); - norms.push(nrmA[0]); norms.push(nrmA[1]); norms.push(nrmA[2]); - norms.push(nrmB[0]); norms.push(nrmB[1]); norms.push(nrmB[2]); - norms.push(nrmC[0]); norms.push(nrmC[1]); norms.push(nrmC[2]); - - // split the current triangle into 4 - indices[index+1] = nVertices; indices[index+2] = nVertices+2; - indices.push(nVertices); indices.push(i1); indices.push(nVertices+1); nTriangles++; - indices.push(nVertices+1); indices.push(i2); indices.push(nVertices+2); nTriangles++; - indices.push(nVertices); indices.push(nVertices+1); indices.push(nVertices+2); nTriangles++; - nVertices += 3; - - // by not advancing 'index', we examine the first of the 3 triangles generated above - } - } - } - return nVertices; -} -- cgit v1.2.3