From 67362c4ba8011147d8a862ea42e1ab3bf03ad051 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Mon, 1 Jun 2015 12:06:11 +0200 Subject: [PATCH] fixed importing buffer geometry with bounding bug --- slice_test.html | 3 ++- src/slicer.js | 12 ++---------- src/slicerworker.js | 9 ++++++--- webworker/worker.js | 6 +++++- webworker_test.html | 9 +++++---- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/slice_test.html b/slice_test.html index b02b71a..e985515 100644 --- a/slice_test.html +++ b/slice_test.html @@ -30,7 +30,7 @@ function init () { var scene = createScene(); var localIp = location.hash.substring(1); - doodleBox = new D3D.Box(localIp); + //doodleBox = new D3D.Box(localIp); var printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS["ultimaker"]); @@ -69,6 +69,7 @@ function init () { mesh.rotation.x = -Math.PI/2; mesh.scale.x = mesh.scale.y = mesh.scale.z = 1; + mesh.position.y = -9.260265119962973e-17; mesh.position.x = 100; mesh.position.z = 100; diff --git a/src/slicer.js b/src/slicer.js index 3809e28..db89005 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -2,14 +2,6 @@ * * Slicer * -* TODO (optimalisatie) -* sorteer lijnen op laagste hoogte -> stop loop wanneer hij een lijn zonder intersectie heeft gevonden -* verwijder lijnen die ooit interactie gehad hebben, maar nu niet meer -* helft van lijnen toevoegen omdat 4face altijd recht is, en 3face dus te veel data bevat -* -* omliggende lagen -> difference && sum omliggende lijnen -* voor laag 5 = 5 diff (3 && 4 && 6 && 7)) -* ******************************************************/ D3D.Slicer = function () { @@ -137,8 +129,8 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) { //still error in first layer, so remove first layer & last layer //see https://github.com/Doodle3D/Doodle3D-Slicer/issues/1 - for (var layer = 1; layer < layersIntersections.length-1; layer ++) { - //for (var layer = 0; layer < layersIntersections.length; layer ++) { + //for (var layer = 1; layer < layersIntersections.length-1; layer ++) { + for (var layer = 0; layer < layersIntersections.length; layer ++) { var layerIntersections = layersIntersections[layer]; var y = layer * layerHeight; diff --git a/src/slicerworker.js b/src/slicerworker.js index c233a68..5b885f6 100644 --- a/src/slicerworker.js +++ b/src/slicerworker.js @@ -10,7 +10,7 @@ D3D.SlicerWorker = function () { switch (event.data["cmd"]) { case "PROGRESS": var progress = event.data["progress"]; - var procent = (progress.sliceLayer + progress.dataLayer + progress.gcodeLayer) / progress.totalLayers / 3; + var procent = (progress.sliceLayer + progress.dataLayer + progress.gcodeLayer) / (progress.totalLayers * 3 - 5); progressBar.style.width = procent * 100 + "%"; break; @@ -38,7 +38,7 @@ D3D.SlicerWorker.prototype.setMesh = function (mesh) { else { var geometry = mesh.geometry.clone(); } - + var buffers = []; for (var i = 0; i < geometry.attributesKeys.length; i ++) { @@ -50,7 +50,10 @@ D3D.SlicerWorker.prototype.setMesh = function (mesh) { this.worker.postMessage({ "cmd": "SET_MESH", - "geometry": geometry, + "geometry": { + "attributes": geometry.attributes, + "attributesKeys": geometry.attributesKeys + }, "matrix": mesh.matrix.toArray() }, buffers); }; diff --git a/webworker/worker.js b/webworker/worker.js index 5818184..1974d0f 100644 --- a/webworker/worker.js +++ b/webworker/worker.js @@ -23,7 +23,11 @@ self.addEventListener("message", function (event) { switch (event.data["cmd"]) { case "SET_MESH": - + + //hack... + //because boundings loses functions when converting + event.data["geometry"].boundingBox = event.data["geometry"].boundingSphere = null; + var geometry = new THREE.Geometry().fromBufferGeometry(event.data["geometry"]); var matrix = new THREE.Matrix4().fromArray(event.data["matrix"]); diff --git a/webworker_test.html b/webworker_test.html index 9c08303..5dacd3d 100644 --- a/webworker_test.html +++ b/webworker_test.html @@ -31,20 +31,21 @@ function init () { var scene = createScene(); var localIp = location.hash.substring(1); - //doodleBox = new D3D.Box(localIp); + doodleBox = new D3D.Box(localIp); var slicer = new D3D.SlicerWorker(); slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS["ultimaker"]); var loader = new THREE.STLLoader(); - loader.load("models/stanford_bunny_high.stl", function (geometry) { + loader.load("models/dom.stl", function (geometry) { + //var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone(); var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false}); var mesh = new THREE.Mesh(geometry, material); mesh.rotation.x = -Math.PI/2; - mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.5; - mesh.position.y = -9.260265119962973e-17; + mesh.scale.x = mesh.scale.y = mesh.scale.z = 1; + //mesh.position.y = -9.260265119962973e-17; mesh.position.x = 100; mesh.position.z = 100;