diff --git a/assets/stls/oneBitBot/foot1.stl b/assets/stls/oneBitBot/foot1.stl index b2e6d8be1b76eb4c90539b5910386ef94f64e8fe..731a86298bc1f00e8a1c8a82f51486da966b67ab 100644 Binary files a/assets/stls/oneBitBot/foot1.stl and b/assets/stls/oneBitBot/foot1.stl differ diff --git a/assets/stls/oneBitBot/foot2.stl b/assets/stls/oneBitBot/foot2.stl index 285a9abe693f23e995815ce6ed88c4da69919708..ebf4febc7c243a973ff5a6465da0ac547e3185ef 100644 Binary files a/assets/stls/oneBitBot/foot2.stl and b/assets/stls/oneBitBot/foot2.stl differ diff --git a/js/menus/ImportMenuView.js b/js/menus/ImportMenuView.js index 27c3bc4cfce67e6168819b9b51b01c6b0f012990..2bd8cf0280ad04833c353c95236668bd9b84fcaa 100644 --- a/js/menus/ImportMenuView.js +++ b/js/menus/ImportMenuView.js @@ -73,7 +73,7 @@ ImportMenuView = Backbone.View.extend({ _fillGeo: function(e){ e.preventDefault(); - + this.fillGeometry.fillGeo(); }, _removeMesh: function(e){ @@ -122,7 +122,7 @@ ImportMenuView = Backbone.View.extend({ Filename: <%= filename %><br/><br/>\ <% if (mesh){ %>\ Scale:<br/><br/>\ - <a href="#" id="doFllGeo" class=" btn btn-block btn-lg btn-default">Fill Mesh</a><br/>\ + <a href="#" id="doFillGeo" class=" btn btn-block btn-lg btn-default">Fill Mesh</a><br/>\ <a href="#" id="removeFillGeo" class=" btn btn-block btn-lg btn-default">Remove Mesh</a><br/>\ <hr>\ <% } %>\ @@ -136,7 +136,7 @@ ImportMenuView = Backbone.View.extend({ <li><a class="selectMesh" data-file="meshes-airbus/wingCrossection.stl" href="#">Wing</a></li>\ </ul>\ </div><!-- /btn-group -->\ - <br/><br/> todo: fill geometry - move/rotate/scale mesh') + ') }); diff --git a/js/models/FillGeometry.js b/js/models/FillGeometry.js index 41a39b33cbd033949b3611d42c5094b1c81b4a55..f6f7868a561d005474721feaccd69756849cd82e 100644 --- a/js/models/FillGeometry.js +++ b/js/models/FillGeometry.js @@ -39,13 +39,75 @@ FillGeometry = Backbone.Model.extend({ 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); dmaGlobals.three.sceneAdd(box); }, - updateBoundingBox: function(){ -// this.get("boundingBoxHelper").update(); -// this.trigger("change:boundingBoxHelper"); + fillGeo: function(){ + var boundingBox = this.get("boundingBox"); + boundingBox.geometry.computeBoundingBox(); + var bounds = boundingBox.geometry.boundingBox; + + var scale = dmaGlobals.lattice.get("scale"); + + var minIndex = dmaGlobals.lattice.getIndexForPosition(bounds.min); + var maxIndex = dmaGlobals.lattice.getIndexForPosition(bounds.max); + 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+10;//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 = dmaGlobals.lattice.getPositionForIndex({x:x, y:y, z:minIndex.z}); + origin.z = bounds.min.z-1; + raycaster.set(origin, direction); + var intersections = raycaster.intersectObject(mesh); + if (intersections.length == 0) continue; + var inside = false; + 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 position = dmaGlobals.lattice.getPositionForIndex(index); + if (!inside){ + if (position.z<nextIntersection) continue; + else { + inside = true; + dmaGlobals.lattice.addCellAtIndex(index, true); + var next = this._getNextIntersection(position, intersections, nextIntersectionIndex, inside); + if (!next) break; + inside = next.inside; + nextIntersection = next.nextIntersection; + nextIntersectionIndex = next.nextIntersetcionIndex; + } + } else { + if (position.z<nextIntersection) dmaGlobals.lattice.addCellAtIndex(index, true); + else { + inside = false; + var next = this._getNextIntersection(position, intersections, nextIntersectionIndex, inside); + if (!next) break; + inside = next.inside; + nextIntersection = next.nextIntersection; + nextIntersectionIndex = next.nextIntersetcionIndex; + } + } + } + } + } + dmaGlobals.three.render(); + }, + + _getNextIntersection: function(position, intersections, nextIntersectionIndex, inside){ + nextIntersectionIndex += 1; + 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}; + } + else return null; }, subtractGeo: function(){ diff --git a/js/models/Lattice.js b/js/models/Lattice.js index 4e83df232bba1da6a0c96e0c16d2b845e2d269b3..eeee34e4302f18e41d68153a4ab23913921a0fee 100644 --- a/js/models/Lattice.js +++ b/js/models/Lattice.js @@ -71,7 +71,7 @@ Lattice = Backbone.Model.extend({ dmaGlobals.three.render(); }, - addCellAtIndex: function(indices){ + addCellAtIndex: function(indices, dontRender){ var scale = this.get("scale"); var cells = this.get("cells"); @@ -81,7 +81,7 @@ Lattice = Backbone.Model.extend({ if (!cells[index.x][index.y][index.z]) { cells[index.x][index.y][index.z] = this.makeCellForLatticeType(indices, scale); this.set("numCells", this.get("numCells")+1); - dmaGlobals.three.render(); + if (!dontRender) dmaGlobals.three.render(); } else console.warn("already a cell there"); },