From baf73c6c18c6052c057f053e5ec7b720de4e4630 Mon Sep 17 00:00:00 2001 From: Lewin Kelly Date: Sun, 4 Feb 2024 03:00:11 +0000 Subject: [PATCH] Improve render scripts and formatting --- Modules/Render.luau | 75 ++++++++++++++++++++++++++++++++++++++++ compile.sh | 2 +- luau/renderAvatar.luau | 69 ++++-------------------------------- luau/renderClothing.luau | 63 +++------------------------------ 4 files changed, 88 insertions(+), 121 deletions(-) create mode 100644 Modules/Render.luau diff --git a/Modules/Render.luau b/Modules/Render.luau new file mode 100644 index 0000000..27fd5a6 --- /dev/null +++ b/Modules/Render.luau @@ -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 diff --git a/compile.sh b/compile.sh index 908b4a5..b2bc33c 100644 --- a/compile.sh +++ b/compile.sh @@ -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 diff --git a/luau/renderAvatar.luau b/luau/renderAvatar.luau index ad1f7a9..477ef29 100644 --- a/luau/renderAvatar.luau +++ b/luau/renderAvatar.luau @@ -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}`) diff --git a/luau/renderClothing.luau b/luau/renderClothing.luau index c5e0520..5908ddb 100644 --- a/luau/renderClothing.luau +++ b/luau/renderClothing.luau @@ -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}`)