Improper thin instances translation

Hello!
I’m fairly new to the idea of thin instancing, but found myself in need to utilize it for my scene.
I want to make a dense forest of around 60k trees and I managed to do it using a basic array of translation matrices. Trouble is the instances seem to be “stacking” one on top of another and the trees are linearly going upwards.

Playground with the trees.

I’d like the trees to be spread evenly on an Y axis so it makes a nice looking forest.
I’m probably missing something stupid but as I said I’m new to this feature and don’t really know what am I doing wrong. Docs aren’t pointing out to anything specific.

Another thing, how can I easily apply scaling to those instances? I’d like all of my trees to be a bit bigger. Probably needs a scaling vector or another matrix but I’m not sure how to combine this with the translation matrices.

Any help would be appreciated.

This should help https://playground.babylonjs.com/#LLPCR7#1 also random rotation would prevent the stacking effect I guess and now it should be easy to add in :slight_smile:

3 Likes

I’ve managed to play around it and mitigate this issue by applying a RotationYawPitchRoll matrix with certain values, but it doesn’t seem to be completely even just yet.

I switched some inspector values and found some combination using rotation quaternions to level all the instances out. Perhaps there could be a way to apply these?

You can create matrices from quaternions with BABYLON.Matrix.FromQuaternionToRef

Sorry, not sure how to actually make quaternions straight in the code. Mind helping a little? :sweat_smile:

    var q = BABYLON.Quaternion.FromEulerAngles(1,1,1); // radians
    var mat = new BABYLON.Matrix();
    BABYLON.Matrix.FromQuaternionToRef(q, mat);

    // equivalent to 

    BABYLON.Matrix.FromEulerAngles(1,1,1)

so you might even not need the quaternions :slight_smile:

1 Like

Thanks a lot, fiddled around a bit and managed to level it out quite nicely.
It’s not perfectly even though but that’s probably just a case of inputing more precise angles. It’s close enough for my purposes.
Thanks for your help!

2 Likes