massive refactor toDrop cascadeStudio and add CadQuery + OpenSCAD

resolves #400
This commit is contained in:
Kurt Hutten
2021-07-08 21:17:07 +10:00
parent 477a557eb8
commit 8e558d2342
158 changed files with 2335 additions and 2300 deletions

View File

@@ -0,0 +1,51 @@
import { useRef, useEffect } from 'react'
import { useIdeContext } from './useIdeContext'
import { requestRender } from './useIdeState'
export const use3dViewerResize = () => {
const viewerDomRef = useRef(null)
const debounceTimeoutId = useRef<number>()
const { thunkDispatch } = useIdeContext()
useEffect(handleViewerSizeUpdate, [viewerDomRef])
function handleViewerSizeUpdate() {
if (viewerDomRef !== null && viewerDomRef.current) {
const { width, height } = viewerDomRef.current.getBoundingClientRect()
thunkDispatch({
type: 'updateViewerSize',
payload: { viewerSize: { width, height } },
})
thunkDispatch((dispatch, getState) => {
const state = getState()
if (['png', 'INIT'].includes(state.objectData?.type)) {
dispatch({ type: 'setLoading' })
requestRender({
state,
dispatch,
code: state.code,
viewerSize: { width, height },
camera: state.camera,
})
}
})
}
}
const debouncedViewerSizeUpdate = () => {
clearTimeout(debounceTimeoutId.current)
debounceTimeoutId.current = setTimeout(() => {
handleViewerSizeUpdate()
}, 1000) as unknown as number
}
useEffect(() => {
window.addEventListener('resize', debouncedViewerSizeUpdate)
return () => {
window.removeEventListener('resize', debouncedViewerSizeUpdate)
}
}, [])
return {
viewerDomRef,
handleViewerSizeUpdate,
}
}