Sign in to follow this  
Robert_h

Issue with Box Mesh Rotation (I think)

Recommended Posts

Hey guys,

New to this so bare with me if I've done something stupid. So basically I'm slowly working through the tutorials and features, trying some stuff out for a potential future project, but I have ran in to an issue that I have no idea what its being caused by.

The idea of the scene is to have a ball dropping on a rotating box, as a test to see the physics. Fairly straight forward, the ball gets removed and a new one created. Here is the scene, directly copy/pasted from my current code: http://www.babylonjs-playground.com/#3TNP9

As you can see, the first couple seconds it looks fine but it very quickly goes wrong when the box mesh begins glitching back and forth before effectively doubling in size over and over again. I have no idea what I have done to cause this other than it must be something to do with the way I'm rotating the box and updating its position for the physics because removing this results in a static but non-glitchy box. Even still, no idea how or why this is the result. 

As a side note, the scene seems to play a whole lot quicker in the playground than it does on my local version. Not sure if this means anything or not, figured it'd be worth mentioning.

Any help would be greatly appreciated, 

Thanks. 

 

Share this post


Link to post
Share on other sites

Hi @Robert_h, welcome to the forum!

  Yes, something is acting strange with the Oimo plugin.  No problems with your code.

http://www.babylonjs-playground.com/#3TNP9#2

I removed the updatePhysicsBodyPosition (supposedly it's no longer needed after recent plugin updates/rewrites).  I did assorted other little things, but... the REAL issue is in the difference of line 12 and 13 (one with the new keyword, one without).  It changes/fixes the box unwanted-scaling troubles, but we see a drastic speed change between the two methods, as you mentioned.  hmm.

I hope @RaananW comes to visit because he might know exactly what is causing this.  And, this is at least the second time an issue with the new keyword... has been seen.  The other report mentioned speed differences, too. 

I'll keep thinking about this.  Sorry for the troubles.  Please report any new things you find... if you do more tests.  thx.

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Ok,

found the problem. The quaternion from Oimo is not normalized. Which is wonderful!!! Or not. So, normalizing the quaternion is the fastest solution. I will, of course, push a fix during the day.

About the flickering - that seems to happen because of the sphere.dispose() function. I managed to get it to flicker only on the first mesh's dispose. When disposing the impostor only it works and doesn't flicker, so I can only assume it has something to do with the dispose itself. I will try debugging later and see.

This PG is with normalization and only a single flicker - http://www.babylonjs-playground.com/#1PCAGO . BTW . the values were moltiplied times 10 (all sizes, positions etc'), because Oimo likes LARGE numbers (I will explain that whenevr I finish the physics documentation. on my todo list, with appologies to the community).

 

Share this post


Link to post
Share on other sites

Yep, I wonder how that happened. I know about the "s", and I actually tested that constantly while developing...

it is the right solution, I just want to see if there was a reason for me doing that. If you want to submit a bug fix PR, be my guest. I will do it later this evening (in a few hours)

 

Share this post


Link to post
Share on other sites

Ok, so I suddenly rememberd something about Oimo :)

Oimo has a Quat class (with s instead of w) and a Quaternion class, with w (https://github.com/BabylonJS/Babylon.js/blob/7317ed822e3e2d52a44966fa4d2fdc3b0a91291a/dist/Oimo.js#L1938) . So this worked correctly. One of us (Oimo or Babylon) is not normalizing the quaternion before sending it out.

I will normalize in the plugin just to make sure

Share this post


Link to post
Share on other sites

It looks like all that OIMO.Quaternion class does is take a OIMO rotationMatrix and convert it to a Quaternion that uses a w instead of an s.  That seems pretty heavy for simply doing this:

babQuat.x = oimoQuat.x;

babQuat.y = oimoQuat.y;

babQuat.z = oimoQuat.z;

babQuat.w = oimoQuat.s;

I have been using OIMO with BJS without the plugin and haven't seen any issues that required me to normalize quats before applying them to a mesh.

 

Share this post


Link to post
Share on other sites

Thanks adam, you are totally right.

I will check this further. In both plugins I tried using the public APIs the plugins are offering. With oimo (as you stated) it is always a little hack - the public Body APIs are not the best. I'll see if I can optimize it a bit further. Will probably do as you suggested.

Have you noticed any different in the local Quat of the body and the rotation matrix?

Share this post


Link to post
Share on other sites
50 minutes ago, RaananW said:

Have you noticed any different in the local Quat of the body and the rotation matrix?

I haven't.  You are referring to these, right?

orientaion:

https://github.com/BabylonJS/Babylon.js/blob/7317ed822e3e2d52a44966fa4d2fdc3b0a91291a/dist/Oimo.js#L673

rotation:

https://github.com/BabylonJS/Babylon.js/blob/7317ed822e3e2d52a44966fa4d2fdc3b0a91291a/dist/Oimo.js#L721

Share this post


Link to post
Share on other sites

Just got around to being able to read through this thread properly. Thanks for the help and suggestions.

It seems that increasing the size of all of the objects had a pretty huge affect and fixed a lot of the problems I was having. The last problem with objects freaking out and changing shapes was still happening so I switched to babylon.js from the 'preview release' folder and everything cleared up perfectly.

So that's everything solved, time to move =)

Thanks.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.