Jump to content

GetBoundingInfo correct values


highvrahos
 Share

Recommended Posts

Hello,

 

I'm trying to get some dimensions of models I load using GetBoundingInfo method on Mesh.

 

Using console.log to debug the return values I see something I can't understand. When the variables are printed in the console log, the dimensions are wrong (first picture). But when I click on the variable on Firebug to see a tree view of the variable dimensions are correct (second picture).

 

Do you have any idea why that is happening?

 

Sadly if I store the return value in a variable inside JS code, the wrong values are stored.

 

Thank you in advance,

post-5854-0-57915800-1388132905_thumb.pn

post-5854-0-42844700-1388132909_thumb.pn

Link to comment
Share on other sites

I'm not sure it's linked to your issue but I know I've noticed that console.log doesn't necesseraly print the value of your variable as it was at the moment of the call to console.log. To be sure to get the right value, you have to throw an exception right after the call to console.log. Of course it's only for you to be able to debug... In that case, actually it's the same behavior as using the javascript debugger of your browser.

 

The returned value that you store, is it a reference or a copy? When you write "the wrong values are stored", do you mean that you checked them with a console.log or with the debugger?

Link to comment
Share on other sites

What could be happened it's that shape.position.y and shape.getBoundingInfo().boundingBox.center.y are linked. You set position.y according to center.y but center.y depends on position.y. I didn't test but that could be the issue. Try to store shape.getBoundingInfo().boundingBox.center.y in a local variable not in shape.position.y just to check you have the right value.

 

P.S: no image is showed for me

Link to comment
Share on other sites

I think I have found the solution to this issue. The following code works both in the debugger as well as in code (returns always the correct value):

        setTimeout(function(){            shape.refreshBoundingInfo();            var height = shape.getBoundingInfo().boundingBox.maximumWorld.y - shape.getBoundingInfo().boundingBox.minimumWorld.y;            shape.position.y = plates_height + height / 2;            shape.setEnabled(true);        },200);

Mesh is loaded using SceneLoader.ImportMesh and code is placed in the "then" function. What I thought in the beginning was the problem is to refreshBoundingInfo() inside scene.executeWhenReady(function (){}) function, but that didn't work out.

 

Only when putting a delay in the code script, using setTimeout everything worked as expected.

 

Thank you,

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...