Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Aug 25, 2017
2 parents 7e55b95 + d0f3137 commit 24a100f
Show file tree
Hide file tree
Showing 14 changed files with 331 additions and 51 deletions.
80 changes: 80 additions & 0 deletions simpleExample/coming_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import Shape from 'clipper-js';
import comb from '../src/sliceActions/helpers/comb.js';

const canvas = document.createElement('canvas');
document.body.appendChild(canvas);
canvas.width = 720;
canvas.height = 480;
const context = canvas.getContext('2d');

const outline = new Shape([[
{ x: 100, y: 100 },
{ x: 400, y: 100 },
{ x: 400, y: 150 },
{ x: 200, y: 150 },
{ x: 200, y: 200 },
{ x: 400, y: 200 },
{ x: 400, y: 250 },
{ x: 200, y: 250 },
{ x: 200, y: 300 },
{ x: 400, y: 300 },
{ x: 400, y: 400 },
{ x: 100, y: 400 }
], [
{ x: 130, y: 310 },
{ x: 130, y: 370 },
{ x: 360, y: 370 },
{ x: 360, y: 360 },
{ x: 150, y: 360 },
{ x: 150, y: 350 },
{ x: 360, y: 350 },
{ x: 360, y: 340 },
{ x: 150, y: 340 },
{ x: 150, y: 330 },
{ x: 360, y: 330 },
{ x: 360, y: 310 }
]], true, true, false);

const start = { x: 380, y: 120 };
const end = { x: 200, y: 380 };

let combPath = comb(outline, start, end);

canvas.onmousemove = (event) => {
start.x = event.x;
start.y = event.y;

combPath = comb(outline, start, end);
draw();
};

draw();

function draw() {
context.clearRect(0, 0, canvas.width, canvas.height);

context.strokeStyle = 'black';
for (const path of outline.mapToLower()) {
context.beginPath();
for (const point of path) {
context.lineTo(point.x, point.y);
}
context.closePath();
context.stroke();
}

context.strokeStyle = 'red';
context.beginPath();
for (const point of combPath) {
context.lineTo(point.x, point.y);
}
context.stroke();

context.beginPath();
context.arc(start.x, start.y, 3, 0, Math.PI * 2.0, false);
context.stroke();

context.beginPath();
context.arc(end.x, end.y, 3, 0, Math.PI * 2.0, false);
context.stroke();
}
24 changes: 16 additions & 8 deletions simpleExample/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as THREE from 'three';
import { defaultSettings, sliceGeometry } from 'doodle3d-slicer';
import fileURL from '!url-loader!./models/combingtest.json';
import fileSaver from 'file-saver';

