Strange thin intances behaviour

Hi guys!

Here is the scenario:

  1. Load a GLTF
  2. create thin instances on a mesh

The created instances are rotated by PI (or maybe negative Y scaling) when I create the thin instances after returning from createScene() and I invoke the thinnization with a GUI button.

The created instances are positioned OK, when I invoke the thinnization just right after I loaded the model.

I believe, that some calcuations takes place after returning from createScene and that changes the matrices.

https://playground.babylonjs.com/#TGFS49#17

How to use the playground:
After running it some objects appear. Click (lines 33-35) on the thinnize button to make two thin instances of a particular mesh (function thInnIze(scene) at line 43). Everything except that particular mesh is setEnabled(false) and two tables appear in black. They are actualy rotated, you can look at them form below and see the light woodish color.

Now uncomment line 37, so the thinnization takes place while still in createScene(). Run. Now you can immediately see the tables correctly faced up.

Can somene help me to understand what is going on? :slight_smile:

Appreciating any input, thank you!

R.

EDIT: is this related to the fact, that the GLTF exporter from Blender exports by -Y scaling?

Gltf are not in the same handedness than babylon so we scale them by -1 and rotate them.

You could change your scene handedness to prevent it with scene.useRightHandedā€¦ or maybe add an extra rotation into your matrix which sounds the simplest ?

Ok, but when does the scaling take place? Is there a safe way for me to know, whether it is already applied or not? Iā€™d like to make the script universal. Thanks!

Just call node.computeWorldMatrix(true) before so you d be sure it is all uptodate

There is still something interesting. Iā€™ve added computeWorldMatrix(true). Now the instances faced the same direction regardless when the function was called, so this part is ok. Thank you!

However, if you take a look at this PG:

https://playground.babylonjs.com/#TGFS49#25

Hit Thinnize and you will get this result:
Screenshot 2021-07-02 225536

It doesnā€™t use (or whatever) the transformation matrices defined here:
Screenshot 2021-07-02 225607

If you uncomment line 37 you will get the correct output:

I donā€™t get it :smiley: is there an explanation for this?

Let me add the genius mind behind thin instances into the thread @Evgeni_Popov as it sounds strange indeed

1 Like

Hi,
https://playground.babylonjs.com/#TGFS49#35

Iā€™ve added addTestMeshes() which basically replaces the loaded meshes with torus knots. Everything else in the code stays the same. With the torus knots the PG behaves the same regardless when the thinnize method is called and it uses the matrix correctly. So it seems to be a problem only with the loaded meshes.

Hopefully this will help you/us/me :smiley:

Thanks!
R.

https://playground.babylonjs.com/#TGFS49#38

Hit the button, and start to rotate the camera. The table is rendering very oddly. Itā€™s flickering, sometimes it is visible, sometimes not. And again if you uncomment line 38, you get a correct output. :sunglasses:

R.

OMG, just switched the PG to 4.2 and it works correctly in both cases! :sunglasses:

Guys, I have a de ja vu now, because this is the second time I got fooled by the PGā€™s default Latest selection. A few months ago I was struggling to get IK bones working. My code ran well on 4.2, but not on Latest. Nor the official BJS example is running the IK example well on the Latest version of BJS.

Shouldnā€™t the Production version be the default one for the PGs? Or some other mechanism to prevent such situations, because I am quite confident, that not I am the only one who had this experience.

Thank you!
R.

Nope it actually helps catching regressions faster and this should not happenā€¦ in theory :slight_smile:

Yes, it seems to be a good reason.

I will remember to check on what version I am testing in the future for sure, because I was already tearing my hair for two days before I wrote to the forum. :joy:

Have a nice day!
R.

EDIT: just looked at my avatar and realized that I am bold, so no hair tearing could happen :joy::pray::sunglasses:

This PR will fix the problem:

2 Likes

Hi!
How is this working? Should I, who initiated the process review the changes you made? Thanks!
R.

No you donā€™t need to. It should be merged today, and maybe the Playground will be updated today too, or tomorrow.

Currently building the nightly, it will be available in the PG in a couple hours as I am running a bit of tests beforehand.

2 Likes