diff options
Diffstat (limited to 'honey/ecs/collision.lua')
-rw-r--r-- | honey/ecs/collision.lua | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/honey/ecs/collision.lua b/honey/ecs/collision.lua index 4c8af5b..46028b4 100644 --- a/honey/ecs/collision.lua +++ b/honey/ecs/collision.lua @@ -1,3 +1,4 @@ +local mesh = require 'honey.mesh' local glm = require 'honey.glm' local Vec3 = glm.Vec3 local ode = honey.ode @@ -7,6 +8,18 @@ setmetatable(module, {__index=_G}) setfenv(1, module) +local function loadTriMesh(space, filename) + local attrib, shapes, _ = honey.tinyobj.parse_obj( + filename, honey.tinyobj.FLAG_TRIANGULATE + ) + local vertices, indices = mesh.loadShape(shapes[1], attrib) + + trimeshdata = ode.GeomTriMeshDataCreate() + ode.GeomTriMeshDataBuild(trimeshdata, vertices, indices) + return ode.CreateTriMesh(space, trimeshdata) +end + + --===== collision space =====-- @@ -27,6 +40,8 @@ local function createGeom(self, id, collision) geom = ode.CreatePlane(self.space, normal[1], normal[2], normal[3], d) elseif collision.class == "ray" then geom = ode.CreateRay(self.space, collision.length) + elseif collision.class == "trimesh" then + geom = loadTriMesh(self.space, collision.filename) end ode.GeomSetCategoryBits(geom, collision.category or 1) @@ -44,6 +59,8 @@ end local function isPlaceable(collision) if collision.class == "ray" then return true + elseif collision.class == "trimesh" then + return true end return false end |