aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xassets/shaders/linearGradient.vert.glsl5
-rw-r--r--assets/shaders/radialGradient.vert.glsl4
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js139
-rwxr-xr-xjs/helper-classes/3D/view-utils.js5
-rwxr-xr-xjs/lib/geom/circle.js3
-rwxr-xr-xjs/lib/geom/rectangle.js13
-rw-r--r--js/lib/geom/shape-primitive.js27
-rwxr-xr-xjs/lib/rdge/materials/linear-gradient-material.js14
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js43
10 files changed, 172 insertions, 85 deletions
diff --git a/assets/shaders/linearGradient.vert.glsl b/assets/shaders/linearGradient.vert.glsl
index aac9cbee..f0800812 100755
--- a/assets/shaders/linearGradient.vert.glsl
+++ b/assets/shaders/linearGradient.vert.glsl
@@ -37,6 +37,7 @@ uniform float u_colorStop3;
37uniform float u_colorStop4; 37uniform float u_colorStop4;
38uniform vec2 u_cos_sin_angle; 38uniform vec2 u_cos_sin_angle;
39//uniform int u_colorCount; // currently using 4 39//uniform int u_colorCount; // currently using 4
40uniform mat3 u_texTransform;
40 41
41varying vec2 v_uv; 42varying vec2 v_uv;
42 43
@@ -44,5 +45,7 @@ varying vec2 v_uv;
44void main(void) 45void main(void)
45{ 46{
46 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; 47 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ;
47 v_uv = texcoord; 48 //v_uv = texcoord;
49 vec3 tmp = u_texTransform * vec3( texcoord, 1.0);
50 v_uv = tmp.xy;
48} 51}
diff --git a/assets/shaders/radialGradient.vert.glsl b/assets/shaders/radialGradient.vert.glsl
index c3e1b50a..7994ac12 100644
--- a/assets/shaders/radialGradient.vert.glsl
+++ b/assets/shaders/radialGradient.vert.glsl
@@ -18,11 +18,13 @@ attribute vec2 texcoord;
18// matrix uniforms 18// matrix uniforms
19uniform mat4 u_mvMatrix; 19uniform mat4 u_mvMatrix;
20uniform mat4 u_projMatrix; 20uniform mat4 u_projMatrix;
21uniform mat3 u_texTransform;
21 22
22varying vec2 v_uv; 23varying vec2 v_uv;
23 24
24void main(void) 25void main(void)
25{ 26{
26 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ; 27 gl_Position = u_projMatrix * u_mvMatrix * vec4(vert,1.0) ;
27 v_uv = texcoord; 28 vec3 tmp = u_texTransform * vec3( texcoord, 1.0);
29 v_uv = tmp.xy;
28} \ No newline at end of file 30} \ No newline at end of file
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index 6766ac7f..27a95941 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -230,64 +230,19 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
230 else 230 else
231 parentPt = [xScreen, yScreen, 0.0]; 231 parentPt = [xScreen, yScreen, 0.0];
232 232
233 var eyePt = []; 233 var hitRec = this.snapToStage( parentPt, quadPt );
234 var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); 234
235 if (vec) 235 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
236 { 236 if (this.gridSnapEnabled())
237 // activate the drag working plane 237 this.snapToGrid( hitRec );
238 if (!snap3D && this.hasDragPlane()) 238
239 this.activateDragPlane(); 239 // save the hit record
240 240 hitRecArray.push( hitRec );
241 // project to the working plane 241
242 var currentWorkingPlane = workingPlane.slice(0); 242 // restore the original working plane
243 var wp = currentWorkingPlane.slice(0); 243 if (!snap3D && this.hasDragPlane())
244 var mat = viewUtils.getMatrixFromElement(stage); 244 this.deactivateDragPlane();
245 wp = MathUtils.transformPlane(wp, mat); 245
246 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp);
247 if (projPt)
248 {
249 // the local point gets stored in the coordinate space of the plane
250 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane));
251 projPt[3] = 1.0;
252 //var planeToViewMat = mat.multiply(wpMat);
253 var planeToViewMat = glmat4.multiply(mat, wpMat, []);
254 //var viewToPlaneMat = planeToViewMat.inverse();
255 var viewToPlaneMat = glmat4.inverse( planeToViewMat, [] );
256 var planePt = projPt.slice(0);
257 planePt[3] = 1.0;
258 //planePt = viewToPlaneMat.multiply(planePt);
259 planePt = glmat4.multiplyVec3( viewToPlaneMat, planePt );
260
261 // get the screen position of the projected point
262 viewUtils.setViewportObj(stage);
263 var offset = viewUtils.getElementOffset(stage);
264 offset[2] = 0;
265 var scrPt = viewUtils.viewToScreen(projPt);
266 //scrPt = scrPt.add(offset);
267 scrPt = vecUtils.vecAdd(3, scrPt, offset);
268
269 // create the hit record
270 var hitRec = Object.create(HitRecord);//new HitRecord();
271 hitRec.setLocalPoint(planePt);
272 hitRec.setPlaneMatrix( wpMat );
273 hitRec.setScreenPoint(scrPt);
274 hitRec.setPlane(currentWorkingPlane);
275 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
276 hitRec.setElt( stage );
277 if (quadPt) hitRec.setUseQuadPoint( true );
278
279 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
280 if (this.gridSnapEnabled())
281 this.snapToGrid( hitRec );
282
283 // save the hit record
284 hitRecArray.push( hitRec );
285
286 // restore the original working plane
287 if (!snap3D && this.hasDragPlane())
288 this.deactivateDragPlane();
289 }
290 }
291 } //if (hitRecArray.length == 0) 246 } //if (hitRecArray.length == 0)
292 247
293 var rtnHit; 248 var rtnHit;
@@ -312,6 +267,62 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
312 } 267 }
313 }, 268 },
314 269
270 snapToStage:
271 {
272 value: function( scrPt, quadPt )
273 {
274 var stage = this.getStage();
275 var l2g = viewUtils.getLocalToGlobalMatrix( stage );
276 var g2l = glmat4.inverse( l2g, [] );
277
278 var pt0 = scrPt.slice(), pt1 = scrPt.slice();
279 pt0[2] = 0.0; pt1[2] = 10;
280
281 var localPt0 = MathUtils.transformAndDivideHomogeneousPoint( pt0, g2l ),
282 localPt1 = MathUtils.transformAndDivideHomogeneousPoint( pt1, g2l );
283
284 var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ),
285 stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage );
286 var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 );
287
288 var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane);
289
290 var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)),
291 wpMatInv = glmat4.inverse( wpMat, [] );
292 var localPt = MathUtils.transformPoint( ptOnWorkingPlane, wpMatInv );
293
294 // create the hit record
295 var hitRec = Object.create(HitRecord);
296 hitRec.setLocalPoint( localPt );
297 hitRec.setPlaneMatrix( wpMat );
298 hitRec.setScreenPoint(scrPt);
299 hitRec.setPlane(workingPlane);
300 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
301 hitRec.setElt( stage );
302 if (quadPt) hitRec.setUseQuadPoint( true );
303
304 // DEBUG CODE
305 // check that the point is on the working plane
306 var tmpStageWorldPt = hitRec.calculateStageWorldPoint();
307 var err = vecUtils.vecDot(3, tmpStageWorldPt, workingPlane) + workingPlane[3];
308 if (MathUtils.fpSign(err) !== 0)
309 console.log( "snapToStage (function) not on working plane: " + err );
310 //////////////////////////////////////////////////////////////////////
311
312 var calculatedScreenPt = hitRec.calculateScreenPoint();
313 hitRec.setScreenPoint(calculatedScreenPt);
314
315 // DEBUG CODE
316 // check that the point is on the working plane
317 var err2 = vecUtils.vecDist(2, calculatedScreenPt, scrPt );
318 if (MathUtils.fpSign(err2) !== 0)
319 console.log( "snapToStage (function) error in screen point: " + err2 );
320 //////////////////////////////////////////////////////////////////////
321
322 return hitRec;
323 }
324 },
325
315 snapToGrid : { 326 snapToGrid : {
316 value: function( hitRec ) 327 value: function( hitRec )
317 { 328 {
@@ -481,7 +492,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
481 492
482 this._elementCache = null; 493 this._elementCache = null;
483 } 494 }
484 //console.log( "clear 2D cache" ); 495 console.log( "clear 2D cache" );
485 } 496 }
486 }, 497 },
487 498
@@ -494,7 +505,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
494 this.hLoadElementCache( stage, plane, 0 ); 505 this.hLoadElementCache( stage, plane, 0 );
495 this._isCacheInvalid = false; 506 this._isCacheInvalid = false;
496 507
497 //console.log( "2D cache loade