camera-controls icon indicating copy to clipboard operation
camera-controls copied to clipboard

Add the ability to hold children

Open netgfx opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe.

I'm trying to attach children to the CameraControls in order for them to be "pinned" to the camera

Describe the solution you'd like

Being able to add children to the camera controls, like OrbitControls can

Describe alternatives you've considered

Alligning the camera position on every frame, but it feels like too much work for a simple task

Additional context

No response

netgfx avatar Jul 21 '23 11:07 netgfx

How did you do that in OrbitControls? Also, this might work for you, since Camera classes inherit Object3D.

const pinnedMesh = new THREE.Mesh(
	new THREE.BoxGeometry( 1, 1, 1 ),
	new THREE.MeshBasicMaterial( { color: 0xff00ff } )
);

scene.add( camera );
camera.add( pinnedMesh );
pinnedMesh.position.z = - 5;

yomotsu avatar Jul 22 '23 15:07 yomotsu

In r3f we just included the Object as a child of the camera like

<PerspectiveCamera>
  <mesh></mesh>
 </PerspectiveCamera

then I guess I can just add that camera ref as the camera in CameraControls?

netgfx avatar Jul 22 '23 16:07 netgfx

Actually, I'm not sure because I don't really use R3F... One thing I can say is that PerspectiveCamera must be a child of the rendering Scene.

yomotsu avatar Jul 25 '23 00:07 yomotsu

Just attach them to cameraControls.camera, which is just a ref to the actual camera in the scene.

timothyallan avatar Aug 04 '23 18:08 timothyallan