-
-
Notifications
You must be signed in to change notification settings - Fork 2
feat: ragdoll demo #160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: ragdoll demo #160
Changes from all commits
f7ef270
aaae596
7507591
b33f11e
7b9c441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,182 @@ | ||||||||||||||||||||||||||||||||||
| <script lang="ts" setup> | ||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line ts/ban-ts-comment | ||||||||||||||||||||||||||||||||||
| // @ts-ignore | ||||||||||||||||||||||||||||||||||
| import { CuboidCollider, type ExposedRigidBody, RigidBody, SphericalJoint } from '@tresjs/rapier' | ||||||||||||||||||||||||||||||||||
| import { onMounted, shallowRef, type ShallowRef } from 'vue' | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const headRef: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
| const torsoRef: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
| const upperArmL: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
| const lowerArmL: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const upperArmR: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
| const lowerArmR: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const upperLegL: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
| const lowerLegL: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const upperLegR: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
| const lowerLegR: ShallowRef<ExposedRigidBody> = shallowRef(null) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Adjust this to make it more flexible | ||||||||||||||||||||||||||||||||||
| const stiffness = 0.02 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const torsoWidth = 0.4 | ||||||||||||||||||||||||||||||||||
| const torsoHeight = 0.4 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const headSize = 0.2 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const armLength = 0.25 | ||||||||||||||||||||||||||||||||||
| const armThickness = 0.15 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const legSegmentHeight = torsoHeight * 0.8 | ||||||||||||||||||||||||||||||||||
| const legthickness = 0.16 | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorHead = [0, -headSize / 2 - stiffness, 0] | ||||||||||||||||||||||||||||||||||
| const localAnchorNeck = [0, torsoHeight / 2, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorLTorso = [(torsoWidth / 2) + stiffness, 0.1, 0] | ||||||||||||||||||||||||||||||||||
| const localAnchorLArm = [-armLength / 2, 0, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorLArmBottom = [(armLength / 2) + stiffness, 0 / 2, 0.0] | ||||||||||||||||||||||||||||||||||
| const localAnchorLArmLower = [-armLength / 2, 0 / 2, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorRTorso = [-(torsoWidth / 2) - stiffness, 0.1, 0] | ||||||||||||||||||||||||||||||||||
| const localAnchorRArm = [armLength / 2, 0, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorRArmBottom = [-(armLength / 2) - stiffness, 0 / 2, 0.0] | ||||||||||||||||||||||||||||||||||
| const localAnchorRArmLower = [armLength / 2, 0 / 2, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorLTorsoBottom = [-(torsoWidth / 2) + legthickness / 2, -torsoHeight / 2 - stiffness, 0] | ||||||||||||||||||||||||||||||||||
| const localAnchorLLegUpper = [0, legSegmentHeight / 2, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorLLegUpperLower = [0, -legSegmentHeight / 2 - stiffness, 0] | ||||||||||||||||||||||||||||||||||
| const localAnchorLLegLowerTop = [0, legSegmentHeight / 2, 0] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const localAnchorRTorsoBottom = [+(torsoWidth / 2) - legthickness / 2, -torsoHeight / 2 - stiffness, 0] | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| const localAnchorRTorsoBottom = [+(torsoWidth / 2) - legthickness / 2, -torsoHeight / 2 - stiffness, 0] | |
| const localAnchorLTorsoBottom = [-(torsoWidth / 2) + legThickness / 2, -torsoHeight / 2 - stiffness, 0] | |
| const localAnchorLLegUpper = [0, legSegmentHeight / 2, 0] | |
| const localAnchorLLegUpperLower = [0, -legSegmentHeight / 2 - stiffness, 0] | |
| const localAnchorLLegLowerTop = [0, legSegmentHeight / 2, 0] | |
| const localAnchorRTorsoBottom = [+(torsoWidth / 2) - legThickness / 2, -torsoHeight / 2 - stiffness, 0] |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable reference contains a spelling error: 'legthickness' should be 'legThickness' to match the corrected variable name.
| const localAnchorRTorsoBottom = [+(torsoWidth / 2) - legthickness / 2, -torsoHeight / 2 - stiffness, 0] | |
| const localAnchorLTorsoBottom = [-(torsoWidth / 2) + legThickness / 2, -torsoHeight / 2 - stiffness, 0] | |
| const localAnchorLLegUpper = [0, legSegmentHeight / 2, 0] | |
| const localAnchorLLegUpperLower = [0, -legSegmentHeight / 2 - stiffness, 0] | |
| const localAnchorLLegLowerTop = [0, legSegmentHeight / 2, 0] | |
| const localAnchorRTorsoBottom = [+(torsoWidth / 2) - legThickness / 2, -torsoHeight / 2 - stiffness, 0] |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The click event listener is added to the document without being removed on component unmount, which could cause memory leaks. Consider using onUnmounted to clean up the event listener.
| }) | |
| const handleDocumentClick = () => { | |
| if (!headRef.value) { return } | |
| headRef.value.instance?.applyImpulse({ x: 0, y: 10, z: 0 }, true) | |
| } | |
| onMounted(() => { | |
| document.addEventListener('click', handleDocumentClick) | |
| }) | |
| onUnmounted(() => { | |
| document.removeEventListener('click', handleDocumentClick) |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable reference contains a spelling error: 'legthickness' should be 'legThickness' to match the corrected variable name.
| <CuboidCollider :args="[legthickness / 2, legSegmentHeight / 2, legthickness / 2]" /> | |
| <CuboidCollider :args="[legThickness / 2, legSegmentHeight / 2, legThickness / 2]" /> |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable reference contains a spelling error: 'legthickness' should be 'legThickness' to match the corrected variable name.
| <CuboidCollider :args="[legthickness / 2, legSegmentHeight / 2, legthickness / 2]" /> | |
| <CuboidCollider :args="[legThickness / 2, legSegmentHeight / 2, legThickness / 2]" /> |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable reference contains a spelling error: 'legthickness' should be 'legThickness' to match the corrected variable name.
| <CuboidCollider :args="[legthickness / 2, legSegmentHeight / 2, legthickness / 2]" /> | |
| <CuboidCollider :args="[legThickness / 2, legSegmentHeight / 2, legThickness / 2]" /> |
Copilot
AI
Aug 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable reference contains a spelling error: 'legthickness' should be 'legThickness' to match the corrected variable name.
| <CuboidCollider :args="[legthickness / 2, legSegmentHeight / 2, legthickness / 2]" /> | |
| <CuboidCollider :args="[legThickness / 2, legSegmentHeight / 2, legThickness / 2]" /> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| <script lang="ts" setup> | ||
| import { OrbitControls } from '@tresjs/cientos' | ||
| import { TresCanvas } from '@tresjs/core' | ||
| import { TresLeches, useControls } from '@tresjs/leches' | ||
| // eslint-disable-next-line ts/ban-ts-comment | ||
| // @ts-ignore | ||
| import { Physics, RigidBody } from '@tresjs/rapier' | ||
| import { ACESFilmicToneMapping, SRGBColorSpace } from 'three' | ||
| import '@tresjs/leches/styles' | ||
|
|
||
| import Ragdoll from './../../components/Ragdoll.vue' | ||
|
|
||
| const gl = { | ||
| clearColor: '#82DBC5', | ||
| shadows: true, | ||
| alpha: false, | ||
| outputColorSpace: SRGBColorSpace, | ||
| toneMapping: ACESFilmicToneMapping, | ||
| } | ||
|
|
||
| const { gravityY } = useControls({ | ||
| gravityY: { value: -9.81, min: -20, max: 20, step: 0.1 }, | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <TresLeches /> | ||
| <TresCanvas v-bind="gl" window-size> | ||
| <TresPerspectiveCamera :position="[-4, 1, -4]" :look-at="[0, 0, 0]" /> | ||
| <OrbitControls /> | ||
|
|
||
| <Suspense> | ||
| <Physics debug :gravity="[0, gravityY, 0]"> | ||
| <Ragdoll /> | ||
|
|
||
| <RigidBody type="fixed" :position="[0, -1, 0]"> | ||
| <TresMesh> | ||
| <TresPlaneGeometry :args="[20, 20, 20]" :rotate-x="-Math.PI / 2" /> | ||
| <TresMeshBasicMaterial color="#f4f4f4" /> | ||
| </TresMesh> | ||
| </RigidBody> | ||
| </Physics> | ||
| </Suspense> | ||
| </TresCanvas> | ||
| </template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable name contains a spelling error: 'legthickness' should be 'legThickness' to follow consistent camelCase naming.