const settings = {
...defaultSettings.base,
Expand All @@ -8,14 +10,20 @@ const settings = {
...defaultSettings.quality.high
};

const geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
geometry.mergeVertices();
const jsonLoader = new THREE.JSONLoader();
jsonLoader.load(fileURL, geometry => {
geometry.applyMatrix(new THREE.Matrix4().makeRotationX(Math.PI / -2));
geometry.applyMatrix(new THREE.Matrix4().setPosition(new THREE.Vector3(50, -0.0, 50)));

const onProgress = ({ progress: { done, total, action } }) => {
const percentage = `${(done / total * 100).toFixed()}%`
document.write(`<p>${action}, ${percentage}</p>`);
};
const onProgress = ({ progress: { done, total, action } }) => {
const percentage = `${(done / total * 100).toFixed()}%`
document.write(`<p>${action}, ${percentage}</p>`);
};

sliceGeometry(settings, geometry, null, false, onProgress).then(gcode => {
document.body.innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '<br />');
const { filament, duration, gcode } = sliceGeometry(settings, geometry, null, true, onProgress);
// console.log('filament: ', filament);
// console.log('duration: ', duration);
// document.body.innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '<br />');
const file = new File([gcode], 'gcode.gcode', { type: 'text/plain' });
fileSaver.saveAs(file);
});
1 change: 1 addition & 0 deletions simpleExample/models/Doodle.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"vertices":[47.12482452392578,42.35624313354492,-2.593571992041396e-15,-7.293127536773682,29.7335205078125,-1.820653115308456e-15,-4.207573413848877,-19.915847778320312,1.219494014914264e-15,54.97896194458008,-14.586255073547363,8.931505683412107e-16,53.85694122314453,-42.07573699951172,2.576395944332666e-15,-35.624122619628906,-25.245441436767578,1.5458375198830296e-15,-38.99018096923828,51.6129035949707,-3.1603789970181283e-15,47.12482452392578,61.71107864379883,-3.7787139115382e-15,47.12482452392578,42.35624313354492,19.999999999999996,-7.293127536773682,29.7335205078125,19.999999999999996,-4.207573413848877,-19.915847778320312,20,54.97896194458008,-14.586255073547362,20,53.85694122314453,-42.07573699951172,20.000000000000004,-35.624122619628906,-25.245441436767578,20,-38.99018096923828,51.6129035949707,19.999999999999996,47.12482452392578,61.71107864379883,19.999999999999996],"normals":[0,-6.123234262925839e-17,-1,0,6.123234262925839e-17,1,0.22595957126202507,-0.9741366804278966,5.964867098368936e-17,0.22595959003447755,-0.9741366760734609,5.964867071705706e-17,0.9980744575480833,0.062027229424660574,-3.798072564474434e-18,0.9980744575147102,0.06202722996166134,-3.798072597356249e-18,-0.08968451372047671,0.995970224453885,-6.098559003229967e-17,-0.0896845139633491,0.9959702244320148,-6.098559003096051e-17,0.9991680515439634,-0.04078240765133586,2.4972023585526864e-18,0.9991680513997995,-0.040782411183346925,2.4972025748259983e-18,-0.18484654771165182,-0.9827673955718536,6.017714989051966e-17,-0.1848465343760269,-0.9827673980801217,6.017715004410679e-17,-0.9990423495327988,-0.04375367230285246,2.679139853736555e-18,-0.9990423494957035,-0.04375367314986121,2.6791399056008846e-18,-0.11646581097902166,0.993194701391927,-6.081563825319445e-17,-0.11646581460851489,0.9931947009663187,-6.081563822713346e-17,1,0,0],"faces":[50,7,0,1,0,0,0,0,0,50,2,3,4,0,0,0,0,0,50,6,7,1,0,0,0,0,0,50,2,4,5,0,0,0,0,0,50,5,6,1,0,0,0,0,0,50,1,2,5,0,0,0,0,0,50,13,10,9,0,1,1,1,1,50,9,14,13,0,1,1,1,1,50,13,12,10,0,1,1,1,1,50,9,15,14,0,1,1,1,1,50,12,11,10,0,1,1,1,1,50,9,8,15,0,1,1,1,1,50,0,8,1,0,2,3,3,3,50,8,9,1,0,2,3,3,3,50,1,9,2,0,4,5,5,5,50,9,10,2,0,4,5,5,5,50,2,10,3,0,6,7,7,7,50,10,11,3,0,6,7,7,7,50,3,11,4,0,8,9,9,9,50,11,12,4,0,8,9,9,9,50,4,12,5,0,10,11,11,11,50,12,13,5,0,10,11,11,11,50,5,13,6,0,12,13,13,13,50,13,14,6,0,12,13,13,13,50,6,14,7,0,14,15,15,15,50,14,15,7,0,14,15,15,15,50,7,15,0,0,16,16,16,16,50,15,8,0,0,16,16,16,16]}
1 change: 1 addition & 0 deletions simpleExample/models/combingtest.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions simpleExample/models/error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"vertices":[7.733087062835693,-16.304513931274414,9.983635834433116e-16,8.114167213439941,-15.617469787597656,9.56294261036271e-16,9.221924781799316,-19.25043296813965,1.1787491072666986e-15,10.481419563293457,-24.082372665405273,1.4746200943735824e-15,10.416656494140625,-24.073749542236328,1.4740920803411672e-15,11.006467819213867,-29.265962600708008,1.7920234493416148e-15,11.137995719909668,-30.818424224853516,1.8870843114300675e-15,11.103300094604492,-31.763607025146484,1.9449600685048884e-15,10.899033546447754,-32.431793212890625,1.9858746740929756e-15,9.662759780883789,-32.623329162597656,1.997602868991257e-15,8.328606605529785,-32.92055130004883,2.0158024767486677e-15,6.698436737060547,-32.96634292602539,2.0186064052800154e-15,3.5711848735809326,-32.66859436035156,2.0003745630893053e-15,-0.5375360250473022,-32.12141418457031,1.96686943908593e-15,0.0021668951958417892,-30.785547256469727,1.88507117763738e-15,0.1536201536655426,-28.728025436401367,1.7590842965837789e-15,0.469533234834671,-26.777210235595703,1.639631311801681e-15,1.0006184577941895,-22.86216163635254,1.3999037145626254e-15,1.7190589904785156,-18.598926544189453,1.1388558426902173e-15,2.692584753036499,-17.151229858398438,1.05020998320262e-15,3.9281325340270996,-16.374448776245117,1.0026458578322818e-15,4.4832611083984375,-17.47450828552246,1.070005078616926e-15,4.920013904571533,-18.29590606689453,1.1203011890008133e-15,5.9995808601379395,-18.363353729248047,1.1244311673715863e-15,6.881400108337402,-18.2179012298584,1.1155247700926773e-15,7.659770965576172,-17.04950523376465,1.0439811461332112e-15,7.733087062835693,-16.304513931274414,2.0679547786712655,8.114167213439941,-15.617469787597656,2.0679547786712655,9.221924781799316,-19.25043296813965,2.067954778671266,10.481419563293457,-24.082372665405273,2.067954778671266,10.416656494140625,-24.073749542236328,2.067954778671266,11.006467819213867,-29.265962600708008,2.0679547786712664,11.137995719909668,-30.818424224853516,2.0679547786712664,11.103300094604492,-31.763607025146484,2.0679547786712664,10.899033546447754,-32.431793212890625,2.0679547786712664,9.662759780883789,-32.623329162597656,2.0679547786712664,8.328606605529785,-32.92055130004883,2.067954778671267,6.698436737060547,-32.96634292602539,2.067954778671267,3.5711848735809326,-32.66859436035156,2.067954778671267,-0.5375360250473022,-32.12141418457031,2.0679547786712664,0.0021668951958417892,-30.785547256469727,2.0679547786712664,0.1536201536655426,-28.728025436401367,2.0679547786712664,0.469533234834671,-26.777210235595703,2.0679547786712664,1.0006184577941895,-22.86216163635254,2.067954778671266,1.7190589904785156,-18.598926544189453,2.067954778671266,2.692584753036499,-17.151229858398438,2.0679547786712655,3.9281325340270996,-16.374448776245117,2.0679547786712655,4.4832611083984375,-17.47450828552246,2.0679547786712655,4.920013904571533,-18.29590606689453,2.067954778671266,5.9995808601379395,-18.363353729248047,2.067954778671266,6.881400108337402,-18.2179012298584,2.067954778671266,7.659770965576172,-17.04950523376465,2.0679547786712655],"normals":[0,6.123234262925839e-17,1,0,-6.123234262925839e-17,-1,-0.8744872499850042,0.48504850233112273,-2.9700656086547946e-17,-0.8744872697373354,0.48504846671991564,-2.970065390599031e-17,0.9565217103851972,0.29166113481534883,-1.7859094538651763e-17,0.9565217145882972,0.29166112103100816,-1.7859093694604294e-17,0.9611352403273946,0.27607797775411497,-1.6904901326232744e-17,0.9647576429502183,0.26314005846533406,-1.611268221943242e-17,0.9676667171519953,0.2522322828590353,-1.5444773566184468e-17,0.9676667150226643,0.2522322910280244,-1.5444774066390808e-17,-0.13198396733724552,-0.9912518511286227,6.069667298019446e-17,-0.13198398355663685,-0.9912518489690304,6.069667284795756e-17,0.9936098243924144,0.11286946828472061,-6.911261954392226e-18,0.9936098243236207,0.11286946889032329,-6.911261991474697e-18,0.9940216038685177,0.10918356580850452,-6.68556551107053e-18,0.9947585507557595,0.10225177601538833,-6.2611157834244435e-18,0.996430283577508,0.08441972500338428,-5.169217526074998e-18,0.9984142160483992,0.05629434423155276,-3.4470345740758543e-18,0.9998371719830533,0.01804520769983466,-1.1049503406924077e-18,0.9993269471071408,-0.03668314034433081,2.246194618281236e-18,0.9943285991838128,-0.10635147787011166,6.512150132070669e-18,0.9816481860810309,-0.1907009144283837,1.1677063731991675e-17,0.9563121467608497,-0.29234752941944786,1.790112408822883e-17,0.9563121469388717,-0.29234752883711157,1.7901124052571014e-17,0.15310344537065693,-0.9882101674318243,6.051042356190227e-17,0.15310345955372404,-0.9882101652344409,6.051042342735134e-17,0.1759224823806564,-0.9844040228448012,6.027736441245318e-17,0.19733856278495723,-0.9803353975237085,6.002823295276194e-17,0.21744888460932224,-0.9760717097540333,5.976715736238502e-17,0.14731970051452048,-0.9890889271649502,6.056423207896983e-17,0.08432283862065745,-0.9964384872569679,6.101426286069859e-17,0.02807901895786308,-0.9996057066135448,6.120819912152252e-17,-0.03225911059406078,-0.9994795394522493,6.120047361067351e-17,-0.06954940454839427,-0.9975785083525828,6.108406902302986e-17,-0.09478229507230097,-0.9954980243781638,6.095667611547356e-17,-0.10959848802377353,-0.993975941068446,6.086347538874264e-17,-0.12179657101463538,-0.9925550842593459,6.07764729977807e-17,-0.13200981334392795,-0.9912484094216248,6.069646223641234e-17,-0.13200981651022176,-0.9912484089999527,6.069646221059236e-17,-0.9271892431338771,0.3745932559681612,-2.2937222596051935e-17,-0.9271892407474963,0.3745932618749054,-2.293722295773572e-17,-0.9677600503727625,0.25187394645438865,-1.5422831788678607e-17,-0.9882622406854719,0.1527669585850637,-9.354278750510347e-18,-0.9973017769930169,0.07341093655968955,-4.495123620157662e-18,-0.9948365551357828,0.10149004170641013,-6.214473007224629e-18,-0.9914719233091036,0.13032047149142453,-7.979827761969408e-18,-0.9871402607033498,0.15985651597142633,-9.788388957481893e-18,-0.9891136706972448,0.14715347919713867,-9.010552257286641e-18,-0.9902196495497442,0.13951718763500734,-8.542964235937303e-18,-0.990924295911338,0.1344211284457137,-8.230920593599493e-18,-0.9893334511085832,0.14566853647092337,-8.919625735490202e-18,-0.9877199277487606,0.1562349011200226,-9.56662899602953e-18,-0.9860959533920762,0.16617692590661398,-1.0175402464190673e-17,-0.9720188333927847,0.23490293214374747,-1.438365682564338e-17,-0.9371441160148597,0.34894255375165595,-2.136657000924981e-17,-0.8298227835561691,0.5580270135854458,-3.416930129224585e-17,-0.7556841877751381,0.6549361864690559,-4.0103276970173094e-17,-0.6569182421204328,0.7539618181111033,-4.616684837595767e-17,-0.5322457294674823,0.84658991457708,-5.183868371585836e-17,-0.5322457014352014,0.8465899322007973,-5.183868479499985e-17,0.8927658626737265,0.45052093674371774,-2.7586452360345772e-17,0.8927658557654704,0.45052095043332596,-2.7586453198592553e-17,0.8901146166887495,0.4557367322885451,-2.79058277402308e-17,0.8869056220510353,0.4619506657363599,-2.82863214421828e-17,0.8829440956376842,0.4694781400433378,-2.8747246328080616e-17,0.8829441021763355,0.4694781277461446,-2.874724557509467e-17,0.06235501287541495,0.9980540327904632,-6.111318649833874e-17,0.06235501574262814,0.9980540326113295,-6.111318648736996e-17,-0.0034716462038585747,0.9999939738181604,-6.123197363202725e-17,-0.078351840210522,0.9969257691200609,-6.104410027069651e-17,-0.16274685127953692,0.9866678581967675,-6.0415984354381e-17,-0.16274683015911187,0.9866678616804955,-6.041598456769783e-17,-0.8322342840539375,0.5544241124312956,-3.3948687214315574e-17,-0.8322342985045962,0.5544240907397177,-3.3948685886089434e-17,-0.9951924300530124,0.09793889505798979,-5.997027978921813e-18,-0.9951924298305381,0.09793889731863359,-5.9970281173463275e-18],"faces":[50,1,0,25,0,0,0,0,0,50,21,20,19,0,0,0,0,0,50,19,18,17,0,0,0,0,0,50,16,15,14,0,0,0,0,0,50,14,13,12,0,0,0,0,0,50,12,11,10,0,0,0,0,0,50,9,8,7,0,0,0,0,0,50,7,6,5,0,0,0,0,0,50,4,3,2,0,0,0,0,0,50,2,1,25,0,0,0,0,0,50,22,21,19,0,0,0,0,0,50,19,17,16,0,0,0,0,0,50,16,14,12,0,0,0,0,0,50,12,10,9,0,0,0,0,0,50,9,7,5,0,0,0,0,0,50,5,4,2,0,0,0,0,0,50,2,25,24,0,0,0,0,0,50,22,19,16,0,0,0,0,0,50,16,12,9,0,0,0,0,0,50,9,5,2,0,0,0,0,0,50,2,24,23,0,0,0,0,0,50,23,22,16,0,0,0,0,0,50,16,9,2,0,0,0,0,0,50,2,23,16,0,0,0,0,0,50,42,49,28,0,1,1,1,1,50,28,35,42,0,1,1,1,1,50,42,48,49,0,1,1,1,1,50,49,50,28,0,1,1,1,1,50,28,31,35,0,1,1,1,1,50,35,38,42,0,1,1,1,1,50,42,45,48,0,1,1,1,1,50,50,51,28,0,1,1,1,1,50,28,30,31,0,1,1,1,1,50,31,33,35,0,1,1,1,1,50,35,36,38,0,1,1,1,1,50,38,40,42,0,1,1,1,1,50,42,43,45,0,1,1,1,1,50,45,47,48,0,1,1,1,1,50,51,27,28,0,1,1,1,1,50,28,29,30,0,1,1,1,1,50,31,32,33,0,1,1,1,1,50,33,34,35,0,1,1,1,1,50,36,37,38,0,1,1,1,1,50,38,39,40,0,1,1,1,1,50,40,41,42,0,1,1,1,1,50,43,44,45,0,1,1,1,1,50,45,46,47,0,1,1,1,1,50,51,26,27,0,1,1,1,1,50,0,26,1,0,2,3,3,3,50,26,27,1,0,2,3,3,3,50,1,27,2,0,4,5,5,6,50,27,28,2,0,4,5,7,6,50,2,28,3,0,8,6,7,9,50,28,29,3,0,8,7,9,9,50,3,29,4,0,10,11,11,11,50,29,30,4,0,10,11,11,11,50,4,30,5,0,12,13,13,14,50,30,31,5,0,12,13,15,14,50,5,31,6,0,16,14,15,17,50,31,32,6,0,16,15,18,17,50,6,32,7,0,19,17,18,20,50,32,33,7,0,19,18,21,20,50,7,33,8,0,22,20,21,23,50,33,34,8,0,22,21,23,23,50,8,34,9,0,24,25,25,26,50,34,35,9,0,24,25,27,26,50,9,35,10,0,28,26,27,29,50,35,36,10,0,28,27,30,29,50,10,36,11,0,31,29,30,32,50,36,37,11,0,31,30,33,32,50,11,37,12,0,34,32,33,35,50,37,38,12,0,34,33,36,35,50,12,38,13,0,37,35,36,38,50,38,39,13,0,37,36,38,38,50,13,39,14,0,39,40,40,41,50,39,40,14,0,39,40,42,41,50,14,40,15,0,43,41,42,44,50,40,41,15,0,43,42,45,44,50,15,41,16,0,46,44,45,47,50,41,42,16,0,46,45,48,47,50,16,42,17,0,49,47,48,50,50,42,43,17,0,49,48,51,50,50,17,43,18,0,52,50,51,53,50,43,44,18,0,52,51,54,53,50,18,44,19,0,55,53,54,56,50,44,45,19,0,55,54,57,56,50,19,45,20,0,58,56,57,59,50,45,46,20,0,58,57,59,59,50,20,46,21,0,60,61,61,62,50,46,47,21,0,60,61,63,62,50,21,47,22,0,64,62,63,65,50,47,48,22,0,64,63,65,65,50,22,48,23,0,66,67,67,68,50,48,49,23,0,66,67,69,68,50,23,49,24,0,70,68,69,71,50,49,50,24,0,70,69,71,71,50,24,50,25,0,72,73,73,73,50,50,51,25,0,72,73,73,73,50,25,51,0,0,74,75,75,75,50,51,26,0,0,74,75,75,75]}
1 change: 1 addition & 0 deletions simpleExample/models/shape.json

Large diffs are not rendered by default.

27 changes: 18 additions & 9 deletions simpleExample/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion simpleExample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"license": "ISC",
"dependencies": {
"babel-polyfill": "^6.23.0",
"three": "^0.83.0"
"file-saver": "^1.3.3",
"three": "^0.83.0",
"url-loader": "^0.5.9"
},
"devDependencies": {
"babel-core": "^6.25.0",
Expand Down
1 change: 1 addition & 0 deletions src/settings/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ filamentThickness: 2.85
temperature: 210
bedTemperature: 70
layerHeight: 0.15
combing: true
thickness:
top: 1.2
bottom: 1.2
Expand Down
Loading

0 comments on commit 24a100f

Please sign in to comment.