Jump to content

[SOLVED] MeshImpostor not working with imported .gltf file


vtange
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :

59fce38867432_Nov3201710-38PM-Edited-Edited-Edited.gif.b976abf581b483cfd3bfa93e911ba45a.gif

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

  • 7 months later...

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