-
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
Enable adding new ContactMaterial to World #64
Comments
I found this issue because I need the |
See comment below |
A ContactMaterial requires two Materials as parameters, but it looks like useBody is what produces each Material. How would you pass the ContactMaterial into useBody without first having references to the Materials upon which it depends? const [planeRef, planeApi, planeMaterial] = usePlane(...)
const [sphereRef, sphereApi, sphereMaterial] = useSphere(...)
useContactMaterial(planeMaterial, sphereMaterial, { restitution: 1 }) |
You're right, I didn't review my original post closely enough and misspoke. But you actually create the materials that you pass into the useBody hooks: const material1 = {...}
const material2 = {...}
const [ref1, api1] = useBox(() => ({ material: material1, ... }))
const [ref2, api2] = useBox(() => ({ material: material2, ... }))
useContactMaterial(material1, material2, { ...options }) |
That's a good point. So in that case I also wonder how it behaves when the objects are empty. Personally, I have no use for the Material properties, I only care about ContactMaterials properties, so I'd be inclined to keep the objects empty. It seems a bit strange to be creating a bunch of variables to hold empty objects (perhaps another argument for making the name or id a requirement). |
Two Materials are required to create a ContactMaterial, but if I remember correctly the only Material property that the ContactMaterial cares about is the id. Cannon sets the ids of Materials and ContactMaterials inside their respective classes using a static counter. I don't think it's a good idea to change the id generation in the Cannon classes. So I think maybe we need a const elasticMaterial = useMaterial(() => ({ name: 'PerfectlyElastic', friction: 0, restitution: 1 }))
const otherMaterial= useMaterial()
const [ ref, api ] = useBox(() => ({ material: elasticMaterial }))
const contactMaterial = useContactMaterial(elasticMaterial, otherMaterial, options) |
Update: #317 has been merged, adding the feature.
@bjornstar is polishing up the worker and example code in #328 before publishing. 🚀 Thanks all for your interest and contributing! The previous discussions and PRs helped make #316 happen. |
Adding multiple ContactMaterials to the World is useful for unique contact equation properties between two specific Materials
The text was updated successfully, but these errors were encountered: