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

Add more examples: Hinge Vehicle, Gears, Tear constraint, Friction/ContactMaterial #316

Closed
wants to merge 6 commits into from

Conversation

Glavin001
Copy link
Contributor

@Glavin001 Glavin001 commented Dec 20, 2021

Hinge Vehicle Gears Tear Friction
https://use-cannon-git-fork-glavin001-feat-more-examples-pmndrs.vercel.app/#/demo/HingeVehicle https://use-cannon-git-fork-glavin001-feat-more-examples-pmndrs.vercel.app/#/demo/Gears https://use-cannon-git-fork-glavin001-feat-more-examples-pmndrs.vercel.app/#/demo/Tear https://use-cannon-git-fork-glavin001-feat-more-examples-pmndrs.vercel.app/#/demo/Friction
image image image image

I'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!

@vercel
Copy link

vercel bot commented Dec 20, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pmndrs/use-cannon/14P1DA4BT48iXccqeGjkPzUHyCBV
✅ Preview: https://use-cannon-git-fork-glavin001-feat-more-examples-pmndrs.vercel.app

@@ -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
Copy link
Contributor Author

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:
Copy link
Contributor Author

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.

@@ -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",
Copy link
Contributor Author

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'}
Copy link
Contributor Author

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>
Copy link
Contributor Author

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.

@@ -292,7 +292,7 @@
integrity sha512-OWORNpfjMsSSUBVrRBVGECkhWcULOAJz9ZW8uK9qgxD+87M7jHRcvh/A96XXNhXTLmKcoYSQtBEX7lHMO7YRwg==

"@react-three/cannon@file:..":
version "4.1.0"
version "4.2.0"
Copy link
Contributor Author

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: {},
Copy link
Contributor Author

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

// If this exceeds a limit we disable the constraint.
const multiplier = Math.abs(constraint.equations[0].multiplier)
if (multiplier > maxMultiplier) {
constraint.disable()
Copy link
Contributor Author

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<{}>) => {
Copy link
Contributor Author

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.

@Glavin001 Glavin001 marked this pull request as ready for review December 20, 2021 06:37
@Glavin001 Glavin001 changed the title Add more examples Add more examples: Hinge Vehicle, Gears, Tear constraint Dec 20, 2021

function PhysicsContent() {
const groundMaterial = {
name: 'ground',
Copy link
Contributor Author

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.

@Glavin001 Glavin001 changed the title Add more examples: Hinge Vehicle, Gears, Tear constraint Add more examples: Hinge Vehicle, Gears, Tear constraint, Friction/ContactMaterial Dec 22, 2021
@bjornstar
Copy link
Member

There's a lot going on here, can we focus on one example at a time?

@Glavin001
Copy link
Contributor Author

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!

@Glavin001
Copy link
Contributor Author

@Glavin001
Copy link
Contributor Author

@Glavin001 Glavin001 closed this Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants