Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace pokeball experiment #222

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions components/content/brickelangelo-david/David.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script setup lang="ts">
import type { Group } from 'three'
import { InstancedMesh, MeshPhongMaterial, Raycaster, Vector3, Object3D } from 'three'
import { InstancedMesh, MeshPhongMaterial, Vector3, Object3D } from 'three'
import { MeshSurfaceSampler } from 'three/addons/math/MeshSurfaceSampler.js'
import { useMouse } from '@vueuse/core'

const groupRef = ref<Group>()

const gltf = await useGLTF('/models/legolangelo/david.glb')
const gltf = await useGLTF('/models/brickelangelo/david.glb')

const david = gltf.nodes.David

Expand All @@ -17,12 +17,12 @@ watch([x, y], () => {
groupRef.value.rotation.y = -x.value * 0.0001
})

const { nodes: legoNodes } = await useGLTF('/models/legolangelo/lego.glb')
const { nodes: brickNodes } = await useGLTF('/models/brickelangelo/brick.glb')

const lego = legoNodes.LegoPiece
const brick = brickNodes.LegoPiece

const legoMaterial = new MeshPhongMaterial({ color: 'lightgray' })
const legoInstancedMesh = new InstancedMesh(lego.geometry, legoMaterial, instanceCount)
const brickMaterial = new MeshPhongMaterial({ color: 'lightgray' })
const brickInstancedMesh = new InstancedMesh(brick.geometry, brickMaterial, instanceCount)

useControls('fpsgraph')

Expand All @@ -32,30 +32,30 @@ const sampler = new MeshSurfaceSampler(david)

const instanceCount = 75000 // or whatever count you want
const dummy = new Object3D()
const legoSize = 0.03 // Define according to the size of your LEGO piece
const brickSize = 0.03 // Define according to the size of your brick piece

for (let i = 0; i < instanceCount; i++) {
const sampledPoint = new Vector3()
sampler.sample(sampledPoint)

const alignedPoint = new Vector3(
Math.round(sampledPoint.x / legoSize) * legoSize,
Math.round(sampledPoint.y / legoSize) * legoSize,
Math.round(sampledPoint.z / legoSize) * legoSize,
Math.round(sampledPoint.x / brickSize) * brickSize,
Math.round(sampledPoint.y / brickSize) * brickSize,
Math.round(sampledPoint.z / brickSize) * brickSize,
)

dummy.position.copy(alignedPoint)
dummy.scale.set(legoSize, legoSize, legoSize)
dummy.scale.set(brickSize, brickSize, brickSize)
dummy.updateMatrix()
legoInstancedMesh.setMatrixAt(i, dummy.matrix)
brickInstancedMesh.setMatrixAt(i, dummy.matrix)
}

legoInstancedMesh.instanceMatrix.needsUpdate = true
brickInstancedMesh.instanceMatrix.needsUpdate = true
</script>

<template>
<TresGroup ref="groupRef">
<primitive :object="legoInstancedMesh" />
<primitive :object="brickInstancedMesh" />
</TresGroup>
<!-- <primitive :object="david" /> -->
</template>
7 changes: 7 additions & 0 deletions components/content/realistic/DamagedHelmet.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
const { scene } = await useGLTF('/models/damaged-helmet/DamagedHelmet.glb', { draco: true })
</script>

<template>
<primitive :object="scene" />
</template>
9 changes: 0 additions & 9 deletions components/content/realistic/Pokeball.vue

This file was deleted.

6 changes: 3 additions & 3 deletions components/content/realistic/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ const { hasFinishLoading, progress } = await useProgress()
>
<div class="w-200px">
Loading... {{ progress }} %
<i class="i-ic-twotone-catching-pokemon animate-rotate-in" />
<i class="animate-rotate-in" />
</div>
</div>
</Transition>
<TresCanvas preset="realistic">
<TresPerspectiveCamera :position="[11, 11, 11]" />
<TresPerspectiveCamera :position="[3, 3, 5]" />
<OrbitControls />
<Suspense>
<Environment
Expand All @@ -30,7 +30,7 @@ const { hasFinishLoading, progress } = await useProgress()
/>
</Suspense>
<Suspense>
<Pokeball />
<DamagedHelmet />
</Suspense>

<TresDirectionalLight
Expand Down
2 changes: 1 addition & 1 deletion content/experiments/brickelangelo-david.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
author: alvarosabu
description: Lego ThreeJS Journey challenge
description: Bricks ThreeJS Journey challenge
tags: ['basic', 'cientos', 'MeshSurfaceSampler']
---

Expand Down
Binary file added public/models/damaged-helmet/DamagedHelmet.glb
Binary file not shown.
6 changes: 6 additions & 0 deletions public/models/damaged-helmet/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Flight helmet with damage
Credit:
© 2018, ctxwing. [CC BY 4.0 International](https://creativecommons.org/licenses/by/4.0/legalcode)
- ctxwing for Rebuild and conversion to glTF
© 2016, theblueturtle_. [CC BY-NC 4.0 International](https://creativecommons.org/licenses/by-nc/4.0/legalcode)
- theblueturtle_ for Earlier version of model
2 changes: 1 addition & 1 deletion public/models/nuxt-stones/nuxt-stones.gltf

Large diffs are not rendered by default.

11 changes: 0 additions & 11 deletions public/models/realistic-pokeball/license.txt

This file was deleted.

Binary file removed public/models/realistic-pokeball/scene.bin
Binary file not shown.
Loading
Loading