Skip to content

Commit 7deb26f

Browse files
feat(app): 111 Add gravity as a props (#114)
* feat(app): 111 Add gravity as a props * feat: handle gravity as Vector, array and object format + lint issues * feat: accept VectorCoordinates for gravity --------- Co-authored-by: alvarosabu <alvaro.saburido@gmail.com>
1 parent fab78d8 commit 7deb26f

File tree

4 files changed

+4718
-5652
lines changed

4 files changed

+4718
-5652
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script setup lang="ts">
2+
import { OrbitControls } from '@tresjs/cientos'
3+
import { TresCanvas } from '@tresjs/core'
4+
import { TresLeches, useControls } from '@tresjs/leches'
5+
import { Physics, RigidBody } from '@tresjs/rapier'
6+
import { ACESFilmicToneMapping, SRGBColorSpace } from 'three'
7+
import '@tresjs/leches/styles'
8+
9+
const gl = {
10+
clearColor: '#82DBC5',
11+
shadows: true,
12+
alpha: false,
13+
outputColorSpace: SRGBColorSpace,
14+
toneMapping: ACESFilmicToneMapping,
15+
}
16+
17+
const { gravityY } = useControls({
18+
gravityY: { value: 0, min: -20, max: 20, step: 0.1 },
19+
})
20+
</script>
21+
22+
<template>
23+
<TresLeches />
24+
<TresCanvas v-bind="gl" window-size>
25+
<TresPerspectiveCamera :position="[15, 15, 15]" :look-at="[0, 0, 0]" />
26+
<OrbitControls />
27+
28+
<Suspense>
29+
<Physics debug :gravity="[0, gravityY, 0]">
30+
<RigidBody>
31+
<TresMesh :position="[0, 8, 0]">
32+
<TresTorusGeometry />
33+
<TresMeshNormalMaterial />
34+
</TresMesh>
35+
36+
<TresMesh :position="[0, 5, 0]">
37+
<TresBoxGeometry />
38+
<TresMeshNormalMaterial />
39+
</TresMesh>
40+
</RigidBody>
41+
42+
<RigidBody v-for="ball in [1, 2, 3, 4, 5, 6, 7] " :key="ball" collider="ball">
43+
<TresMesh :position="[Math.random() * 2, Math.random() * 2 + 8, Math.random() * 2]">
44+
<TresSphereGeometry />
45+
<TresMeshNormalMaterial />
46+
</TresMesh>
47+
</RigidBody>
48+
49+
<RigidBody type="fixed">
50+
<TresMesh :position="[0, 0, 0]">
51+
<TresPlaneGeometry :args="[20, 20, 20]" :rotate-x="-Math.PI / 2" />
52+
<TresMeshBasicMaterial color="#f4f4f4" />
53+
</TresMesh>
54+
</RigidBody>
55+
</Physics>
56+
</Suspense>
57+
</TresCanvas>
58+
</template>

playground/src/router/routes/basics.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ export const basicsRoutes = [
44
name: 'Rigid Body',
55
component: () => import('../../pages/basics/RigidBodyDemo.vue'),
66
},
7+
{
8+
path: '/basics/gravity',
9+
name: 'Gravity',
10+
component: () => import('../../pages/basics/GravityDemo.vue'),
11+
},
712
]

0 commit comments

Comments
 (0)