diff --git a/src/components/PreviewComponent.tsx b/src/components/PreviewComponent.tsx index cf42cf2..113c027 100644 --- a/src/components/PreviewComponent.tsx +++ b/src/components/PreviewComponent.tsx @@ -76,7 +76,7 @@ const PreviewComponent: React.FC = ({ // Whenever the URL or color changes, reload the model useEffect(() => { loadModelAndCheckDimensions(url); - }, [url, color]); + }, [url]); const initializeScene = () => { renderer.setSize(600, 400); // Fixed size @@ -178,6 +178,19 @@ const PreviewComponent: React.FC = ({ gridHelperRef.current = gridHelper; }; + const updateMaterialColor = (hexColor: number) => { + if (meshRef.current) { + const material = new THREE.MeshStandardMaterial({ color: hexColor }); + meshRef.current.material = material; + } + }; + + useEffect(() => { + if (modelLoaded) { + updateMaterialColor(parseInt(color.replace("#", ""), 16)); + } + }, [color]); + const updateDimensions = () => { const boundingBox = new THREE.Box3().setFromObject(meshRef.current!); const size = boundingBox.getSize(new THREE.Vector3());