-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): 119 Add props to rigidbody (#129)
* feat(app): 119 Add props to rigidbody * fix: fix set initial props, docs, types, demos. Add additionalMass * fix: move types * refactor(core): watcher types accessibility ### Description - Add object types support - `NonNever` - `Methods` - `CallableProps` - Improve `makePropWatcherRB` types accessibility - Improve `makePropsWatcherRB` types accessibility Co-Authored-By: Jaime A Torrealba C <63722373+JaimeTorrealba@users.noreply.github.com> --------- Co-authored-by: Nathan Mande <neodarksoulink@gmail.com>
- Loading branch information
1 parent
7b509d4
commit e3ec76f
Showing
12 changed files
with
314 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
# How does it work? | ||
|
||
## Caveats | ||
|
||
- Rapier set object to sleep... | ||
- HMR sometimes work unexpected prefer reload page (unles reactive property is set) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<script setup lang="ts"> | ||
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 { ACESFilmicToneMapping, SRGBColorSpace } from 'three' | ||
import { shallowRef } from 'vue' | ||
import '@tresjs/leches/styles' | ||
const gl = { | ||
clearColor: '#82DBC5', | ||
shadows: true, | ||
alpha: false, | ||
outputColorSpace: SRGBColorSpace, | ||
toneMapping: ACESFilmicToneMapping, | ||
} | ||
const rigidTorusRef = shallowRef<ExposedRigidBody>(null) | ||
const rigidBoxRef = shallowRef<ExposedRigidBody>(null) | ||
const jump = () => { | ||
if (!rigidTorusRef.value) { return } | ||
rigidTorusRef.value.instance.applyImpulse({ x: 0, y: 35, z: 0 }, true) | ||
} | ||
const rotate = () => { | ||
if (!rigidBoxRef.value) { return } | ||
rigidBoxRef.value.instance.applyTorqueImpulse({ x: 3, y: 5, z: 0 }, true) | ||
} | ||
const { gravityScale, linearDamping, angularDamping, lockT, linvelX } = 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, | ||
}) | ||
// TODO test locks and enabledTranslations, check docs | ||
</script> | ||
|
||
<template> | ||
<TresLeches /> | ||
<TresCanvas v-bind="gl" window-size> | ||
<TresPerspectiveCamera :position="[11, 11, 11]" :look-at="[0, 0, 0]" /> | ||
<OrbitControls /> | ||
|
||
<Suspense> | ||
<Physics debug> | ||
<!-- TORUS --> | ||
<RigidBody | ||
ref="rigidTorusRef" | ||
:gravityScale="gravityScale.value" | ||
:linearDamping="linearDamping.value" | ||
:angularDamping="angularDamping.value" | ||
:enabledTranslations="{ x: true, y: true, z: true }" | ||
:lockTranslations="lockT.value" | ||
> | ||
<TresMesh :position="[4, 8, 0]" @click="jump"> | ||
<TresTorusGeometry /> | ||
<TresMeshNormalMaterial /> | ||
</TresMesh> | ||
</RigidBody> | ||
|
||
<RigidBody> | ||
<TresMesh :position="[0, 8, 0]"> | ||
<TresTorusGeometry /> | ||
<TresMeshNormalMaterial /> | ||
</TresMesh> | ||
</RigidBody> | ||
|
||
<!-- BOX --> | ||
|
||
<RigidBody | ||
ref="rigidBoxRef" | ||
:gravityScale="-0.01" | ||
:additionalMass="50" | ||
:enabledRotations="{ x: true, y: false, z: true }" | ||
:linvel="{ x: linvelX.value, y: 0, z: 0 }" | ||
> | ||
<TresMesh :position="[4, 2, 5]" @click="rotate"> | ||
<TresBoxGeometry /> | ||
<TresMeshBasicMaterial :color="0xFF0000" /> | ||
</TresMesh> | ||
</RigidBody> | ||
|
||
<RigidBody> | ||
<TresMesh :position="[0, 8, 5]"> | ||
<TresBoxGeometry /> | ||
<TresMeshBasicMaterial :color="0xFF0000" /> | ||
</TresMesh> | ||
</RigidBody> | ||
|
||
<RigidBody type="fixed"> | ||
<TresMesh :position="[0, 0, 0]"> | ||
<TresPlaneGeometry :args="[20, 20, 20]" :rotate-x="-Math.PI / 2" /> | ||
<TresMeshBasicMaterial color="#f4f4f4" /> | ||
</TresMesh> | ||
</RigidBody> | ||
</Physics> | ||
</Suspense> | ||
</TresCanvas> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export interface enableBolean { x: boolean, y: boolean, z: boolean } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from './boolean' | ||
export * from './collider' | ||
export * from './object' | ||
export * from './physics' | ||
export * from './rapier' | ||
export * from './rigid-body' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** @description Utility type to exclude properties with the type `never` */ | ||
export type NonNever<T extends object> = { | ||
[K in keyof T as T[K] extends never ? never : K]: T[K]; | ||
} | ||
|
||
/** @description Utility type to extract only **methods** of an `object` */ | ||
export type Methods<T extends object> = NonNever<{ | ||
[K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : never; | ||
}> | ||
|
||
export type CallableProps<T extends object = object> = Record<keyof Methods<T>, (...args: any[]) => unknown> |
Oops, something went wrong.