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.updatethread = true
|
||||
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
|
||||
ecs.addSystem( api.world, baseEntify )
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ return {
|
|||
name = "3DFile",
|
||||
enabled = true,
|
||||
|
||||
loadasset = function(obj)
|
||||
onURI = function(obj)
|
||||
if( obj.URL ~= nil and obj.URLResponse ~= nil and
|
||||
(obj.URL.extension == 'GLB' or
|
||||
obj.URL.extension == 'GLTF' or
|
||||
|
|
@ -13,10 +13,10 @@ return {
|
|||
if obj.URLResponse.ok then
|
||||
obj.model = api.graphics.newModel( api.data.newBlob( obj.URLResponse.data) )
|
||||
obj.root = (obj.URI.target == '_top')
|
||||
obj.x = 0
|
||||
obj.y = 0
|
||||
obj.z = 0
|
||||
obj.commit() -- notify systems
|
||||
if obj.x == nil then obj.x = 0 end
|
||||
if obj.y == nil then obj.y = 0 end
|
||||
if obj.z == nil then obj.z = 0 end
|
||||
obj.commit('on3DFile') -- notify systems
|
||||
else
|
||||
print("[3DFile] error: could not load " .. obj.URL.string )
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ return {
|
|||
|
||||
to = function(URI,refererer, obj)
|
||||
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.URLResponse = {}
|
||||
foreach( api.protocol, function(name, p)
|
||||
|
|
@ -35,7 +36,7 @@ return {
|
|||
data = data,
|
||||
headers = headers
|
||||
}
|
||||
api.exec( api.ext, 'loadasset', obj)
|
||||
obj.commit('onURI')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,38 +6,63 @@ return {
|
|||
name = "janusxr",
|
||||
enabled = true,
|
||||
|
||||
init = function()
|
||||
JMLLoader = ecs.processingSystem()
|
||||
JMLLoader.updatethread = true
|
||||
JMLLoader.filter = ecs.requireAll('URL', 'method', 'data', 'ok')
|
||||
function JMLLoader:process(req, dt)
|
||||
if req.ok and req.xml == nil then
|
||||
|
||||
-- JML heuristic
|
||||
if req.data.find("<fireboxroom>") or req.data.match("<room[ >]") then
|
||||
|
||||
local JML0
|
||||
local JML
|
||||
req.xml = api.parser.xml.newParser()
|
||||
local xmlstr = req.data
|
||||
-- cleanup JML0
|
||||
local JML0 = xmlstr:gsub("[=%w].*<room>","<fireboxroom")
|
||||
JML0 = JML0:gsub("[=%w]</room>","</room>")
|
||||
util.traverseXML( req.xml:ParseXmlText(JML0), function(node,raw)
|
||||
print_r(node)
|
||||
end)
|
||||
os.exit()
|
||||
--api.world.add({
|
||||
-- x = 0,
|
||||
-- y = 0,
|
||||
-- z = 0,
|
||||
-- model = req.model,
|
||||
-- req = req
|
||||
--})
|
||||
end
|
||||
onURI = function(obj)
|
||||
if obj.URL ~= nil and obj.URLResponse ~= nil and obj.URLResponse.ok then
|
||||
local res = obj.URLResponse
|
||||
-- JML heuristic
|
||||
if res.data:lower():match("<fireboxroom>") or res.data:lower():match("<room[ >]") then
|
||||
local JML0
|
||||
local JML
|
||||
res.xml = api.parser.xml.newParser()
|
||||
local xmlstr = res.data
|
||||
-- cleanup JML0
|
||||
local JML0 = xmlstr:gsub(".*<[Rr]oom","<room")
|
||||
JML0 = JML0:gsub("</[Rr]oom>.*","</room>")
|
||||
api.ext.janusxr.loadXML( JML0, res, obj )
|
||||
end
|
||||
end
|
||||
ecs.addSystem(api.world,JMLLoader)
|
||||
|
||||
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:draw(
|
||||
obj['model'],
|
||||
obj['x'] or 0,
|
||||
obj['y'] or 0,
|
||||
obj['z'] or 0,
|
||||
obj['x'],
|
||||
obj['y'],
|
||||
obj['z'],
|
||||
1, 0, 1, 0, 0, 1)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,10 +30,16 @@ util.loaddir( "media", api, api.media )
|
|||
ecs.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/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://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' } })
|
||||
|
|
|
|||
22
src/util.lua
22
src/util.lua
|
|
@ -88,14 +88,14 @@ function util.count(self)
|
|||
end
|
||||
end
|
||||
|
||||
function util.traverse(arr, cb, key)
|
||||
function util.traverse(arr, cb, key, parent)
|
||||
if key == nil then key = 'children' end
|
||||
foreach( arr, function(k,child)
|
||||
if type(child) == 'table' then
|
||||
cb(child)
|
||||
cb(child,parent)
|
||||
if type(child[key]) == 'table' then
|
||||
if child[key][1] then
|
||||
util.traverse( child[key], cb, key )
|
||||
util.traverse( child[key], cb, key, child )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -104,16 +104,21 @@ end
|
|||
|
||||
function util.traverseXML( parsedXml, cb)
|
||||
util.traverse( parsedXml,
|
||||
function(node)
|
||||
function(node, parent)
|
||||
local struct = { tag = '?', prop = {} }
|
||||
if node['name'] ~= nil then struct['tag'] = node:name() end
|
||||
foreach( node['___props'], function(k,v)
|
||||
if node['name'] ~= nil then struct['tag'] = node:name():lower() end
|
||||
foreach( node['___props'], function(k,v) -- move to props array
|
||||
local val = node[ '@' .. v['name'] ]
|
||||
if type(val) == "table" then
|
||||
foreach( val, function(k,v) val = v end) -- pick last
|
||||
end
|
||||
struct['prop'][ v['name'] ] = val
|
||||
end)
|
||||
if parent ~= nil then
|
||||
struct['parent'] = (function(parent)
|
||||
return function() return parent end
|
||||
end)(parent)
|
||||
end
|
||||
cb(struct,raw)
|
||||
end,
|
||||
'___children'
|
||||
|
|
@ -162,8 +167,8 @@ end
|
|||
-- recalculate filters for tiny-ecs systems
|
||||
-- usage: entity.commit = util.commit(api.world) -- once
|
||||
-- entity.commit() -- this recalculates the filtercache of systems
|
||||
util.commit = function(world)
|
||||
return function()
|
||||
util.commit = function(world, obj, api)
|
||||
return function(extCb)
|
||||
for j = 1, #world.entities do
|
||||
local system = world.systems[j]
|
||||
system.entities = {}
|
||||
|
|
@ -174,6 +179,7 @@ util.commit = function(world)
|
|||
end
|
||||
end
|
||||
end
|
||||
api.exec( api.ext, extCb, obj)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue