tscircuit / jscad-fiber

Create 3d CAD models with React using jscad
MIT License
20 stars 4 forks source link

Customizing JSCadFixture #25

Open r-bt opened 1 month ago

r-bt commented 1 month ago

I'd like to be able to custom JSCadFixture. Specifically the size, background colour, and positioning of the ThreeJS camera.

I was wondering are there any thoughts about the best way to do this. My initial ideas are either:

  1. Expose props on the existing JSCadFixture component
  2. Integrating with react-three-fiber to be able to declaratively specify lights, camera, etc

Other thoughts?

seveibar commented 1 month ago

I like the idea of exposing props for basic customization, but I would recommend we create a component called <JscadMesh> or <JscadThreeMesh> that neatly integrates into ThreeJS, it's not too hard to do this but it does require some knowledge of how fiber works. I can try to give some pointers in a moment

seveibar commented 1 month ago

So the basic idea of the implementation is this, @r-bt lmk if you're interested in implementing otherwise I can probably implement ~tomorrow

import { createRoot } from "../somewhere-in-jscad-fiber"

export const JscadThreeMesh = ({ children }) => {
  const threeMesh = useMemo(() => {
    const jscadElms = []
    createRoot(children, jscadElms)
    const mesh = convertCsgToThree(jscadElms)
  }, [])
  return <primitive mesh={mesh} />
}

Usage would be like:

<Scene>
  <Light {/* ... */} />
  <JscadThreeMesh>
    <Cube size={1} />
  </JscadThreeMesh>
</Scene>
r-bt commented 1 month ago

Awesome, I can give it a shot