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

Custom mesh and softbodies #43

Open
circlegarage opened this issue Jan 17, 2013 · 21 comments

Comments

Projects
None yet
5 participants
@ghost
Copy link

commented Jan 17, 2013

First of all, many compliments for the awesome work.

Just two questions:

  • is it possible to connect cannon.js physics to three.js imported mesh (e.g. exported from blender)?
  • playing with demo/examples i've seen you implemented springs and dampers and going deep into code also masses. The question is do you think is it possible to have softbody physics implemented in this way? I mean vertexs deformation and not only faces deformation.

many thanks and again great work!

@schteppe

This comment has been minimized.

Copy link
Owner

commented Jan 17, 2013

Hi!
Out of the box, it is not possible to import meshes with cannon.js like that. Here's a related project though, it's able to export a scene from Blender, load into Three.js and then create a Cannon.js scene. Works with boxes at the moment.

Cannon.js does not have support for arbitrary trimeshes. It does only support convex meshes, boxes, spheres, particles, and assembled shapes.
I'd like to recommend you to make a simplified physics model for any object you want to simulate. That way you can improve performance greatly. There are very few cases you want to use the same geometry for physics as for rendering. (insert joke about spherical cows in vacuum here)

I haven't studied soft body dynamics, only rigid, so I can't answer your second question. However, you may be able to do what you want using constrained particles, each particle being a vertex. Have a look at the "3D cloth structure" scene in the constraints demo. Try using a less stiff constraint (set solver.k to a smaller value) and make sure to render the constraints to see what is really happening.

Thank YOU for looking into my project :)

@kmcminn

This comment has been minimized.

Copy link

commented Jan 21, 2013

I haven't tried this but I assumed that using child or parent geometries (natively or via another object relationship) on your mesh would work?

@ghost

This comment has been minimized.

Copy link
Author

commented Jan 23, 2013

mmmhhh ideas:

  • closed cloth. Many 3d gaming editor that support Physix allow to use this kind of object playing with pressure and density you can achieve poor results but at least is better than nothing. @schteppe do you think could be possible to build a closed cloth...than maybe playing with constraints between opposite point regulated by k and d to have a simila effect?
  • the other option could be: import a mesh with three.js (thanks for the link example), than assign to every (or part of, for performance issues) vertex a particle, than connect them with constraints (again :) ) and play with spring and dumper....

IMHO these could be the two solution to work with. I tried to have a little mesh with particles but the big problem is that i can achieve a very poor level of performance. Do you think that using a webworker the simulation could be faster?

thanks

@schteppe

This comment has been minimized.

Copy link
Owner

commented Jan 23, 2013

The effect you would get by making a closed cloth and constraining the vertices (particles) with distance constraints to each other and e.g. the center of the shape, would be interesting to see. You should be able to control the softness of the body with the spring parameters to make it behave like you want.
This solution has a few drawbacks. For example: how to create concave shapes this way?
And another thing: the shape created will not have a surface, just particle vertices. If you try to collide two of these, they will just fall through each other. Other shapes that does not fall in between the particles would be fine though.

Running the simulation in a separate thread may increase the total performance of your app. You still have to exchange data in between threads though, that may slow down. Have a look at how Chandler did it in Physijs.

@schteppe

This comment has been minimized.

Copy link
Owner

commented Jan 29, 2013

How's it going with your soft bodies and meshes?
I was wondering what is your goal with the soft bodies? Do you want to simulate a pillow? A deformable car wheel? Maybe I could help you better if I knew!

@ghost

This comment has been minimized.

Copy link
Author

commented Feb 15, 2013

hei schteppe,

sorry for the delay. What I want is to simulate human organs, so something similar to jelly bodies. I was wondering to implement a sort of "central bone" in a custom mesh as you were already thinking, but not a single point (the centrer of the shape). Than constraining the bone to the external points on the surface of the mesh. IMHO in this way we could achieve a good level of realism. The problem is that cannon.js doesn't support meshes other than convex or basic geometries...

I tried using your constraints demo to increment the points in a very simple way (having as a result a long parellelepiped) and results are encouraging.

Thinking about a simple cube we could already have soft bodies simulation just incrementing the total number of constrained points of the cube surfaces...problem is that constraints are very time consuming....

Next step is to grasp the object to perform drag&drop operations.

Now I'm using Unity3D, but I'm very disappointed by the Physix system....(objects trough others for example is very disppointing) and I was considering to use cannon.js

Thanks schteppe!!!

@ghost

This comment has been minimized.

Copy link
Author

commented Feb 15, 2013

just as a brief example, check this out:

