Improve render scripts and formatting

This commit is contained in:
Lewin Kelly 2024-02-04 03:00:11 +00:00
parent 87845e5e97
commit 407318f410
4 changed files with 88 additions and 121 deletions

75
Modules/Render.luau Normal file
View File

@ -0,0 +1,75 @@
local HttpService = game:GetService "HttpService"
local ScriptContext = game:GetService "ScriptContext"
local Players = game:GetService "Players"
local ContentProvider = game:GetService "ContentProvider"
local InsertService = game:GetService "InsertService"
local function post(url: string, body: string)
-- We have to lie about the contentType to avoid being nuked by CORS from the website
game:HttpPost(url, body, true, "text/json")
end
return function(baseUrl: string, thumbnailKey: string)
local Render = {}
function Render.SetupAvatar(
renderType: string,
assetId: string,
characterAppearance: string
)
pcall(function()
ContentProvider:SetBaseUrl(baseUrl)
InsertService:SetAssetUrl(`{baseUrl}/asset?id=%d`)
InsertService:SetAssetVersionUrl(
`{baseUrl}/asset?assetversionid=%d`
)
end)
HttpService.HttpEnabled = true
ScriptContext.ScriptsDisabled = true
print(
`[{game.JobId}] Starting new render for {renderType} ID {assetId}`
)
post(
`{baseUrl}/api/render/update?apiKey={thumbnailKey}&taskID={game.JobId}`,
"Rendering"
)
local player = Players:CreateLocalPlayer(0)
player.CharacterAppearance = baseUrl .. characterAppearance .. assetId
player:LoadCharacter(false)
-- Raise up the character's arm if they have gear.
local gear = player.Backpack:GetChildren()[1]
if gear then
gear.Parent = player.Character
player.Character.Torso["Right Shoulder"].CurrentAngle = math.rad(90)
end
return player
end
function Render.Upload(result: string)
for i = 1, 3 do
local ok, err = pcall(function()
post(
`{baseUrl}/api/render/update?apiKey={thumbnailKey}&taskID={game.JobId}`,
result
)
end)
if ok then
print(`[{game.JobId}] Upload successful! Moving on...`)
break
elseif i == 3 then
print(`[{game.JobId}] An error occurred! ({err}). Giving up...`)
break
end
print(
`[{game.JobId}] An error occurred! ({err}). Uploading again...`
)
end
end
return Render
end

View File

@ -5,7 +5,7 @@ done
echo "Processing libraries..."
darklua process -c dense.json5 ./corescripts/Libraries/Fusion/init.luau ./corescripts/processed/10000001.lua
darklua process -c bundle.json5 ./corescripts/Libraries/Red/init.luau ./corescripts/processed/10000002.lua
darklua process -c dense.json5 ./corescripts/Libraries/Red/init.luau ./corescripts/processed/10000002.lua
echo "Processing other corescripts..."
for file in ./corescripts/luau/[a-z]*.luau; do

View File

@ -1,54 +1,18 @@
-- Avatar v1.1.0
-- This is the thumbnail script for R6 avatars. Straight up and down, with the right arm out if they have a gear.
local baseUrl = _BASE_URL
local thumbnailKey = _THUMBNAIL_KEY
local renderType = _RENDER_TYPE
local assetId = _ASSET_ID
-- Render script for R6 avatars
local ThumbnailGenerator = game:GetService "ThumbnailGenerator"
local ContentProvider = game:GetService "ContentProvider"
local InsertService = game:GetService "InsertService"
local HttpService = game:GetService "HttpService"
local ScriptContext = game:GetService "ScriptContext"
local Render = require "../Modules/Render.luau"(_BASE_URL, _THUMBNAIL_KEY)
pcall(function()
ContentProvider:SetBaseUrl(baseUrl)
InsertService:SetAssetUrl(`{baseUrl}/asset?id=%d`)
InsertService:SetAssetVersionUrl(`{baseUrl}/asset?assetversionid=%d`)
end)
local player =
Render.SetupAvatar(_RENDER_TYPE, _ASSET_ID, `/asset/characterfetch?userID=`)
HttpService.HttpEnabled = true
ScriptContext.ScriptsDisabled = true
print(`[{game.JobId}] Starting new render for {renderType} ID {assetId}`)
game:HttpPost(
`{baseUrl}/api/render/update?apiKey={thumbnailKey}&taskID={game.JobId}`,
"Rendering",
true,
"text/json"
)
local player = game:GetService("Players"):CreateLocalPlayer(0)
player.CharacterAppearance = `{baseUrl}/asset/characterfetch?userID={assetId}`
player:LoadCharacter(false)
-- Raise up the character's arm if they have gear.
local gear = player.Backpack:GetChildren()[1]
if gear then
gear.Parent = player.Character
player.Character.Torso["Right Shoulder"].CurrentAngle = math.rad(90)
end
local clickBody = ThumbnailGenerator:Click("PNG", 2048, 2048, true)
local clickBody = ThumbnailGenerator:Click("PNG", 1680, 1680, true)
print(`[{game.JobId}] Rendered bodyshot`)
player.Character.Torso["Right Shoulder"].CurrentAngle = 0
-- Headshot Camera
local FOV = 52.5
local CameraAngle = player.Character.Head.CFrame
local CameraPosition = CameraAngle
+ CFrame.Angles(0, math.pi, 0).lookVector.unit * 2.75
@ -57,31 +21,12 @@ local Camera = Instance.new "Camera"
Camera.Name = "ThumbnailCamera"
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CoordinateFrame = CFrame.new(CameraPosition.p, CameraAngle.p)
Camera.FieldOfView = FOV
Camera.FieldOfView = 52.5
Camera.Parent = player.Character
workspace.CurrentCamera = Camera
local clickHead = ThumbnailGenerator:Click("PNG", 300, 300, true)
local result = `Completed\n{clickBody}\n{clickHead}`
print(`[{game.JobId}] Rendered headshot`)
for i = 1, 3 do
local ok, err = pcall(function()
game:HttpPost(
`{baseUrl}/api/render/update?apiKey={thumbnailKey}&taskID={game.JobId}`,
result,
true,
"text/json"
)
end)
if ok then
print(`[{game.JobId}] Upload successful! Moving on...`)
break
elseif i == 3 then
print(`[{game.JobId}] An error occurred! ({err}). Giving up...`)
break
end
print(`[{game.JobId}] An error occurred! ({err}). Uploading again...`)
end
Render.Upload(`Completed\n{clickBody}\n{clickHead}`)

View File

@ -1,65 +1,12 @@
-- Avatar v1.1.0
-- This is the thumbnail script for R6 avatars. Straight up and down, with the right arm out if they have a gear.
local baseUrl = _BASE_URL
local thumbnailKey = _THUMBNAIL_KEY
local renderType = _RENDER_TYPE
local assetId = _ASSET_ID
-- Render script for R6 clothing
local ThumbnailGenerator = game:GetService "ThumbnailGenerator"
local ContentProvider = game:GetService "ContentProvider"
local InsertService = game:GetService "InsertService"
local HttpService = game:GetService "HttpService"
local ScriptContext = game:GetService "ScriptContext"
local Render = require "../Modules/Render.luau"(_BASE_URL, _THUMBNAIL_KEY)
pcall(function()
ContentProvider:SetBaseUrl(baseUrl)
InsertService:SetAssetUrl(`{baseUrl}/asset?id=%d`)
InsertService:SetAssetVersionUrl(`{baseUrl}/asset?assetversionid=%d`)
end)
Render.SetupAvatar(_RENDER_TYPE, _ASSET_ID, `/api/render/characterasset?id=`)
HttpService.HttpEnabled = true
ScriptContext.ScriptsDisabled = true
local click = ThumbnailGenerator:Click("PNG", 1680, 1680, true)
print(`[{game.JobId}] Starting new render for {renderType} ID {assetId}`)
game:HttpPost(
`{baseUrl}/api/render/update?apiKey={thumbnailKey}&taskID={game.JobId}`,
"Rendering",
true,
"text/json"
)
local player = game:GetService("Players"):CreateLocalPlayer(0)
player.CharacterAppearance = `{baseUrl}/api/render/characterasset?id={assetId}`
player:LoadCharacter(false)
-- Raise up the character's arm if they have gear.
local gear = player.Backpack:GetChildren()[1]
if gear then
gear.Parent = player.Character
player.Character.Torso["Right Shoulder"].CurrentAngle = math.rad(90)
end
local click = ThumbnailGenerator:Click("PNG", 2048, 2048, true)
local result = "Completed\n" .. tostring(click)
print(`[{game.JobId}] Successfully rendered, moving on...`)
for i = 1, 3 do
local ok, err = pcall(function()
game:HttpPost(
`{baseUrl}/api/render/update?apiKey={thumbnailKey}&taskID={game.JobId}`,
result,
true,
"text/json"
)
end)
if ok then
print(`[{game.JobId}] Upload successful! Moving on...`)
break
elseif i == 3 then
print(`[{game.JobId}] An error occurred! ({err}). Giving up...`)
break
end
print(`[{game.JobId}] An error occurred! ({err}). Uploading again...`)
end
Render.Upload(`Completed\n{click}`)