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.js146
-rwxr-xr-xjs/helper-classes/3D/view-utils.js13
-rwxr-xr-xjs/lib/geom/circle.js122
-rwxr-xr-xjs/lib/geom/rectangle.js190
-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.js70
10 files changed, 332 insertions, 263 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..97901d50 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -230,64 +230,22 @@ 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 if (!snap3D && this._hasDragPlane)
234 var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); 234 this.activateDragPlane();
235 if (vec) 235
236 { 236 var hitRec = this.snapToStage( parentPt, quadPt );
237 // activate the drag working plane 237
238 if (!snap3D && this.hasDragPlane()) 238 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
239 this.activateDragPlane(); 239 if (this.gridSnapEnabled())
240 240 this.snapToGrid( hitRec );
241 // project to the working plane 241
242 var currentWorkingPlane = workingPlane.slice(0); 242 // save the hit record
243 var wp = currentWorkingPlane.slice(0); 243 hitRecArray.push( hitRec );
244 var mat = viewUtils.getMatrixFromElement(stage); 244
245 wp = MathUtils.transformPlane(wp, mat); 245 // restore the original working plane
246 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 246 if (!snap3D && this.hasDragPlane())
247 if (projPt) 247 this.deactivateDragPlane();
248 { 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) 249 } //if (hitRecArray.length == 0)
292 250
293 var rtnHit; 251 var rtnHit;
@@ -312,6 +270,62 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
312 } 270 }
313 }, 271 },
314 272
273 snapToStage:
274 {
275 value: function( scrPt, quadPt )
276 {
277 var stage = this.getStage();
278 var l2g = viewUtils.getLocalToGlobalMatrix( stage );
279 var g2l = glmat4.inverse( l2g, [] );
280
281 var pt0 = scrPt.slice(), pt1 = scrPt.slice();
282 pt0[2] = 0.0; pt1[2] = 10;
283
284 var localPt0 = MathUtils.transformAndDivideHomogeneousPoint( pt0, g2l ),
285 localPt1 = MathUtils.transformAndDivideHomogeneousPoint( pt1, g2l );
286
287 var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ),
288 stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage );
289 var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 );
290
291 var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane);
292
293 var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)),
294 wpMatInv = glmat4.inverse( wpMat, [] );
295 var localPt = MathUtils.transformPoint( ptOnWorkingPlane, wpMatInv );
296
297 // create the hit record
298 var hitRec = Object.create(HitRecord);
299 hitRec.setLocalPoint( localPt );
300 hitRec.setPlaneMatrix( wpMat );
301 hitRec.setScreenPoint(scrPt);
302 hitRec.setPlane(workingPlane);
303 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
304 hitRec.setElt( stage );
305 if (quadPt) hitRec.setUseQuadPoint( true );
306
307 // DEBUG CODE
308 // check that the point is on the working plane
309 var tmpStageWorldPt = hitRec.calculateStageWorldPoint();
310 var err = vecUtils.vecDot(3, tmpStageWorldPt, workingPlane) + workingPlane[3];
311 if (MathUtils.fpSign(err) !== 0)
312 console.log( "snapToStage (function) not on working plane: " + err );
313 //////////////////////////////////////////////////////////////////////
314
315 var calculatedScreenPt = hitRec.calculateScreenPoint();
316 hitRec.setScreenPoint(calculatedScreenPt);
317
318 // DEBUG CODE
319 // check that the point is on the working plane
320 var err2 = vecUtils.vecDist(2, calculatedScreenPt, scrPt );
321 if (MathUtils.fpSign(err2) !== 0)
322 console.log( "snapToStage (function) error in screen point: " + err2 );
323 //////////////////////////////////////////////////////////////////////
324
325 return hitRec;
326 }
327 },
328
315 snapToGrid : { 329 snapToGrid : {
316 value: function( hitRec ) 330 value: function( hitRec )
317 { 331 {
@@ -1799,8 +1813,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1799 hSnap.setScreenPoint( scrPt ); 1813 hSnap.setScreenPoint( scrPt );
1800 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1814 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1801 hSnap.setElement( stage ); 1815 hSnap.setElement( stage );
1802 hSnap.setPlane( [0,0,1,0] ); 1816 //hSnap.setPlane( [0,0,1,0] );
1803 hSnap.setPlaneMatrix( Matrix.I(4) ); 1817 //hSnap.setPlaneMatrix( Matrix.I(4) );
1804 if (vSnap.hasAssociatedScreenPoint() ) 1818 if (vSnap.hasAssociatedScreenPoint() )
1805 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1819 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1806