hrgdavor / jscadui

MIT License
30 stars 7 forks source link

jscad.app demo should be modified that it works in openjscad.xyz as well #82

Closed Hermann-SW closed 7 months ago

Hermann-SW commented 7 months ago

Opening just https://jscad.app displays this demo script:

import * as jscad from '@jscad/modeling'
const { intersect, subtract } = jscad.booleans
const { colorize } = jscad.colors
const { cube, sphere } = jscad.primitives

export const main = () => {
  const outer = subtract(
    cube({ size: 10 }),
    sphere({ radius: 6.8 })
  )
  const inner = intersect(
    sphere({ radius: 4 }),
    cube({ size: 7 })
  )
  return [
    colorize([0.65, 0.25, 0.8], outer),
    colorize([0.7, 0.7, 0.1], inner),
  ]
} 

It produces the following error on https://openjscad.xzy:

SyntaxError: Cannot use import statement outside a module

Wouldn't it be nicer to have default jscad.app script modified in such a way, that it does work on openjscad.xyz as well? (for feature comparison)

hrgdavor commented 7 months ago

That is a valid point, but until it is settled, here is equivalent you can try on https://openjscad.xyz

const jscad = require('@jscad/modeling')
const { intersect, subtract } = jscad.booleans
const { colorize } = jscad.colors
const { cube, sphere } = jscad.primitives

module.exports = () => {
  const outer = subtract(
    cube({ size: 10 }),
    sphere({ radius: 6.8 })
  )
  const inner = intersect(
    sphere({ radius: 4 }),
    cube({ size: 7 })
  )
  return [
    colorize([0.65, 0.25, 0.8], outer),
    colorize([0.7, 0.7, 0.1], inner),
  ]
} 
Hermann-SW commented 7 months ago

@hrgdavor Thanks, that works on openjscad.xyz.