From 45dbe47d17303050cbea7c2c51e838acfe21c2fb Mon Sep 17 00:00:00 2001 From: sanine-a Date: Tue, 28 Mar 2023 16:35:22 -0500 Subject: add cached mesh loading --- honey/mesh.lua | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'honey/mesh.lua') diff --git a/honey/mesh.lua b/honey/mesh.lua index 430d5c3..e46c399 100644 --- a/honey/mesh.lua +++ b/honey/mesh.lua @@ -1,7 +1,7 @@ -local mesh = {} +local module = {} local gl = honey.gl -setmetatable(mesh, {__index=_G}) -setfenv(1, mesh) +setmetatable(module, {__index=_G}) +setfenv(1, module) local function insertVertex(vertices, attrib, vertex) @@ -54,6 +54,15 @@ function loadFile(filename) end +local meshCache = {} +function loadMesh(filename, index) + if not meshCache[filename] then + meshCache[filename] = loadFile(filename) + end + return meshCache[filename][index] +end + + Mesh = {} Mesh.__index = Mesh @@ -92,4 +101,4 @@ function Mesh.drawElements(self) end -return mesh +return module -- cgit v1.2.1