From 96a1b867176498daf169c4b31842aa498c35fb7d Mon Sep 17 00:00:00 2001 From: lawnjelly Date: Fri, 26 Aug 2022 10:43:48 +0100 Subject: [PATCH] Bind Physics Interpolation functions in VisualServer To allow maximum flexibility in the initial rollout, VisualServer functions were not bound in order to prevent compatibility issues if the API changed. These functions are now bound to allow direct use from the VisualServer. --- doc/classes/VisualServer.xml | 74 ++++++++++++++++++++++++++ scene/resources/multimesh.cpp | 2 +- servers/visual/rasterizer.cpp | 4 +- servers/visual/rasterizer.h | 2 +- servers/visual/visual_server_raster.h | 2 +- servers/visual/visual_server_wrap_mt.h | 2 +- servers/visual_server.cpp | 10 ++++ servers/visual_server.h | 8 ++- 8 files changed, 97 insertions(+), 7 deletions(-) diff --git a/doc/classes/VisualServer.xml b/doc/classes/VisualServer.xml index 2b370bb9a30..abe44ca3b90 100644 --- a/doc/classes/VisualServer.xml +++ b/doc/classes/VisualServer.xml @@ -45,6 +45,14 @@ Once finished with your RID, you will want to free the RID using the VisualServer's [method free_rid] static method. + + + + + Prevents physics interpolation for the current physics tick. + This is useful when moving a [Camera] to a new location, to give an instantaneous change rather than interpolation from the previous location. + + @@ -72,6 +80,14 @@ Sets camera to use frustum projection. This mode allows adjusting the [code]offset[/code] argument to create "tilted frustum" effects. + + + + + + Turns on and off physics interpolation for the [Camera]. + + @@ -1404,6 +1420,14 @@ Sets a material that will override the material for all surfaces on the mesh associated with this instance. Equivalent to [member GeometryInstance.material_override]. + + + + + Prevents physics interpolation for the current physics tick. + This is useful when moving an instance to a new location, to give an instantaneous change rather than interpolation from the previous location. + + @@ -1445,6 +1469,14 @@ Sets a margin to increase the size of the AABB when culling objects from the view frustum. This allows you to avoid culling objects that fall outside the view frustum. Equivalent to [member GeometryInstance.extra_cull_margin]. + + + + + + Turns on and off physics interpolation for the instance. + + @@ -2115,6 +2147,15 @@ Returns the [Transform2D] of the specified instance. For use when the multimesh is set to use 2D transforms. + + + + + + Prevents physics interpolation for the specified instance during the current physics tick. + This is useful when moving an instance to a new location, to give an instantaneous change rather than interpolation from the previous location. + + @@ -2163,6 +2204,16 @@ [Transform] is stored as 12 floats, [Transform2D] is stored as 8 floats, [code]COLOR_8BIT[/code] / [code]CUSTOM_DATA_8BIT[/code] is stored as 1 float (4 bytes as is) and [code]COLOR_FLOAT[/code] / [code]CUSTOM_DATA_FLOAT[/code] is stored as 4 floats. + + + + + + + Alternative version of [method multimesh_set_as_bulk_array] for use with physics interpolation. + Takes both an array of current data and an array of data for the previous physics tick. + + @@ -2171,6 +2222,23 @@ Sets the mesh to be drawn by the multimesh. Equivalent to [member MultiMesh.mesh]. + + + + + + Turns on and off physics interpolation for the [MultiMesh]. + + + + + + + + Sets the physics interpolation quality for the [MultiMesh]. + A value of [code]0[/code] gives fast but low quality interpolation, a value of [code]1[/code] gives slower but higher quality interpolation. + + @@ -3801,6 +3869,12 @@ MultiMesh custom data uses a float per component. + + MultiMesh physics interpolation favours speed over quality. + + + MultiMesh physics interpolation favours quality over speed. + Reflection probe will update reflections once and then stop. diff --git a/scene/resources/multimesh.cpp b/scene/resources/multimesh.cpp index 9bd55274bd1..c9b37da0bff 100644 --- a/scene/resources/multimesh.cpp +++ b/scene/resources/multimesh.cpp @@ -219,7 +219,7 @@ void MultiMesh::set_visible_instance_count(int p_count) { void MultiMesh::set_physics_interpolation_quality(PhysicsInterpolationQuality p_quality) { _physics_interpolation_quality = p_quality; - VisualServer::get_singleton()->multimesh_set_physics_interpolation_quality(multimesh, (int)p_quality); + VisualServer::get_singleton()->multimesh_set_physics_interpolation_quality(multimesh, (VS::MultimeshPhysicsInterpolationQuality)p_quality); } int MultiMesh::get_visible_instance_count() const { diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp index 18c70c01d33..35cce2cb85f 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer.cpp @@ -466,11 +466,11 @@ void RasterizerStorage::multimesh_set_physics_interpolated(RID p_multimesh, bool } } -void RasterizerStorage::multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality) { +void RasterizerStorage::multimesh_set_physics_interpolation_quality(RID p_multimesh, VS::MultimeshPhysicsInterpolationQuality p_quality) { ERR_FAIL_COND((p_quality < 0) || (p_quality > 1)); MMInterpolator *mmi = _multimesh_get_interpolator(p_multimesh); if (mmi) { - mmi->quality = p_quality; + mmi->quality = (int)p_quality; } } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index ce71698a77b..8b0ff0bbdb7 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -389,7 +389,7 @@ public: virtual void multimesh_set_as_bulk_array_interpolated(RID p_multimesh, const PoolVector &p_array, const PoolVector &p_array_prev); virtual void multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated); - virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality); + virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, VS::MultimeshPhysicsInterpolationQuality p_quality); virtual void multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index); virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible); diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 8bdab6bc0a4..6eb315ce240 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -286,7 +286,7 @@ public: BIND3(multimesh_set_as_bulk_array_interpolated, RID, const PoolVector &, const PoolVector &) BIND2(multimesh_set_physics_interpolated, RID, bool) - BIND2(multimesh_set_physics_interpolation_quality, RID, int) + BIND2(multimesh_set_physics_interpolation_quality, RID, MultimeshPhysicsInterpolationQuality) BIND2(multimesh_instance_reset_physics_interpolation, RID, int) BIND2(multimesh_set_visible_instances, RID, int) diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 8b665d57002..3d87d18359d 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -209,7 +209,7 @@ public: FUNC3(multimesh_set_as_bulk_array_interpolated, RID, const PoolVector &, const PoolVector &) FUNC2(multimesh_set_physics_interpolated, RID, bool) - FUNC2(multimesh_set_physics_interpolation_quality, RID, int) + FUNC2(multimesh_set_physics_interpolation_quality, RID, MultimeshPhysicsInterpolationQuality) FUNC2(multimesh_instance_reset_physics_interpolation, RID, int) FUNC2(multimesh_set_visible_instances, RID, int) diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index f56e4202775..41bd45a1d4b 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -1932,6 +1932,10 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("multimesh_set_visible_instances", "multimesh", "visible"), &VisualServer::multimesh_set_visible_instances); ClassDB::bind_method(D_METHOD("multimesh_get_visible_instances", "multimesh"), &VisualServer::multimesh_get_visible_instances); ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array", "multimesh", "array"), &VisualServer::multimesh_set_as_bulk_array); + ClassDB::bind_method(D_METHOD("multimesh_set_as_bulk_array_interpolated", "multimesh", "array", "array_previous"), &VisualServer::multimesh_set_as_bulk_array_interpolated); + ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolated", "multimesh", "interpolated"), &VisualServer::multimesh_set_physics_interpolated); + ClassDB::bind_method(D_METHOD("multimesh_set_physics_interpolation_quality", "multimesh", "quality"), &VisualServer::multimesh_set_physics_interpolation_quality); + ClassDB::bind_method(D_METHOD("multimesh_instance_reset_physics_interpolation", "multimesh", "index"), &VisualServer::multimesh_instance_reset_physics_interpolation); #ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("immediate_create"), &VisualServer::immediate_create); ClassDB::bind_method(D_METHOD("immediate_begin", "immediate", "primitive", "texture"), &VisualServer::immediate_begin, DEFVAL(RID())); @@ -2060,6 +2064,8 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("camera_set_orthogonal", "camera", "size", "z_near", "z_far"), &VisualServer::camera_set_orthogonal); ClassDB::bind_method(D_METHOD("camera_set_frustum", "camera", "size", "offset", "z_near", "z_far"), &VisualServer::camera_set_frustum); ClassDB::bind_method(D_METHOD("camera_set_transform", "camera", "transform"), &VisualServer::camera_set_transform); + ClassDB::bind_method(D_METHOD("camera_set_interpolated", "camera", "interpolated"), &VisualServer::camera_set_interpolated); + ClassDB::bind_method(D_METHOD("camera_reset_physics_interpolation", "camera"), &VisualServer::camera_reset_physics_interpolation); ClassDB::bind_method(D_METHOD("camera_set_cull_mask", "camera", "layers"), &VisualServer::camera_set_cull_mask); ClassDB::bind_method(D_METHOD("camera_set_environment", "camera", "env"), &VisualServer::camera_set_environment); ClassDB::bind_method(D_METHOD("camera_set_use_vertical_aspect", "camera", "enable"), &VisualServer::camera_set_use_vertical_aspect); @@ -2136,6 +2142,8 @@ void VisualServer::_bind_methods() { ClassDB::bind_method(D_METHOD("instance_set_scenario", "instance", "scenario"), &VisualServer::instance_set_scenario); ClassDB::bind_method(D_METHOD("instance_set_layer_mask", "instance", "mask"), &VisualServer::instance_set_layer_mask); ClassDB::bind_method(D_METHOD("instance_set_transform", "instance", "transform"), &VisualServer::instance_set_transform); + ClassDB::bind_method(D_METHOD("instance_set_interpolated", "instance", "interpolated"), &VisualServer::instance_set_interpolated); + ClassDB::bind_method(D_METHOD("instance_reset_physics_interpolation", "instance"), &VisualServer::instance_reset_physics_interpolation); ClassDB::bind_method(D_METHOD("instance_attach_object_instance_id", "instance", "id"), &VisualServer::instance_attach_object_instance_id); ClassDB::bind_method(D_METHOD("instance_set_blend_shape_weight", "instance", "shape", "weight"), &VisualServer::instance_set_blend_shape_weight); ClassDB::bind_method(D_METHOD("instance_set_surface_material", "instance", "surface", "material"), &VisualServer::instance_set_surface_material); @@ -2487,6 +2495,8 @@ void VisualServer::_bind_methods() { BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_NONE); BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_8BIT); BIND_ENUM_CONSTANT(MULTIMESH_CUSTOM_DATA_FLOAT); + BIND_ENUM_CONSTANT(MULTIMESH_INTERP_QUALITY_FAST); + BIND_ENUM_CONSTANT(MULTIMESH_INTERP_QUALITY_HIGH); BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ONCE); BIND_ENUM_CONSTANT(REFLECTION_PROBE_UPDATE_ALWAYS); diff --git a/servers/visual_server.h b/servers/visual_server.h index a3f6878a7c5..f53a2b4d72e 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -362,6 +362,11 @@ public: MULTIMESH_CUSTOM_DATA_MAX, }; + enum MultimeshPhysicsInterpolationQuality { + MULTIMESH_INTERP_QUALITY_FAST, + MULTIMESH_INTERP_QUALITY_HIGH, + }; + virtual void multimesh_allocate(RID p_multimesh, int p_instances, MultimeshTransformFormat p_transform_format, MultimeshColorFormat p_color_format, MultimeshCustomDataFormat p_data_format = MULTIMESH_CUSTOM_DATA_NONE) = 0; virtual int multimesh_get_instance_count(RID p_multimesh) const = 0; @@ -384,7 +389,7 @@ public: // Interpolation virtual void multimesh_set_as_bulk_array_interpolated(RID p_multimesh, const PoolVector &p_array, const PoolVector &p_array_prev) = 0; virtual void multimesh_set_physics_interpolated(RID p_multimesh, bool p_interpolated) = 0; - virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, int p_quality) = 0; + virtual void multimesh_set_physics_interpolation_quality(RID p_multimesh, MultimeshPhysicsInterpolationQuality p_quality) = 0; virtual void multimesh_instance_reset_physics_interpolation(RID p_multimesh, int p_index) = 0; virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0; @@ -1235,6 +1240,7 @@ VARIANT_ENUM_CAST(VisualServer::Features); VARIANT_ENUM_CAST(VisualServer::MultimeshTransformFormat); VARIANT_ENUM_CAST(VisualServer::MultimeshColorFormat); VARIANT_ENUM_CAST(VisualServer::MultimeshCustomDataFormat); +VARIANT_ENUM_CAST(VisualServer::MultimeshPhysicsInterpolationQuality); VARIANT_ENUM_CAST(VisualServer::LightBakeMode); VARIANT_ENUM_CAST(VisualServer::LightOmniShadowMode); VARIANT_ENUM_CAST(VisualServer::LightOmniShadowDetail);