diff --git a/js/fea/DmaCellOther.js b/js/fea/DmaCellOther.js index b5a57326f3c47dfc063ba5289c4c499d312c7252..123ceaaa982af1aad7cdf969b627535776828fd6 100644 --- a/js/fea/DmaCellOther.js +++ b/js/fea/DmaCellOther.js @@ -83,14 +83,30 @@ var cellMaterial = [new THREE.MeshNormalMaterial()]; DMAGIKCell.prototype.setSuperCell = function(superCell, index){ this.superCell = superCell; this.superCellIndex = index; + if (dmaGlobals.appState.get("cellMode")=="part") { + this.parts = this.__initParts(); + this.draw(); + } }; - DMAGIKCell.prototype._initParts = function(){ + DMAGIKCell.prototype.__initParts = function(){ var parts = []; - if (dmaGlobals.lattice.get("partType") == "lego") parts.push(new DMAGIKPart(0, this)); - else parts.push(new DMAGIKPartLowPoly(0, this)); + var isEnd = this.superCellIndex == 0 || this.superCellIndex == this.superCell.getLength()-1; + if (dmaGlobals.lattice.get("partType") == "lego") { + if (isEnd) parts.push(new DMAGIKEndPart(0, this)); + else parts.push(new DMAGIKPart(0, this)); + } + else { + if (isEnd) parts.push(new DMAGIKEndPartLowPoly(0, this)); + else parts.push(new DMAGIKPartLowPoly(0, this)); + } return parts; -}; + }; + + DMAGIKCell.prototype._initParts = function(){ + if (this.superCell) return this.__initParts(); + return []; + }; self.DMAGIKCell = DMAGIKCell; diff --git a/js/fea/DmaPart.js b/js/fea/DmaPart.js index 2dc06eb6399e6d9f1d28b6c711427bfa6120fc87..ae66d74a646fc0456ccf426f4f9fa000b0d9f4ad 100644 --- a/js/fea/DmaPart.js +++ b/js/fea/DmaPart.js @@ -226,12 +226,12 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE unitPartGeo.computeBoundingBox(); unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+unitPartGeo.boundingBox.max.x)/2, -(unitPartGeo.boundingBox.min.y+unitPartGeo.boundingBox.max.y)/2, -(unitPartGeo.boundingBox.min.z+unitPartGeo.boundingBox.max.z)/2)); - var unitScale = 1/(unitPartGeo.boundingBox.max.x-unitPartGeo.boundingBox.min.x); + var unitScale = 1/(1.2699999809265137); unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); }); - function DMAGIKPart(type, parent, rotated){ + function DMAGIKPart(type, parent){ DMAPart.call(this, type, parent); } DMAGIKPart.prototype = Object.create(DMAPart.prototype); @@ -258,16 +258,68 @@ var partMaterial = new THREE.MeshLambertMaterial({ color:0xffffff, shading: THRE unitPartGeo.computeBoundingBox(); unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+unitPartGeo.boundingBox.max.x)/2, -(unitPartGeo.boundingBox.min.y+unitPartGeo.boundingBox.max.y)/2, -(unitPartGeo.boundingBox.min.z+unitPartGeo.boundingBox.max.z)/2)); - var unitScale = 1/(unitPartGeo.boundingBox.max.x-unitPartGeo.boundingBox.min.x); + var unitScale = 1/(1.2699999809265137); unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); }); - function DMAGIKPartLowPoly(type, parent, rotated){ - DMAGIKPart.call(this, type, parent, rotated); + function DMAGIKPartLowPoly(type, parent){ + DMAGIKPart.call(this, type, parent); } DMAGIKPartLowPoly.prototype = Object.create(DMAGIKPart.prototype); self.DMAGIKPartLowPoly = DMAGIKPartLowPoly; +})(); + +(function () { + + var unitPartGeo; + + //import part geometry + var loader = new THREE.STLLoader(); + loader.load("assets/stls/parts/GIKEndPart.stl", function(geometry){ + + unitPartGeo = geometry; + unitPartGeo.computeBoundingBox(); + unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+unitPartGeo.boundingBox.max.x)/2, + -(unitPartGeo.boundingBox.min.y+unitPartGeo.boundingBox.max.y)/2, -(unitPartGeo.boundingBox.min.z+unitPartGeo.boundingBox.max.z)/2)); + var unitScale = 1/(1.2699999809265137); + unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); + unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + }); + + function DMAGIKEndPart(type, parent){ + DMAGIKPart.call(this, type, parent); + } + DMAGIKEndPart.prototype = Object.create(DMAGIKPart.prototype); + + self.DMAGIKEndPart = DMAGIKEndPart; + +})(); + +(function () { + + var unitPartGeo; + + //import part geometry + var loader = new THREE.STLLoader(); + loader.load("assets/stls/parts/GIKEndPartLowPoly.stl", function(geometry){ + + unitPartGeo = geometry; + unitPartGeo.computeBoundingBox(); + unitPartGeo.applyMatrix(new THREE.Matrix4().makeTranslation(-(unitPartGeo.boundingBox.min.x+unitPartGeo.boundingBox.max.x)/2, + -(unitPartGeo.boundingBox.min.y+unitPartGeo.boundingBox.max.y)/2, -(unitPartGeo.boundingBox.min.z+unitPartGeo.boundingBox.max.z)/2)); + var unitScale = 1/(1.2699999809265137); + unitPartGeo.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI/2)); + unitPartGeo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + }); + + function DMAGIKEndPartLowPoly(type, parent){ + DMAGIKPart.call(this, type, parent); + } + DMAGIKEndPartLowPoly.prototype = Object.create(DMAGIKPart.prototype); + + self.DMAGIKEndPartLowPoly = DMAGIKEndPartLowPoly; + })(); \ No newline at end of file diff --git a/js/models/LatticeOther.js b/js/models/LatticeOther.js index b8197b783683fc6415bdb71e30c25a9dab5186b9..0cbc382d1ea957a4c54aca9d2781afde694dfd39 100644 --- a/js/models/LatticeOther.js +++ b/js/models/LatticeOther.js @@ -92,7 +92,7 @@ OtherLatticeSubclasses = { var cells = this.addCellsInRange(range); var superCell = new DMASuperCell(length, range, cells); _.each(cells, function(cell, index){ - cell.setSuperCell(superCell, index, length); + cell.setSuperCell(superCell, index); }); },