diff --git a/app/web/src/components/IdeViewer/IdeViewer.tsx b/app/web/src/components/IdeViewer/IdeViewer.tsx index cf71f89..fcd3efd 100644 --- a/app/web/src/components/IdeViewer/IdeViewer.tsx +++ b/app/web/src/components/IdeViewer/IdeViewer.tsx @@ -10,9 +10,12 @@ import { TextureLoader } from 'three/src/loaders/TextureLoader' const loader = new TextureLoader() const colorMap = loader.load(texture) +let lastGroup + extend({ OrbitControls }) function Asset({ geometry: incomingGeo }) { + const state = useThree() const mesh = useRef() const ref = useRef({}) useLayoutEffect(() => { @@ -21,7 +24,20 @@ function Asset({ geometry: incomingGeo }) { } }, [incomingGeo]) if (!incomingGeo) return null - + + let groupData = incomingGeo.children ? incomingGeo : null + if(lastGroup && lastGroup != groupData){ + state.scene.remove(lastGroup) + lastGroup.children.forEach(c=>c?.geometry?.dispose()) + // returning does not add the new group to the scene + // there is probably some useRef magic that would make this work, but I don't have time to reseach it + /// FIXME - do this properly with useRef or other react magic + if(groupData) state.scene.add(groupData) + } + lastGroup = groupData + + if(groupData) return + if (incomingGeo.children) return return (