Delta was so kind to post for me: https://www.babylonjs-playground.com/#PFKSUJ#1
Originally I had 5 boxes and I was trying to get the camera to change targets on double-click. Each time I changed target, the camera would then rotate around the newly selected mesh. Great! So, I changed some things and this time around I used AssetManager to load up a model I have. Only now I’ve noticed that, while the double-clicks are catching the correct meshes, the camera doesn’t focus on the selected mesh or change its pivot point to the selected mesh’s position. Why and how do I fix this?
Again, I apologize for the lack of a playground. I can’t get one to save today for the life of me. Here’s the code.
var createScene = function() {
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3(0.8, 0.8, 0.8);
scene.checkCollisions = true;
scene.collisionsEnabled = true;
var camera = new BABYLON.ArcRotateCamera("camera1", 0, 0, 10, new BABYLON.Vector3(0, 0, 0), scene);
camera.attachControl(canvas, true);
camera.checkCollisions = true;
camera.applyGravity = true;
camera.speed = 1;
camera.layerMask = 2;
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 1), scene);
light.intensity = .5;
var assetsManager = new BABYLON.AssetsManager(scene);
var meshTask = assetsManager.addMeshTask("mtask", "", "https://raw.githubusercontent.com/carlos-mendieta/models/master/", "AH-64.obj");
assetsManager.load();
meshTask.onSuccess = function (task) {
let ms = task.loadedMeshes.filter(function (mesh) {
return mesh.geometry._totalVertices > 0;
});
var meshes = ms;
meshes.forEach(function (mesh) {
mesh.checkCollisions = true;
mesh.ellipsoid = new BABYLON.Vector3(1, 1, 1);
mesh.ellipsoidOffset = new BABYLON.Vector3(0, 0, 0);
mesh.scaling.x = mesh.scaling.y = mesh.scaling.z = 1;
mesh.isPickable = true;
mesh.renderOutline = true;
mesh.outlineColor = new BABYLON.Color3(0, 0, 0);
mesh.outlineWidth = .3;
mesh.actionManager = new BABYLON.ActionManager(scene);
mesh.actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{
trigger: BABYLON.ActionManager.OnDoublePickTrigger,
},
function () {
camera.setTarget(mesh.position);
console.log("selected " + mesh.id);
}
)
);
});
};
return scene;
};