http://egraether.com/demos/soft/index.html

@schteppe

This comment has been minimized.

Copy link
Owner

commented Feb 15, 2013

Hi again,
What about using a rigid body as center bone and constraining particles to its surface? That would for sure be possible to do. How this should look geometrically is still a question to me though...
Anyway, to do this, first construct the center bone body. Could be a CANNON.Cylinder or similar. Then use CANNON.PointToPointConstraint to connect particles to the center bone surface. In this case, the "pivotA" vector goes from the center of mass in the bone to a point on its surface. The second pivot vector should go from the particle to the same point on the bone.
The center bone does not have to be a cylinder either. You could set it to be a cube or anything. You're still able to connect any point inside or outside it to a particle pivot point using the PointToPointConstraint.
Not sure if all this is understandable... Point is that you don't have to constrain the particles to one center of mass. Maybe I should make you a simple drawing to be able to explain better?

By the way, cool demo :D

@ghost

This comment has been minimized.

Copy link
Author

commented Mar 1, 2013

@schteppe mmhhhhh i think i'm not completely understand. Could you give me some code snippets to make some tests?

thanks bro!

@schteppe

This comment has been minimized.

Copy link
Owner

commented Mar 12, 2013

I'm swamped at the moment, but will try to find some time.
I really love the demo, it's awesome :) Just wish there were settings for spring stiffness and solver etc.

@ghost

This comment has been minimized.

Copy link
Author

commented Apr 9, 2013

ehi schteppe any news on this?

@schteppe

This comment has been minimized.

Copy link
Owner

commented Apr 10, 2013

No, sorry.

@bnolan

This comment has been minimized.

Copy link

commented Jul 18, 2014

Hey @schteppe, any plans to add custom trimeshes to cannon.js? I'd prefer not to use ammo.js since it's so massive, and all I really need is collision detection for my FPS. Is there a way this could be developed? How would you recommend I start out?

@schteppe

This comment has been minimized.

Copy link
Owner

commented Jul 18, 2014

I don't like trimeshes because they have bad performance and need small timesteps to function properly. Game devs start using them but quickly switch to convexes (or other primitives) instead, to get better performance.

Because of this, I've not prioritized trimeshes much. There are other things needed in Cannon that are more important.

What do you need the trimesh for? Maybe you can construct your game physics some other way?

If you really want a trimesh implementation, you can start off with a simple case such as Trimesh/sphere. A first implementation could naively loop over all faces and edges in the trimesh and check for intersections with the sphere. A more optimized version would include a hierarchical volume tree to cut down the number of triangle intersection tests.

@bnolan

This comment has been minimized.

Copy link

commented Jul 23, 2014

Okay, thanks for the pointers. I'm trying to creating really simple walkthrough visualizations of sketchup architectural models. I've found the HACD library for decomposing meshes into convex hulls. I'll try it out and see if I can get it to work with cannon.js. Thanks for your pointers.

@lazd

This comment has been minimized.

Copy link

commented Aug 21, 2014

@bnolan, did you end up getting HACD to work with Cannon?

@bnolan

This comment has been minimized.

Copy link

commented Aug 25, 2014

Hey Larry,

I couldn’t get hacd to accurately map my model (the barcelona pavillion), so I never got to try it with cannon.

Ben

On 22/08/2014, at 6:41 am, Larry Davis notifications@github.com wrote:

@bnolan, did you end up getting HACD to work with Cannon?


Reply to this email directly or view it on GitHub.

@bnolan

This comment has been minimized.

Copy link

commented Nov 16, 2014

I'm getting to the point where I might try implementing mesh support. Even if it's really slow to start with, it'd help me out a lot, and I think we maybe be able to use bxh as an acceleration structure.

@bnolan

This comment has been minimized.

Copy link

commented Nov 16, 2014

Ok, so I had a bit more of a play with HACD and successfully created a mesh. @schteppe, how did you convert the .wrl output from testHACD into the .js description you use for the bunny demo? I tried using meshconv, but if doesn't keep the group information from the hacd output, just making one big mesh which is kind of useless.

@schteppe

This comment has been minimized.

Copy link
Owner

commented Nov 17, 2014

@bnolan Awesome! Please let me know how it goes. Can you point me to your fork if you start working on the new mesh shape?

It was a while ago, I think I did it manually by copy pasting and applying some text editor magic tricks. The .js file format I produced is not standard in any way.

@schteppe

This comment has been minimized.

Copy link
Owner

commented Dec 6, 2014

@bnolan I added trimesh support along with plane collisions recently. No bvh structure yet though, but at least the basic stuff is there. b45172f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.