aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D/draw-utils.js
diff options
context:
space:
mode:
authorJon Reid2012-06-25 11:07:33 -0700
committerJon Reid2012-06-25 11:07:33 -0700
commit831e3058a9d58c5e56066d2ff90e572be17d6f7e (patch)
treeaa6acda9aeddad8f93cae63b955349a442ddf01f /js/helper-classes/3D/draw-utils.js
parent82638621ed793fcb37438798363dba151efd9cd2 (diff)
parentda3d11366fa6f42a99cbd8998eebd5fe572b76bc (diff)
downloadninja-831e3058a9d58c5e56066d2ff90e572be17d6f7e.tar.gz
Merge remote-tracking branch 'ninja-jduran/TimelineUber' into timeline-local
Conflicts: js/panels/Timeline/TimelinePanel.reel/TimelinePanel.js Resolution: Use both.
Diffstat (limited to 'js/helper-classes/3D/draw-utils.js')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js118
1 files changed, 66 insertions, 52 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index 6a84c86b..bd47ffc3 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -247,18 +247,18 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
247 // TODO - Check why handleElementChange is being fired before handleAddElement 247 // TODO - Check why handleElementChange is being fired before handleAddElement
248 handleElementChange: { 248 handleElementChange: {
249 value: function(event) { 249 value: function(event) {
250 this._elementChangeHelper(event); 250 this._elementChangeHelper(event, false);
251 } 251 }
252 }, 252 },
253 253
254 handleElementChanging: { 254 handleElementChanging: {
255 value: function(event) { 255 value: function(event) {
256 this._elementChangeHelper(event); 256 this._elementChangeHelper(event, true);
257 } 257 }
258 }, 258 },
259 259
260 _elementChangeHelper: { 260 _elementChangeHelper: {
261 value: function(event) { 261 value: function(event, isChanging) {
262 if(!event.detail || !event.detail.data) { 262 if(!event.detail || !event.detail.data) {
263 return; 263 return;
264 } 264 }
@@ -273,35 +273,45 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
273 l, 273 l,
274 t, 274 t,
275 plane, 275 plane,
276 changed = false; 276 changed = false,
277 adjustStagePadding = !isChanging || (event.detail.data.prop !== "matrix");
277 for(var i=0; i < len; i++) { 278 for(var i=0; i < len; i++) {
278 plane = els[i].elementModel.props3D.elementPlane; 279 plane = els[i].elementModel.props3D.elementPlane;
279 if(plane) { 280 if(plane) {
280 plane.init(); 281 plane.init();
281 l = plane._rect.m_left - docLeft; 282 if(adjustStagePadding) {
282 t = plane._rect.m_top - docTop; 283 l = plane._rect.m_left - docLeft;
283 if(l < minLeft) { 284 t = plane._rect.m_top - docTop;
284 minLeft = l; 285 if(l < minLeft) {
285 } 286 minLeft = l;
286 if(t < minTop) { 287 }
287 minTop = t; 288 if(t < minTop) {
289 minTop = t;
290 }
288 } 291 }
289 } 292 }
290 } 293 }
291 294
292 if(minLeft !== stage.userPaddingLeft) { 295 if(adjustStagePadding) {
293 stage.userPaddingLeft = minLeft; 296 if(minLeft !== stage.userPaddingLeft) {
294 changed = true; 297 stage.userPaddingLeft = minLeft;
295 } 298 changed = true;
296 if(minTop !== stage.userPaddingTop) { 299 }
297 stage.userPaddingTop = minTop; 300 if(minTop !== stage.userPaddingTop) {
298 changed = true; 301 stage.userPaddingTop = minTop;
302 changed = true;
303 }
299 } 304 }
300 305
301 if(!changed) { 306 if(!changed) {
302 this.drawWorkingPlane(); 307 this.drawWorkingPlane();
303 this.draw3DCompass(); 308 this.draw3DCompass();
304 } 309 }
310
311 // TODO - Remove this once all stage drawing is consolidated into a single draw cycle
312 if(!isChanging && this.application.ninja.toolsData.selectedToolInstance.captureSelectionDrawn) {
313 this.application.ninja.toolsData.selectedToolInstance.captureSelectionDrawn(null);
314 }
305 } 315 }
306 } 316 }
307 }, 317 },
@@ -620,6 +630,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
620 value: function () 630 value: function ()
621 { 631 {
622 this.application.ninja.stage.clearGridCanvas(); 632 this.application.ninja.stage.clearGridCanvas();
633 this.drawStageOutline();
623 if (!this.isDrawingGrid()) return; 634 if (!this.isDrawingGrid()) return;
624 635
625 var saveContext = this.getDrawingSurfaceElement(); 636 var saveContext = this.getDrawingSurfaceElement();
@@ -691,21 +702,6 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
691 this._lineColor = saveColor; 702 this._lineColor = saveColor;
692 this._drawingContext.lineWidth = saveLineWidth; 703 this._drawingContext.lineWidth = saveLineWidth;
693 704
694 if(this.application.ninja.currentDocument.model.documentRoot.id !== "UserContent") {
695 // draw an outline around the body
696 var stagePt = MathUtils.getPointOnPlane([0,0,1,0]);
697 var stageMat = this.getPlaneToWorldMatrix([0,0,1], stagePt);
698 // glmat4.multiply( tMat, stageMat, stageMat);
699 pt0 = [0, 0, 0];
700 pt1 = [0, height, 0];
701 delta = [width, 0, 0];
702 this.drawGridLines(pt0, pt1, delta, stageMat, 2);
703 pt0 = [0, 0, 0];
704 pt1 = [width, 0, 0];
705 delta = [0, height, 0];
706 this.drawGridLines(pt0, pt1, delta, stageMat, 2);
707 }
708
709 // draw the lines 705 // draw the lines
710 this.redrawGridLines(); 706 this.redrawGridLines();
711 707
@@ -728,15 +724,11 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
728 var sourceSpaceMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt ); 724 var sourceSpaceMat = this.viewUtils.getLocalToGlobalMatrix( this._sourceSpaceElt );
729 for (var i = 0; i < nLines; i++) { 725 for (var i = 0; i < nLines; i++) {
730 // transform the points from working plane space to world space 726 // transform the points from working plane space to world space
731 //var t0 = mat.multiply(p0),
732 // t1 = mat.multiply(p1);
733 var t0 = glmat4.multiplyVec3( mat, p0, [] ), 727 var t0 = glmat4.multiplyVec3( mat, p0, [] ),
734 t1 = glmat4.multiplyVec3( mat, p1, [] ); 728 t1 = glmat4.multiplyVec3( mat, p1, [] );
735 729
736 // transform from world space to global screen space 730 // transform from world space to global screen space
737 if (this._sourceSpaceElt) { 731 if (this._sourceSpaceElt) {
738// t0 = this.viewUtils.localToGlobal(t0, this._sourceSpaceElt);
739// t1 = this.viewUtils.localToGlobal(t1, this._sourceSpaceElt);
740 t0 = this.viewUtils.localToGlobal2(t0, sourceSpaceMat); 732 t0 = this.viewUtils.localToGlobal2(t0, sourceSpaceMat);
741 t1 = this.viewUtils.localToGlobal2(t1, sourceSpaceMat); 733 t1 = this.viewUtils.localToGlobal2(t1, sourceSpaceMat);
742 } 734 }
@@ -754,9 +746,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
754 line.setVisibility(vis); 746 line.setVisibility(vis);
755 747
756 // increment the points to the next position 748 // increment the points to the next position
757// p0 = p0.add(d); p0[3] = 1.0;
758 p0 = vecUtils.vecAdd(4, p0, d); p0[3] = 1.0; 749 p0 = vecUtils.vecAdd(4, p0, d); p0[3] = 1.0;
759// p1 = p1.add(d); p1[3] = 1.0;
760 p1 = vecUtils.vecAdd(4, p1, d); p1[3] = 1.0; 750 p1 = vecUtils.vecAdd(4, p1, d); p1[3] = 1.0;
761 } 751 }
762 } 752 }
@@ -809,25 +799,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
809 // draw the lines 799 // draw the lines
810 var line, 800 var line,
811 nLines = this._gridLineArray.length; 801 nLines = this._gridLineArray.length;
812 if(this.application.ninja.currentDocument.model.documentRoot.id !== "UserContent") {
813 nLines = this._gridLineArray.length-4;
814 }
815 802
816 for (var i = 0; i < nLines; i++) { 803 for (var i = 0; i < nLines; i++) {
817 line = this._gridLineArray[i]; 804 line = this._gridLineArray[i];
818 this.drawIntersectedLine(line, this._drawingContext); 805 this.drawIntersectedLine(line, this._drawingContext);
819 } 806 }
820 807
821 if(this.application.ninja.currentDocument.model.documentRoot.id !== "UserContent") {
822 this._lineColor = "red";
823 i = nLines;
824 nLines += 4;
825 for (; i < nLines; i++) {
826 line = this._gridLineArray[i];
827 this.drawIntersectedLine(line, this._drawingContext);
828 }
829 }
830
831 this.popState(); 808 this.popState();
832 } 809 }
833 }, 810 },
@@ -1203,6 +1180,43 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
1203 } 1180 }
1204 }, 1181 },
1205 1182
1183 drawStageOutline : {
1184 value: function() {
1185 var context = this.application.ninja.stage.gridContext;
1186 var stage = this.application.ninja.stage;
1187 var stageRoot = this.application.ninja.currentDocument.model.documentRoot;
1188 var bounds3D = this.viewUtils.getElementBoundsInGlobal(stageRoot);
1189
1190 var l = MathUtils.segSegIntersection2D(bounds3D[0], bounds3D[3], [0, 0, 0], [0, stage.canvas.height, 0], 0.1);
1191 if(!l) return;
1192 var r = MathUtils.segSegIntersection2D(bounds3D[0], bounds3D[3], [stage.canvas.width, 0, 0], [stage.canvas.width, stage.canvas.height, 0], 0.1);
1193 if(!r) return;
1194
1195 var t = MathUtils.segSegIntersection2D(bounds3D[0], bounds3D[1], [0, 0, 0], [stage.canvas.width, 0, 0], 0.1);
1196 if(!t) return;
1197 var b = MathUtils.segSegIntersection2D(bounds3D[0], bounds3D[1], [0, stage.canvas.height, 0], [stage.canvas.width, stage.c