/render/clothing
This commit is contained in:
parent
512ef31ffc
commit
bf6636e7c8
|
|
@ -24,6 +24,7 @@ app.use("/render/game", require("./routes/render/game.js"))
|
|||
app.use("/render/texture", require("./routes/render/texture.js"))
|
||||
app.use("/render/user", require("./routes/render/user.js"))
|
||||
app.use("/render/texture", require("./routes/render/texture.js"))
|
||||
app.use("/render/clothing", require("./routes/render/clothing.js"))
|
||||
|
||||
app.use("*", require("./routes/index.js"))
|
||||
|
||||
|
|
|
|||
|
|
@ -213,6 +213,48 @@ class RenderJob extends Job {
|
|||
if (!result) return false
|
||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||
}
|
||||
|
||||
async RenderClothing(id, three_d = false) {
|
||||
this.id = randomUUID()
|
||||
|
||||
const running = this.started
|
||||
if (!running) {
|
||||
const started = await this.Start()
|
||||
if (!started) throw new Error("RCCService failed to start")
|
||||
}
|
||||
|
||||
if (!this.client) await this.CreateClient()
|
||||
|
||||
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Asset RenderJob started for ${id}`)
|
||||
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Asset RenderJob started for ${id}`)
|
||||
|
||||
const result = await this.OpenJobEx({
|
||||
name: this.id,
|
||||
script: await readFile(__dirname + "/../../lua/clothing.lua", { encoding: "utf-8" }),
|
||||
arguments: {
|
||||
LuaValue: [
|
||||
{ type: "LUA_TSTRING", value: this.id },
|
||||
|
||||
{ type: "LUA_TSTRING", value: "Clothing" },
|
||||
{ type: "LUA_TSTRING", value: three_d ? "OBJ" : "PNG" },
|
||||
|
||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_WIDTH },
|
||||
{ type: "LUA_TNUMBER", value: process.env.RENDER_ASSET_HEIGHT },
|
||||
|
||||
{ type: "LUA_TSTRING", value: process.env.BASE_URL },
|
||||
{ type: "LUA_TNUMBER", value: id },
|
||||
],
|
||||
},
|
||||
}).catch((e) => false)
|
||||
|
||||
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Asset RenderJob finished for ${id}`)
|
||||
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Asset RenderJob finished for ${id}`)
|
||||
|
||||
this.Stop()
|
||||
|
||||
if (!result) return false
|
||||
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RenderJob
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
local jobId, type, format, x, y, baseUrl, assetId = ...
|
||||
|
||||
print(("[%s] Started RenderJob for type '%s' with assetId %d"):format(jobId, type, assetId))
|
||||
|
||||
game:GetService("ScriptInformationProvider"):SetAssetUrl(baseUrl .. "/asset/")
|
||||
game:GetService("InsertService"):SetAssetUrl(baseUrl .. "/asset/?id=%d")
|
||||
game:GetService("InsertService"):SetAssetVersionUrl(baseUrl .. "/Asset/?assetversionid=%d")
|
||||
game:GetService("ContentProvider"):SetBaseUrl(baseUrl)
|
||||
game:GetService("ScriptContext").ScriptsDisabled = true
|
||||
|
||||
local Player = game.Players:CreateLocalPlayer(0)
|
||||
Player.CharacterAppearance = ("%s/thumbnail/clothingcharapp/%d"):format(baseUrl, assetId)
|
||||
Player:LoadCharacter(false)
|
||||
|
||||
game:GetService("RunService"):Run()
|
||||
|
||||
Player.Character.Animate.Disabled = true
|
||||
Player.Character.Torso.Anchored = true
|
||||
|
||||
print(("[%s] Rendering ..."):format(jobId))
|
||||
local result = game:GetService("ThumbnailGenerator"):Click(format, x, y, true)
|
||||
print(("[%s] Done!"):format(jobId))
|
||||
|
||||
return result
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
const express = require("express")
|
||||
const app = express.Router()
|
||||
|
||||
const RenderJob = require("../../lib/classes/RenderJob.js")
|
||||
|
||||
app.get("/:id", async (request, response) => {
|
||||
const { params, query } = request
|
||||
const job = new RenderJob()
|
||||
|
||||
const asset = await job.RenderClothing(params.id).catch((_) => _)
|
||||
if (asset?.message) return response.status(500).json({ error: asset.message })
|
||||
|
||||
return response.end(asset)
|
||||
})
|
||||
|
||||
app.get("/:id/3d", async (request, response) => {
|
||||
const { params, query } = request
|
||||
const job = new RenderJob()
|
||||
|
||||
const three_d = await job.RenderClothing(params.id, true).catch((_) => _)
|
||||
if (three_d?.message) return response.status(500).json({ error: three_d.message })
|
||||
|
||||
return response.json(JSON.parse(three_d))
|
||||
})
|
||||
|
||||
module.exports = app
|
||||
Loading…
Reference in New Issue