From 32dbccd7ecb39104c960ffdb161a734c6eea49d2 Mon Sep 17 00:00:00 2001 From: Jaime Torrealba Date: Thu, 26 Sep 2024 10:46:05 +0100 Subject: [PATCH] feat(app): 119 Props for colliders --- docs/components/collider.md | 27 +++++++++++++++ docs/components/rigid-body.md | 34 +++++++++++-------- .../src/pages/basics/RigidBodyProps.vue | 23 ++++++++----- src/components/RigidBody.vue | 10 ++++++ src/components/colliders/BaseCollider.vue | 7 ++++ src/types/collider.ts | 20 +++++++++++ src/types/rigid-body.ts | 23 +++++++++++++ src/utils/props.ts | 28 ++++++++++++++- 8 files changed, 147 insertions(+), 25 deletions(-) diff --git a/docs/components/collider.md b/docs/components/collider.md index 3b3b0b0..280e449 100644 --- a/docs/components/collider.md +++ b/docs/components/collider.md @@ -1 +1,28 @@ # Collider + +## Props + +| Prop | Description | Default | +| :-------------- | :------------------------------------------------------------------------------------------------------------ | --------- | +| **shape** | shape of the collider | `cuboid` | +| **args** | The half-sizes of the collider shapes | `[1,1,1]` | +| **object** | Required for certain shapes like `trimesh`, `hull`, `heightfield`. | | +| **friction** | The friction coefficient of this collider. (automatic-collider) | `0.5` | +| **mass** | Mass of the collider. (automatic-collider) | `1` | +| **density** | Restitution controls how elastic (aka. bouncy) a contact is. (automatic-collider) | `0` | +| **restitution** | The collider density. If non-zero the collider's mass and angular inertia will be added. (automatic-collider) | `1` | + +:::info The `colliders` instance has many other methods, please check the +[official docs](https://rapier.rs/docs/api/javascript/JavaScript3D/) for a +complete list, if you need them, you can +use[Template ref](https://vuejs.org/guide/essentials/template-refs.html#template-refs). +::: + +## Expose object + +``` + { + instance, + colliderDesc, +} +``` diff --git a/docs/components/rigid-body.md b/docs/components/rigid-body.md index 3a2b65c..0a44157 100644 --- a/docs/components/rigid-body.md +++ b/docs/components/rigid-body.md @@ -133,21 +133,25 @@ SOON ## Props -| Prop | Description | Default | -| :---------------------- | :----------------------------------- | ------------------------------ | -| **type** | `rigidBody` type | `dynamic` | -| **collider** | `automatic collider | `cuboid` | -| **gravityScale** | gravity for the `rigidBody` | `1` | -| **additionalMass** | add extra mass to the `rigidBody` | `0` | -| **linearDamping** | set the linear damping | `0` | -| **angularDamping** | set the angular damping | `0` | -| **dominanceGroup** | set the dominance group | `0` | -| **linvel** | linear velocity | `x: 0, y: 0, z: 0` | -| **angvel** | angular velocity | `x: 0, y: 0, z: 0` | -| **enabledRotations** | enable rotations in specific axis | `{x: true, y: true, z: true }` | -| **enabledTranslations** | enable translations in specific axis | `{x: true, y: true, z: true }` | -| **lockTranslations** | Lock all translations | `false` | -| **lockRotations** | Lock all rotations | `false` | +| Prop | Description | Default | +| :---------------------- | :------------------------------------------------------------------------------------------------------------ | ------------------------------ | +| **type** | `rigidBody` type | `dynamic` | +| **collider** | automatic collider | `cuboid` | +| **gravityScale** | gravity for the `rigidBody` | `1` | +| **additionalMass** | add extra mass to the `rigidBody` | `0` | +| **linearDamping** | set the linear damping | `0` | +| **angularDamping** | set the angular damping | `0` | +| **dominanceGroup** | set the dominance group | `0` | +| **linvel** | linear velocity | `x: 0, y: 0, z: 0` | +| **angvel** | angular velocity | `x: 0, y: 0, z: 0` | +| **enabledRotations** | enable rotations in specific axis | `{x: true, y: true, z: true }` | +| **enabledTranslations** | enable translations in specific axis | `{x: true, y: true, z: true }` | +| **lockTranslations** | Lock all translations | `false` | +| **lockRotations** | Lock all rotations | `false` | +| **friction** | The friction coefficient of this collider. (automatic-collider) | `0.5` | +| **mass** | Mass of the collider. (automatic-collider) | `1` | +| **density** | Restitution controls how elastic (aka. bouncy) a contact is. (automatic-collider) | `0` | +| **restitution** | The collider density. If non-zero the collider's mass and angular inertia will be added. (automatic-collider) | `1` | :::info The `rigidBody` instance has many other functions, please check the [official docs](https://rapier.rs/docs/api/javascript/JavaScript3D/) for a diff --git a/playground/src/pages/basics/RigidBodyProps.vue b/playground/src/pages/basics/RigidBodyProps.vue index a624f00..916634b 100644 --- a/playground/src/pages/basics/RigidBodyProps.vue +++ b/playground/src/pages/basics/RigidBodyProps.vue @@ -2,7 +2,7 @@ import { OrbitControls } from '@tresjs/cientos' import { TresCanvas } from '@tresjs/core' import { TresLeches, useControls } from '@tresjs/leches' -import { type ExposedRigidBody, Physics, RigidBody } from '@tresjs/rapier' +import { BallCollider, type ExposedRigidBody, Physics, RigidBody } from '@tresjs/rapier' import { ACESFilmicToneMapping, SRGBColorSpace } from 'three' import { shallowRef } from 'vue' import '@tresjs/leches/styles' @@ -28,15 +28,18 @@ const rotate = () => { rigidBoxRef.value.instance.applyTorqueImpulse({ x: 3, y: 5, z: 0 }, true) } -const { gravityScale, linearDamping, angularDamping, lockT, linvelX } = useControls({ +const { gravityScale, linearDamping, angularDamping, lockT, linvelX, friction, mass, density, restitution } = useControls({ gravityScale: { value: 2.5, min: -10, max: 10, step: 1 }, linearDamping: { value: 0, min: -10, max: 10, step: 1 }, angularDamping: { value: 0, min: -10, max: 10, step: 1 }, linvelX: { value: 0, min: -10, max: 10, step: 1 }, - lockT: true, + lockT: false, + // colliders + friction: { value: 0, min: 0, max: 10, step: 1 }, + mass: { value: 1, min: 0, max: 10, step: 1 }, + density: { value: 1, min: 0, max: 10, step: 1 }, + restitution: { value: 1, min: 0, max: 10, step: 1 }, }) - -// TODO test locks and enabledTranslations, check docs