Fixing Object Placement Issues When Replacing GLTF Placeholders

Hello everyone! I’m currently developing a 3D game engine. I’m converting a USDZ file into GLTF and displaying it in the browser. I can see a room and placeholders (bounding boxes), and I want the placeholders to be replaced with rendered furniture. The replacement should ensure that the furniture is placed on the floor.

To achieve this, I recursively search for placeholder meshes in the GLTF file with names like “chair.” My script then looks into my model folder, retrieves the path to the corresponding 3D model, and replaces the placeholder.

The problem is that the replacement doesn’t work correctly. While it takes the bounding box values (like translation, rotation, etc.), the object is never placed on the floor. The placeholders, when not replaced, are always on the floor. For example, if I simply load the 3D scene with placeholders (bounding boxes) without replacing them with rendered models, the placeholders (bounding boxes) are always positioned correctly on the floor.

However, as soon as I replace them, the objects are no longer on the floor but are always hovering above it. I’ve tried solving this issue but haven’t succeeded. I also can’t find any resources or information on this. Now I’m feeling quite desperate and don’t know how to fix this.
The GLTF file contains specific meshes, nodes, and groups. For instance, my GLTF file also includes a floor. It is visible, and it has its dimensions, which I can see. However, I can never get the replaced object to align with the floor.
How can I ensure that the replaced models are placed on the floor and no longer hover above it?

I look forward to your solutions and ideas. Thank you very much, and have a great day!

Not sure if it helps, but instead of .remove’ing a deeply nested node and .add ing it to the scene…

Instead use scene.attach( theNode )

.attach takes care of making the visual transform stay the same when transferring to a new parent.

Hi manthrax,

Thank you for your response. I was able to fix the issue in the meantime, and I think the solution could be helpful for everyone.

I imported the scene into Blender and analyzed how the objects are connected or related to each other. That’s when I noticed something important: for example, when I clicked on a placeholder, I realized that the cursor was never on the ground. The same was true for the meshes I created and added to the scene.

Afterward, I analyzed the glTF file in more detail. I discovered that the Y and Z coordinates in the glTF file are defined differently compared to Blender. Specifically, in the glTF file, the Y-axis is crucial for placement on the ground, whereas in Blender, it’s the Z-axis.

This was the reason why my calculations were incorrect the whole time. I was working with the wrong axis. This is definitely something to watch out for. It’s an important point to understand.

1 Like