JekSun97 / gdTree3D

Plugin for procedural generation of 3D trees of varying complexity for Godot Engine.
Other
136 stars 3 forks source link

Duplication problem #1

Open JekSun97 opened 1 month ago

JekSun97 commented 1 month ago

I noticed a problem when duplicating a Tree3D node using Ctrl+D: if we change any leaf or branch value, we see that the old mesh of the duplicate node remains and it looks like one tree is overlaid on top of another.

This multi-level tree disappears after the project is restarted.

I don't know how to solve this problem yet, if anyone has any ideas, I'd be glad for your help.

mrjustaguy commented 1 month ago

From a cursory glance at the code, I see you are using Surface tool, and I don't see any surface_clear which might resolve the issue - https://docs.godotengine.org/en/stable/tutorials/3d/procedural_geometry/immediatemesh.html#using-immediatemesh

JekSun97 commented 1 month ago

@mrjustaguy This is unlikely to solve the problem, especially since SurfceTool also has a "clear" method

RonYanDaik commented 1 month ago

What happens is that editor copies all child nodes (trunk and leash nodes are just invisible to editor) but you create nodes on constructor again.
I think what you need to do:

  1. When creating mesh instance assign owner to make nodes visible (copy from parent nodes)
  2. Expose those member nodes to editor
  3. Move creation into _ready instead in constructor and check if member variables are valid

Also you need to expose MeshInstances3D to editor because user might want and need to use them. (For example when he well be creating custom culling system, or he might want to save mesh to disk because mesh instance allows that end etc.)

Also I don't think you need parent as node3d. Might be better to inherit it from MeshInstance3d and to not create one more node.

JekSun97 commented 3 weeks ago

@RonYanDaik I have made the MeshInstance3D available to the editor using

void Tree3D::_ready() {
trunk_inst->set_owner(get_owner());
twig_inst->set_owner(get_owner());
}

and when we open the demo the MeshInstance3D are available to the editor, but when we create a new tree in the editor they are not available to the editor until we reload the project.

Also memnew in _ready() causes a crash, I tried to do this