chandlerprall / Physijs

Physics plugin for Three.js
MIT License
2.77k stars 455 forks source link

Physijs.TorusMesh needed (matches THREE.TorusGeometry) #273

Closed KasparLee closed 8 years ago

KasparLee commented 8 years ago

According to the Wiki Page, there is no Physijs.TorusMesh to match THREE.TorusGeometry.

I need this because I have a THREE.TorusGeometry. Currently I am using Physijs.ConvexMesh, is this what I should be using?

ghost commented 8 years ago

@Druzion you are right, Physijs.ConvexMesh is what you should be using. If you look at the shapes example you will see it in action.

KasparLee commented 8 years ago

@xprogram Yes, this does create the Torus, however this happens:

13 14

As you can see, it seems there is a Box around the Mesh, and I do not understand why this is happening. Here is the code I used to create it:

Player = new Physijs.ConvexMesh(
    new THREE.TorusGeometry(10, 3, 32, 32),
    new THREE.MeshPhongMaterial({color: 0xFF0000, shininess: 300}),
    10000
)

Is this a Physijs bug?

ghost commented 8 years ago

Actually, it is not a Physijs bug. That's just how it is supposed to be defined.

A convex shape is a shape where all of its angles are less than 180 degrees (defintion). In this case the torus geometry is actually concave because of the hole in the middle. When you add the mesh to the world, it is just the vertices that are passed through to Ammo.js. It doesn't need the triangles, it will build the convex representation with only points.

I don't know if u got that, but the point is unless you want a real torus collision system, you need to use Physijs.ConcaveMesh, but that one can't move (only used for scenery).

You could of course use a concave shape decomposition algorithm. Basically it transforms a concave shape (your torus) into a bunch of smaller convex shapes. You would then build a moving torus with those small shapes. I can't really point you to a good one, but I'm sure you'll find something.

KasparLee commented 8 years ago

Cool, thank you @xprogram. I did want to use it to move, maybe for a wheel, but I found out that as a Physijs.ConcaveMesh it will not work. I'll try and find a decomposition algorithm. Thanks!

ghost commented 8 years ago

No problem. Happy coding.