Robert_h Posted June 11, 2016 Share Posted June 11, 2016 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. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted June 12, 2016 Share Posted June 12, 2016 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. Quote Link to comment Share on other sites More sharing options...
adam Posted June 12, 2016 Share Posted June 12, 2016 There is an issue when copying the quat from OIMO to BABYLON. Oimo uses an s instead of a w. https://github.com/BabylonJS/Babylon.js/blob/7317ed822e3e2d52a44966fa4d2fdc3b0a91291a/dist/Oimo.js#L1790 https://github.com/BabylonJS/Babylon.js/blob/master/src/Physics/Plugins/babylon.oimoJSPlugin.ts#L309 http://www.babylonjs-playground.com/#3TNP9#3 I'm not sure what is causing the blinking issue. Quote Link to comment Share on other sites More sharing options...
adam Posted June 12, 2016 Share Posted June 12, 2016 1 hour ago, Wingnut said: REAL issue is in the difference of line 12 and 13 ( I think your PG is using Cannon. https://github.com/BabylonJS/Babylon.js/blob/9eecc40cacb41b117cf6d229a87ab63e8182108b/src/Physics/babylon.physicsEngine.ts#L13 Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 13, 2016 Share Posted June 13, 2016 Hi Guys, i'm on it, seems like a very interesting bug or maybe a few. I'll keep you all updated here. Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 13, 2016 Share Posted June 13, 2016 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). NasimiAsl 1 Quote Link to comment Share on other sites More sharing options...
adam Posted June 13, 2016 Share Posted June 13, 2016 @RaananW I believe it isn't normalized because you have a bug copying the quat from OIMO to BJS. Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 13, 2016 Share Posted June 13, 2016 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) Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 13, 2016 Share Posted June 13, 2016 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 Quote Link to comment Share on other sites More sharing options...
adam Posted June 13, 2016 Share Posted June 13, 2016 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. Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 13, 2016 Share Posted June 13, 2016 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? Quote Link to comment Share on other sites More sharing options...
adam Posted June 13, 2016 Share Posted June 13, 2016 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 Quote Link to comment Share on other sites More sharing options...
Robert_h Posted June 14, 2016 Author Share Posted June 14, 2016 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. 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.