diff options
Diffstat (limited to 'js/helper-classes/3D/draw-utils.js')
-rwxr-xr-x | js/helper-classes/3D/draw-utils.js | 111 |
1 files changed, 80 insertions, 31 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 88830964..871b832d 100755 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js | |||
@@ -119,19 +119,46 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
119 | 119 | ||
120 | initializeFromDocument:{ | 120 | initializeFromDocument:{ |
121 | value:function(){ | 121 | value:function(){ |
122 | var documentRootChildren = null, i; | 122 | var i, |
123 | documentRootChildren = this.application.ninja.currentDocument.model.views.design.getLiveNodeList(true), | ||
124 | stage = this.application.ninja.stage, | ||
125 | len = documentRootChildren.length; | ||
123 | //initialize with current document | 126 | //initialize with current document |
124 | this._eltArray = []; | 127 | this._eltArray = []; |
125 | this._planesArray = []; | 128 | this._planesArray = []; |
126 | this.setDrawingSurfaceElement(this.application.ninja.stage.canvas); | 129 | this.setDrawingSurfaceElement(stage.canvas); |
127 | this.setSourceSpaceElement( this.application.ninja.stage.stageDeps.currentStage ); | 130 | this.setSourceSpaceElement( this.application.ninja.currentDocument.model.documentRoot); |
128 | this.setWorkingPlane( [0,0,1,0] ); | 131 | this.setWorkingPlane( [0,0,1,0] ); |
129 | 132 | ||
130 | //Loop through all the top-level children of the current document and call drawUtils.addElement on them | 133 | //Loop through all the top-level children of the current document and call drawUtils.addElement on them |
131 | if(this.application.ninja.currentDocument._liveNodeList.length > 0){ | 134 | if(len > 0) { |
132 | documentRootChildren = this.application.ninja.currentDocument._liveNodeList; | 135 | var initL = 0, |
133 | for(i=0;i<documentRootChildren.length;i++){ | 136 | initT = 0, |
134 | this.addElement(documentRootChildren[i]); | 137 | minLeft = 0, |
138 | minTop = 0, | ||
139 | docLeft = stage.documentOffsetLeft, | ||
140 | docTop = stage.documentOffsetTop, | ||
141 | l, | ||
142 | t, | ||
143 | plane, | ||
144 | elt; | ||
145 | for(i=0; i<len; i++) { | ||
146 | elt = documentRootChildren[i]; | ||
147 | plane = this.addElement(elt); | ||
148 | l = plane._rect.m_left - docLeft; | ||
149 | t = plane._rect.m_top - docTop; | ||
150 | if(l < minLeft) { | ||
151 | minLeft = l; | ||
152 | } | ||
153 | if(t < minTop) { | ||
154 | minTop = t; | ||
155 | } | ||
156 | } | ||
157 | if(minLeft !== initL) { | ||
158 | stage.userPaddingLeft = minLeft; | ||
159 | } | ||
160 | if(minTop !== initT) { | ||
161 | stage.userPaddingTop = minTop; | ||
135 | } | 162 | } |
136 | } | 163 | } |
137 | } | 164 | } |
@@ -245,16 +272,45 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
245 | } | 272 | } |
246 | var els = event.detail.data.els; | 273 | var els = event.detail.data.els; |
247 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { | 274 | if(els && this._shouldUpdatePlanes(event.detail.data.prop)) { |
248 | var len = els.length; | 275 | var len = els.length, |
276 | stage = this.application.ninja.stage, | ||
277 | minLeft = stage.userPaddingLeft, | ||
278 | minTop = stage.userPaddingTop, | ||
279 | docLeft = stage.documentOffsetLeft, | ||
280 | docTop = stage.documentOffsetTop, | ||
281 | l, | ||
282 | t, | ||
283 | plane, | ||
284 | changed = false; | ||
249 | for(var i=0; i < len; i++) { | 285 | for(var i=0; i < len; i++) { |
250 | if(els[i].elementModel.props3D.elementPlane) { | 286 | plane = els[i].elementModel.props3D.elementPlane; |
251 | els[i].elementModel.props3D.elementPlane.init(); | 287 | if(plane) { |
288 | plane.init(); | ||
289 | l = plane._rect.m_left - docLeft; | ||
290 | t = plane._rect.m_top - docTop; | ||
291 | if(l < minLeft) { | ||
292 | minLeft = l; | ||
293 | } | ||
294 | if(t < minTop) { | ||
295 | minTop = t; | ||
296 | } | ||
252 | } | 297 | } |
253 | } | 298 | } |
254 | 299 | ||
255 | this.application.ninja.stage.layout.draw(); | 300 | if(minLeft !== stage.userPaddingLeft) { |
256 | this.drawWorkingPlane(); | 301 | stage.userPaddingLeft = minLeft; |
257 | this.draw3DCompass(); | 302 | changed = true; |
303 | } | ||
304 | if(minTop !== stage.userPaddingTop) { | ||
305 | stage.userPaddingTop = minTop; | ||
306 | changed = true; | ||
307 | } | ||
308 | |||
309 | if(!changed) { | ||
310 | stage.layout.draw(); | ||
311 | this.drawWorkingPlane(); | ||
312 | this.draw3DCompass(); | ||
313 | } | ||
258 | } | 314 | } |
259 | } | 315 | } |
260 | }, | 316 | }, |
@@ -281,6 +337,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
281 | plane.init(); | 337 | plane.init(); |
282 | this._planesArray.push( plane ); | 338 | this._planesArray.push( plane ); |
283 | elt.elementModel.props3D.elementPlane = plane; | 339 | elt.elementModel.props3D.elementPlane = plane; |
340 | return plane; | ||
284 | } | 341 | } |
285 | }, | 342 | }, |
286 | 343 | ||
@@ -584,18 +641,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
584 | var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); | 641 | var ptOnPlane = MathUtils.getPointOnPlane(this._workingPlane); |
585 | 642 | ||
586 | // define the grid parameters | 643 | // define the grid parameters |
587 | var width, | 644 | var width = this.snapManager.getStageWidth(), |
588 | height, | 645 | height = this.snapManager.getStageHeight(), |
589 | nLines = 10; | 646 | nLines = 10; |
590 | 647 | ||
591 | // if(this.application.ninja.documentController.webTemplate) { | ||
592 | if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { | ||
593 | width = this.application.ninja.currentDocument.documentRoot.scrollWidth; | ||
594 | height = this.application.ninja.currentDocument.documentRoot.scrollHeight; | ||
595 | } else { | ||
596 | width = this.snapManager.getStageWidth(); | ||
597 | height = this.snapManager.getStageHeight(); | ||
598 | } | ||
599 | // get a matrix from working plane space to the world | 648 | // get a matrix from working plane space to the world |
600 | var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); | 649 | var mat = this.getPlaneToWorldMatrix(zAxis, ptOnPlane); |
601 | var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] ); | 650 | var tMat = Matrix.Translation( [0.5*width, 0.5*height, 0] ); |
@@ -651,7 +700,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
651 | this._lineColor = saveColor; | 700 | this._lineColor = saveColor; |
652 | this._drawingContext.lineWidth = saveLineWidth; | 701 | this._drawingContext.lineWidth = saveLineWidth; |
653 | 702 | ||
654 | if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { | 703 | if(this.application.ninja.currentDocument.model.documentRoot.id !== "UserContent") { |
655 | // draw an outline around the body | 704 | // draw an outline around the body |
656 | var stagePt = MathUtils.getPointOnPlane([0,0,1,0]); | 705 | var stagePt = MathUtils.getPointOnPlane([0,0,1,0]); |
657 | var stageMat = this.getPlaneToWorldMatrix([0,0,1], stagePt); | 706 | var stageMat = this.getPlaneToWorldMatrix([0,0,1], stagePt); |
@@ -769,7 +818,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
769 | // draw the lines | 818 | // draw the lines |
770 | var line, | 819 | var line, |
771 | nLines = this._gridLineArray.length; | 820 | nLines = this._gridLineArray.length; |
772 | if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { | 821 | if(this.application.ninja.currentDocument.model.documentRoot.id !== "UserContent") { |
773 | nLines = this._gridLineArray.length-4; | 822 | nLines = this._gridLineArray.length-4; |
774 | } | 823 | } |
775 | 824 | ||
@@ -778,7 +827,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
778 | this.drawIntersectedLine(line, this._drawingContext); | 827 | this.drawIntersectedLine(line, this._drawingContext); |
779 | } | 828 | } |
780 | 829 | ||
781 | if(this.application.ninja.currentDocument.documentRoot.id !== "UserContent") { | 830 | if(this.application.ninja.currentDocument.model.documentRoot.id !== "UserContent") { |
782 | this._lineColor = "red"; | 831 | this._lineColor = "red"; |
783 | i = nLines; | 832 | i = nLines; |
784 | nLines += 4; | 833 | nLines += 4; |
@@ -877,7 +926,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
877 | // if all of the planes are aligned, check if they are aligned with the view direction | 926 | // if all of the planes are aligned, check if they are aligned with the view direction |
878 | if (flat) | 927 | if (flat) |
879 | { | 928 | { |
880 | var stage = this.application.ninja.currentDocument.documentRoot; | 929 | var stage = this.application.ninja.currentDocument.model.documentRoot; |
881 | var stageMat = this.viewUtils.getMatrixFromElement(stage); | 930 | var stageMat = this.viewUtils.getMatrixFromElement(stage); |
882 | var viewDir = [ stageMat[8], stageMat[9], stageMat[10] ]; | 931 | var viewDir = [ stageMat[8], stageMat[9], stageMat[10] ]; |
883 | viewDir = vecUtils.vecNormalize( 3, viewDir ); | 932 | viewDir = vecUtils.vecNormalize( 3, viewDir ); |
@@ -1167,7 +1216,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
1167 | value: function() { | 1216 | value: function() { |
1168 | // set the element to be the viewport object - temporarily | 1217 | // set the element to be the viewport object - temporarily |
1169 | var tmpCanvas = this.application.ninja.stage.canvas; | 1218 | var tmpCanvas = this.application.ninja.stage.canvas; |
1170 | var tmpStage = this.application.ninja.currentDocument.documentRoot; | 1219 | var tmpStage = this.application.ninja.currentDocument.model.documentRoot; |
1171 | this.viewUtils.pushViewportObj( tmpCanvas ); | 1220 | this.viewUtils.pushViewportObj( tmpCanvas ); |
1172 | 1221 | ||
1173 | // save the source space object and set to the target object | 1222 | // save the source space object and set to the target object |
@@ -1178,8 +1227,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||
1178 | var saveColor = this._lineColor; | 1227 | var saveColor = this._lineColor; |
1179 | var saveLineWidth = this._lineWidth; | 1228 | var saveLineWidth = this._lineWidth; |
1180 | 1229 | ||
1181 | var origLeft = 50; | 1230 | var origLeft = 60; |
1182 | var origTop = 50; | 1231 | var origTop = this.snapManager.getStageHeight() - 60; |
1183 | 1232 | ||
1184 | var mat = this.viewUtils.getMatrixFromElement( this._sourceSpaceElt ); | 1233 | var mat = this.viewUtils.getMatrixFromElement( this._sourceSpaceElt ); |
1185 | var tMat = Matrix.Translation([origLeft,origTop,0]); | 1234 | var tMat = Matrix.Translation([origLeft,origTop,0]); |
@@ -1211,7 +1260,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { | |||