-
Notifications
You must be signed in to change notification settings - Fork 156
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 Tear constraint example #318
Add Tear constraint example #318
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pmndrs/use-cannon/6CrKqrLJVz6F8vK9yBxS1wtGiUBC |
@bjornstar : I've commented on the code above with questions I'd appreciate your feedback on so I can implement it in a way you're happy with. Hope this helps. Thanks! |
873afcf
to
8c64609
Compare
@bjornstar Ready for final review 🎉 |
src/worker.js
Outdated
@@ -331,12 +332,29 @@ self.onmessage = (e) => { | |||
} | |||
constraint.uuid = uuid | |||
state.world.addConstraint(constraint) | |||
|
|||
if (!isNaN(maxMultiplier)) { |
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.
Please don't use isNaN
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.
OK. Would a truthy check be satisfactory?
if (!isNaN(maxMultiplier)) { | |
if (maxMultiplier) { |
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 above wouldn't support maxMultiplier
being 0
, this may be more appropriate:
if (!isNaN(maxMultiplier)) { | |
if (maxMultiplier !== undefined) { |
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.
Done.
examples/src/demos/Tear.tsx
Outdated
<spotLight position={[10, 10, 10]} angle={0.3} penumbra={1} intensity={1} castShadow /> | ||
<Physics gravity={[0, -40, 0]} allowSleep={false}> | ||
<Handle radius={0.5}> | ||
<Projectile radius={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.
I don't think the Projectile should be inside of the chain.
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.
Can do. This was to ensure the Projectile lines up the shot with the Handle and the Chain Links below it.
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.
Removed projectile entirely in favour of your suggestion:
Can we drag one chain through several other chains that tear?
I'd really prefer not to have cross dependencies between demos. The hallmark of demos is that they are a single file that demonstrate a feature. We should be able to take that file put it in a sandbox with minimal setup. If the two are so similar that they share files, they should be in the same file with some form of interaction. Can we drag one chain through several other chains that tear? How about clicking to reset the torn chains? |
Add maxMultipler threshold to constraints. Inspired by https://github.com/pmndrs/cannon-es/blob/6f11e268d5e196f7f4f5908dbf60ae6365bd6ab6/examples/tear.html
8c64609
to
02f8cbf
Compare
@bjornstar : Pushed new demo/example and other fixes based on your feedback above. Ready for review again. Thanks! |
Cool, I think this turned out quite well. Thanks for the contribution! |
Released in v4.5.0 |
Thanks for merging, @bjornstar ! Next up is #317 (comment) |
Add maxMultipler threshold to constraints.
Inspired by https://github.com/pmndrs/cannon-es/blob/6f11e268d5e196f7f4f5908dbf60ae6365bd6ab6/examples/tear.html
maxMultiplier
option to all constraints, which disables constraint when threshold is exceededpostStep
listener ifmaxMultiplier
set / notundefined
Chain
)maxMultiplier
values0 = blue
/easily break,1500 = red
/harder to break,white = undefined
/won't break)Demo
https://use-cannon-git-fork-glavin001-feat-constraint-max-e97738-pmndrs.vercel.app/#/demo/Chain
Initially:
After breaking some chain constraints: