-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add more examples: Hinge Vehicle, Gears, Tear constraint, Friction/ContactMaterial #316
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/use-cannon/14P1DA4BT48iXccqeGjkPzUHyCBV |
@@ -0,0 +1,16 @@ | |||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.208.0/containers/typescript-node/.devcontainer/base.Dockerfile |
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.
From #312, you can ignore. I will remove soon.
@@ -0,0 +1,37 @@ | |||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: |
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.
From #312, you can ignore. I will remove soon.
examples/package.json
Outdated
@@ -40,7 +40,7 @@ | |||
"@types/three": "^0.134.0", | |||
"@vitejs/plugin-react-refresh": "^1.3.6", | |||
"typescript": "^4.4.4", | |||
"vite": "^2.6.14", | |||
"vite": "^2.7.2", |
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.
From #312, you can ignore. I will remove soon.
<ConstraintPart | ||
ref={robotRef} | ||
// mass={50} | ||
// type={'Dynamic'} |
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.
@Glavin001 : TODO remove old/commented out code
<Pillar position={[-5, 2.5, -5]} userData={{ id: 'pillar-1' }} /> | ||
<Pillar position={[0, 2.5, -5]} userData={{ id: 'pillar-2' }} /> | ||
<Pillar position={[5, 2.5, -5]} userData={{ id: 'pillar-3' }} /> | ||
<Debug> |
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.
@Glavin001 TODO revert enabling debugging of Raycast Vehicle.
examples/yarn.lock
Outdated
@@ -292,7 +292,7 @@ | |||
integrity sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg== | |||
|
|||
"@react-three/cannon@file:..": | |||
version "4.1.0" | |||
version "4.2.0" |
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.
From #312, you can ignore. I will remove soon.
@@ -24,6 +24,7 @@ const state = { | |||
vehicles: {}, | |||
springs: {}, | |||
springInstances: {}, | |||
constraints: {}, |
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.
I named this constraints
similar to how the postStep
callback was stored in springs
: https://github.com/pmndrs/use-cannon/blob/master/src/worker.js#L389-L391
Ideally I think these all can be renamed to more informative / accurate variable names. It works as is though!
@@ -139,6 +139,7 @@ export type ConstraintTypes = 'PointToPoint' | 'ConeTwist' | 'Distance' | 'Lock' | |||
|
|||
export interface ConstraintOptns { | |||
maxForce?: number | |||
maxMultiplier?: number |
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.
Is maxMultiplier
a good name for this? The inspiration comes from https://github.com/pmndrs/cannon-es/blob/6f11e268d5e196f7f4f5908dbf60ae6365bd6ab6/examples/tear.html#L63-L66
// If this exceeds a limit we disable the constraint. | ||
const multiplier = Math.abs(constraint.equations[0].multiplier) | ||
if (multiplier > maxMultiplier) { | ||
constraint.disable() |
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.
I disabled the constraint instead of removing, so it can be renamed.
- TODO: Not yet implemented would be an event to tell the main thread the worker has disabled the constraint.
Do you think this is a good idea / worthwhile?
Any preference on the API for implementing this event?
pos: [0, 0, 0] as Triplet, | ||
}) | ||
|
||
const ChainLink = ({ children, ...props }: PropsWithChildren<{}>) => { |
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.
Most of this is copied & modified version of https://github.com/pmndrs/use-cannon/blob/master/examples/src/demos/Chain.tsx#L9-L11
With a bit of work they could reuse the same components, with Chain.tsx
not leveraging all of the features to demonstrate tear.
Alternatively, Chain.tsx
and Tear.tsx
could become 1 example with some interactivity.
Let me know your preference.
…at/more-examples
|
||
function PhysicsContent() { | ||
const groundMaterial = { | ||
name: 'ground', |
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.
@Glavin001 : TODO need to add name
to MaterialOptions
type.
There's a lot going on here, can we focus on one example at a time? |
Absolutely, that's the plan. Any specific example/feature I should cherry-pick for review first? I'll start with the Friction example and new feature/change since others are also interested. PR coming soon! |
|
|
maxMultiplier
option to all constraints, which disables constraint when threshold is exceededI'm still learning React-Three-Fiber and Cannon-ES and use-cannon. Appreciate any and all feedback!
I can remove/cherry-pick any of the examples you like. I wanted to learn how to achieve these for myself and figured someone else may find these examples useful, too.
Love these projects! Thank you!