From 342fb451bd251358068a0dcb10e9dc218b79a176 Mon Sep 17 00:00:00 2001 From: Jonathan Duran Date: Tue, 6 Mar 2012 11:38:39 -0800 Subject: Squashed commit of the following: commit 1cd89d4d06e3a8f2c221628b19cf26a2c69f5d3f Author: Jose Antonio Marquez Date: Tue Mar 6 11:24:25 2012 -0800 Fixing WebGL not available bug commit 84332ab81c1b445195f1d9be8bbeae0725c8e758 Author: Valerio Virgillito Date: Tue Mar 6 10:58:25 2012 -0800 Squashed commit of preload-fix into Master - Requiring all the previously pre-loaded files - RDGE, Codemirror and gl-matrix are not included via a script tag. Signed-off-by: Valerio Virgillito commit 13f52cf0c74f53a919fa864f86669e8155f82961 Merge: dced508 abc04f3 Author: Valerio Virgillito Date: Fri Mar 2 15:46:11 2012 -0800 Merge pull request #93 from imix23ways/Timeline Timeline: Critical bug fixes commit dced508bb19a7bcd467ff1b86b5df5bbec4be794 Merge: 0aeb400 cc772ef Author: Valerio Virgillito Date: Fri Mar 2 15:45:35 2012 -0800 Merge pull request #92 from mqg734/WebGLFixes Selection Tool Fixes for elements flying off into space when they overlap commit 0aeb400070762cf01d83cf9f9ee25a5595098b7f Merge: ff0a956 aabb48a Author: Valerio Virgillito Date: Fri Mar 2 14:05:21 2012 -0800 Merge pull request #94 from ericguzman/PresetsPanel Presets Panel - Fix single-click activation, and transition cut-off bug. commit cc772ef3333ed419d269a2bda7aea5b0150a7bd9 Author: Nivesh Rajbhandari Date: Fri Mar 2 11:34:58 2012 -0800 Fixing flying off into space bug for translate tool too. Signed-off-by: Nivesh Rajbhandari commit abc04f3d50311ed1c21067344bc7e448686f8c5c Author: Jonathan Duran Date: Fri Mar 2 11:26:25 2012 -0800 Timeline Fix timing function Signed-off-by: Jonathan Duran commit aabb48a1c8d34bc968f4c6b0ffee4e31c1d5d286 Author: Eric Guzman Date: Fri Mar 2 11:22:44 2012 -0800 Presets Panel - Fix single-click activation, and transition cut-off bug. Use double-click as the activation event for transition presets. Also fixed the bug when applying a style preset before the transition preset, which disabled transitions after the first one. commit f3207f39ea9d8c1c34246217a23d3a689671903d Author: Nivesh Rajbhandari Date: Fri Mar 2 11:21:29 2012 -0800 Don't draw transform handles if the stage is the target element. Signed-off-by: Nivesh Rajbhandari commit 5425be91e7125c22955b4459a62412ff574e49a8 Author: Jonathan Duran Date: Fri Mar 2 11:11:48 2012 -0800 Timeline: Fix for animation iteration count Add default webkit css properties to allow animations with integer iteration counts. Signed-off-by: Jonathan Duran commit 1760bac1da9218315ad1bacdcf3a157495a049e8 Author: Nivesh Rajbhandari Date: Fri Mar 2 10:48:41 2012 -0800 Fix for jumping issue when moving items that have any 3d on them. We can't translate 3d moves into 2d space due to perspective, so we must update the matrix3d values instead of the top-left values if items have 3d. Signed-off-by: Nivesh Rajbhandari commit 2c04935f0ccb1cb7c98371fc10b43155f2d956c4 Author: Nivesh Rajbhandari Date: Thu Mar 1 22:20:06 2012 -0800 Fix for elements flying off into space when moving elements that overlap. This was happening because our hit record's element and the browser's element from point did not match. Signed-off-by: Nivesh Rajbhandari commit 50058746779f714ed9b0287f49e56c9f0d35593e Merge: 500426d ff0a956 Author: Nivesh Rajbhandari Date: Thu Mar 1 21:49:44 2012 -0800 Merge branch 'refs/heads/ninja-internal' into WebGLFixes commit 500426dea0ca95a6b45be8ea8d132cfdb4d2c940 Author: Nivesh Rajbhandari Date: Thu Mar 1 10:11:39 2012 -0800 Fixed logic error when resizing with the top-left transform handles. Signed-off-by: Nivesh Rajbhandari commit 7980d9bde2b43aa5a494ddf6f1db5c4959a57b91 Author: Nivesh Rajbhandari Date: Thu Mar 1 10:04:15 2012 -0800 Re-fixing IKNinja-940 - Can't select objects when in side/top view. Signed-off-by: Nivesh Rajbhandari commit f04cc0146d8f7573628678613a99c270116768e4 Author: Nivesh Rajbhandari Date: Wed Feb 29 16:45:40 2012 -0800 Last-used material (instead of FlatMaterial) is applied to shape when turning on use WebGL checkbox in the PI. Signed-off-by: Nivesh Rajbhandari Signed-off-by: Jonathan Duran --- js/helper-classes/3D/ParseUtils.js | 84 --------- js/helper-classes/3D/Rectangle.js | 2 +- js/helper-classes/3D/StageLine.js | 8 +- js/helper-classes/3D/draw-utils.js | 2 +- js/helper-classes/3D/element-planes.js | 2 +- js/helper-classes/3D/glUtils.js | 319 --------------------------------- js/helper-classes/3D/math-utils.js | 87 +++++---- js/helper-classes/3D/snap-2d-record.js | 2 +- js/helper-classes/3D/snap-manager.js | 78 ++++---- js/helper-classes/3D/vec-utils.js | 16 +- js/helper-classes/3D/view-utils.js | 12 +- 11 files changed, 121 insertions(+), 491 deletions(-) delete mode 100755 js/helper-classes/3D/ParseUtils.js delete mode 100755 js/helper-classes/3D/glUtils.js (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/ParseUtils.js b/js/helper-classes/3D/ParseUtils.js deleted file mode 100755 index 556253e9..00000000 --- a/js/helper-classes/3D/ParseUtils.js +++ /dev/null @@ -1,84 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ - -/////////////////////////////////////////////////////////////////////// -// Class Utils -// Vector Utility functions -/////////////////////////////////////////////////////////////////////// -function ParseUtils( theStr ) -{ - /////////////////////////////////////////////////////////////////////// - // Instance variables - /////////////////////////////////////////////////////////////////////// - this._strBuffer = theStr; - - /////////////////////////////////////////////////////////////////////// - // Property accessors - /////////////////////////////////////////////////////////////////////// - this.getBuffer = function() { return this._strBuffer; } - this.setBuffer = function(b) { this._strBuffer = b; } - - /////////////////////////////////////////////////////////////////////// - // Methods - /////////////////////////////////////////////////////////////////////// - this.nextValue = function( prop, endKeyArg, advanceBufferArg ) - { - if (!this._strBuffer) return; - - // make the 2 & 3rd argument optional. default is to advance the string - var endKey = "\n", advanceBuffer = true; - if (endKeyArg) - endKey = endKeyArg; - if (advanceBufferArg) - advanceBuffer = advanceBufferArg; - - var iStart = this._strBuffer.indexOf( prop ); - if (iStart < 0) return; - - var iEnd = this._strBuffer.indexOf( endKey, iStart ); - if (iEnd < 0) throw new Error( "property " + prop + " improperly terminated: " + this._strBuffer); - - iStart += prop.length; - var nChars = iEnd - iStart; - var rtnStr = this._strBuffer.substr( iStart, nChars ); - - if (advanceBuffer) - this._strBuffer = this._strBuffer.substr( iEnd + endKey.length ); - - return rtnStr; - } - - this.nextToken = function() - { - if (!this._strBuffer) return; - - // find the limits - var index = this._strBuffer.search( /\S/ ); // first non-whitespace character - if (index > 0) this._strBuffer = this._strBuffer.slice(index); - index = this._strBuffer.search( /\s/ ); // first whitespace character marking the end of the token - - var token; - if (index > 0) - { - token = this._strBuffer.slice(0, index); - this._strBuffer = this._strBuffer.slice( index ); - } - - return token; - } - - this.advancePastToken = function( token ) - { - var index = this._strBuffer.indexOf( token ); - if (index < 0) - console.log( "could not find token: " + token + " in string: " + this._strBuffer ); - else - this._strBuffer = this._strBuffer.substr( index + token.length ); - } - -} - - diff --git a/js/helper-classes/3D/Rectangle.js b/js/helper-classes/3D/Rectangle.js index e797eedf..b8906f18 100755 --- a/js/helper-classes/3D/Rectangle.js +++ b/js/helper-classes/3D/Rectangle.js @@ -35,7 +35,7 @@ var Rectangle = exports.Rectangle = Object.create(Object.prototype, { getTop: { value: function() { return this.m_top; } }, setTop: { value: function(t) { this.m_top = t; } }, - getCenter: { value: function() { return Vector.create( [this.m_left + 0.5*this.m_width, this.m_top + 0.5*this.m_height] ); } }, + getCenter: { value: function() { return [this.m_left + 0.5*this.m_width, this.m_top + 0.5*this.m_height]; } }, getWidth: { value: function() { return this.m_width; } }, setWidth: { value: function(w) { this.m_width = w; } }, diff --git a/js/helper-classes/3D/StageLine.js b/js/helper-classes/3D/StageLine.js index e0e7a8e3..b86673d1 100755 --- a/js/helper-classes/3D/StageLine.js +++ b/js/helper-classes/3D/StageLine.js @@ -149,8 +149,8 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { var vec = vecUtils.vecSubtract(3, bPt1, bPt0); if (plane.isBackFacing()) MathUtils.negate( vec ); - planeEq = Vector.create( [-vec[1], vec[0], 0] ); - var normal = Vector.create( [planeEq[0], planeEq[1], planeEq[2]] ); + 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; @@ -414,8 +414,8 @@ var StageLine = exports.StageLine = Object.create(Object.prototype, { if (pt0[1] < pt1[1]) { yMin = pt0[1]; yMax = pt1[1]; } else { yMin = pt1[1]; yMax = pt0[1]; } if (pt0[2] < pt1[2]) { zMin = pt0[2]; zMax = pt1[2]; } else { zMin = pt1[2]; zMax = pt0[2]; } - this._minPt = Vector.create( [xMin, yMin, zMin] ); - this._maxPt = Vector.create( [xMax, yMax, zMax] ); + this._minPt = [xMin, yMin, zMin]; + this._maxPt = [xMax, yMax, zMax]; } }//, diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 85870097..02d946ae 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -123,7 +123,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this._planesArray = []; this.setDrawingSurfaceElement(this.application.ninja.stage.canvas); this.setSourceSpaceElement( this.application.ninja.stage.stageDeps.currentStage ); - this.setWorkingPlane( Vector.create( [0,0,1,0] ) ); + this.setWorkingPlane( [0,0,1,0] ); //Loop through all the top-level children of the current document and call drawUtils.addElement on them if(this.application.ninja.currentDocument._liveNodeList.length > 0){ diff --git a/js/helper-classes/3D/element-planes.js b/js/helper-classes/3D/element-planes.js index 7ccf311e..38a7bf47 100755 --- a/js/helper-classes/3D/element-planes.js +++ b/js/helper-classes/3D/element-planes.js @@ -88,7 +88,7 @@ var ElementPlanes = exports.ElementPlanes = Object.create(Object.prototype, { // create the plane equation //var d = -( nrm.dot( this._boundaryPts[0]) ); var d = -vecUtils.vecDot(3, nrm, this._boundaryPts[0]); - var planeEq = Vector.create( [nrm[0], nrm[1], nrm[2], d] ); + var planeEq = [nrm[0], nrm[1], nrm[2], d] ; this.setPlaneEq( planeEq ); // get the 2D rectangle diff --git a/js/helper-classes/3D/glUtils.js b/js/helper-classes/3D/glUtils.js deleted file mode 100755 index f6d075f8..00000000 --- a/js/helper-classes/3D/glUtils.js +++ /dev/null @@ -1,319 +0,0 @@ -/* -This file contains proprietary software owned by Motorola Mobility, Inc.
-No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.
-(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. -
*/ - -// Constructor function -function Vector() {} -Vector.create = function(elements) -{ - var rtn; - if (elements) - rtn = elements.slice( 0 ); - else - rtn = []; - - return rtn; -}; - -Vector.dup = function(srcPt) -{ - return srcPt.slice(0); -} - - - -function Matrix() {} - -Matrix.create = function( rowArray ) -{ - var mat = Matrix.I(4); - var index = 0; - for(var j=0; j<4; j++) - { - for (var i=0; i<4; i++) - { - mat[index] = rowArray[i][j]; - index++; - } - } - - return mat; -} -Matrix.I = function(dimen) -{ - var mat = []; - for (var i=0; i 4 || - this.elements[0].length > 4) - return null; - - for (var i = 0; i < this.elements.length; i++) { - for (var j = this.elements[i].length; j < 4; j++) { - if (i == j) - this.elements[i].push(1); - else - this.elements[i].push(0); - } - } - - for (var i = this.elements.length; i < 4; i++) { - if (i == 0) - this.elements.push([1, 0, 0, 0]); - else if (i == 1) - this.elements.push([0, 1, 0, 0]); - else if (i == 2) - this.elements.push([0, 0, 1, 0]); - else if (i == 3) - this.elements.push([0, 0, 0, 1]); - } - - return this; -}; - -Matrix.prototype.make3x3 = function() -{ - if (this.elements.length != 4 || - this.elements[0].length != 4) - return null; - - return Matrix.create([[this.elements[0][0], this.elements[0][1], this.elements[0][2]], - [this.elements[1][0], this.elements[1][1], this.elements[1][2]], - [this.elements[2][0], this.elements[2][1], this.elements[2][2]]]); -}; -*/ - -/* -///////////////////////////////////////////////////////////////////////////////////////////// -// SMatrix - -SMatrix.Translation = function (vec) -{ - var mat = SMatrix.I(4); - mat.elements[0][3] = vec[0]; - mat.elements[1][3] = vec[1]; - mat.elements[2][3] = vec[2]; - return mat; -} - -SMatrix.RotationX = function( angle ) -{ - var mat = SMatrix.I(4); - mat.rotateX(angle); - return mat; -} - -SMatrix.RotationY = function( angle ) -{ - var mat = SMatrix.I(4); - mat.rotateX(angle); - return mat; -} - -SMatrix.RotationZ = function( angle ) -{ - var mat = SMatrix.I(4); - mat.rotateZ(angle); - return mat; -} - -SMatrix.MatrixtoSMatrix = function( mat ) -{ - var smat = SMatrix.I(4); - var index = 0; - for (var j=0; j<4; j++) - { - for (var i=0; i<4; i++) - { - smat.elements[i][j] = mat[index]; - index++; - } - } - - return smat; -} - -SMatrix.MatEqSMat = function( mat, sMat ) -{ - var index = 0; - for (var j=0; j<4; j++) - { - for (var i=0; i<4; i++) - { - var m = mat[index]; - var s = smat.elements[i][j]; - if ( MathUtils.fpCmp(m,s) != 0) - throw new Error( "mat != smat" ); - index++; - } - } -} - -// Matrix -///////////////////////////////////////////////////////////////////////////////////////////// -*/ - -Vector.prototype.flatten = function () -{ - return this.elements; -}; - -function mht(m) { - var s = ""; - if (m.length == 16) { - for (var i = 0; i < 4; i++) { - s += "[" + m[i*4+0].toFixed(4) + "," + m[i*4+1].toFixed(4) + "," + m[i*4+2].toFixed(4) + "," + m[i*4+3].toFixed(4) + "]
"; - } - } else if (m.length == 9) { - for (var i = 0; i < 3; i++) { - s += "[" + m[i*3+0].toFixed(4) + "," + m[i*3+1].toFixed(4) + "," + m[i*3+2].toFixed(4) + "]
"; - } - } else { - return m.toString(); - } - return s; -} - -// -// gluLookAt -// -function makeLookAt(ex, ey, ez, - cx, cy, cz, - ux, uy, uz) -{ - var eye = $V([ex, ey, ez]); - var center = $V([cx, cy, cz]); - var up = $V([ux, uy, uz]); - - var mag; - - var z = eye.subtract(center).toUnitVector(); - var x = up.cross(z).toUnitVector(); - var y = z.cross(x).toUnitVector(); - - var m = $M([[x.e(1), x.e(2), x.e(3), 0], - [y.e(1), y.e(2), y.e(3), 0], - [z.e(1), z.e(2), z.e(3), 0], - [0, 0, 0, 1]]); - - var t = $M([[1, 0, 0, -ex], - [0, 1, 0, -ey], - [0, 0, 1, -ez], - [0, 0, 0, 1]]); - return m.x(t); -} - -// -// gluPerspective -// -function makePerspective(fovy, aspect, znear, zfar) -{ - var ymax = znear * Math.tan(fovy * Math.PI / 360.0); - var ymin = -ymax; - var xmin = ymin * aspect; - var xmax = ymax * aspect; - - return makeFrustum(xmin, xmax, ymin, ymax, znear, zfar); -} - -// -// glFrustum -// -function makeFrustum(left, right, - bottom, top, - znear, zfar) -{ - var X = 2*znear/(right-left); - var Y = 2*znear/(top-bottom); - var A = (right+left)/(right-left); - var B = (top+bottom)/(top-bottom); - var C = -(zfar+znear)/(zfar-znear); - var D = -2*zfar*znear/(zfar-znear); - - return Matrix.create([[X, 0, A, 0], - [0, Y, B, 0], - [0, 0, C, D], - [0, 0, -1, 0]]); -} - -// -// glOrtho -// -function makeOrtho(left, right, bottom, top, znear, zfar) -{ - var tx = - (right + left) / (right - left); - var ty = - (top + bottom) / (top - bottom); - var tz = - (zfar + znear) / (zfar - znear); - - return $M([[2 / (right - left), 0, 0, tx], - [0, 2 / (top - bottom), 0, ty], - [0, 0, -2 / (zfar - znear), tz], - [0, 0, 0, 1]]); -} diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 37044763..562a6e73 100755 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -86,7 +86,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { if (b.length < n) n = b.length; if (n > 0) { - rtnVec = Vector.create([0]); + rtnVec = [0]; for (var i=0; i 0) { - rtnVec = Vector.create([0]); + rtnVec = [0]; for (var i=0; i 1.0 ) { - var intersection = Vector.create([ - segP0[0] + U * (segP1[0] - segP0[0]), - segP0[1] + U * (segP1[1] - segP0[1]), - segP0[2] + U * (segP1[2] - segP0[2])]); + var intersection = [ segP0[0] + U * (segP1[0] - segP0[0]), segP0[1] + U * (segP1[1] - segP0[1]), segP0[2] + U * (segP1[2] - segP0[2])]; return this.vecDist(intersection, pt); } @@ -538,6 +525,39 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, + isIdentityMatrix: { + value: function( mat ) + { + if(!mat) + { + return false; + } + else + { + if(mat[0] !== 1) return false; + if(mat[1] !== 0) return false; + if(mat[2] !== 0) return false; + if(mat[3] !== 0) return false; + + if(mat[4] !== 0) return false; + if(mat[5] !== 1) return false; + if(mat[6] !== 0) return false; + if(mat[7] !== 0) return false; + + if(mat[8] !== 0) return false; + if(mat[9] !== 0) return false; + if(mat[10] !== 1) return false; + if(mat[11] !== 0) return false; + + if(mat[12] !== 0) return false; + if(mat[13] !== 0) return false; + if(mat[14] !== 0) return false; + if(mat[15] !== 1) return false; + } + return true; + } + }, + rectsOverlap: { value: function( pt, width, height, elt ) @@ -704,7 +724,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { yNrm += (zPts[i] - zPts[j]) * (xPts[i] + xPts[j]); zNrm += (xPts[i] - xPts[j]) * (yPts[i] + yPts[j]); } - var normal = Vector.create( [xNrm, yNrm, zNrm] ); + var normal = [xNrm, yNrm, zNrm]; // the area of the polygon is the length of the normal var area = VecUtils.vecMag(3, normal ); @@ -727,7 +747,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { yNrm += (b[i][2] - b[j][2]) * (b[i][0] + b[j][0]); zNrm += (b[i][0] - b[j][0]) * (b[i][1] + b[j][1]); } - var normal = Vector.create( [xNrm, yNrm, zNrm] ); + var normal = [xNrm, yNrm, zNrm]; // the area of the polygon is the length of the normal var area = VecUtils.vecMag(3, normal ); @@ -867,7 +887,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { // var v0 = pt0.slice(0); // var v1 = pt1.slice(0); // -// var origin = Vector.create([0, 0]); +// var origin = [0, 0]; // // if(origin) // { @@ -931,8 +951,7 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { if(!localPt) { return null; - return Vector.create( [1, 1]); - return [1, 1]; +// return [1, 1]; } localPt = this.transformPoint(localPt, matL); @@ -1023,12 +1042,12 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { perspectiveMatrix, inversePerspectiveMatrix, transposedInversePerspectiveMatrix, - perspective = Vector.create([0,0,0,0]), - translate = Vector.create([0,0,0]), - scale = Vector.create([0,0,0]), - skew = Vector.create([0,0,0]), - rotate = Vector.create([0,0,0]), - rightHandSide = Vector.create([0,0,0,0]); + perspective = [0,0,0,0], + translate = [0,0,0], + scale = [0,0,0], + skew = [0,0,0], + rotate = [0,0,0], + rightHandSide = [0,0,0,0]; // Normalize the matrix. if (matrix[15] === 0) { @@ -1106,9 +1125,9 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } // Compute X scale factor and normalize first row. - var rowX = Vector.create([row[0], row[0+4], row[0+8]]); - var rowY = Vector.create([row[1], row[1+4], row[1+8]]); - var rowZ = Vector.create([row[2], row[2+4], row[2+8]]); + var rowX = [row[0], row[0+4], row[0+8]]; + var rowY = [row[1], row[1+4], row[1+8]]; + var rowZ = [row[2], row[2+4], row[2+8]]; scale[0] = VecUtils.vecMag(3, rowX); rowX = VecUtils.vecNormalize(3, rowX); row[0] = rowX[0]; diff --git a/js/helper-classes/3D/snap-2d-record.js b/js/helper-classes/3D/snap-2d-record.js index c77b28b3..844bb3be 100755 --- a/js/helper-classes/3D/snap-2d-record.js +++ b/js/helper-classes/3D/snap-2d-record.js @@ -78,7 +78,7 @@ var Snap2DRecord = exports.Snap2DRecord = Object.create(Object.prototype, // add the center point var xCtr = 0.5*(bounds[0][0] + bounds[3][0]), yCtr = 0.5*(bounds[0][1] + bounds[1][1]); - var ctr = Vector.create( [xCtr, yCtr, 0] ); + var ctr = [xCtr, yCtr, 0]; this._screenPtArray[4] = viewUtils.localToGlobal( ctr, elt ); var worldPt = viewUtils.localToStageWorld( ctr, elt ); this._alignPtArray[4] = MathUtils.transformPoint( worldPt, snapManager.SnapManager._worldToDragPlane ); diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 372be345..cf8a91db 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -40,6 +40,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { // keep a reference to the most recent hitRecord. Used for drawing feedback on the stage _lastHit : { value: null, writable: true }, + _hitRecords : { value: [], writable: true }, // keep a list of objects to avoid snapping to _avoidList : { value: [], writable: true }, @@ -210,9 +211,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var stage = this.getStage(); var parentPt; if (quadPt) - parentPt = Vector.create([quadPt[0], quadPt[1], 0.0]); + parentPt = [quadPt[0], quadPt[1], 0.0]; else - parentPt = Vector.create([xScreen, yScreen, 0.0]); + parentPt = [xScreen, yScreen, 0.0]; var vec = viewUtils.parentToChildVec(parentPt, stage); if (vec) { @@ -274,6 +275,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { } //if (hitRecArray.length == 0) var rtnHit; + + // Save reference to hit records to verify last hit record's element matches browser's elementFromPoint + this._hitRecords.length = 0; + this._hitRecords = hitRecArray; + if (hitRecArray.length > 0) { this.sortHitRecords( hitRecArray ); @@ -315,7 +321,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { // get the point to the lower left of the plane point and // see if it falls within the snap distance - var origin = Vector.create( [-0.5*this.getStageWidth(), -0.5*this.getStageHeight()] ); + var origin = [-0.5*this.getStageWidth(), -0.5*this.getStageHeight()]; var planePt = hitRec.getLocalPoint(); var dToOrigin = MathUtils.vecSubtract(planePt, origin); var nx = Math.floor( dToOrigin[0]/dx), @@ -332,11 +338,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { return false; } - var pt00 = Vector.create( [ - origin[0] + nx*dx, - origin[1] + ny*dy, - 0.0 - ] ); + var pt00 = [ origin[0] + nx*dx, origin[1] + ny*dy, 0.0 ]; var planeMat = hitRec.getPlaneMatrix(); var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt00,planeMat), stage ); scrPt2 = MathUtils.makeDimension3( scrPt2 ); @@ -360,11 +362,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { return true; // check the far corner point and 2 edges out from it - var pt11 = Vector.create( [ - origin[0] + (nx+1)*dx, - origin[1] + (ny+1)*dy, - 0.0 - ] ); + var pt11 = [ origin[0] + (nx+1)*dx, origin[1] + (ny+1)*dy, 0.0 ]; var scrPt4 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(pt11,planeMat), stage ); scrPt4 = MathUtils.makeDimension3( scrPt4 ); scrPt4 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt4, stageMat) ), offset ); @@ -414,11 +412,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { horizontalLineCount = 2; } - var edgePt = Vector.create( [ - gridOrigin[0] + nx*dx, - gridOrigin[1] + ny*dy, - 0.0 - ] ); + var edgePt = [ gridOrigin[0] + nx*dx, gridOrigin[1] + ny*dy, 0.0 ]; var scrPt2 = viewUtils.postViewToStageWorld( MathUtils.transformPoint(edgePt,planeMat), stage ); scrPt2 = MathUtils.makeDimension3( scrPt2 ); scrPt2 = vecUtils.vecAdd(3, viewUtils.viewToScreen( MathUtils.transformPoint(scrPt2, stageMat) ), offset ); @@ -843,7 +837,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { MathUtils.makeDimension3( stageOffset ); var x = vPt[0], y = hPt[1]; - var localPt = Vector.create( [x,y,0,1] ); + var localPt = [x,y,0,1]; var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); @@ -1185,7 +1179,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { // Calculate the local point var planeMat; var mat = viewUtils.getMatrixFromElement( elt ); - var wp = Vector.create([0,0,1,0]); + var wp = [0,0,1,0]; wp = MathUtils.transformPlane( wp, mat ); var wpMat = drawUtils.getPlaneToWorldMatrix(wp, MathUtils.getPointOnPlane(wp)); //var wpMatInv = wpMat.inverse(); @@ -1277,7 +1271,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { { // convert to GL coordinates var glPt = this.globalScreenToWebGL( targetScrPt, elt ); - var eyePt = Vector.create( [0, 0, world.getViewDistance()] ); + var eyePt = [0, 0, world.getViewDistance()]; var dir = vecUtils.vecSubtract(3, glPt, eyePt); // recursively go through the tree testing all objects @@ -1528,7 +1522,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { viewUtils.pushViewportObj( elt ); var cop = viewUtils.getCenterOfProjection(); viewUtils.popViewportObj(); - var s2v = Matrix.Translation(Vector.create([-cop[0], -cop[1], 0])); + var s2v = Matrix.Translation([-cop[0], -cop[1], 0]); var vToNDC = Matrix.I(4); vToNDC[0] = 1.0/(0.5*world.getViewportWidth()); vToNDC[5] = 1.0/(0.5*world.getViewportHeight()); @@ -1566,11 +1560,11 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { tmpPt2 = MathUtils.applyHomogeneousCoordinate( tmpPt2 ); // project the 2 object space points onto the original plane of the object - var tmpPt3 = MathUtils.vecIntersectPlane( tmpPt1, vecUtils.vecSubtract(3, tmpPt2, tmpPt1), Vector.create([0,0,1,0]) ); + var tmpPt3 = MathUtils.vecIntersectPlane( tmpPt1, vecUtils.vecSubtract(3, tmpPt2, tmpPt1), [0,0,1,0]); //console.log( "object space pt: " + tmpPt3 ); // get the z value in NDC space of the projection plane - var ndcPt = MathUtils.transformHomogeneousPoint( Vector.create( [0, 0, 0] ), glToNDC ); + var ndcPt = MathUtils.transformHomogeneousPoint( [0, 0, 0], glToNDC ); ndcPt = MathUtils.applyHomogeneousCoordinate( ndcPt ); var zNDC = ndcPt[2]; @@ -1642,7 +1636,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var drawingGrid = drawUtils.isDrawingGrid(); // get the Z axis of the matrix - var dir = Vector.create([mat[8], mat[9], mat[10]]); + var dir = [mat[8], mat[9], mat[10]]; dir = vecUtils.vecNormalize(3, dir, 1.0); var x = Math.abs(dir[0]), y = Math.abs(dir[1]), @@ -1653,7 +1647,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { //x = 0; y = 0; z = 1; // X/Y plane var id; - var plane = Vector.create([0, 0, 0, 0]); + var plane = [0, 0, 0, 0]; var change = false; if (x > y) { if (x > z) { @@ -1823,7 +1817,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { MathUtils.makeDimension3( stageOffset ); var x = vPt[0], y = hPt[1]; - var localPt = Vector.create( [x,y,0,1] ); + var localPt = [x,y,0,1]; var planeToViewMat = this.getPlaneToViewMat(); var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); @@ -1872,7 +1866,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { MathUtils.makeDimension3( stageOffset ); var y = hPt[1], x = vPt[0]; - var localPt = Vector.create( [x,y,0,1] ); + var localPt = [x,y,0,1]; var planeToViewMat = this.getPlaneToViewMat(); var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); @@ -1927,7 +1921,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { MathUtils.makeDimension3( stageOffset ); var y = hPt[1], x = vPt[0]; - var localPt = Vector.create( [x,y,0,1] ); + var localPt = [x,y,0,1]; var planeToViewMat = this.getPlaneToViewMat(); var viewPt = MathUtils.transformPoint( localPt, planeToViewMat ); var scrPt = vecUtils.vecAdd(3, viewUtils.viewToScreen( viewPt ), stageOffset ); @@ -2246,6 +2240,30 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { drawUtils.setDrawingSurfaceElement(saveContext); } } - } + }, + + findHitRecordForElement: { + value: function(elt) { + var rtnHit; + + if (!this._hitRecords) return; + var nHits = this._hitRecords.length; + + for (var i=0; i