1
1
<script setup lang="ts">
2
2
import type { Group } from ' three'
3
- import { InstancedMesh , MeshPhongMaterial , Raycaster , Vector3 , Object3D } from ' three'
3
+ import { InstancedMesh , MeshPhongMaterial , Vector3 , Object3D } from ' three'
4
4
import { MeshSurfaceSampler } from ' three/addons/math/MeshSurfaceSampler.js'
5
5
import { useMouse } from ' @vueuse/core'
6
6
7
7
const groupRef = ref <Group >()
8
8
9
- const gltf = await useGLTF (' /models/legolangelo /david.glb' )
9
+ const gltf = await useGLTF (' /models/brickelangelo /david.glb' )
10
10
11
11
const david = gltf .nodes .David
12
12
@@ -17,12 +17,12 @@ watch([x, y], () => {
17
17
groupRef .value .rotation .y = - x .value * 0.0001
18
18
})
19
19
20
- const { nodes : legoNodes } = await useGLTF (' /models/legolangelo/lego .glb' )
20
+ const { nodes : brickNodes } = await useGLTF (' /models/brickelangelo/brick .glb' )
21
21
22
- const lego = legoNodes .LegoPiece
22
+ const brick = brickNodes .LegoPiece
23
23
24
- const legoMaterial = new MeshPhongMaterial ({ color: ' lightgray' })
25
- const legoInstancedMesh = new InstancedMesh (lego .geometry , legoMaterial , instanceCount )
24
+ const brickMaterial = new MeshPhongMaterial ({ color: ' lightgray' })
25
+ const brickInstancedMesh = new InstancedMesh (brick .geometry , brickMaterial , instanceCount )
26
26
27
27
useControls (' fpsgraph' )
28
28
@@ -32,30 +32,30 @@ const sampler = new MeshSurfaceSampler(david)
32
32
33
33
const instanceCount = 75000 // or whatever count you want
34
34
const dummy = new Object3D ()
35
- const legoSize = 0.03 // Define according to the size of your LEGO piece
35
+ const brickSize = 0.03 // Define according to the size of your brick piece
36
36
37
37
for (let i = 0 ; i < instanceCount ; i ++ ) {
38
38
const sampledPoint = new Vector3 ()
39
39
sampler .sample (sampledPoint )
40
40
41
41
const alignedPoint = new Vector3 (
42
- Math .round (sampledPoint .x / legoSize ) * legoSize ,
43
- Math .round (sampledPoint .y / legoSize ) * legoSize ,
44
- Math .round (sampledPoint .z / legoSize ) * legoSize ,
42
+ Math .round (sampledPoint .x / brickSize ) * brickSize ,
43
+ Math .round (sampledPoint .y / brickSize ) * brickSize ,
44
+ Math .round (sampledPoint .z / brickSize ) * brickSize ,
45
45
)
46
46
47
47
dummy .position .copy (alignedPoint )
48
- dummy .scale .set (legoSize , legoSize , legoSize )
48
+ dummy .scale .set (brickSize , brickSize , brickSize )
49
49
dummy .updateMatrix ()
50
- legoInstancedMesh .setMatrixAt (i , dummy .matrix )
50
+ brickInstancedMesh .setMatrixAt (i , dummy .matrix )
51
51
}
52
52
53
- legoInstancedMesh .instanceMatrix .needsUpdate = true
53
+ brickInstancedMesh .instanceMatrix .needsUpdate = true
54
54
</script >
55
55
56
56
<template >
57
57
<TresGroup ref =" groupRef" >
58
- <primitive :object =" legoInstancedMesh " />
58
+ <primitive :object =" brickInstancedMesh " />
59
59
</TresGroup >
60
60
<!-- <primitive :object="david" /> -->
61
61
</template >
0 commit comments