# Convexhull shape in 3D

Can someone explain how convexhull works in 3D space. So let’s say I have a 4 sided die and an 8 sided die. How can I create a convexhull to be that shape?

I need a collsionobject to match my die, and I can’t find an easy to understand explanation of how this will work in 3D. I understand the 2D version, but I can’t wrap my head around how to do it in 3D space.

It’s very simple. It is a set of vertices in space that create a convex shape. Literally. There are no triangles or lines here. The order is not important. Duplicates or randomly internal vertices do not affect anything, except for the extra volume of data.

To get a cube it is enough to have a set of XYZ vertices in any order:

``````0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
``````

To build 4-sided dice (pyramid?) or 8-sided dice, you should, for example, find a 3D model in OBJ and look at the coordinates of the vertices, because I can’t imagine in my head what coordinates are there.

1 Like

What about connectivity information, defining faces and the body, does Defold work this out, or are they not used and it is just a point cloud?

I’m not sure if this one still works but there is a py script for Blender.
see `defold_mesh.py` in this example: Mesh Component

Here is the discussion:

Also this:

And this:

1 Like

this.
The physics engine will build the planes itself and check for intersection with other entities. But this has a side effect: convexhull shape is not visible in the editor and debug drawing in runtime does not work correctly.

3 Likes

Well that explains why I can’t see any debug lines on the object. So I have no idea if I have the right shape or how I need to fix it.

The debug drawing in runtime just appears as a line strip from the first vertex to the last.

1 Like

Absolutely right. Yes, the debug rendering of Defold draws 3D physics it’s like a set of lines in order, probably since that’s how the debug rendering of 2D physics works.

Well I’m stuck. I can’t see any debug lines at all. ANd clearly these dice aren’t working correctly. Where as my 6 sided dice are perfect. But I used a box collsionobject so it was easier. Can anyone give me a clue?

I have no idea how to debug this issue.

And this is my convexhull.shape file

``````shape_type: TYPE_HULL
data: 0.0
data: 1.0
data: 0.0
data: 1.0
data: 0.0
data: 0.0
data: -1.0
data: 0.0
data: 1.0
data: 0.0
data: -1.0
data: 0.0
``````

I don’t think that shape file describes a regular tetrahedron with its center of gravity at 0,0,0.

Try this one, based on a cube, with this geometric proof from wikipedia:

``````shape_type: TYPE_HULL
data: -1
data: -1
data: -1
data: 1
data: -1
data: 1
data: -1
data: 1
data: 1
data: 1
data: 1
data: -1
``````
2 Likes

Thank for helping but this didn’t change much (see video). Also I’m not sure how would a box shape work for a tetrahedron when I need the dice to be able to lay flat on one of the sides. That is an honest question…I really don’t undestand these convexhulls in 3D especially when I can’t even see the outline of it in defold.

How the heck does one debug convexhull shapes when the debugger doesn’t show anything?

1 Like

Could you share the project? Either here or private

Are you sure the convex hull is correct? I just had a quick test and doesn’t have a issue( is this something you are looking for?))

2 Likes

It would probably make sense to include a set of convex hulls in builtins, for instance a tetrahedron, cone and so on. And the collada files should have gltf counterparts as well. Anyone wanna make a contribution?

2 Likes

I think I’m going to write a small tutorial for exporting convex hull data from Blender using very simple py script(which I use above)

6 Likes

Yes but I’m traveling right now. It may be a week before I can.