bug: follow cam doesn't register objects newly added or removed from scene
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 797
- Forks
- 98
- Avg merge
- 8m
- Merged PRs (30d)
- 1
Description
replace the code below in the example
I added a test that toggles the Slopes every 3s and you can see that the camera still detects slopes and zooms in even though the slopes have been removed from the scene
the problem is that the useFollowCam relies on component render, so if you add or remove elements that aren't at the level ecctrl was invoked then it won't rerender ecctrl and useFollowCam wouldn't update the intersectObjects array
import { RigidBody } from "@react-three/rapier";
import { useGLTF, Text } from "@react-three/drei";
import { useEffect, useState } from "react";
import * as THREE from "three";
export default function Slopes() {
// Load models
const slopes = useGLTF("./slopes.glb");
const [visible, setVisible] = useState(true);
useEffect(() => {
// Receive Shadows
slopes.scene.traverse((child) => {
if (
child instanceof THREE.Mesh &&
child.material instanceof THREE.MeshStandardMaterial
) {
child.receiveShadow = true;
}
});
}, []);
useEffect(() => {
const a = setInterval(() => {
setVisible(!visible);
}, 3000);
return () => {
clearInterval(a);
};
}, [visible]);
if (!visible) {
return null;
}
return (
<group position={[-10, -1, 10]}>
<RigidBody type="fixed" colliders="trimesh" rotation={[0, Math.PI, 0]}>
<primitive object={slopes.scene} />
</RigidBody>
<Text
rotation={[0, Math.PI, 0]}
position={[3.5, 3, 0]}
color="black"
fontSize={0.5}
>
23.5 Deg
</Text>
<Text
rotation={[0, Math.PI, 0]}
position={[0, 4.5, 0]}
color="black"
fontSize={0.5}
>
43.1 Deg
</Text>
<Text
rotation={[0, Math.PI, 0]}
position={[-3.5, 7, 0]}
color="black"
fontSize={0.5}
>
62.7 Deg
</Text>
</group>
);
}
https://github.com/user-attachments/assets/ade3537f-51dd-4c98-bd67-7e4f49e78980
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the example and the useFollowCam implementation; reproduce the Slopes component toggling every 3 seconds and inspect how intersectObjects is updated when nested objects mount or unmount. Done means the follow camera detects newly added slopes and stops detecting slopes after they are removed from the scene.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, three.js, typescript
- Domain
- frontend, game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100