Zoom to fit for openscad (#569)

* Add viewall flag to openscad cli in prep for zoom to fit for scad previews

* Fix remaining issues with social image capture
This commit was merged in pull request #569.
This commit is contained in:
Kurt Hutten
2021-11-06 09:46:55 +11:00
committed by GitHub
parent a909188f15
commit 43fc897bf9
12 changed files with 473 additions and 369 deletions

View File

@@ -11,6 +11,7 @@ const cleanOpenScadError = (error) =>
export const runScad = async ({
file,
settings: {
viewAll = false,
size: { x = 500, y = 500 } = {},
parameters,
camera: {
@@ -44,10 +45,13 @@ export const runScad = async ({
const fullPath = `/tmp/${tempFile}/output.gz`
const imPath = `/tmp/${tempFile}/output.png`
const customizerPath = `/tmp/${tempFile}/customizer.param`
const summaryPath = `/tmp/${tempFile}/summary.json` // contains camera info
const command = [
OPENSCAD_COMMON,
`-o ${customizerPath}`,
`-o ${imPath}`,
`--summary camera --summary-file ${summaryPath}`,
viewAll ? '--viewall' : '',
`-p /tmp/${tempFile}/params.json -P default`,
cameraArg,
`--imgsize=${x},${y}`,
@@ -58,14 +62,20 @@ export const runScad = async ({
try {
const consoleMessage = await runCommand(command, 15000)
const params = JSON.parse(
await readFile(customizerPath, { encoding: 'ascii' })
).parameters
const files: string[] = await Promise.all(
[customizerPath, summaryPath].map((path) =>
readFile(path, { encoding: 'ascii' })
)
)
const [params, cameraInfo] = files.map((fileStr: string) =>
JSON.parse(fileStr)
)
await writeFiles(
[
{
file: JSON.stringify({
customizerParams: params,
cameraInfo: viewAll ? cameraInfo.camera : undefined,
customizerParams: params.parameters,
consoleMessage,
type: 'png',
}),