highvrahos Posted December 27, 2013 Share Posted December 27, 2013 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, Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted December 27, 2013 Share Posted December 27, 2013 Do you get the same behavior on Chrome or IE? Quote Link to comment Share on other sites More sharing options...
highvrahos Posted December 27, 2013 Author Share Posted December 27, 2013 Just checked Chrome, yes, I'm getting the same behavior. I'm working in Mac OS, can't test IE at this time. Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 27, 2013 Share Posted December 27, 2013 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? Quote Link to comment Share on other sites More sharing options...
highvrahos Posted December 27, 2013 Author Share Posted December 27, 2013 I see, I'll have to keep experimenting with the debugger. When I say that the wrong values is strored, what I mean is when I do the following:shape.position.y = shape.getBoundingInfo().boundingBox.center.yThe repositioned shape is positioned on the wrong value (first image). Quote Link to comment Share on other sites More sharing options...
gwenael Posted December 27, 2013 Share Posted December 27, 2013 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 Quote Link to comment Share on other sites More sharing options...
highvrahos Posted December 27, 2013 Author Share Posted December 27, 2013 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, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.