Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing a OBJ mesh into a MeshInstance2D completely messes its transforms #85963

Closed
Azagwen opened this issue Dec 9, 2023 · 4 comments · Fixed by #86144
Closed

Importing a OBJ mesh into a MeshInstance2D completely messes its transforms #85963

Azagwen opened this issue Dec 9, 2023 · 4 comments · Fixed by #86144

Comments

@Azagwen
Copy link

Azagwen commented Dec 9, 2023

Tested versions

Reproductible in v4.2.stable.mono.official [46dc277]
Not Reproductible in v4.1.3.stable.official [f06b6836a]

System information

Godot v4.2.stable.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 (NVIDIA; 30.0.15.1165) - Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz (8 Threads)

Issue description

I'm doing a 2D game in a very polygonal/vector style, and I was planning on using 2D Meshes.
However, upon re-importing my meshes in 4.2, I noticed that all of them were incorrectly scaled in the 2D Viewport, despite their actual (Node2D) scale not changing.

The situation in Godot v4.2.stable.mono.official [46dc27791]

What I expected the mesh to look like (screenshot from Blender, the mesh is built on the XZ axis, and exported to use Y as up, so it should be on XY in Godot)
image

The mesh in Godot's 2D viewport, it was clearly offset to the bottom left, and squished on one axis. Its visual scale is also immensely smaller than the export scale.
image

The MeshInstance's full hitbox (the model isn't even visible anymore)
image

Double-checking

Now, to Check that I wasn't just going Insane or doing something wrong, I tried to create a completely new project AND a completely blank blend file with this mesh that I quickly cobbled together.
image

However, when I imported it to Godot, I was met with this, and to double check that it was also doing what I described above...
image
... I superposed the blender viewport and Godot viewport, and this mesh seems to also be squished, with no intervention on my part
image

Checking in Godot 4.1

To be fully sure, I imported the same OBJ meshes in Godot v4.1.3.stable.official [f06b6836a].
Which seems to work as expected
image
image

Steps to reproduce

  • Create a flat mesh in Blender (or any software of your choice)
  • Export that mesh as a OBJ, so that it should be aligned with the XY plane
  • Import it in a fresh Godot project
  • Create a 2D scene, and add a MeshInstance2D to it
  • Assign your mesh to the MeshInstance2D's mesh field
  • Verify that its Hitbox matches its bounds, and that it wasn't deformed or moved around by the importer

Minimal reproduction project (MRP)

4.2 and 4.1 Projects used in this report linked below
godot_4.1_bug_hunt.zip
godot_4.2_bug_hunt.zip

@Azagwen Azagwen changed the title Importing a OBJ mesh into a MeshInstance2D completely messes its scale Importing a OBJ mesh into a MeshInstance2D completely messes its transforms Dec 9, 2023
@clayjohn
Copy link
Member

clayjohn commented Dec 9, 2023

This seems to be caused by the new mesh compression option.

You can fix the problem by disabling mesh compression in the import settings:

image

I can think of two possible engine changes that would help alleviate this issue:

  1. We could detect if the z channel is used in the vertex positions, if z is always 0, we could assume the mesh is 2D and disable compression
  2. We could add a callback that disables compression if the mesh is used in 2D (we do something similar for textures where we enable compression if used in 3D)

@clayjohn clayjohn added this to the 4.3 milestone Dec 9, 2023
@Azagwen
Copy link
Author

Azagwen commented Dec 9, 2023

This seems to be caused by the new mesh compression option.

You can fix the problem by disabling mesh compression in the import settings:

I can think of two possible engine changes that would help alleviate this issue:

1. We could detect if the z channel is used in the vertex positions, if z is always 0, we could assume the mesh is 2D and disable compression

2. We could add a callback that disables compression if the mesh is used in 2D (we do something similar for textures where we enable compression if used in 3D)

I can confirm that this seems to fix it! I hadn't thought of trying this 😅

@clayjohn
Copy link
Member

clayjohn commented Dec 9, 2023

This seems to be caused by the new mesh compression option.
You can fix the problem by disabling mesh compression in the import settings:
I can think of two possible engine changes that would help alleviate this issue:

1. We could detect if the z channel is used in the vertex positions, if z is always 0, we could assume the mesh is 2D and disable compression

2. We could add a callback that disables compression if the mesh is used in 2D (we do something similar for textures where we enable compression if used in 3D)

I can confirm that this seems to fix it! I hadn't thought of trying this 😅

To be fair, its a new option and it wasn't needed before. We are still figuring out how to make the option more visible to users as there are cases where it will be needed.

In this case though, I think we can figure out an in-engine fix that won't require you to toggle the option. Its just a workaround for now

@GrauBlitz
Copy link

I can also confirm this issue in v4.3-dev5 with .glb files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants