Merge branch 'master' into tadah

This commit is contained in:
I-Have-An-Issue 2023-02-20 04:25:58 -05:00
commit 5ebbee0e0d
No known key found for this signature in database
GPG Key ID: E55435DEA0825091
6 changed files with 149 additions and 55 deletions

View File

@ -7,3 +7,99 @@ It comes preloaded with some Lua scripts made by kinery and jackd900.
You **will** have to replace/modify these scripts when implementing for your own projects.
Set your desired settings in `.env.example`, then rename it to `.env`.
## Routes
### GET /render/asset/:id
<details>
<summary>200 OK</summary>
```
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
```
</details>
### GET /render/asset/3d/:id
<details>
<summary>200 OK</summary>
```json
{
"camera": {
"position": { "x": 0, "y": 0, "z": 0 },
"direction": { "x": 0, "y": 0, "z": 0 }
},
"AABB": {
"min": { "x": 0, "y": 0, "z": 0 },
"max": { "x": 0, "y": 0, "z": 0 }
},
"files": {
"scene.obj": { "content": "..." },
"scene.mtl": { "content": "..." },
"Handle1Tex.png": { "content": "..." }
}
}
```
</details>
### GET /render/texture/:id
<details>
<summary>200 OK</summary>
```
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
```
</details>
### GET /render/user/headshot/:id
<details>
<summary>200 OK</summary>
```
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
```
</details>
### GET /render/user/bodyshot/:id
<details>
<summary>200 OK</summary>
```
iVBORw0KGgoAAAANSUhEUgAAAtAAAALQCAYAAAC...
```
</details>
### GET /render/user/3d/:id
<details>
<summary>200 OK</summary>
```json
{
"camera": {
"position": { "x": 0, "y": 0, "z": 0 },
"direction": { "x": 0, "y": 0, "z": 0 }
},
"AABB": {
"min": { "x": 0, "y": 0, "z": 0 },
"max": { "x": 0, "y": 0, "z": 0 }
},
"files": {
"scene.obj": { "content": "..." },
"scene.mtl": { "content": "..." },
"Handle1Tex.png": { "content": "..." }
}
}
```
</details>

View File

@ -44,6 +44,8 @@ class RenderJob extends Job {
logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Headshot RenderJob finished for ${id}`)
this.Stop()
if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
@ -84,6 +86,8 @@ class RenderJob extends Job {
if (three_d) logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} 3D Bodyshot RenderJob finished for ${id}`)
else logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Bodyshot RenderJob finished for ${id}`)
this.Stop()
if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
@ -125,6 +129,8 @@ class RenderJob extends Job {
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
}
@ -166,6 +172,8 @@ class RenderJob extends Job {
logger.info(`${chalk.gray(`${chalk.gray(`[${this.id}]`)}`)} Place RenderJob finished for ${id}`)
this.Stop()
if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}
@ -204,6 +212,8 @@ class RenderJob extends Job {
logger.info(`[${this.id}] Headshot RenderJob finished for ${id}`)
this.Stop()
if (!result) return false
return result[0]?.OpenJobExResult?.LuaValue[0]?.value
}

View File

@ -6,27 +6,21 @@ const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const { params, query } = request
const job = new RenderJob()
let body = {}
const asset = await job.RenderAsset(params.id).catch((_) => _)
if (asset?.message) {
job.Stop()
return response.status(500).json({ error: asset.message })
}
body.asset = asset
if (asset?.message) return response.status(500).json({ error: asset.message })
if (query.three_d) {
const three_d = await job.RenderAsset(params.id, true).catch((_) => _)
if (three_d?.message) {
job.Stop()
return response.status(500).json({ error: three_d.message })
}
body.three_d = three_d
}
return response.end(asset)
})
job.Stop()
app.get("/:id/3d", async (request, response) => {
const { params, query } = request
const job = new RenderJob()
return response.json(body)
const three_d = await job.RenderAsset(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

View File

@ -3,12 +3,16 @@ const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const job = new RenderJob()
const result = await job.RenderPlace(request.params.id, process.env.RENDER_BASE64).catch((_) => _)
// app.get("/:id", async (request, response) => {
// const job = new RenderJob()
// const result = await job.RenderPlace(request.params.id, process.env.RENDER_BASE64).catch((_) => _)
if (result?.message) return response.status(500).json({ error: result.message })
else return response.end(result)
// if (result?.message) return response.status(500).json({ error: result.message })
// else return response.end(result)
// })
app.get("*", (request, response) => {
response.status(501).end("Not Implemented")
})
module.exports = app

View File

@ -6,18 +6,11 @@ const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const { params, query } = request
const job = new RenderJob()
let body = {}
const texture = await job.RenderTexture(params.id).catch((_) => _)
if (texture?.message) {
job.Stop()
return response.status(500).json({ error: texture.message })
}
body.texture = texture
if (texture?.message) return response.status(500).json({ error: texture.message })
job.Stop()
return response.json(body)
return response.end(texture)
})
module.exports = app

View File

@ -3,37 +3,34 @@ const app = express.Router()
const RenderJob = require("../../lib/classes/RenderJob.js")
app.get("/:id", async (request, response) => {
const { params, query } = request
app.get("/:id/bodyshot", async (request, response) => {
const { params } = request
const job = new RenderJob()
let body = {}
const headshot = await job.RenderHeadshot(params.id).catch((_) => _)
if (headshot?.message) {
job.Stop()
return response.status(500).json({ error: headshot.message })
}
body.headshot = headshot
const bodyshot = await job.RenderBodyshot(params.id).catch((_) => _)
if (bodyshot?.message) {
job.Stop()
return response.status(500).json({ error: bodyshot.message })
}
body.bodyshot = bodyshot
if (bodyshot?.message) return response.status(500).json({ error: bodyshot.message })
if (query.three_d) {
const three_d = await job.RenderBodyshot(params.id, true).catch((_) => _)
if (three_d?.message) {
job.Stop()
return response.status(500).json({ error: three_d.message })
}
body.three_d = three_d
}
return response.end(bodyshot)
})
job.Stop()
app.get("/:id/headshot", async (request, response) => {
const { params } = request
const job = new RenderJob()
return response.json(body)
const headshot = await job.RenderHeadshot(params.id).catch((_) => _)
if (headshot?.message) return response.status(500).json({ error: headshot.message })
return response.end(headshot)
})
app.get("/:id/3d", async (request, response) => {
const { params, query } = request
const job = new RenderJob()
const three_d = await job.RenderBodyshot(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