Last active
July 1, 2022 23:40
-
-
Save NobleDraconian/3496e2ce66a6e60230263c81f23385b7 to your computer and use it in GitHub Desktop.
Convert all model files in a directory into binary format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local Debug_TabLevel = 0 | |
local function SplitString(inputstr, sep) | |
if sep == nil then | |
sep = "%s" | |
end | |
local t={} | |
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do | |
table.insert(t, str) | |
end | |
return t | |
end | |
local function GetFileExtension(FileName) | |
local SplitFilename = SplitString(FileName, ".") | |
local FileExtension = SplitFilename[#SplitFilename] | |
return FileExtension | |
end | |
local function TrimFileExtension(FileName) | |
local SplitFilename = SplitString(FileName, ".") | |
local TrimmedName = "" | |
for _,StringSegment in ipairs(SplitFilename) do | |
if _ ~= #SplitFilename then | |
TrimmedName = TrimmedName .. StringSegment | |
end | |
end | |
return TrimmedName | |
end | |
local function Log(Message) | |
print(string.rep(" ", Debug_TabLevel) .. Message) | |
end | |
local function ConvertAssetsInFolderToBinary(DirectoryPath) | |
Debug_TabLevel = Debug_TabLevel + 1 | |
Log("Converting assets in folder '" .. DirectoryPath .. "' to binary...") | |
for _,FileName in pairs(remodel.readDir(DirectoryPath)) do | |
if remodel.isDir(DirectoryPath .. "/" .. FileName) then | |
ConvertAssetsInFolderToBinary(DirectoryPath .. "/" .. FileName) | |
else | |
local FileExtension = GetFileExtension(FileName) | |
if FileExtension == "rbxmx" then | |
local TrimmedFileName = TrimFileExtension(FileName) | |
Log("- Converting '" .. DirectoryPath .. "/" .. FileName .. "' to binary...") | |
remodel.writeModelFile(remodel.readModelFile(DirectoryPath .. "/" .. FileName)[1], DirectoryPath .. "/" .. TrimmedFileName .. ".rbxm") | |
Log(" Wrote to '" .. DirectoryPath .. "/" .. TrimmedFileName .. ".rbxm'") | |
end | |
end | |
end | |
Log("Done converting assets in folder '" .. DirectoryPath .. "' to binary.\n") | |
Debug_TabLevel = Debug_TabLevel - 1 | |
end | |
ConvertAssetsInFolderToBinary("Assets/") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment