diff --git a/js/cam/Assembler.js b/js/cam/Assembler.js index b5c0743d1bfe7225edbd56f7e1445f0fcc6b51e0..a96832e1057ba24e7227bd7fd4b49be6af257423 100644 --- a/js/cam/Assembler.js +++ b/js/cam/Assembler.js @@ -62,6 +62,12 @@ Assembler = Backbone.Model.extend({ this.listenTo(options.lattice, "change:scale", this._setCAMScale); this.listenTo(dmaGlobals.appState, "change:stockSimulationPlaying", this._stockSimulation); + this.listenTo(options.lattice, "change:partType", this._updatePartType); + this.listenTo(options.appState, "change:cellMode", this._updateCellMode); + + + + //init origin mesh var origin = new THREE.Mesh(new THREE.SphereGeometry(1), new THREE.MeshBasicMaterial({color:0xff0000})); @@ -84,9 +90,23 @@ Assembler = Backbone.Model.extend({ }, /////////////////////////////////////////////////////////////////////////////////////////////// -////////////////////////////////STOCK / ORIGIN///////////////////////////////////////////////// +////////////////////////////////VISUALIZATION////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// + _isVisible: function(){ + var currentTab = dmaGlobals.appState.get("currentTab"); + return (currentTab == "cam" || currentTab == "animate" || currentTab == "send"); + }, + + _updatePartType: function(){ + if (this._isVisible()) this.get("machine").updatePartType(); + }, + + _updateCellMode: function(){ + this.get("machine").setVisibility(this._isVisible()); + dmaGlobals.three.render(); + }, + _setCAMScale: function(){ var scale = dmaGlobals.lattice.get("scale")/8; this.get("origin").scale.set(scale, scale, scale); @@ -94,11 +114,10 @@ Assembler = Backbone.Model.extend({ }, _setCAMVisibility: function(){ - var visible = false; - var currentTab = dmaGlobals.appState.get("currentTab"); - if (currentTab == "cam" || currentTab == "animate" || currentTab == "send") visible = true; + var visible = this._isVisible(); this.get("origin").visible = visible; this.get("stock").visible = visible; + this.get("machine").setVisibility(visible); dmaGlobals.three.render(); }, diff --git a/js/cam/Machine.js b/js/cam/Machine.js index 92f55857d28f5bcc886230921272c3bcce8efe91..71d9990b6d6ef59ec20af548b7d6f169692d0af3 100644 --- a/js/cam/Machine.js +++ b/js/cam/Machine.js @@ -4,27 +4,41 @@ function Machine() { - var mesh = new THREE.Mesh(new THREE.BoxGeometry(2,2,2));//this._makeStock(); - dmaGlobals.three.sceneAdd(mesh); - this.mesh = mesh; + + this.cell = new DMARotatedEdgeCell(null); + this.setVisibility(false); + } -Machine.prototype._makeStock = function(){ - var mesh = DMAEdgeVoxPart.prototype._makeMeshForType(); - mesh.myPart = null; - return mesh; +Machine.prototype.setVisibility = function(visible){ + if (visible){ + this.cell.draw(); + } else { + this.cell.hide(); + } +}; + +Machine.prototype.updatePartType = function(){ + this.cell.destroyParts(); + this.cell.draw(); }; -Machine.prototype.pause = function(){ + + + + +Machine.prototype.pause = function(){ }; Machine.prototype.moveTo = function(x, y, z, speed, wcs, callback){ var self = this; setTimeout( function() { - if (x != "") self.mesh.position.x = parseFloat(x)+wcs.x; - if (y != "") self.mesh.position.y = parseFloat(y)+wcs.y; - if (z != "") self.mesh.position.z = parseFloat(z)+wcs.z; + //reaching a little deep here, might want to find a better solution + if (x != "") self.cell.cellMesh.position.x = parseFloat(x)+wcs.x; + if (y != "") self.cell.cellMesh.position.y = parseFloat(y)+wcs.y; + if (z != "") self.cell.cellMesh.position.z = parseFloat(z)+wcs.z; + self.cell.updateForScale(); dmaGlobals.three.render(); return callback(); }, 500/dmaGlobals.assembler.get("simSpeed")); diff --git a/js/fea/DmaCell.js b/js/fea/DmaCell.js index a4862a97a13125537d1f7ee80ceaed05023d484f..fbf413b131135b0a483921a4c990259f178f0bd1 100644 --- a/js/fea/DmaCell.js +++ b/js/fea/DmaCell.js @@ -14,7 +14,10 @@ function DMACell(indices, scale, cellMode, partType) { this.cellMesh = this._buildCellMesh(); this._doMeshTransformations(this.cellMesh);//some cell types require transformations - dmaGlobals.three.sceneAdd(this.cellMesh, "cell"); + + var sceneType = "cell"; + if (!indices) sceneType = null; + dmaGlobals.three.sceneAdd(this.cellMesh,sceneType); this.nodes = this._initNodes(this.cellMesh.children[0].geometry.vertices); this.beams = this._initBeams(this.nodes, this.cellMesh.children[0].geometry.faces); @@ -99,6 +102,7 @@ DMACell.prototype.updateForScale = function(scale, cellMode, partType){ } }; + DMACell.prototype._setMeshPosition = function(mesh, position){ mesh.position.x = position.x; mesh.position.y = position.y; @@ -107,7 +111,7 @@ DMACell.prototype._setMeshPosition = function(mesh, position){ DMACell.prototype.getType = function(){ return null;//only used in freeform layout -} +}; DMACell.prototype.getScale = function(){//need for part relay return dmaGlobals.lattice.get("scale"); @@ -126,7 +130,8 @@ DMACell.prototype.getEulerRotation = function(){ }; DMACell.prototype._calcPosition = function(){//need for part relay - return dmaGlobals.lattice.getPositionForIndex(this.indices); + if (this.indices) return dmaGlobals.lattice.getPositionForIndex(this.indices); + return this.cellMesh.position;//used for cam simulation }; DMACell.prototype._setCellMeshVisibility = function(visibility){ diff --git a/js/fea/DmaCellOcta.js b/js/fea/DmaCellOcta.js index 4eb1c7e3e32ed050bda0a0186f81b8a6ce298538..ad1b048961f76248a0f7e92f92b0a72b8bc0e967 100644 --- a/js/fea/DmaCellOcta.js +++ b/js/fea/DmaCellOcta.js @@ -12,8 +12,8 @@ var unitFaceOctaGeo = new THREE.OctahedronGeometry(1/Math.sqrt(2)); unitFaceOctaGeo.applyMatrix(new THREE.Matrix4().makeRotationZ(-3*Math.PI/12)); unitFaceOctaGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.asin(2/Math.sqrt(2)/Math.sqrt(3)))); -function DMAFaceOctaCell(indices, scale){ - DMACell.call(this, indices, scale); +function DMAFaceOctaCell(indices, scale, cellMode, partType){ + DMACell.call(this, indices, scale, cellMode, partType); } DMAFaceOctaCell.prototype = Object.create(DMACell.prototype); @@ -121,8 +121,8 @@ DMAFreeFormOctaCell.prototype.zScale = function(scale){ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAEdgeOctaCell(indices, scale){ - DMAFaceOctaCell.call(this, indices, scale); +function DMAEdgeOctaCell(indices, scale, cellMode, partType){ + DMAFaceOctaCell.call(this, indices, scale, cellMode, partType); } DMAEdgeOctaCell.prototype = Object.create(DMAFaceOctaCell.prototype); @@ -145,8 +145,8 @@ DMAEdgeOctaCell.prototype.calcHighlighterPosition = function(face){ var unitVertexOcta = new THREE.OctahedronGeometry(1/Math.sqrt(2)); -function DMARotatedEdgeCell(indices, scale){ - DMACell.call(this, indices, scale); +function DMARotatedEdgeCell(indices, scale, cellMode, partType){ + DMACell.call(this, indices, scale, cellMode, partType); } DMARotatedEdgeCell.prototype = Object.create(DMACell.prototype); @@ -239,8 +239,8 @@ DMARotatedEdgeCell.prototype._getGeometry = function(){ /////////////////////////////////////////////////////////////////////////////////////////////// -function DMAVertexOctaCell(indices, scale){ - DMACell.call(this, indices, scale); +function DMAVertexOctaCell(indices, scale, cellMode, partType){ + DMACell.call(this, indices, scale, cellMode, partType); } DMAVertexOctaCell.prototype = Object.create(DMACell.prototype); diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index 8241bbe2babd863e0a185b0513438292e7fec6c5..1fd71a6b6dd4455c084ca5367828f4bd836007c9 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -15,8 +15,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; var unitCellGeo = new THREE.BoxGeometry(1,1,1); - function DMACubeCell(indices, scale){ - DMACell.call(this, indices, scale); + function DMACubeCell(indices, scale, cellMode, partType){ + DMACell.call(this, indices, scale, cellMode, partType); } DMACubeCell.prototype = Object.create(DMACell.prototype); @@ -111,8 +111,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; ]; unitCellGeo.computeFaceNormals(); - function DMATruncCubeCell(indices, scale){ - DMACell.call(this, indices, scale); + function DMATruncCubeCell(indices, scale, cellMode, partType){ + DMACell.call(this, indices, scale, cellMode, partType); } DMATruncCubeCell.prototype = Object.create(DMACell.prototype); @@ -254,8 +254,8 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; ]; unitCellGeo.computeFaceNormals(); - function DMATruncOctaCell(indices, scale){ - DMATruncCubeCell.call(this, indices, scale); + function DMATruncOctaCell(indices, scale, cellMode, partType){ + DMATruncCubeCell.call(this, iindices, scale, cellMode, partType); } DMATruncOctaCell.prototype = Object.create(DMATruncCubeCell.prototype); diff --git a/js/fea/DmaCellTetra.js b/js/fea/DmaCellTetra.js index 9f8b87ce64d91e4f672ebc58a4735710099507c7..e7b4a36eee6e44c703ab675925091f15171c9c9c 100644 --- a/js/fea/DmaCellTetra.js +++ b/js/fea/DmaCellTetra.js @@ -14,8 +14,8 @@ unitCellGeo.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,Math.sqrt(3/8)-1 var unitCellGeoUpsideDown = unitCellGeo.clone(); unitCellGeoUpsideDown.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI)); -function DMATetraFaceCell(indices, scale){ - DMACell.call(this, indices, scale); +function DMATetraFaceCell(indices, scale, cellMode, partType){ + DMACell.call(this, indices, scale, cellMode, partType); } DMATetraFaceCell.prototype = Object.create(DMACell.prototype); @@ -40,8 +40,8 @@ DMATetraFaceCell.prototype._getGeometry = function(){ ////////////////////////EDGE CONNECTED OCTA//////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////// -function DMATetraEdgeCell(indices, scale){ - DMATetraFaceCell.call(this, indices, scale); +function DMATetraEdgeCell(indices, scale, cellMode, partType){ + DMATetraFaceCell.call(this, indices, scale, cellMode, partType); } DMATetraEdgeCell.prototype = Object.create(DMATetraFaceCell.prototype);