Force to recompute billboard

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


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)

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

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)));

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.

Perhaps this is the same issue.

It is the same issue, main problem is we can’t make a playground because the 3D context come from mapbox. To resolve the issue we need to explore the mapbox API and find a better way to reconstruct a babylon camera from the mapbox camera attributes.

1 Like

The first place I asked my question is long, so I want to move it here.
I make demo. Why doesn’t billbordmode work…?

front :slightly_smiling_face: (screen shot)
スクリーンショット 2022-09-21 105705

side :skull: (screen shot)
スクリーンショット 2022-09-21 105735

To get the camera position from mapbox :point_down:.

Your demo isn’t working for me: