schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

Shape's global contactMaterial? #253

Open issy123 opened 8 years ago

issy123 commented 8 years ago

If I understand it correctly the only way to append friction,restitution and stiffness of a body i need to add a ContactMaterial which needs ShapeA.material and ShapeB.material

Can't I just say this shape has x friction, x restitution and x stiffness?!

I can't create a contact material for each and every single shape or body, that isn't even practical. If a shape is jelly-ish, it's not jelly-ish for a single shape but for everything that comes in contact with that shape.

schteppe commented 8 years ago

At the moment, that is correct.

I've implemented per-shape friction + restitution in Cannon.js, which seem to work well. In that case, the final friction value is the product of the two friction values from the shapes. I guess it should be pretty easy to get this into p2!

issy123 commented 8 years ago

So you mean you can make it so it will be like other physics engines for example box2d. You can set the restitution and friction on each body.

If so that would be awesome!

I tried box2d port but it has either lack of documentation or memory leaks/bugs

schteppe commented 8 years ago

Yep.

You're right about the box2d ports, they aren't that good. Some of them don't contain all the features from the original project either. But that's where p2 comes in ^^

issy123 commented 8 years ago

Yeah I like p2.js, I made duals.io with it. And have more plans with p2js.

I thought cannon.js is something different. Would be easier for me to understand it if it was named p3.js

If it is p3js people using p3js could recommend p2js because of the experience with p3js and vice versa.

Keep me posted when this issue is fixed

schteppe commented 8 years ago

Wow, duals.io looks really cool! But I see you built it using pixi.js, but I see no p2.js in the client? Maybe it's only server side?

p3.js would be a nice name for Cannon.js yes but I think it's too late to switch now...

issy123 commented 8 years ago

Thanks! Yes only the server side is made with p2js. It's built in nodejs.

Client is only responsible for rendering data.

Its never too late.

And you could add a little note: Looking for 2d physics? try p2.js! Can also be applied to p2.js Looking for 3d physics? try p3.js!

schteppe commented 8 years ago

Sounds kinda good :) I'll add at least add links between cannon and p2 in their readme's in any case.

By the way, let's keep this issue open until per-shape friction/restitution has been implemented. Not sure when I have time enough to get this into p2 but hopefully soon.

And-re commented 7 years ago

@schteppe is there any update for this?

schteppe commented 7 years ago

No, not really, sorry. If you want to contribute and need some help to get started, here's the commit that added per-shape friction/restitution to cannon: https://github.com/schteppe/cannon.js/commit/0418abe8ee987c64052bb0bfaa0ede0ab577b111

And-re commented 7 years ago

Thanks for the reply. I just decided to try P2 after I had some problems with Matter JS https://github.com/liabru/matter-js/issues/394 I created a similar prototype in P2 and it seems to work but adding materials for every shape and ContactMaterials for every material pair is a little bit annoying http://codepen.io/and_re/pen/evrgLG?editors=0010

Is there any p2@next version available on npm with the code from the master branch?

schteppe commented 7 years ago

I agree... No, not yet. I guess you could point your package.json directly to Github. Just make sure that p2 gets rebuilt before you use the stuff in build/ though.