Add mesh render endpoint

This commit is contained in:
cirroskais 2023-09-13 18:49:45 -04:00
parent cd8d56e767
commit cd4c0a20a6
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
4 changed files with 93 additions and 1 deletions

View File

@ -23,8 +23,8 @@ app.use("/render/asset", require("./routes/render/asset.js"))
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("/render/mesh", require("./routes/render/mesh.js"))
app.use("*", require("./routes/index.js"))

View File

@ -256,6 +256,49 @@ class RenderJob extends Job {
if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
async RenderMesh(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 Mesh RenderJob started for ${id}`)
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Mesh RenderJob started for ${id}`)
const result = await this.OpenJobEx({
name: this.id,
script: await readFile(__dirname + "/../../lua/mesh.lua", { encoding: "utf-8" }),
arguments: {
LuaValue: [
{ type: "LUA_TSTRING", value: this.id },
{ type: "LUA_TSTRING", value: "Mesh" },
{ 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 },
{ type: "LUA_TBOOLEAN", value: "true" },
],
},
}).catch((e) => false)
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Mesh RenderJob finished for ${id}`)
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Mesh RenderJob finished for ${id}`)
this.Stop()
if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
}
module.exports = RenderJob

23
src/lua/mesh.lua Normal file
View File

@ -0,0 +1,23 @@
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 meshPart = Instance.new("Part", workspace)
meshPart.Anchored = true
meshPart.Size = Vector3.new(1.5, 1.5, 1.5)
local mesh = Instance.new("SpecialMesh", meshPart)
mesh.MeshType = "FileMesh"
mesh.MeshId = ("%s/asset?id=%d"):format(baseUrl, assetId)
print(("[%s] Rendering ..."):format(jobId))
local result = game:GetService("ThumbnailGenerator"):Click(format, x, y, true)
print(("[%s] Done!"):format(jobId))
return result

26
src/routes/render/mesh.js Normal file
View File

@ -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.RenderMesh(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.RenderMesh(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