A Defold library for converting DAE meshes to collision objects.
You can use dae2collision in your own project by adding it as a Defold library dependency. Open your game.project file and in the dependencies field add:
https://github.com/JustAPotota/dae2collision/archive/master.zip
Or point to the ZIP file of a specific release, like https://github.com/JustAPotota/dae2collision/archive/v1.1.1.zip.
This library comes with an editor script (located at /dae2collision/d2c.editor_script
) that adds a context menu option to .dae
files which uses d2c.generate_collision to create a game object with collision objects in the shape of the selected mesh. The collision objects are given default properties which will work for many, but not all, games. If you need custom settings for your game, you can simply make a copy of the included editor script or build your own using one of the two functions provided by the d2c
module:
Reads the .dae
file given by dae_path
and writes the convex shapes from d2c.shapes_from_string() into the same folder. It then generates a game object containing collision objects which use those convex shapes as well as the settings specified in properties
.
- dae_path:
string
- The project path to a.dae
file. - properties:
table
- A table with settings to be applied to the generated collision objects. Its structure is as follows:- mass:
number
- friction:
number
- restitution:
number
- linear_damping:
number
- angular_damping:
number
- locked_rotation:
bool
- bullet:
bool
- group:
string
- mask:
string
- type:
string
- The type of collision object. Can beCOLLISION_OBJECT_TYPE_DYNAMIC
,COLLISION_OBJECT_TYPE_KINEMATIC
,COLLISION_OBJECT_TYPE_STATIC
, orCOLLISION_OBJECT_TYPE_TRIGGER
- mass:
Converts the contents of a .dae
file to an array of convex shapes.
- s:
string
- The contents of a.dae
file.
- shapes:
table
- An array of strings holding the contents of the resulting convex shapes, one per object in the mesh.