performance improvements

This commit is contained in:
2024-03-04 21:46:19 +01:00
parent 369df93204
commit 830fa22bee
3 changed files with 8 additions and 7 deletions

View File

@@ -14,7 +14,7 @@
</Canvas> </Canvas>
<div class="controls"> <div class="controls">
<input type="range" min="0" max="1" step="0.01" bind:value={showSlices} orient="vertical" /> <input type="range" min="0" max="1" step="0.001" bind:value={showSlices} orient="vertical" />
</div> </div>
{#if $progress !== undefined} {#if $progress !== undefined}
@@ -28,6 +28,7 @@
<style lang="scss"> <style lang="scss">
input[type='range'] { input[type='range'] {
height: 80%;
} }
.controls { .controls {

View File

@@ -10,7 +10,8 @@
Mesh, Mesh,
DoubleSide, DoubleSide,
Color, Color,
BufferGeometryLoader BufferGeometryLoader,
ConeGeometry
} from 'three'; } from 'three';
import { writable } from 'svelte/store'; import { writable } from 'svelte/store';
import { onDestroy, onMount } from 'svelte'; import { onDestroy, onMount } from 'svelte';
@@ -63,7 +64,6 @@
export let maxNonPlanarAngle = MathUtils.degToRad(20); export let maxNonPlanarAngle = MathUtils.degToRad(20);
export let bedNormal = new Vector3(0, 0, 1); export let bedNormal = new Vector3(0, 0, 1);
let mesh: Mesh;
let layers = writable<Layer[]>([]); let layers = writable<Layer[]>([]);
const stl: AsyncWritable<BufferGeometry> = useLoader(STLLoader).load('/benchy.stl'); const stl: AsyncWritable<BufferGeometry> = useLoader(STLLoader).load('/benchy.stl');
@@ -113,8 +113,8 @@
{/if} {/if}
{/each} {/each}
{#if $stl && false} {#if $stl}
<T.Mesh geometry={$stl} bind:ref={mesh}> <T.Mesh geometry={$stl} position.y={40}>
<T.MeshNormalMaterial /> <T.MeshNormalMaterial />
</T.Mesh> </T.Mesh>
{/if} {/if}

View File

@@ -153,14 +153,14 @@ function slice({
const positions: number[] = []; const positions: number[] = [];
for (let i = 0; i < nonPlanarSurfaces.length; i++) { for (let i = 0; i < nonPlanarSurfaces.length; i++) {
if (consumedNonPlanarSurfaces[i]) continue; if (consumedNonPlanarSurfaces[i]) continue;
if (nonPlanarSurfaces[i].geometry.boundingBox!.min.z > layer) { if (layer >= nonPlanarSurfaces[i].geometry.boundingBox!.min.z) {
consumedNonPlanarSurfaces[i] = true; consumedNonPlanarSurfaces[i] = true;
activeNonPlanarSurfaces.push([i, nonPlanarSurfaces[i]]); activeNonPlanarSurfaces.push([i, nonPlanarSurfaces[i]]);
} }
} }
deactivate: for (let i = 0; i < activeNonPlanarSurfaces.length; i++) { deactivate: for (let i = 0; i < activeNonPlanarSurfaces.length; i++) {
const [index, surface] = activeNonPlanarSurfaces[i]; const [index, surface] = activeNonPlanarSurfaces[i];
if (surface.geometry.boundingBox!.max.z <= layer) { if (layer > surface.geometry.boundingBox!.max.z) {
activeNonPlanarSurfaces.splice(i, 1); activeNonPlanarSurfaces.splice(i, 1);
i--; i--;