diff options
Diffstat (limited to 'js/lib')
-rwxr-xr-x | js/lib/NJUtils.js | 14 | ||||
-rwxr-xr-x | js/lib/drawing/world.js | 11 | ||||
-rwxr-xr-x | js/lib/geom/brush-stroke.js | 50 | ||||
-rwxr-xr-x | js/lib/geom/circle.js | 61 | ||||
-rwxr-xr-x | js/lib/geom/geom-obj.js | 59 | ||||
-rwxr-xr-x | js/lib/geom/rectangle.js | 40 |
6 files changed, 194 insertions, 41 deletions
diff --git a/js/lib/NJUtils.js b/js/lib/NJUtils.js index 67bb59c4..dae128e4 100755 --- a/js/lib/NJUtils.js +++ b/js/lib/NJUtils.js | |||
@@ -94,10 +94,10 @@ exports.NJUtils = Object.create(Object.prototype, { | |||
94 | ///// TODO: find a different place for this function | 94 | ///// TODO: find a different place for this function |
95 | makeElementModel: { | 95 | makeElementModel: { |
96 | value: function(el, selection, controller, isShape) { | 96 | value: function(el, selection, controller, isShape) { |
97 | //el.elementModel = Montage.create(ElementModel).initialize(el.nodeName, selection, controller, isShape); | ||
98 | |||
97 | var p3d = Montage.create(Properties3D); | 99 | var p3d = Montage.create(Properties3D); |
98 | if(selection === "Stage") { | 100 | |
99 | p3d.init(el, true); | ||
100 | } | ||
101 | var shapeProps = null; | 101 | var shapeProps = null; |
102 | var pi = controller + "Pi"; | 102 | var pi = controller + "Pi"; |
103 | 103 | ||
@@ -143,6 +143,7 @@ exports.NJUtils = Object.create(Object.prototype, { | |||
143 | isShape: { value: isShape} | 143 | isShape: { value: isShape} |
144 | }); | 144 | }); |
145 | 145 | ||
146 | |||
146 | } | 147 | } |
147 | }, | 148 | }, |
148 | 149 | ||
@@ -167,15 +168,12 @@ exports.NJUtils = Object.create(Object.prototype, { | |||
167 | break; | 168 | break; |
168 | case "canvas": | 169 | case "canvas": |
169 | isShape = el.getAttribute("data-RDGE-id"); | 170 | isShape = el.getAttribute("data-RDGE-id"); |
170 | if(isShape) | 171 | if(isShape) { |
171 | { | ||
172 | // TODO - Need more info about the shape | 172 | // TODO - Need more info about the shape |
173 | selection = "canvas"; | 173 | selection = "canvas"; |
174 | controller = "shape"; | 174 | controller = "shape"; |
175 | isShape = true; | 175 | isShape = true; |
176 | } | 176 | } else { |
177 | else | ||
178 | { | ||
179 | selection = "canvas"; | 177 | selection = "canvas"; |
180 | controller = "canvas"; | 178 | controller = "canvas"; |
181 | } | 179 | } |
diff --git a/js/lib/drawing/world.js b/js/lib/drawing/world.js index 1a391338..7ce23921 100755 --- a/js/lib/drawing/world.js +++ b/js/lib/drawing/world.js | |||
@@ -362,9 +362,9 @@ var World = function GLWorld( canvas, use3D, preserveDrawingBuffer ) { | |||
362 | 362 | ||
363 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state | 363 | // start RDGE passing your runtime object, and false to indicate we don't need a an initialization state |
364 | // in the case of a procedurally built scene an init state is not needed for loading data | 364 | // in the case of a procedurally built scene an init state is not needed for loading data |
365 | this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); | ||
365 | if (this._useWebGL) { | 366 | if (this._useWebGL) { |
366 | rdgeStarted = true; | 367 | rdgeStarted = true; |
367 | this._canvas.rdgeid = this._canvas.getAttribute( "data-RDGE-id" ); | ||
368 | RDGE.globals.engine.unregisterCanvas( this._canvas ); | 368 | RDGE.globals.engine.unregisterCanvas( this._canvas ); |
369 | RDGE.globals.engine.registerCanvas(this._canvas, this); | 369 | RDGE.globals.engine.registerCanvas(this._canvas, this); |
370 | RDGE.RDGEStart( this._canvas ); | 370 | RDGE.RDGEStart( this._canvas ); |
@@ -758,7 +758,7 @@ World.prototype.exportJSON = function () { | |||
758 | // would not be destructive of the data. You would be wrong... | 758 | // would not be destructive of the data. You would be wrong... |
759 | // We need to rebuild everything | 759 | // We need to rebuild everything |
760 | if (this._useWebGL) { | 760 | if (this._useWebGL) { |
761 | if (worldObj.children && (worldObj.children.length === 1)) { | 761 | if (worldObj.children && (worldObj.children.length >= 1)) { |
762 | this.rebuildTree(this._geomRoot); | 762 | this.rebuildTree(this._geomRoot); |
763 | this.restartRenderLoop(); | 763 | this.restartRenderLoop(); |
764 | } | 764 | } |
@@ -835,8 +835,11 @@ World.prototype.importJSON = function (jObj) { | |||
835 | 835 | ||
836 | // import the objects | 836 | // import the objects |
837 | // there should be exactly one child of the parent object | 837 | // there should be exactly one child of the parent object |
838 | if (jObj.children && (jObj.children.length === 1)) | 838 | if (jObj.children) |
839 | this.importObjectsJSON( jObj.children[0] ); | 839 | { |
840 | for (var i=0; i<jObj.children.length; i++) | ||
841 | this.importObjectsJSON( jObj.children[i] ); | ||
842 | } | ||
840 | else | 843 | else |
841 | throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); | 844 | throw new Error ("unrecoverable canvas import error - inconsistent root object: " + jObj.children ); |
842 | 845 | ||
diff --git a/js/lib/geom/brush-stroke.js b/js/lib/geom/brush-stroke.js index efd21c4a..1fae0c1d 100755 --- a/js/lib/geom/brush-stroke.js +++ b/js/lib/geom/brush-stroke.js | |||
@@ -117,7 +117,7 @@ var BrushStroke = function GLBrushStroke() { | |||
117 | }; | 117 | }; |
118 | 118 | ||
119 | this.getPoint = function (index) { | 119 | this.getPoint = function (index) { |
120 | return this._Points[index]; | 120 | return this._Points[index].slice(0); |
121 | }; | 121 | }; |
122 | 122 | ||
123 | this.addPoint = function (pt) { | 123 | this.addPoint = function (pt) { |
@@ -399,7 +399,7 @@ var BrushStroke = function GLBrushStroke() { | |||
399 | 399 | ||
400 | // ***** unproject all the centered points and convert them to 2D (plane space)***** | 400 | // ***** unproject all the centered points and convert them to 2D (plane space)***** |
401 | // (undo the projection step performed by the browser) | 401 | // (undo the projection step performed by the browser) |
402 | localPoint = this._unprojectPt(localPoint, 1400); //todo get the perspective distance from the canvas | 402 | //localPoint = this._unprojectPt(localPoint, 1400); //todo get the perspective distance from the canvas |
403 | localPoint = MathUtils.transformPoint(localPoint, this._planeMatInv); | 403 | localPoint = MathUtils.transformPoint(localPoint, this._planeMatInv); |
404 | 404 | ||
405 | //add to the list of local points | 405 | //add to the list of local points |
@@ -568,17 +568,17 @@ var BrushStroke = function GLBrushStroke() { | |||
568 | } | 568 | } |
569 | ctx.save(); | 569 | ctx.save(); |
570 | ctx.clearRect(0, 0, bboxWidth, bboxHeight); | 570 | ctx.clearRect(0, 0, bboxWidth, bboxHeight); |
571 | this.drawToContext(ctx, 0, 0, false); | 571 | this.drawToContext(ctx, false); |
572 | ctx.restore(); | 572 | ctx.restore(); |
573 | } //this.render() | 573 | } //this.render() |
574 | 574 | ||
575 | this.drawToContext = function(ctx, origX, origY, drawStageWorldPts){ | 575 | this.drawToContext = function(ctx, drawStageWorldPts, stageWorldDeltaX, stageWorldDeltaY, stageWorldToScreenMat){ |
576 | var points = this._LocalPoints; | 576 | var points = this._LocalPoints; |
577 | if (drawStageWorldPts){ | 577 | if (drawStageWorldPts){ //this is usually true when we're drawing the brush stroke on the stage (no canvas yet) |
578 | points = this._Points; | 578 | points = this._Points; |
579 | } | 579 | } |
580 | var numPoints = points.length; | 580 | var numPoints = points.length; |
581 | 581 | var tempP, p; | |
582 | if (this._strokeUseCalligraphic) { | 582 | if (this._strokeUseCalligraphic) { |
583 | //build the stamp for the brush stroke | 583 | //build the stamp for the brush stroke |
584 | var t=0; | 584 | var t=0; |
@@ -623,9 +623,23 @@ var BrushStroke = function GLBrushStroke() { | |||
623 | //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")"; | 623 | //ctx.strokeStyle="rgba("+parseInt(255*currStrokeColor[0])+","+parseInt(255*currStrokeColor[1])+","+parseInt(255*currStrokeColor[2])+","+alphaVal+")"; |
624 | ctx.translate(disp[0],disp[1]); | 624 | ctx.translate(disp[0],disp[1]); |
625 | ctx.beginPath(); | 625 | ctx.beginPath(); |
626 | ctx.moveTo(points[0][0]-origX, points[0][1]-origY); | 626 | if (drawStageWorldPts) { |
627 | tempP = points[0].slice(0); | ||
628 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
629 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
630 | } else { | ||
631 | p = points[0]; | ||
632 | } | ||
633 | ctx.moveTo(p[0],p[1]); | ||
627 | for (var i=0;i<numPoints;i++){ | 634 | for (var i=0;i<numPoints;i++){ |
628 | ctx.lineTo(points[i][0]-origX, points[i][1]-origY); | 635 | if (drawStageWorldPts) { |
636 | tempP = points[i].slice(0); | ||
637 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
638 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
639 | } else { | ||
640 | p = points[i]; | ||
641 | } | ||
642 | ctx.lineTo(p[0],p[1]); | ||
629 | } | 643 | } |
630 | ctx.stroke(); | 644 | ctx.stroke(); |
631 | ctx.restore(); | 645 | ctx.restore(); |
@@ -641,13 +655,27 @@ var BrushStroke = function GLBrushStroke() { | |||
641 | ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; | 655 | ctx.strokeStyle="rgba("+parseInt(255*this._strokeColor[0])+","+parseInt(255*this._strokeColor[1])+","+parseInt(255*this._strokeColor[2])+","+alphaVal+")"; |
642 | for (var l=0;l<numlayers;l++){ | 656 | for (var l=0;l<numlayers;l++){ |
643 | ctx.beginPath(); | 657 | ctx.beginPath(); |
644 | ctx.moveTo(points[0][0]-origX, points[0][1]-origY); | 658 | if (drawStageWorldPts) { |
659 | tempP = points[0].slice(0); | ||
660 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
661 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
662 | } else { | ||
663 | p = points[0]; | ||
664 | } | ||
665 | ctx.moveTo(p[0],p[1]); | ||
645 | if (numPoints===1){ | 666 | if (numPoints===1){ |
646 | //display a tiny segment as a single point | 667 | //display a tiny segment as a single point |
647 | ctx.lineTo(points[0][0]-origX, points[0][1]-origY+0.01); | 668 | ctx.lineTo(p[0],p[1]+0.01); |
648 | } | 669 | } |
649 | for (var i=1;i<numPoints;i++){ | 670 | for (var i=1;i<numPoints;i++){ |
650 | ctx.lineTo(points[i][0]-origX, points[i][1]-origY); | 671 | if (drawStageWorldPts) { |
672 | tempP = points[i].slice(0); | ||
673 | tempP[0]+=stageWorldDeltaX; tempP[1]+=stageWorldDeltaY; | ||
674 | p = MathUtils.transformAndDivideHomogeneousPoint(tempP, stageWorldToScreenMat); | ||
675 | } else { | ||
676 | p = points[i]; | ||
677 | } | ||
678 | ctx.lineTo(p[0],p[1]); | ||
651 | } | 679 | } |
652 | ctx.lineWidth=2*l+minStrokeWidth; | 680 | ctx.lineWidth=2*l+minStrokeWidth; |
653 | ctx.stroke(); | 681 | ctx.stroke(); |
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 218dcfa6..0f1f49a9 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -4,9 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | 8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; |
9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
10 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | ||
11 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | ||
12 |