mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 03:23:48 +01:00
added algorithm to remove unnecessary polygons in shape
This commit is contained in:
parent
c4c32234ae
commit
498708e4e4
@ -17,7 +17,7 @@ var mesh = new THREE.Mesh(geometry, material);
|
||||
doodleBox.onload = function () {
|
||||
"use strict";
|
||||
|
||||
var slicer = new D3D.Slicer().setGeometry(mesh);
|
||||
var slicer = new D3D.Slicer().setMesh(mesh);
|
||||
var gcode = slicer.getGcode(doodleBox.printer);
|
||||
|
||||
doodleBox.print(gcode);
|
||||
|
45
build/d3d.js
vendored
45
build/d3d.js
vendored
@ -90,7 +90,7 @@ Array.prototype.clone = function () {
|
||||
return array;
|
||||
};
|
||||
|
||||
function applyMouseControls (renderer, camera, maxDistance) {
|
||||
function applyMouseControls (renderer, camera, center, maxDistance) {
|
||||
"use strict";
|
||||
//TODO
|
||||
//impliment touch controls
|
||||
@ -102,10 +102,12 @@ function applyMouseControls (renderer, camera, maxDistance) {
|
||||
var moveCamera = false;
|
||||
|
||||
function updateCamera () {
|
||||
camera.position.x = Math.cos(rotY)*Math.sin(rotX)*distance;
|
||||
camera.position.y = Math.sin(rotY)*distance;
|
||||
camera.position.z = Math.cos(rotY)*Math.cos(rotX)*distance;
|
||||
camera.lookAt(new THREE.Vector3(0, 0, 0));
|
||||
camera.position.set(
|
||||
Math.cos(rotY)*Math.sin(rotX)*distance,
|
||||
Math.sin(rotY)*distance,
|
||||
Math.cos(rotY)*Math.cos(rotX)*distance
|
||||
).add(center);
|
||||
camera.lookAt(center);
|
||||
}
|
||||
|
||||
$(renderer.domElement).on("mousedown", function (e) {
|
||||
@ -632,9 +634,11 @@ D3D.Slicer = function () {
|
||||
|
||||
this.lines = [];
|
||||
};
|
||||
D3D.Slicer.prototype.setGeometry = function (mesh) {
|
||||
D3D.Slicer.prototype.setMesh = function (mesh) {
|
||||
"use strict";
|
||||
|
||||
mesh.updateMatrix();
|
||||
|
||||
var geometry = mesh.geometry.clone();
|
||||
geometry.mergeVertices();
|
||||
geometry.applyMatrix(mesh.matrix);
|
||||
@ -731,8 +735,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
var x = line.start.x * alpha + line.end.x * (1 - alpha);
|
||||
var z = line.start.z * alpha + line.end.z * (1 - alpha);
|
||||
|
||||
//remove +100 when implimenting good stucture for creating geometry is complete
|
||||
intersections[index] = new THREE.Vector2(x + 100, z + 100);
|
||||
intersections[index] = new THREE.Vector2(x, z);
|
||||
}
|
||||
|
||||
var done = [];
|
||||
@ -773,6 +776,28 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (var i = 0; i < shape.length; i ++) {
|
||||
var point = shape[i];
|
||||
var previousPoint = shape[(i + shape.length - 1) % shape.length];
|
||||
var nextPoint = shape[(i + 1) % shape.length];
|
||||
|
||||
var point = new THREE.Vector2(point.X, point.Y);
|
||||
var previousPoint = new THREE.Vector2(previousPoint.X, previousPoint.Y);
|
||||
var nextPoint = new THREE.Vector2(nextPoint.X, nextPoint.Y);
|
||||
//var lineLength = nextPoint.sub(previousPoint).length();
|
||||
|
||||
var normal = nextPoint.sub(previousPoint).normal().normalize();
|
||||
var distance = Math.abs(normal.dot(point.sub(previousPoint)));
|
||||
|
||||
//something better for offset check
|
||||
if (distance <= 0.01) {
|
||||
shape.splice(i, 1);
|
||||
i --;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//think this check is not nescesary, always higher as 0
|
||||
if (shape.length > 0) {
|
||||
slice.push(shape);
|
||||
@ -1093,8 +1118,8 @@ D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
|
||||
var slice = data[layer % data.length];
|
||||
|
||||
drawLines(slice.outerLayer, "red");
|
||||
//drawLines(slice.innerLayer, "green");
|
||||
//drawLines(slice.fill, "blue");
|
||||
drawLines(slice.innerLayer, "green");
|
||||
drawLines(slice.fill, "blue");
|
||||
|
||||
drawVertexes(slice.outerLayer, "green");
|
||||
}
|
||||
|
2
build/d3d.min.js
vendored
2
build/d3d.min.js
vendored
File diff suppressed because one or more lines are too long
@ -35,7 +35,7 @@ var printerConfig = {
|
||||
"printer.dimensions.x": 200,
|
||||
"printer.dimensions.y": 200,
|
||||
"printer.dimensions.z": 200,
|
||||
"printer.enableTraveling": true, //wat is dit?
|
||||
"printer.enableTraveling": true, //wat is dit?
|
||||
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)",
|
||||
"printer.filamentThickness": 2.89,
|
||||
"printer.firstLayerSlow": true,
|
||||
@ -43,7 +43,7 @@ var printerConfig = {
|
||||
"printer.heatup.bed.temperature": 70,
|
||||
"printer.heatup.enabled": true,
|
||||
"printer.heatup.temperature": 180,
|
||||
"printer.layerHeight": 0.2,
|
||||
"printer.layerHeight": 0.3,
|
||||
"printer.retraction.amount": 3,
|
||||
"printer.retraction.enabled": true,
|
||||
"printer.retraction.minDistance": 5,
|
||||
@ -65,8 +65,8 @@ var printerConfig = {
|
||||
};
|
||||
var printer = new D3D.Printer(printerConfig);
|
||||
|
||||
//var localIp = location.hash.substring(1);
|
||||
//var doodleBox = new D3D.Box(localIp);
|
||||
var localIp = location.hash.substring(1);
|
||||
var doodleBox = new D3D.Box(localIp);
|
||||
//var printer = doodleBox.printer;
|
||||
|
||||
var scene = new THREE.Scene();
|
||||
@ -76,16 +76,16 @@ renderer.setClearColor(0xffffff, 1);
|
||||
|
||||
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
||||
|
||||
applyMouseControls(renderer, camera, 1000);
|
||||
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
||||
|
||||
var geometry = (function () {
|
||||
"use strict";
|
||||
|
||||
var circle = new THREE.Shape();
|
||||
circle.absarc(0, 0, 10, 0, Math.PI*2, false);
|
||||
circle.absarc(0, 0, 100, 0, Math.PI*2, false);
|
||||
|
||||
var hole = new THREE.Path();
|
||||
hole.absarc(0, 0, 5, 0, Math.PI*2, true );
|
||||
hole.absarc(0, 0, 15, 0, Math.PI*2, true );
|
||||
|
||||
circle.holes.push(hole);
|
||||
|
||||
@ -103,16 +103,18 @@ var geometry = (function () {
|
||||
})();
|
||||
|
||||
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
|
||||
var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||
//var geometry = new THREE.BoxGeometry(20, 5, 20, 1, 1, 1);
|
||||
var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||
var geometry = new THREE.BoxGeometry(20, 20, 20, 1, 1, 1);
|
||||
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||
var mesh = new THREE.Mesh(geometry, material);
|
||||
mesh.position.x = 100;
|
||||
mesh.position.z = 100;
|
||||
scene.add(mesh);
|
||||
|
||||
var canvas = document.getElementById("canvas");
|
||||
var context = canvas.getContext("2d");
|
||||
|
||||
var slicer = new D3D.Slicer().setGeometry(mesh);
|
||||
var slicer = new D3D.Slicer().setMesh(mesh);
|
||||
|
||||
gcode = slicer.getGcode(printer);
|
||||
|
||||
@ -139,7 +141,7 @@ loader.load('stl/overhang_test.stl', function (geometry) {
|
||||
var canvas = document.getElementById("canvas");
|
||||
var context = canvas.getContext("2d");
|
||||
|
||||
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||
var slicer = new D3D.Slicer().setMesh(geometry);
|
||||
|
||||
var layer = 149;
|
||||
var img = slicer.drawPaths(printer, layer, layer + 1);
|
||||
|
@ -17,9 +17,11 @@ D3D.Slicer = function () {
|
||||
|
||||
this.lines = [];
|
||||
};
|
||||
D3D.Slicer.prototype.setGeometry = function (mesh) {
|
||||
D3D.Slicer.prototype.setMesh = function (mesh) {
|
||||
"use strict";
|
||||
|
||||
mesh.updateMatrix();
|
||||
|
||||
var geometry = mesh.geometry.clone();
|
||||
geometry.mergeVertices();
|
||||
geometry.applyMatrix(mesh.matrix);
|
||||
@ -116,8 +118,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
var x = line.start.x * alpha + line.end.x * (1 - alpha);
|
||||
var z = line.start.z * alpha + line.end.z * (1 - alpha);
|
||||
|
||||
//remove +100 when implimenting good stucture for creating geometry is complete
|
||||
intersections[index] = new THREE.Vector2(x + 100, z + 100);
|
||||
intersections[index] = new THREE.Vector2(x, z);
|
||||
}
|
||||
|
||||
var done = [];
|
||||
@ -158,6 +159,28 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
for (var i = 0; i < shape.length; i ++) {
|
||||
var point = shape[i];
|
||||
var previousPoint = shape[(i + shape.length - 1) % shape.length];
|
||||
var nextPoint = shape[(i + 1) % shape.length];
|
||||
|
||||
var point = new THREE.Vector2(point.X, point.Y);
|
||||
var previousPoint = new THREE.Vector2(previousPoint.X, previousPoint.Y);
|
||||
var nextPoint = new THREE.Vector2(nextPoint.X, nextPoint.Y);
|
||||
//var lineLength = nextPoint.sub(previousPoint).length();
|
||||
|
||||
var normal = nextPoint.sub(previousPoint).normal().normalize();
|
||||
var distance = Math.abs(normal.dot(point.sub(previousPoint)));
|
||||
|
||||
//something better for offset check
|
||||
if (distance <= 0.01) {
|
||||
shape.splice(i, 1);
|
||||
i --;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
//think this check is not nescesary, always higher as 0
|
||||
if (shape.length > 0) {
|
||||
slice.push(shape);
|
||||
@ -478,8 +501,8 @@ D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
|
||||
var slice = data[layer % data.length];
|
||||
|
||||
drawLines(slice.outerLayer, "red");
|
||||
//drawLines(slice.innerLayer, "green");
|
||||
//drawLines(slice.fill, "blue");
|
||||
drawLines(slice.innerLayer, "green");
|
||||
drawLines(slice.fill, "blue");
|
||||
|
||||
drawVertexes(slice.outerLayer, "green");
|
||||
}
|
||||
|
12
src/utils.js
12
src/utils.js
@ -90,7 +90,7 @@ Array.prototype.clone = function () {
|
||||
return array;
|
||||
};
|
||||
|
||||
function applyMouseControls (renderer, camera, maxDistance) {
|
||||
function applyMouseControls (renderer, camera, center, maxDistance) {
|
||||
"use strict";
|
||||
//TODO
|
||||
//impliment touch controls
|
||||
@ -102,10 +102,12 @@ function applyMouseControls (renderer, camera, maxDistance) {
|
||||
var moveCamera = false;
|
||||
|
||||
function updateCamera () {
|
||||
camera.position.x = Math.cos(rotY)*Math.sin(rotX)*distance;
|
||||
camera.position.y = Math.sin(rotY)*distance;
|
||||
camera.position.z = Math.cos(rotY)*Math.cos(rotX)*distance;
|
||||
camera.lookAt(new THREE.Vector3(0, 0, 0));
|
||||
camera.position.set(
|
||||
Math.cos(rotY)*Math.sin(rotX)*distance,
|
||||
Math.sin(rotY)*distance,
|
||||
Math.cos(rotY)*Math.cos(rotX)*distance
|
||||
).add(center);
|
||||
camera.lookAt(center);
|
||||
}
|
||||
|
||||
$(renderer.domElement).on("mousedown", function (e) {
|
||||
|
Loading…
Reference in New Issue
Block a user