godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.44k stars 21.07k forks source link

Any way to import OBJ/GLTF with objects as separate scenes, centered at origin? #13980

Closed Zylann closed 1 month ago

Zylann commented 6 years ago

In Godot 3.0 beta 1

I have a Blender file in which I modeled dungeon parts, similar to "gridmap mesh library items", so that I can assemble them procedurally in my game. I have all models in the same .blend file because it's easier to work with (make items connectable) and share materials if needed. For comparison, it's a bit similar to the workflow for creating tilemaps in Godot, but with 3D models.

The problem is, when I import it with "Instanced sub-scenes", it correctly produces one scene per model, but they all conserve their offset, which makes them unusable. I found that Blender exports OBJ without pivot information, so vertices themselves end up having the offset... so I may try GLTF hoping it has more capabilities.

However I still wonder, could there be a way to choose to import models at origin instead of their [convenience-only] position? I don't want to move everything at the origin everytime I export from Blender, and I don't want to re-offset them all .scn one by ones, especially because I may change their position in Blender purely for convenience.

djrm commented 6 years ago

i know this might not be relevant but i ended up creating a blender script that exports multiple objs for every object, so i end up with just the meshes correctly centered.

Zylann commented 6 years ago

@djrm I thought of this too, but it kind of defeats material re-use...

djrm commented 6 years ago

i dont export materials, just the meshes (well with placeholder materials to preserve the material groups), then create scene to setup the materials, it is a bit painful but works. but yeah i really dont know if this should be a DCC issue or godot issue (both are valid).

Web-eWorks commented 6 years ago

Using the post-import script option in the import dock, you can do almost anything you want to the scene. Here is the currently undocumented class, and here is the code where it is applied.

Toshiwoz commented 5 years ago

Using the post-import script option in the import dock, you can do almost anything you want to the scene. Here is the currently undocumented class, and here is the code where it is applied.

I noticed that lil'box, and it would be great to be able to use it, yet, with no documentation it will take a while to figure out how to use it. Yes, being able to use that it will open the gates of heaven, probably we can do magic in there.

I think this is the commit that implemented this, so I guess @reduz is the only one able to provide some information about it. https://github.com/godotengine/godot/commit/209cb3830c605edef494d45253b89bd76b3bbbc3#diff-c7a13e481cde417ca3cfa672811009e1

fire commented 4 years ago

Maybe this patch https://github.com/godotengine/godot/pull/35006 can be improved for this usage.

aaronfranke commented 1 month ago

This feature is available in Godot 4.0 and later, using the "Meshes" tab in the Advanced Import Settings dialog. Meshes within a .glb file can be saved to a separate file, such as .res, which can then be used on a MeshInstance3D node like you can with individual OBJ files. For example, the Truck Town demo uses this for the vehicle models:

Screenshot 2024-09-08 at 2 24 45 AM