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

@@ -8,6 +8,7 @@ import {
splitGziped,
} from '../common'
import { openScadToCadhubParams } from './openScadParams'
import type { XYZ, Camera } from 'src/helpers/hooks/useIdeState'
export const render = async ({ code, settings }: RenderArgs) => {
const pixelRatio = window.devicePixelRatio || 1
@@ -19,6 +20,7 @@ export const render = async ({ code, settings }: RenderArgs) => {
const body = JSON.stringify({
settings: {
size,
viewAll: settings.viewAll,
parameters: settings.parameters,
camera: {
// rounding to give our caching a chance to sometimes work
@@ -59,7 +61,21 @@ export const render = async ({ code, settings }: RenderArgs) => {
}
const blob = await response.blob()
const text = await new Response(blob).text()
const { consoleMessage, customizerParams, type } = splitGziped(text)
const { consoleMessage, customizerParams, type, cameraInfo } =
splitGziped(text)
const vecArray2Obj = (arr: number[]): XYZ => ({
x: arr[0],
y: arr[1],
z: arr[2],
})
const camera: Camera = cameraInfo
? {
dist: cameraInfo?.distance,
position: vecArray2Obj(cameraInfo?.translation),
rotation: vecArray2Obj(cameraInfo?.rotation),
isScadUpdate: true,
}
: undefined
return createHealthyResponse({
type: type !== 'stl' ? 'png' : 'geometry',
data:
@@ -67,6 +83,7 @@ export const render = async ({ code, settings }: RenderArgs) => {
? blob
: await stlToGeometry(window.URL.createObjectURL(blob)),
consoleMessage,
camera,
date: new Date(),
customizerParams: openScadToCadhubParams(customizerParams || []),
})