So I’ve made a function that uses the information from this post. New image endpoints that can be used in-game! - Updates / Announcements - Developer Forum | Roblox
To create some code that can compress all the texture in your game or a certain directory in your game and revert them back to normal.
-- Example usage:
function extractAssetId(url)
local assetId
-- Check for the "rbxassetid://" format
assetId = url:match("rbxassetid://(%d+)")
if assetId then return assetId end
-- Check for the "http://www.roblox.com/asset/?id=" format
assetId = url:match("www%.roblox%.com/asset/%?id=(%d+)")
if assetId then return assetId end
-- Check for the "rbxthumb://" format and strip "&w=" and everything after it
assetId = url:match("rbxthumb://type=Asset&id=(%d+)&w=")
if assetId then return assetId end
-- Return nil if no match is found
return nil
local prefix="rbxthumb://type=Asset&id="
local size="&w=150&h=150"
--local size="&w=420&h=420"
if game["Run Service"]:IsStudio() then
for i,v in game:GetDescendants() do
if v.ClassName=="Decal" or v.ClassName=="Texture" or v.ClassName=="ParticleEmitter" then
local id=extractAssetId(v.Texture)
if id then
v.Texture=prefix..id..size
end
elseif v.ClassName=="SpecialMesh" and v.TextureId~="" then
local id=extractAssetId(v.TextureId)
if id then
v.TextureId=prefix..id..size
end
elseif v.ClassName=="MeshPart" and v.TextureID~="" then
local id=extractAssetId(v.TextureID)
if id then
v.TextureID=prefix..id..size
end
end
end
end
This version can run during runtime. In my use case I am running it when isStudio to reduce the RAM usage. Smaller textures allow for faster loading and higher framerates. In my use case it reduces the normal RAM usage by 800MB.
This additional version cannot be used during runtime but can be executed via the command console and allows you to toggle the SurfaceAppearances of some assets. Although certain texture assets do not work with the thumbnail endpoint and will return invalid and revert to its normal state.
function extractAssetId(url)
local assetId
-- Check for the "rbxassetid://" format
assetId = url:match("rbxassetid://(%d+)")
if assetId then return assetId end
assetId = url:match("www%.roblox%.com/asset/%?id=(%d+)")
if assetId then return assetId end
assetId = url:match("assetdelivery%.roblox%.com/v1/asset/%?id=(%d+)")
if assetId then return assetId end
assetId = url:match("rbxthumb://type=Asset&id=(%d+)&w=")
if assetId then return assetId end
return nil
end
local prefix="rbxthumb://type=Asset&id="
local size="&w=150&h=150"
if game["Run Service"]:IsStudio() then
for i,v in game:GetDescendants() do
if v.ClassName=="Decal" or v.ClassName=="Texture" or v.ClassName=="ParticleEmitter" then
local id=extractAssetId(v.Texture)
if id then
v.Texture=prefix..id..size
end
elseif v.ClassName=="SpecialMesh" and v.TextureId~="" then
local id=extractAssetId(v.TextureId)
if id then
v.TextureId=prefix..id..size
end
elseif v.ClassName=="MeshPart" and v.TextureID~="" then
local id=extractAssetId(v.TextureID)
if id then
v.TextureID=prefix..id..size
end
elseif v.ClassName=="SurfaceAppearance" and v.ColorMap~="" then
local id=extractAssetId(v.ColorMap)
if id then
v.ColorMap=prefix..id..size
end
end
end
end
To revert back to the normal endpoint change prefix to “rbxassetid://” and size to “”.
Before you run the function in the command line please make a backup of your game, Suggested use is for certain directories of small models and accessories.