From 6cbeb36736e5a012fa1688db78d5981c2e61d95b Mon Sep 17 00:00:00 2001 From: hwc487 Date: Thu, 28 Jun 2012 15:06:33 -0700 Subject: Fixes for incorrect line/polygon intersections. --- js/helper-classes/3D/StageLine.js | 76 ++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 33 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index 23e8cf5b..540109dc 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js @@ -222,49 +222,59 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { if (s0 != s1) { var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); - if (t == 0) + if (MathUtils.fpSign(t) === 0) { - if (s1 > 0) // entering the material from the beginning of the line that is to be drawn + // the first point of the line is on the (infinite) extension of a side of the boundary. + // Make sure the point (pt0) is within the range of the polygon edge + var vt0 = vecUtils.vecSubtract(3, pt0, bp0), + vt1 = vecUtils.vecSubtract(3, bp1, pt0); + var dt0 = vecUtils.vecDot(3, vec, vt0), + dt1 = vecUtils.vecDot(3, vec, vt1); + var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1); + if ((st0 >= 0) && (st1 >= 0)) { - // see if the start point of the line is at a corner of the bounded plane - var lineDir = vecUtils.vecSubtract(3, pt1, pt0); - vecUtils.vecNormalize(3, lineDir); - var dist = vecUtils.vecDist( 3, pt0, bp1 ); - var bp2, bv0, bv1, cross1, cross2, cross3; - if ( MathUtils.fpSign(dist) == 0) + if (s1 > 0) // entering the material from the beginning of the line that is to be drawn { - bp2 = boundaryPts[(i+1) % 4]; - bv0 = vecUtils.vecSubtract(3, bp2, bp1); - bv1 = vecUtils.vecSubtract(3, bp0, bp1); - cross1 = vecUtils.vecCross(3, bv0, lineDir); - cross2 = vecUtils.vecCross(3, lineDir, bv1); - cross3 = vecUtils.vecCross(3, bv0, bv1); - if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + // see if the start point of the line is at a corner of the bounded plane + var lineDir = vecUtils.vecSubtract(3, pt1, pt0); + vecUtils.vecNormalize(3, lineDir); + var dist = vecUtils.vecDist( 3, pt0, bp1 ); + var bp2, bv0, bv1, cross1, cross2, cross3; + if ( MathUtils.fpSign(dist) == 0) { - gotEnter = true; - this.addIntersection( plane, t, 1 ); + bp2 = boundaryPts[(i+1) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp1); + bv1 = vecUtils.vecSubtract(3, bp0, bp1); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } } - } - else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) - { - bp2 = boundaryPts[(i+2) % 4]; - bv0 = vecUtils.vecSubtract(3, bp2, bp0); - bv1 = vecUtils.vecSubtract(3, bp1, bp0); - cross1 = vecUtils.vecCross(3, bv0, lineDir); - cross2 = vecUtils.vecCross(3, lineDir, bv1); - cross3 = vecUtils.vecCross(3, bv0, bv1); - if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) { + bp2 = boundaryPts[(i+2) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp0); + bv1 = vecUtils.vecSubtract(3, bp1, bp0); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else + { + // check if the line is on the edge of the boundary or goes to the interior gotEnter = true; this.addIntersection( plane, t, 1 ); } } - else - { - // check if the line is on the edge of the boundary or goes to the interior - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } } } else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) -- cgit v1.2.3 From 3df60279083f2cda60b3b871037c6d58454de5b2 Mon Sep 17 00:00:00 2001 From: hwc487 Date: Fri, 29 Jun 2012 10:53:03 -0700 Subject: Fixes a bug in rectangle containment test. --- js/helper-classes/3D/math-utils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 44e2499d..409d2750 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -815,7 +815,8 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { { //var t = vec1.modulus() / vec0.modulus(); var t = VecUtils.vecMag(2, vec1)/VecUtils.vecMag(2, vec0); - if ((this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0)) + var dot = VecUtils.vecDot(2, vec0, vec1); + if ((this.fpSign(dot) >= 0) && (this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0)) return this.ON; else return this.OUTSIDE; -- cgit v1.2.3 From 92822886cecd76eeac8207742f290e5b87902ddb Mon Sep 17 00:00:00 2001 From: hwc487 Date: Tue, 3 Jul 2012 11:41:06 -0700 Subject: fixes for grid drawing. --- js/helper-classes/3D/StageLine.js | 299 ++++++++++++++++++++++--------------- js/helper-classes/3D/math-utils.js | 9 +- 2 files changed, 187 insertions(+), 121 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index 540109dc..12efb140 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js @@ -52,149 +52,201 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { // Methods /////////////////////////////////////////////////////////////////////// - intersectWithPlane: { - value: function( plane ) - { - // if the plane is edge-on, ignore it - if ( MathUtils.fpSign( plane.getPlaneEq()[2] ) == 0 ) return; + intersectWithPlane: { + value: function( plane ) + { + // if the plane is edge-on, ignore it + if ( MathUtils.fpSign( plane.getPlaneEq()[2] ) == 0 ) return; - // do some quick box tests. - var minPt = this.getMinPoint(), - maxPt = this.getMaxPoint(); + // do some quick box tests. + var minPt = this.getMinPoint(), + maxPt = this.getMaxPoint(); - if (maxPt[0] < plane._rect.getLeft()) return; - if (minPt[0] > plane._rect.getRight()) return; + if (maxPt[0] < plane._rect.getLeft()) return; + if (minPt[0] > plane._rect.getRight()) return; - if (maxPt[1] < plane._rect.getTop()) return; - if (minPt[1] > plane._rect.getBottom()) return; + if (maxPt[1] < plane._rect.getTop()) return; + if (minPt[1] > plane._rect.getBottom()) return; - if (minPt[2] > plane.getZMax()) return; + if (minPt[2] > plane.getZMax()) return; - // get the boundary points for the plane - var boundaryPts = plane.getBoundaryPoints(); + // get the boundary points for the plane + var boundaryPts = plane.getBoundaryPoints().slice(); - // get the points and direction vector for the current line - var pt0 = this.getPoint0(), pt1 = this.getPoint1(); - //var lineDir = pt1.subtract( pt0 ); - var lineDir = vecUtils.vecSubtract(3, pt1, pt0); + // get the points and direction vector for the current line + var pt0 = this.getPoint0(), pt1 = this.getPoint1(); + //var lineDir = pt1.subtract( pt0 ); + var lineDir = vecUtils.vecSubtract(3, pt1, pt0); - // intersect with the front plane - var planeEq = plane.getPlaneEq(); - var t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); - if (t != undefined) - { - if ((MathUtils.fpSign(t) >= 0) && (MathUtils.fpCmp(t,1.0) <= 0)) - { - // get the intersection point - var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); - - // see if the intersection point is contained in the bounds - //var contains = this.boundaryContainsPoint( boundaryPts, plane.isBackFacing(), pt ); - var contains = MathUtils.boundaryContainsPoint( boundaryPts, pt, plane.isBackFacing() ); - if (contains == MathUtils.INSIDE) - { - // add the intersection - var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; - var deltaVis = (dot > 0) ? 1 : -1; + // intersect with the front plane + var planeEq = plane.getPlaneEq(); + var t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); + if (t != undefined) + { + if ((MathUtils.fpSign(t) >= 0) && (MathUtils.fpCmp(t,1.0) <= 0)) + { + // get the intersection point + var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); + + // see if the intersection point is contained in the bounds + //var contains = this.boundaryContainsPoint( boundaryPts, plane.isBackFacing(), pt ); + var onEdge = []; + var contains = MathUtils.boundaryContainsPoint( boundaryPts, pt, plane.isBackFacing(), onEdge ); + if (contains == MathUtils.INSIDE) + { + // add the intersection + var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; + var deltaVis = (dot > 0) ? 1 : -1; // if (plane.isBackFacing()) // deltaVis = (dot < 0) ? 1 : -1; - this.addIntersection( plane, t, deltaVis ); - } - else if (contains == MathUtils.ON) - { - if (MathUtils.fpCmp(t,1.0) < 0) - { - // take the dot product between the line and the normal to the plane - // to determine the change in visibility - var vec = vecUtils.vecSubtract( 3, pt1, pt0 ); - var dot = vecUtils.vecDot( 3, vec, plane.getPlaneEq() ); - var sign = MathUtils.fpSign( dot ); - if (sign == 0) - throw new Error( "coplanar intersection being treated as not coplanar" ); - if (!plane.isBackFacing()) - { - if (sign < 0) - this.addIntersection( plane, t, 1 ); - } - else - { - if (sign > 0) - this.addIntersection( plane, t, -1 ); - } - } - } - } - } - else - { - // the line must be parallel to the plane. If the line is in the plane, - // we need to do some special processing - var d0 = vecUtils.vecDot(3, planeEq, pt0) + planeEq[3], - d1 = vecUtils.vecDot(3, planeEq, pt1) + planeEq[3]; - if ((MathUtils.fpSign(d0) == 0) && (MathUtils.fpSign(d1) == 0)) - this.doCoplanarIntersection( plane ); - } + this.addIntersection( plane, t, deltaVis ); + } + else if (contains == MathUtils.ON) + { + if (MathUtils.fpCmp(t,1.0) < 0) + { + // determine if the intersection is on a front side (no intersection) of the polygons + //var ctr = [ 0.5*(boundaryPts[0][0] + boundaryPts[2][0]), 0.5*(boundaryPts[0][1] + boundaryPts[2][1]), 0.5*(boundaryPts[0][2] + boundaryPts[2][2]) ]; + //var vec = vecUtils.vecSubtract(3, pt, ctr ); + if ( !this.edgeIsFrontFacing(boundaryPts, planeEq, plane.isBackFacing(), onEdge[0], onEdge[1]) ) + { + // take the dot product between the line and the normal to the plane + // to determine the change in visibility + var vec = vecUtils.vecSubtract( 3, pt1, pt0 ); + var dot = vecUtils.vecDot( 3, vec, planeEq ); + var sign = MathUtils.fpSign( dot ); + if (sign == 0) + throw new Error( "coplanar intersection being treated as not coplanar" ); + if (!plane.isBackFacing()) + { + if (sign < 0) + this.addIntersection( plane, t, 1 ); + } + else + { + if (sign > 0) + this.addIntersection( plane, t, -1 ); + } + } + } + } + } + } + else + { + // the line must be parallel to the plane. If the line is in the plane, + // we need to do some special processing + var d0 = vecUtils.vecDot(3, planeEq, pt0) + planeEq[3], + d1 = vecUtils.vecDot(3, planeEq, pt1) + planeEq[3]; + if ((MathUtils.fpSign(d0) == 0) && (MathUtils.fpSign(d1) == 0)) + this.doCoplanarIntersection( plane ); + } - // intersect with the 4 planes formed by the edges of the plane, going back in Z - var bPt1 = boundaryPts[3]; - for (var i=0; i<4; i++) - { - // get the 2 points that define the front edge of the plane - var bPt0 = bPt1; - var bPt1 = boundaryPts[i]; - - // calculate the plane equation. The normal should point towards the OUTSIDE of the boundary - //var vec = bPt1.subtract( bPt0 ); - var vec = vecUtils.vecSubtract(3, bPt1, bPt0); - if (plane.isBackFacing()) - MathUtils.negate( vec ); - planeEq = [-vec[1], vec[0], 0]; - var normal = [planeEq[0], planeEq[1], planeEq[2]]; + // intersect with the 4 planes formed by the edges of the plane, going back in Z + var bPt1 = boundaryPts[3]; + for (var i=0; i<4; i++) + { + // get the 2 points that define the front edge of the plane + var bPt0 = bPt1; + var bPt1 = boundaryPts[i]; + + // calculate the plane equation. The normal should point towards the OUTSIDE of the boundary + //var vec = bPt1.subtract( bPt0 ); + var vec = vecUtils.vecSubtract(3, bPt1, bPt0); + if (plane.isBackFacing()) + MathUtils.negate( vec ); + planeEq = [-vec[1], vec[0], 0]; + var normal = [planeEq[0], planeEq[1], planeEq[2]]; // var d = -planeEq.dot(bPt0); - var d = -vecUtils.vecDot(3, planeEq, bPt0); - planeEq[3] = d; + var d = -vecUtils.vecDot(3, planeEq, bPt0); + planeEq[3] = d; - t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); - if (t) - { - if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! - { - // get the intersection point - var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); - - // we need to get the parameter on the edge of the projection - // of the intersection point onto the line. - var index = (Math.abs(vec[0]) > Math.abs(vec[1])) ? 0 : 1; - var tEdge = (pt[index] - bPt0[index])/(bPt1[index] - bPt0[index]); - if ((MathUtils.fpSign(tEdge) > 0) && (MathUtils.fpCmp(tEdge,1.0) <= 0)) - { - var edgePt = MathUtils.interpolateLine3D( bPt0, bPt1, tEdge ); - if (MathUtils.fpCmp(pt[2],edgePt[2]) < 0) - { - // add the intersection - var deltaVis = MathUtils.dot(lineDir,normal) > 0 ? -1 : 1; - this.addIntersection( plane, t, deltaVis ); - } - } - } - } - } - } - }, + t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); + if (t) + { + if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! + { + // get the intersection point + var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); + + // we need to get the parameter on the edge of the projection + // of the intersection point onto the line. + var index = (Math.abs(vec[0]) > Math.abs(vec[1])) ? 0 : 1; + var tEdge = (pt[index] - bPt0[index])/(bPt1[index] - bPt0[index]); + if ((MathUtils.fpSign(tEdge) > 0) && (MathUtils.fpCmp(tEdge,1.0) <= 0)) + { + var edgePt = MathUtils.interpolateLine3D( bPt0, bPt1, tEdge ); + if (MathUtils.fpCmp(pt[2],edgePt[2]) < 0) + { + // add the intersection + var deltaVis = MathUtils.dot(lineDir,normal) > 0 ? -1 : 1; + this.addIntersection( plane, t, deltaVis ); + } + } + } + } + } + } + }, + + edgeIsFrontFacing: + { + value: function(boundaryPts, planeNormal, backfacing, iEdge, t) + { + var frontFacing = false; + if (MathUtils.fpCmp(t,1.0) == 0) + { + iEdge = (iEdge + 1) % 4; + t = 0.0; + } + + var pt0 = boundaryPts[iEdge].slice(), + pt1 = boundaryPts[(iEdge+1)%4].slice(); + + var ctr = [ 0.5*(boundaryPts[0][0] + boundaryPts[2][0]), 0.5*(boundaryPts[0][1] + boundaryPts[2][1]), 0.5*(boundaryPts[0][2] + boundaryPts[2][2]) ], + mid = MathUtils.interpolateLine3D( pt0, pt1, 0.5 ); + var vec = vecUtils.vecSubtract( 3, mid, ctr ); + + if (MathUtils.fpSign(t) == 0) + { + // if the edge already calculated is back facing, check the preceeding edge + if (vec[2] > 0) + { + frontFacing = true; + } + else + { + var ptm1 = boundaryPts[(iEdge+3)%4].slice(); + mid = MathUtils.interpolateLine3D( ptm1, pt0, 0.5 ); + vec = vecUtils.vecSubtract( 3, mid, ctr ); + if (vec[2] > 0) frontFacing = true; + } + } + else + { + var cross = VecUtils.vecCross( 3, planeNormal, vecUtils.vecSubtract(3, pt1, pt0) ); + if ((!backfacing && (cross[2] > 0)) || (backfacing && (cross[2] < 0))) frontFacing = true; + } + + return frontFacing; + } + }, doCoplanarIntersection: { value: function( plane ) { // get the boundary points for the plane - var boundaryPts = plane.getBoundaryPoints(); + var boundaryPts = plane.getBoundaryPoints().slice(); var planeEq = plane.getPlaneEq(); - if (plane.isBackFacing()) + var backFacing = plane.isBackFacing(); + if (backFacing) { var tmp; tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; + vecUtils.vecNegate(4, planeEq); } var pt0 = this.getPoint0(), @@ -221,6 +273,12 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { if (s0 != s1) { + if (backFacing) + { + s0 = -s0; + s1 = -s1; + } + var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); if (MathUtils.fpSign(t) === 0) { @@ -233,7 +291,8 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { var st0 = MathUtils.fpSign(dt0), st1 = MathUtils.fpSign(dt1); if ((st0 >= 0) && (st1 >= 0)) { - if (s1 > 0) // entering the material from the beginning of the line that is to be drawn + //if ( (plane.isBackFacing() && (s1 < 0)) || (!plane.isBackFacing() && (s1 > 0)) ) // entering the material from the beginning of the line that is to be drawn + if (s1 > 0) { // see if the start point of the line is at a corner of the bounded plane var lineDir = vecUtils.vecSubtract(3, pt1, pt0); diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 409d2750..4da3d2c8 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -784,7 +784,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { }, boundaryContainsPoint: { - value: function( bounds, targetPt, backFacing ) + value: function( bounds, targetPt, backFacing, onParams ) { var pt = targetPt.slice(0); while (pt.length > 2) pt.pop(); @@ -817,7 +817,14 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { var t = VecUtils.vecMag(2, vec1)/VecUtils.vecMag(2, vec0); var dot = VecUtils.vecDot(2, vec0, vec1); if ((this.fpSign(dot) >= 0) && (this.fpSign(t) >= 0) && (this.fpCmp(t,1.0) <= 0)) + { + if (onParams) + { + onParams[0] = (i+3) % 4; + onParams[1] = t; + } return this.ON; + } else return this.OUTSIDE; } -- cgit v1.2.3 From 648ee61ae84216d0236e0dbc211addc13b2cfa3a Mon Sep 17 00:00:00 2001 From: Kris Kowal Date: Fri, 6 Jul 2012 11:52:06 -0700 Subject: Expand tabs --- js/helper-classes/3D/LinePlaneIntersectRec.js | 16 +- js/helper-classes/3D/Rectangle.js | 8 +- js/helper-classes/3D/StageLine.js | 372 +- js/helper-classes/3D/draw-utils.js | 2092 +++++----- js/helper-classes/3D/hit-record.js | 322 +- js/helper-classes/3D/math-utils.js | 252 +- js/helper-classes/3D/snap-2d-record.js | 84 +- js/helper-classes/3D/snap-manager.js | 4042 ++++++++++---------- js/helper-classes/3D/vec-utils.js | 146 +- js/helper-classes/3D/view-utils.js | 318 +- .../RDGE/src/core/script/MeshManager.js | 82 +- js/helper-classes/RDGE/src/core/script/box.js | 64 +- js/helper-classes/RDGE/src/core/script/camera.js | 8 +- js/helper-classes/RDGE/src/core/script/engine.js | 186 +- .../RDGE/src/core/script/init_state.js | 312 +- js/helper-classes/RDGE/src/core/script/jpass.js | 102 +- js/helper-classes/RDGE/src/core/script/jshader.js | 60 +- .../RDGE/src/core/script/lightmanager.js | 12 +- .../RDGE/src/core/script/math/mat4.js | 192 +- .../RDGE/src/core/script/math/quat.js | 64 +- .../RDGE/src/core/script/math/vec2.js | 6 +- .../RDGE/src/core/script/math/vec3.js | 18 +- .../RDGE/src/core/script/math/vec4.js | 46 +- .../RDGE/src/core/script/objectManager.js | 120 +- js/helper-classes/RDGE/src/core/script/particle.js | 14 +- .../RDGE/src/core/script/precompiled.js | 26 +- .../RDGE/src/core/script/renderUtils.js | 100 +- js/helper-classes/RDGE/src/core/script/renderer.js | 782 ++-- .../RDGE/src/core/script/run_state.js | 462 +-- js/helper-classes/RDGE/src/core/script/runtime.js | 24 +- .../RDGE/src/core/script/scenegraph.js | 306 +- .../RDGE/src/core/script/scenegraphNodes.js | 462 +-- .../RDGE/src/core/script/shadowLight.js | 4 +- js/helper-classes/RDGE/src/core/script/sockets.js | 130 +- .../RDGE/src/core/script/utilities.js | 14 +- 35 files changed, 5624 insertions(+), 5624 deletions(-) (limited to 'js/helper-classes') diff --git a/js/helper-classes/3D/LinePlaneIntersectRec.js b/js/helper-classes/3D/LinePlaneIntersectRec.js index 71ee81f4..ec2d6d57 100755 --- a/js/helper-classes/3D/LinePlaneIntersectRec.js +++ b/js/helper-classes/3D/LinePlaneIntersectRec.js @@ -60,17 +60,17 @@ var LinePlaneIntersectRec = exports.LinePlaneIntersectRec = Object.create(Object getElementPlanes: { value: function() { return this._elementPlanes; } }, setElementPlanes: { value: function(p) { this._elementPlanes = p; } }, - getT: { value: function() { return this._t; } }, - setT: { value: function(t) { this._t = t; } }, + getT: { value: function() { return this._t; } }, + setT: { value: function(t) { this._t = t; } }, - setDeltaVis: { value: function(d) { this._deltaVis = d; } }, - getDeltaVis: { value: function() { return this._deltaVis; } }, + setDeltaVis: { value: function(d) { this._deltaVis = d; } }, + getDeltaVis: { value: function() { return this._deltaVis; } }, - setNext: { value: function(n) { this._next = n; } }, - getNext: { value: function() { return this._next; } }, + setNext: { value: function(n) { this._next = n; } }, + getNext: { value: function() { return this._next; } }, - getPrev: { value: function() { return this._prev; } }, - setPrev: { value: function(p) { this._prev = p; } } + getPrev: { value: function() { return this._prev; } }, + setPrev: { value: function(p) { this._prev = p; } } /////////////////////////////////////////////////////////////////////// // Methods diff --git a/js/helper-classes/3D/Rectangle.js b/js/helper-classes/3D/Rectangle.js index 1922bd91..fb6127ed 100755 --- a/js/helper-classes/3D/Rectangle.js +++ b/js/helper-classes/3D/Rectangle.js @@ -67,7 +67,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { getHeight: { value: function() { return this.m_height; } }, setHeight: { value: function(h) { this.m_height = h; } }, - geomType: { value: function() { return this.GEOM_TYPE_RECTANGLE; } }, + geomType: { value: function() { return this.GEOM_TYPE_RECTANGLE; } }, /////////////////////////////////////////////////////////////////////// // Methods @@ -84,7 +84,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { } }, - dup: { + dup: { value: function() { var rtnRec = Object.create(Rectangle, {}); @@ -122,7 +122,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { } }, - setToBounds: { + setToBounds: { value: function( bounds ) { var pt = bounds[0]; @@ -166,7 +166,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { } }, - getQuadrant: { + getQuadrant: { value: function( iQuad ) { // quadrant ordering starts at upper left and continues around counter-clockwise diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index 787a4568..d6eea478 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js @@ -120,7 +120,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { // add the intersection var dot = MathUtils.dot3( pt0, planeEq ) + planeEq[3]; var deltaVis = (dot > 0) ? 1 : -1; -// if (plane.isBackFacing()) +// if (plane.isBackFacing()) // deltaVis = (dot < 0) ? 1 : -1; this.addIntersection( plane, t, deltaVis ); @@ -175,14 +175,14 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { MathUtils.negate( vec ); planeEq = [-vec[1], vec[0], 0]; var normal = [planeEq[0], planeEq[1], planeEq[2]]; -// var d = -planeEq.dot(bPt0); +// var d = -planeEq.dot(bPt0); var d = -vecUtils.vecDot(3, planeEq, bPt0); planeEq[3] = d; t = MathUtils.vecIntersectPlaneForParam( pt0, lineDir, planeEq ); if (t) { - if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! + if ((MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) // the strict vs not-strict inequality comparisons are IMPORTANT! { // get the intersection point var pt = MathUtils.interpolateLine3D( pt0, pt1, t ); @@ -207,184 +207,184 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { } }, - doCoplanarIntersection: { - value: function( plane ) - { - // get the boundary points for the plane - var boundaryPts = plane.getBoundaryPoints(); - var planeEq = plane.getPlaneEq(); - - if (plane.isBackFacing()) - { - var tmp; - tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; - tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; - } - - var pt0 = this.getPoint0(), - pt1 = this.getPoint1(); - - // keep a couple flags to prevent counting crossings twice in edge cases - var gotEnter = false, - gotExit = false; - - var bp1 = boundaryPts[3]; - for (var i=0; i<4; i++) - { - var bp0 = bp1; - bp1 = boundaryPts[i]; - var vec = vecUtils.vecSubtract(3, bp1, bp0); - var nrm = vecUtils.vecCross(3, vec, planeEq); - nrm[3] = -vecUtils.vecDot(3, bp0, nrm); - - var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], - d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; - - var s0 = MathUtils.fpSign(d0), - s1 = MathUtils.fpSign(d1); - - if (s0 != s1) - { - var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); - if (t == 0) - { - if (s1 > 0) // entering the material from the beginning of the line that is to be drawn - { - // see if the start point of the line is at a corner of the bounded plane - var lineDir = vecUtils.vecSubtract(3, pt1, pt0); - vecUtils.vecNormalize(3, lineDir); - var dist = vecUtils.vecDist( 3, pt0, bp1 ); - var bp2, bv0, bv1, cross1, cross2, cross3; - if ( MathUtils.fpSign(dist) == 0) - { - bp2 = boundaryPts[(i+1) % 4]; - bv0 = vecUtils.vecSubtract(3, bp2, bp1); - bv1 = vecUtils.vecSubtract(3, bp0, bp1); - cross1 = vecUtils.vecCross(3, bv0, lineDir); - cross2 = vecUtils.vecCross(3, lineDir, bv1); - cross3 = vecUtils.vecCross(3, bv0, bv1); - if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) - { - bp2 = boundaryPts[(i+2) % 4]; - bv0 = vecUtils.vecSubtract(3, bp2, bp0); - bv1 = vecUtils.vecSubtract(3, bp1, bp0); - cross1 = vecUtils.vecCross(3, bv0, lineDir); - cross2 = vecUtils.vecCross(3, lineDir, bv1); - cross3 = vecUtils.vecCross(3, bv0, bv1); - if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else - { - // check if the line is on the edge of the boundary or goes to the interior - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - } - else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) - { - // get the point where the line crosses the edge of the element plane - var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); - - // we know that the line crosses the infinite extension of the edge. Determine - // if that crossing is within the bounds of the edge - var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), - dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); - if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) - { - // determine if the line is entering or exiting - if (s0 <= 0) // entering - { - if (!gotEnter) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) // exiting - { - if (!gotExit) - { - gotExit = true; - this.addIntersection( plane, t, -1 ); - } - } - else // s0 == 0 - { - // TODO - } - } - else if ((MathUtils.fpSign(dot0) == 0) && (MathUtils.fpSign(dot1) < 0)) - { - var j = i - 2; - if (j < 0) j += 4; - var bp = boundaryPts[j]; - - var v0 = vecUtils.vecSubtract( 3, bp, bp0 ), - v1 = vec; - - if (s0 <= 0) - { - var v = vecUtils.vecSubtract(3, pt1, pt0); - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) - { - var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, -1 ); - } - } - } - else if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) == 0)) - { - var j = (i + 1) % 4; - var bp = boundaryPts[j]; - - var v1 = vec.slice(0), - v0 = vecUtils.vecSubtract( 3, bp, bp1 ), - v1 = vecUtils.vecNegate(3, v1); - - if (s0 <= 0) - { - var v = vecUtils.vecSubtract(3, pt1, pt0); - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) < 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) < 0)) - { - gotEnter = true; - this.addIntersection( plane, t, 1 ); - } - } - else if (s0 > 0) - { - var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case - if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) - { - gotEnter = true; - this.addIntersection( plane, t, -1 ); - } - } - } - } - } - } - } - }, + doCoplanarIntersection: { + value: function( plane ) + { + // get the boundary points for the plane + var boundaryPts = plane.getBoundaryPoints(); + var planeEq = plane.getPlaneEq(); + + if (plane.isBackFacing()) + { + var tmp; + tmp = boundaryPts[0]; boundaryPts[0] = boundaryPts[3]; boundaryPts[3] = tmp; + tmp = boundaryPts[1]; boundaryPts[1] = boundaryPts[2]; boundaryPts[2] = tmp; + } + + var pt0 = this.getPoint0(), + pt1 = this.getPoint1(); + + // keep a couple flags to prevent counting crossings twice in edge cases + var gotEnter = false, + gotExit = false; + + var bp1 = boundaryPts[3]; + for (var i=0; i<4; i++) + { + var bp0 = bp1; + bp1 = boundaryPts[i]; + var vec = vecUtils.vecSubtract(3, bp1, bp0); + var nrm = vecUtils.vecCross(3, vec, planeEq); + nrm[3] = -vecUtils.vecDot(3, bp0, nrm); + + var d0 = vecUtils.vecDot(3, nrm, pt0) + nrm[3], + d1 = vecUtils.vecDot(3, nrm, pt1) + nrm[3]; + + var s0 = MathUtils.fpSign(d0), + s1 = MathUtils.fpSign(d1); + + if (s0 != s1) + { + var t = Math.abs(d0)/( Math.abs(d0) + Math.abs(d1) ); + if (t == 0) + { + if (s1 > 0) // entering the material from the beginning of the line that is to be drawn + { + // see if the start point of the line is at a corner of the bounded plane + var lineDir = vecUtils.vecSubtract(3, pt1, pt0); + vecUtils.vecNormalize(3, lineDir); + var dist = vecUtils.vecDist( 3, pt0, bp1 ); + var bp2, bv0, bv1, cross1, cross2, cross3; + if ( MathUtils.fpSign(dist) == 0) + { + bp2 = boundaryPts[(i+1) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp1); + bv1 = vecUtils.vecSubtract(3, bp0, bp1); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (MathUtils.fpSign( vecUtils.vecDist(3, pt0, bp0)) === 0) + { + bp2 = boundaryPts[(i+2) % 4]; + bv0 = vecUtils.vecSubtract(3, bp2, bp0); + bv1 = vecUtils.vecSubtract(3, bp1, bp0); + cross1 = vecUtils.vecCross(3, bv0, lineDir); + cross2 = vecUtils.vecCross(3, lineDir, bv1); + cross3 = vecUtils.vecCross(3, bv0, bv1); + if ( (MathUtils.fpSign(vecUtils.vecDot(3, cross1, cross3)) == 0) && (MathUtils.fpSign(vecUtils.vecDot(3, cross2, cross3)) == 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else + { + // check if the line is on the edge of the boundary or goes to the interior + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + } + else if ( (MathUtils.fpSign(t) > 0) && (MathUtils.fpCmp(t,1.0) <= 0)) + { + // get the point where the line crosses the edge of the element plane + var pt = MathUtils.interpolateLine3D(pt0, pt1, t ); + + // we know that the line crosses the infinite extension of the edge. Determine + // if that crossing is within the bounds of the edge + var dot0 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp0), vec), + dot1 = vecUtils.vecDot(3, vecUtils.vecSubtract(3,pt, bp1), vec); + if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) < 0)) + { + // determine if the line is entering or exiting + if (s0 <= 0) // entering + { + if (!gotEnter) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) // exiting + { + if (!gotExit) + { + gotExit = true; + this.addIntersection( plane, t, -1 ); + } + } + else // s0 == 0 + { + // TODO + } + } + else if ((MathUtils.fpSign(dot0) == 0) && (MathUtils.fpSign(dot1) < 0)) + { + var j = i - 2; + if (j < 0) j += 4; + var bp = boundaryPts[j]; + + var v0 = vecUtils.vecSubtract( 3, bp, bp0 ), + v1 = vec; + + if (s0 <= 0) + { + var v = vecUtils.vecSubtract(3, pt1, pt0); + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) + { + var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, -1 ); + } + } + } + else if ((MathUtils.fpSign(dot0) > 0) && (MathUtils.fpSign(dot1) == 0)) + { + var j = (i + 1) % 4; + var bp = boundaryPts[j]; + + var v1 = vec.slice(0), + v0 = vecUtils.vecSubtract( 3, bp, bp1 ), + v1 = vecUtils.vecNegate(3, v1); + + if (s0 <= 0) + { + var v = vecUtils.vecSubtract(3, pt1, pt0); + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) < 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) < 0)) + { + gotEnter = true; + this.addIntersection( plane, t, 1 ); + } + } + else if (s0 > 0) + { + var v = vecUtils.vecSubtract(3, pt0, pt1); // note the reversed order from the previous case + if ((MathUtils.fpSign(vecUtils.vecCross(3, v0,v)) > 0) && (MathUtils.fpSign(vecUtils.vecCross(3, v,v1)) > 0)) + { + gotEnter = true; + this.addIntersection( plane, t, -1 ); + } + } + } + } + } + } + } + }, removeIntersections: { value: function() @@ -440,7 +440,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { } }, - boundaryContainsPoint: { + boundaryContainsPoint: { value: function( boundaryPts, backFacing, pt ) { // the computation is done in 2D. @@ -451,12 +451,12 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { { var pt0 = pt1; var pt1 = boundaryPts[i]; - //var vec0 = pt1.subtract( pt0 ), - // vec1 = pt.subtract( pt0 ); + //var vec0 = pt1.subtract( pt0 ), + // vec1 = pt.subtract( pt0 ); var vec0 = vecUtils.vecSubtract(3, pt1, pt0), vec1 = vecUtils.vecSubtract(pt, pt0); - // var cross = vec0.cross( vec1 ); + // var cross = vec0.cross( vec1 ); var cross = vecUtils.vecCross(3, vec0, vec1); var inside; if (backFacing) @@ -468,7 +468,7 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { } return true; - } + } }, setPoints: { diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 235b381e..6f4c287d 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -42,104 +42,104 @@ var StageLine = require("js/helper-classes/3D/StageLine").StageLine; var DrawUtils = exports.DrawUtils = Montage.create(Component, { - /////////////////////////////////////////////////////////////////////// - // Instance variables - /////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////// + // Instance variables + /////////////////////////////////////////////////////////////////////// viewUtils: { value: null, writable: true }, snapManager: { value: null }, ElementPlanes : { value: null, writable: true }, - // the drawing surface (a canvas) - _drawingSurfaceElt : { value: null, writable: true }, - _drawingContext : { value: null, writable: true }, + // the drawing surface (a canvas) + _drawingSurfaceElt : { value: null, writable: true }, + _drawingContext : { value: null, writable: true }, - // color to draw the lines - _lineColor : { value: "black", writable: true}, + // color to draw the lines + _lineColor : { value: "black", writable: true}, - // define a stack for quickly setting graphics states and restoring them - _stateArray : { value: [], writable: true }, + // define a stack for quickly setting graphics states and restoring them + _stateArray : { value: [], writable: true }, - // save references to the grid lines for quick redraw - _gridLineArray : {value: [], writable: true }, + // save references to the grid lines for quick redraw + _gridLineArray : {value: [], writable: true }, - // state for moveTo, lineTo - _curPt : { value: null, writable: true }, - _curVis : { value: null, writable: true }, + // state for moveTo, lineTo + _curPt : { value: null, writable: true }, + _curVis : { value: null, writable: true }, - // the element that defines the coordinate system for the displayed lines - _sourceSpaceElt : { value: null, writable: true }, + // the element that defines the coordinate system for the displayed lines + _sourceSpaceElt : { value: null, writable: true }, - // maintain a list of objects to hide against - _eltArray : {value: [], writable: true }, + // maintain a list of objects to hide against + _eltArray : {value: [], writable: true }, - // maintain a list of the planes to test against - _planesArray : {value: [], writable: true }, + // maintain a list of the planes to test against + _planesArray : {value: [], writable: true }, - // the working plane. - // a grid may be drawn aligned with this working plane - _workingPlane : { value: null, writable: true }, + // the working plane. + // a grid may be drawn aligned with this working plane + _workingPlane : { value: null, writable: true }, - // save some parameters about the grid. - // these parameters are set when the grid is drawn - _gridHorizontalSpacing : {value: 50, writable: true }, - _gridVerticalSpacing : {value: 50, writable: true }, - _gridHorizontalLineCount : {value:10, writable: true }, - _gridVerticalLineCount : {value:0, writable: true }, - _gridOrigin : {value: null, writable: true }, + // save some parameters about the grid. + // these parameters are set when the grid is drawn + _gridHorizontalSpacing : {value: 50, writable: true }, + _gridVerticalSpacing : {value: 50, writable: true }, + _gridHorizontalLineCount : {value:10, writable: true }, + _gridVerticalLineCount : {value:0, writable: true }, + _gridOrigin : {value: null, writable: true }, - drawXY : {value: false, writable: true }, - drawXZ : {value: false, writable: true }, - drawYZ : {value: false, writable: true }, + drawXY : {value: false, writable: true }, + drawXZ : {value: false, writable: true }, + drawYZ : {value: false, writable: true }, - drawElementN : {value: false, writable: true }, + drawElementN : {value: false, writable: true }, - _selectionCtr : {value: null, writable: true }, + _selectionCtr : {value: null, writable: true }, // Properties that require element planes to be updated - _updatePlaneProps : {value: ["matrix", "left", "top", "width", "height"], writable: false }, - _recalculateScrollOffsets : { value: false }, + _updatePlaneProps : {value: ["matrix", "left", "top", "width", "height"], writable: false }, + _recalculateScrollOffsets : { value: false }, - /////////////////////////////////////////////////////////////////////// - // Property accessors - /////////////////////////////////////////////////////////////////////// - setDrawingSurfaceElement : { value: function( s ) { this._drawingSurfaceElt = s; if (s) this._drawingContext = s.getContext("2d"); }}, - getDrawingSurfaceElement : { value: function() { return this._drawingSurfaceElt; }}, + /////////////////////////////////////////////////////////////////////// + // Property accessors + /////////////////////////////////////////////////////////////////////// + setDrawingSurfaceElement : { value: function( s ) { this._drawingSurfaceElt = s; if (s) this._drawingContext = s.getContext("2d"); }}, + getDrawingSurfaceElement : { value: function() { return this._drawingSurfaceElt; }}, - getDrawingContext : { value: function() { return this._drawingContext; }}, + getDrawingContext : { value: function() { return this._drawingContext; }}, - setSourceSpaceElement : { value: function(ss) { this._sourceSpaceElt = ss; }}, - getSourceSpaceElement : { value: function() { return this._sourceSpaceElt; }}, + setSourceSpaceElement : { value: function(ss) { this._sourceSpaceElt = ss; }}, + getSourceSpaceElement : { value: function() { return this._sourceSpaceElt; }}, - getWorkingPlane : { value: function() { return this._workingPlane; }}, - setWorkingPlane : { value: function (wp) { this._workingPlane = wp; }}, + getWorkingPlane : { value: function() { return this._workingPlane; }}, + setWorkingPlane : { value: function (wp) { this._workingPlane = wp; }}, - getGridHorizontalSpacing : { value: function() { return this._gridHorizontalSpacing; }}, - getGridVerticalSpacing : { value: function() { return this._gridVerticalSpacing; }}, - getGridHorizontalLineCount : { value: function() { return this._gridHorizontalLineCount; }}, - getGridVerticalLineCount : { value: function() { return this._gridVerticalLineCount; }}, - getGridOrigin : { value: function() { return this._gridOrigin.slice(0); }}, + getGridHorizontalSpacing : { value: function() { return this._gridHorizontalSpacing; }}, + getGridVerticalSpacing : { value: function() { return this._gridVerticalSpacing; }}, + getGridHorizontalLineCount : { value: function() { return this._gridHorizontalLineCount; }}, + getGridVerticalLineCount : { value: function() { return this._gridVerticalLineCount; }}, + getGridOrigin : { value: function() { return this._gridOrigin.slice(0); }}, - isDrawingGrid : { value: function() { return this.drawXY || this.drawYZ || this.drawXZ; }}, - isDrawingElementNormal : { value: function() { return this.drawElementN }}, + isDrawingGrid : { value: function() { return this.drawXY || this.drawYZ || this.drawXZ; }}, + isDrawingElementNormal : { value: function() { return this.drawElementN }}, - getLineColor : { value: function() { return this._lineColor; }}, - setLineColor : { value: function( color ) { this._lineColor = color; }}, + getLineColor : { value: function() { return this._lineColor; }}, + setLineColor : { value: function( color ) { this._lineColor = color; }}, - getLineWidth : { value: function() { return this._drawingContext.lineWidth; }}, - setLineWidth : { value: function( w ) { this._drawingContext.lineWidth = w; }}, + getLineWidth : { value: function() { return this._drawingContext.lineWidth; }}, + setLineWidth : { value: function( w ) { this._drawingContext.lineWidth = w; }}, - initialize: { - value: function() { - this._gridOrigin = [0,0]; // 2D plane space point + initialize: { + value: function() { + this._gridOrigin = [0,0]; // 2D plane space point this.eventManager.addEventListener("elementAdded", this, false); this.eventManager.addEventListener("elementsRemoved", this, false); this.eventManager.addEventListener("elementChange", this, false); this.eventManager.addEventListener("elementChanging", this, false); this.eventManager.addEventListener("elementReplaced", this, false); - } - }, + } + }, initializeFromDocument:{ value:function(adjustScrollOffsets, useStageValues){ @@ -364,502 +364,502 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { } }, - /////////////////////////////////////////////////////////////////////// - // Methods - /////////////////////////////////////////////////////////////////////// - - addElement: { - value: function( elt ) { - // check if we already know about this object - var n = this._eltArray.length; - for (var i=0; i 3) pt.pop(); - - var z = pt[2]; - var n = this._planesArray.length; - var vis = 0; - for (var i=0; i plane.getZMax()) continue; - - // test for containment in the polygon bounds - var contain = MathUtils.boundaryContainsPoint( plane.getBoundaryPoints(), pt, plane.isBackFacing() ); - if (contain == MathUtils.OUTSIDE) continue; - if (contain == MathUtils.ON) continue; - - // shoot a ray from the point in the +Z direction to get the z value of the plane - var vec = [0,0,1]; - var planeEq = plane.getPlaneEq(); - var ptOnPlane = MathUtils.vecIntersectPlane( pt, vec, planeEq ); - if (ptOnPlane) - { - // in keeping with the convention that a point "on" a face is outside the element, - // check that case. - //if (MathUtils.fpCmp(pt[2], ptOnPlane[2]) == 0) continue; - - // if the point is behind the plane, increase the visibility - if (MathUtils.fpCmp(pt[2],ptOnPlane[2]) <= 0) vis++; - } - } - - return vis; - } - }, - - moveTo : { - value: function( pt ) { - if (this._sourceSpaceElt) - pt = this.viewUtils.localToGlobal( pt, this._sourceSpaceElt ); - - this._curPt = pt.slice(0); - this._curVis = this.getVisibilityAtPoint( pt ); - } - }, - - lineTo : - { - value: function( pt ) - { - if (this._sourceSpaceElt) - pt = this.viewUtils.localToGlobal( pt, this._sourceSpaceElt ); - - var line = Object.create(StageLine, {}); - line.setPoints( this._curPt, pt ); - line.setVisibility( this._curVis ); - - // find all the plane intersections - this.getLineIntersections( line ); - - // draw the line - this._curVis = this.drawIntersectedLine( line, this._drawingContext ); - this._curPt = pt.slice(0); - } - }, - - - drawLine : - { - value: function( pt0, pt1 ) - { - if (this._drawingContext) - { - // transform the points from local object space to world space - if (this._sourceSpaceElt) - { - pt0 = this.viewUtils.localToGlobal( pt0, this._sourceSpaceElt ); - pt1 = this.viewUtils.localToGlobal( pt1, this._sourceSpaceElt ); - } - - // create the line structure - var line = Object.create(StageLine, {}); - line.setPoints( pt0, pt1 ); - - // find all the plane intersections - this.getLineIntersections( line ); - - // get the starting visibility - var vis = this.getVisibilityAtPoint( pt0 ); - line.setVisibility( vis ); - - // draw the line - this._curVis = this.drawIntersectedLine( line, this._drawingContext ); - } - } - }, - - drawIntersectedLine : - { - value: function( line ) - { - this._drawingContext.strokeStyle = this._lineColor; - this._drawingContext.beginPath(); - - // get the 2 enpoints of the line - var pt0 = line.getPoint0(), - pt1 = line.getPoint1(); - - // find the visibility at the start point - var vis = line.getVisibility(); - if (vis == 0) - { - this._drawingContext.strokeStyle = this._lineColor; - this._drawingContext.beginPath(); - this._drawingContext.moveTo( pt0[0], pt0[1] ); - } - - // go through each intersection - var n = line.getIntersectionCount(); - var t = 0.0; - var iRec = line.getIntersectionList(); - for (var i=0; i 3) pt.pop(); + + var z = pt[2]; + var n = this._planesArray.length; + var vis = 0; + for (var i=0; i