godotengine / godot

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

glTF importer ignores "-colonly" import hint on Blender empty objects #32363

Open jeffres opened 5 years ago

jeffres commented 5 years ago

Godot version:

Both 3.1.1 and 202440a

OS/device including version:

Ubuntu 19.10

Issue description:

Documentation on import hints states that:

Option “-colonly” can also be used with Blender’s empty objects. On import, it will create a StaticBody with a collision node as a child.

However, when importing a glTF file with such an empty into Godot, it just turns into a Spatial node as such:

image

A Collada file exported from the same Blender scene shows the expected behavior:

image

where Cube3-TestColonly is a StaticBody and BoxShape is a CollisionShape

Steps to reproduce:

Minimal reproduction project:

glTF import test.zip

The project directory also includes the Blender (2.80) file used to export the glb and dae (with Better Collada exporter) files.

The node of interest is Cube3-TestColonly, other ones are here to showcase other kind of import hints.

akien-mga commented 5 years ago

Relevant code: https://github.com/godotengine/godot/blob/04032a94459ebb6a65930e4b37778e3e82323a19/editor/import/resource_importer_scene.cpp#L379-L465

CC @marstaik @fire

jeffres commented 5 years ago

@akien-mga: thanks, I'll let you know if I have any clue.

jeffres commented 5 years ago

It clearly seems to come from the "empty_draw_type" meta data not being set in the node at glTF import time.

If I force it with this patch (very quick and dirty of course), Cube3-TestColonly gets converted to a StaticBody as expected.

But I don't know how to identify empties at import time yet. When exporting the Blender scene to a plain text gltf file, it doesn't really differ from other objects (expect that it has no mesh attached but so does a light).

I'm trying to have a look at glTF exporter documentation for more info.

marstaik commented 5 years ago

In the gltf importer, all the empty node candidates are the spatial nodes. Spatial nodes only get created when neither mesh, camera, skin, joint, etc is flagged on an import node. Basically, it's the end case for no mesh/camera.

What I do not know however, is what is considered an empty_draw_type. Is it just a spatial node? Or is it any node with no render body? Or is it the above + no renderable children?

@reduz might have insight

jeffres commented 5 years ago

Ok thanks, that's interesting.

Which leads me to notice that, on the Collada side, empties are taken explicitly in charge by the Better Collada exporter that adds some extra information in the dae file, which are then handled by the importer:

<node id="Cube3-TestColonly-colonly" name="Cube3-TestColonly-colonly" type="NODE">
    <matrix sid="transform"> 1.0 0.0 0.0 3.5 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0  </matrix>
        <extra>
            <technique profile="GODOT">
                <empty_draw_type>CUBE</empty_draw_type>
            </technique>
        </extra>
</node>

When exporting with Blender default Collada exporter, those extra information are missing, which leads to the same behavior as with glTF (no StaticBody created at import time).

Klowner commented 5 years ago

Might be good to attack this issue from both ends? Seems there's been some effort put forward to add rigid body info to glTF but the discussion seems to have stalled. https://github.com/KhronosGroup/glTF/issues/1307

fire commented 4 years ago

Current list of flags that need to be recognized:

https://docs.godotengine.org/en/latest/getting_started/workflow/assets/importing_scenes.html#animation-loop-loop-cycle

aclave1 commented 4 years ago

In 3.2, i'm only noticing this issue when the exported object is parented to an armature. I've attached a glb which demonstrates the issue. chest.zip

fire commented 4 years ago

Try gltf master from blender, this is why the release notes mention blender 2.83.

aclave1 commented 4 years ago

What do you mean gltf master from blender? I should try to run from blender's master branch? I'm new to the project, where are the release notes that mention blender 2.83?

KoBeWi commented 3 years ago

Seems still valid in 3.2.4 beta4

babak-karimi-asl commented 2 years ago

problem still exists with blender-3.0.0 and godot-3.4, are there any quick workarounds ?

mina-skunk commented 2 years ago

I'm still running into this issue with Godot 3.4.4 and Blender 3.1.2

wenqiangwang commented 2 years ago

Godot 4.0 b1 have the same issue. '-col' works but '-colonly' on empty objects not working.

