aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes/3D
diff options
context:
space:
mode:
authorNivesh Rajbhandari2012-04-04 17:24:27 -0700
committerNivesh Rajbhandari2012-04-04 17:24:27 -0700
commit01cf259da7aaa7d70789d9a7c32111d88b477463 (patch)
tree0bff3395ac681e5f685d2267f7dbc03a8e32bc4a /js/helper-classes/3D
parent331ea08655245e3532e48bf160d5f68a04d8723f (diff)
parent13368ca6ebbc13adeafccd898dfffd7ce37cb28a (diff)
downloadninja-01cf259da7aaa7d70789d9a7c32111d88b477463.tar.gz
Merge branch 'refs/heads/ToolFixes' into WebGLMaterials
Conflicts: js/document/templates/montage-html/default_html.css js/mediators/element-mediator.js js/panels/properties.reel/properties.js js/tools/BrushTool.js js/tools/LineTool.js js/tools/PenTool.js js/tools/SelectionTool.js js/tools/ShapeTool.js js/tools/TranslateObject3DTool.js Signed-off-by: Nivesh Rajbhandari <mqg734@motorola.com>
Diffstat (limited to 'js/helper-classes/3D')
-rwxr-xr-xjs/helper-classes/3D/draw-utils.js104
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js24
-rwxr-xr-xjs/helper-classes/3D/vec-utils.js2
-rwxr-xr-xjs/helper-classes/3D/view-utils.js13
4 files changed, 98 insertions, 45 deletions
diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js
index d6334e6c..a5428ea3 100755
--- a/js/helper-classes/3D/draw-utils.js
+++ b/js/helper-classes/3D/draw-utils.js
@@ -109,10 +109,10 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
109 this._gridOrigin = [0,0]; // 2D plane space point 109 this._gridOrigin = [0,0]; // 2D plane space point
110 110
111 this.eventManager.addEventListener("elementAdded", this, false); 111 this.eventManager.addEventListener("elementAdded", this, false);
112 this.eventManager.addEventListener("elementDeleted", this, false); 112 this.eventManager.addEventListener("elementsRemoved", this, false);
113 this.eventManager.addEventListener("deleteSelection", this, false);
114 this.eventManager.addEventListener("elementChange", this, false); 113 this.eventManager.addEventListener("elementChange", this, false);
115 this.eventManager.addEventListener("closeDocument", this, false); 114 this.eventManager.addEventListener("closeDocument", this, false);
115 this.eventManager.addEventListener("elementReplaced", this, false);
116 } 116 }
117 }, 117 },
118 118
@@ -147,38 +147,75 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
147 147
148 handleElementAdded: { 148 handleElementAdded: {
149 value: function(event) { 149 value: function(event) {
150 this.addElement(event.detail); 150 var elements = event.detail;
151
152 if(Array.isArray(elements)) {
153 elements.forEach(function(element) {
154 this.addElement(element);
155 }, this);
156 } else {
157 this.addElement(elements);
158 }
159
151 this.drawWorkingPlane(); 160 this.drawWorkingPlane();
152 } 161 }
153 }, 162 },
154 163
155 handleElementDeleted: { 164 handleElementsRemoved: {
156 value: function(event) { 165 value: function(event) {
157 this.removeElement(event.detail); 166 var elements = event.detail;
167
168 if(Array.isArray(elements)) {
169 elements = Array.prototype.slice.call(elements, 0);
170 elements.forEach(function(element) {
171 this.removeElement(element);
172 }, this);
173 } else {
174 this.removeElement(elements);
175 }
176
177 this.drawWorkingPlane();
158 } 178 }
159 }, 179 },
160 180
161 handleDeleteSelection: { 181 handleElementReplaced: {
162 value: function(event) { 182 value: function(event) {
163 this.drawWorkingPlane(); 183 var oldElement = event.detail.data.oldChild;
184 var newElement = event.detail.data.newChild;
185
186 // check if we already know about this object
187 var n = this._eltArray.length,
188 plane;
189 for (var i=0; i<n; i++) {
190 if (oldElement === this._eltArray[i]) {
191 this._eltArray[i] = newElement;
192 plane = this._planesArray[i];
193 break;
194 }
195 }
196
197 if(!plane) {
198 this._eltArray.push( newElement );
199 plane = Object.create(this.ElementPlanes, {});
200 this._planesArray.push( plane );
201 }
202
203 plane.setElement( newElement );
204 plane.init();
205 newElement.elementModel.props3D.elementPlane = plane;
164 } 206 }
165 }, 207 },
166 208
167 _shouldUpdatePlanes: { 209 _shouldUpdatePlanes: {
168 value: function(props) { 210 value: function(props) {
169 if(!props) 211 if(!props) {
170 {
171 return false; 212 return false;
172 } 213 } else if (typeof props === "string") {
173 else if (typeof props === "string")
174 {
175 return (this._updatePlaneProps.indexOf(props) !== -1); 214 return (this._updatePlaneProps.indexOf(props) !== -1);
176 } 215 }
177 216
178 for (var p in props) 217 for (var p in props) {
179 { 218 if(this._updatePlaneProps.indexOf(p) !== -1) {
180 if(this._updatePlaneProps.indexOf(p) !== -1)
181 {
182 return true; 219 return true;
183 } 220 }
184 } 221 }
@@ -199,15 +236,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
199 { 236 {
200 var len = els.length, 237 var len = els.length,
201 i = 0, 238 i = 0,
202 item, 239 item;
203 el;
204 240
205 for(i=0; i < len; i++) { 241 for(i=0; i < len; i++) {
206 item = els[i]; 242 if(els[i].elementModel.props3D.elementPlane)
207 el = item._element || item;
208 if(el.elementModel.props3D.elementPlane)
209 { 243 {
210 el.elementModel.props3D.elementPlane.init(); 244 els[i].elementModel.props3D.elementPlane.init();
211 } 245 }
212 } 246 }
213 247
@@ -222,17 +256,12 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
222 // Methods 256 // Methods
223 /////////////////////////////////////////////////////////////////////// 257 ///////////////////////////////////////////////////////////////////////
224 258
225 addElement: 259 addElement: {
226 { 260 value: function( elt ) {
227 value: function( elt )
228 {
229 // check if we already know about this object 261 // check if we already know about this object
230 var n = this._eltArray.length; 262 var n = this._eltArray.length;
231 for (var i=0; i<n; i++) 263 for (var i=0; i<n; i++) {
232 { 264 if (elt == this._eltArray[i]) {
233 if (elt == this._eltArray[i])
234 {
235// console.log( "element already added to stage display: " + elt.id );
236 return; 265 return;
237 } 266 }
238 } 267 }
@@ -248,17 +277,14 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, {
248 } 277 }
249 }, 278 },
250 279
251 removeElement : { 280 removeElement: {
252 value: function( elt ) { 281 value: function(element) {
253 // check if object exists 282 // check if object exists
254 var n = this._eltArray.length; 283 var _elements = this._eltArray.length;
255 for (var i=0; i<n; i++) 284 for (var i=0; i < _elements; i++) {
256 { 285 if (element === this._eltArray[i]) {
257 if (elt == this._eltArray[i])
258 {
259 // First remove the planes for this element 286 // First remove the planes for this element
260 this._planesArray.splice(i, 1); 287 this._planesArray.splice(i, 1);
261
262 // Then remove the element 288 // Then remove the element
263 this._eltArray.splice(i, 1); 289 this._eltArray.splice(i, 1);
264 290
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index a755e9e2..a401c363 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -123,7 +123,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
123 /////////////////////////////////////////////////////////////////////// 123 ///////////////////////////////////////////////////////////////////////
124 initialize: { 124 initialize: {
125 value: function() { 125 value: function() {
126 this.eventManager.addEventListener("elementDeleted", this, false); 126 this.eventManager.addEventListener("elementsRemoved", this, false);
127 this.eventManager.addEventListener("elementReplaced", this, false);
127 } 128 }
128 }, 129 },
129 130
@@ -163,12 +164,26 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
163 }, 164 },
164 165
165 166
166 handleElementDeleted: { 167 handleElementsRemoved: {
167 value: function(event) { 168 value: function(event) {
168 this.removeElementFrom2DCache(event.detail); 169 var self = this, elements = event.detail;
170
171 if(Array.isArray(elements)) {
172 elements = Array.prototype.slice.call(elements, 0);
173 elements.forEach(function(element) {
174 self.removeElementFrom2DCache(element);
175 });
176 } else {