From 6321075d93044c6747682a8e7280b5996da7ec52 Mon Sep 17 00:00:00 2001
From: hwc487
Date: Thu, 2 Feb 2012 11:57:58 -0800
Subject: added some additional shaders
---
js/helper-classes/RDGE/Materials/DeformMaterial.js | 133 +++++++++++++++++++++
js/helper-classes/RDGE/Materials/FlyMaterial.js | 133 +++++++++++++++++++++
.../RDGE/Materials/ReliefTunnelMaterial.js | 133 +++++++++++++++++++++
.../RDGE/Materials/SquareTunnelMaterial.js | 133 +++++++++++++++++++++
js/helper-classes/RDGE/Materials/StarMaterial.js | 133 +++++++++++++++++++++
js/helper-classes/RDGE/Materials/WaterMaterial.js | 133 +++++++++++++++++++++
.../RDGE/Materials/ZInvertMaterial.js | 133 +++++++++++++++++++++
js/helper-classes/RDGE/MaterialsLibrary.js | 21 ++++
8 files changed, 952 insertions(+)
create mode 100644 js/helper-classes/RDGE/Materials/DeformMaterial.js
create mode 100644 js/helper-classes/RDGE/Materials/FlyMaterial.js
create mode 100644 js/helper-classes/RDGE/Materials/ReliefTunnelMaterial.js
create mode 100644 js/helper-classes/RDGE/Materials/SquareTunnelMaterial.js
create mode 100644 js/helper-classes/RDGE/Materials/StarMaterial.js
create mode 100644 js/helper-classes/RDGE/Materials/WaterMaterial.js
create mode 100644 js/helper-classes/RDGE/Materials/ZInvertMaterial.js
(limited to 'js/helper-classes')
diff --git a/js/helper-classes/RDGE/Materials/DeformMaterial.js b/js/helper-classes/RDGE/Materials/DeformMaterial.js
new file mode 100644
index 00000000..ddc97383
--- /dev/null
+++ b/js/helper-classes/RDGE/Materials/DeformMaterial.js
@@ -0,0 +1,133 @@
+/*
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function DeformMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "DeformMaterial";
+ this._shaderName = "deform";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new DeformMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function FlyMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "FlyMaterial";
+ this._shaderName = "tunnel";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new FlyMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function ReliefTunnelMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "ReliefTunnelMaterial";
+ this._shaderName = "tunnel";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new ReliefTunnelMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function SquareTunnelMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "SquareTunnelMaterial";
+ this._shaderName = "tunnel";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new SquareTunnelMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function StarMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "StarMaterial";
+ this._shaderName = "star";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new StarMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function WaterMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "WaterMaterial";
+ this._shaderName = "water";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new WaterMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i
+ 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 GLMaterial
+// RDGE representation of a material.
+///////////////////////////////////////////////////////////////////////
+function ZInvertMaterial()
+{
+ // initialize the inherited members
+ this.inheritedFrom = PulseMaterial;
+ this.inheritedFrom();
+
+ ///////////////////////////////////////////////////////////////////////
+ // Instance variables
+ ///////////////////////////////////////////////////////////////////////
+ this._name = "ZInvertMaterial";
+ this._shaderName = "zinvert";
+
+ this._texMap = 'assets/images/rocky-normal.jpg';
+
+ this._time = 0.0;
+ this._dTime = 0.01;
+
+ ///////////////////////////////////////////////////////////////////////
+ // Properties
+ ///////////////////////////////////////////////////////////////////////
+ // all defined in parent PulseMaterial.js
+ // load the local default value
+ this._propValues[ this._propNames[0] ] = this._texMap.slice(0);
+
+ ///////////////////////////////////////////////////////////////////////
+ // Material Property Accessors
+ ///////////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////////
+
+
+ ///////////////////////////////////////////////////////////////////////
+ // Methods
+ ///////////////////////////////////////////////////////////////////////
+ // duplcate method requirde
+ this.dup = function( world )
+ {
+ // allocate a new uber material
+ var newMat = new ZInvertMaterial();
+
+ // copy over the current values;
+ var propNames = [], propValues = [], propTypes = [], propLabels = [];
+ this.getAllProperties( propNames, propValues, propTypes, propLabels);
+ var n = propNames.length;
+ for (var i=0; i 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;
+}
+
+
+
diff --git a/js/helper-classes/RDGE/GLWorld.js b/js/helper-classes/RDGE/GLWorld.js
index 819f89db..c97e29d4 100644
--- a/js/helper-classes/RDGE/GLWorld.js
+++ b/js/helper-classes/RDGE/GLWorld.js
@@ -225,19 +225,15 @@ function GLWorld( canvas, use3D )
{
if (this._useWebGL)
{
- if (this._allMapsLoaded)
+ var ctx = g_Engine.getContext();
+ var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle);
+ if (ctx1 != ctx) console.log( "***** different contexts (2) *****" );
+ var aRenderer = ctx1.renderer;
+ var renderer = ctx.renderer;
+ if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" );
+
+ if (renderer.unloadedTextureCount <= 0)
{
- var ctx = g_Engine.getContext();
- //console.log( "RDGE state: " + ctx.ctxStateManager.currentState().name);
-
- /////////////////////////////
- var ctx1 = g_Engine.ctxMan.handleToObject(this._canvas.rdgeCtxHandle);
- if (ctx1 != ctx) console.log( "***** different contexts (2) *****" );
- var aRenderer = ctx1.renderer;
- //////////////////////////////////////////
-
- var renderer = ctx.renderer;
- if (renderer != aRenderer) console.log( "***** DIFFERENT RENDERERS *****" );
renderer.disableCulling();
this.myScene.render();
//console.log( "render" );
@@ -249,8 +245,8 @@ function GLWorld( canvas, use3D )
if (!this.hasAnimatedMaterials())
{
//this.myScene.render();
- //this._canvas.task.stop();
- this._renderCount = 10;
+ this._canvas.task.stop();
+ //this._renderCount = 10;
}
}
else if (this._renderCount >= 0)
@@ -259,7 +255,6 @@ function GLWorld( canvas, use3D )
if (this._renderCount <= 0)
this._canvas.task.stop();
}
-
}
}
else
diff --git a/js/helper-classes/RDGE/Materials/FlatMaterial.js b/js/helper-classes/RDGE/Materials/FlatMaterial.js
index 3e3ae25e..c8eb3b6c 100644
--- a/js/helper-classes/RDGE/Materials/FlatMaterial.js
+++ b/js/helper-classes/RDGE/Materials/FlatMaterial.js
@@ -121,6 +121,7 @@ function FlatMaterial()
flatShaderDef =
{
'shaders': { // shader files
+ //'defaultVShader':"assets/shaders/Taper.vert.glsl",
'defaultVShader':"assets/shaders/Basic.vert.glsl",
'defaultFShader':"assets/shaders/Basic.frag.glsl",
},
diff --git a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js
index ce965296..8b23d77e 100644
--- a/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js
+++ b/js/helper-classes/RDGE/Materials/LinearGradientMaterial.js
@@ -135,8 +135,10 @@ function LinearGradientMaterial()
// duplcate method requirde
this.dup = function() { return new LinearGradientMaterial(); }
- this.init = function()
+ this.init = function( world )
{
+ this.setWorld( world );
+
// set up the shader
this._shader = new jshader();
this._shader.def = linearGradientMaterialDef;
diff --git a/js/helper-classes/RDGE/src/core/script/renderer.js b/js/helper-classes/RDGE/src/core/script/renderer.js
index 517947df..04cb36a7 100644
--- a/js/helper-classes/RDGE/src/core/script/renderer.js
+++ b/js/helper-classes/RDGE/src/core/script/renderer.js
@@ -359,9 +359,11 @@ _renderer = function(canvas) {
* @param wrap - optional "CLAMP or "REPEAT", default is clamp
* @param mips - optional true/false value to create mipmaps, the default is true
*/
+ this.unloadedTextureCount = 0;
_texparams = function(wrap, mips) { this.wrap = wrap, this.mips = mips };
this.createTexture = function(url, wrap, mips) {
var texture = this.ctx.createTexture();
+ this.unloadedTextureCount++;
if (wrap === undefined)
wrap = "CLAMP";
@@ -379,7 +381,18 @@ _renderer = function(canvas) {
stateMan.RDGEInitState.loadTexture(texture);
//console.log( "loaded texture: " + texture.lookUpName );
if (texture.callback) texture.callback( texture );
+ this.context.renderer.unloadedTextureCount--;
+ if (this.context.renderer.unloadedTextureCount < 0)
+ console.log( "more textures loaded then created..." );
};
+ texture.image.onerror = function() {
+ this.context.renderer.unloadedTextureCount--;
+ if (texture.callback) texture.callback( texture );
+ console.log( "Error loading texture: " + texture.image.src );
+ if (this.context.renderer.unloadedTextureCount < 0)
+ console.log( "more textures loaded then created..." );
+ }
+
}
return texture;
}
--
cgit v1.2.3
From 465636cc0676d7fb83939d6fdb9204e474d47d46 Mon Sep 17 00:00:00 2001
From: hwc487
Date: Mon, 6 Feb 2012 13:08:26 -0800
Subject: Removed an unnecessary (and incorrect) snapping calculation.
---
js/helper-classes/3D/snap-manager.js | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
(limited to 'js/helper-classes')
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 8819f637..7e1260bf 100644
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -977,7 +977,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
viewUtils.setViewportObj( stage );
MathUtils.makeDimension3( screenPt );
- this.hSnapToElements( stage, screenPt, hitRecs, 0, screenPt );
+ this.hSnapToElements( stage, hitRecs, 0, screenPt );
return;
}
@@ -985,7 +985,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
hSnapToElements :
{
- value: function( elt, parentPt, hitRecs, depth, globalScrPt )
+ value: function( elt, hitRecs, depth, globalScrPt )
{
// hit test the current object
var hit;
@@ -994,8 +994,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
// if the element is in the 2D cache snapping is done there
if (elt.elementModel && !elt.elementModel.isIn2DSnapCache)
{
- var scrPt = viewUtils.parentToChild( parentPt, elt, false );
- hit = this.snapToElement( elt, scrPt, globalScrPt );
+ hit = this.snapToElement( elt, globalScrPt );
if (hit)
{
//hitRecs.push( hit );
@@ -1017,14 +1016,14 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
}
// test the rest of the tree
var n = elt.childElementCount;
- var eltPt = viewUtils.parentToChild( parentPt, elt, true );
+ //var eltPt = viewUtils.parentToChild( parentPt, elt, true );
if (n > 0)
{
for (var i=0; i 0) { xMin = pt[0]; xMax = pt[0] + width; }
+ else { xMax = pt[0]; xMin = pt[0] + width; }
+ if (height > 0) { yMin = pt[1]; yMax = pt[1] + height; }
+ else { yMax = pt[1]; yMin = pt[1] + height; }
+
+ // get the bounds of the element in global screen space
+ var bounds = ViewUtils.getElementViewBounds3D( elt );
+ var bounds3D = [];
+ for (var i=0; i<4; i++)
+ bounds3D[i] = ViewUtils.localToGlobal( bounds[i], elt );
+
+ // get the min/maxs for the element
+ var xMinElt = bounds3D[0][0], xMaxElt = bounds3D[0][0],
+ yMinElt = bounds3D[0][1], yMaxElt = bounds3D[0][1];
+ for (var i=1; i<4; i++)
+ {
+ if (bounds3D[i][0] < xMinElt) xMinElt = bounds3D[i][0];
+ else if (bounds3D[i][0] > xMaxElt) xMaxElt = bounds3D[i][0];
+ if (bounds3D[i][1] < yMinElt) yMinElt = bounds3D[i][1];
+ else if (bounds3D[i][1] > yMaxElt) yMaxElt = bounds3D[i][1];
+ }
+
+ // test 1. Overall bounding box test
+ if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax))
+ return false;
+
+ // test 2. See if any of the corners of the element are contained in the rectangle
+ var rect = Object.create(Rectangle, {});
+ rect.set( pt[0], pt[1], width, height );
+ for (var i=0; i<4; i++)
+ {
+ if (rect.contains( bounds3D[i][0], bounds3D[i][1] )) return true;
+ }
+
+ // test 3. Bounding box tests on individual edges of the element
+ for (var i=0; i<4; i++)
+ {
+ var pt0 = bounds3D[i],
+ pt1 = bounds3D[(i+1)%4];
+
+ // get the extremes of the edge
+ if (pt0[0] < pt1[0]) { xMinElt = pt0[0]; xMaxElt = pt1[0]; }
+ else { xMaxElt = pt0[0]; xMinElt = pt1[0]; }
+ if (pt0[1] < pt1[1]) { yMinElt = pt0[1]; yMaxElt = pt1[1]; }
+ else { yMaxElt = pt0[1]; yMinElt = pt1[1]; }
+
+ if ((xMaxElt < xMin) || (xMinElt > xMax) || (yMaxElt < yMin) || (yMinElt > yMax))
+ continue;
+ else
+ {
+ // intersect the element edge with the 4 sides of the rectangle
+ // vertical edges
+ var xRect = xMin;
+ for (var j=0; j<2; j++)
+ {
+ if ((xMinElt < xRect) && (xMaxElt > xRect))
+ {
+ var t = (xRect - pt0[0])/(pt1[0] - pt0[0]);
+ var y = pt0[1] + t*(pt1[1] - pt0[1]);
+ if ((y >= yMin) && (y <= yMax)) return true;
+ }
+ xRect = xMax;
+ }
+
+ // horizontal edges
+ var yRect = yMin;
+ for (var j=0; j<2; j++)
+ {
+ if ((yMinElt < yRect) && (yMaxElt > yRect))
+ {
+ var t = (yRect - pt0[1])/(pt1[1] - pt0[1]);
+ var x = pt0[0] + t*(pt1[0] - pt0[0]);
+ if ((x >= xMin) && (x <= xMax)) return true;
+ }
+ yRect = yMax;
+ }
+ }
+ }
+
+ // if we get here there is no overlap
+ return false;
+ }
+ },
+
///////////////////////////////////////////////////////////////////////
// Bezier Methods
///////////////////////////////////////////////////////////////////////
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 7e1260bf..f3e8b823 100644
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -971,7 +971,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
value: function( screenPt, hitRecs ) {
// start at the stage.
var stage = this.getStage();
- //var stagePt = viewUtils.parentToChild( screenPt, stage );
// the root should be the 'view' canvas, so the first matrix is the camera
viewUtils.setViewportObj( stage );
@@ -997,7 +996,6 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
hit = this.snapToElement( elt, globalScrPt );
if (hit)
{
- //hitRecs.push( hit );
if (!hit.checkType())
{
console.log( "invalid hit record: " + hit.getTypeString() );
@@ -1016,17 +1014,14 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
}
// test the rest of the tree
var n = elt.childElementCount;
- //var eltPt = viewUtils.parentToChild( parentPt, elt, true );
if (n > 0)
{
for (var i=0; i