summaryrefslogtreecommitdiff
path: root/honey/ecs
diff options
context:
space:
mode:
authorsanine <sanine.not@pm.me>2023-05-12 01:16:46 -0500
committersanine <sanine.not@pm.me>2023-05-12 01:16:46 -0500
commit3275ae4948fd2c1bb8da780214cbb741dc3178be (patch)
tree69dbf1d5b56896e1212454e5f79daaec1d201ec1 /honey/ecs
parent14195dac1eda9140192ca07003258715b8b0abd3 (diff)
begin refactor
Diffstat (limited to 'honey/ecs')
-rw-r--r--honey/ecs/collision.lua17
-rw-r--r--honey/ecs/render.lua9
2 files changed, 26 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
diff --git a/honey/ecs/render.lua b/honey/ecs/render.lua
index abeac04..1e41e7a 100644
--- a/honey/ecs/render.lua
+++ b/honey/ecs/render.lua
@@ -67,6 +67,15 @@ system = function(params)
(node and node._matrix) or
Mat4():identity()
-- get shader
+ if not tbl.shader then
+ print(node)
+ print(node and node._matrix)
+ print(node and node.name)
+ print(node and node.parent)
+ for k, v in pairs(tbl) do
+ print(k, v)
+ end
+ end
local shader = honey.shader.loadShader(
tbl.shader.vertex, tbl.shader.fragment
)