aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-rwxr-xr-xjs/document/html-document.js4
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js146
-rwxr-xr-xjs/helper-classes/3D/view-utils.js13
-rw-r--r--js/io/system/ninjalibrary.json2
-rwxr-xr-xjs/lib/geom/circle.js124
-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.js46
-rwxr-xr-xjs/lib/rdge/materials/material.js4
-rwxr-xr-xjs/lib/rdge/materials/radial-gradient-material.js64
10 files changed, 341 insertions, 279 deletions
diff --git a/js/document/html-document.js b/js/document/html-document.js
index 9d083dd8..61223499 100755
--- a/js/document/html-document.js
+++ b/js/document/html-document.js
@@ -209,8 +209,8 @@ exports.HTMLDocument = Montage.create(TextDocument, {
209 { 209 {
210 /* 210 /*
211 // Use this code to test the runtime version of WebGL 211 // Use this code to test the runtime version of WebGL
212 var cdm = new NinjaCvsRt.CanvasDataManager(); 212 var cvsDataMngr = Object.create(NinjaCvsRt.CanvasDataManager, {});
213 cdm.loadGLData(elt, value, null ); 213 cvsDataMngr.loadGLData(elt, value);
214 */ 214 */
215 215
216 // /* 216 // /*
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 if (vSnap.hasAssociatedScreenPoint2() ) 1820 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1848,8 +1862,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1848 hSnap.setScreenPoint( scrPt ); 1862 hSnap.setScreenPoint( scrPt );
1849 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1863 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1850 hSnap.setElement( stage ); 1864 hSnap.setElement( stage );
1851 hSnap.setPlane( [0,0,1,0] ); 1865 //hSnap.setPlane( [0,0,1,0] );
1852 hSnap.setPlaneMatrix( Matrix.I(4) ); 1866 //hSnap.setPlaneMatrix( Matrix.I(4) );
1853 if (vSnap.hasAssociatedScreenPoint() ) 1867 if (vSnap.hasAssociatedScreenPoint() )
1854 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1868 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1855 if (vSnap.hasAssociatedScreenPoint2() ) 1869 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1903,8 +1917,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1903 hSnap.setScreenPoint( scrPt ); 1917 hSnap.setScreenPoint( scrPt );
1904 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1918 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1905 hSnap.setElement( stage ); 1919 hSnap.setElement( stage );
1906 hSnap.setPlane( [0,0,1,0] ); 1920 //hSnap.setPlane( [0,0,1,0] );
1907 hSnap.setPlaneMatrix( Matrix.I(4) ); 1921 //hSnap.setPlaneMatrix( Matrix.I(4) );
1908 if (vSnap.hasAssociatedScreenPoint() ) 1922 if (vSnap.hasAssociatedScreenPoint() )