while select a object on scene , then move camera view focus on the selected object, although we can use lookat method to focus the selected object with fixed arguments, but it is too trouble if we have many objects parts on the scene …
so that is why I want more simply but effectively solution for the focus eye view .
Not sure if I understood correctly, but if what you mean is that you have complex models with submeshes and want the camera to focus on the root model instead of submesh when clicked, then for example:
// NOTE When loading models do this:
new GLTFLoader().load('./model.glb', (gltf) => {
scene.add(gltf.scene);
gltf.scene.traverse(child => {
child.userData.clickTarget = gltf.scene;
});
});
// NOTE When listening to clicks do this:
const raycaster = new Three.Raycaster();
const hits = raycaster.intersectObjects(scene.children, true);
if (hits.length) {
const { object } = hits[0];
const target = object.userData.clickTarget || object;
const position = new Three.Vector3();
target.getWorldPosition(position);
camera.lookAt(position);
}
good code , I want focus the part of a object which includes many different sub objects ( parts), not whole object view, just move camera focus on the sub object ( part)
I meaning if scene load a complex model which contains many different mesh parts, if pick one then camera focus on it with suitable view point, the camera position / lookAt value might calculate with some formula or solution ?
above code apply animation, also the camera have to move to right position then lookAt somewhere …
I am fresh on 3js, I just want the feature, if we typing a part object name which contains in the gltf objects tree, then the camera focus on the part object directly . although we can hard code set the position and lookAt value but we still want another solution : may we can calculate the target position & lookAt variable with some way?
hi, mesh position is no big problem, question is how to calculate or estimate a ‘correct’ or ‘most good view’ of the camera position ? put the camera to right (maybe should most good view point’) position and look at the target mesh