-
-
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
[3.x] Physics interpolation - Zero server side multimesh data #91877
Conversation
To prevent possibility of use of uninitialized data.
Is there some alternative that would avoid interpolating with zero as the starting value? For example the MRP in #91818 (comment) (in the first post, not in the first reply) prints the position of the first instance, and without interpolation it is:
whereas with interpolation it is:
The script just does vertical movement, so it seems at least the interpolation with zero at the start has "attracted" the instance to the origin. |
I think there should be a |
Potentially there could be. The existing Certainly I wouldn't be against adding it. I erred on the side of implementing the minimum viable product and then waiting for feedback before adding more features. And we are likely to get feedback a lot quicker for 4.x as there are many more users. BTW I'm guessing you are hinting about having it auto-detect the first update and do a reset. Will write more but have to turn PC off as there is lightning storm here. ⚡ |
I wanted to add (using the Godot 4 syntax): void RendererMeshStorage::multimesh_reset_physics_interpolation(RID p_multimesh) {
MultiMeshInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
if (mmi) {
mmi->_data_prev = mmi->_data_curr;
}
} to reset all instances, and call it when Adding the following workaround to the script then does fix the "attraction to zero" issue mentioned above:
I'm not sure what's the best way to make it work out-of-the-box. Edit: The following would make the buffer reassignment automatic: diff --git a/servers/rendering/storage/mesh_storage.cpp b/servers/rendering/storage/mesh_storage.cpp
index eb2640a9f1..0148176ade 100644
--- a/servers/rendering/storage/mesh_storage.cpp
+++ b/servers/rendering/storage/mesh_storage.cpp
@@ -261,7 +261,11 @@ void RendererMeshStorage::multimesh_set_buffer_interpolated(RID p_multimesh, con
void RendererMeshStorage::multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated) {
MultiMeshInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
if (mmi) {
+ bool was_interpolated = mmi->interpolated;
mmi->interpolated = p_interpolated;
+ if (p_interpolated != was_interpolated) {
+ multimesh_set_buffer(p_multimesh, multimesh_get_buffer(p_multimesh));
+ }
}
} Now I just need to find why we need to call Edit 2: Ah, I just didn't port the part that does it automatically on Does this solution look reasonable? (We can still additionally zero the data, for people using servers.) Edit 3: Oh, the automatic mechanism sending Edit 4: We could just hardcode an extra reset in |
This is really getting off topic for this PR, as the PR is just a safety to prevent reading uninitialized data rather than trying to solve resets. Reset discussion should really go in its own PR or proposal. But to continue:
The instance transforms are defined in the node coordinate space, both are potentially interpolated and both should be capable of resetting independently. Resetting both together would lose a degree of freedom. Consider for example you might want to move a node, reset the node, but keep the instances interpolating in local space. Or you might wish to reset the instances but not reset the node transform. Currently, internally you can just already just call I (unsurprisingly 😁 ) did look quite a bit into doing an automatic reset when adding 3D nodes to the tree and experimented with it, but there were some situations in which it created problems (I forget the details, it may have been things like reparenting nodes within the tree without mucking up their interpolation, moving origins, and there can be issues with order of operations on loading / construction). In the end I decided to postpone 3D resets on adding to the tree until we have a bit more testing in the wild, and all the potential problems ironed out. I'm a bit wary that in future we could end up having to add ugly workarounds as a result of jumping the gun on such automation. Overall initially I would advise being cautious and implementing the minimum in general until we have further use data. Users will be overjoyed to have the basics working, and will be far better off waiting a little for us to get it right on the "icing on the top" features rather than rushing on the wrong solution and making things unworkable in the future. |
Fair enough. Thanks for the explanation! I will continue with the minimalist approach. |
Thanks! |
To prevent possibility of use of uninitialized data.
Notes
MultiMesh
#91818