Jump to content



Recommended Posts

In this example I set a parent to the ground and then rotate it. I would expect that the absolute position of the ground would change but it doesn't... The weirder thing is that getAbsolutePosition returns always the same vector - the vector it returned first time I called it. For instance in this example the absolute position does change according to the rotation but after I get an absolute position for the first time it doesn't change.

Am I missing something?

Link to comment
Share on other sites

Thanks, Deltakosh. Checked it out and it works now. Just a little correction - I should force the both world matrices evaluation (the parent's one and the child's one). Otherwise it doesn't work.

If I understood well it will be automatically evaluated if this code will run in rendering loop, right?

Link to comment
Share on other sites

  • 1 year later...

I ran into the same problem where i am trying to get the absolute position (or more generally, the world matrix components) of a mesh deep down in the hierarchy of a scene *before* any rendering happens. Seems like what i need to do is to go up the hierarchy and do computeWorldMatrix(true) for each mesh in the ancestry as well.

Deltakosh, might be worthwhile to consider a scene.computeWorldMatrixForAllMeshes (force)

Link to comment
Share on other sites

Here's some code i wrote to make sure that the world matrix is up-to-date (outside of rendering loop). Both these seem like nice utilities to add to BJS classes. I am new, so passing on code for now..


/* Get a node's parent hierarchy */
getHierarchy: function ( node, includeThis ) {
    var hierarchy = [];
    if ( includeThis )
        hierarchy.push( node );
    var item = node.parent;
    while ( item ) {
        hierarchy.push( item );
        item = item.parent;

    return hierarchy;

/* Compute world matrix for node and its parent hierarchy */
computeWorldMatrix: function ( node, force, hierarchy ) {

    if ( hierarchy ) {
        var nodes = this.getHierarchy( node );
        for ( var n=nodes.length-1; n >= 0; n-- )
            nodes[n].computeWorldMatrix( force );

    node.computeWorldMatrix( force );
Link to comment
Share on other sites

Note that i had to do this only because i was trying to get the world matrix of a mesh deep down in hierarchy BEFORE any rendering starts. (Wanted to set the camera position/rotation to that of the "eye" of the avatar). When i didnt do computeWorldMatrix(force) for the hierarchy, it was only returning the local matrix. After i did the above code, it worked.

Link to comment
Share on other sites

  • 3 weeks later...
  • 11 months later...

Hi, sorry for bumping up this old thread, but I think its not finished yet.

I have the same problem like Srisub. It occurs when I use computeWorldMatrix(true) inside the createScene function ( not in the runRenderLoop ). 

The result of the computeWorldMatrix looks wrong ( expect  {X:3 Y:1 Z:0}, but get {X:1 Y:0 Z:0} )

If I use the code from Srisub it works.


Here is a Playground where I can reproduce the problem.


@Deltakosh maybe you can have a look on it

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.

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.


  • Recently Browsing   0 members

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