Skip to content

Commit 9aaa784

Browse files
docs: 132 improve docs (#140)
* feat(app): 105 First stage of Collision event * docs: add collision docs * docs(app): 132 Add proper documentation to the library * docs(app): 132 Proper docs for all the library
1 parent 8b34d9c commit 9aaa784

File tree

15 files changed

+5115
-5750
lines changed

15 files changed

+5115
-5750
lines changed

docs/.vitepress/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,13 @@ export default defineConfig({
6565
items: [
6666
{ text: 'Physics', link: '/components/physics' },
6767
{ text: 'RigidBody', link: '/components/rigid-body' },
68-
{ text: 'Collider', link: '/components/collider' },
68+
{ text: 'Custom Collider', link: '/components/custom-collider' },
6969
],
7070
},
7171
{
7272
text: 'Composables',
7373
items: [
74+
{ text: 'useRapier', link: '/composables/use-rapier' },
7475
],
7576
},
7677
],
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<script setup lang="ts">
2+
</script>
3+
4+
<template>
5+
<ClientOnly>
6+
<div
7+
class="relative aspect-video"
8+
style=" height: auto; margin: 2rem 0; border-radius: 8px; overflow:hidden;"
9+
>
10+
<Suspense>
11+
<slot></slot>
12+
</Suspense>
13+
</div>
14+
</ClientOnly>
15+
</template>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<script setup>
2+
import { TresCanvas } from '@tresjs/core'
3+
import { Physics, RigidBody } from '@tresjs/rapier'
4+
import { shallowRef } from 'vue'
5+
6+
const rigidBallRef = shallowRef(null)
7+
8+
const resetBallPosition = () => {
9+
if (rigidBallRef.value) {
10+
rigidBallRef.value.instance.applyImpulse({ x: 0, y: 8, z: 0 }, true)
11+
}
12+
}
13+
</script>
14+
15+
<template>
16+
<button class="floating-button" @click="resetBallPosition">Jump</button>
17+
<TresCanvas>
18+
<TresPerspectiveCamera :position="[15, 15, 15]" :look-at="[0, 0, 0]" />
19+
20+
<Suspense>
21+
<Physics>
22+
<RigidBody ref="rigidBallRef">
23+
<TresMesh :position="[0, 8, 0]">
24+
<TresSphereGeometry :args="[1, 16]" />
25+
<TresMeshNormalMaterial />
26+
</TresMesh>
27+
</RigidBody>
28+
29+
<RigidBody type="fixed">
30+
<TresMesh :position="[0, 0, 0]">
31+
<TresPlaneGeometry :args="[20, 20, 20]" :rotate-x="-Math.PI / 2" />
32+
<TresMeshBasicMaterial color="#f4f4f4" />
33+
</TresMesh>
34+
</RigidBody>
35+
</Physics>
36+
</Suspense>
37+
</TresCanvas>
38+
</template>
39+
40+
<style scoped>
41+
.floating-button {
42+
position: relative;
43+
top: 0;
44+
left: 40%;
45+
z-index: 1000;
46+
padding: 0.5rem 1rem;
47+
font-size: 1rem;
48+
background-color: #007bff;
49+
color: white;
50+
border: none;
51+
border-radius: 0.25rem;
52+
cursor: pointer;
53+
}
54+
</style>

docs/components/collider.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

docs/components/custom-collider.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Custom Colliders
2+
3+
You can add colliders that are not tied to a 3D mesh, this way you can create
4+
your own collider shape.
5+
6+
```vue
7+
<template>
8+
<RigidBody>
9+
<BallCollider />
10+
</RigidBody>
11+
</template>
12+
```
13+
14+
:::warning
15+
Custom collider needs to be child of a `Rigid-body` component.
16+
:::
17+
18+
### Available as component
19+
20+
| Prop | Description |
21+
| :------------ | :---------------------------------------------------------------------------------- |
22+
| `<CuboidCollider>` | Box shape |
23+
| `<BallCollider>` | Sphere shape |
24+
| `<CapsuleCollider>` | Capsule shape |
25+
| `<ConeCollider>` | Cone shape |
26+
| `<CylinderCollider>` | Cylinder shape |
27+
| `<HullCollider>` | The smallest convex shape that contains all the given points. |
28+
| `<TrimeshCollider>` | A set of indices indicating what vertex is used by what triangle. |
29+
| `<HeightfieldCollider>` | Large rectangle in the X-Z plane, subdivided in a grid pattern at regular intervals |
30+
31+
:::warning
32+
Avoid using `<TrimeshCollider >` with dynamic bodies, since the performance get compromised
33+
:::
34+
35+
## Collisions
36+
37+
Similar to [how collisions work in rigid-bodies](./rigid-body.md#collisions) you
38+
can set a custom collider to receive collisions events.
39+
40+
Be aware that the event will be emitted by the `RigidBody` parent
41+
42+
```vue
43+
<template>
44+
<RigidBody
45+
@collision-enter="onCollisionEnter"
46+
@collision-exit="onCollisionExit"
47+
>
48+
<BallCollider activeCollision />
49+
</RigidBody>
50+
</template>
51+
```
52+
53+
## Props
54+
55+
| Prop | Description | Default |
56+
| :----------------------- | :------------------------------------------------------------------------------------------------------------ | ------------------------------ |
57+
| **shape** | shape of the collider | `cuboid` |
58+
| **args** | The half-sizes of the collider shapes | `[1,1,1]` |
59+
| **object** | Required for certain shapes like `trimesh`, `hull`, `heightfield`. | |
60+
| **friction** | The friction coefficient of this collider. (automatic-collider) | `0.5` |
61+
| **mass** | Mass of the collider. (automatic-collider) | `1` |
62+
| **density** | Restitution controls how elastic (aka. bouncy) a contact is. (automatic-collider) | `0` |
63+
| **restitution** | The collider density. If non-zero the collider's mass and angular inertia will be added. (automatic-collider) | `1` |
64+
| **activeCollision** | To set the collider receiver/emitter collision events | `false` |
65+
| **activeCollisionTypes** | Type of the collision event. | `ActiveCollisionTypes.DEFAULT` |
66+
| **collisionGroups** | To specify collision groups. | `undefined` |
67+
68+
:::info
69+
You can access the
70+
[Collider](https://rapier.rs/docs/user_guides/javascript/colliders) instance
71+
which offers full control over all the properties & methods available by using
72+
[Template refs](https://vuejs.org/guide/essentials/template-refs.html#template-refs).
73+
:::
74+
75+
## Expose object
76+
77+
```js
78+
const exposeObject = {
79+
instance,
80+
colliderDesc,
81+
}
82+
```

docs/components/physics.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
11
# Physics
2+
3+
The `<Physics />` component act as a provider and it need to wrapper our
4+
physic scene.
5+
6+
```vue{4,10-14}
7+
<script setup lang="ts" >
8+
import { TresCanvas } from '@tresjs/core'
9+
import { Physics } from '@tresjs/rapier'
10+
</script>
11+
12+
<template>
13+
<TresCanvas window-size>
14+
<TresPerspectiveCamera :position="[11, 11, 11]" :look-at="[0, 0, 0]" />
15+
16+
<Suspense>
17+
<Physics>
18+
// your scene with physics goes here
19+
</Physics>
20+
</Suspense>
21+
</TresCanvas>
22+
</template>
23+
```
24+
25+
:::warning
26+
Note that in order to work the `<Physics />` needs to be wrapped in a
27+
`<Suspense >` component
28+
:::
29+
30+
## Props
31+
32+
| Prop | Description | default |
33+
| :-------- | :---------------------------- | :------ |
34+
| `gravity` | Sets the gravity of the world | `[0, -9.8, 0]` |
35+
| `debug` | Enables debug mode | `false` |
36+
| `timestep` | Sets the new simulation timestep in seconds. | `1` |
37+
38+
## Expose object
39+
40+
SOON

0 commit comments

Comments
 (0)