Initial work to support curv (#578)
* Initial work to support curv * Correct the initial code file location * Preview and stl mvp working * Prepare changes for review and preview build * Run curv inside of /tmp When exporting an stl it writes temporary files which is not allowed when deployed to aws unless it's in temp. * Lock in specific curv commit for reproducible builds see: https://discord.com/channels/412182089279209474/886321278821216277/912507472441401385 * Add curv to backend schema * Frontend changes to accommodate curv deploy * Use vcount instead of vsize, as it's independant of geometry size, This is good for CadHub usecase where we don't know anything about the user's project * Final tweaks for deploy virtual screen size does matter,and curv is a little more memory hungry than the other functions * Format project Co-authored-by: lf94 <inbox@leefallat.ca> Co-authored-by: Kurt Hutten <k.hutten@protonmail.ch>
This commit was merged in pull request #578.
This commit is contained in:
@@ -5,7 +5,7 @@ import type { Camera } from 'src/helpers/hooks/useIdeState'
|
||||
|
||||
export const lambdaBaseURL =
|
||||
process.env.CAD_LAMBDA_BASE_URL ||
|
||||
'https://oxt2p7ddgj.execute-api.us-east-1.amazonaws.com/prod'
|
||||
'https://2inlbple1b.execute-api.us-east-1.amazonaws.com/prod2'
|
||||
|
||||
export const stlToGeometry = (url) =>
|
||||
new Promise((resolve, reject) => {
|
||||
|
||||
103
app/web/src/helpers/cadPackages/curv/curvController.ts
Normal file
103
app/web/src/helpers/cadPackages/curv/curvController.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
import {
|
||||
lambdaBaseURL,
|
||||
stlToGeometry,
|
||||
createHealthyResponse,
|
||||
createUnhealthyResponse,
|
||||
timeoutErrorMessage,
|
||||
RenderArgs,
|
||||
splitGziped,
|
||||
} from '../common'
|
||||
|
||||
export const render = async ({ code, settings }: RenderArgs) => {
|
||||
const pixelRatio = window.devicePixelRatio || 1
|
||||
const size = {
|
||||
x: Math.round(settings.viewerSize?.width * pixelRatio),
|
||||
y: Math.round(settings.viewerSize?.height * pixelRatio),
|
||||
}
|
||||
const body = JSON.stringify({
|
||||
settings: {
|
||||
size,
|
||||
},
|
||||
file: code,
|
||||
})
|
||||
try {
|
||||
const response = await fetch(lambdaBaseURL + '/curv/preview', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
})
|
||||
if (response.status === 400) {
|
||||
const { error } = await response.json()
|
||||
const cleanedErrorMessage = cleanError(error)
|
||||
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
|
||||
}
|
||||
if (response.status === 502) {
|
||||
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const text = await new Response(blob).text()
|
||||
const { consoleMessage, type } = splitGziped(text)
|
||||
return createHealthyResponse({
|
||||
type: type !== 'stl' ? 'png' : 'geometry',
|
||||
data:
|
||||
type !== 'stl'
|
||||
? blob
|
||||
: await stlToGeometry(window.URL.createObjectURL(blob)),
|
||||
consoleMessage,
|
||||
date: new Date(),
|
||||
})
|
||||
} catch (e) {
|
||||
return createUnhealthyResponse(new Date())
|
||||
}
|
||||
}
|
||||
|
||||
export const stl = async ({ code /*settings*/ }: RenderArgs) => {
|
||||
const body = JSON.stringify({
|
||||
settings: {},
|
||||
file: code,
|
||||
})
|
||||
try {
|
||||
const response = await fetch(lambdaBaseURL + '/curv/stl', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body,
|
||||
})
|
||||
if (response.status === 400) {
|
||||
const { error } = await response.json()
|
||||
const cleanedErrorMessage = cleanError(error)
|
||||
return createUnhealthyResponse(new Date(), cleanedErrorMessage)
|
||||
}
|
||||
if (response.status === 502) {
|
||||
return createUnhealthyResponse(new Date(), timeoutErrorMessage)
|
||||
}
|
||||
const blob = await response.blob()
|
||||
const text = await new Response(blob).text()
|
||||
const { consoleMessage, type } = splitGziped(text)
|
||||
return createHealthyResponse({
|
||||
type: type !== 'stl' ? 'png' : 'geometry',
|
||||
data:
|
||||
type !== 'stl'
|
||||
? blob
|
||||
: await stlToGeometry(window.URL.createObjectURL(blob)),
|
||||
consoleMessage,
|
||||
date: new Date(),
|
||||
})
|
||||
} catch (e) {
|
||||
return createUnhealthyResponse(new Date())
|
||||
}
|
||||
}
|
||||
|
||||
const curv = {
|
||||
render,
|
||||
stl,
|
||||
}
|
||||
|
||||
export default curv
|
||||
|
||||
function cleanError(error) {
|
||||
return error.replace(/["|']\/tmp\/.+\/main.curv["|']/g, "'main.curv'")
|
||||
}
|
||||
10
app/web/src/helpers/cadPackages/curv/initialCode.curv
Normal file
10
app/web/src/helpers/cadPackages/curv/initialCode.curv
Normal file
@@ -0,0 +1,10 @@
|
||||
let
|
||||
N = 5;
|
||||
C = red;
|
||||
Twists = 6;
|
||||
in
|
||||
box [1,1,N]
|
||||
>> colour C
|
||||
>> twist (Twists*90*deg/N)
|
||||
>> rotate {angle: 90*deg, axis: Y_axis}
|
||||
>> bend{}
|
||||
15
app/web/src/helpers/cadPackages/curv/userGuide.md
Normal file
15
app/web/src/helpers/cadPackages/curv/userGuide.md
Normal file
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: Curv
|
||||
Written with: [Domain-Specific Language](https://martinfowler.com/dsl.html)
|
||||
Kernal type: Signed distance functions
|
||||
Maintained by: [Doug Moen and contributors](https://github.com/curv/curv/graphs/contributors)
|
||||
Documentation: [curv3d.org](https://curv3d.org)
|
||||
---
|
||||
|
||||
Curv is a programming language for creating art using mathematics. It's a 2D and 3D geometric modelling tool that supports full colour, animation and 3D printing.
|
||||
|
||||
### [Examples](https://github.com/curv3d/curv/tree/master/examples)
|
||||
|
||||
- [Flog spiral](https://619b5e6c6689420008eedfe5--cadhubxyz.netlify.app/draft/curv#fetch_text_v1=https%3A%2F%2Fraw.githubusercontent.com%2Fcurv3d%2Fcurv%2Fmaster%2Fexamples%2Flog_spiral.curv)
|
||||
- [Shreks donut](https://619b5e6c6689420008eedfe5--cadhubxyz.netlify.app/draft/curv#fetch_text_v1=https%3A%2F%2Fraw.githubusercontent.com%2Fcurv3d%2Fcurv%2Fmaster%2Fexamples%2Fshreks_donut.curv)
|
||||
- [Wood grain](https://619b5e6c6689420008eedfe5--cadhubxyz.netlify.app/draft/curv#fetch_text_v1=https%3A%2F%2Fraw.githubusercontent.com%2Fcurv3d%2Fcurv%2Fmaster%2Fexamples%2Ffinial.curv)
|
||||
@@ -13,16 +13,22 @@ import jscad from './jsCad/jsCadController'
|
||||
import jsCadGuide from 'src/helpers/cadPackages/jsCad/userGuide.md'
|
||||
import jsCadInitialCode from 'src/helpers/cadPackages/jsCad/initialCode.jscad.js'
|
||||
|
||||
import curv from './curv/curvController'
|
||||
import curvGuide from 'src/helpers/cadPackages/curv/userGuide.md'
|
||||
import curvInitialCode from 'src/helpers/cadPackages/curv/initialCode.curv'
|
||||
|
||||
export const cadPackages: { [key in CadPackageType]: DefaultKernelExport } = {
|
||||
openscad,
|
||||
cadquery,
|
||||
jscad,
|
||||
curv,
|
||||
}
|
||||
|
||||
export const initGuideMap: { [key in CadPackageType]: string } = {
|
||||
openscad: openScadGuide,
|
||||
cadquery: cadQueryGuide,
|
||||
jscad: jsCadGuide,
|
||||
curv: curvGuide,
|
||||
INIT: '',
|
||||
}
|
||||
|
||||
@@ -30,5 +36,6 @@ export const initCodeMap: { [key in CadPackageType]: string } = {
|
||||
openscad: openScadInitialCode,
|
||||
cadquery: cadQueryInitialCode,
|
||||
jscad: jsCadInitialCode,
|
||||
curv: curvInitialCode,
|
||||
INIT: '',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user