Fix bug where images was being converted to stl and erroring

This commit is contained in:
Kurt Hutten
2021-04-26 19:18:53 +10:00
parent 924de4c7a1
commit 320e8e4fb8
2 changed files with 10 additions and 6 deletions

View File

@@ -50,7 +50,7 @@ const IdeToolbarNew = ({ cadPackage }) => {
}
return (
<IdeContext.Provider value={{ state, thunkDispatch: thunkDispatch }}>
<IdeContext.Provider value={{ state, thunkDispatch }}>
<div className="h-full flex flex-col">
<nav className="flex">
<button

View File

@@ -14,19 +14,19 @@ import { requestRender } from 'src/helpers/hooks/useIdeState'
extend({ OrbitControls })
function Asset({ url }) {
function Asset({ stlData }) {
const [loadedGeometry, setLoadedGeometry] = useState()
const mesh = useRef()
const ref = useUpdate((geometry) => {
geometry.attributes = loadedGeometry.attributes
})
useEffect(() => {
if (url) {
const decoded = atob(url)
if (stlData) {
const decoded = atob(stlData)
const loader = new STLLoader()
setLoadedGeometry(loader.parse(decoded))
}
}, [url])
}, [stlData])
if (!loadedGeometry) return null
return (
<mesh ref={mesh} scale={[1, 1, 1]}>
@@ -228,7 +228,11 @@ const IdeViewer = () => {
</>
)}
{state.ideType === 'cadQuery' && (
<Asset url={state.objectData?.data} />
<Asset
stlData={
state.objectData?.type === 'stl' && state.objectData?.data
}
/>
)}
</Canvas>
</div>