working version of janusxr src-equivalent
This commit is contained in:
parent
46c21d041e
commit
22a06916f3
7 changed files with 89 additions and 51 deletions
|
|
@ -6,7 +6,7 @@ ecs.init = function()
|
||||||
baseEntify.filter = ecs.rejectAll('commit')
|
baseEntify.filter = ecs.rejectAll('commit')
|
||||||
baseEntify.updatethread = true
|
baseEntify.updatethread = true
|
||||||
function baseEntify:onAdd(obj)
|
function baseEntify:onAdd(obj)
|
||||||
obj.commit = api.util.commit( api.world, api.ecs.requireAll('allowcommit') )
|
obj.commit = api.util.commit( api.world, obj, api )
|
||||||
end
|
end
|
||||||
ecs.addSystem( api.world, baseEntify )
|
ecs.addSystem( api.world, baseEntify )
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ return {
|
||||||
name = "3DFile",
|
name = "3DFile",
|
||||||
enabled = true,
|
enabled = true,
|
||||||
|
|
||||||
loadasset = function(obj)
|
onURI = function(obj)
|
||||||
if( obj.URL ~= nil and obj.URLResponse ~= nil and
|
if( obj.URL ~= nil and obj.URLResponse ~= nil and
|
||||||
(obj.URL.extension == 'GLB' or
|
(obj.URL.extension == 'GLB' or
|
||||||
obj.URL.extension == 'GLTF' or
|
obj.URL.extension == 'GLTF' or
|
||||||
|
|
@ -13,10 +13,10 @@ return {
|
||||||
if obj.URLResponse.ok then
|
if obj.URLResponse.ok then
|
||||||
obj.model = api.graphics.newModel( api.data.newBlob( obj.URLResponse.data) )
|
obj.model = api.graphics.newModel( api.data.newBlob( obj.URLResponse.data) )
|
||||||
obj.root = (obj.URI.target == '_top')
|
obj.root = (obj.URI.target == '_top')
|
||||||
obj.x = 0
|
if obj.x == nil then obj.x = 0 end
|
||||||
obj.y = 0
|
if obj.y == nil then obj.y = 0 end
|
||||||
obj.z = 0
|
if obj.z == nil then obj.z = 0 end
|
||||||
obj.commit() -- notify systems
|
obj.commit('on3DFile') -- notify systems
|
||||||
else
|
else
|
||||||
print("[3DFile] error: could not load " .. obj.URL.string )
|
print("[3DFile] error: could not load " .. obj.URL.string )
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@ return {
|
||||||
|
|
||||||
to = function(URI,refererer, obj)
|
to = function(URI,refererer, obj)
|
||||||
obj = obj or {}
|
obj = obj or {}
|
||||||
print("surfing to " .. URI.url)
|
local msg = "[i] loading"
|
||||||
|
print("[i] loading " .. URI.url)
|
||||||
obj.URL = api.url.parse(URI.url)
|
obj.URL = api.url.parse(URI.url)
|
||||||
obj.URLResponse = {}
|
obj.URLResponse = {}
|
||||||
foreach( api.protocol, function(name, p)
|
foreach( api.protocol, function(name, p)
|
||||||
|
|
@ -35,7 +36,7 @@ return {
|
||||||
data = data,
|
data = data,
|
||||||
headers = headers
|
headers = headers
|
||||||
}
|
}
|
||||||
api.exec( api.ext, 'loadasset', obj)
|
obj.commit('onURI')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,38 +6,63 @@ return {
|
||||||
name = "janusxr",
|
name = "janusxr",
|
||||||
enabled = true,
|
enabled = true,
|
||||||
|
|
||||||
init = function()
|
onURI = function(obj)
|
||||||
JMLLoader = ecs.processingSystem()
|
if obj.URL ~= nil and obj.URLResponse ~= nil and obj.URLResponse.ok then
|
||||||
JMLLoader.updatethread = true
|
local res = obj.URLResponse
|
||||||
JMLLoader.filter = ecs.requireAll('URL', 'method', 'data', 'ok')
|
|
||||||
function JMLLoader:process(req, dt)
|
|
||||||
if req.ok and req.xml == nil then
|
|
||||||
|
|
||||||
-- JML heuristic
|
-- JML heuristic
|
||||||
if req.data.find("<fireboxroom>") or req.data.match("<room[ >]") then
|
if res.data:lower():match("<fireboxroom>") or res.data:lower():match("<room[ >]") then
|
||||||
|
|
||||||
local JML0
|
local JML0
|
||||||
local JML
|
local JML
|
||||||
req.xml = api.parser.xml.newParser()
|
res.xml = api.parser.xml.newParser()
|
||||||
local xmlstr = req.data
|
local xmlstr = res.data
|
||||||
-- cleanup JML0
|
-- cleanup JML0
|
||||||
local JML0 = xmlstr:gsub("[=%w].*<room>","<fireboxroom")
|
local JML0 = xmlstr:gsub(".*<[Rr]oom","<room")
|
||||||
JML0 = JML0:gsub("[=%w]</room>","</room>")
|
JML0 = JML0:gsub("</[Rr]oom>.*","</room>")
|
||||||
util.traverseXML( req.xml:ParseXmlText(JML0), function(node,raw)
|
api.ext.janusxr.loadXML( JML0, res, obj )
|
||||||
print_r(node)
|
|
||||||
end)
|
|
||||||
os.exit()
|
|
||||||
--api.world.add({
|
|
||||||
-- x = 0,
|
|
||||||
-- y = 0,
|
|
||||||
-- z = 0,
|
|
||||||
-- model = req.model,
|
|
||||||
-- req = req
|
|
||||||
--})
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
ecs.addSystem(api.world,JMLLoader)
|
|
||||||
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
loadXML = function(xml,res,obj)
|
||||||
|
print("[i] janusxr: loading JML:\n\n" .. xml .. "\n\n")
|
||||||
|
util.traverseXML( res.xml:ParseXmlText(xml), function(node,raw)
|
||||||
|
if node.tag == 'object' and node.prop.id ~= nil then
|
||||||
|
local protocol = nil
|
||||||
|
foreach( api.protocol, function(name, p)
|
||||||
|
if node.prop.id:match("^"..name) then
|
||||||
|
protocol = p
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
if protocol ~= nil then
|
||||||
|
local newobj = {
|
||||||
|
URI = { url = node.prop.id, method = 'GET' },
|
||||||
|
janusxr = node
|
||||||
|
}
|
||||||
|
api.ext.janusxr.parseProps(node, newobj)
|
||||||
|
api.ecs.add( api.world, newobj )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
|
||||||
|
parseProps = function(node,obj)
|
||||||
|
local me = api.ext.janusxr
|
||||||
|
foreach( node.prop, function(k,v)
|
||||||
|
if k == 'pos' then
|
||||||
|
local xyz = me.parseFloats(v)
|
||||||
|
obj.x = xyz[1]
|
||||||
|
obj.y = xyz[2]
|
||||||
|
obj.z = xyz[3]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end,
|
||||||
|
|
||||||
|
parseFloats = function(s)
|
||||||
|
local t = {}
|
||||||
|
for num in s:gmatch("%S+") do
|
||||||
|
t[#t+1] = tonumber(num)
|
||||||
|
end
|
||||||
|
return t
|
||||||
|
end
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,9 @@ local initECS = function(ecs)
|
||||||
pass:setCullMode('none')
|
pass:setCullMode('none')
|
||||||
pass:draw(
|
pass:draw(
|
||||||
obj['model'],
|
obj['model'],
|
||||||
obj['x'] or 0,
|
obj['x'],
|
||||||
obj['y'] or 0,
|
obj['y'],
|
||||||
obj['z'] or 0,
|
obj['z'],
|
||||||
1, 0, 1, 0, 0, 1)
|
1, 0, 1, 0, 0, 1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,16 @@ util.loaddir( "media", api, api.media )
|
||||||
ecs.init()
|
ecs.init()
|
||||||
api.exec( api.ext, 'init')
|
api.exec( api.ext, 'init')
|
||||||
|
|
||||||
local url='https://coderofsalvation.codeberg.page/xrfragment-haxe/example/assets/example.glb?bar=1&f=2#foo'
|
-- GLB URLS
|
||||||
|
--local url='https://coderofsalvation.codeberg.page/xrfragment-haxe/example/assets/example.glb?bar=1&f=2#foo'
|
||||||
--local url = 'https://codeberg.org/coderofsalvation/xrfragment/raw/branch/main/assets/template/website/website.glb'
|
--local url = 'https://codeberg.org/coderofsalvation/xrfragment/raw/branch/main/assets/template/website/website.glb'
|
||||||
--local url = 'https://codeberg.org/coderofsalvation/xrfragment/raw/branch/main/assets/simple-a.glb'
|
--local url = 'https://codeberg.org/coderofsalvation/xrfragment/raw/branch/main/assets/simple-a.glb'
|
||||||
|
--local url = 'https://xrforge.isvery.ninja/models/zzswz4qlqw8w/model_files/test.xrf.glb'
|
||||||
|
--
|
||||||
|
-- JANUS JML URLS
|
||||||
--local url = 'https://janusxr.org/index.html'
|
--local url = 'https://janusxr.org/index.html'
|
||||||
|
--local url = 'https://snips.sh/f/rHFLg-cewi?r=1' -- cube
|
||||||
|
local url = 'https://snips.sh/f/_U5-XctEVE?r=1' -- cube, monkey, scene
|
||||||
|
|
||||||
|
|
||||||
api.ecs.add( api.world, { URI = { url = url, method = 'GET', target = '_top' } })
|
api.ecs.add( api.world, { URI = { url = url, method = 'GET', target = '_top' } })
|
||||||
|
|
|
||||||
22
src/util.lua
22
src/util.lua
|
|
@ -88,14 +88,14 @@ function util.count(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function util.traverse(arr, cb, key)
|
function util.traverse(arr, cb, key, parent)
|
||||||
if key == nil then key = 'children' end
|
if key == nil then key = 'children' end
|
||||||
foreach( arr, function(k,child)
|
foreach( arr, function(k,child)
|
||||||
if type(child) == 'table' then
|
if type(child) == 'table' then
|
||||||
cb(child)
|
cb(child,parent)
|
||||||
if type(child[key]) == 'table' then
|
if type(child[key]) == 'table' then
|
||||||
if child[key][1] then
|
if child[key][1] then
|
||||||
util.traverse( child[key], cb, key )
|
util.traverse( child[key], cb, key, child )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -104,16 +104,21 @@ end
|
||||||
|
|
||||||
function util.traverseXML( parsedXml, cb)
|
function util.traverseXML( parsedXml, cb)
|
||||||
util.traverse( parsedXml,
|
util.traverse( parsedXml,
|
||||||
function(node)
|
function(node, parent)
|
||||||
local struct = { tag = '?', prop = {} }
|
local struct = { tag = '?', prop = {} }
|
||||||
if node['name'] ~= nil then struct['tag'] = node:name() end
|
if node['name'] ~= nil then struct['tag'] = node:name():lower() end
|
||||||
foreach( node['___props'], function(k,v)
|
foreach( node['___props'], function(k,v) -- move to props array
|
||||||
local val = node[ '@' .. v['name'] ]
|
local val = node[ '@' .. v['name'] ]
|
||||||
if type(val) == "table" then
|
if type(val) == "table" then
|
||||||
foreach( val, function(k,v) val = v end) -- pick last
|
foreach( val, function(k,v) val = v end) -- pick last
|
||||||
end
|
end
|
||||||
struct['prop'][ v['name'] ] = val
|
struct['prop'][ v['name'] ] = val
|
||||||
end)
|
end)
|
||||||
|
if parent ~= nil then
|
||||||
|
struct['parent'] = (function(parent)
|
||||||
|
return function() return parent end
|
||||||
|
end)(parent)
|
||||||
|
end
|
||||||
cb(struct,raw)
|
cb(struct,raw)
|
||||||
end,
|
end,
|
||||||
'___children'
|
'___children'
|
||||||
|
|
@ -162,8 +167,8 @@ end
|
||||||
-- recalculate filters for tiny-ecs systems
|
-- recalculate filters for tiny-ecs systems
|
||||||
-- usage: entity.commit = util.commit(api.world) -- once
|
-- usage: entity.commit = util.commit(api.world) -- once
|
||||||
-- entity.commit() -- this recalculates the filtercache of systems
|
-- entity.commit() -- this recalculates the filtercache of systems
|
||||||
util.commit = function(world)
|
util.commit = function(world, obj, api)
|
||||||
return function()
|
return function(extCb)
|
||||||
for j = 1, #world.entities do
|
for j = 1, #world.entities do
|
||||||
local system = world.systems[j]
|
local system = world.systems[j]
|
||||||
system.entities = {}
|
system.entities = {}
|
||||||
|
|
@ -174,6 +179,7 @@ util.commit = function(world)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
api.exec( api.ext, extCb, obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue