-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add drag-and-drop support for materials in 3D Instances #56597
Conversation
4775b1f
to
980801a
Compare
980801a
to
9cdf295
Compare
Updated to support assignment to CSG objects. Requires this PR to work properly though #56602 |
9cdf295
to
e93163e
Compare
e93163e
to
6d84182
Compare
Okay, this has now been updated to a state that I think this can come out of draft and consider it ready for review. The biggest issue with code quality should be resolved now, a minor bug has been addressed, and new feature of being able to drag textures directly into your 3D scene has been added. |
6d84182
to
51f9daa
Compare
Hold on, I missed something... |
51f9daa
to
519ee22
Compare
Okay, should be sorted now |
b78e670
to
9fe6e8e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't able to give a deep technical review but my brief test shows the functionality does what I think it does.
2022-02-14.06-33-31.mp4
break; | ||
} | ||
|
||
editor->set_preview_material(mat); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is can_drop_data
, AFAIK it's only supported to check if the selected files contain anything that can be used as a result of drag and drop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (editor->get_preview_material().is_valid()) { | ||
ObjectID new_object_id = _select_ray(p_point); | ||
|
||
// Get the corresponding GeometryInstance for new_object_id, and if it is not valid, reset the new_object_id | ||
if (new_object_id.is_valid()) { | ||
GeometryInstance3D *geometry_instance = Object::cast_to<GeometryInstance3D>(ObjectDB::get_instance(new_object_id)); | ||
if (!geometry_instance) { | ||
new_object_id = ObjectID(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing, this is in the wrong callback. It should only be set when the drop action is actually confirmed (drop_data_fw
I believe).
My main issue with this is that it uses material override. I feel this should be setting the proper surface and not the override (or at least we should make it controllable somehow by hitting a key while dragging over the viewport). |
Maybe show some subtext while dragging at the bottom of the viewport like "hit space to switch between surface and override", or some option in the view menu setting? like DND Material -> Set Surface, Set Override. |
As discussed on PR this requires some more work, maybe other contributors familiar with it can help:
|
1d83275
to
dade434
Compare
@KoBeWi Okay, should be resolved now |
@@ -42,6 +42,7 @@ class Mesh : public Resource { | |||
GDCLASS(Mesh, Resource); | |||
|
|||
mutable Ref<TriangleMesh> triangle_mesh; //cached | |||
mutable Vector<Ref<TriangleMesh>> surface_triangle_meshes; //cached |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rather than doing this, it should be simpler to modify TriangleMesh to contain an index of the surface ID as an optional second argument Vector<int32_t> to triangle_mesh->create()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will also ensure that ray collision is correct.
Since I didn't write the per-surface assignment part of this, do you have any thoughts @gaudecker? The technique seems like it would be a little more efficent, but I feel there was likely reluctance to alter too many internal data structures for one feature; supplying an array of custom face IDs may not be too bad though, since it could possibly be used for other things outside of the scope of this too. @reduz One alternative approach I might want to mention though is instead of simply creating the TriangleMesh with the surface IDs directly, instead, we modify the intersection functions so the return the specific face ID (and maybe even the exact triangle intersection point too) which could then be cross-referenced with an external ID buffer which would give the surface IDX. The reason doing it this way might be better is it may make the TriangleMesh more generically useful when it comes to mapping intersections tests with other forms of regular mesh data, like UVs for example. It could be just me though, I tend to get a bit nervous about modifying APIs for one specific purpose unless I can claim there's other stuff changing it might be useful for. |
Actually, thinking about it, the internal TriangleMesh data would still likely need to be modified to factor the mapping between raw triangle data and face indicies, but my question was how generic this metadata should be |
@SaracenOne In the context of #59266, I think these meta-indices could probably work both for mesh surfaces and CSG faces. 🤔 There are probably other use-cases as well. |
I would just harcode it into TriangleMesh because this is only really used by the editor, to be honest. If other uses can be added, I think they should be added at the time they are needed. |
dade434
to
720deca
Compare
Helps unblock godotengine#56597
I opened #62321 to help unblock this PR. Once merged, it should make implementation of this easier as you can simply query the surface index of the ray collision. |
I will be salvaging this. |
Add mesh surface picking for material drag & drop, show drag info label
720deca
to
86aa2a8
Compare
Having an infinite loop in TriangleMesh::intersect_ray. Investigating. This is not the pr branch, but trying to use reduz's new api. |
@fire Did you have any luck so far? |
Not so much. I got stuck and I moved onto assisting tokage on animations and lyuma on ModificationStack conversion to nodes.. |
Ok, if for the PR it works well, your freeze is mostly unrelated because all my code did was add an extra return information. |
Thanks! |
I think this should not put the material on the Reasons:
|
PR for adding drag and drop support for materials into 3D editor viewport. Uses the material override slot by default.
Things changed since draft:
I would still like to add some extra features in the future such as being able to drag onto individual surfaces and/or a modifer key to choose the individual surface once the mouse is released (similar to what happens when you drag a material onto a mesh instance in the scene tree), but I think this is in a good enough state for review now.