fire commented 2 years ago

I wonder why it's wrong, need to get the godot-tests to the godot master and do a look https://github.com/godotengine/godot-tests

mrkdji commented 2 years ago

I believe this should be mentioned in the docs

portaloffreedom commented 1 year ago

I just tested this on both godot4 (compiled from master) and godot3.5.1 with GLTF, .escn (godot-blender-exporter) and the default collada .dae exporter in blender. -colonly on empties works only on .escn files in godot3.5.1 -col on a mesh works everywhere except .escn in godot4

so, godot4 has .escn file reading completely ignoring all suffixes I've tried .dae and .gltf ignore empties on both versions of godot. .escn on godot3.5.1 is the only one working correctly

it could be that better-collada-exporter changes something, but I was not able to install it easily.

edit: inspecting the .escn file there doesn't seem to be any reference to godot3 specific classes, the empties get written this way:

[node name="column-collision016-colonly" type="Spatial" parent="column007"]

transform = Transform(0.35, 0.0, 0.0, 0.0, 10.3, 0.0, 0.0, 0.0, 0.35, 0.0, 10.0, 0.0)
__meta__ = { "empty_draw_type": "CUBE" }

edit: The Better Collada Exporter seem to work correctly.

warcanin commented 1 year ago

Maybe instead of complicating the process we could just add different hints like -boxcol -spherecol -cylindercol etc... The must for blender import would obviously be that the rigid body settings and it's collision shape are transfered automatically but that would be harder than just fixing the hint problem. edit: It seems that the checkbox image doesn't work at all, the only option to not import meshes is to add the -noimp hint at the end of the object

Alastor01 commented 1 year ago

Godot 4.0 RC2, Blender 3.4

The issues is not limited to GLTF importer (which includes both direct Blend import as well as exported GLTF). It also affects Collada exports, so I assume all file types are affected.

The issue is not limited to Empties of Cube type either - it affects all shapes of Empty - that is none work.

Col / colonly makes no difference - neither work.

Exporting Empty collision shapes by themselves, without mesh parent, doesn't work either.

Polygonal shapes work as expected.

lyuma commented 1 year ago

I would appreciate an example file from someone encountering this issue on Godot 4

To be clear, this is a feature where specific collision shapes can be added to empty nodes, but only when coming from Blender? If so, I believe this feature is not fully implemented in Godot 4 due to the new blend -> gltf import pipeline. It relies on something called get_meta which requires the importer to fill it out.

As an alternative to blend->gltf import, there is ESCN which does technically function in Godot 4. However, due to the version upgrade and the fact that most exporters are designed for Godot 3, we cannot fully support ESCN workflow in Godot 4.0 until the tooling is updated (chicken/egg problem). Renaming a .tscn to .escn is the only fully supported usage of ESCN import at this time. Correct me if I'm wrong, @fire

Having an actual example (blend or gltf) would help us triage this specific issue, but otherwise the clock has run out for 4.0, and due to the implementation complexity of supporting node metadata not standardized in gltf, I'm not sure it's trivial to fix. We may look into this in a future 4.x release.

lyuma commented 1 year ago

Okay I see the other usecase is convering a node into a sort of placeholder StaticBody3D with no known collision shape attached. is that correct? That might be possible to get working for 4.0 by removing the check for if (shapes.size()) in resource_importer_scene.cpp.

I might be in favor of this. It means imported scenes will not be fully functional since they will be missing collision shapes, but it will provide a space to add your own. Is this what you all are expecting?

Alastor01 commented 1 year ago

Import_Bug.zip

Very simple example, two meshes - one which generates polygonal collision shape, the other should generate primitive box collider - but does not.

miskatonicstudio commented 11 months ago

Hi! I just checked Empty export from Blender (v3.6.5) to Godot (v4.1.1) and it still doesn't work (tested with sphere and cube). It seems like a great option to have, allowing us to use primitive shapes instead of complex ones for collisions ;) It seems that this issue hasn't been fixed in a while, do you think that's going to change anytime soon? If not, perhaps the documentation could be updated?

https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/importing_scenes.html#create-collisions-col-convcol-colonly-convcolonly