Posting this as a new question as requested by Delta.
Ok, so after thinking about it for a while, I started realizing I was overcomplicating things. To make it easier, I just grabbed the point I wanted the camera to rotate around with scene.pick. I don’t know what I was thinking before, but this works great now.
Now I have a different problem. I put the code into a project and its not working. It doesn’t appear to detect my double-clicks. Here’s my code
meshes.forEach(function (mesh) {
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; //0.3;
mesh.material = new BABYLON.StandardMaterial("modelTexture", scene);
mesh.material.diffuseTexture = modelTexture;
mesh.material.bumpTexture = new BABYLON.Texture(modeltexture, scene);
mesh.material.specularTexture = new BABYLON.Texture(modeltexture, scene);
mesh.material.emissiveTexture = new BABYLON.Texture(modeltexture, scene);
mesh.isPickable = true;
camera.setTarget(mesh, true, true);
mesh.renderOutline = true;
mesh.outlineColor = new BABYLON.Color3(0, 0, 0);
mesh.outlineWidth = .3;
setMeshActions(mesh); // Also tried to set the code directly here,
// without the function but no joy.
});
var setMeshActions = function (mesh) {
mesh.actionManager = new BABYLON.ActionManager(scene);
mesh.actionManager.registerAction(
new BABYLON.ExecuteCodeAction(
{
trigger: BABYLON.ActionManager.OnDoublePickTrigger,
},
function () {
console.log("Got inside the action!"); // doesn't even get here
var dpic = scene.pick(scene.pointerX, scene.pointerY);
if (dpic.hit) {
var pickresult = scene.pick(scene.pointerX, scene.pointerY);
}
camera.setTarget(pickresult.pickedPoint);
}
)
The logging at the start of the setMeshActions method doesn’t even fire off. I’m not sure what to think, as I moved the code from playground to project over in the same place.
@Wingnut posted this in response to this here ActionManager with AssetManager and Camera pivot points
and its freaking awesome. I may end up using it, thank you very much, but I’m still wondering why the code in my playground works but not when it’s placed in the project. Thanks Wing! Oh hey also, notice with the playground I linked I still get that annoying position of 0,0,0 for all meshes in the model but the action manager works how its set up. And did you mean it has all meshes at 0,0,0 because of the way it was created or the way it was exported?
FYI i’m using BABYLON JS version 3.3