diff --git a/web/app/engine.js b/web/app/engine.js index 84a4d548..626853d7 100644 --- a/web/app/engine.js +++ b/web/app/engine.js @@ -264,17 +264,20 @@ TCAD.SketchFace.prototype.SKETCH_MATERIAL = new THREE.LineBasicMaterial({ color: 0xFFFFFF, linewidth: 3}); TCAD.SketchFace.prototype.syncSketches = function(geom) { + var i; var normal = this.polygon.normal; var offVector = normal.multiply(0.5); - + if (this.sketch3DGroup != null) { - this.sketch3DGroup.remove(this.sketch3DGroup.children); + for (var i = this.sketch3DGroup.children.length - 1; i >= 0; --i) { + this.sketch3DGroup.remove(this.sketch3DGroup.children[i]); + } + } else { this.sketch3DGroup = new THREE.Object3D(); } this.geom = []; - var i = 0; var _3dTransformation = new TCAD.Matrix().setBasis(TCAD.geom.someBasis(this.polygon.shell, normal)); //we lost depth or z off in 2d sketch, calculate it again var depth = normal.dot(this.polygon.shell[0]); diff --git a/web/app/main.js b/web/app/main.js index a2f9549e..67f8aca6 100644 --- a/web/app/main.js +++ b/web/app/main.js @@ -22,13 +22,33 @@ TCAD.App = function() { } this.viewer.render(); - + var viewer = this.viewer; + var app = this; function storage_handler(evt) { - console.log('The modified key was '+evt.key); - console.log('The original value was '+evt.oldValue); - console.log('The new value is '+evt.newValue); - console.log('The URL of the page that made the change was '+evt.url); - console.log('The window where the change was made was '+evt.source); +// console.log('The modified key was '+evt.key); +// console.log('The original value was '+evt.oldValue); +// console.log('The new value is '+evt.newValue); +// console.log('The URL of the page that made the change was '+evt.url); +// console.log('The window where the change was made was '+evt.source); + + var prefix = "TCAD.projects."+app.id+".sketch."; + if (evt.key.indexOf(prefix) < 0) return; + sketchFaceId = evt.key.substring(prefix.length); + + for (var oi = 0; oi < viewer.scene.children.length; ++oi) { + var obj = viewer.scene.children[oi]; + if (obj.geometry !== undefined && obj.geometry.polyFaces !== undefined) { + for (var i = 0; i < box.geometry.polyFaces.length; i++) { + var sketchFace = box.geometry.polyFaces[i]; + if (sketchFace.id == sketchFaceId) { + var geom = TCAD.workbench.readSketchGeom(JSON.parse(evt.newValue)); + sketchFace.syncSketches(geom); + viewer.render(); + break; + } + } + } + } } window.addEventListener('storage', storage_handler, false);