Skip to content

Commit c59e951

Browse files
committed
fix: broken app
1 parent 717eebe commit c59e951

1 file changed

Lines changed: 25 additions & 16 deletions

File tree

src/components/Mesh3DScene.svelte

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,34 @@
11
<script lang="ts">
22
import { T } from '@threlte/core';
33
import { OrbitControls } from '@threlte/extras';
4-
import { onMount } from 'svelte';
5-
import type { BufferGeometry, NormalOrGLBufferAttributes } from 'three';
4+
import { BufferAttribute, type BufferGeometry, type NormalOrGLBufferAttributes } from 'three';
65
7-
export let vertices: Float32Array;
8-
export let volume: number;
9-
export let wireframe: boolean;
10-
export let color: string = '#118811';
11-
export let positionOffset: number = 0;
12-
export let opacity: number = 1;
13-
export let flipZ: boolean = false;
6+
interface Properties {
7+
vertices: Float32Array;
8+
volume: number;
9+
wireframe: boolean;
10+
color?: string;
11+
positionOffset?: number;
12+
opacity?: number;
13+
flipZ?: boolean;
14+
}
15+
16+
const {
17+
vertices,
18+
volume,
19+
wireframe,
20+
color = '#118811',
21+
positionOffset = 0,
22+
opacity = 1,
23+
flipZ = false
24+
}: Properties = $props();
1425
1526
const CAMERA_FAR = 2;
1627
17-
let bufferGeometry: BufferGeometry<NormalOrGLBufferAttributes>;
18-
onMount(() => {
19-
if (bufferGeometry) bufferGeometry.computeVertexNormals();
20-
});
28+
const setupGeometry = (geo: BufferGeometry<NormalOrGLBufferAttributes>) => {
29+
geo.setAttribute('position', new BufferAttribute(vertices, 3));
30+
geo.computeVertexNormals();
31+
};
2132
</script>
2233

2334
<T.PerspectiveCamera
@@ -31,8 +42,6 @@
3142
<T.AmbientLight color="white" intensity={1} />
3243

3344
<T.Mesh position.y={positionOffset} rotation.x={-Math.PI / 2} scale.z={flipZ ? -1 : 1}>
34-
<T.BufferGeometry bind:ref={bufferGeometry}>
35-
<T.BufferAttribute args={[vertices, 3]} attach="attributes.position" />
36-
</T.BufferGeometry>
45+
<T.BufferGeometry oncreate={setupGeometry} />
3746
<T.MeshPhongMaterial {color} {opacity} transparent={opacity < 1} {wireframe} />
3847
</T.Mesh>

0 commit comments

Comments
 (0)