Changing thinInstance Position

hi team,

I need to change worldMaterices ( or just y position of thininstance ) at specific index with another thininstance index, I need to change Y position from the obtained matrices, not sure how to apply this index1Matrices to another index:

   let worldMatrix = sphere.thinInstanceGetWorldMatrices()
   let index1Matrices = worldMatrix[1];
   sphere.thinInstanceSetMatrixAt(0, index1Matrices);

do I have to convert index1Matrices?


Your PG does work as expected (you set the same matrix for instance 0 than for instance 1, so the two spheres are at the exact same location), what is the problem you face with?

1 Like

I would like to replace Y position of this value

let index1Matrices = worldMatrix[1];
/// change Y position of index1Matrices here and then apply below
sphere.thinInstanceSetMatrixAt(0, index1Matrices);

but don’t understand how would I do that

You can use the setTranslationFromFloats method of the matrix:


Thanks @Evgeni_Popov , That did the trick, but I am facing some weird issue in my localhost, That sphere is actually a blocker object in my localhost which has some other objects behind it, on clicking at blocker I am changing its position, ( here in PG on click it changes its position perfectly )

But, something weird is happening on my localhost , when I click on blocker after adding setTranslationFromFloats , I am able click on objects behind my blocker, but the blocker doesn’t change its position visually. I was using below options for optimisation, but even after removing below doesn’t helps:

        obj.doNotSyncBoundingInfo = true;

any idea how can I debug this ? Thanks

That’s hard to tell if the code works in the Playground…

Does the exact code from the Playground work in your local project ? If yes, you should try to modify it by small increments to reach your current code until it fails.

Yup it works, now I am trying to break the code and see if could find the real issue. Thanks

@Evgeni_Popov finally after hours I was able to find the issue, I found that I was setting buffers as static on matrix, which was causing to not move my object. While it fixed above problem I am still not able to achieve what I wants, I have 3 boxes in below PG, what I wold like to happen is, when click on a box, it should move a little up, when I click next box, previous box should go back to its initial position and move clicked box up, so only clicked box remains in air, here I created a PG: Babylon.js Playground

if you click on any of box, it will go above on same place ( because I am using same setTranslationFromFloats(2, 10, 0) here since can’t figure how to get box’s previous value dynamically) , what actually I need is, when I click on one box, that clicked box change Y position, and if any previous box was higher, it will go back to initial position, to accomplish this I saved objects metrics states boxWorldMatrix = obj.thinInstanceGetWorldMatrices(); , then when click on any box I try to apply but object doesn’t goes back to its initial position. also I have some rotation, scaling etc which I would like to maintain.


Finally figured xD, I also had to save positions:

1 Like