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

feat: rigid body continued #18

Merged
merged 22 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f9b28f2
Add `<Physics />` and `<RigidBody />` components
kekkorider Nov 13, 2023
f8a3f4e
feat: world and rigid boxy
alvarosabu Dec 14, 2023
a141335
chore: add prettier for coding harmony
Neosoulink Jun 8, 2024
f574732
chore(config): correct `vite` configuration
Neosoulink Jun 8, 2024
96cd52a
feat: add `trimesh` supporrt
Neosoulink Jun 8, 2024
9b23479
chore(config): add bracket & endline prettier support
Neosoulink Jun 8, 2024
bfde220
refactor: better access to rapier context
Neosoulink Jun 10, 2024
8daecef
Merge branch 'main' into feat/rigid-body-continued
Neosoulink Jun 11, 2024
7e18f7b
Merge branch 'main' into feat/rigid-body-continued
Neosoulink Jun 13, 2024
6cca9d3
chore(deps): install packages with `pnpm`
Neosoulink Jun 13, 2024
9441602
refactor(architecture): better structure separation
Neosoulink Jun 17, 2024
8412712
feat: delegate responsibilities to sub-utils
Neosoulink Jun 18, 2024
3b366f6
feat: add `hull` collider
Neosoulink Jun 20, 2024
d68dd43
feat: base of instanced `mesh` support
Neosoulink Jun 20, 2024
5998f29
feat: rigid-body instance Matrix compose support
Neosoulink Jun 21, 2024
c1df088
Merge branch 'main' into feat/rigid-body-continued
Neosoulink Jun 23, 2024
274e067
Merge branch 'main' into feat/rigid-body-continued
Neosoulink Jun 23, 2024
ec8d78d
refactor(style): request changes improvements
Neosoulink Jun 29, 2024
0b56245
Merge branch 'main' into feat/rigid-body-continued
Neosoulink Jun 29, 2024
fa0fc3d
Merge branch 'main' into feat/rigid-body-continued
alvarosabu Jul 1, 2024
12e5800
Merge branch 'main' into feat/rigid-body-continued
Neosoulink Jul 9, 2024
62283f6
Merge remote-tracking branch 'origin/main' into feat/rigid-body-conti…
Neosoulink Sep 3, 2024
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
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"version": "0.0.0",
"private": true,
"packageManager": "[email protected]",
"description": "TresJs physics support, powered by rapier",
"author": "Alvaro Saburido <[email protected]> (https://github.com/alvarosabu/)",
"license": "MIT",
"keywords": [
"vue",
Expand Down
64 changes: 44 additions & 20 deletions playground/src/pages/basics/RigidBodyDemo.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<script setup lang="ts">
import { shallowRef, watch } from 'vue'
import { TresCanvas } from '@tresjs/core'
import { OrbitControls } from '@tresjs/cientos'
import { Physics, RigidBody } from '@tresjs/rapier'
import { ACESFilmicToneMapping, SRGBColorSpace } from 'three'
import { ACESFilmicToneMapping, DynamicDrawUsage, Matrix4, MeshNormalMaterial, SRGBColorSpace, TorusKnotGeometry } from 'three'
import type { InstancedMesh } from 'three'

const gl = {
clearColor: '#82DBC5',
Expand All @@ -11,42 +13,64 @@ const gl = {
outputColorSpace: SRGBColorSpace,
toneMapping: ACESFilmicToneMapping,
}

const torusInstancedMesh = shallowRef<InstancedMesh>()

const torusKnots = new TorusKnotGeometry()
const torusKnotsMaterial = new MeshNormalMaterial()

watch(torusInstancedMesh, (mesh) => {
mesh?.instanceMatrix.setUsage(DynamicDrawUsage)

if (mesh) {
for (let i = 0; i < mesh.count; i++) {
const x = (Math.random() - 0.5) * 5
const y = ((Math.random()) * 2) + 5
const z = (Math.random() - 0.5) * 5

mesh.setMatrixAt(
i,
new Matrix4().makeTranslation(x, y, z),
)
}
mesh.instanceMatrix.needsUpdate = true
}
})
</script>

<template>
<TresCanvas
v-bind="gl"
window-size
>
<TresPerspectiveCamera
:position="[11, 11, 11]"
:look-at="[0, 0, 0]"
/>
<TresCanvas v-bind="gl" window-size>
<TresPerspectiveCamera :position="[11, 11, 11]" :look-at="[0, 0, 0]" />
<OrbitControls />

<Suspense>
<Physics debug>
<RigidBody instanced collider="hull">
<TresInstancedMesh ref="torusInstancedMesh" :args="[torusKnots, torusKnotsMaterial, 3]" />
</RigidBody>

<RigidBody>
<TresMesh :position="[0, 4, 0]">
<TresMesh :position="[0, 8, 0]">
<TresTorusGeometry />
<TresMeshNormalMaterial />
</TresMesh>

<TresMesh :position="[0, 5, 0]">
<TresBoxGeometry />
<TresMeshNormalMaterial />
</TresMesh>
</RigidBody>
<RigidBody
v-for="ball in [1, 2, 3, 4, 5, 6, 7] "
:key="ball"
collider="ball"
>

<RigidBody v-for="ball in [1, 2, 3, 4, 5, 6, 7] " :key="ball" collider="ball">
<TresMesh :position="[Math.random() * 2, Math.random() * 2 + 8, Math.random() * 2]">
<TresSphereGeometry />
<TresMeshNormalMaterial />
</TresMesh>
</RigidBody>

<RigidBody type="fixed">
<TresMesh>
<TresPlaneGeometry
:args="[20, 20, 20]"
:rotate-x="-Math.PI / 2"
/>
<TresMesh :position="[0, 0, 0]">
<TresPlaneGeometry :args="[20, 20, 20]" :rotate-x="-Math.PI / 2" />
<TresMeshBasicMaterial color="#f4f4f4" />
</TresMesh>
</RigidBody>
Expand Down
Loading
Loading