godotengine / godot

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

MeshLibraries don't preserve editor-created materials #24130

Closed Dar13 closed 5 years ago

Dar13 commented 5 years ago

Godot version:

3.0.6 (self-built from commit 8ac39d886307d76c286e804e027fc39f6b5aaac6) master (commit 8dd00ed1762c4956b3231d709ce0d01ee9b306c8)

OS/device including version:

Arch Linux (4.19.4-arch1-1-ARCH, Mesa 18.2.5-1)

Issue description:

Materials on editor-created meshes are not preserved in a MeshLibrary created via "Convert To -> MeshLibrary". It sounds very similar to what was happening in #1239, but I'm not sure it's the same issue.

Steps to reproduce:

  1. Create scene with a root node and a child MeshInstance where mesh is created via "New PlaneMesh"
  2. Create a SpatialMaterial for mesh, set Albedo to (255,0,0)
  3. Save scene, then "Convert To" -> "MeshLibrary..."
  4. Create GridMap in new scene, using the MeshLibrary created in Step 3 as theme.
  5. Place the plane on grid

Expected: A red plane Result: A white plane

Minimal reproduction project: gridmap_material_issue_example.zip

Additional Information: master build printed out the following after executing Step 3:

ERROR: create_from_image: Condition ' p_image.is_null() ' is true.
   At: scene/resources/texture.cpp:191.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: _write_resource: Resource was not pre cached for the resource section, bug?
   At: scene/resources/scene_format_text.cpp:1369.

And the following after Step 4:

ERROR: create_from_image: Condition ' p_image.is_null() ' is true.
   At: scene/resources/texture.cpp:191.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
ERROR: texture_get_data: Condition ' !texture->active ' is true. returned: Ref<Image>()
   At: drivers/gles3/rasterizer_storage_gles3.cpp:1033.
bojidar-bg commented 5 years ago

From what I remember from past issues/discussions, this is caused by the MeshLibrary collecting the Mesh resources, which do not contain the overridden Materials. There are two main ways this might be solved in:

  1. Add material overrides to the MeshLibrary (and respectively, to the GridMap). This might also mean adding them to MultiMeshInstance as well. While this is probably the best solution, it is likely to take some effort to implement.
  2. Duplicate and change the Mesh resource if material overrides are detected, else continue as normal. As this will result in duplication of the Mesh (which is potentially a huge resource), this is probably a bad idea.
DesertFroggo commented 5 years ago

Can confirm as well.

Godot 3.1 beta1

Toshiwoz commented 5 years ago

Seems the same problem I'm having.

What I did was:

Dogpot commented 5 years ago

Can confirm this is still an issue on 3.1 beta2

novemberisms commented 5 years ago

This is still an issue in 3.1 beta 3. Is anyone working on this? It seems like a pretty important bug for the 3d workflow.

Toshiwoz commented 5 years ago

This is still an issue in 3.1 beta 3. Is anyone working on this? It seems like a pretty important bug for the 3d workflow.

For now I found a workaround:

If you then import into the GridMap you should have those materials, I think this is the same think @bojidar-bg was mentioning above.

reduz commented 5 years ago

Clarified this in documentation here: https://github.com/godotengine/godot-docs/commit/f118ce32137ba57174def4e0e8290e11a3e85c9c Also, errors shown before no longre happen, so closing this.

Sogomn commented 5 years ago

I don't see why this has been closed. I just started getting into Godot and this is a huge turnoff. I really don't fancy creating ten meshes that are exactly the same just because I want to use the same cube with a different texture in my gridmap.

richard-hajek commented 5 years ago

Love Godot, but this issue, while having workarounds, is still and issue. I don't see why it has been closed either.

Calinou commented 5 years ago

@meowxiik Wasn't this solved by https://github.com/godotengine/godot/pull/25522? If so, it may be a matter of documenting it more clearly.

richard-hajek commented 5 years ago

@Calinou Huh I see. It still happens to me but I've been able to figure out a relatively unpainful workaround, so I don't really mind it anymore.

Calinou commented 5 years ago

@meowxiik How does the workaround work? Maybe it could be documented :slightly_smiling_face:

richard-hajek commented 5 years ago

@Calinou My approach was similiar to @Toshiwoz, except simpler:

DO NOT ACTUALLY USE THIS, I have just discovered changes made like this do NOT survive project reload. See the bottom for more details.

All scenes containing this MeshLib update immidiatelly. So the fact it doesn't save is maybe a bug? Or if that is intended, one of those image would be handy. (My build of Godot is v3.1.1 Mono Stable Official)

Toshiwoz commented 5 years ago

I understand concerns about closing this issue. But strictly speaking this one is solved. The problem is more the improvements needed to the feature in general, and AFAIK it will be worked on, I hoped on 3.2 but may be delayed, depending on volunteers will, and patreons + community votes (perfectly fine for me). I abandoned completely the use of this feature for now as I found using procedurally generated mesh more fit to my project.

tustin2121 commented 3 years ago

So this bug is still in the engine and this issue was closed because the documentation was updated? So it's still not possible to apply different materials to a gridmap, and the material used has to be something exported with the geometry even though that material will never be actually usable? And you want people to actually use this engine when you leave massive bugs in like this?

Calinou commented 3 years ago

@tustin2121 I have to remind you that we have a Code of Conduct. Please stay constructive.

tustin2121 commented 3 years ago

@tustin2121 I have to remind you that we have a Code of Conduct. Please stay constructive.

I don't know how much more constructive I can be when expressing my disbelief that a bug that's been keeping me from using the engine has yet to be fixed after several versions and two years. And that for speaking up about this, I get a slap on the wrist like I've done something wrong.