Skip to content
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

feat: Joints implementation #150

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

feat: Joints implementation #150

wants to merge 8 commits into from

Conversation

Neosoulink
Copy link
Collaborator

@Neosoulink Neosoulink commented Nov 20, 2024

Summary

This PR introduces the Joints feature.

Joints are one of the advanced features natively available in Rapier.
This PR provides an easy, basic but robust way to deal with it.

Logs

  • Support for Joint types:
    • "fixed" | "spring" | "rope" | "generic" | "spherical" | "prismatic" | "revolute"
  • New components based on the supported joint types (FixedJoint, SphericalJoint, ...)

How to use

Here's a basic implementation example:

<RigidBody
  v-for="(ref, i) in bodyRefs"
  :key="i"
  :ref="ref"
  :type="i === 0 ? 'kinematic' : 'dynamic'"
  :position="[i * 1.5, 0, 0]"
   collider="ball"
 >
  <TresMesh>
    <TresSphereGeometry />
    <TresMeshNormalMaterial />
  </TresMesh>
</RigidBody>

<SphericalJoint
  v-for="(ref, i) in bodyRefs"
  :key="i"
  :bodies="[ref.value?.[0]?.instance, bodyRefs[i - 1]?.value?.[0]?.instance]"
  :params="[
    [-1.1, 0, 0],
    [1.1, 0, 0],
  ]"
/>

Preview

Screen.Recording.2024-11-20.at.2.10.27.AM.mov

Will close #108

@Neosoulink Neosoulink self-assigned this Nov 20, 2024
@Neosoulink Neosoulink marked this pull request as draft November 20, 2024 00:19
@Neosoulink Neosoulink marked this pull request as ready for review December 9, 2024 14:05
@Neosoulink
Copy link
Collaborator Author

Hi @alvarosabu, I just added a base documentation for Joint.
I'd appreciate having your review of it (the Joint implementation in general).

cc: @JaimeTorrealba

@Neosoulink Neosoulink added enhancement New feature or request feature p3-significant High-priority enhancement (priority) labels Dec 10, 2024
@Neosoulink
Copy link
Collaborator Author

Any update on this one?

This PR is waiting for review

Copy link
Member

@JaimeTorrealba JaimeTorrealba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the implementation, But also I would add a composable WDYT? With the same logic

an useJoint() or similar so the people is not force to use it with Tres.js components only

}
},

"cSpell.words": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the settings should be removed here, this is personal to our environments.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it ✅


Joints is an extension feature provided in [Rapier#Joint](https://rapier.rs/docs/user_guides/javascript/joints/). It lets us connect two or more bodies, restricting their movements according to each other.

In **Tres** we can achieve such motion restriction by using one of the available components designed to handle joints:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small one but maybe we need consistency here it all pages should be "Tres.js"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted


<template>
<RigidBody
v-for="(ref, i) in bodyRefs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got a problem, the mental load of this example is high. I would instead, in this page, come with a very basic example, just two rigid Bodies joined (just that). The idea here is that they learn how to use it.

Array.from({ length: 10 }).map(() => shallowRef<ExposedRigidBody>(null)),
)

setInterval(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why setInterval?

And if you decided to use setInterval, please remember to clear the interval in the onUnmouted

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, you're right,

setInterval was used to update the rotation of the first and have that whip effect

}

if (hasParamsError) {
throw new Error(`Invalid "${type}" joint parameters`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe too difficult, but could be said what parameters have problems?

@Neosoulink
Copy link
Collaborator Author

I like the implementation, But also I would add a composable WDYT? With the same logic

an useJoint() or similar so the people is not force to use it with Tres.js components only

I think it possible even to have both features

@JaimeTorrealba
Copy link
Member

I like the implementation, But also I would add a composable WDYT? With the same logic
an useJoint() or similar so the people is not force to use it with Tres.js components only

I think it possible even to have both features

Completely, maybe another PR to be more organized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature p3-significant High-priority enhancement (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Joints
2 participants