88 lines
3.1 KiB
Lua
88 lines
3.1 KiB
Lua
local util = require('util')
|
|
|
|
app.on('scan_experience', function(exp)
|
|
--print_r(exp)
|
|
end)
|
|
|
|
app.on('scan_experience_file', function(exp)
|
|
local me = app.plugin.convert
|
|
if me.assimp then
|
|
local filetypes_in = app.opts.plugin_convert_assimp_filetypes_in:gsub(" "," ")
|
|
local filetypes_out = app.opts.plugin_convert_assimp_filetypes_out:gsub(" "," ")
|
|
local convert = false
|
|
foreach( util.split( filetypes_in , ' '), function(k,ext)
|
|
ext = ext:gsub("%W", "")
|
|
if exp.path:lower():match( "." .. ext:lower() .. "$") then
|
|
convert = true
|
|
end
|
|
end)
|
|
if convert then
|
|
foreach( util.split( filetypes_out , ' '), function(k,ext)
|
|
ext = ext:gsub("%W", "")
|
|
local outfile = exp.path .. '.' .. ext
|
|
local fullpath = exp.file.fullpath .. '.' .. ext
|
|
local flags = ''
|
|
if ext:lower() == 'glb' then flags = flags .. ' --embed-textures' end
|
|
if not util.fileExist(outfile) then
|
|
print('> assimp export ' .. exp.file.fullpath .. ' ' .. fullpath )
|
|
local ok = os.execute('assimp export ' .. exp.file.fullpath .. ' ' .. fullpath )
|
|
if ok then
|
|
-- notify extra file to plugins
|
|
local stat,err = unix.stat(outfile)
|
|
if not err then
|
|
app.pub("scan_experience_file", nil, util.merge( exp, {
|
|
parent = exp.parent,
|
|
path = outfile,
|
|
url = "/" .. util.stripPath(outfile),
|
|
id = outfile,
|
|
file = {stat=stat, ino = stat:ino(), attr=stat, fullpath=fullpath}
|
|
}))
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
end)
|
|
|
|
app.on('set', function(k,v)
|
|
end)
|
|
|
|
-- this registers the plugin UI
|
|
local plugin = {
|
|
name = "Conversion",
|
|
info = 'Auto-convert (older) 3D fileformats to newer ones, by generating sidecarfiles (foo.x3d.glb e.g.) via <a href="https://assimp.org" target="_blank">assimp</a>',
|
|
opts = {
|
|
{
|
|
key='app.opts.plugin_convert_assimp_filetypes_in',
|
|
title='from filetype',
|
|
info='Space-separated 3D File extensions for assimp to process, <a href="http://lua-users.org/wiki/PatternsTutorial" target="_blank">lua patterns</a> are allowed',
|
|
default = "x3d",
|
|
placeholder = "",
|
|
values=''
|
|
},
|
|
{
|
|
key='app.opts.plugin_convert_assimp_filetypes_out',
|
|
title='to filetype',
|
|
info='Space-separated 3D File extensions for assimp to process, <a href="http://lua-users.org/wiki/PatternsTutorial" target="_blank">lua patterns</a> are allowed',
|
|
default = 'glb',
|
|
values=''
|
|
},
|
|
},
|
|
}
|
|
|
|
if util.cmdExist('assimp') then
|
|
plugin.assimp = true
|
|
local stdout, retstr, retcode = util.execute('assimp listext')
|
|
plugin.filetypes = stdout:gsub(";%*."," ")
|
|
plugin.info = "<br><b class='tag'>assimp detected</b> <br>" .. plugin.info .. '<br><b>Supported filetypes</b>: '
|
|
foreach( util.split( plugin.filetypes, ' '), function(k,ext)
|
|
plugin.info = plugin.info .. '<b class="tag">' .. ext .. '</b> '
|
|
end)
|
|
else
|
|
plugin.info = plugin.info .. "<br><br><b>NOTE:</b> <a href='https://assimp.org' target='_blank'>assimp</a> is not installed on this system: please install."
|
|
|
|
end
|
|
|
|
|
|
return plugin
|