vtange Posted November 1, 2017 Share Posted November 1, 2017 https://www.babylonjs-playground.com/#SVHR8A I'm trying to create a simple (at least in my mind) scene where I have a ball rolling within the confines of a single mesh "room" I built in blender and exported as .gltf. However, no matter what I do, the ball seems to always go through the imported mesh and hit the ground below (which I kept to make sure the ball doesn't fall forever). Am I doing something wrong? In the playground there isn't a physics engine but locally I've tried cannon.js after reading that it supports MeshImpostors but I get the same result with or without a physics engine. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 1, 2017 Share Posted November 1, 2017 Howdy, welcome to the forum I noticed one problem with the playground and tried fixing it, but the mesh impostor simply wouldn't work correctly. Let me go through the first fix, and then explain the problem: your model is built using a root node as a parent of the actual mesh. parenting in Babylon and the physics engine imply compound (a "merge" of many impostors to a single one). But this is not what you wanted to achieve. You wanted a mesh impostor on the second mesh, the one with the parent. Since you didn't implement the onError callback, you didn't see the error. For that we introduced the ignoreParent flag, which is a boolean that simply cancels the compound-creation and treat every mesh as an individual, assuming (!!) the parent node has no impostor. It should look something like this: https://www.babylonjs-playground.com/#SVHR8A#1 You will notice, however, that it didn't really solve anything I ran some tests. The first one was to use the box impostor instead of the mesh impostor. This works perfectly. So I assumed there was something wrong during the creation of the mesh impostor. Then I noticed that your parent node has a negative scale on the z axis (-1) and that your mesh is downscaled to ca. 0.02 on all axis. I am not sure why the negative scaling is needed, and I assume this is the problem with the impostor, as the mesh impostor is reading straight out of the vertex data of the mesh. A negative scaling might make it look correctly, but it seems to break the vertex data. Is there any way of you exporting this mesh with a 1,1,1 scale, 0,0,0 position and no rotation just to make sure what the problem is (babylon, the physics engine, or the mesh itself). Wingnut 1 Quote Link to comment Share on other sites More sharing options...
vtange Posted November 2, 2017 Author Share Posted November 2, 2017 Hey Raanan, Thank you for testing around and explaining the .ImportMesh stuff to me. Yeah I didn't know about the ignoreParent flag and the details about how the meshes are structured after import. Is there a reason why the Blender exporter just exports things the way it did with a parent-child relationship. I had a feeling thru skimming the .gltf and debugging that there was a mesh in my imported mesh, but couldn't tell which was the 'official' one, so I assumed it was the one at the highest level. Anyways, apparently when you draw with Sketchup, everything is in negative space, so we ended up with the negative scales and funky stuff. Here's a new playground with everything in positive space. Same box room, just rotated 180 degrees in Sketchup and exported. https://www.babylonjs-playground.com/#SVHR8A#2 Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 2, 2017 Share Posted November 2, 2017 Great So, I am not sure what was updated, but the mesh's parent's scaling is still negative on the z axis, and the rotation is still Math.PI on the y axis. Also, it seems like the object is not centered. It shouldn't be a problem (!!), but I really want to first check with a mesh I am sure SHOULD work before I get into fixing this issue. I believe I know what the issue is - the vertex data being provided to the physics engine is totally off (I have been experimenting today quite a lot in that regards). Any chance of getting the mesh centered, with no negative scaling? Quote Link to comment Share on other sites More sharing options...
vtange Posted November 2, 2017 Author Share Posted November 2, 2017 Hmm, that's weird. So the scaling is still off even when the model is not in negative space? In the playground it clearly is in (55, Y, 55) instead of -55 now. How are you checking the scaling, rotation, centering, of the mesh? Is there a specific part of the .gltf file you're reading? * I got work right now and won't be able to work on the mesh soon, but I'd like to know so I can get something done quick once I'm home Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 2, 2017 Share Posted November 2, 2017 I did find the reason (thanks to oh' mighty deltakosh ). This is the way to support left and right handed systems. Should stay, cannot be avoided. I need a way around it! Working on it right now. Quote Link to comment Share on other sites More sharing options...
vtange Posted November 3, 2017 Author Share Posted November 3, 2017 What did deltakosh tell you? So is there anything I should fix in my playground or regarding the mesh? Thanks so much for working on this. I'm a newb in BJS so from my POV you and deltakosh are both awesome. If there's anything I can do to help, do tell Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 3, 2017 Share Posted November 3, 2017 hi @vtange, seems like I found the problem and fixed it. I am still in the process of running tests, and your mesh really helped a lot in understanding what's going on. Your mesh has all of the "problems" I needed in order to find a working solution: 1. parent with awesomely weird transformation (negative z scaling, Math.PI on y) 2. Your mesh is not centered. At all Wonderful! 3. Your mesh is downscaled. 0.025 times to be exact. 4. It is relatively complex! Which is good for testing. Here is the current working state : You will notice the collisions are working correctly. There are walls that are not seen due to back face culling, but you know the model better than me I will PR "soonish". I want to make sure everything is working, as this is a rather big change in the way I am calculating the initial physics bodies. Wingnut and Raggar 2 Quote Link to comment Share on other sites More sharing options...
vtange Posted November 4, 2017 Author Share Posted November 4, 2017 Oh my god @RaananW you are a GOD. I'm glad my mesh helped you find the problem and fix it. Yeah I'm aware of the invisible walls - I kept them there on purpose to see if the balls would go through them in one direction or something. With this fix, we can theoretically make a pinball game with a Sketchup Model and 1 ball Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 6, 2017 Share Posted November 6, 2017 So! https://github.com/BabylonJS/Babylon.js/pull/3085 @vtange, I used your mesh as an example. I also tried playing with its transformation (rotation, position), and it works wonderfully out of the box. Quote Link to comment Share on other sites More sharing options...
RaananW Posted November 6, 2017 Share Posted November 6, 2017 Here is the playground - https://playground.babylonjs.com/#SVHR8A#13 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 6, 2017 Share Posted November 6, 2017 Merged and published to PG Quote Link to comment Share on other sites More sharing options...
stephanedemotte Posted June 21, 2018 Share Posted June 21, 2018 Hello, https://playground.babylonjs.com/#SVHR8A#13 dont work anymore, any news on this ? Quote Link to comment Share on other sites More sharing options...
RaananW Posted June 21, 2018 Share Posted June 21, 2018 Hi, the #13 has temporary fixes that were already merged into the framework so - https://playground.babylonjs.com/#SVHR8A#20 is now working 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.