StrayEddy / GodotPlugin-MeshPainter

Mesh painter plugin for Godot
Creative Commons Zero v1.0 Universal
23 stars 4 forks source link

3D-cursor sphere doesn't show properly #24

Open Flavelius opened 2 years ago

Flavelius commented 2 years ago

I was interested in seeing how you manage to project view- or worldspace to UV, and i couldn't pinpoint the exact part that does the conversion while browsing the code on github; so i decided to download the whole repo and open it in 3.5rc6. Upon opening the project, i had like 80 import errors. When reopening it, i got the popup saying it created the necessary folders and textures. The folders got created, but no texture or anything in it. When trying to paint, it just throws a lot of errors, but doesn't do anything else: core/bind/core_bind.cpp:2751 - Condition "p_method == StringName() || !p_instance->has_method(p_method)" is true. Returned: ERR_INVALID_PARAMETER Thread must have been started to wait for its completion. scene/3d/spatial.cpp:385 - Condition "!is_inside_tree()" is true. Returned: Transform() tex_albedo_brush core/bind/core_bind.cpp:2751 - Condition "p_method == StringName() || !p_instance->has_method(p_method)" is true. Returned: ERR_INVALID_PARAMETER etc. Does it require godot 4 or some other specific version? (EDIT: i just saw it in the discord post - 3.4) It's also near impossible to see buttons and icons when using the light editor theme (they all blend with the background) grafik

Flavelius commented 2 years ago

I tried opening it in 3.4. It doesn't throw any errors, but it also doesn't display the 3D-cursor sphere. When clicking on the mesh to paint, it just closes the paint inspector. The editor also slows down progressively, when selecting and reselecting the paint mode, maybe some resources are leaked? And when reopening the project, it reimports all its textures every time, taking a good amount of time.

Flavelius commented 2 years ago

Would you mind explaining how the projection works? I really don't understand how this can even possibly work. in plugin_cursor.gd there's:

var local_pos = mesh_instance.to_local(hit.position)
var brush_info = Color(local_pos.x, local_pos.y, local_pos.z, brush_size)
...
brush_buffer.append(brush_info)

then:

for i in range(0, brush_buffer.size()):
        var x = i % width
        var y = i / width
        brush_image.set_pixel(x, y, brush_buffer[i])

How does the mesh-local 3D position directly relate to the 2D uv-space without conversion?

StrayEddy commented 2 years ago

Hi Flavelius, there are no UV projection and that is why you can't find code related to that anywhere. The way the shader works is it keeps a track of all 3D positions on the mesh where you paint (keeps a list of 3d brush positions in the brush.mpaint. Than the shader will check how far a pixel is from the brush positions to determine its value (albedo, roughness, metalness, emission).

Brush-info contains the 3d position of the brush, raycasted on the mesh you are painting, and the size of the brush: Color(local_pos.x, local_pos.y, local_pos.z, brush_size)

To paint the mesh you first have to select a MeshInstance in the tree. Than click on the paint button for the paint brush sphere to appear. If you could send me a video or gif showing what you mean, that would be great.

Thanks for your feedback, there is still a lot of work needed on this plugin, but I can assure you that it works for 3.4.

If you want to retest with a clean state, you can: 1- Remove the ShaderMaterial inside your MeshInstance 2- Delete the meshpainter-textures folder 3- Disable and Re-enable the plugin

You should than properly see the brush sphere and be able to paint. Could you retest by following this procedure please ?

Flavelius commented 2 years ago

That's unfortunate, i hoped someone finally found a good way to access UVs in worldspace in a performant way, but this then even shifts the performance heavy part into the runtime, and is not what i was looking for. Interesting workaround nonetheless.

But, here are two clips, one where i deleted the folder to paint directly and one right after restarting godot thereafter; they basically have the same outcome

https://user-images.githubusercontent.com/8841352/179990355-a8f8e47f-dd0e-471b-9c07-0bf43b9a47db.mp4

https://user-images.githubusercontent.com/8841352/179990366-3c7f0fc8-2b2e-43c7-b706-70904ace280b.mp4

StrayEddy commented 2 years ago

Thank you for that info. The shader is actually not that costly, but it really depends on how much painting you did (number of brush positions). The first video shows that the cursor did not show when it definitely should have. If you do have a chance, could you send me what the output console showed at that time. There must have been some error showing up there for the cursor to not show at all. Anyway, thanks a lot for your feedback

Flavelius commented 2 years ago

You can kind of see in the video that the output at the bottom actually printed no errors (no red dot)

StrayEddy commented 2 years ago

That's unfortunate, i hoped someone finally found a good way to access UVs in worldspace in a performant way...

Actually there is this attempt at it, but it's not a plugin: Godot Texture Painter