36 lines
1 KiB
Lua
36 lines
1 KiB
Lua
local api = ...
|
|
local ecs = api.ecs
|
|
|
|
return {
|
|
name = "3DFile",
|
|
enabled = true,
|
|
|
|
onURI = function(obj)
|
|
if( obj.URL ~= nil and (obj.URLResponse ~= nil or obj.URL.protocol == 'file') and
|
|
(obj.URL.extension == 'GLB' or
|
|
obj.URL.extension == 'GLTF' or
|
|
obj.URL.extension == 'OBJ')) then
|
|
if obj.URLResponse.ok or obj.URL.protocol == 'file' then
|
|
obj.root = false
|
|
if obj.URI.target == '_top' then
|
|
obj.root = true
|
|
api.ext.URI.current = obj.URL -- set current url
|
|
end
|
|
obj.x = obj.x or 0
|
|
obj.y = obj.y or 0
|
|
obj.z = obj.z or 0
|
|
obj.scale = obj.scale or 1
|
|
if obj.URL.protocol == 'file' then
|
|
obj.model = api.graphics.newModel( obj.URL.string )
|
|
else
|
|
obj.model = api.graphics.newModel( api.data.newBlob( obj.URLResponse.data) )
|
|
end
|
|
api.ecs.add( api.world, obj )
|
|
obj.commit('on3DFile') -- notify systems
|
|
else
|
|
print("[3DFile] error: could not load " .. obj.URL.string )
|
|
end
|
|
end
|
|
end
|
|
|
|
}
|