Skip to content

Commit

Permalink
Refactor useEffect dependencies in PreviewComponent (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlessc authored Oct 24, 2024
1 parent 2a1b17d commit 47980c3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/PreviewComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const PreviewComponent: React.FC<PreviewComponentProps> = ({
// Whenever the URL or color changes, reload the model
useEffect(() => {
loadModelAndCheckDimensions(url);
}, [url, color]);
}, [url]);

const initializeScene = () => {
renderer.setSize(600, 400); // Fixed size
Expand Down Expand Up @@ -178,6 +178,19 @@ const PreviewComponent: React.FC<PreviewComponentProps> = ({
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());
Expand Down

0 comments on commit 47980c3

Please sign in to comment.