88 lines
2.4 KiB
Plaintext
Executable File
88 lines
2.4 KiB
Plaintext
Executable File
|
|
source = get_param("input")
|
|
outputFile = get_param("output")
|
|
|
|
|
|
if source == "" then
|
|
print("NO SOURCE")
|
|
end
|
|
|
|
print(source)
|
|
print(outputFile)
|
|
|
|
imageNumber = 1
|
|
|
|
-----------------------------------------------------------------------------
|
|
-- Functions
|
|
-----------------------------------------------------------------------------
|
|
|
|
function extract_recursive( path, srcName, isOccluder )
|
|
|
|
-- Don't actually process any mesh files until we hit a directory that matches the
|
|
-- naming convention.
|
|
if (string.find(srcName, "_occ.")) then
|
|
isOccluder = 1
|
|
end
|
|
|
|
-- Scan all files inside the archive
|
|
|
|
local files = find_files( path .. "\\" .. "*.*" )
|
|
for key, value in files do
|
|
|
|
-- If it's a .mesh file, add it to the list.
|
|
local input = path .. "\\" .. value
|
|
local inputExt = string.lower(get_extension_from_path(value))
|
|
|
|
if (inputExt == ".mesh" and isOccluder == 1) then
|
|
print ("Adding file " .. input )
|
|
load_occ_meshes ( input )
|
|
end
|
|
|
|
-- Dig into any sub-archives we can find here.
|
|
if (inputExt == ".zip" or inputExt == ".rpf") then
|
|
|
|
-- Copy it to a temporary file since we can't handle nested compressed ZIPs.
|
|
local tempZipFile = "tempArchive" .. imageNumber .. ".$$$.zip"
|
|
copy_file(input, tempZipFile)
|
|
|
|
local mountPointName = "image" .. imageNumber .. ":/"
|
|
imageNumber = imageNumber + 1
|
|
mount_pack(tempZipFile, mountPointName)
|
|
extract_recursive(mountPointName, input, isOccluder)
|
|
|
|
-- Don't unmount the archive yet, we'll need it until we call save_occ_imap().
|
|
-- Note that we're technically leaking archives here, but does that really matter? Nah.
|
|
end
|
|
|
|
-- Now look into sub-directories inside this archive.
|
|
local dirs = find_dirs( path )
|
|
for key, value in dirs do
|
|
|
|
local dir = path .. "\\" .. value
|
|
extract_recursive( dir )
|
|
end
|
|
end
|
|
end
|
|
|
|
function clean_up_temp_files()
|
|
while (imageNumber > 1) do
|
|
imageNumber = imageNumber - 1
|
|
local tempZipFile = "tempArchive" .. imageNumber .. ".$$$.zip"
|
|
del_file(tempZipFile)
|
|
end
|
|
end
|
|
|
|
|
|
-----------------------------------------------------------------------------
|
|
-- Entry-Point
|
|
-----------------------------------------------------------------------------
|
|
|
|
set_platform("independent")
|
|
|
|
mount_pack(source, "image:/")
|
|
extract_recursive( "image:/", source, 0 )
|
|
save_occ_imap( outputFile )
|
|
unmount_pack(source)
|
|
|
|
clean_up_temp_files()
|