diff --git a/assets/stls/crab/crab.stl b/assets/stls/crab/crab.stl new file mode 100644 index 0000000000000000000000000000000000000000..73e680a7351ead9002cd235c2c32207e720ad905 Binary files /dev/null and b/assets/stls/crab/crab.stl differ diff --git a/js/cam/assemblers/Crab.js b/js/cam/assemblers/Crab.js new file mode 100644 index 0000000000000000000000000000000000000000..ee3b92b8f37699afe57d9f59da726624fc5a02b9 --- /dev/null +++ b/js/cam/assemblers/Crab.js @@ -0,0 +1,23 @@ +/** + * Created by aghassaei on 6/23/15. + */ + + +define(['stlLoader', 'bin!crabSTL', 'threeModel'], function(THREE, geometry, three){ + + + var loader = new THREE.STLLoader(); + var unitGeo = preProcessGeo(loader.parse(geometry)); + + function preProcessGeo(geo){ + var unitScale = 1/4; + geo.applyMatrix(new THREE.Matrix4().makeScale(unitScale, unitScale, unitScale)); + geo.applyMatrix(new THREE.Matrix4().makeTranslation(0.6, 0.7, 0.5)); + return geo; + } + + var mesh = new THREE.Mesh(unitGeo, new THREE.MeshLambertMaterial({color:0x777777, shading:THREE.FlatShading})); + three.sceneAdd(mesh); + three.render(); + +}); \ No newline at end of file diff --git a/js/lattice/LatticeBase.js b/js/lattice/LatticeBase.js index 306735f33ab852182af61e1d3ac9260ca2dc7f0f..74c430f3570c9b4fe3ae5224ee416fdd4506351d 100644 --- a/js/lattice/LatticeBase.js +++ b/js/lattice/LatticeBase.js @@ -100,6 +100,7 @@ define(['underscore', 'backbone', 'appState', 'globals', 'plist', 'three', 'thre }, addCellsInRange: function(range){//add a block of cells (extrude) + this.checkForMatrixExpansion(this.sparseCells, range.max, range.min); var cellsMin = this.get("cellsMin"); diff --git a/js/main.js b/js/main.js index 422badae08548dc992adb60dbe922c7f32c25c3d..08418e1fabf98c5257e5f113dbf1afbff4543f1d 100644 --- a/js/main.js +++ b/js/main.js @@ -133,6 +133,9 @@ require.config({ setupCommMenuTemplate: 'menus/templates/SetupCommMenuView.html', discoveryMenuTemplate: 'menus/templates/DiscoveryMenuView.html', + //assemblers + crab: 'cam/assemblers/crab', + //stls octaFaceTrianglePartSTL: '../assets/stls/parts/OctaFaceTrianglePart.stl', octaEdgeVoxPartSTL: '../assets/stls/parts/OctaEdgeVoxPart.stl', @@ -140,7 +143,8 @@ require.config({ gikPartSTL: '../assets/stls/parts/GIKPart.stl', gikEndPartSTL: '../assets/stls/parts/GIKEndPart.stl', gikPartLowPolySTL: '../assets/stls/parts/GIKPartLowPoly.stl', - gikEndPartLowPolySTL: '../assets/stls/parts/GIKEndPartLowPoly.stl' + gikEndPartLowPolySTL: '../assets/stls/parts/GIKEndPartLowPoly.stl', + crabSTL: '../assets/stls/crab/crab.stl' }, diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index a9f36a71a508597cc4b6d9f9af0ab427ffc45c9a..08143c9d17e479b9c9904ad0c229f3494b455e47 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -26,6 +26,7 @@ define(['jquery', 'underscore', 'menuParent', 'plist', 'lattice', 'text!importMe getPropertyOwner: function($target){ if ($target.hasClass("fillGeometry")) return this.fillGeometry; + return null; }, _uploadSTL: function(e){//select a mesh to upload diff --git a/js/menus/MenuWrapperView.js b/js/menus/MenuWrapperView.js index 201e4f0c4b95519a30d58ea97d9c63fa20904d6c..b3ef87f20c2dacc52ffa15d1ddb243281f6e83ff 100644 --- a/js/menus/MenuWrapperView.js +++ b/js/menus/MenuWrapperView.js @@ -13,8 +13,8 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'text!menuWrappe "click .menuWrapperTab>a": "_tabWasSelected", "click .dropdownSelector": "_makeDropdownSelection", "click .clearCells": "_clearCells", - "focusout .floatInput": "_renderTab",//force rounding if needed - "focusout .intInput": "_renderTab", + "focusout .floatInput": "_softRenderTab",//force rounding if needed + "focusout .intInput": "_softRenderTab", "change input:checkbox": "_clickCheckbox", "click input:radio": "_radioSelection" }, @@ -40,7 +40,7 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'text!menuWrappe if ($(".unresponsiveInput").is(":focus")) return; if ($("input").is(":focus") && e.keyCode == 13) {//enter key $(e.target).blur(); - this._renderTab(); + this._softRenderTab(); return; } @@ -215,6 +215,11 @@ define(['jquery', 'underscore', 'plist', 'backbone', 'lattice', 'text!menuWrappe this._renderTab(tabName); }, + _softRenderTab: function(){ + if (this.menu) this.menu.render(); + else console.warn("no menu found"); + }, + _renderTab: function(tabName){ if (!tabName || !_.isString(tabName)) tabName = this.model.get("currentTab"); diff --git a/js/models/PList.js b/js/models/PList.js index 6c37bdc3841c1e4a8c7a0f2da6c3198f21e7fdd2..9259fb3293a06c4e0175063072af16820962f64f 100644 --- a/js/models/PList.js +++ b/js/models/PList.js @@ -99,7 +99,8 @@ define(['three'], function(THREE){ allMaterialClasses:{ mechanical: "Structural", - electronic: "Electronic" + electronic: "Electronic", + space: "Space Structures" }, allMaterials:{ @@ -155,6 +156,47 @@ define(['three'], function(THREE){ color: "#aaa", altColor: "#8391AC" } + }, + space:{ + fiberGlass: { + name: "Glass Filled Nylon", + color: "#fef1b5", +// opacity: "0.9", + altColor: "#ecf0f1" + }, + carbon: { + name: "Carbon Composite", + color: "#222", + altColor: "#000" + }, + nType: { + name: "Aluminum", + color: "#bcc6cc", + altColor: "#8391AC" + }, + brass:{ + name: "Brass", + color: "#b5a642", + altColor: "#857B64" + }, + nTypePlus: { + name: "Power Storage", + color: "#c6ccbc", + altColor: "#9CC9CB" + }, + pType: { + name: "Logic", + color: "#ccbcc6", + altColor: "#F5447B" + }, + pTypePlus: { + name: "Solar Panel", + color: "#ccc2bc", + altColor: "#F99987" + } + //857B64 + //FDE2D9 + //D77948 } }, diff --git a/js/three/FillGeometry.js b/js/three/FillGeometry.js index 30ce41d0d8137ce7a8c66354ed811eb9e1e4a659..de91c17c4ac2cdf4315841040eb973af963575f1 100644 --- a/js/three/FillGeometry.js +++ b/js/three/FillGeometry.js @@ -28,47 +28,42 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], geometry.applyMatrix(new THREE.Matrix4().makeTranslation(0,0,-geometry.boundingBox.min.z));//set on top of baseplane geometry.computeBoundingBox(); - var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial( - {color:0xf25536, - shading: THREE.FlatShading, - transparent:true, - opacity:0.4, - side:THREE.DoubleSide})); - this.makeBoundingBox(mesh); + var mesh = new THREE.Mesh(geometry, new THREE.MeshLambertMaterial({ + color:0xf25536, + shading: THREE.FlatShading, + transparent:true, + opacity:0.4, + side:THREE.DoubleSide + })); this.set({mesh: mesh}); three.sceneAdd(mesh); three.render(); }, - makeBoundingBox: function(mesh){ - var box = new THREE.BoxHelper(mesh); - box.material.color.setRGB(0,0,0); - box.material.opacity = 0.4; - box.material.transparent = true; - this.set("boundingBox", box); - // three.sceneAdd(box); - }, - fillGeo: function(){ - var boundingBox = this.get("boundingBox"); - boundingBox.geometry.computeBoundingBox(); - var bounds = boundingBox.geometry.boundingBox; + var boundingBox = this.get("mesh").geometry.boundingBox; var scale = this.get("scale"); + var scaledMin = boundingBox.min.clone().multiplyScalar(scale); + var scaledMax = boundingBox.max.clone().multiplyScalar(scale); + console.log(scaledMin); + console.log(scaledMax); - var minIndex = lattice.getIndexForPosition(bounds.min); - var maxIndex = lattice.getIndexForPosition(bounds.max); + var minIndex = lattice.getIndexForPosition(scaledMin); + var maxIndex = lattice.getIndexForPosition(scaledMax); + console.log(minIndex); + console.log(maxIndex); lattice.checkForMatrixExpansion(null, maxIndex, minIndex);//expand cells matrix before var raycaster = new THREE.Raycaster(); var direction = new THREE.Vector3(0,0,1); var mesh = this.get("mesh"); raycaster.near = 0; - raycaster.far = bounds.max-bounds.min+2;//add some padding just in case + raycaster.far = scaledMax.z-scaledMin.z+2;//add some padding just in case for (var x=minIndex.x;x<=maxIndex.x;x++){ for (var y=minIndex.y;y<=maxIndex.y;y++){ - var origin = lattice.getPositionForIndex({x:x, y:y, z:minIndex.z}); - origin.z = bounds.min.z-1;//more padding + var origin = lattice.getPositionForIndex(new THREE.Vector3(x, y, minIndex.z)); + origin.z = scaledMin.z-1;//more padding raycaster.set(origin, direction); var intersections = raycaster.intersectObject(mesh); if (intersections.length == 0) continue; @@ -76,7 +71,7 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], var nextIntersectionIndex = 0; var nextIntersection = intersections[nextIntersectionIndex].distance; for (var z=minIndex.z;z<=maxIndex.z;z++){ - var index = {x:x,y:y,z:z}; + var index = new THREE.Vector3(x, y, z); var position = lattice.getPositionForIndex(index); if (!inside){ if (position.z<nextIntersection) continue; @@ -95,7 +90,7 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], if (!next) break; inside = next.inside; nextIntersection = next.nextIntersection; - nextIntersectionIndex = next.nextIntersetcionIndex; + nextIntersectionIndex = next.nextIntersectionIndex; } } } @@ -107,7 +102,7 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], if (nextIntersectionIndex < intersections.length) { var nextIntersection = intersections[nextIntersectionIndex].distance; if (nextIntersection < position.z) return this._getNextIntersection(position, intersections, nextIntersectionIndex, !inside); - return {nextIntersection:nextIntersection, nextIntersetcionIndex: nextIntersectionIndex, inside:inside}; + return {nextIntersection:nextIntersection, nextIntersectionIndex: nextIntersectionIndex, inside:inside}; } else return null; }, @@ -127,13 +122,9 @@ define(['three', 'underscore', 'backbone', 'lattice', 'threeModel'], }, _changeScale: function(){ - console.log(this.get("scale")); - // var currentScale = this.get("scale"); - // for (var i=0;i<currentScale.length;i++){ - // if (!scale[i]) scale[i] = currentScale[i]; - // } - // this.get("mesh").scale.set(scale[0], scale[1], scale[2]); - // this.set("scale", scale); + var scale = this.get("scale"); + this.get("mesh").scale.set(scale, scale, scale); + three.render(); } }); });