-
-
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: sensor support integration (#141)
* feat: implement `intersection` feature * feat(playground): add `sesnor` demo * fix(playground): remove unsupported `name` * fix(core): debug `line bounding-box` availability * fix(core): unsupported props warns correction ### Description - Add new `vNode` extended types - `TresVNodeObject` - `TresVNode` - Add a `TresObject` to collider * docs(component): minimal `sensor` documentation * fix(docs): minor * refactor(core): improve `emitIntersection` integration * refactor(core): use `TresObject3D` * feat(core): `RigdBody` inherit props from `Collider` ### Description - Add `Sensor` to `RigidBody` component props - `RigidBodyProps` inherits types from `ColliderProps` * feat(core): `RigidBody` catch intersection events * refactor(playground): add `RigidBody` intersection demo * chore(conf): set default `TS` formater * docs(collider): add note for sensor auto-colliders * docs(collider): move intersection refs to info-block * docs: improve docs guide for colliders * chore: lint github folder --------- Co-authored-by: alvarosabu <alvaro.saburido@gmail.com>
- Loading branch information
1 parent
2f906e2
commit 41eae54
Showing
21 changed files
with
388 additions
and
116 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 @@ | ||
blank_issues_enabled: false | ||
blank_issues_enabled: false |
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,4 +1,4 @@ | ||
name: 'Lint PR' | ||
name: Lint PR | ||
|
||
on: | ||
pull_request_target: | ||
|
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
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,122 @@ | ||
<script setup lang="ts"> | ||
import { OrbitControls } from '@tresjs/cientos' | ||
import { TresCanvas } from '@tresjs/core' | ||
// eslint-disable-next-line ts/ban-ts-comment | ||
// @ts-ignore | ||
import { CuboidCollider, Physics, RigidBody } from '@tresjs/rapier' | ||
import { ACESFilmicToneMapping, MeshNormalMaterial, SRGBColorSpace } from 'three' | ||
import { onMounted, shallowRef } from 'vue' | ||
import type { Mesh } from 'three' | ||
const gl = { | ||
clearColor: '#82DBC5', | ||
shadows: true, | ||
alpha: false, | ||
outputColorSpace: SRGBColorSpace, | ||
toneMapping: ACESFilmicToneMapping, | ||
} | ||
const bodyContextRef = shallowRef() | ||
const ballRef = shallowRef<Mesh>() | ||
const onIntersection1Enter = (ev) => { | ||
// eslint-disable-next-line no-console | ||
console.log('Intersection 1 enter', ev) | ||
if (ballRef.value?.material instanceof MeshNormalMaterial) { | ||
ballRef.value.material.visible = false | ||
} | ||
} | ||
const onIntersection2Enter = () => { | ||
if (ballRef.value?.material instanceof MeshNormalMaterial) { | ||
ballRef.value.material.colorWrite = false | ||
} | ||
} | ||
const onIntersection3Enter = () => { | ||
if (ballRef.value?.material instanceof MeshNormalMaterial) { | ||
ballRef.value.material.wireframe = true | ||
} | ||
} | ||
const onIntersectionExit = () => { | ||
if (ballRef.value?.material instanceof MeshNormalMaterial) { | ||
ballRef.value.material.visible = true | ||
ballRef.value.material.colorWrite = true | ||
ballRef.value.material.wireframe = false | ||
} | ||
} | ||
const resetBall = () => { | ||
bodyContextRef.value?.instance?.setAngvel({ x: -2, y: 0, z: 0 }, true) | ||
bodyContextRef.value?.instance?.setLinvel({ x: 0, y: 0, z: -8 }, true) | ||
bodyContextRef.value?.instance?.setRotation({ x: 0, y: 0, z: 0, w: 1 }, true) | ||
bodyContextRef.value?.instance?.setTranslation({ x: 0, y: 0, z: 0 }, true) | ||
} | ||
onMounted(() => { | ||
setTimeout(() => { | ||
resetBall() | ||
setInterval(() => { | ||
resetBall() | ||
}, 3000) | ||
}, 100) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<TresCanvas v-bind="gl" window-size> | ||
<TresPerspectiveCamera :position="[-30, 8, -10]" :look-at="[0, 0, 0]" /> | ||
<OrbitControls /> | ||
|
||
<Suspense> | ||
<Physics debug> | ||
<RigidBody ref="bodyContextRef" collider="ball"> | ||
<TresMesh ref="ballRef" :position="[0, 8, 8]" name="ball"> | ||
<TresSphereGeometry /> | ||
<TresMeshNormalMaterial /> | ||
</TresMesh> | ||
</RigidBody> | ||
|
||
<RigidBody | ||
type="fixed" | ||
activeCollision | ||
sensor | ||
@intersection-enter="onIntersection2Enter" | ||
@intersection-exit="onIntersectionExit" | ||
> | ||
<TresMesh :position="[0, 5, 0]"> | ||
<TresBoxGeometry :args="[10, 10, 0.5]" /> | ||
<TresMeshBasicMaterial color="#f4f4f4" /> | ||
</TresMesh> | ||
|
||
<CuboidCollider | ||
:args="[10, 3, 0.5]" | ||
:position="[0, 3, 3]" | ||
activeCollision | ||
sensor | ||
@intersection-enter="onIntersection1Enter" | ||
@intersection-exit="onIntersectionExit" | ||
/> | ||
|
||
<CuboidCollider | ||
:args="[10, 3, 0.5]" | ||
:position="[0, 3, -3]" | ||
activeCollision | ||
sensor | ||
@intersection-enter="onIntersection3Enter" | ||
@intersection-exit="onIntersectionExit" | ||
/> | ||
</RigidBody> | ||
|
||
<RigidBody type="fixed" name="fixedFloor" :restitution="0.2"> | ||
<TresMesh :position="[0, 0, 0]"> | ||
<TresPlaneGeometry :args="[20, 20, 1]" :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
Oops, something went wrong.