diff options
author | sanine <sanine.not@pm.me> | 2023-05-12 01:16:46 -0500 |
---|---|---|
committer | sanine <sanine.not@pm.me> | 2023-05-12 01:16:46 -0500 |
commit | 3275ae4948fd2c1bb8da780214cbb741dc3178be (patch) | |
tree | 69dbf1d5b56896e1212454e5f79daaec1d201ec1 /honey/ecs/collision.lua | |
parent | 14195dac1eda9140192ca07003258715b8b0abd3 (diff) |
begin refactor
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 |