Jump to content

the correct way to set _worldMatrix of a mesh


yokewang
 Share

Recommended Posts

I want to set the _worldMatrix directly instead of calling computeWorldMatrix from position/scale/rotation. (For performance issue)

But the _worldMatrix will be updated when the rendering system calls computeWorldMatrix internally.

So, I have to use below code to prevent computeWorldMatrix.

Quote

 


myMesh._worldMatrix = matrix;

(<any>myMesh)._isWorldMatrixFrozen = true;

 

But I am not sure If this is the correct way.

 

Thanks.

Link to comment
Share on other sites

Instead of accessing isWorldMatrixFrozen directly, you could call

myMesh.freezeWorldMatrix();

There is no setter to the world matrix (as far as I know), so technically, the only way to do this is to set it the way you do. But why not set the transformation once, have the matrix calculated and then freeze it? wouldn't it be better?

Link to comment
Share on other sites

Thanks RaananW, I have first tried freezeWorldMatrix, but it calls computeWorldMatrix internally. And I find computeWorldMatrix will be very slow when scaling.

https://playground.babylonjs.com/#BU5QQR#4  it's fast with out scaling. 234ms for my computer.

https://playground.babylonjs.com/#BU5QQR#3 it's very slow when scaling. 2607ms . And when size change to 30, it will be timeout.

Thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...