added flat shading to models instead of a wireframe

This commit is contained in:
casperlamboo 2015-05-17 23:22:27 +02:00
parent 26f13eb998
commit f38ab10e62
4 changed files with 20 additions and 24 deletions

View File

@ -6596,7 +6596,7 @@
} }
catch (err) catch (err)
{ {
console.warn(err.message); //console.warn(err.message);
} }
}; };
// --------------------------------- // ---------------------------------

View File

@ -56,7 +56,7 @@ var printerConfig = {
"printer.useSubLayers": true, //wat is dit? "printer.useSubLayers": true, //wat is dit?
"printer.wallThickness": 0.4, //nozzle "printer.wallThickness": 0.4, //nozzle
"printer.layerHeight": 0.3, "printer.layerHeight": 0.2,
//variabele toevoegen; //variabele toevoegen;
//-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill) //-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill)
@ -77,18 +77,18 @@ var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-prev
renderer.setClearColor(0xffffff, 1); renderer.setClearColor(0xffffff, 1);
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000); var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
scene.add(camera);
var light = new THREE.AmbientLight(0x404040); var light = new THREE.AmbientLight(0x404040);
scene.add(light ); scene.add(light);
var directionalLight = new THREE.DirectionalLight(0xffffff, 0.5); var directionalLight = new THREE.PointLight(0xffffff, 0.5);
directionalLight.position.set(0, 1, 1); camera.add(directionalLight);
scene.add(directionalLight);
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000); applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
var loader = new THREE.STLLoader(); var loader = new THREE.STLLoader();
loader.load("models/stanford_bunny.stl", function (geometry) { loader.load("models/pikachu.stl", function (geometry) {
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1); //var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(10, 10, 10); //var geometry = new THREE.SphereGeometry(10, 10, 10);
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30); //var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
@ -134,7 +134,7 @@ loader.load("models/stanford_bunny.stl", function (geometry) {
var canvas = document.getElementById("canvas"); var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
var img = slicer.drawPaths(printer, 0, 1); var img = slicer.drawPaths(printer, 5, 6);
context.drawImage(img, 0, 0); context.drawImage(img, 0, 0);
gcode = slicer.getGcode(printer); gcode = slicer.getGcode(printer);

View File

@ -124,6 +124,8 @@ D3D.Slicer.prototype.slice = function (height, step) {
var slices = []; var slices = [];
//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 = 1; layer < layersIntersections.length-1; layer ++) {
//for (var layer = 0; layer < layersIntersections.length; layer ++) { //for (var layer = 0; layer < layersIntersections.length; layer ++) {
var layerIntersections = layersIntersections[layer]; var layerIntersections = layersIntersections[layer];
@ -257,10 +259,10 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var data = []; var data = [];
var lowFillTemplate = this.getFillTemplate({ var lowFillTemplate = this.getFillTemplate({
left: 0, left: this.geometry.boundingBox.min.z * scale,
top: 0, top: this.geometry.boundingBox.min.x * scale,
right: dimensionsZ, right: this.geometry.boundingBox.max.z * scale,
bottom: dimensionsZ bottom: this.geometry.boundingBox.max.x * scale
}, fillSize, true, true); }, fillSize, true, true);
for (var layer = 0; layer < slices.length; layer ++) { for (var layer = 0; layer < slices.length; layer ++) {
@ -283,7 +285,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
upSkin.join(downLayer[i]); upSkin.join(downLayer[i]);
} }
} }
var surroundingLayer = upSkin.intersect(downSkin).clone().scaleUp(scale); var surroundingLayer = upSkin.intersect(downSkin).scaleUp(scale);
var sliceData = []; var sliceData = [];
for (var i = 0; i < slice.length; i ++) { for (var i = 0; i < slice.length; i ++) {
@ -514,22 +516,16 @@ D3D.Slicer.prototype.getGcode = function (printer) {
var start = new Date().getTime(); var start = new Date().getTime();
var slices = this.slice(dimensionsZ, layerHeight); var slices = this.slice(dimensionsZ, layerHeight);
var end = new Date().getTime(); var end = new Date().getTime();
console.log("Slicing: " + (end - start) + "ms"); console.log("Slicing: " + (end - start) + "ms");
//still error in first layer, so remove first layer
//see https://github.com/Doodle3D/Doodle3D-Slicer/issues/1
var start = new Date().getTime(); var start = new Date().getTime();
var data = this.slicesToData(slices, printer); var data = this.slicesToData(slices, printer);
var end = new Date().getTime(); var end = new Date().getTime();
console.log("Data: " + (end - start) + "ms"); console.log("Data: " + (end - start) + "ms");
var start = new Date().getTime(); var start = new Date().getTime();
var gcode = this.dataToGcode(data, printer); var gcode = this.dataToGcode(data, printer);
var end = new Date().getTime(); var end = new Date().getTime();
console.log("Gcode: " + (end - start) + "ms"); console.log("Gcode: " + (end - start) + "ms");
return gcode; return gcode;

View File

@ -71,11 +71,11 @@ function getAPI (url, callback) {
function downloadFile (file, data) { function downloadFile (file, data) {
"use strict"; "use strict";
$(document.createElement("a")).attr({ var button = document.createElement("a");
download: file, button.download = file;
href: "data:text/plain," + data button.href = "data:text/plain," + data;
})[0].click(); button.click();
} }
Array.prototype.clone = function () { Array.prototype.clone = function () {