Difference between revisions of "R3d.ConvexMeshShape"

From GiderosMobile
 
Line 5: Line 5:
  
 
=== Description ===
 
=== Description ===
The ConvexMeshShape class can be used to describe the shape of a convex mesh centered at the origin of the collider.
+
The ConvexMeshShape class can be used to describe the shape of a convex mesh centered at the origin of the collider. An example of a ConvexMeshShape is a disco ball.
  
 
In order to create a ConvexMeshShape, you first need to create an array of PolygonFace to describe each face of your mesh. You also need to have an array with the vertices coordinates and an array with the vertex indices of each face of your mesh. Then, you have to create a PolygonVertexArray with your vertices coordinates and indices array. You also need to specify your array of PolygonFace. Then, you have to create a PolyhedronMesh with your PolygonVertexArray. Once this is done, you can create the ConvexMeshShape by passing your PolyhedronMesh in parameter.
 
In order to create a ConvexMeshShape, you first need to create an array of PolygonFace to describe each face of your mesh. You also need to have an array with the vertices coordinates and an array with the vertex indices of each face of your mesh. Then, you have to create a PolygonVertexArray with your vertices coordinates and indices array. You also need to specify your array of PolygonFace. Then, you have to create a PolyhedronMesh with your PolygonVertexArray. Once this is done, you can create the ConvexMeshShape by passing your PolyhedronMesh in parameter.

Latest revision as of 06:03, 19 December 2025

Supported platforms: Platform android.pngPlatform ios.pngPlatform mac.pngPlatform pc.pngPlatform html5.pngPlatform winrt.pngPlatform win32.png
Available since: Gideros 2019.10

Description

The ConvexMeshShape class can be used to describe the shape of a convex mesh centered at the origin of the collider. An example of a ConvexMeshShape is a disco ball.

In order to create a ConvexMeshShape, you first need to create an array of PolygonFace to describe each face of your mesh. You also need to have an array with the vertices coordinates and an array with the vertex indices of each face of your mesh. Then, you have to create a PolygonVertexArray with your vertices coordinates and indices array. You also need to specify your array of PolygonFace. Then, you have to create a PolyhedronMesh with your PolygonVertexArray. Once this is done, you can create the ConvexMeshShape by passing your PolyhedronMesh in parameter.

The vertex coordinates and indices array are copied into the ConvexMesh. Therefore, you can release the memory of the PolygonVertexArray after the ConvexMesh creation. However, the mesh data is stored inside the ConvexMesh. Therefore, you should not release it until all the ConvexMeshShapes that have been instantiated from it are destroyed
You need to make sure that the mesh you provide is indeed convex
You should provide the simplest possible convex mesh. It means that you need to avoid coplanar faces in your convex mesh shape. Coplanar faces have to be merged together. Remember that convex meshes are not limited to triangular faces, you can create faces with more than three vertices
Meshes with duplicated vertices are not supported. The number of vertices you pass to create the PolygonVertexArray must be exactly the number of vertices in your convex mesh. The PhysicsCommon::createConvexMesh() will also report errors if some faces of your mesh have almost zero area (degenerated face). You will need to fix those errors in order to create the ConvexMesh
When you specify the vertices for each face of your convex mesh, be careful with their order. The vertices of a face must be specified in counter clockwise order as seen from the outside of your convex mesh
You also need to make sure that the origin of your mesh is inside the convex mesh. A mesh with an origin outside the convex mesh is not currently supported by the library

Methods

r3d.ConvexMeshShape.new creates a new collision convex mesh shape

r3d.ConvexMeshShape:setScale scales the collision convex mesh shape