feat: stuff

This commit is contained in:
2024-03-24 19:20:44 +01:00
parent 61d3b15c73
commit e6e0f1bc1d
4 changed files with 41 additions and 80 deletions

View File

@@ -1,38 +1,18 @@
# create-svelte
# Bampy
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).
[Discord](https://discord.gg/v6qBb76zkK), any help is welcome.
## Creating a project
A work-in-progress slicer universal non-planar slicing, currently in proof-of-concept state.
If you're seeing this, you've probably already done this step. Congrats!
The slicer was written from scratch, using Rust and WASM to run in the browser.
```bash
# create a new project in the current directory
npm create svelte@latest
## Explanation
# create a new project in my-app
npm create svelte@latest my-app
```
Non-planar slicing is nothing new, however so far what you see everywhere are either just hardware projects or hand-crafted gcode.
Full Control was an interesting step, but ultimately not something everyone can use.
Same with bending gcode, conical slicing - they require tons of manual work and pre-thinking and an object designed for it.
## Developing
The challenge with a non-planar slicer is that the toolhead would bump into already printed objects while printing the non-planar surfaces.
In this first step I managed to create a slicer that finds toolpaths that work around this issue.
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
```bash
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
```
## Building
To create a production version of your app:
```bash
npm run build
```
You can preview the production build with `npm run preview`.
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
The next step is getting the slicer to a point where it can output gcode following the prepared toolpaths and adding infill, as well as fixing the bugs that would cause the toolhead to print paths under existing layers (you can see it at the front of the ship).

View File

@@ -80,7 +80,12 @@ pub fn slice(
slicable_triangles.push(triangle);
let angle = triangle.normal.angle(&BED_NORMAL);
if angle <= max_angle || relative_eq!(angle, max_angle) {
let opposite_angle = std::f64::consts::PI - angle;
if angle <= max_angle
|| relative_eq!(angle, max_angle)
|| opposite_angle <= max_angle
|| relative_eq!(opposite_angle, max_angle)
{
surface_triangles.push(triangle);
}
}
@@ -97,7 +102,7 @@ pub fn slice(
console_log!("Creating Slices");
let mut slices = create_slices(&slicer_options, &slicable);
console_log!("Tracing Surfaces");
/*console_log!("Tracing Surfaces");
let a = max_angle.tan();
for slice in &mut slices {
for surface in &surfaces {
@@ -105,7 +110,7 @@ pub fn slice(
trace_surface(slice, surface, a);
}
}
}
}*/
console_log!("Done");
SliceResult {

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { T, type AsyncWritable } from '@threlte/core';
import { Gizmo, Grid, OrbitControls } from '@threlte/extras';
import { Gizmo, Grid, MeshLineGeometry, MeshLineMaterial, OrbitControls } from '@threlte/extras';
import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
import { useLoader } from '@threlte/core';
import {
@@ -9,7 +9,9 @@
Vector3,
DoubleSide,
Color,
BufferGeometryLoader
BufferGeometryLoader,
TubeGeometry,
CatmullRomCurve3
} from 'three';
import { writable } from 'svelte/store';
import { onDestroy, onMount } from 'svelte';
@@ -34,12 +36,19 @@
break;
}
case 'layer': {
const layer = event.data.data;
layers.update((layers) => {
layers.push({
type: layer.type,
geometry: geometryLoader.parse(layer.geometry)
});
const layer = event.data.data;
if (layer.type === 'ring') {
const curve = new CatmullRomCurve3(
Array.from({ length: layer.position.length / 3 }, (_, i) =>
new Vector3().fromArray(layer.position, i * 3)
)
);
const geometry = new TubeGeometry(curve, undefined, 0.1);
layers.push(geometry);
} else if (layer.type === 'surface') {
}
return layers;
});
break;
@@ -98,19 +107,13 @@
gridSize={[buildSurface[0], buildSurface[1]]}
/>
{#each $layers as { geometry, type }, i}
{#each $layers as geometry, i}
{@const visible = maxZ !== 0 ? i === maxZ : showSlices >= i / $layers.length}
{@const color = new Color(Math.random() * 0xffffff)}
<!---{@const color = new Color(0, i / $layers.length, 0.2)}-->
{#if type === LayerType.Line}
<T.Line {geometry} {visible}>
<T.LineBasicMaterial {color} />
</T.Line>
{:else if type === LayerType.Surface}
<T.Mesh {geometry} {visible}>
<T.MeshMatcapMaterial {color} side={DoubleSide} />
</T.Mesh>
{/if}
<T.Mesh {geometry} {visible}>
<T.MeshMatcapMaterial {color} side={DoubleSide} />
</T.Mesh>
{/each}
{#if $stl}

View File

@@ -21,37 +21,10 @@ addEventListener('message', async (event: MessageEvent<WorkerEvent>) => {
maxAngle: event.data.data.maxNonPlanarAngle
});
for (const layer of result.slices) {
const geometry = new BufferGeometry();
geometry.setAttribute('position', new Float32BufferAttribute(layer.position, 3));
if (layer.type === 'surface') {
geometry.computeVertexNormals();
}
self.postMessage({
type: 'layer',
data: {
type: layer.type === 'ring' ? LayerType.Line : LayerType.Surface,
geometry: geometry.toJSON()
}
} satisfies LayerMessage);
data: layer
});
}
}
});
async function todo({
stl,
bedNormal: bedNormalArray,
maxNonPlanarAngle,
tolerance,
layerHeight
}: SliceArguments) {
greet();
self.postMessage({ type: 'progress', percent: 0, layer: 0 } satisfies ProgressMessage);
// TODO
self.postMessage({
type: 'progress',
layer: Math.round(geometry.boundingBox!.max.z / layerHeight)
} satisfies ProgressMessage);
}