local loader = require ("source/libs/obj/obj_loader")

local function modelLoader(path)
	local mesh = {}

	local objdata = loader.load(path) 

	local vertices = objdata.v
	local uvVertices = objdata.vt
	local normalVertices = objdata.vn

	local hasVT = #objdata.vt>0
	local hasVN = #objdata.vn>0

	for i,v in ipairs(objdata.f) do
		for ii,vv in ipairs(v) do
			table.insert(mesh, {
				vertices[vv.v].x, vertices[vv.v].y, vertices[vv.v].z, vertices[vv.v].w,

				hasVT and uvVertices[vv.vt].u or nil, 
				hasVT and 1-uvVertices[vv.vt].v or nil,
				1,1,1,1
				,hasVN and normalVertices[vv.vn].x or nil
				,hasVN and normalVertices[vv.vn].y or nil, 
				 hasVN and normalVertices[vv.vn].z or nil
				})
		end
	end



	return mesh

end

return modelLoader
