285 lines
8.9 KiB
Lua
285 lines
8.9 KiB
Lua
|
|
-- cgltf.lua (Part 1)
|
||
|
|
local ffi = require("ffi")
|
||
|
|
local cgltf = {}
|
||
|
|
local C = ffi.C
|
||
|
|
|
||
|
|
--[[
|
||
|
|
Public API Functions (from cgltf.h)
|
||
|
|
Part 1: top-level parsing & freeing
|
||
|
|
]]
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse(const cgltf_options* options, const void* data, size_t size, cgltf_data** out_data)
|
||
|
|
function cgltf.cgltf_parse(options, data, size, out_data)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_file(const cgltf_options* options, const char* path, cgltf_data** out_data)
|
||
|
|
function cgltf.cgltf_parse_file(options, path, out_data)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_load_buffers(const cgltf_options* options, cgltf_data* data, const char* path)
|
||
|
|
function cgltf.cgltf_load_buffers(options, data, path)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void cgltf_free(cgltf_data* data)
|
||
|
|
function cgltf.cgltf_free(data)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_validate(const cgltf_data* data)
|
||
|
|
function cgltf.cgltf_validate(data)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- Helper function: allocate out-param pointer if needed
|
||
|
|
-- Usage pattern:
|
||
|
|
-- local out_ptr = ffi.new("cgltf_data*[1]")
|
||
|
|
-- cgltf.cgltf_parse(options, data, size, out_ptr)
|
||
|
|
-- local result_data = out_ptr[0]
|
||
|
|
|
||
|
|
-- cgltf.lua (Part 2)
|
||
|
|
--[[
|
||
|
|
Internal JSON Parsing Helpers
|
||
|
|
Part 2: JSON parse functions from cgltf.h implementation
|
||
|
|
]]
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json(const cgltf_options* options, const char* json_data, size_t size, cgltf_data* data)
|
||
|
|
function cgltf.cgltf_parse_json(options, json_data, size, data)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_asset(cgltf_data* data, const void* json_asset)
|
||
|
|
function cgltf.cgltf_parse_json_asset(data, json_asset)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_buffers(cgltf_data* data, const void* json_buffers)
|
||
|
|
function cgltf.cgltf_parse_json_buffers(data, json_buffers)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_buffer_views(cgltf_data* data, const void* json_buffer_views)
|
||
|
|
function cgltf.cgltf_parse_json_buffer_views(data, json_buffer_views)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_accessors(cgltf_data* data, const void* json_accessors)
|
||
|
|
function cgltf.cgltf_parse_json_accessors(data, json_accessors)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_nodes(cgltf_data* data, const void* json_nodes)
|
||
|
|
function cgltf.cgltf_parse_json_nodes(data, json_nodes)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_meshes(cgltf_data* data, const void* json_meshes)
|
||
|
|
function cgltf.cgltf_parse_json_meshes(data, json_meshes)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_materials(cgltf_data* data, const void* json_materials)
|
||
|
|
function cgltf.cgltf_parse_json_materials(data, json_materials)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_textures(cgltf_data* data, const void* json_textures)
|
||
|
|
function cgltf.cgltf_parse_json_textures(data, json_textures)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_images(cgltf_data* data, const void* json_images)
|
||
|
|
function cgltf.cgltf_parse_json_images(data, json_images)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_samplers(cgltf_data* data, const void* json_samplers)
|
||
|
|
function cgltf.cgltf_parse_json_samplers(data, json_samplers)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_skins(cgltf_data* data, const void* json_skins)
|
||
|
|
function cgltf.cgltf_parse_json_skins(data, json_skins)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_cameras(cgltf_data* data, const void* json_cameras)
|
||
|
|
function cgltf.cgltf_parse_json_cameras(data, json_cameras)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_nodes_extra(cgltf_data* data, const void* json_nodes)
|
||
|
|
function cgltf.cgltf_parse_json_nodes_extra(data, json_nodes)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf.lua (Part 3)
|
||
|
|
--[[
|
||
|
|
Internal Buffer, Accessor, and Image Helpers
|
||
|
|
Part 3: data-loading functions from cgltf.h implementation
|
||
|
|
]]
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_mesh_primitives(cgltf_data* data, const void* json_primitives)
|
||
|
|
function cgltf.cgltf_parse_json_mesh_primitives(data, json_primitives)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_accessor_data(cgltf_data* data, const void* json_accessors)
|
||
|
|
function cgltf.cgltf_parse_json_accessor_data(data, json_accessors)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_buffer_view_data(cgltf_data* data, const void* json_buffer_views)
|
||
|
|
function cgltf.cgltf_parse_json_buffer_view_data(data, json_buffer_views)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_buffer_data(cgltf_data* data, const void* json_buffers)
|
||
|
|
function cgltf.cgltf_parse_json_buffer_data(data, json_buffers)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_image_data(cgltf_data* data, const void* json_images)
|
||
|
|
function cgltf.cgltf_parse_json_image_data(data, json_images)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_sampler_data(cgltf_data* data, const void* json_samplers)
|
||
|
|
function cgltf.cgltf_parse_json_sampler_data(data, json_samplers)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_material_data(cgltf_data* data, const void* json_materials)
|
||
|
|
function cgltf.cgltf_parse_json_material_data(data, json_materials)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_skin_data(cgltf_data* data, const void* json_skins)
|
||
|
|
function cgltf.cgltf_parse_json_skin_data(data, json_skins)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_parse_json_camera_data(cgltf_data* data, const void* json_cameras)
|
||
|
|
function cgltf.cgltf_parse_json_camera_data(data, json_cameras)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_load_buffer(cgltf_data* data, cgltf_buffer* buffer, const char* path)
|
||
|
|
function cgltf.cgltf_load_buffer(data, buffer, path)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_load_image(cgltf_data* data, cgltf_image* image, const char* path)
|
||
|
|
function cgltf.cgltf_load_image(data, image, path)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_load_buffers(cgltf_data* data, const char* path)
|
||
|
|
function cgltf.cgltf_load_buffers(data, path)
|
||
|
|
-- TODO: implement
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf.lua (Part 4)
|
||
|
|
--[[
|
||
|
|
Internal Utilities, Helpers, and Final Parsing Methods
|
||
|
|
Part 4: remaining functions from cgltf.h implementation
|
||
|
|
]]
|
||
|
|
|
||
|
|
function cgltf.cgltf_default_alloc(user, cgltf_size size)
|
||
|
|
return ffi.new("uint8_t[?]", size)
|
||
|
|
end
|
||
|
|
|
||
|
|
function cgltf.cgltf_default_free(user, ptr)
|
||
|
|
ffi.free(ptr)
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void* cgltf_allocate(const cgltf_options* options, size_t size)
|
||
|
|
function cgltf.cgltf_allocate(options, size)
|
||
|
|
-- TODO: implement memory allocation logic
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void cgltf_free_memory(const cgltf_options* options, void* ptr)
|
||
|
|
function cgltf.cgltf_free_memory(options, ptr)
|
||
|
|
-- TODO: implement memory free logic
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- const char* cgltf_lookup_string(const void* json_object, const char* key)
|
||
|
|
function cgltf.cgltf_lookup_string(json_object, key)
|
||
|
|
-- TODO: implement string lookup from JSON
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_bool cgltf_json_type_is_valid(int json_type, int expected_type)
|
||
|
|
function cgltf.cgltf_json_type_is_valid(json_type, expected_type)
|
||
|
|
-- TODO: implement JSON type validation
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- cgltf_result cgltf_copy_string(const char* src, char** dst)
|
||
|
|
function cgltf.cgltf_copy_string(src, dst)
|
||
|
|
-- TODO: implement string copy
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void cgltf_default_values(cgltf_data* data)
|
||
|
|
function cgltf.cgltf_default_values(data)
|
||
|
|
-- TODO: implement default value population
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void cgltf_cleanup_extras(cgltf_data* data)
|
||
|
|
function cgltf.cgltf_cleanup_extras(data)
|
||
|
|
-- TODO: implement extras cleanup
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void cgltf_cleanup(cgltf_data* data)
|
||
|
|
function cgltf.cgltf_cleanup(data)
|
||
|
|
-- TODO: implement full cleanup of cgltf_data
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- void cgltf_free(cgltf_data* data) -- final alias to cleanup
|
||
|
|
function cgltf.cgltf_free(data)
|
||
|
|
-- TODO: implement free alias
|
||
|
|
error("not implemented yet")
|
||
|
|
end
|
||
|
|
|
||
|
|
-- Final module return
|
||
|
|
return cgltf
|