Skip to content

Commit 822fd08

Browse files
committed
Merge pull request #108114 from lawnjelly/fti_multimesh_reset_all
`FTI` - Add `multimesh_instances_reset_physics_interpolation()`
2 parents fb81777 + 1c8ef47 commit 822fd08

File tree

9 files changed

+36
-0
lines changed

9 files changed

+36
-0
lines changed

doc/classes/MultiMesh.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
This allows you to move instances instantaneously, and should usually be used when initially placing an instance such as a bullet to prevent graphical glitches.
6060
</description>
6161
</method>
62+
<method name="reset_instances_physics_interpolation">
63+
<return type="void" />
64+
<description>
65+
When using [i]physics interpolation[/i], this function allows you to prevent interpolation for all instances in the current physics tick.
66+
This allows you to move all instances instantaneously, and should usually be used when initially placing instances to prevent graphical glitches.
67+
</description>
68+
</method>
6269
<method name="set_buffer_interpolated">
6370
<return type="void" />
6471
<param index="0" name="buffer_curr" type="PackedFloat32Array" />

doc/classes/RenderingServer.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,6 +2772,14 @@
27722772
Sets the [Transform2D] for this instance. For use when multimesh is used in 2D. Equivalent to [method MultiMesh.set_instance_transform_2d].
27732773
</description>
27742774
</method>
2775+
<method name="multimesh_instances_reset_physics_interpolation">
2776+
<return type="void" />
2777+
<param index="0" name="multimesh" type="RID" />
2778+
<description>
2779+
Prevents physics interpolation for all instances during the current physics tick.
2780+
This is useful when moving all instances to new locations, to give instantaneous changes rather than interpolation from the previous locations.
2781+
</description>
2782+
</method>
27752783
<method name="multimesh_set_buffer">
27762784
<return type="void" />
27772785
<param index="0" name="multimesh" type="RID" />

scene/resources/multimesh.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,10 @@ void MultiMesh::reset_instance_physics_interpolation(int p_instance) {
308308
RenderingServer::get_singleton()->multimesh_instance_reset_physics_interpolation(multimesh, p_instance);
309309
}
310310

311+
void MultiMesh::reset_instances_physics_interpolation() {
312+
RenderingServer::get_singleton()->multimesh_instances_reset_physics_interpolation(multimesh);
313+
}
314+
311315
void MultiMesh::set_physics_interpolated(bool p_interpolated) {
312316
RenderingServer::get_singleton()->multimesh_set_physics_interpolated(multimesh, p_interpolated);
313317
}
@@ -382,6 +386,7 @@ void MultiMesh::_bind_methods() {
382386
ClassDB::bind_method(D_METHOD("set_instance_custom_data", "instance", "custom_data"), &MultiMesh::set_instance_custom_data);
383387
ClassDB::bind_method(D_METHOD("get_instance_custom_data", "instance"), &MultiMesh::get_instance_custom_data);
384388
ClassDB::bind_method(D_METHOD("reset_instance_physics_interpolation", "instance"), &MultiMesh::reset_instance_physics_interpolation);
389+
ClassDB::bind_method(D_METHOD("reset_instances_physics_interpolation"), &MultiMesh::reset_instances_physics_interpolation);
385390
ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &MultiMesh::set_custom_aabb);
386391
ClassDB::bind_method(D_METHOD("get_custom_aabb"), &MultiMesh::get_custom_aabb);
387392
ClassDB::bind_method(D_METHOD("get_aabb"), &MultiMesh::get_aabb);

scene/resources/multimesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class MultiMesh : public Resource {
115115
Color get_instance_custom_data(int p_instance) const;
116116

117117
void reset_instance_physics_interpolation(int p_instance);
118+
void reset_instances_physics_interpolation();
118119

119120
void set_physics_interpolated(bool p_interpolated);
120121

servers/rendering/rendering_server.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,7 @@ void RenderingServer::_bind_methods() {
25432543
ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolated", "multimesh", "interpolated"), &RenderingServer::multimesh_set_physics_interpolated);
25442544
ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolation_quality", "multimesh", "quality"), &RenderingServer::multimesh_set_physics_interpolation_quality);
25452545
ClassDB::bind_method(D_METHOD("multimesh_instance_reset_physics_interpolation", "multimesh", "index"), &RenderingServer::multimesh_instance_reset_physics_interpolation);
2546+
ClassDB::bind_method(D_METHOD("multimesh_instances_reset_physics_interpolation", "multimesh"), &RenderingServer::multimesh_instances_reset_physics_interpolation);
25462547

25472548
BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_2D);
25482549
BIND_ENUM_CONSTANT(MULTIMESH_TRANSFORM_3D);

servers/rendering/rendering_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ class RenderingServer : public Object {
514514
virtual void multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated) = 0;
515515
virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, MultimeshPhysicsInterpolationQuality p_quality) = 0;
516516
virtual void multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index) = 0;
517+
virtual void multimesh_instances_reset_physics_interpolation(RID p_multimesh) = 0;
517518

518519
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0;
519520
virtual int multimesh_get_visible_instances(RID p_multimesh) const = 0;

servers/rendering/rendering_server_default.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ class RenderingServerDefault : public RenderingServer {
424424
FUNC2(multimesh_set_physics_interpolated, RID, bool)
425425
FUNC2(multimesh_set_physics_interpolation_quality, RID, MultimeshPhysicsInterpolationQuality)
426426
FUNC2(multimesh_instance_reset_physics_interpolation, RID, int)
427+
FUNC1(multimesh_instances_reset_physics_interpolation, RID)
427428

428429
FUNC2(multimesh_set_visible_instances, RID, int)
429430
FUNC1RC(int, multimesh_get_visible_instances, RID)

servers/rendering/storage/mesh_storage.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ void RendererMeshStorage::multimesh_instance_reset_physics_interpolation(RID p_m
329329
}
330330
}
331331

332+
void RendererMeshStorage::multimesh_instances_reset_physics_interpolation(RID p_multimesh) {
333+
MultiMeshInterpolator *mmi = _multimesh_get_interpolator(p_multimesh);
334+
if (mmi && mmi->_data_curr.size()) {
335+
// We don't want to invoke COW here, so copy the data directly.
336+
ERR_FAIL_COND(mmi->_data_prev.size() != mmi->_data_curr.size());
337+
float *w = mmi->_data_prev.ptrw();
338+
const float *r = mmi->_data_curr.ptr();
339+
memcpy(w, r, sizeof(float) * mmi->_data_curr.size());
340+
}
341+
}
342+
332343
void RendererMeshStorage::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
333344
return _multimesh_set_visible_instances(p_multimesh, p_visible);
334345
}

servers/rendering/storage/mesh_storage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class RendererMeshStorage {
152152
virtual void multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated);
153153
virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, RS::MultimeshPhysicsInterpolationQuality p_quality);
154154
virtual void multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index);
155+
virtual void multimesh_instances_reset_physics_interpolation(RID p_multimesh);
155156

156157
virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible);
157158
virtual int multimesh_get_visible_instances(RID p_multimesh) const;

0 commit comments

Comments
 (0)