Force to recompute billboard

In a project I’m working on (mapbox ^^), I only set the projectionMatrix to control my Camera :

scene.activeCamera.freezeProjectionMatrix(projectionMatrix);
scene.render(true);

So billboards does not work because camera.position = (0,0,0)
For a specific mesh I can make :

let invert = scene.activeCamera.getProjectionMatrix().clone().invert();
scene.activeCamera.position = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(), invert)
mesh.lookAt(scene.activeCamera.position)

And it works…But I don’t want to do that because I would have to re-implement Billboard.X, Y, ALL etc.

I see that billboard are implemented in TransformNode.computeWorldMatrix().

But when I do

scene.activeCamera.freezeProjectionMatrix(projectionMatrix);
let invert = scene.activeCamera.getProjectionMatrix().clone().invert();
scene.activeCamera.position = BABYLON.Vector3.TransformCoordinates(new BABYLON.Vector3(), invert)
scene.meshes.forEach(mesh => mesh.freezeWorldMatrix(mesh.computeWorldMatrix(true)));
scene.render(true);

Billboards still not working, am I missing something ?

Hi sharp,

Sounds like a pretty interesting and unusual use case! Do you by any chance have a working sample you can share, ideally a Playground? There are a couple things that seem a little confusing to me which might be cleared up if I could see them in action.

If you don’t have a working sample, I think the main two points of uncertainty for me are as follows:

  1. I’ve almost never seen anyone invert a projection matrix before. In fact, my understanding is that canonical projection matrices cannot be generally inverted. Can you dive a little deeper into the reasoning behind what this is doing and why you need to go about it this way?
  2. Typically when values need to be recomputed, I would not expect them to be frozen as, without that, most of them will recompute themselves. Can you help me understand what all the freezing is doing? If, for example, you could achieve the effect you’re going for via a more conventional usage of the variables (setting the position and allowing values to auto-recompute on render), would that be an option?

Hi @syntheticmagus and thanks for taking the time to respond

I use web mercator projection so it’s conformal and can be inverted. When I use a lookAt function on a mesh it works great !

I would like so much them to recompute themselves :)…But I there’s not enough data so they can’t do…I provide the camera position but maybe Billboards needs more…Maybe @Deltakosh will have a clue :smile:?

I will try to make a minimalist codePen :)…

1 Like

A playground here would definitely help :slight_smile: we do not need the mapbox part just a couple planes highlighting your issue would be great.