From 85819b199a5d49e75f78f67415e82c46bbe061a9 Mon Sep 17 00:00:00 2001 From: PouleyKetchoupp Date: Tue, 14 Sep 2021 11:44:30 -0700 Subject: Rename RigidBody to RigidDynamicBody and SoftBody to SoftDynamicBody --- doc/classes/CharacterBody2D.xml | 2 +- doc/classes/CharacterBody3D.xml | 2 +- doc/classes/ConcavePolygonShape2D.xml | 2 +- doc/classes/ConcavePolygonShape3D.xml | 2 +- doc/classes/PackedScene.xml | 26 +- doc/classes/Performance.xml | 4 +- doc/classes/PhysicalBone2D.xml | 4 +- doc/classes/PhysicsDirectBodyState2D.xml | 4 +- doc/classes/PhysicsDirectBodyState3D.xml | 4 +- doc/classes/PhysicsServer3D.xml | 2 +- doc/classes/RigidBody2D.xml | 229 --------- doc/classes/RigidBody3D.xml | 225 -------- doc/classes/RigidDynamicBody2D.xml | 229 +++++++++ doc/classes/RigidDynamicBody3D.xml | 225 ++++++++ doc/classes/Skeleton3D.xml | 4 +- doc/classes/SoftBody3D.xml | 134 ----- doc/classes/SoftDynamicBody3D.xml | 134 +++++ doc/classes/StaticBody2D.xml | 2 +- doc/classes/StaticBody3D.xml | 2 +- doc/classes/VehicleBody3D.xml | 6 +- doc/classes/VehicleWheel3D.xml | 6 +- doc/classes/VisibleOnScreenEnabler3D.xml | 2 +- editor/icons/RigidBody2D.svg | 1 - editor/icons/RigidBody3D.svg | 1 - editor/icons/RigidDynamicBody2D.svg | 1 + editor/icons/RigidDynamicBody3D.svg | 1 + editor/icons/SoftBody3D.svg | 1 - editor/icons/SoftDynamicBody3D.svg | 1 + editor/import/resource_importer_scene.cpp | 6 +- editor/plugins/node_3d_editor_gizmos.cpp | 38 +- editor/plugins/node_3d_editor_gizmos.h | 6 +- editor/plugins/node_3d_editor_plugin.cpp | 2 +- scene/2d/collision_polygon_2d.cpp | 2 +- scene/2d/collision_shape_2d.cpp | 2 +- scene/2d/physical_bone_2d.cpp | 14 +- scene/2d/physical_bone_2d.h | 4 +- scene/2d/physics_body_2d.cpp | 236 ++++----- scene/2d/physics_body_2d.h | 16 +- scene/3d/collision_polygon_3d.cpp | 2 +- scene/3d/collision_shape_3d.cpp | 8 +- scene/3d/physics_body_3d.cpp | 224 ++++---- scene/3d/physics_body_3d.h | 14 +- scene/3d/soft_body_3d.cpp | 816 ------------------------------ scene/3d/soft_body_3d.h | 207 -------- scene/3d/soft_dynamic_body_3d.cpp | 800 +++++++++++++++++++++++++++++ scene/3d/soft_dynamic_body_3d.h | 203 ++++++++ scene/3d/vehicle_body_3d.cpp | 2 +- scene/3d/vehicle_body_3d.h | 4 +- scene/register_scene_types.cpp | 13 +- scene/resources/immediate_mesh.cpp | 3 - scene/resources/immediate_mesh.h | 1 - scene/resources/mesh.cpp | 5 - scene/resources/mesh.h | 1 - 53 files changed, 1928 insertions(+), 1957 deletions(-) delete mode 100644 doc/classes/RigidBody2D.xml delete mode 100644 doc/classes/RigidBody3D.xml create mode 100644 doc/classes/RigidDynamicBody2D.xml create mode 100644 doc/classes/RigidDynamicBody3D.xml delete mode 100644 doc/classes/SoftBody3D.xml create mode 100644 doc/classes/SoftDynamicBody3D.xml delete mode 100644 editor/icons/RigidBody2D.svg delete mode 100644 editor/icons/RigidBody3D.svg create mode 100644 editor/icons/RigidDynamicBody2D.svg create mode 100644 editor/icons/RigidDynamicBody3D.svg delete mode 100644 editor/icons/SoftBody3D.svg create mode 100644 editor/icons/SoftDynamicBody3D.svg delete mode 100644 scene/3d/soft_body_3d.cpp delete mode 100644 scene/3d/soft_body_3d.h create mode 100644 scene/3d/soft_dynamic_body_3d.cpp create mode 100644 scene/3d/soft_dynamic_body_3d.h diff --git a/doc/classes/CharacterBody2D.xml b/doc/classes/CharacterBody2D.xml index f98c22a1e9..7637356f63 100644 --- a/doc/classes/CharacterBody2D.xml +++ b/doc/classes/CharacterBody2D.xml @@ -107,7 +107,7 @@ - Moves the body based on [member linear_velocity]. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a [CharacterBody2D] or [RigidBody2D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes. + Moves the body based on [member linear_velocity]. If the body collides with another, it will slide along the other body (by default only on floor) rather than stop immediately. If the other body is a [CharacterBody2D] or [RigidDynamicBody2D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed. Modifies [member linear_velocity] if a slide collision occurred. To get the latest collision call [method get_last_slide_collision], for detailed information about collisions that occurred, use [method get_slide_collision]. When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions. diff --git a/doc/classes/CharacterBody3D.xml b/doc/classes/CharacterBody3D.xml index 81ffbe01c1..f08a2cafea 100644 --- a/doc/classes/CharacterBody3D.xml +++ b/doc/classes/CharacterBody3D.xml @@ -93,7 +93,7 @@ - Moves the body based on [member linear_velocity]. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [CharacterBody3D] or [RigidBody3D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes. + Moves the body based on [member linear_velocity]. If the body collides with another, it will slide along the other body rather than stop immediately. If the other body is a [CharacterBody3D] or [RigidDynamicBody3D], it will also be affected by the motion of the other body. You can use this to make moving and rotating platforms, or to make nodes push other nodes. This method should be used in [method Node._physics_process] (or in a method called by [method Node._physics_process]), as it uses the physics step's [code]delta[/code] value automatically in calculations. Otherwise, the simulation will run at an incorrect speed. Modifies [member linear_velocity] if a slide collision occurred. To get the latest collision call [method get_last_slide_collision], for more detailed information about collisions that occurred, use [method get_slide_collision]. When the body touches a moving platform, the platform's velocity is automatically added to the body motion. If a collision occurs due to the platform's motion, it will always be first in the slide collisions. diff --git a/doc/classes/ConcavePolygonShape2D.xml b/doc/classes/ConcavePolygonShape2D.xml index e6b2e1845d..50632cd2c8 100644 --- a/doc/classes/ConcavePolygonShape2D.xml +++ b/doc/classes/ConcavePolygonShape2D.xml @@ -4,7 +4,7 @@ Concave polygon 2D shape resource for physics. - Concave polygon 2D shape resource for physics. It is made out of segments and is optimal for complex polygonal concave collisions. However, it is not advised to use for [RigidBody2D] nodes. A CollisionPolygon2D in convex decomposition mode (solids) or several convex objects are advised for that instead. Otherwise, a concave polygon 2D shape is better for static collisions. + Concave polygon 2D shape resource for physics. It is made out of segments and is optimal for complex polygonal concave collisions. However, it is not advised to use for [RigidDynamicBody2D] nodes. A CollisionPolygon2D in convex decomposition mode (solids) or several convex objects are advised for that instead. Otherwise, a concave polygon 2D shape is better for static collisions. The main difference between a [ConvexPolygonShape2D] and a [ConcavePolygonShape2D] is that a concave polygon assumes it is concave and uses a more complex method of collision detection, and a convex one forces itself to be convex in order to speed up collision detection. diff --git a/doc/classes/ConcavePolygonShape3D.xml b/doc/classes/ConcavePolygonShape3D.xml index 34fb06a476..907afa6367 100644 --- a/doc/classes/ConcavePolygonShape3D.xml +++ b/doc/classes/ConcavePolygonShape3D.xml @@ -5,7 +5,7 @@ Concave polygon shape resource, which can be set into a [PhysicsBody3D] or area. This shape is created by feeding a list of triangles. - Note: when used for collision, [ConcavePolygonShape3D] is intended to work with static [PhysicsBody3D] nodes like [StaticBody3D] and will not work with [CharacterBody3D] or [RigidBody3D] with a mode other than Static. + Note: when used for collision, [ConcavePolygonShape3D] is intended to work with static [PhysicsBody3D] nodes like [StaticBody3D] and will not work with [CharacterBody3D] or [RigidDynamicBody3D] with a mode other than Static. https://godotengine.org/asset-library/asset/675 diff --git a/doc/classes/PackedScene.xml b/doc/classes/PackedScene.xml index 1374496b52..618123855f 100644 --- a/doc/classes/PackedScene.xml +++ b/doc/classes/PackedScene.xml @@ -22,23 +22,23 @@ AddChild(scene); [/csharp] [/codeblocks] - [b]Example of saving a node with different owners:[/b] The following example creates 3 objects: [code]Node2D[/code] ([code]node[/code]), [code]RigidBody2D[/code] ([code]rigid[/code]) and [code]CollisionObject2D[/code] ([code]collision[/code]). [code]collision[/code] is a child of [code]rigid[/code] which is a child of [code]node[/code]. Only [code]rigid[/code] is owned by [code]node[/code] and [code]pack[/code] will therefore only save those two nodes, but not [code]collision[/code]. + [b]Example of saving a node with different owners:[/b] The following example creates 3 objects: [code]Node2D[/code] ([code]node[/code]), [code]RigidDynamicBody2D[/code] ([code]body[/code]) and [code]CollisionObject2D[/code] ([code]collision[/code]). [code]collision[/code] is a child of [code]body[/code] which is a child of [code]node[/code]. Only [code]body[/code] is owned by [code]node[/code] and [code]pack[/code] will therefore only save those two nodes, but not [code]collision[/code]. [codeblocks] [gdscript] # Create the objects. var node = Node2D.new() - var rigid = RigidBody2D.new() + var body = RigidDynamicBody2D.new() var collision = CollisionShape2D.new() # Create the object hierarchy. - rigid.add_child(collision) - node.add_child(rigid) + body.add_child(collision) + node.add_child(body) - # Change owner of `rigid`, but not of `collision`. - rigid.owner = node + # Change owner of `body`, but not of `collision`. + body.owner = node var scene = PackedScene.new() - # Only `node` and `rigid` are now packed. + # Only `node` and `body` are now packed. var result = scene.pack(node) if result == OK: var error = ResourceSaver.save("res://path/name.tscn", scene) # Or "user://..." @@ -48,18 +48,18 @@ [csharp] // Create the objects. var node = new Node2D(); - var rigid = new RigidBody2D(); + var body = new RigidDynamicBody2D(); var collision = new CollisionShape2D(); // Create the object hierarchy. - rigid.AddChild(collision); - node.AddChild(rigid); + body.AddChild(collision); + node.AddChild(body); - // Change owner of `rigid`, but not of `collision`. - rigid.Owner = node; + // Change owner of `body`, but not of `collision`. + body.Owner = node; var scene = new PackedScene(); - // Only `node` and `rigid` are now packed. + // Only `node` and `body` are now packed. Error result = scene.Pack(node); if (result == Error.Ok) { diff --git a/doc/classes/Performance.xml b/doc/classes/Performance.xml index 335c3d254b..6e905eace6 100644 --- a/doc/classes/Performance.xml +++ b/doc/classes/Performance.xml @@ -169,7 +169,7 @@ - Number of active [RigidBody2D] nodes in the game. + Number of active [RigidDynamicBody2D] nodes in the game. Number of collision pairs in the 2D physics engine. @@ -178,7 +178,7 @@ Number of islands in the 2D physics engine. - Number of active [RigidBody3D] and [VehicleBody3D] nodes in the game. + Number of active [RigidDynamicBody3D] and [VehicleBody3D] nodes in the game. Number of collision pairs in the 3D physics engine. diff --git a/doc/classes/PhysicalBone2D.xml b/doc/classes/PhysicalBone2D.xml index b4d92475a1..8fa42a9596 100644 --- a/doc/classes/PhysicalBone2D.xml +++ b/doc/classes/PhysicalBone2D.xml @@ -1,10 +1,10 @@ - + A 2D node that can be used for physically aware bones in 2D. - The [code]PhysicalBone2D[/code] node is a [RigidBody2D]-based node that can be used to make [Bone2D] nodes in a [Skeleton2D] react to physics. This node is very similar to the [PhysicalBone3D] node, just for 2D instead of 3D. + The [code]PhysicalBone2D[/code] node is a [RigidDynamicBody2D]-based node that can be used to make [Bone2D] nodes in a [Skeleton2D] react to physics. This node is very similar to the [PhysicalBone3D] node, just for 2D instead of 3D. [b]Note:[/b] To have the Bone2D nodes visually follow the [code]PhysicalBone2D[/code] node, use a [SkeletonModification2DPhysicalBones] modification on the [Skeleton2D] node with the [Bone2D] nodes. [b]Note:[/b] The PhysicalBone2D node does not automatically create a [Joint2D] node to keep [code]PhysicalBone2D[/code] nodes together. You will need to create these manually. For most cases, you want to use a [PinJoint2D] node. The [code]PhysicalBone2D[/code] node can automatically configure the [Joint2D] node once it's been created as a child node. diff --git a/doc/classes/PhysicsDirectBodyState2D.xml b/doc/classes/PhysicsDirectBodyState2D.xml index 8698fbec61..3b3b5b948e 100644 --- a/doc/classes/PhysicsDirectBodyState2D.xml +++ b/doc/classes/PhysicsDirectBodyState2D.xml @@ -4,7 +4,7 @@ Direct access object to a physics body in the [PhysicsServer2D]. - Provides direct access to a physics body in the [PhysicsServer2D], allowing safe changes to physics properties. This object is passed via the direct state callback of dynamic bodies, and is intended for changing the direct state of that body. See [method RigidBody2D._integrate_forces]. + Provides direct access to a physics body in the [PhysicsServer2D], allowing safe changes to physics properties. This object is passed via the direct state callback of dynamic bodies, and is intended for changing the direct state of that body. See [method RigidDynamicBody2D._integrate_forces]. https://docs.godotengine.org/en/latest/tutorials/physics/ray-casting.html @@ -107,7 +107,7 @@ Returns the number of contacts this body has with other bodies. - [b]Note:[/b] By default, this returns 0 unless bodies are configured to monitor contacts. See [member RigidBody2D.contact_monitor]. + [b]Note:[/b] By default, this returns 0 unless bodies are configured to monitor contacts. See [member RigidDynamicBody2D.contact_monitor]. diff --git a/doc/classes/PhysicsDirectBodyState3D.xml b/doc/classes/PhysicsDirectBodyState3D.xml index 4599f86423..7900af015d 100644 --- a/doc/classes/PhysicsDirectBodyState3D.xml +++ b/doc/classes/PhysicsDirectBodyState3D.xml @@ -4,7 +4,7 @@ Direct access object to a physics body in the [PhysicsServer3D]. - Provides direct access to a physics body in the [PhysicsServer3D], allowing safe changes to physics properties. This object is passed via the direct state callback of dynamic bodies, and is intended for changing the direct state of that body. See [method RigidBody3D._integrate_forces]. + Provides direct access to a physics body in the [PhysicsServer3D], allowing safe changes to physics properties. This object is passed via the direct state callback of dynamic bodies, and is intended for changing the direct state of that body. See [method RigidDynamicBody3D._integrate_forces]. @@ -101,7 +101,7 @@ Returns the number of contacts this body has with other bodies. - [b]Note:[/b] By default, this returns 0 unless bodies are configured to monitor contacts. See [member RigidBody3D.contact_monitor]. + [b]Note:[/b] By default, this returns 0 unless bodies are configured to monitor contacts. See [member RigidDynamicBody3D.contact_monitor]. diff --git a/doc/classes/PhysicsServer3D.xml b/doc/classes/PhysicsServer3D.xml index 2fbe84b8b1..d0dc4278ae 100644 --- a/doc/classes/PhysicsServer3D.xml +++ b/doc/classes/PhysicsServer3D.xml @@ -1212,7 +1212,7 @@ The [Shape3D] is a [HeightMapShape3D]. - The [Shape3D] is a [SoftBody3D]. + The [Shape3D] is used internally for a soft body. Any attempt to create this kind of shape results in an error. This constant is used internally by the engine. Any attempt to create this kind of shape results in an error. diff --git a/doc/classes/RigidBody2D.xml b/doc/classes/RigidBody2D.xml deleted file mode 100644 index 0702955495..0000000000 --- a/doc/classes/RigidBody2D.xml +++ /dev/null @@ -1,229 +0,0 @@ - - - - Physics Body which is moved by 2D physics simulation. Useful for objects that have gravity and can be pushed by other objects. - - - This node implements simulated 2D physics. You do not control a RigidBody2D directly. Instead, you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties. - A RigidBody2D has 4 behavior [member mode]s: Dynamic, Static, DynamicLocked, and Kinematic. - [b]Note:[/b] You should not change a RigidBody2D's [code]position[/code] or [code]linear_velocity[/code] every frame or even very often. If you need to directly affect the body's state, use [method _integrate_forces], which allows you to directly access the physics state. - Please also keep in mind that physics bodies manage their own transform which overwrites the ones you set. So any direct or indirect transformation (including scaling of the node or its parent) will be visible in the editor only, and immediately reset at runtime. - If you need to override the default physics behavior or add a transformation at runtime, you can write a custom force integration. See [member custom_integrator]. - The center of mass is always located at the node's origin without taking into account the [CollisionShape2D] centroid offsets. - - - https://godotengine.org/asset-library/asset/119 - https://godotengine.org/asset-library/asset/148 - - - - - - - Allows you to read and safely modify the simulation state for the object. Use this instead of [method Node._physics_process] if you need to directly change the body's [code]position[/code] or other physics properties. By default, it works in addition to the usual physics behavior, but [member custom_integrator] allows you to disable the default behavior and write custom force integration for a body. - - - - - - - Adds a constant directional force without affecting rotation. - - - - - - - - Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates. - - - - - - - Adds a constant rotational force. - - - - - - - Applies a directional impulse without affecting rotation. - - - - - - - - Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts (use the "_force" functions otherwise). The position uses the rotation of the global coordinate system, but is centered at the object's origin. - - - - - - - Applies a rotational impulse to the body. - - - - - - Returns a list of the bodies colliding with this one. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. - [b]Note:[/b] The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead. - - - - - - - Sets the body's velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior. - - - - - - Damps the body's [member angular_velocity]. If [code]-1[/code], the body will use the [b]Default Angular Damp[/b] defined in [b]Project > Project Settings > Physics > 2d[/b]. - See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping. - - - The body's rotational velocity. - - - The body's total applied force. - - - The body's total applied torque. - - - If [code]true[/code], the body can enter sleep mode when there is no movement. See [member sleeping]. - - - The body's custom center of mass, relative to the body's origin position, when [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_CUSTOM]. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration. - When [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_AUTO] (default value), the center of mass is automatically computed. - - - Defines the way the body's center of mass is set. See [enum CenterOfMassMode] for possible values. - - - If [code]true[/code], the body will emit signals when it collides with another RigidBody2D. See also [member contacts_reported]. - - - The maximum number of contacts that will be recorded. Requires [member contact_monitor] to be set to [code]true[/code]. - [b]Note:[/b] The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end). - - - Continuous collision detection mode. - Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See [enum CCDMode] for details. - - - If [code]true[/code], internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the [method _integrate_forces] function. - - - Multiplies the gravity applied to the body. The body's gravity is calculated from the [b]Default Gravity[/b] value in [b]Project > Project Settings > Physics > 2d[/b] and/or any additional gravity vector applied by [Area2D]s. - - - The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value. - If set to [code]0[/code], inertia is automatically computed (default value). - - - Damps the body's [member linear_velocity]. If [code]-1[/code], the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 2d[/b]. - See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping. - - - The body's linear velocity. - - - The body's mass. - - - The body's mode. See [enum Mode] for possible values. - For a body that uses only Static or Kinematic mode, use [StaticBody2D] or [AnimatableBody2D] instead. - - - The physics material override for the body. - If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one. - - - If [code]true[/code], the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the [method apply_impulse] or [method add_force] methods. - - - - - - - Emitted when a collision with another [PhysicsBody2D] or [TileMap] occurs. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. - - - - - - Emitted when the collision with another [PhysicsBody2D] or [TileMap] ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. - - - - - - - - - Emitted when one of this RigidBody2D's [Shape2D]s collides with another [PhysicsBody2D] or [TileMap]'s [Shape2D]s. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. - [code]body_id[/code] the [RID] of the other [PhysicsBody2D] or [TileSet]'s [CollisionObject2D] used by the [PhysicsServer2D]. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. - [code]body_shape[/code] the index of the [Shape2D] of the other [PhysicsBody2D] or [TileMap] used by the [PhysicsServer2D]. - [code]local_shape[/code] the index of the [Shape2D] of this RigidBody2D used by the [PhysicsServer2D]. - - - - - - - - - Emitted when the collision between one of this RigidBody2D's [Shape2D]s and another [PhysicsBody2D] or [TileMap]'s [Shape2D]s ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. - [code]body_id[/code] the [RID] of the other [PhysicsBody2D] or [TileSet]'s [CollisionObject2D] used by the [PhysicsServer2D]. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. - [code]body_shape[/code] the index of the [Shape2D] of the other [PhysicsBody2D] or [TileMap] used by the [PhysicsServer2D]. - [code]local_shape[/code] the index of the [Shape2D] of this RigidBody2D used by the [PhysicsServer2D]. - - - - - Emitted when the physics engine changes the body's sleeping state. - [b]Note:[/b] Changing the value [member sleeping] will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or [code]emit_signal("sleeping_state_changed")[/code] is used. - - - - - - Dynamic body mode. This is the default mode of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code. - - - Static body mode. The body behaves like a [StaticBody2D], and must be moved by code. - - - Locked dynamic body mode. Similar to [constant MODE_DYNAMIC], but the body can not rotate. - - - Kinematic body mode. The body behaves like a [AnimatableBody2D], and must be moved by code. - - - In this mode, the body's center of mass is calculated automatically based on its shapes. - - - In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. - - - Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects. - - - Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise. - - - Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise. - - - diff --git a/doc/classes/RigidBody3D.xml b/doc/classes/RigidBody3D.xml deleted file mode 100644 index 1be35b0576..0000000000 --- a/doc/classes/RigidBody3D.xml +++ /dev/null @@ -1,225 +0,0 @@ - - - - Physics Body which is moved by 3D physics simulation. Useful for objects that have gravity and can be pushed by other objects. - - - This is the node that implements full 3D physics. This means that you do not control a RigidBody3D directly. Instead, you can apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, collision, bouncing, rotating, etc. - A RigidBody3D has 4 behavior [member mode]s: Dynamic, Static, DynamicLocked, and Kinematic. - [b]Note:[/b] Don't change a RigidBody3D's position every frame or very often. Sporadic changes work fine, but physics runs at a different granularity (fixed Hz) than usual rendering (process callback) and maybe even in a separate thread, so changing this from a process loop may result in strange behavior. If you need to directly affect the body's state, use [method _integrate_forces], which allows you to directly access the physics state. - If you need to override the default physics behavior, you can write a custom force integration function. See [member custom_integrator]. - With Bullet physics (the default), the center of mass is the RigidBody3D center. With GodotPhysics, the center of mass is the average of the [CollisionShape3D] centers. - - - https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html - https://godotengine.org/asset-library/asset/524 - https://godotengine.org/asset-library/asset/675 - - - - - - - Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default, it works in addition to the usual physics behavior, but the [member custom_integrator] property allows you to disable the default behavior and do fully custom force integration for a body. - - - - - - - Adds a constant directional force (i.e. acceleration) without affecting rotation. - This is equivalent to [code]add_force(force, Vector3(0,0,0))[/code]. - - - - - - - - Adds a constant directional force (i.e. acceleration). - The position uses the rotation of the global coordinate system, but is centered at the object's origin. - - - - - - - Adds a constant rotational force (i.e. a motor) without affecting position. - - - - - - - Applies a directional impulse without affecting rotation. - This is equivalent to [code]apply_impulse(Vector3(0,0,0), impulse)[/code]. - - - - - - - - Applies a positioned impulse to the body. An impulse is time independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts. The position uses the rotation of the global coordinate system, but is centered at the object's origin. - - - - - - - Applies a torque impulse which will be affected by the body mass and shape. This will rotate the body around the [code]impulse[/code] vector passed. - - - - - - Returns a list of the bodies colliding with this one. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. - [b]Note:[/b] The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead. - - - - - - Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the [RigidBody3D]. - - - - - - - Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior. - - - - - - Damps RigidBody3D's rotational forces. - See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping. - - - RigidBody3D's rotational velocity. - - - If [code]true[/code], the body can enter sleep mode when there is no movement. See [member sleeping]. - - - The body's custom center of mass, relative to the body's origin position, when [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_CUSTOM]. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration. - When [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_AUTO] (default value), the center of mass is automatically computed. - - - Defines the way the body's center of mass is set. See [enum CenterOfMassMode] for possible values. - - - If [code]true[/code], the RigidBody3D will emit signals when it collides with another RigidBody3D. See also [member contacts_reported]. - - - The maximum number of contacts that will be recorded. Requires [member contact_monitor] to be set to [code]true[/code]. - [b]Note:[/b] The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner). - - - If [code]true[/code], continuous collision detection is used. - Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. Continuous collision detection is more precise, and misses fewer impacts by small, fast-moving objects. Not using continuous collision detection is faster to compute, but can miss small, fast-moving objects. - - - If [code]true[/code], internal force integration will be disabled (like gravity or air friction) for this body. Other than collision response, the body will only move as determined by the [method _integrate_forces] function, if defined. - - - This is multiplied by the global 3D gravity setting found in [b]Project > Project Settings > Physics > 3d[/b] to produce RigidBody3D's gravity. For example, a value of 1 will be normal gravity, 2 will apply double gravity, and 0.5 will apply half gravity to this object. - - - The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body on each axis. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value. - If set to [code]Vector3.ZERO[/code], inertia is automatically computed (default value). - - - The body's linear damp. Cannot be less than -1.0. If this value is different from -1.0, any linear damp derived from the world or areas will be overridden. - See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping. - - - The body's linear velocity. Can be used sporadically, but [b]don't set this every frame[/b], because physics may run in another thread and runs at a different granularity. Use [method _integrate_forces] as your process loop for precise control of the body state. - - - The body's mass. - - - The body's mode. See [enum Mode] for possible values. - For a body that uses only Static or Kinematic mode, use [StaticBody3D] or [AnimatableBody3D] instead. - - - The physics material override for the body. - If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one. - - - If [code]true[/code], the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the [method apply_impulse] or [method add_force] methods. - - - - - - - Emitted when a collision with another [PhysicsBody3D] or [GridMap] occurs. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. - - - - - - Emitted when the collision with another [PhysicsBody3D] or [GridMap] ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. - - - - - - - - - Emitted when one of this RigidBody3D's [Shape3D]s collides with another [PhysicsBody3D] or [GridMap]'s [Shape3D]s. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. - [code]body_id[/code] the [RID] of the other [PhysicsBody3D] or [MeshLibrary]'s [CollisionObject3D] used by the [PhysicsServer3D]. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. - [code]body_shape[/code] the index of the [Shape3D] of the other [PhysicsBody3D] or [GridMap] used by the [PhysicsServer3D]. - [code]local_shape[/code] the index of the [Shape3D] of this RigidBody3D used by the [PhysicsServer3D]. - [b]Note:[/b] Bullet physics cannot identify the shape index when using a [ConcavePolygonShape3D]. Don't use multiple [CollisionShape3D]s when using a [ConcavePolygonShape3D] with Bullet physics if you need shape indices. - - - - - - - - - Emitted when the collision between one of this RigidBody3D's [Shape3D]s and another [PhysicsBody3D] or [GridMap]'s [Shape3D]s ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. - [code]body_id[/code] the [RID] of the other [PhysicsBody3D] or [MeshLibrary]'s [CollisionObject3D] used by the [PhysicsServer3D]. [GridMap]s are detected if the Meshes have [Shape3D]s. - [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. - [code]body_shape[/code] the index of the [Shape3D] of the other [PhysicsBody3D] or [GridMap] used by the [PhysicsServer3D]. - [code]local_shape[/code] the index of the [Shape3D] of this RigidBody3D used by the [PhysicsServer3D]. - [b]Note:[/b] Bullet physics cannot identify the shape index when using a [ConcavePolygonShape3D]. Don't use multiple [CollisionShape3D]s when using a [ConcavePolygonShape3D] with Bullet physics if you need shape indices. - - - - - Emitted when the physics engine changes the body's sleeping state. - [b]Note:[/b] Changing the value [member sleeping] will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or [code]emit_signal("sleeping_state_changed")[/code] is used. - - - - - - Dynamic body mode. This is the default mode of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code. - - - Static body mode. The body behaves like a [StaticBody3D], and can only move by user code. - - - Locked dynamic body mode. Similar to [constant MODE_DYNAMIC], but the body can not rotate. - - - Kinematic body mode. The body behaves like a [AnimatableBody3D], and can only move by user code. - - - In this mode, the body's center of mass is calculated automatically based on its shapes. - - - In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. - - - diff --git a/doc/classes/RigidDynamicBody2D.xml b/doc/classes/RigidDynamicBody2D.xml new file mode 100644 index 0000000000..059379242b --- /dev/null +++ b/doc/classes/RigidDynamicBody2D.xml @@ -0,0 +1,229 @@ + + + + Physics Body which is moved by 2D physics simulation. Useful for objects that have gravity and can be pushed by other objects. + + + This node implements simulated 2D physics. You do not control a RigidDynamicBody2D directly. Instead, you apply forces to it (gravity, impulses, etc.) and the physics simulation calculates the resulting movement based on its mass, friction, and other physical properties. + A RigidDynamicBody2D has 4 behavior [member mode]s: Dynamic, Static, DynamicLocked, and Kinematic. + [b]Note:[/b] You should not change a RigidDynamicBody2D's [code]position[/code] or [code]linear_velocity[/code] every frame or even very often. If you need to directly affect the body's state, use [method _integrate_forces], which allows you to directly access the physics state. + Please also keep in mind that physics bodies manage their own transform which overwrites the ones you set. So any direct or indirect transformation (including scaling of the node or its parent) will be visible in the editor only, and immediately reset at runtime. + If you need to override the default physics behavior or add a transformation at runtime, you can write a custom force integration. See [member custom_integrator]. + The center of mass is always located at the node's origin without taking into account the [CollisionShape2D] centroid offsets. + + + https://godotengine.org/asset-library/asset/119 + https://godotengine.org/asset-library/asset/148 + + + + + + + Allows you to read and safely modify the simulation state for the object. Use this instead of [method Node._physics_process] if you need to directly change the body's [code]position[/code] or other physics properties. By default, it works in addition to the usual physics behavior, but [member custom_integrator] allows you to disable the default behavior and write custom force integration for a body. + + + + + + + Adds a constant directional force without affecting rotation. + + + + + + + + Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates. + + + + + + + Adds a constant rotational force. + + + + + + + Applies a directional impulse without affecting rotation. + + + + + + + + Applies a positioned impulse to the body. An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts (use the "_force" functions otherwise). The position uses the rotation of the global coordinate system, but is centered at the object's origin. + + + + + + + Applies a rotational impulse to the body. + + + + + + Returns a list of the bodies colliding with this one. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. + [b]Note:[/b] The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead. + + + + + + + Sets the body's velocity on the given axis. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior. + + + + + + Damps the body's [member angular_velocity]. If [code]-1[/code], the body will use the [b]Default Angular Damp[/b] defined in [b]Project > Project Settings > Physics > 2d[/b]. + See [member ProjectSettings.physics/2d/default_angular_damp] for more details about damping. + + + The body's rotational velocity. + + + The body's total applied force. + + + The body's total applied torque. + + + If [code]true[/code], the body can enter sleep mode when there is no movement. See [member sleeping]. + + + The body's custom center of mass, relative to the body's origin position, when [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_CUSTOM]. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration. + When [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_AUTO] (default value), the center of mass is automatically computed. + + + Defines the way the body's center of mass is set. See [enum CenterOfMassMode] for possible values. + + + If [code]true[/code], the body will emit signals when it collides with another RigidDynamicBody2D. See also [member contacts_reported]. + + + The maximum number of contacts that will be recorded. Requires [member contact_monitor] to be set to [code]true[/code]. + [b]Note:[/b] The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end). + + + Continuous collision detection mode. + Continuous collision detection tries to predict where a moving body will collide instead of moving it and correcting its movement after collision. Continuous collision detection is slower, but more precise and misses fewer collisions with small, fast-moving objects. Raycasting and shapecasting methods are available. See [enum CCDMode] for details. + + + If [code]true[/code], internal force integration is disabled for this body. Aside from collision response, the body will only move as determined by the [method _integrate_forces] function. + + + Multiplies the gravity applied to the body. The body's gravity is calculated from the [b]Default Gravity[/b] value in [b]Project > Project Settings > Physics > 2d[/b] and/or any additional gravity vector applied by [Area2D]s. + + + The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value. + If set to [code]0[/code], inertia is automatically computed (default value). + + + Damps the body's [member linear_velocity]. If [code]-1[/code], the body will use the [b]Default Linear Damp[/b] in [b]Project > Project Settings > Physics > 2d[/b]. + See [member ProjectSettings.physics/2d/default_linear_damp] for more details about damping. + + + The body's linear velocity. + + + The body's mass. + + + The body's mode. See [enum Mode] for possible values. + For a body that uses only Static or Kinematic mode, use [StaticBody2D] or [AnimatableBody2D] instead. + + + The physics material override for the body. + If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one. + + + If [code]true[/code], the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the [method apply_impulse] or [method add_force] methods. + + + + + + + Emitted when a collision with another [PhysicsBody2D] or [TileMap] occurs. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. + + + + + + Emitted when the collision with another [PhysicsBody2D] or [TileMap] ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. + + + + + + + + + Emitted when one of this RigidDynamicBody2D's [Shape2D]s collides with another [PhysicsBody2D] or [TileMap]'s [Shape2D]s. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. + [code]body_id[/code] the [RID] of the other [PhysicsBody2D] or [TileSet]'s [CollisionObject2D] used by the [PhysicsServer2D]. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. + [code]body_shape[/code] the index of the [Shape2D] of the other [PhysicsBody2D] or [TileMap] used by the [PhysicsServer2D]. + [code]local_shape[/code] the index of the [Shape2D] of this RigidDynamicBody2D used by the [PhysicsServer2D]. + + + + + + + + + Emitted when the collision between one of this RigidDynamicBody2D's [Shape2D]s and another [PhysicsBody2D] or [TileMap]'s [Shape2D]s ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [TileMap]s are detected if the [TileSet] has Collision [Shape2D]s. + [code]body_id[/code] the [RID] of the other [PhysicsBody2D] or [TileSet]'s [CollisionObject2D] used by the [PhysicsServer2D]. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody2D] or [TileMap]. + [code]body_shape[/code] the index of the [Shape2D] of the other [PhysicsBody2D] or [TileMap] used by the [PhysicsServer2D]. + [code]local_shape[/code] the index of the [Shape2D] of this RigidDynamicBody2D used by the [PhysicsServer2D]. + + + + + Emitted when the physics engine changes the body's sleeping state. + [b]Note:[/b] Changing the value [member sleeping] will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or [code]emit_signal("sleeping_state_changed")[/code] is used. + + + + + + Dynamic body mode. This is the default mode of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code. + + + Static body mode. The body behaves like a [StaticBody2D], and must be moved by code. + + + Locked dynamic body mode. Similar to [constant MODE_DYNAMIC], but the body can not rotate. + + + Kinematic body mode. The body behaves like a [AnimatableBody2D], and must be moved by code. + + + In this mode, the body's center of mass is calculated automatically based on its shapes. + + + In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. + + + Continuous collision detection disabled. This is the fastest way to detect body collisions, but can miss small, fast-moving objects. + + + Continuous collision detection enabled using raycasting. This is faster than shapecasting but less precise. + + + Continuous collision detection enabled using shapecasting. This is the slowest CCD method and the most precise. + + + diff --git a/doc/classes/RigidDynamicBody3D.xml b/doc/classes/RigidDynamicBody3D.xml new file mode 100644 index 0000000000..9b6bcd840b --- /dev/null +++ b/doc/classes/RigidDynamicBody3D.xml @@ -0,0 +1,225 @@ + + + + Physics Body which is moved by 3D physics simulation. Useful for objects that have gravity and can be pushed by other objects. + + + This is the node that implements full 3D physics. This means that you do not control a RigidDynamicBody3D directly. Instead, you can apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, collision, bouncing, rotating, etc. + A RigidDynamicBody3D has 4 behavior [member mode]s: Dynamic, Static, DynamicLocked, and Kinematic. + [b]Note:[/b] Don't change a RigidDynamicBody3D's position every frame or very often. Sporadic changes work fine, but physics runs at a different granularity (fixed Hz) than usual rendering (process callback) and maybe even in a separate thread, so changing this from a process loop may result in strange behavior. If you need to directly affect the body's state, use [method _integrate_forces], which allows you to directly access the physics state. + If you need to override the default physics behavior, you can write a custom force integration function. See [member custom_integrator]. + With Bullet physics (the default), the center of mass is the RigidDynamicBody3D center. With GodotPhysics, the center of mass is the average of the [CollisionShape3D] centers. + + + https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html + https://godotengine.org/asset-library/asset/524 + https://godotengine.org/asset-library/asset/675 + + + + + + + Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default, it works in addition to the usual physics behavior, but the [member custom_integrator] property allows you to disable the default behavior and do fully custom force integration for a body. + + + + + + + Adds a constant directional force (i.e. acceleration) without affecting rotation. + This is equivalent to [code]add_force(force, Vector3(0,0,0))[/code]. + + + + + + + + Adds a constant directional force (i.e. acceleration). + The position uses the rotation of the global coordinate system, but is centered at the object's origin. + + + + + + + Adds a constant rotational force (i.e. a motor) without affecting position. + + + + + + + Applies a directional impulse without affecting rotation. + This is equivalent to [code]apply_impulse(Vector3(0,0,0), impulse)[/code]. + + + + + + + + Applies a positioned impulse to the body. An impulse is time independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason it should only be used when simulating one-time impacts. The position uses the rotation of the global coordinate system, but is centered at the object's origin. + + + + + + + Applies a torque impulse which will be affected by the body mass and shape. This will rotate the body around the [code]impulse[/code] vector passed. + + + + + + Returns a list of the bodies colliding with this one. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. + [b]Note:[/b] The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead. + + + + + + Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the [RigidDynamicBody3D]. + + + + + + + Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior. + + + + + + Damps RigidDynamicBody3D's rotational forces. + See [member ProjectSettings.physics/3d/default_angular_damp] for more details about damping. + + + RigidDynamicBody3D's rotational velocity. + + + If [code]true[/code], the body can enter sleep mode when there is no movement. See [member sleeping]. + + + The body's custom center of mass, relative to the body's origin position, when [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_CUSTOM]. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration. + When [member center_of_mass_mode] is set to [constant CENTER_OF_MASS_MODE_AUTO] (default value), the center of mass is automatically computed. + + + Defines the way the body's center of mass is set. See [enum CenterOfMassMode] for possible values. + + + If [code]true[/code], the RigidDynamicBody3D will emit signals when it collides with another RigidDynamicBody3D. See also [member contacts_reported]. + + + The maximum number of contacts that will be recorded. Requires [member contact_monitor] to be set to [code]true[/code]. + [b]Note:[/b] The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner). + + + If [code]true[/code], continuous collision detection is used. + Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. Continuous collision detection is more precise, and misses fewer impacts by small, fast-moving objects. Not using continuous collision detection is faster to compute, but can miss small, fast-moving objects. + + + If [code]true[/code], internal force integration will be disabled (like gravity or air friction) for this body. Other than collision response, the body will only move as determined by the [method _integrate_forces] function, if defined. + + + This is multiplied by the global 3D gravity setting found in [b]Project > Project Settings > Physics > 3d[/b] to produce RigidDynamicBody3D's gravity. For example, a value of 1 will be normal gravity, 2 will apply double gravity, and 0.5 will apply half gravity to this object. + + + The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body on each axis. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value. + If set to [code]Vector3.ZERO[/code], inertia is automatically computed (default value). + + + The body's linear damp. Cannot be less than -1.0. If this value is different from -1.0, any linear damp derived from the world or areas will be overridden. + See [member ProjectSettings.physics/3d/default_linear_damp] for more details about damping. + + + The body's linear velocity. Can be used sporadically, but [b]don't set this every frame[/b], because physics may run in another thread and runs at a different granularity. Use [method _integrate_forces] as your process loop for precise control of the body state. + + + The body's mass. + + + The body's mode. See [enum Mode] for possible values. + For a body that uses only Static or Kinematic mode, use [StaticBody3D] or [AnimatableBody3D] instead. + + + The physics material override for the body. + If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one. + + + If [code]true[/code], the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the [method apply_impulse] or [method add_force] methods. + + + + + + + Emitted when a collision with another [PhysicsBody3D] or [GridMap] occurs. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. + + + + + + Emitted when the collision with another [PhysicsBody3D] or [GridMap] ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. + + + + + + + + + Emitted when one of this RigidDynamicBody3D's [Shape3D]s collides with another [PhysicsBody3D] or [GridMap]'s [Shape3D]s. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. + [code]body_id[/code] the [RID] of the other [PhysicsBody3D] or [MeshLibrary]'s [CollisionObject3D] used by the [PhysicsServer3D]. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. + [code]body_shape[/code] the index of the [Shape3D] of the other [PhysicsBody3D] or [GridMap] used by the [PhysicsServer3D]. + [code]local_shape[/code] the index of the [Shape3D] of this RigidDynamicBody3D used by the [PhysicsServer3D]. + [b]Note:[/b] Bullet physics cannot identify the shape index when using a [ConcavePolygonShape3D]. Don't use multiple [CollisionShape3D]s when using a [ConcavePolygonShape3D] with Bullet physics if you need shape indices. + + + + + + + + + Emitted when the collision between one of this RigidDynamicBody3D's [Shape3D]s and another [PhysicsBody3D] or [GridMap]'s [Shape3D]s ends. Requires [member contact_monitor] to be set to [code]true[/code] and [member contacts_reported] to be set high enough to detect all the collisions. [GridMap]s are detected if the [MeshLibrary] has Collision [Shape3D]s. + [code]body_id[/code] the [RID] of the other [PhysicsBody3D] or [MeshLibrary]'s [CollisionObject3D] used by the [PhysicsServer3D]. [GridMap]s are detected if the Meshes have [Shape3D]s. + [code]body[/code] the [Node], if it exists in the tree, of the other [PhysicsBody3D] or [GridMap]. + [code]body_shape[/code] the index of the [Shape3D] of the other [PhysicsBody3D] or [GridMap] used by the [PhysicsServer3D]. + [code]local_shape[/code] the index of the [Shape3D] of this RigidDynamicBody3D used by the [PhysicsServer3D]. + [b]Note:[/b] Bullet physics cannot identify the shape index when using a [ConcavePolygonShape3D]. Don't use multiple [CollisionShape3D]s when using a [ConcavePolygonShape3D] with Bullet physics if you need shape indices. + + + + + Emitted when the physics engine changes the body's sleeping state. + [b]Note:[/b] Changing the value [member sleeping] will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or [code]emit_signal("sleeping_state_changed")[/code] is used. + + + + + + Dynamic body mode. This is the default mode of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code. + + + Static body mode. The body behaves like a [StaticBody3D], and can only move by user code. + + + Locked dynamic body mode. Similar to [constant MODE_DYNAMIC], but the body can not rotate. + + + Kinematic body mode. The body behaves like a [AnimatableBody3D], and can only move by user code. + + + In this mode, the body's center of mass is calculated automatically based on its shapes. + + + In this mode, the body's center of mass is set through [member center_of_mass]. Defaults to the body's origin position. + + + diff --git a/doc/classes/Skeleton3D.xml b/doc/classes/Skeleton3D.xml index 2f340adb9f..c2b514f232 100644 --- a/doc/classes/Skeleton3D.xml +++ b/doc/classes/Skeleton3D.xml @@ -216,7 +216,7 @@ Adds a collision exception to the physical bone. - Works just like the [RigidBody3D] node. + Works just like the [RigidDynamicBody3D] node. @@ -224,7 +224,7 @@ Removes a collision exception to the physical bone. - Works just like the [RigidBody3D] node. + Works just like the [RigidDynamicBody3D] node. diff --git a/doc/classes/SoftBody3D.xml b/doc/classes/SoftBody3D.xml deleted file mode 100644 index d5f0e3c95c..0000000000 --- a/doc/classes/SoftBody3D.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - - A soft mesh physics body. - - - A deformable physics body. Used to create elastic or deformable objects such as cloth, rubber, or other flexible materials. - - - https://docs.godotengine.org/en/latest/tutorials/physics/soft_body.html - - - - - - - Adds a body to the list of bodies that this body can't collide with. - - - - - - Returns an array of nodes that were added as collision exceptions for this body. - - - - - - - Returns whether or not the specified layer of the [member collision_layer] is enabled, given a [code]layer_number[/code] between 1 and 32. - - - - - - - Returns whether or not the specified layer of the [member collision_mask] is enabled, given a [code]layer_number[/code] between 1 and 32. - - - - - - - - - - - - Returns local translation of a vertex in the surface array. - - - - - - - Returns [code]true[/code] if vertex is set to pinned. - - - - - - - Removes a body from the list of bodies that this body can't collide with. - - - - - - - - Based on [code]value[/code], enables or disables the specified layer in the [member collision_layer], given a [code]layer_number[/code] between 1 and 32. - - - - - - - - Based on [code]value[/code], enables or disables the specified layer in the [member collision_mask], given a [code]layer_number[/code] between 1 and 32. - - - - - - - - - Sets the pinned state of a surface vertex. When set to [code]true[/code], the optional [code]attachment_path[/code] can define a [Node3D] the pinned vertex will be attached to. - - - - - - The physics layers this SoftBody3D [b]is in[/b]. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask]. - [b]Note:[/b] Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - - The physics layers this SoftBody3D [b]scans[/b]. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. - [b]Note:[/b] Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. - - - - - Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED]. See [enum DisableMode] for more details about the different modes. - - - - - - - [NodePath] to a [CollisionObject3D] this SoftBody3D should avoid clipping. - - - - - If [code]true[/code], the [SoftBody3D] will respond to [RayCast3D]s. - - - Increasing this value will improve the resulting simulation, but can affect performance. Use with care. - - - The SoftBody3D's mass. - - - - - When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [SoftBody3D]. - Automatically re-added to the physics simulation when the [Node] is processed again. - - - When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation. - - - diff --git a/doc/classes/SoftDynamicBody3D.xml b/doc/classes/SoftDynamicBody3D.xml new file mode 100644 index 0000000000..f999f77e78 --- /dev/null +++ b/doc/classes/SoftDynamicBody3D.xml @@ -0,0 +1,134 @@ + + + + A soft mesh physics body. + + + A deformable physics body. Used to create elastic or deformable objects such as cloth, rubber, or other flexible materials. + + + https://docs.godotengine.org/en/latest/tutorials/physics/soft_body.html + + + + + + + Adds a body to the list of bodies that this body can't collide with. + + + + + + Returns an array of nodes that were added as collision exceptions for this body. + + + + + + + Returns whether or not the specified layer of the [member collision_layer] is enabled, given a [code]layer_number[/code] between 1 and 32. + + + + + + + Returns whether or not the specified layer of the [member collision_mask] is enabled, given a [code]layer_number[/code] between 1 and 32. + + + + + + + + + + + + Returns local translation of a vertex in the surface array. + + + + + + + Returns [code]true[/code] if vertex is set to pinned. + + + + + + + Removes a body from the list of bodies that this body can't collide with. + + + + + + + + Based on [code]value[/code], enables or disables the specified layer in the [member collision_layer], given a [code]layer_number[/code] between 1 and 32. + + + + + + + + Based on [code]value[/code], enables or disables the specified layer in the [member collision_mask], given a [code]layer_number[/code] between 1 and 32. + + + + + + + + + Sets the pinned state of a surface vertex. When set to [code]true[/code], the optional [code]attachment_path[/code] can define a [Node3D] the pinned vertex will be attached to. + + + + + + The physics layers this SoftDynamicBody3D [b]is in[/b]. Collision objects can exist in one or more of 32 different layers. See also [member collision_mask]. + [b]Note:[/b] Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. + + + The physics layers this SoftDynamicBody3D [b]scans[/b]. Collision objects can scan one or more of 32 different layers. See also [member collision_layer]. + [b]Note:[/b] Object A can detect a contact with object B only if object B is in any of the layers that object A scans. See [url=https://docs.godotengine.org/en/latest/tutorials/physics/physics_introduction.html#collision-layers-and-masks]Collision layers and masks[/url] in the documentation for more information. + + + + + Defines the behavior in physics when [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED]. See [enum DisableMode] for more details about the different modes. + + + + + + + [NodePath] to a [CollisionObject3D] this SoftDynamicBody3D should avoid clipping. + + + + + If [code]true[/code], the [SoftDynamicBody3D] will respond to [RayCast3D]s. + + + Increasing this value will improve the resulting simulation, but can affect performance. Use with care. + + + The SoftDynamicBody3D's mass. + + + + + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], remove from the physics simulation to stop all physics interactions with this [SoftDynamicBody3D]. + Automatically re-added to the physics simulation when the [Node] is processed again. + + + When [member Node.process_mode] is set to [constant Node.PROCESS_MODE_DISABLED], do not affect the physics simulation. + + + diff --git a/doc/classes/StaticBody2D.xml b/doc/classes/StaticBody2D.xml index 0344c3e0d1..9cbe0bdb40 100644 --- a/doc/classes/StaticBody2D.xml +++ b/doc/classes/StaticBody2D.xml @@ -5,7 +5,7 @@ Static body for 2D physics. - A static body is a simple body that can't be moved by external forces or contacts. It is ideal for implementing objects in the environment, such as walls or platforms. In contrast to [RigidBody2D], it doesn't consume any CPU resources as long as they don't move. + A static body is a simple body that can't be moved by external forces or contacts. It is ideal for implementing objects in the environment, such as walls or platforms. In contrast to [RigidDynamicBody2D], it doesn't consume any CPU resources as long as they don't move. They have extra functionalities to move and affect other bodies: [b]Static transform change:[/b] Static bodies can be moved by animation or script. In this case, they are just teleported and don't affect other bodies on their path. [b]Constant velocity:[/b] When [member constant_linear_velocity] or [member constant_angular_velocity] is set, static bodies don't move themselves but affect touching bodies as if they were moving. This is useful for simulating conveyor belts or conveyor wheels. diff --git a/doc/classes/StaticBody3D.xml b/doc/classes/StaticBody3D.xml index 4cb51b60ec..6e2377def0 100644 --- a/doc/classes/StaticBody3D.xml +++ b/doc/classes/StaticBody3D.xml @@ -5,7 +5,7 @@ Static body for 3D physics. - A static body is a simple body that can't be moved by external forces or contacts. It is ideal for implementing objects in the environment, such as walls or platforms. In contrast to [RigidBody3D], it doesn't consume any CPU resources as long as they don't move. + A static body is a simple body that can't be moved by external forces or contacts. It is ideal for implementing objects in the environment, such as walls or platforms. In contrast to [RigidDynamicBody3D], it doesn't consume any CPU resources as long as they don't move. They have extra functionalities to move and affect other bodies: [b]Static transform change:[/b] Static bodies can be moved by animation or script. In this case, they are just teleported and don't affect other bodies on their path. [b]Constant velocity:[/b] When [member constant_linear_velocity] or [member constant_angular_velocity] is set, static bodies don't move themselves but affect touching bodies as if they were moving. This is useful for simulating conveyor belts or conveyor wheels. diff --git a/doc/classes/VehicleBody3D.xml b/doc/classes/VehicleBody3D.xml index 90d0591949..21a37f7b53 100644 --- a/doc/classes/VehicleBody3D.xml +++ b/doc/classes/VehicleBody3D.xml @@ -1,5 +1,5 @@ - + Physics body that simulates the behavior of a car. @@ -15,10 +15,10 @@ - Slows down the vehicle by applying a braking force. The vehicle is only slowed down if the wheels are in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the [member RigidBody3D.mass] of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking. + Slows down the vehicle by applying a braking force. The vehicle is only slowed down if the wheels are in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the [member RigidDynamicBody3D.mass] of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking. - Accelerates the vehicle by applying an engine force. The vehicle is only speed up if the wheels that have [member VehicleWheel3D.use_as_traction] set to [code]true[/code] and are in contact with a surface. The [member RigidBody3D.mass] of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 50 range for acceleration. + Accelerates the vehicle by applying an engine force. The vehicle is only speed up if the wheels that have [member VehicleWheel3D.use_as_traction] set to [code]true[/code] and are in contact with a surface. The [member RigidDynamicBody3D.mass] of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 50 range for acceleration. [b]Note:[/b] The simulation does not take the effect of gears into account, you will need to add logic for this if you wish to simulate gears. A negative value will result in the vehicle reversing. diff --git a/doc/classes/VehicleWheel3D.xml b/doc/classes/VehicleWheel3D.xml index 35f1189a06..5b4511beab 100644 --- a/doc/classes/VehicleWheel3D.xml +++ b/doc/classes/VehicleWheel3D.xml @@ -32,7 +32,7 @@ - Slows down the wheel by applying a braking force. The wheel is only slowed down if it is in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the [member RigidBody3D.mass] of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking. + Slows down the wheel by applying a braking force. The wheel is only slowed down if it is in contact with a surface. The force you need to apply to adequately slow down your vehicle depends on the [member RigidDynamicBody3D.mass] of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 30 range for hard braking. The damping applied to the spring when the spring is being compressed. This value should be between 0.0 (no damping) and 1.0. A value of 0.0 means the car will keep bouncing as the spring keeps its energy. A good value for this is around 0.3 for a normal car, 0.5 for a race car. @@ -41,7 +41,7 @@ The damping applied to the spring when relaxing. This value should be between 0.0 (no damping) and 1.0. This value should always be slightly higher than the [member damping_compression] property. For a [member damping_compression] value of 0.3, try a relaxation value of 0.5. - Accelerates the wheel by applying an engine force. The wheel is only speed up if it is in contact with a surface. The [member RigidBody3D.mass] of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 50 range for acceleration. + Accelerates the wheel by applying an engine force. The wheel is only speed up if it is in contact with a surface. The [member RigidDynamicBody3D.mass] of the vehicle has an effect on the acceleration of the vehicle. For a vehicle with a mass set to 1000, try a value in the 25 - 50 range for acceleration. [b]Note:[/b] The simulation does not take the effect of gears into account, you will need to add logic for this if you wish to simulate gears. A negative value will result in the wheel reversing. @@ -49,7 +49,7 @@ The steering angle for the wheel. Setting this to a non-zero value will result in the vehicle turning when it's moving. - The maximum force the spring can resist. This value should be higher than a quarter of the [member RigidBody3D.mass] of the [VehicleBody3D] or the spring will not carry the weight of the vehicle. Good results are often obtained by a value that is about 3× to 4× this number. + The maximum force the spring can resist. This value should be higher than a quarter of the [member RigidDynamicBody3D.mass] of the [VehicleBody3D] or the spring will not carry the weight of the vehicle. Good results are often obtained by a value that is about 3× to 4× this number. This value defines the stiffness of the suspension. Use a value lower than 50 for an off-road car, a value between 50 and 100 for a race car and try something around 200 for something like a Formula 1 car. diff --git a/doc/classes/VisibleOnScreenEnabler3D.xml b/doc/classes/VisibleOnScreenEnabler3D.xml index 3205d6b415..f781ef9749 100644 --- a/doc/classes/VisibleOnScreenEnabler3D.xml +++ b/doc/classes/VisibleOnScreenEnabler3D.xml @@ -4,7 +4,7 @@ Enables certain nodes only when approximately visible. - The VisibleOnScreenEnabler3D will disable [RigidBody3D] and [AnimationPlayer] nodes when they are not visible. It will only affect other nodes within the same scene as the VisibleOnScreenEnabler3D itself. + The VisibleOnScreenEnabler3D will disable [RigidDynamicBody3D] and [AnimationPlayer] nodes when they are not visible. It will only affect other nodes within the same scene as the VisibleOnScreenEnabler3D itself. If you just want to receive notifications, use [VisibleOnScreenNotifier3D] instead. [b]Note:[/b] VisibleOnScreenEnabler3D uses an approximate heuristic for performance reasons. It doesn't take walls and other occlusion into account. The heuristic is an implementation detail and may change in future versions. If you need precise visibility checking, use another method such as adding an [Area3D] node as a child of a [Camera3D] node and/or [method Vector3.dot]. [b]Note:[/b] VisibleOnScreenEnabler3D will not affect nodes added after scene initialization. diff --git a/editor/icons/RigidBody2D.svg b/editor/icons/RigidBody2D.svg deleted file mode 100644 index 5d08e991ae..0000000000 --- a/editor/icons/RigidBody2D.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/RigidBody3D.svg b/editor/icons/RigidBody3D.svg deleted file mode 100644 index 7f5db4ce88..0000000000 --- a/editor/icons/RigidBody3D.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/RigidDynamicBody2D.svg b/editor/icons/RigidDynamicBody2D.svg new file mode 100644 index 0000000000..5d08e991ae --- /dev/null +++ b/editor/icons/RigidDynamicBody2D.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/RigidDynamicBody3D.svg b/editor/icons/RigidDynamicBody3D.svg new file mode 100644 index 0000000000..7f5db4ce88 --- /dev/null +++ b/editor/icons/RigidDynamicBody3D.svg @@ -0,0 +1 @@ + diff --git a/editor/icons/SoftBody3D.svg b/editor/icons/SoftBody3D.svg deleted file mode 100644 index 7bc9a22c22..0000000000 --- a/editor/icons/SoftBody3D.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/editor/icons/SoftDynamicBody3D.svg b/editor/icons/SoftDynamicBody3D.svg new file mode 100644 index 0000000000..7bc9a22c22 --- /dev/null +++ b/editor/icons/SoftDynamicBody3D.svg @@ -0,0 +1 @@ + diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index c2244befa1..46f1bfb70c 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -413,8 +413,8 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Mapset_name(_fixstr(name, "rigid")); + RigidDynamicBody3D *rigid_body = memnew(RigidDynamicBody3D); + rigid_body->set_name(_fixstr(name, "rigid_body")); p_node->replace_by(rigid_body); rigid_body->set_transform(mi->get_transform()); p_node = rigid_body; @@ -612,7 +612,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, Mapset_name(p_node->get_name()); p_node->replace_by(rigid_body); rigid_body->set_transform(mi->get_transform()); diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index d20f3d105b..5e8585aa29 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -53,7 +53,7 @@ #include "scene/3d/position_3d.h" #include "scene/3d/ray_cast_3d.h" #include "scene/3d/reflection_probe.h" -#include "scene/3d/soft_body_3d.h" +#include "scene/3d/soft_dynamic_body_3d.h" #include "scene/3d/spring_arm_3d.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body_3d.h" @@ -1866,7 +1866,7 @@ MeshInstance3DGizmoPlugin::MeshInstance3DGizmoPlugin() { } bool MeshInstance3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - return Object::cast_to(p_spatial) != nullptr && Object::cast_to(p_spatial) == nullptr; + return Object::cast_to(p_spatial) != nullptr && Object::cast_to(p_spatial) == nullptr; } String MeshInstance3DGizmoPlugin::get_gizmo_name() const { @@ -2489,30 +2489,30 @@ void VehicleWheel3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { /////////// -SoftBody3DGizmoPlugin::SoftBody3DGizmoPlugin() { +SoftDynamicBody3DGizmoPlugin::SoftDynamicBody3DGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); create_material("shape_material", gizmo_color); create_handle_material("handles"); } -bool SoftBody3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - return Object::cast_to(p_spatial) != nullptr; +bool SoftDynamicBody3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { + return Object::cast_to(p_spatial) != nullptr; } -String SoftBody3DGizmoPlugin::get_gizmo_name() const { - return "SoftBody3D"; +String SoftDynamicBody3DGizmoPlugin::get_gizmo_name() const { + return "SoftDynamicBody3D"; } -int SoftBody3DGizmoPlugin::get_priority() const { +int SoftDynamicBody3DGizmoPlugin::get_priority() const { return -1; } -bool SoftBody3DGizmoPlugin::is_selectable_when_hidden() const { +bool SoftDynamicBody3DGizmoPlugin::is_selectable_when_hidden() const { return true; } -void SoftBody3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - SoftBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); +void SoftDynamicBody3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { + SoftDynamicBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); p_gizmo->clear(); @@ -2548,22 +2548,22 @@ void SoftBody3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_collision_triangles(tm); } -String SoftBody3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { - return "SoftBody3D pin point"; +String SoftDynamicBody3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { + return "SoftDynamicBody3D pin point"; } -Variant SoftBody3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { - SoftBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); +Variant SoftDynamicBody3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { + SoftDynamicBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); return Variant(soft_body->is_point_pinned(p_id)); } -void SoftBody3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) { - SoftBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); +void SoftDynamicBody3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) { + SoftDynamicBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); soft_body->pin_point_toggle(p_id); } -bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const { - SoftBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); +bool SoftDynamicBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const { + SoftDynamicBody3D *soft_body = Object::cast_to(p_gizmo->get_spatial_node()); return soft_body->is_point_pinned(p_id); } diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index 415ed5da5c..fa2d3cad5f 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -379,8 +379,8 @@ public: VehicleWheel3DGizmoPlugin(); }; -class SoftBody3DGizmoPlugin : public EditorNode3DGizmoPlugin { - GDCLASS(SoftBody3DGizmoPlugin, EditorNode3DGizmoPlugin); +class SoftDynamicBody3DGizmoPlugin : public EditorNode3DGizmoPlugin { + GDCLASS(SoftDynamicBody3DGizmoPlugin, EditorNode3DGizmoPlugin); public: bool has_gizmo(Node3D *p_spatial) override; @@ -394,7 +394,7 @@ public: void commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false) override; bool is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const override; - SoftBody3DGizmoPlugin(); + SoftDynamicBody3DGizmoPlugin(); }; class VisibleOnScreenNotifier3DGizmoPlugin : public EditorNode3DGizmoPlugin { diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 291cafab2b..1494346249 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -6863,7 +6863,7 @@ void Node3DEditor::_register_all_gizmos() { add_gizmo_plugin(Ref(memnew(AudioStreamPlayer3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(MeshInstance3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(OccluderInstance3DGizmoPlugin))); - add_gizmo_plugin(Ref(memnew(SoftBody3DGizmoPlugin))); + add_gizmo_plugin(Ref(memnew(SoftDynamicBody3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(Sprite3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(Skeleton3DGizmoPlugin))); add_gizmo_plugin(Ref(memnew(Position3DGizmoPlugin))); diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index 8c8a292ad7..271a4da705 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -243,7 +243,7 @@ TypedArray CollisionPolygon2D::get_configuration_warnings() const { TypedArray warnings = Node::get_configuration_warnings(); if (!Object::cast_to(get_parent())) { - warnings.push_back(TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, CharacterBody2D, etc. to give them a shape.")); + warnings.push_back(TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidDynamicBody2D, CharacterBody2D, etc. to give them a shape.")); } int polygon_count = polygon.size(); diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index d52795f0d5..54cb851216 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -175,7 +175,7 @@ TypedArray CollisionShape2D::get_configuration_warnings() const { TypedArray warnings = Node::get_configuration_warnings(); if (!Object::cast_to(get_parent())) { - warnings.push_back(TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidBody2D, CharacterBody2D, etc. to give them a shape.")); + warnings.push_back(TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidDynamicBody2D, CharacterBody2D, etc. to give them a shape.")); } if (!shape.is_valid()) { warnings.push_back(TTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!")); diff --git a/scene/2d/physical_bone_2d.cpp b/scene/2d/physical_bone_2d.cpp index d547914e16..c4b2608812 100644 --- a/scene/2d/physical_bone_2d.cpp +++ b/scene/2d/physical_bone_2d.cpp @@ -33,7 +33,7 @@ void PhysicalBone2D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - // Position the RigidBody in the correct position. + // Position the RigidDynamicBody in the correct position. if (follow_bone_when_simulating) { _position_at_bone2d(); } @@ -158,14 +158,14 @@ void PhysicalBone2D::_start_physics_simulation() { PhysicsServer2D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); // Apply the correct mode - RigidBody2D::Mode rigid_mode = get_mode(); - if (rigid_mode == RigidBody2D::MODE_STATIC) { + RigidDynamicBody2D::Mode rigid_mode = get_mode(); + if (rigid_mode == RigidDynamicBody2D::MODE_STATIC) { set_body_mode(PhysicsServer2D::BODY_MODE_STATIC); - } else if (rigid_mode == RigidBody2D::MODE_DYNAMIC) { + } else if (rigid_mode == RigidDynamicBody2D::MODE_DYNAMIC) { set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC); - } else if (rigid_mode == RigidBody2D::MODE_KINEMATIC) { + } else if (rigid_mode == RigidDynamicBody2D::MODE_KINEMATIC) { set_body_mode(PhysicsServer2D::BODY_MODE_KINEMATIC); - } else if (rigid_mode == RigidBody2D::MODE_DYNAMIC_LOCKED) { + } else if (rigid_mode == RigidDynamicBody2D::MODE_DYNAMIC_LOCKED) { set_body_mode(PhysicsServer2D::BODY_MODE_DYNAMIC_LOCKED); } else { // Default to Dynamic. @@ -295,7 +295,7 @@ void PhysicalBone2D::_bind_methods() { } PhysicalBone2D::PhysicalBone2D() { - // Stop the RigidBody from executing its force integration. + // Stop the RigidDynamicBody from executing its force integration. PhysicsServer2D::get_singleton()->body_set_collision_layer(get_rid(), 0); PhysicsServer2D::get_singleton()->body_set_collision_mask(get_rid(), 0); PhysicsServer2D::get_singleton()->body_set_mode(get_rid(), PhysicsServer2D::BodyMode::BODY_MODE_STATIC); diff --git a/scene/2d/physical_bone_2d.h b/scene/2d/physical_bone_2d.h index 46a2772bad..a250d0aadd 100644 --- a/scene/2d/physical_bone_2d.h +++ b/scene/2d/physical_bone_2d.h @@ -36,8 +36,8 @@ #include "scene/2d/skeleton_2d.h" -class PhysicalBone2D : public RigidBody2D { - GDCLASS(PhysicalBone2D, RigidBody2D); +class PhysicalBone2D : public RigidDynamicBody2D { + GDCLASS(PhysicalBone2D, RigidDynamicBody2D); protected: void _notification(int p_what); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 30f012c7aa..bfead777b6 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -309,7 +309,7 @@ AnimatableBody2D::AnimatableBody2D() : _update_kinematic_motion(); } -void RigidBody2D::_body_enter_tree(ObjectID p_id) { +void RigidDynamicBody2D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); ERR_FAIL_COND(!node); @@ -331,7 +331,7 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody2D::_body_exit_tree(ObjectID p_id) { +void RigidDynamicBody2D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); ERR_FAIL_COND(!node); @@ -352,7 +352,7 @@ void RigidBody2D::_body_exit_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_local_shape) { +void RigidDynamicBody2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_local_shape) { bool body_in = p_status == 1; ObjectID objid = p_instance; @@ -371,8 +371,8 @@ void RigidBody2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan //E->get().rc=0; E->get().in_scene = node && node->is_inside_tree(); if (node) { - node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody2D::_body_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody2D::_body_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidDynamicBody2D::_body_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidDynamicBody2D::_body_exit_tree), make_binds(objid)); if (E->get().in_scene) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -400,8 +400,8 @@ void RigidBody2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan if (E->get().shapes.is_empty()) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody2D::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody2D::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidDynamicBody2D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidDynamicBody2D::_body_exit_tree)); if (in_scene) { emit_signal(SceneStringNames::get_singleton()->body_exited, node); } @@ -415,19 +415,19 @@ void RigidBody2D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan } } -struct _RigidBody2DInOut { +struct _RigidDynamicBody2DInOut { RID rid; ObjectID id; int shape = 0; int local_shape = 0; }; -void RigidBody2D::_body_state_changed_callback(void *p_instance, PhysicsDirectBodyState2D *p_state) { - RigidBody2D *body = (RigidBody2D *)p_instance; +void RigidDynamicBody2D::_body_state_changed_callback(void *p_instance, PhysicsDirectBodyState2D *p_state) { + RigidDynamicBody2D *body = (RigidDynamicBody2D *)p_instance; body->_body_state_changed(p_state); } -void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) { +void RigidDynamicBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) { set_block_transform_notify(true); // don't want notify (would feedback loop) if (mode != MODE_KINEMATIC) { set_global_transform(p_state->get_transform()); @@ -457,9 +457,9 @@ void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) { } } - _RigidBody2DInOut *toadd = (_RigidBody2DInOut *)alloca(p_state->get_contact_count() * sizeof(_RigidBody2DInOut)); + _RigidDynamicBody2DInOut *toadd = (_RigidDynamicBody2DInOut *)alloca(p_state->get_contact_count() * sizeof(_RigidDynamicBody2DInOut)); int toadd_count = 0; //state->get_contact_count(); - RigidBody2D_RemoveAction *toremove = (RigidBody2D_RemoveAction *)alloca(rc * sizeof(RigidBody2D_RemoveAction)); + RigidDynamicBody2D_RemoveAction *toremove = (RigidDynamicBody2D_RemoveAction *)alloca(rc * sizeof(RigidDynamicBody2D_RemoveAction)); int toremove_count = 0; //put the ones to add @@ -523,7 +523,7 @@ void RigidBody2D::_body_state_changed(PhysicsDirectBodyState2D *p_state) { } } -void RigidBody2D::set_mode(Mode p_mode) { +void RigidDynamicBody2D::set_mode(Mode p_mode) { mode = p_mode; switch (p_mode) { case MODE_DYNAMIC: { @@ -544,31 +544,31 @@ void RigidBody2D::set_mode(Mode p_mode) { } } -RigidBody2D::Mode RigidBody2D::get_mode() const { +RigidDynamicBody2D::Mode RigidDynamicBody2D::get_mode() const { return mode; } -void RigidBody2D::set_mass(real_t p_mass) { +void RigidDynamicBody2D::set_mass(real_t p_mass) { ERR_FAIL_COND(p_mass <= 0); mass = p_mass; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_MASS, mass); } -real_t RigidBody2D::get_mass() const { +real_t RigidDynamicBody2D::get_mass() const { return mass; } -void RigidBody2D::set_inertia(real_t p_inertia) { +void RigidDynamicBody2D::set_inertia(real_t p_inertia) { ERR_FAIL_COND(p_inertia < 0); inertia = p_inertia; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_INERTIA, inertia); } -real_t RigidBody2D::get_inertia() const { +real_t RigidDynamicBody2D::get_inertia() const { return inertia; } -void RigidBody2D::set_center_of_mass_mode(CenterOfMassMode p_mode) { +void RigidDynamicBody2D::set_center_of_mass_mode(CenterOfMassMode p_mode) { if (center_of_mass_mode == p_mode) { return; } @@ -590,11 +590,11 @@ void RigidBody2D::set_center_of_mass_mode(CenterOfMassMode p_mode) { } } -RigidBody2D::CenterOfMassMode RigidBody2D::get_center_of_mass_mode() const { +RigidDynamicBody2D::CenterOfMassMode RigidDynamicBody2D::get_center_of_mass_mode() const { return center_of_mass_mode; } -void RigidBody2D::set_center_of_mass(const Vector2 &p_center_of_mass) { +void RigidDynamicBody2D::set_center_of_mass(const Vector2 &p_center_of_mass) { if (center_of_mass == p_center_of_mass) { return; } @@ -605,84 +605,84 @@ void RigidBody2D::set_center_of_mass(const Vector2 &p_center_of_mass) { PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_CENTER_OF_MASS, center_of_mass); } -const Vector2 &RigidBody2D::get_center_of_mass() const { +const Vector2 &RigidDynamicBody2D::get_center_of_mass() const { return center_of_mass; } -void RigidBody2D::set_physics_material_override(const Ref &p_physics_material_override) { +void RigidDynamicBody2D::set_physics_material_override(const Ref &p_physics_material_override) { if (physics_material_override.is_valid()) { - if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody2D::_reload_physics_characteristics))) { - physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody2D::_reload_physics_characteristics)); + if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidDynamicBody2D::_reload_physics_characteristics))) { + physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidDynamicBody2D::_reload_physics_characteristics)); } } physics_material_override = p_physics_material_override; if (physics_material_override.is_valid()) { - physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody2D::_reload_physics_characteristics)); + physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidDynamicBody2D::_reload_physics_characteristics)); } _reload_physics_characteristics(); } -Ref RigidBody2D::get_physics_material_override() const { +Ref RigidDynamicBody2D::get_physics_material_override() const { return physics_material_override; } -void RigidBody2D::set_gravity_scale(real_t p_gravity_scale) { +void RigidDynamicBody2D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } -real_t RigidBody2D::get_gravity_scale() const { +real_t RigidDynamicBody2D::get_gravity_scale() const { return gravity_scale; } -void RigidBody2D::set_linear_damp(real_t p_linear_damp) { +void RigidDynamicBody2D::set_linear_damp(real_t p_linear_damp) { ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_LINEAR_DAMP, linear_damp); } -real_t RigidBody2D::get_linear_damp() const { +real_t RigidDynamicBody2D::get_linear_damp() const { return linear_damp; } -void RigidBody2D::set_angular_damp(real_t p_angular_damp) { +void RigidDynamicBody2D::set_angular_damp(real_t p_angular_damp) { ERR_FAIL_COND(p_angular_damp < -1); angular_damp = p_angular_damp; PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } -real_t RigidBody2D::get_angular_damp() const { +real_t RigidDynamicBody2D::get_angular_damp() const { return angular_damp; } -void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) { +void RigidDynamicBody2D::set_axis_velocity(const Vector2 &p_axis) { Vector2 axis = p_axis.normalized(); linear_velocity -= axis * axis.dot(linear_velocity); linear_velocity += p_axis; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } -void RigidBody2D::set_linear_velocity(const Vector2 &p_velocity) { +void RigidDynamicBody2D::set_linear_velocity(const Vector2 &p_velocity) { linear_velocity = p_velocity; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } -Vector2 RigidBody2D::get_linear_velocity() const { +Vector2 RigidDynamicBody2D::get_linear_velocity() const { return linear_velocity; } -void RigidBody2D::set_angular_velocity(real_t p_velocity) { +void RigidDynamicBody2D::set_angular_velocity(real_t p_velocity) { angular_velocity = p_velocity; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); } -real_t RigidBody2D::get_angular_velocity() const { +real_t RigidDynamicBody2D::get_angular_velocity() const { return angular_velocity; } -void RigidBody2D::set_use_custom_integrator(bool p_enable) { +void RigidDynamicBody2D::set_use_custom_integrator(bool p_enable) { if (custom_integrator == p_enable) { return; } @@ -691,87 +691,87 @@ void RigidBody2D::set_use_custom_integrator(bool p_enable) { PhysicsServer2D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); } -bool RigidBody2D::is_using_custom_integrator() { +bool RigidDynamicBody2D::is_using_custom_integrator() { return custom_integrator; } -void RigidBody2D::set_sleeping(bool p_sleeping) { +void RigidDynamicBody2D::set_sleeping(bool p_sleeping) { sleeping = p_sleeping; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_SLEEPING, sleeping); } -void RigidBody2D::set_can_sleep(bool p_active) { +void RigidDynamicBody2D::set_can_sleep(bool p_active) { can_sleep = p_active; PhysicsServer2D::get_singleton()->body_set_state(get_rid(), PhysicsServer2D::BODY_STATE_CAN_SLEEP, p_active); } -bool RigidBody2D::is_able_to_sleep() const { +bool RigidDynamicBody2D::is_able_to_sleep() const { return can_sleep; } -bool RigidBody2D::is_sleeping() const { +bool RigidDynamicBody2D::is_sleeping() const { return sleeping; } -void RigidBody2D::set_max_contacts_reported(int p_amount) { +void RigidDynamicBody2D::set_max_contacts_reported(int p_amount) { max_contacts_reported = p_amount; PhysicsServer2D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } -int RigidBody2D::get_max_contacts_reported() const { +int RigidDynamicBody2D::get_max_contacts_reported() const { return max_contacts_reported; } -void RigidBody2D::apply_central_impulse(const Vector2 &p_impulse) { +void RigidDynamicBody2D::apply_central_impulse(const Vector2 &p_impulse) { PhysicsServer2D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } -void RigidBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position) { +void RigidDynamicBody2D::apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position) { PhysicsServer2D::get_singleton()->body_apply_impulse(get_rid(), p_impulse, p_position); } -void RigidBody2D::apply_torque_impulse(real_t p_torque) { +void RigidDynamicBody2D::apply_torque_impulse(real_t p_torque) { PhysicsServer2D::get_singleton()->body_apply_torque_impulse(get_rid(), p_torque); } -void RigidBody2D::set_applied_force(const Vector2 &p_force) { +void RigidDynamicBody2D::set_applied_force(const Vector2 &p_force) { PhysicsServer2D::get_singleton()->body_set_applied_force(get_rid(), p_force); }; -Vector2 RigidBody2D::get_applied_force() const { +Vector2 RigidDynamicBody2D::get_applied_force() const { return PhysicsServer2D::get_singleton()->body_get_applied_force(get_rid()); }; -void RigidBody2D::set_applied_torque(const real_t p_torque) { +void RigidDynamicBody2D::set_applied_torque(const real_t p_torque) { PhysicsServer2D::get_singleton()->body_set_applied_torque(get_rid(), p_torque); }; -real_t RigidBody2D::get_applied_torque() const { +real_t RigidDynamicBody2D::get_applied_torque() const { return PhysicsServer2D::get_singleton()->body_get_applied_torque(get_rid()); }; -void RigidBody2D::add_central_force(const Vector2 &p_force) { +void RigidDynamicBody2D::add_central_force(const Vector2 &p_force) { PhysicsServer2D::get_singleton()->body_add_central_force(get_rid(), p_force); } -void RigidBody2D::add_force(const Vector2 &p_force, const Vector2 &p_position) { +void RigidDynamicBody2D::add_force(const Vector2 &p_force, const Vector2 &p_position) { PhysicsServer2D::get_singleton()->body_add_force(get_rid(), p_force, p_position); } -void RigidBody2D::add_torque(const real_t p_torque) { +void RigidDynamicBody2D::add_torque(const real_t p_torque) { PhysicsServer2D::get_singleton()->body_add_torque(get_rid(), p_torque); } -void RigidBody2D::set_continuous_collision_detection_mode(CCDMode p_mode) { +void RigidDynamicBody2D::set_continuous_collision_detection_mode(CCDMode p_mode) { ccd_mode = p_mode; PhysicsServer2D::get_singleton()->body_set_continuous_collision_detection_mode(get_rid(), PhysicsServer2D::CCDMode(p_mode)); } -RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() const { +RigidDynamicBody2D::CCDMode RigidDynamicBody2D::get_continuous_collision_detection_mode() const { return ccd_mode; } -TypedArray RigidBody2D::get_colliding_bodies() const { +TypedArray RigidDynamicBody2D::get_colliding_bodies() const { ERR_FAIL_COND_V(!contact_monitor, Array()); TypedArray ret; @@ -789,7 +789,7 @@ TypedArray RigidBody2D::get_colliding_bodies() const { return ret; } -void RigidBody2D::set_contact_monitor(bool p_enabled) { +void RigidDynamicBody2D::set_contact_monitor(bool p_enabled) { if (p_enabled == is_contact_monitor_enabled()) { return; } @@ -803,8 +803,8 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { Node *node = Object::cast_to(obj); if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody2D::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody2D::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidDynamicBody2D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidDynamicBody2D::_body_exit_tree)); } } @@ -816,11 +816,11 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { } } -bool RigidBody2D::is_contact_monitor_enabled() const { +bool RigidDynamicBody2D::is_contact_monitor_enabled() const { return contact_monitor != nullptr; } -void RigidBody2D::_notification(int p_what) { +void RigidDynamicBody2D::_notification(int p_what) { #ifdef TOOLS_ENABLED switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -838,86 +838,86 @@ void RigidBody2D::_notification(int p_what) { #endif } -TypedArray RigidBody2D::get_configuration_warnings() const { +TypedArray RigidDynamicBody2D::get_configuration_warnings() const { Transform2D t = get_transform(); TypedArray warnings = CollisionObject2D::get_configuration_warnings(); if ((get_mode() == MODE_DYNAMIC || get_mode() == MODE_DYNAMIC_LOCKED) && (ABS(t.elements[0].length() - 1.0) > 0.05 || ABS(t.elements[1].length() - 1.0) > 0.05)) { - warnings.push_back(TTR("Size changes to RigidBody2D (in dynamic modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); + warnings.push_back(TTR("Size changes to RigidDynamicBody2D (in dynamic modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); } return warnings; } -void RigidBody2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody2D::set_mode); - ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody2D::get_mode); +void RigidDynamicBody2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidDynamicBody2D::set_mode); + ClassDB::bind_method(D_METHOD("get_mode"), &RigidDynamicBody2D::get_mode); - ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody2D::set_mass); - ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody2D::get_mass); + ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidDynamicBody2D::set_mass); + ClassDB::bind_method(D_METHOD("get_mass"), &RigidDynamicBody2D::get_mass); - ClassDB::bind_method(D_METHOD("get_inertia"), &RigidBody2D::get_inertia); - ClassDB::bind_method(D_METHOD("set_inertia", "inertia"), &RigidBody2D::set_inertia); + ClassDB::bind_method(D_METHOD("get_inertia"), &RigidDynamicBody2D::get_inertia); + ClassDB::bind_method(D_METHOD("set_inertia", "inertia"), &RigidDynamicBody2D::set_inertia); - ClassDB::bind_method(D_METHOD("set_center_of_mass_mode", "mode"), &RigidBody2D::set_center_of_mass_mode); - ClassDB::bind_method(D_METHOD("get_center_of_mass_mode"), &RigidBody2D::get_center_of_mass_mode); + ClassDB::bind_method(D_METHOD("set_center_of_mass_mode", "mode"), &RigidDynamicBody2D::set_center_of_mass_mode); + ClassDB::bind_method(D_METHOD("get_center_of_mass_mode"), &RigidDynamicBody2D::get_center_of_mass_mode); - ClassDB::bind_method(D_METHOD("set_center_of_mass", "center_of_mass"), &RigidBody2D::set_center_of_mass); - ClassDB::bind_method(D_METHOD("get_center_of_mass"), &RigidBody2D::get_center_of_mass); + ClassDB::bind_method(D_METHOD("set_center_of_mass", "center_of_mass"), &RigidDynamicBody2D::set_center_of_mass); + ClassDB::bind_method(D_METHOD("get_center_of_mass"), &RigidDynamicBody2D::get_center_of_mass); - ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidBody2D::set_physics_material_override); - ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidBody2D::get_physics_material_override); + ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidDynamicBody2D::set_physics_material_override); + ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidDynamicBody2D::get_physics_material_override); - ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody2D::set_gravity_scale); - ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody2D::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidDynamicBody2D::set_gravity_scale); + ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidDynamicBody2D::get_gravity_scale); - ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidBody2D::set_linear_damp); - ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody2D::get_linear_damp); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidDynamicBody2D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidDynamicBody2D::get_linear_damp); - ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidBody2D::set_angular_damp); - ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody2D::get_angular_damp); + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidDynamicBody2D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidDynamicBody2D::get_angular_damp); - ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidBody2D::set_linear_velocity); - ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody2D::get_linear_velocity); + ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidDynamicBody2D::set_linear_velocity); + ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidDynamicBody2D::get_linear_velocity); - ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody2D::set_angular_velocity); - ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody2D::get_angular_velocity); + ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidDynamicBody2D::set_angular_velocity); + ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidDynamicBody2D::get_angular_velocity); - ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidBody2D::set_max_contacts_reported); - ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody2D::get_max_contacts_reported); + ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidDynamicBody2D::set_max_contacts_reported); + ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidDynamicBody2D::get_max_contacts_reported); - ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidBody2D::set_use_custom_integrator); - ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody2D::is_using_custom_integrator); + ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidDynamicBody2D::set_use_custom_integrator); + ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidDynamicBody2D::is_using_custom_integrator); - ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidBody2D::set_contact_monitor); - ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody2D::is_contact_monitor_enabled); + ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidDynamicBody2D::set_contact_monitor); + ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidDynamicBody2D::is_contact_monitor_enabled); - ClassDB::bind_method(D_METHOD("set_continuous_collision_detection_mode", "mode"), &RigidBody2D::set_continuous_collision_detection_mode); - ClassDB::bind_method(D_METHOD("get_continuous_collision_detection_mode"), &RigidBody2D::get_continuous_collision_detection_mode); + ClassDB::bind_method(D_METHOD("set_continuous_collision_detection_mode", "mode"), &RigidDynamicBody2D::set_continuous_collision_detection_mode); + ClassDB::bind_method(D_METHOD("get_continuous_collision_detection_mode"), &RigidDynamicBody2D::get_continuous_collision_detection_mode); - ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody2D::set_axis_velocity); - ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody2D::apply_central_impulse, Vector2()); - ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidBody2D::apply_impulse, Vector2()); - ClassDB::bind_method(D_METHOD("apply_torque_impulse", "torque"), &RigidBody2D::apply_torque_impulse); + ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidDynamicBody2D::set_axis_velocity); + ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidDynamicBody2D::apply_central_impulse, Vector2()); + ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidDynamicBody2D::apply_impulse, Vector2()); + ClassDB::bind_method(D_METHOD("apply_torque_impulse", "torque"), &RigidDynamicBody2D::apply_torque_impulse); - ClassDB::bind_method(D_METHOD("set_applied_force", "force"), &RigidBody2D::set_applied_force); - ClassDB::bind_method(D_METHOD("get_applied_force"), &RigidBody2D::get_applied_force); + ClassDB::bind_method(D_METHOD("set_applied_force", "force"), &RigidDynamicBody2D::set_applied_force); + ClassDB::bind_method(D_METHOD("get_applied_force"), &RigidDynamicBody2D::get_applied_force); - ClassDB::bind_method(D_METHOD("set_applied_torque", "torque"), &RigidBody2D::set_applied_torque); - ClassDB::bind_method(D_METHOD("get_applied_torque"), &RigidBody2D::get_applied_torque); + ClassDB::bind_method(D_METHOD("set_applied_torque", "torque"), &RigidDynamicBody2D::set_applied_torque); + ClassDB::bind_method(D_METHOD("get_applied_torque"), &RigidDynamicBody2D::get_applied_torque); - ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody2D::add_central_force); - ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody2D::add_force, Vector2()); - ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody2D::add_torque); + ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidDynamicBody2D::add_central_force); + ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidDynamicBody2D::add_force, Vector2()); + ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidDynamicBody2D::add_torque); - ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody2D::set_sleeping); - ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody2D::is_sleeping); + ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidDynamicBody2D::set_sleeping); + ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidDynamicBody2D::is_sleeping); - ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidBody2D::set_can_sleep); - ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody2D::is_able_to_sleep); + ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidDynamicBody2D::set_can_sleep); + ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidDynamicBody2D::is_able_to_sleep); - ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody2D::get_colliding_bodies); + ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidDynamicBody2D::get_colliding_bodies); GDVIRTUAL_BIND(_integrate_forces, "state"); @@ -964,7 +964,7 @@ void RigidBody2D::_bind_methods() { BIND_ENUM_CONSTANT(CCD_MODE_CAST_SHAPE); } -void RigidBody2D::_validate_property(PropertyInfo &property) const { +void RigidDynamicBody2D::_validate_property(PropertyInfo &property) const { if (center_of_mass_mode != CENTER_OF_MASS_MODE_CUSTOM) { if (property.name == "center_of_mass") { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -972,18 +972,18 @@ void RigidBody2D::_validate_property(PropertyInfo &property) const { } } -RigidBody2D::RigidBody2D() : +RigidDynamicBody2D::RigidDynamicBody2D() : PhysicsBody2D(PhysicsServer2D::BODY_MODE_DYNAMIC) { PhysicsServer2D::get_singleton()->body_set_state_sync_callback(get_rid(), this, _body_state_changed_callback); } -RigidBody2D::~RigidBody2D() { +RigidDynamicBody2D::~RigidDynamicBody2D() { if (contact_monitor) { memdelete(contact_monitor); } } -void RigidBody2D::_reload_physics_characteristics() { +void RigidDynamicBody2D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_BOUNCE, 0); PhysicsServer2D::get_singleton()->body_set_param(get_rid(), PhysicsServer2D::BODY_PARAM_FRICTION, 1); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 1d6437a3ad..e9930b13a0 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -113,8 +113,8 @@ private: bool is_sync_to_physics_enabled() const; }; -class RigidBody2D : public PhysicsBody2D { - GDCLASS(RigidBody2D, PhysicsBody2D); +class RigidDynamicBody2D : public PhysicsBody2D { + GDCLASS(RigidDynamicBody2D, PhysicsBody2D); public: enum Mode { @@ -177,7 +177,7 @@ private: local_shape = p_ls; } }; - struct RigidBody2D_RemoveAction { + struct RigidDynamicBody2D_RemoveAction { RID rid; ObjectID body_id; ShapePair pair; @@ -283,16 +283,16 @@ public: virtual TypedArray get_configuration_warnings() const override; - RigidBody2D(); - ~RigidBody2D(); + RigidDynamicBody2D(); + ~RigidDynamicBody2D(); private: void _reload_physics_characteristics(); }; -VARIANT_ENUM_CAST(RigidBody2D::Mode); -VARIANT_ENUM_CAST(RigidBody2D::CenterOfMassMode); -VARIANT_ENUM_CAST(RigidBody2D::CCDMode); +VARIANT_ENUM_CAST(RigidDynamicBody2D::Mode); +VARIANT_ENUM_CAST(RigidDynamicBody2D::CenterOfMassMode); +VARIANT_ENUM_CAST(RigidDynamicBody2D::CCDMode); class CharacterBody2D : public PhysicsBody2D { GDCLASS(CharacterBody2D, PhysicsBody2D); diff --git a/scene/3d/collision_polygon_3d.cpp b/scene/3d/collision_polygon_3d.cpp index d5835586f9..6328d9c67d 100644 --- a/scene/3d/collision_polygon_3d.cpp +++ b/scene/3d/collision_polygon_3d.cpp @@ -170,7 +170,7 @@ TypedArray CollisionPolygon3D::get_configuration_warnings() const { TypedArray warnings = Node::get_configuration_warnings(); if (!Object::cast_to(get_parent())) { - warnings.push_back(TTR("CollisionPolygon3D only serves to provide a collision shape to a CollisionObject3D derived node. Please only use it as a child of Area3D, StaticBody3D, RigidBody3D, CharacterBody3D, etc. to give them a shape.")); + warnings.push_back(TTR("CollisionPolygon3D only serves to provide a collision shape to a CollisionObject3D derived node. Please only use it as a child of Area3D, StaticBody3D, RigidDynamicBody3D, CharacterBody3D, etc. to give them a shape.")); } if (polygon.is_empty()) { diff --git a/scene/3d/collision_shape_3d.cpp b/scene/3d/collision_shape_3d.cpp index d4668a24f2..c79f956642 100644 --- a/scene/3d/collision_shape_3d.cpp +++ b/scene/3d/collision_shape_3d.cpp @@ -115,7 +115,7 @@ TypedArray CollisionShape3D::get_configuration_warnings() const { TypedArray warnings = Node::get_configuration_warnings(); if (!Object::cast_to(get_parent())) { - warnings.push_back(TTR("CollisionShape3D only serves to provide a collision shape to a CollisionObject3D derived node. Please only use it as a child of Area3D, StaticBody3D, RigidBody3D, CharacterBody3D, etc. to give them a shape.")); + warnings.push_back(TTR("CollisionShape3D only serves to provide a collision shape to a CollisionObject3D derived node. Please only use it as a child of Area3D, StaticBody3D, RigidDynamicBody3D, CharacterBody3D, etc. to give them a shape.")); } if (!shape.is_valid()) { @@ -123,10 +123,10 @@ TypedArray CollisionShape3D::get_configuration_warnings() const { } if (shape.is_valid() && - Object::cast_to(get_parent()) && + Object::cast_to(get_parent()) && Object::cast_to(*shape) && - Object::cast_to(get_parent())->get_mode() != RigidBody3D::MODE_STATIC) { - warnings.push_back(TTR("ConcavePolygonShape3D doesn't support RigidBody3D in another mode than static.")); + Object::cast_to(get_parent())->get_mode() != RigidDynamicBody3D::MODE_STATIC) { + warnings.push_back(TTR("ConcavePolygonShape3D doesn't support RigidDynamicBody3D in another mode than static.")); } return warnings; diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 00c6664e65..35f6d0930a 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -364,7 +364,7 @@ AnimatableBody3D::AnimatableBody3D() : _update_kinematic_motion(); } -void RigidBody3D::_body_enter_tree(ObjectID p_id) { +void RigidDynamicBody3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); ERR_FAIL_COND(!node); @@ -387,7 +387,7 @@ void RigidBody3D::_body_enter_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody3D::_body_exit_tree(ObjectID p_id) { +void RigidDynamicBody3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to(obj); ERR_FAIL_COND(!node); @@ -408,7 +408,7 @@ void RigidBody3D::_body_exit_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_local_shape) { +void RigidDynamicBody3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_local_shape) { bool body_in = p_status == 1; ObjectID objid = p_instance; @@ -427,8 +427,8 @@ void RigidBody3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan //E->get().rc=0; E->get().in_tree = node && node->is_inside_tree(); if (node) { - node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidDynamicBody3D::_body_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidDynamicBody3D::_body_exit_tree), make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -454,8 +454,8 @@ void RigidBody3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan if (E->get().shapes.is_empty()) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidDynamicBody3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidDynamicBody3D::_body_exit_tree)); if (in_tree) { emit_signal(SceneStringNames::get_singleton()->body_exited, node); } @@ -469,19 +469,19 @@ void RigidBody3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instan } } -struct _RigidBodyInOut { +struct _RigidDynamicBodyInOut { RID rid; ObjectID id; int shape = 0; int local_shape = 0; }; -void RigidBody3D::_body_state_changed_callback(void *p_instance, PhysicsDirectBodyState3D *p_state) { - RigidBody3D *body = (RigidBody3D *)p_instance; +void RigidDynamicBody3D::_body_state_changed_callback(void *p_instance, PhysicsDirectBodyState3D *p_state) { + RigidDynamicBody3D *body = (RigidDynamicBody3D *)p_instance; body->_body_state_changed(p_state); } -void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { +void RigidDynamicBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { set_ignore_transform_notification(true); set_global_transform(p_state->get_transform()); @@ -512,9 +512,9 @@ void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { } } - _RigidBodyInOut *toadd = (_RigidBodyInOut *)alloca(p_state->get_contact_count() * sizeof(_RigidBodyInOut)); + _RigidDynamicBodyInOut *toadd = (_RigidDynamicBodyInOut *)alloca(p_state->get_contact_count() * sizeof(_RigidDynamicBodyInOut)); int toadd_count = 0; //state->get_contact_count(); - RigidBody3D_RemoveAction *toremove = (RigidBody3D_RemoveAction *)alloca(rc * sizeof(RigidBody3D_RemoveAction)); + RigidDynamicBody3D_RemoveAction *toremove = (RigidDynamicBody3D_RemoveAction *)alloca(rc * sizeof(RigidDynamicBody3D_RemoveAction)); int toremove_count = 0; //put the ones to add @@ -580,7 +580,7 @@ void RigidBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { } } -void RigidBody3D::_notification(int p_what) { +void RigidDynamicBody3D::_notification(int p_what) { #ifdef TOOLS_ENABLED switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -598,7 +598,7 @@ void RigidBody3D::_notification(int p_what) { #endif } -void RigidBody3D::set_mode(Mode p_mode) { +void RigidDynamicBody3D::set_mode(Mode p_mode) { mode = p_mode; switch (p_mode) { case MODE_DYNAMIC: { @@ -617,21 +617,21 @@ void RigidBody3D::set_mode(Mode p_mode) { update_configuration_warnings(); } -RigidBody3D::Mode RigidBody3D::get_mode() const { +RigidDynamicBody3D::Mode RigidDynamicBody3D::get_mode() const { return mode; } -void RigidBody3D::set_mass(real_t p_mass) { +void RigidDynamicBody3D::set_mass(real_t p_mass) { ERR_FAIL_COND(p_mass <= 0); mass = p_mass; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_MASS, mass); } -real_t RigidBody3D::get_mass() const { +real_t RigidDynamicBody3D::get_mass() const { return mass; } -void RigidBody3D::set_inertia(const Vector3 &p_inertia) { +void RigidDynamicBody3D::set_inertia(const Vector3 &p_inertia) { ERR_FAIL_COND(p_inertia.x < 0); ERR_FAIL_COND(p_inertia.y < 0); ERR_FAIL_COND(p_inertia.z < 0); @@ -640,11 +640,11 @@ void RigidBody3D::set_inertia(const Vector3 &p_inertia) { PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_INERTIA, inertia); } -const Vector3 &RigidBody3D::get_inertia() const { +const Vector3 &RigidDynamicBody3D::get_inertia() const { return inertia; } -void RigidBody3D::set_center_of_mass_mode(CenterOfMassMode p_mode) { +void RigidDynamicBody3D::set_center_of_mass_mode(CenterOfMassMode p_mode) { if (center_of_mass_mode == p_mode) { return; } @@ -666,11 +666,11 @@ void RigidBody3D::set_center_of_mass_mode(CenterOfMassMode p_mode) { } } -RigidBody3D::CenterOfMassMode RigidBody3D::get_center_of_mass_mode() const { +RigidDynamicBody3D::CenterOfMassMode RigidDynamicBody3D::get_center_of_mass_mode() const { return center_of_mass_mode; } -void RigidBody3D::set_center_of_mass(const Vector3 &p_center_of_mass) { +void RigidDynamicBody3D::set_center_of_mass(const Vector3 &p_center_of_mass) { if (center_of_mass == p_center_of_mass) { return; } @@ -681,88 +681,88 @@ void RigidBody3D::set_center_of_mass(const Vector3 &p_center_of_mass) { PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_CENTER_OF_MASS, center_of_mass); } -const Vector3 &RigidBody3D::get_center_of_mass() const { +const Vector3 &RigidDynamicBody3D::get_center_of_mass() const { return center_of_mass; } -void RigidBody3D::set_physics_material_override(const Ref &p_physics_material_override) { +void RigidDynamicBody3D::set_physics_material_override(const Ref &p_physics_material_override) { if (physics_material_override.is_valid()) { - if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics))) { - physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics)); + if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidDynamicBody3D::_reload_physics_characteristics))) { + physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidDynamicBody3D::_reload_physics_characteristics)); } } physics_material_override = p_physics_material_override; if (physics_material_override.is_valid()) { - physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics)); + physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidDynamicBody3D::_reload_physics_characteristics)); } _reload_physics_characteristics(); } -Ref RigidBody3D::get_physics_material_override() const { +Ref RigidDynamicBody3D::get_physics_material_override() const { return physics_material_override; } -void RigidBody3D::set_gravity_scale(real_t p_gravity_scale) { +void RigidDynamicBody3D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } -real_t RigidBody3D::get_gravity_scale() const { +real_t RigidDynamicBody3D::get_gravity_scale() const { return gravity_scale; } -void RigidBody3D::set_linear_damp(real_t p_linear_damp) { +void RigidDynamicBody3D::set_linear_damp(real_t p_linear_damp) { ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, linear_damp); } -real_t RigidBody3D::get_linear_damp() const { +real_t RigidDynamicBody3D::get_linear_damp() const { return linear_damp; } -void RigidBody3D::set_angular_damp(real_t p_angular_damp) { +void RigidDynamicBody3D::set_angular_damp(real_t p_angular_damp) { ERR_FAIL_COND(p_angular_damp < -1); angular_damp = p_angular_damp; PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } -real_t RigidBody3D::get_angular_damp() const { +real_t RigidDynamicBody3D::get_angular_damp() const { return angular_damp; } -void RigidBody3D::set_axis_velocity(const Vector3 &p_axis) { +void RigidDynamicBody3D::set_axis_velocity(const Vector3 &p_axis) { Vector3 axis = p_axis.normalized(); linear_velocity -= axis * axis.dot(linear_velocity); linear_velocity += p_axis; PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } -void RigidBody3D::set_linear_velocity(const Vector3 &p_velocity) { +void RigidDynamicBody3D::set_linear_velocity(const Vector3 &p_velocity) { linear_velocity = p_velocity; PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } -Vector3 RigidBody3D::get_linear_velocity() const { +Vector3 RigidDynamicBody3D::get_linear_velocity() const { return linear_velocity; } -void RigidBody3D::set_angular_velocity(const Vector3 &p_velocity) { +void RigidDynamicBody3D::set_angular_velocity(const Vector3 &p_velocity) { angular_velocity = p_velocity; PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); } -Vector3 RigidBody3D::get_angular_velocity() const { +Vector3 RigidDynamicBody3D::get_angular_velocity() const { return angular_velocity; } -Basis RigidBody3D::get_inverse_inertia_tensor() const { +Basis RigidDynamicBody3D::get_inverse_inertia_tensor() const { return inverse_inertia_tensor; } -void RigidBody3D::set_use_custom_integrator(bool p_enable) { +void RigidDynamicBody3D::set_use_custom_integrator(bool p_enable) { if (custom_integrator == p_enable) { return; } @@ -771,73 +771,73 @@ void RigidBody3D::set_use_custom_integrator(bool p_enable) { PhysicsServer3D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); } -bool RigidBody3D::is_using_custom_integrator() { +bool RigidDynamicBody3D::is_using_custom_integrator() { return custom_integrator; } -void RigidBody3D::set_sleeping(bool p_sleeping) { +void RigidDynamicBody3D::set_sleeping(bool p_sleeping) { sleeping = p_sleeping; PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_SLEEPING, sleeping); } -void RigidBody3D::set_can_sleep(bool p_active) { +void RigidDynamicBody3D::set_can_sleep(bool p_active) { can_sleep = p_active; PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_CAN_SLEEP, p_active); } -bool RigidBody3D::is_able_to_sleep() const { +bool RigidDynamicBody3D::is_able_to_sleep() const { return can_sleep; } -bool RigidBody3D::is_sleeping() const { +bool RigidDynamicBody3D::is_sleeping() const { return sleeping; } -void RigidBody3D::set_max_contacts_reported(int p_amount) { +void RigidDynamicBody3D::set_max_contacts_reported(int p_amount) { max_contacts_reported = p_amount; PhysicsServer3D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } -int RigidBody3D::get_max_contacts_reported() const { +int RigidDynamicBody3D::get_max_contacts_reported() const { return max_contacts_reported; } -void RigidBody3D::add_central_force(const Vector3 &p_force) { +void RigidDynamicBody3D::add_central_force(const Vector3 &p_force) { PhysicsServer3D::get_singleton()->body_add_central_force(get_rid(), p_force); } -void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_position) { +void RigidDynamicBody3D::add_force(const Vector3 &p_force, const Vector3 &p_position) { PhysicsServer3D *singleton = PhysicsServer3D::get_singleton(); singleton->body_add_force(get_rid(), p_force, p_position); } -void RigidBody3D::add_torque(const Vector3 &p_torque) { +void RigidDynamicBody3D::add_torque(const Vector3 &p_torque) { PhysicsServer3D::get_singleton()->body_add_torque(get_rid(), p_torque); } -void RigidBody3D::apply_central_impulse(const Vector3 &p_impulse) { +void RigidDynamicBody3D::apply_central_impulse(const Vector3 &p_impulse) { PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } -void RigidBody3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) { +void RigidDynamicBody3D::apply_impulse(const Vector3 &p_impulse, const Vector3 &p_position) { PhysicsServer3D *singleton = PhysicsServer3D::get_singleton(); singleton->body_apply_impulse(get_rid(), p_impulse, p_position); } -void RigidBody3D::apply_torque_impulse(const Vector3 &p_impulse) { +void RigidDynamicBody3D::apply_torque_impulse(const Vector3 &p_impulse) { PhysicsServer3D::get_singleton()->body_apply_torque_impulse(get_rid(), p_impulse); } -void RigidBody3D::set_use_continuous_collision_detection(bool p_enable) { +void RigidDynamicBody3D::set_use_continuous_collision_detection(bool p_enable) { ccd = p_enable; PhysicsServer3D::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(), p_enable); } -bool RigidBody3D::is_using_continuous_collision_detection() const { +bool RigidDynamicBody3D::is_using_continuous_collision_detection() const { return ccd; } -void RigidBody3D::set_contact_monitor(bool p_enabled) { +void RigidDynamicBody3D::set_contact_monitor(bool p_enabled) { if (p_enabled == is_contact_monitor_enabled()) { return; } @@ -851,8 +851,8 @@ void RigidBody3D::set_contact_monitor(bool p_enabled) { Node *node = Object::cast_to(obj); if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody3D::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody3D::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidDynamicBody3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidDynamicBody3D::_body_exit_tree)); } } @@ -864,11 +864,11 @@ void RigidBody3D::set_contact_monitor(bool p_enabled) { } } -bool RigidBody3D::is_contact_monitor_enabled() const { +bool RigidDynamicBody3D::is_contact_monitor_enabled() const { return contact_monitor != nullptr; } -Array RigidBody3D::get_colliding_bodies() const { +Array RigidDynamicBody3D::get_colliding_bodies() const { ERR_FAIL_COND_V(!contact_monitor, Array()); Array ret; @@ -886,83 +886,83 @@ Array RigidBody3D::get_colliding_bodies() const { return ret; } -TypedArray RigidBody3D::get_configuration_warnings() const { +TypedArray RigidDynamicBody3D::get_configuration_warnings() const { Transform3D t = get_transform(); TypedArray warnings = Node::get_configuration_warnings(); if ((get_mode() == MODE_DYNAMIC || get_mode() == MODE_DYNAMIC_LOCKED) && (ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) { - warnings.push_back(TTR("Size changes to RigidBody3D (in dynamic modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); + warnings.push_back(TTR("Size changes to RigidDynamicBody (in dynamic modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); } return warnings; } -void RigidBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody3D::set_mode); - ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody3D::get_mode); +void RigidDynamicBody3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidDynamicBody3D::set_mode); + ClassDB::bind_method(D_METHOD("get_mode"), &RigidDynamicBody3D::get_mode); - ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody3D::set_mass); - ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody3D::get_mass); + ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidDynamicBody3D::set_mass); + ClassDB::bind_method(D_METHOD("get_mass"), &RigidDynamicBody3D::get_mass); - ClassDB::bind_method(D_METHOD("set_inertia", "inertia"), &RigidBody3D::set_inertia); - ClassDB::bind_method(D_METHOD("get_inertia"), &RigidBody3D::get_inertia); + ClassDB::bind_method(D_METHOD("set_inertia", "inertia"), &RigidDynamicBody3D::set_inertia); + ClassDB::bind_method(D_METHOD("get_inertia"), &RigidDynamicBody3D::get_inertia); - ClassDB::bind_method(D_METHOD("set_center_of_mass_mode", "mode"), &RigidBody3D::set_center_of_mass_mode); - ClassDB::bind_method(D_METHOD("get_center_of_mass_mode"), &RigidBody3D::get_center_of_mass_mode); + ClassDB::bind_method(D_METHOD("set_center_of_mass_mode", "mode"), &RigidDynamicBody3D::set_center_of_mass_mode); + ClassDB::bind_method(D_METHOD("get_center_of_mass_mode"), &RigidDynamicBody3D::get_center_of_mass_mode); - ClassDB::bind_method(D_METHOD("set_center_of_mass", "center_of_mass"), &RigidBody3D::set_center_of_mass); - ClassDB::bind_method(D_METHOD("get_center_of_mass"), &RigidBody3D::get_center_of_mass); + ClassDB::bind_method(D_METHOD("set_center_of_mass", "center_of_mass"), &RigidDynamicBody3D::set_center_of_mass); + ClassDB::bind_method(D_METHOD("get_center_of_mass"), &RigidDynamicBody3D::get_center_of_mass); - ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidBody3D::set_physics_material_override); - ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidBody3D::get_physics_material_override); + ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidDynamicBody3D::set_physics_material_override); + ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidDynamicBody3D::get_physics_material_override); - ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidBody3D::set_linear_velocity); - ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody3D::get_linear_velocity); + ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidDynamicBody3D::set_linear_velocity); + ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidDynamicBody3D::get_linear_velocity); - ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody3D::set_angular_velocity); - ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody3D::get_angular_velocity); + ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidDynamicBody3D::set_angular_velocity); + ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidDynamicBody3D::get_angular_velocity); - ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &RigidBody3D::get_inverse_inertia_tensor); + ClassDB::bind_method(D_METHOD("get_inverse_inertia_tensor"), &RigidDynamicBody3D::get_inverse_inertia_tensor); - ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody3D::set_gravity_scale); - ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody3D::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidDynamicBody3D::set_gravity_scale); + ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidDynamicBody3D::get_gravity_scale); - ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidBody3D::set_linear_damp); - ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody3D::get_linear_damp); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidDynamicBody3D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidDynamicBody3D::get_linear_damp); - ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidBody3D::set_angular_damp); - ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody3D::get_angular_damp); + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidDynamicBody3D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidDynamicBody3D::get_angular_damp); - ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidBody3D::set_max_contacts_reported); - ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody3D::get_max_contacts_reported); + ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidDynamicBody3D::set_max_contacts_reported); + ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidDynamicBody3D::get_max_contacts_reported); - ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidBody3D::set_use_custom_integrator); - ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody3D::is_using_custom_integrator); + ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidDynamicBody3D::set_use_custom_integrator); + ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidDynamicBody3D::is_using_custom_integrator); - ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidBody3D::set_contact_monitor); - ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody3D::is_contact_monitor_enabled); + ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidDynamicBody3D::set_contact_monitor); + ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidDynamicBody3D::is_contact_monitor_enabled); - ClassDB::bind_method(D_METHOD("set_use_continuous_collision_detection", "enable"), &RigidBody3D::set_use_continuous_collision_detection); - ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"), &RigidBody3D::is_using_continuous_collision_detection); + ClassDB::bind_method(D_METHOD("set_use_continuous_collision_detection", "enable"), &RigidDynamicBody3D::set_use_continuous_collision_detection); + ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"), &RigidDynamicBody3D::is_using_continuous_collision_detection); - ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody3D::set_axis_velocity); + ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidDynamicBody3D::set_axis_velocity); - ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody3D::add_central_force); - ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody3D::add_force, Vector3()); - ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody3D::add_torque); + ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidDynamicBody3D::add_central_force); + ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidDynamicBody3D::add_force, Vector3()); + ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidDynamicBody3D::add_torque); - ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody3D::apply_central_impulse); - ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidBody3D::apply_impulse, Vector3()); - ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody3D::apply_torque_impulse); + ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidDynamicBody3D::apply_central_impulse); + ClassDB::bind_method(D_METHOD("apply_impulse", "impulse", "position"), &RigidDynamicBody3D::apply_impulse, Vector3()); + ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidDynamicBody3D::apply_torque_impulse); - ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody3D::set_sleeping); - ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody3D::is_sleeping); + ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidDynamicBody3D::set_sleeping); + ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidDynamicBody3D::is_sleeping); - ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidBody3D::set_can_sleep); - ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody3D::is_able_to_sleep); + ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidDynamicBody3D::set_can_sleep); + ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidDynamicBody3D::is_able_to_sleep); - ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody3D::get_colliding_bodies); + ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidDynamicBody3D::get_colliding_bodies); GDVIRTUAL_BIND(_integrate_forces, "state"); @@ -1002,7 +1002,7 @@ void RigidBody3D::_bind_methods() { BIND_ENUM_CONSTANT(CENTER_OF_MASS_MODE_CUSTOM); } -void RigidBody3D::_validate_property(PropertyInfo &property) const { +void RigidDynamicBody3D::_validate_property(PropertyInfo &property) const { if (center_of_mass_mode != CENTER_OF_MASS_MODE_CUSTOM) { if (property.name == "center_of_mass") { property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; @@ -1010,18 +1010,18 @@ void RigidBody3D::_validate_property(PropertyInfo &property) const { } } -RigidBody3D::RigidBody3D() : +RigidDynamicBody3D::RigidDynamicBody3D() : PhysicsBody3D(PhysicsServer3D::BODY_MODE_DYNAMIC) { PhysicsServer3D::get_singleton()->body_set_state_sync_callback(get_rid(), this, _body_state_changed_callback); } -RigidBody3D::~RigidBody3D() { +RigidDynamicBody3D::~RigidDynamicBody3D() { if (contact_monitor) { memdelete(contact_monitor); } } -void RigidBody3D::_reload_physics_characteristics() { +void RigidDynamicBody3D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, 0); PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, 1); diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index 8e6463f838..d29241cdce 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -129,8 +129,8 @@ private: bool is_sync_to_physics_enabled() const; }; -class RigidBody3D : public PhysicsBody3D { - GDCLASS(RigidBody3D, PhysicsBody3D); +class RigidDynamicBody3D : public PhysicsBody3D { + GDCLASS(RigidDynamicBody3D, PhysicsBody3D); public: enum Mode { @@ -191,7 +191,7 @@ protected: tagged = false; } }; - struct RigidBody3D_RemoveAction { + struct RigidDynamicBody3D_RemoveAction { RID rid; ObjectID body_id; ShapePair pair; @@ -291,15 +291,15 @@ public: virtual TypedArray get_configuration_warnings() const override; - RigidBody3D(); - ~RigidBody3D(); + RigidDynamicBody3D(); + ~RigidDynamicBody3D(); private: void _reload_physics_characteristics(); }; -VARIANT_ENUM_CAST(RigidBody3D::Mode); -VARIANT_ENUM_CAST(RigidBody3D::CenterOfMassMode); +VARIANT_ENUM_CAST(RigidDynamicBody3D::Mode); +VARIANT_ENUM_CAST(RigidDynamicBody3D::CenterOfMassMode); class KinematicCollision3D; diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp deleted file mode 100644 index 7eb189e890..0000000000 --- a/scene/3d/soft_body_3d.cpp +++ /dev/null @@ -1,816 +0,0 @@ -/*************************************************************************/ -/* soft_body_3d.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#include "soft_body_3d.h" - -#include "scene/3d/physics_body_3d.h" - -SoftBodyRenderingServerHandler::SoftBodyRenderingServerHandler() {} - -void SoftBodyRenderingServerHandler::prepare(RID p_mesh, int p_surface) { - clear(); - - ERR_FAIL_COND(!p_mesh.is_valid()); - - mesh = p_mesh; - surface = p_surface; - - RS::SurfaceData surface_data = RS::get_singleton()->mesh_get_surface(mesh, surface); - - uint32_t surface_offsets[RS::ARRAY_MAX]; - uint32_t vertex_stride; - uint32_t attrib_stride; - uint32_t skin_stride; - RS::get_singleton()->mesh_surface_make_offsets_from_format(surface_data.format, surface_data.vertex_count, surface_data.index_count, surface_offsets, vertex_stride, attrib_stride, skin_stride); - - buffer = surface_data.vertex_data; - stride = vertex_stride; - offset_vertices = surface_offsets[RS::ARRAY_VERTEX]; - offset_normal = surface_offsets[RS::ARRAY_NORMAL]; -} - -void SoftBodyRenderingServerHandler::clear() { - buffer.resize(0); - stride = 0; - offset_vertices = 0; - offset_normal = 0; - - surface = 0; - mesh = RID(); -} - -void SoftBodyRenderingServerHandler::open() { - write_buffer = buffer.ptrw(); -} - -void SoftBodyRenderingServerHandler::close() { - write_buffer = nullptr; -} - -void SoftBodyRenderingServerHandler::commit_changes() { - RS::get_singleton()->mesh_surface_update_vertex_region(mesh, surface, 0, buffer); -} - -void SoftBodyRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { - memcpy(&write_buffer[p_vertex_id * stride + offset_vertices], p_vector3, sizeof(float) * 3); -} - -void SoftBodyRenderingServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { - memcpy(&write_buffer[p_vertex_id * stride + offset_normal], p_vector3, sizeof(float) * 3); -} - -void SoftBodyRenderingServerHandler::set_aabb(const AABB &p_aabb) { - RS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb); -} - -SoftBody3D::PinnedPoint::PinnedPoint() { -} - -SoftBody3D::PinnedPoint::PinnedPoint(const PinnedPoint &obj_tocopy) { - point_index = obj_tocopy.point_index; - spatial_attachment_path = obj_tocopy.spatial_attachment_path; - spatial_attachment = obj_tocopy.spatial_attachment; - offset = obj_tocopy.offset; -} - -SoftBody3D::PinnedPoint &SoftBody3D::PinnedPoint::operator=(const PinnedPoint &obj) { - point_index = obj.point_index; - spatial_attachment_path = obj.spatial_attachment_path; - spatial_attachment = obj.spatial_attachment; - offset = obj.offset; - return *this; -} - -void SoftBody3D::_update_pickable() { - if (!is_inside_tree()) { - return; - } - bool pickable = ray_pickable && is_visible_in_tree(); - PhysicsServer3D::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); -} - -bool SoftBody3D::_set(const StringName &p_name, const Variant &p_value) { - String name = p_name; - String which = name.get_slicec('/', 0); - - if ("pinned_points" == which) { - return _set_property_pinned_points_indices(p_value); - - } else if ("attachments" == which) { - int idx = name.get_slicec('/', 1).to_int(); - String what = name.get_slicec('/', 2); - - return _set_property_pinned_points_attachment(idx, what, p_value); - } - - return false; -} - -bool SoftBody3D::_get(const StringName &p_name, Variant &r_ret) const { - String name = p_name; - String which = name.get_slicec('/', 0); - - if ("pinned_points" == which) { - Array arr_ret; - const int pinned_points_indices_size = pinned_points.size(); - const PinnedPoint *r = pinned_points.ptr(); - arr_ret.resize(pinned_points_indices_size); - - for (int i = 0; i < pinned_points_indices_size; ++i) { - arr_ret[i] = r[i].point_index; - } - - r_ret = arr_ret; - return true; - - } else if ("attachments" == which) { - int idx = name.get_slicec('/', 1).to_int(); - String what = name.get_slicec('/', 2); - - return _get_property_pinned_points(idx, what, r_ret); - } - - return false; -} - -void SoftBody3D::_get_property_list(List *p_list) const { - const int pinned_points_indices_size = pinned_points.size(); - - p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "pinned_points")); - - for (int i = 0; i < pinned_points_indices_size; ++i) { - p_list->push_back(PropertyInfo(Variant::INT, "attachments/" + itos(i) + "/point_index")); - p_list->push_back(PropertyInfo(Variant::NODE_PATH, "attachments/" + itos(i) + "/spatial_attachment_path")); - p_list->push_back(PropertyInfo(Variant::VECTOR3, "attachments/" + itos(i) + "/offset")); - } -} - -bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) { - const int p_indices_size = p_indices.size(); - - { // Remove the pined points on physics server that will be removed by resize - const PinnedPoint *r = pinned_points.ptr(); - if (p_indices_size < pinned_points.size()) { - for (int i = pinned_points.size() - 1; i >= p_indices_size; --i) { - pin_point(r[i].point_index, false); - } - } - } - - pinned_points.resize(p_indices_size); - - PinnedPoint *w = pinned_points.ptrw(); - int point_index; - for (int i = 0; i < p_indices_size; ++i) { - point_index = p_indices.get(i); - if (w[i].point_index != point_index) { - if (-1 != w[i].point_index) { - pin_point(w[i].point_index, false); - } - w[i].point_index = point_index; - pin_point(w[i].point_index, true); - } - } - return true; -} - -bool SoftBody3D::_set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value) { - if (pinned_points.size() <= p_item) { - return false; - } - - if ("spatial_attachment_path" == p_what) { - PinnedPoint *w = pinned_points.ptrw(); - pin_point(w[p_item].point_index, true, p_value); - _make_cache_dirty(); - } else if ("offset" == p_what) { - PinnedPoint *w = pinned_points.ptrw(); - w[p_item].offset = p_value; - } else { - return false; - } - - return true; -} - -bool SoftBody3D::_get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const { - if (pinned_points.size() <= p_item) { - return false; - } - const PinnedPoint *r = pinned_points.ptr(); - - if ("point_index" == p_what) { - r_ret = r[p_item].point_index; - } else if ("spatial_attachment_path" == p_what) { - r_ret = r[p_item].spatial_attachment_path; - } else if ("offset" == p_what) { - r_ret = r[p_item].offset; - } else { - return false; - } - - return true; -} - -void SoftBody3D::_softbody_changed() { - prepare_physics_server(); - _reset_points_offsets(); -#ifdef TOOLS_ENABLED - update_configuration_warnings(); -#endif -} - -void SoftBody3D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_WORLD: { - if (Engine::get_singleton()->is_editor_hint()) { - // I have no idea what this is supposed to do, it's really weird - // leaving for upcoming PK work on physics - //add_change_receptor(this); - } - - RID space = get_world_3d()->get_space(); - PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, space); - prepare_physics_server(); - } break; - - case NOTIFICATION_READY: { - if (!parent_collision_ignore.is_empty()) { - add_collision_exception_with(get_node(parent_collision_ignore)); - } - } break; - - case NOTIFICATION_TRANSFORM_CHANGED: { - if (Engine::get_singleton()->is_editor_hint()) { - _reset_points_offsets(); - return; - } - - PhysicsServer3D::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform()); - - set_notify_transform(false); - // Required to be top level with Transform at center of world in order to modify RenderingServer only to support custom Transform - set_as_top_level(true); - set_transform(Transform3D()); - set_notify_transform(true); - } break; - - case NOTIFICATION_VISIBILITY_CHANGED: { - _update_pickable(); - } break; - - case NOTIFICATION_EXIT_WORLD: { - PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, RID()); - } break; - - case NOTIFICATION_DISABLED: { - if (is_inside_tree() && (disable_mode == DISABLE_MODE_REMOVE)) { - prepare_physics_server(); - } - } break; - - case NOTIFICATION_ENABLED: { - if (is_inside_tree() && (disable_mode == DISABLE_MODE_REMOVE)) { - prepare_physics_server(); - } - } break; - -#ifdef TOOLS_ENABLED - case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { - if (Engine::get_singleton()->is_editor_hint()) { - update_configuration_warnings(); - } - } break; -#endif - } -} - -void SoftBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_physics_rid"), &SoftBody3D::get_physics_rid); - - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &SoftBody3D::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &SoftBody3D::get_collision_mask); - - ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &SoftBody3D::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &SoftBody3D::get_collision_layer); - - ClassDB::bind_method(D_METHOD("set_collision_mask_value", "layer_number", "value"), &SoftBody3D::set_collision_mask_value); - ClassDB::bind_method(D_METHOD("get_collision_mask_value", "layer_number"), &SoftBody3D::get_collision_mask_value); - - ClassDB::bind_method(D_METHOD("set_collision_layer_value", "layer_number", "value"), &SoftBody3D::set_collision_layer_value); - ClassDB::bind_method(D_METHOD("get_collision_layer_value", "layer_number"), &SoftBody3D::get_collision_layer_value); - - ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftBody3D::set_parent_collision_ignore); - ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftBody3D::get_parent_collision_ignore); - - ClassDB::bind_method(D_METHOD("set_disable_mode", "mode"), &SoftBody3D::set_disable_mode); - ClassDB::bind_method(D_METHOD("get_disable_mode"), &SoftBody3D::get_disable_mode); - - ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &SoftBody3D::get_collision_exceptions); - ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftBody3D::add_collision_exception_with); - ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftBody3D::remove_collision_exception_with); - - ClassDB::bind_method(D_METHOD("set_simulation_precision", "simulation_precision"), &SoftBody3D::set_simulation_precision); - ClassDB::bind_method(D_METHOD("get_simulation_precision"), &SoftBody3D::get_simulation_precision); - - ClassDB::bind_method(D_METHOD("set_total_mass", "mass"), &SoftBody3D::set_total_mass); - ClassDB::bind_method(D_METHOD("get_total_mass"), &SoftBody3D::get_total_mass); - - ClassDB::bind_method(D_METHOD("set_linear_stiffness", "linear_stiffness"), &SoftBody3D::set_linear_stiffness); - ClassDB::bind_method(D_METHOD("get_linear_stiffness"), &SoftBody3D::get_linear_stiffness); - - ClassDB::bind_method(D_METHOD("set_pressure_coefficient", "pressure_coefficient"), &SoftBody3D::set_pressure_coefficient); - ClassDB::bind_method(D_METHOD("get_pressure_coefficient"), &SoftBody3D::get_pressure_coefficient); - - ClassDB::bind_method(D_METHOD("set_damping_coefficient", "damping_coefficient"), &SoftBody3D::set_damping_coefficient); - ClassDB::bind_method(D_METHOD("get_damping_coefficient"), &SoftBody3D::get_damping_coefficient); - - ClassDB::bind_method(D_METHOD("set_drag_coefficient", "drag_coefficient"), &SoftBody3D::set_drag_coefficient); - ClassDB::bind_method(D_METHOD("get_drag_coefficient"), &SoftBody3D::get_drag_coefficient); - - ClassDB::bind_method(D_METHOD("get_point_transform", "point_index"), &SoftBody3D::get_point_transform); - - ClassDB::bind_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path"), &SoftBody3D::pin_point, DEFVAL(NodePath())); - ClassDB::bind_method(D_METHOD("is_point_pinned", "point_index"), &SoftBody3D::is_point_pinned); - - ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftBody3D::set_ray_pickable); - ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftBody3D::is_ray_pickable); - - ADD_GROUP("Collision", "collision_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); - - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "parent_collision_ignore", PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, "Parent collision object"), "set_parent_collision_ignore", "get_parent_collision_ignore"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "simulation_precision", PROPERTY_HINT_RANGE, "1,100,1"), "set_simulation_precision", "get_simulation_precision"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_mass", PROPERTY_HINT_RANGE, "0.01,10000,1"), "set_total_mass", "get_total_mass"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_stiffness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_linear_stiffness", "get_linear_stiffness"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure_coefficient"), "set_pressure_coefficient", "get_pressure_coefficient"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_damping_coefficient", "get_damping_coefficient"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "drag_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_coefficient", "get_drag_coefficient"); - - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable"); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,KeepActive"), "set_disable_mode", "get_disable_mode"); - - BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE); - BIND_ENUM_CONSTANT(DISABLE_MODE_KEEP_ACTIVE); -} - -TypedArray SoftBody3D::get_configuration_warnings() const { - TypedArray warnings = Node::get_configuration_warnings(); - - if (get_mesh().is_null()) { - warnings.push_back(TTR("This body will be ignored until you set a mesh.")); - } - - Transform3D t = get_transform(); - if ((ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) { - warnings.push_back(TTR("Size changes to SoftBody3D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); - } - - return warnings; -} - -void SoftBody3D::_update_physics_server() { - if (!simulation_started) { - return; - } - - _update_cache_pin_points_datas(); - // Submit bone attachment - const int pinned_points_indices_size = pinned_points.size(); - const PinnedPoint *r = pinned_points.ptr(); - for (int i = 0; i < pinned_points_indices_size; ++i) { - if (r[i].spatial_attachment) { - PhysicsServer3D::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, r[i].spatial_attachment->get_global_transform().xform(r[i].offset)); - } - } -} - -void SoftBody3D::_draw_soft_mesh() { - if (get_mesh().is_null()) { - return; - } - - if (!rendering_server_handler.is_ready()) { - rendering_server_handler.prepare(get_mesh()->get_rid(), 0); - - /// Necessary in order to render the mesh correctly (Soft body nodes are in global space) - simulation_started = true; - call_deferred(SNAME("set_as_top_level"), true); - call_deferred(SNAME("set_transform"), Transform3D()); - } - - _update_physics_server(); - - rendering_server_handler.open(); - PhysicsServer3D::get_singleton()->soft_body_update_rendering_server(physics_rid, &rendering_server_handler); - rendering_server_handler.close(); - - rendering_server_handler.commit_changes(); -} - -void SoftBody3D::prepare_physics_server() { -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint()) { - if (get_mesh().is_valid()) { - PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); - } else { - PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); - } - - return; - } -#endif - - if (get_mesh().is_valid() && (is_enabled() || (disable_mode != DISABLE_MODE_REMOVE))) { - become_mesh_owner(); - PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); - RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh)); - } else { - PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); - if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh))) { - RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &SoftBody3D::_draw_soft_mesh)); - } - } -} - -void SoftBody3D::become_mesh_owner() { - if (mesh.is_null()) { - return; - } - - if (!mesh_owner) { - mesh_owner = true; - - Vector> copy_materials; - copy_materials.append_array(surface_override_materials); - - ERR_FAIL_COND(!mesh->get_surface_count()); - - // Get current mesh array and create new mesh array with necessary flag for softbody - Array surface_arrays = mesh->surface_get_arrays(0); - Array surface_blend_arrays = mesh->surface_get_blend_shape_arrays(0); - Dictionary surface_lods = mesh->surface_get_lods(0); - uint32_t surface_format = mesh->surface_get_format(0); - - surface_format |= Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE; - - Ref soft_mesh; - soft_mesh.instantiate(); - soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_lods, surface_format); - soft_mesh->surface_set_material(0, mesh->surface_get_material(0)); - - set_mesh(soft_mesh); - - for (int i = copy_materials.size() - 1; 0 <= i; --i) { - set_surface_override_material(i, copy_materials[i]); - } - } -} - -void SoftBody3D::set_collision_mask(uint32_t p_mask) { - collision_mask = p_mask; - PhysicsServer3D::get_singleton()->soft_body_set_collision_mask(physics_rid, p_mask); -} - -uint32_t SoftBody3D::get_collision_mask() const { - return collision_mask; -} - -void SoftBody3D::set_collision_layer(uint32_t p_layer) { - collision_layer = p_layer; - PhysicsServer3D::get_singleton()->soft_body_set_collision_layer(physics_rid, p_layer); -} - -uint32_t SoftBody3D::get_collision_layer() const { - return collision_layer; -} - -void SoftBody3D::set_collision_layer_value(int p_layer_number, bool p_value) { - ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive."); - ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive."); - uint32_t collision_layer = get_collision_layer(); - if (p_value) { - collision_layer |= 1 << (p_layer_number - 1); - } else { - collision_layer &= ~(1 << (p_layer_number - 1)); - } - set_collision_layer(collision_layer); -} - -bool SoftBody3D::get_collision_layer_value(int p_layer_number) const { - ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); - ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); - return get_collision_layer() & (1 << (p_layer_number - 1)); -} - -void SoftBody3D::set_collision_mask_value(int p_layer_number, bool p_value) { - ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive."); - ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive."); - uint32_t mask = get_collision_mask(); - if (p_value) { - mask |= 1 << (p_layer_number - 1); - } else { - mask &= ~(1 << (p_layer_number - 1)); - } - set_collision_mask(mask); -} - -bool SoftBody3D::get_collision_mask_value(int p_layer_number) const { - ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); - ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); - return get_collision_mask() & (1 << (p_layer_number - 1)); -} - -void SoftBody3D::set_disable_mode(DisableMode p_mode) { - if (disable_mode == p_mode) { - return; - } - - bool inside_tree = is_inside_tree(); - - if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) { - prepare_physics_server(); - } - - disable_mode = p_mode; - - if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) { - prepare_physics_server(); - } -} - -SoftBody3D::DisableMode SoftBody3D::get_disable_mode() const { - return disable_mode; -} - -void SoftBody3D::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { - parent_collision_ignore = p_parent_collision_ignore; -} - -const NodePath &SoftBody3D::get_parent_collision_ignore() const { - return parent_collision_ignore; -} - -void SoftBody3D::set_pinned_points_indices(Vector p_pinned_points_indices) { - pinned_points = p_pinned_points_indices; - for (int i = pinned_points.size() - 1; 0 <= i; --i) { - pin_point(p_pinned_points_indices[i].point_index, true); - } -} - -Vector SoftBody3D::get_pinned_points_indices() { - return pinned_points; -} - -Array SoftBody3D::get_collision_exceptions() { - List exceptions; - PhysicsServer3D::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); - Array ret; - for (const RID &body : exceptions) { - ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); - Object *obj = ObjectDB::get_instance(instance_id); - PhysicsBody3D *physics_body = Object::cast_to(obj); - ret.append(physics_body); - } - return ret; -} - -void SoftBody3D::add_collision_exception_with(Node *p_node) { - ERR_FAIL_NULL(p_node); - CollisionObject3D *collision_object = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); - PhysicsServer3D::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); -} - -void SoftBody3D::remove_collision_exception_with(Node *p_node) { - ERR_FAIL_NULL(p_node); - CollisionObject3D *collision_object = Object::cast_to(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); - PhysicsServer3D::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); -} - -int SoftBody3D::get_simulation_precision() { - return PhysicsServer3D::get_singleton()->soft_body_get_simulation_precision(physics_rid); -} - -void SoftBody3D::set_simulation_precision(int p_simulation_precision) { - PhysicsServer3D::get_singleton()->soft_body_set_simulation_precision(physics_rid, p_simulation_precision); -} - -real_t SoftBody3D::get_total_mass() { - return PhysicsServer3D::get_singleton()->soft_body_get_total_mass(physics_rid); -} - -void SoftBody3D::set_total_mass(real_t p_total_mass) { - PhysicsServer3D::get_singleton()->soft_body_set_total_mass(physics_rid, p_total_mass); -} - -void SoftBody3D::set_linear_stiffness(real_t p_linear_stiffness) { - PhysicsServer3D::get_singleton()->soft_body_set_linear_stiffness(physics_rid, p_linear_stiffness); -} - -real_t SoftBody3D::get_linear_stiffness() { - return PhysicsServer3D::get_singleton()->soft_body_get_linear_stiffness(physics_rid); -} - -real_t SoftBody3D::get_pressure_coefficient() { - return PhysicsServer3D::get_singleton()->soft_body_get_pressure_coefficient(physics_rid); -} - -void SoftBody3D::set_pressure_coefficient(real_t p_pressure_coefficient) { - PhysicsServer3D::get_singleton()->soft_body_set_pressure_coefficient(physics_rid, p_pressure_coefficient); -} - -real_t SoftBody3D::get_damping_coefficient() { - return PhysicsServer3D::get_singleton()->soft_body_get_damping_coefficient(physics_rid); -} - -void SoftBody3D::set_damping_coefficient(real_t p_damping_coefficient) { - PhysicsServer3D::get_singleton()->soft_body_set_damping_coefficient(physics_rid, p_damping_coefficient); -} - -real_t SoftBody3D::get_drag_coefficient() { - return PhysicsServer3D::get_singleton()->soft_body_get_drag_coefficient(physics_rid); -} - -void SoftBody3D::set_drag_coefficient(real_t p_drag_coefficient) { - PhysicsServer3D::get_singleton()->soft_body_set_drag_coefficient(physics_rid, p_drag_coefficient); -} - -Vector3 SoftBody3D::get_point_transform(int p_point_index) { - return PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index); -} - -void SoftBody3D::pin_point_toggle(int p_point_index) { - pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index))); -} - -void SoftBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) { - _pin_point_on_physics_server(p_point_index, pin); - if (pin) { - _add_pinned_point(p_point_index, p_spatial_attachment_path); - } else { - _remove_pinned_point(p_point_index); - } -} - -bool SoftBody3D::is_point_pinned(int p_point_index) const { - return -1 != _has_pinned_point(p_point_index); -} - -void SoftBody3D::set_ray_pickable(bool p_ray_pickable) { - ray_pickable = p_ray_pickable; - _update_pickable(); -} - -bool SoftBody3D::is_ray_pickable() const { - return ray_pickable; -} - -SoftBody3D::SoftBody3D() : - physics_rid(PhysicsServer3D::get_singleton()->soft_body_create()) { - PhysicsServer3D::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id()); -} - -SoftBody3D::~SoftBody3D() { - PhysicsServer3D::get_singleton()->free(physics_rid); -} - -void SoftBody3D::reset_softbody_pin() { - PhysicsServer3D::get_singleton()->soft_body_remove_all_pinned_points(physics_rid); - const PinnedPoint *pps = pinned_points.ptr(); - for (int i = pinned_points.size() - 1; 0 < i; --i) { - PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, pps[i].point_index, true); - } -} - -void SoftBody3D::_make_cache_dirty() { - pinned_points_cache_dirty = true; -} - -void SoftBody3D::_update_cache_pin_points_datas() { - if (!pinned_points_cache_dirty) { - return; - } - - pinned_points_cache_dirty = false; - - PinnedPoint *w = pinned_points.ptrw(); - for (int i = pinned_points.size() - 1; 0 <= i; --i) { - if (!w[i].spatial_attachment_path.is_empty()) { - w[i].spatial_attachment = Object::cast_to(get_node(w[i].spatial_attachment_path)); - } - if (!w[i].spatial_attachment) { - ERR_PRINT("Node3D node not defined in the pinned point, this is undefined behavior for SoftBody3D!"); - } - } -} - -void SoftBody3D::_pin_point_on_physics_server(int p_point_index, bool pin) { - PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin); -} - -void SoftBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) { - SoftBody3D::PinnedPoint *pinned_point; - if (-1 == _get_pinned_point(p_point_index, pinned_point)) { - // Create new - PinnedPoint pp; - pp.point_index = p_point_index; - pp.spatial_attachment_path = p_spatial_attachment_path; - - if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { - pp.spatial_attachment = Object::cast_to(get_node(p_spatial_attachment_path)); - pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index)); - } - - pinned_points.push_back(pp); - - } else { - pinned_point->point_index = p_point_index; - pinned_point->spatial_attachment_path = p_spatial_attachment_path; - - if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { - pinned_point->spatial_attachment = Object::cast_to(get_node(p_spatial_attachment_path)); - pinned_point->offset = (pinned_point->spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pinned_point->point_index)); - } - } -} - -void SoftBody3D::_reset_points_offsets() { - if (!Engine::get_singleton()->is_editor_hint()) { - return; - } - - const PinnedPoint *r = pinned_points.ptr(); - PinnedPoint *w = pinned_points.ptrw(); - for (int i = pinned_points.size() - 1; 0 <= i; --i) { - if (!r[i].spatial_attachment) { - if (!r[i].spatial_attachment_path.is_empty() && has_node(r[i].spatial_attachment_path)) { - w[i].spatial_attachment = Object::cast_to(get_node(r[i].spatial_attachment_path)); - } - } - - if (!r[i].spatial_attachment) { - continue; - } - - w[i].offset = (r[i].spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index)); - } -} - -void SoftBody3D::_remove_pinned_point(int p_point_index) { - const int id(_has_pinned_point(p_point_index)); - if (-1 != id) { - pinned_points.remove(id); - } -} - -int SoftBody3D::_get_pinned_point(int p_point_index, SoftBody3D::PinnedPoint *&r_point) const { - const int id = _has_pinned_point(p_point_index); - if (-1 == id) { - r_point = nullptr; - return -1; - } else { - r_point = const_cast(&pinned_points.ptr()[id]); - return id; - } -} - -int SoftBody3D::_has_pinned_point(int p_point_index) const { - const PinnedPoint *r = pinned_points.ptr(); - for (int i = pinned_points.size() - 1; 0 <= i; --i) { - if (p_point_index == r[i].point_index) { - return i; - } - } - return -1; -} diff --git a/scene/3d/soft_body_3d.h b/scene/3d/soft_body_3d.h deleted file mode 100644 index 46b185a32c..0000000000 --- a/scene/3d/soft_body_3d.h +++ /dev/null @@ -1,207 +0,0 @@ -/*************************************************************************/ -/* soft_body_3d.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef SOFT_PHYSICS_BODY_H -#define SOFT_PHYSICS_BODY_H - -#include "scene/3d/mesh_instance_3d.h" -#include "servers/physics_server_3d.h" - -class SoftBody3D; - -class SoftBodyRenderingServerHandler : public RenderingServerHandler { - friend class SoftBody3D; - - RID mesh; - int surface = 0; - Vector buffer; - uint32_t stride = 0; - uint32_t offset_vertices = 0; - uint32_t offset_normal = 0; - - uint8_t *write_buffer = nullptr; - -private: - SoftBodyRenderingServerHandler(); - bool is_ready() { return mesh.is_valid(); } - void prepare(RID p_mesh_rid, int p_surface); - void clear(); - void open(); - void close(); - void commit_changes(); - -public: - void set_vertex(int p_vertex_id, const void *p_vector3) override; - void set_normal(int p_vertex_id, const void *p_vector3) override; - void set_aabb(const AABB &p_aabb) override; -}; - -class SoftBody3D : public MeshInstance3D { - GDCLASS(SoftBody3D, MeshInstance3D); - -public: - enum DisableMode { - DISABLE_MODE_REMOVE, - DISABLE_MODE_KEEP_ACTIVE, - }; - - struct PinnedPoint { - int point_index = -1; - NodePath spatial_attachment_path; - Node3D *spatial_attachment = nullptr; // Cache - Vector3 offset; - - PinnedPoint(); - PinnedPoint(const PinnedPoint &obj_tocopy); - PinnedPoint &operator=(const PinnedPoint &obj); - }; - -private: - SoftBodyRenderingServerHandler rendering_server_handler; - - RID physics_rid; - - DisableMode disable_mode = DISABLE_MODE_REMOVE; - - bool mesh_owner = false; - uint32_t collision_mask = 1; - uint32_t collision_layer = 1; - NodePath parent_collision_ignore; - Vector pinned_points; - bool simulation_started = false; - bool pinned_points_cache_dirty = true; - - Ref debug_mesh_cache; - class MeshInstance3D *debug_mesh = nullptr; - - bool capture_input_on_drag = false; - bool ray_pickable = true; - - void _update_pickable(); - - void _softbody_changed(); - -protected: - bool _set(const StringName &p_name, const Variant &p_value); - bool _get(const StringName &p_name, Variant &r_ret) const; - void _get_property_list(List *p_list) const; - - bool _set_property_pinned_points_indices(const Array &p_indices); - bool _set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value); - bool _get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const; - - void _notification(int p_what); - static void _bind_methods(); - - TypedArray get_configuration_warnings() const override; - -protected: - void _update_physics_server(); - void _draw_soft_mesh(); - -public: - void prepare_physics_server(); - void become_mesh_owner(); - - RID get_physics_rid() const { return physics_rid; } - - void set_collision_mask(uint32_t p_mask); - uint32_t get_collision_mask() const; - - void set_collision_layer(uint32_t p_layer); - uint32_t get_collision_layer() const; - - void set_collision_layer_value(int p_layer_number, bool p_value); - bool get_collision_layer_value(int p_layer_number) const; - - void set_collision_mask_value(int p_layer_number, bool p_value); - bool get_collision_mask_value(int p_layer_number) const; - - void set_disable_mode(DisableMode p_mode); - DisableMode get_disable_mode() const; - - void set_parent_collision_ignore(const NodePath &p_parent_collision_ignore); - const NodePath &get_parent_collision_ignore() const; - - void set_pinned_points_indices(Vector p_pinned_points_indices); - Vector get_pinned_points_indices(); - - void set_simulation_precision(int p_simulation_precision); - int get_simulation_precision(); - - void set_total_mass(real_t p_total_mass); - real_t get_total_mass(); - - void set_linear_stiffness(real_t p_linear_stiffness); - real_t get_linear_stiffness(); - - void set_pressure_coefficient(real_t p_pressure_coefficient); - real_t get_pressure_coefficient(); - - void set_damping_coefficient(real_t p_damping_coefficient); - real_t get_damping_coefficient(); - - void set_drag_coefficient(real_t p_drag_coefficient); - real_t get_drag_coefficient(); - - Array get_collision_exceptions(); - void add_collision_exception_with(Node *p_node); - void remove_collision_exception_with(Node *p_node); - - Vector3 get_point_transform(int p_point_index); - - void pin_point_toggle(int p_point_index); - void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath()); - bool is_point_pinned(int p_point_index) const; - - void set_ray_pickable(bool p_ray_pickable); - bool is_ray_pickable() const; - - SoftBody3D(); - ~SoftBody3D(); - -private: - void reset_softbody_pin(); - - void _make_cache_dirty(); - void _update_cache_pin_points_datas(); - - void _pin_point_on_physics_server(int p_point_index, bool pin); - void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path); - void _reset_points_offsets(); - - void _remove_pinned_point(int p_point_index); - int _get_pinned_point(int p_point_index, PinnedPoint *&r_point) const; - int _has_pinned_point(int p_point_index) const; -}; - -VARIANT_ENUM_CAST(SoftBody3D::DisableMode); - -#endif // SOFT_PHYSICS_BODY_H diff --git a/scene/3d/soft_dynamic_body_3d.cpp b/scene/3d/soft_dynamic_body_3d.cpp new file mode 100644 index 0000000000..a886c61263 --- /dev/null +++ b/scene/3d/soft_dynamic_body_3d.cpp @@ -0,0 +1,800 @@ +/*************************************************************************/ +/* soft_dynamic_body_3d.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "soft_dynamic_body_3d.h" + +#include "scene/3d/physics_body_3d.h" + +SoftDynamicBodyRenderingServerHandler::SoftDynamicBodyRenderingServerHandler() {} + +void SoftDynamicBodyRenderingServerHandler::prepare(RID p_mesh, int p_surface) { + clear(); + + ERR_FAIL_COND(!p_mesh.is_valid()); + + mesh = p_mesh; + surface = p_surface; + + RS::SurfaceData surface_data = RS::get_singleton()->mesh_get_surface(mesh, surface); + + uint32_t surface_offsets[RS::ARRAY_MAX]; + uint32_t vertex_stride; + uint32_t attrib_stride; + uint32_t skin_stride; + RS::get_singleton()->mesh_surface_make_offsets_from_format(surface_data.format, surface_data.vertex_count, surface_data.index_count, surface_offsets, vertex_stride, attrib_stride, skin_stride); + + buffer = surface_data.vertex_data; + stride = vertex_stride; + offset_vertices = surface_offsets[RS::ARRAY_VERTEX]; + offset_normal = surface_offsets[RS::ARRAY_NORMAL]; +} + +void SoftDynamicBodyRenderingServerHandler::clear() { + buffer.resize(0); + stride = 0; + offset_vertices = 0; + offset_normal = 0; + + surface = 0; + mesh = RID(); +} + +void SoftDynamicBodyRenderingServerHandler::open() { + write_buffer = buffer.ptrw(); +} + +void SoftDynamicBodyRenderingServerHandler::close() { + write_buffer = nullptr; +} + +void SoftDynamicBodyRenderingServerHandler::commit_changes() { + RS::get_singleton()->mesh_surface_update_vertex_region(mesh, surface, 0, buffer); +} + +void SoftDynamicBodyRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { + memcpy(&write_buffer[p_vertex_id * stride + offset_vertices], p_vector3, sizeof(float) * 3); +} + +void SoftDynamicBodyRenderingServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { + memcpy(&write_buffer[p_vertex_id * stride + offset_normal], p_vector3, sizeof(float) * 3); +} + +void SoftDynamicBodyRenderingServerHandler::set_aabb(const AABB &p_aabb) { + RS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb); +} + +SoftDynamicBody3D::PinnedPoint::PinnedPoint() { +} + +SoftDynamicBody3D::PinnedPoint::PinnedPoint(const PinnedPoint &obj_tocopy) { + point_index = obj_tocopy.point_index; + spatial_attachment_path = obj_tocopy.spatial_attachment_path; + spatial_attachment = obj_tocopy.spatial_attachment; + offset = obj_tocopy.offset; +} + +SoftDynamicBody3D::PinnedPoint &SoftDynamicBody3D::PinnedPoint::operator=(const PinnedPoint &obj) { + point_index = obj.point_index; + spatial_attachment_path = obj.spatial_attachment_path; + spatial_attachment = obj.spatial_attachment; + offset = obj.offset; + return *this; +} + +void SoftDynamicBody3D::_update_pickable() { + if (!is_inside_tree()) { + return; + } + bool pickable = ray_pickable && is_visible_in_tree(); + PhysicsServer3D::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); +} + +bool SoftDynamicBody3D::_set(const StringName &p_name, const Variant &p_value) { + String name = p_name; + String which = name.get_slicec('/', 0); + + if ("pinned_points" == which) { + return _set_property_pinned_points_indices(p_value); + + } else if ("attachments" == which) { + int idx = name.get_slicec('/', 1).to_int(); + String what = name.get_slicec('/', 2); + + return _set_property_pinned_points_attachment(idx, what, p_value); + } + + return false; +} + +bool SoftDynamicBody3D::_get(const StringName &p_name, Variant &r_ret) const { + String name = p_name; + String which = name.get_slicec('/', 0); + + if ("pinned_points" == which) { + Array arr_ret; + const int pinned_points_indices_size = pinned_points.size(); + const PinnedPoint *r = pinned_points.ptr(); + arr_ret.resize(pinned_points_indices_size); + + for (int i = 0; i < pinned_points_indices_size; ++i) { + arr_ret[i] = r[i].point_index; + } + + r_ret = arr_ret; + return true; + + } else if ("attachments" == which) { + int idx = name.get_slicec('/', 1).to_int(); + String what = name.get_slicec('/', 2); + + return _get_property_pinned_points(idx, what, r_ret); + } + + return false; +} + +void SoftDynamicBody3D::_get_property_list(List *p_list) const { + const int pinned_points_indices_size = pinned_points.size(); + + p_list->push_back(PropertyInfo(Variant::PACKED_INT32_ARRAY, "pinned_points")); + + for (int i = 0; i < pinned_points_indices_size; ++i) { + p_list->push_back(PropertyInfo(Variant::INT, "attachments/" + itos(i) + "/point_index")); + p_list->push_back(PropertyInfo(Variant::NODE_PATH, "attachments/" + itos(i) + "/spatial_attachment_path")); + p_list->push_back(PropertyInfo(Variant::VECTOR3, "attachments/" + itos(i) + "/offset")); + } +} + +bool SoftDynamicBody3D::_set_property_pinned_points_indices(const Array &p_indices) { + const int p_indices_size = p_indices.size(); + + { // Remove the pined points on physics server that will be removed by resize + const PinnedPoint *r = pinned_points.ptr(); + if (p_indices_size < pinned_points.size()) { + for (int i = pinned_points.size() - 1; i >= p_indices_size; --i) { + pin_point(r[i].point_index, false); + } + } + } + + pinned_points.resize(p_indices_size); + + PinnedPoint *w = pinned_points.ptrw(); + int point_index; + for (int i = 0; i < p_indices_size; ++i) { + point_index = p_indices.get(i); + if (w[i].point_index != point_index) { + if (-1 != w[i].point_index) { + pin_point(w[i].point_index, false); + } + w[i].point_index = point_index; + pin_point(w[i].point_index, true); + } + } + return true; +} + +bool SoftDynamicBody3D::_set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value) { + if (pinned_points.size() <= p_item) { + return false; + } + + if ("spatial_attachment_path" == p_what) { + PinnedPoint *w = pinned_points.ptrw(); + pin_point(w[p_item].point_index, true, p_value); + _make_cache_dirty(); + } else if ("offset" == p_what) { + PinnedPoint *w = pinned_points.ptrw(); + w[p_item].offset = p_value; + } else { + return false; + } + + return true; +} + +bool SoftDynamicBody3D::_get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const { + if (pinned_points.size() <= p_item) { + return false; + } + const PinnedPoint *r = pinned_points.ptr(); + + if ("point_index" == p_what) { + r_ret = r[p_item].point_index; + } else if ("spatial_attachment_path" == p_what) { + r_ret = r[p_item].spatial_attachment_path; + } else if ("offset" == p_what) { + r_ret = r[p_item].offset; + } else { + return false; + } + + return true; +} + +void SoftDynamicBody3D::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_WORLD: { + if (Engine::get_singleton()->is_editor_hint()) { + // I have no idea what this is supposed to do, it's really weird + // leaving for upcoming PK work on physics + //add_change_receptor(this); + } + + RID space = get_world_3d()->get_space(); + PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, space); + prepare_physics_server(); + } break; + + case NOTIFICATION_READY: { + if (!parent_collision_ignore.is_empty()) { + add_collision_exception_with(get_node(parent_collision_ignore)); + } + } break; + + case NOTIFICATION_TRANSFORM_CHANGED: { + if (Engine::get_singleton()->is_editor_hint()) { + _reset_points_offsets(); + return; + } + + PhysicsServer3D::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform()); + + set_notify_transform(false); + // Required to be top level with Transform at center of world in order to modify RenderingServer only to support custom Transform + set_as_top_level(true); + set_transform(Transform3D()); + set_notify_transform(true); + } break; + + case NOTIFICATION_VISIBILITY_CHANGED: { + _update_pickable(); + } break; + + case NOTIFICATION_EXIT_WORLD: { + PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, RID()); + } break; + + case NOTIFICATION_DISABLED: { + if (is_inside_tree() && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } + } break; + + case NOTIFICATION_ENABLED: { + if (is_inside_tree() && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } + } break; + +#ifdef TOOLS_ENABLED + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { + if (Engine::get_singleton()->is_editor_hint()) { + update_configuration_warnings(); + } + } break; +#endif + } +} + +void SoftDynamicBody3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("get_physics_rid"), &SoftDynamicBody3D::get_physics_rid); + + ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &SoftDynamicBody3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &SoftDynamicBody3D::get_collision_mask); + + ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &SoftDynamicBody3D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &SoftDynamicBody3D::get_collision_layer); + + ClassDB::bind_method(D_METHOD("set_collision_mask_value", "layer_number", "value"), &SoftDynamicBody3D::set_collision_mask_value); + ClassDB::bind_method(D_METHOD("get_collision_mask_value", "layer_number"), &SoftDynamicBody3D::get_collision_mask_value); + + ClassDB::bind_method(D_METHOD("set_collision_layer_value", "layer_number", "value"), &SoftDynamicBody3D::set_collision_layer_value); + ClassDB::bind_method(D_METHOD("get_collision_layer_value", "layer_number"), &SoftDynamicBody3D::get_collision_layer_value); + + ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftDynamicBody3D::set_parent_collision_ignore); + ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftDynamicBody3D::get_parent_collision_ignore); + + ClassDB::bind_method(D_METHOD("set_disable_mode", "mode"), &SoftDynamicBody3D::set_disable_mode); + ClassDB::bind_method(D_METHOD("get_disable_mode"), &SoftDynamicBody3D::get_disable_mode); + + ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &SoftDynamicBody3D::get_collision_exceptions); + ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftDynamicBody3D::add_collision_exception_with); + ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftDynamicBody3D::remove_collision_exception_with); + + ClassDB::bind_method(D_METHOD("set_simulation_precision", "simulation_precision"), &SoftDynamicBody3D::set_simulation_precision); + ClassDB::bind_method(D_METHOD("get_simulation_precision"), &SoftDynamicBody3D::get_simulation_precision); + + ClassDB::bind_method(D_METHOD("set_total_mass", "mass"), &SoftDynamicBody3D::set_total_mass); + ClassDB::bind_method(D_METHOD("get_total_mass"), &SoftDynamicBody3D::get_total_mass); + + ClassDB::bind_method(D_METHOD("set_linear_stiffness", "linear_stiffness"), &SoftDynamicBody3D::set_linear_stiffness); + ClassDB::bind_method(D_METHOD("get_linear_stiffness"), &SoftDynamicBody3D::get_linear_stiffness); + + ClassDB::bind_method(D_METHOD("set_pressure_coefficient", "pressure_coefficient"), &SoftDynamicBody3D::set_pressure_coefficient); + ClassDB::bind_method(D_METHOD("get_pressure_coefficient"), &SoftDynamicBody3D::get_pressure_coefficient); + + ClassDB::bind_method(D_METHOD("set_damping_coefficient", "damping_coefficient"), &SoftDynamicBody3D::set_damping_coefficient); + ClassDB::bind_method(D_METHOD("get_damping_coefficient"), &SoftDynamicBody3D::get_damping_coefficient); + + ClassDB::bind_method(D_METHOD("set_drag_coefficient", "drag_coefficient"), &SoftDynamicBody3D::set_drag_coefficient); + ClassDB::bind_method(D_METHOD("get_drag_coefficient"), &SoftDynamicBody3D::get_drag_coefficient); + + ClassDB::bind_method(D_METHOD("get_point_transform", "point_index"), &SoftDynamicBody3D::get_point_transform); + + ClassDB::bind_method(D_METHOD("set_point_pinned", "point_index", "pinned", "attachment_path"), &SoftDynamicBody3D::pin_point, DEFVAL(NodePath())); + ClassDB::bind_method(D_METHOD("is_point_pinned", "point_index"), &SoftDynamicBody3D::is_point_pinned); + + ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &SoftDynamicBody3D::set_ray_pickable); + ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftDynamicBody3D::is_ray_pickable); + + ADD_GROUP("Collision", "collision_"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); + + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "parent_collision_ignore", PROPERTY_HINT_PROPERTY_OF_VARIANT_TYPE, "Parent collision object"), "set_parent_collision_ignore", "get_parent_collision_ignore"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "simulation_precision", PROPERTY_HINT_RANGE, "1,100,1"), "set_simulation_precision", "get_simulation_precision"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "total_mass", PROPERTY_HINT_RANGE, "0.01,10000,1"), "set_total_mass", "get_total_mass"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_stiffness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_linear_stiffness", "get_linear_stiffness"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "pressure_coefficient"), "set_pressure_coefficient", "get_pressure_coefficient"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_damping_coefficient", "get_damping_coefficient"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "drag_coefficient", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_coefficient", "get_drag_coefficient"); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable"); + + ADD_PROPERTY(PropertyInfo(Variant::INT, "disable_mode", PROPERTY_HINT_ENUM, "Remove,KeepActive"), "set_disable_mode", "get_disable_mode"); + + BIND_ENUM_CONSTANT(DISABLE_MODE_REMOVE); + BIND_ENUM_CONSTANT(DISABLE_MODE_KEEP_ACTIVE); +} + +TypedArray SoftDynamicBody3D::get_configuration_warnings() const { + TypedArray warnings = Node::get_configuration_warnings(); + + if (get_mesh().is_null()) { + warnings.push_back(TTR("This body will be ignored until you set a mesh.")); + } + + Transform3D t = get_transform(); + if ((ABS(t.basis.get_axis(0).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(1).length() - 1.0) > 0.05 || ABS(t.basis.get_axis(2).length() - 1.0) > 0.05)) { + warnings.push_back(TTR("Size changes to SoftDynamicBody3D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); + } + + return warnings; +} + +void SoftDynamicBody3D::_update_physics_server() { + if (!simulation_started) { + return; + } + + _update_cache_pin_points_datas(); + // Submit bone attachment + const int pinned_points_indices_size = pinned_points.size(); + const PinnedPoint *r = pinned_points.ptr(); + for (int i = 0; i < pinned_points_indices_size; ++i) { + if (r[i].spatial_attachment) { + PhysicsServer3D::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, r[i].spatial_attachment->get_global_transform().xform(r[i].offset)); + } + } +} + +void SoftDynamicBody3D::_draw_soft_mesh() { + if (get_mesh().is_null()) { + return; + } + + if (!rendering_server_handler.is_ready()) { + rendering_server_handler.prepare(get_mesh()->get_rid(), 0); + + /// Necessary in order to render the mesh correctly (Soft body nodes are in global space) + simulation_started = true; + call_deferred(SNAME("set_as_top_level"), true); + call_deferred(SNAME("set_transform"), Transform3D()); + } + + _update_physics_server(); + + rendering_server_handler.open(); + PhysicsServer3D::get_singleton()->soft_body_update_rendering_server(physics_rid, &rendering_server_handler); + rendering_server_handler.close(); + + rendering_server_handler.commit_changes(); +} + +void SoftDynamicBody3D::prepare_physics_server() { +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + if (get_mesh().is_valid()) { + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); + } else { + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); + } + + return; + } +#endif + + if (get_mesh().is_valid() && (is_enabled() || (disable_mode != DISABLE_MODE_REMOVE))) { + become_mesh_owner(); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); + RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &SoftDynamicBody3D::_draw_soft_mesh)); + } else { + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); + if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &SoftDynamicBody3D::_draw_soft_mesh))) { + RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &SoftDynamicBody3D::_draw_soft_mesh)); + } + } +} + +void SoftDynamicBody3D::become_mesh_owner() { + if (mesh.is_null()) { + return; + } + + if (!mesh_owner) { + mesh_owner = true; + + Vector> copy_materials; + copy_materials.append_array(surface_override_materials); + + ERR_FAIL_COND(!mesh->get_surface_count()); + + // Get current mesh array and create new mesh array with necessary flag for SoftDynamicBody + Array surface_arrays = mesh->surface_get_arrays(0); + Array surface_blend_arrays = mesh->surface_get_blend_shape_arrays(0); + Dictionary surface_lods = mesh->surface_get_lods(0); + uint32_t surface_format = mesh->surface_get_format(0); + + surface_format |= Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE; + + Ref soft_mesh; + soft_mesh.instantiate(); + soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_lods, surface_format); + soft_mesh->surface_set_material(0, mesh->surface_get_material(0)); + + set_mesh(soft_mesh); + + for (int i = copy_materials.size() - 1; 0 <= i; --i) { + set_surface_override_material(i, copy_materials[i]); + } + } +} + +void SoftDynamicBody3D::set_collision_mask(uint32_t p_mask) { + collision_mask = p_mask; + PhysicsServer3D::get_singleton()->soft_body_set_collision_mask(physics_rid, p_mask); +} + +uint32_t SoftDynamicBody3D::get_collision_mask() const { + return collision_mask; +} + +void SoftDynamicBody3D::set_collision_layer(uint32_t p_layer) { + collision_layer = p_layer; + PhysicsServer3D::get_singleton()->soft_body_set_collision_layer(physics_rid, p_layer); +} + +uint32_t SoftDynamicBody3D::get_collision_layer() const { + return collision_layer; +} + +void SoftDynamicBody3D::set_collision_layer_value(int p_layer_number, bool p_value) { + ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive."); + uint32_t collision_layer = get_collision_layer(); + if (p_value) { + collision_layer |= 1 << (p_layer_number - 1); + } else { + collision_layer &= ~(1 << (p_layer_number - 1)); + } + set_collision_layer(collision_layer); +} + +bool SoftDynamicBody3D::get_collision_layer_value(int p_layer_number) const { + ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); + return get_collision_layer() & (1 << (p_layer_number - 1)); +} + +void SoftDynamicBody3D::set_collision_mask_value(int p_layer_number, bool p_value) { + ERR_FAIL_COND_MSG(p_layer_number < 1, "Collision layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_MSG(p_layer_number > 32, "Collision layer number must be between 1 and 32 inclusive."); + uint32_t mask = get_collision_mask(); + if (p_value) { + mask |= 1 << (p_layer_number - 1); + } else { + mask &= ~(1 << (p_layer_number - 1)); + } + set_collision_mask(mask); +} + +bool SoftDynamicBody3D::get_collision_mask_value(int p_layer_number) const { + ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Collision layer number must be between 1 and 32 inclusive."); + ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Collision layer number must be between 1 and 32 inclusive."); + return get_collision_mask() & (1 << (p_layer_number - 1)); +} + +void SoftDynamicBody3D::set_disable_mode(DisableMode p_mode) { + if (disable_mode == p_mode) { + return; + } + + bool inside_tree = is_inside_tree(); + + if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } + + disable_mode = p_mode; + + if (inside_tree && (disable_mode == DISABLE_MODE_REMOVE)) { + prepare_physics_server(); + } +} + +SoftDynamicBody3D::DisableMode SoftDynamicBody3D::get_disable_mode() const { + return disable_mode; +} + +void SoftDynamicBody3D::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { + parent_collision_ignore = p_parent_collision_ignore; +} + +const NodePath &SoftDynamicBody3D::get_parent_collision_ignore() const { + return parent_collision_ignore; +} + +void SoftDynamicBody3D::set_pinned_points_indices(Vector p_pinned_points_indices) { + pinned_points = p_pinned_points_indices; + for (int i = pinned_points.size() - 1; 0 <= i; --i) { + pin_point(p_pinned_points_indices[i].point_index, true); + } +} + +Vector SoftDynamicBody3D::get_pinned_points_indices() { + return pinned_points; +} + +Array SoftDynamicBody3D::get_collision_exceptions() { + List exceptions; + PhysicsServer3D::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); + Array ret; + for (const RID &body : exceptions) { + ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); + Object *obj = ObjectDB::get_instance(instance_id); + PhysicsBody3D *physics_body = Object::cast_to(obj); + ret.append(physics_body); + } + return ret; +} + +void SoftDynamicBody3D::add_collision_exception_with(Node *p_node) { + ERR_FAIL_NULL(p_node); + CollisionObject3D *collision_object = Object::cast_to(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); +} + +void SoftDynamicBody3D::remove_collision_exception_with(Node *p_node) { + ERR_FAIL_NULL(p_node); + CollisionObject3D *collision_object = Object::cast_to(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); +} + +int SoftDynamicBody3D::get_simulation_precision() { + return PhysicsServer3D::get_singleton()->soft_body_get_simulation_precision(physics_rid); +} + +void SoftDynamicBody3D::set_simulation_precision(int p_simulation_precision) { + PhysicsServer3D::get_singleton()->soft_body_set_simulation_precision(physics_rid, p_simulation_precision); +} + +real_t SoftDynamicBody3D::get_total_mass() { + return PhysicsServer3D::get_singleton()->soft_body_get_total_mass(physics_rid); +} + +void SoftDynamicBody3D::set_total_mass(real_t p_total_mass) { + PhysicsServer3D::get_singleton()->soft_body_set_total_mass(physics_rid, p_total_mass); +} + +void SoftDynamicBody3D::set_linear_stiffness(real_t p_linear_stiffness) { + PhysicsServer3D::get_singleton()->soft_body_set_linear_stiffness(physics_rid, p_linear_stiffness); +} + +real_t SoftDynamicBody3D::get_linear_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_linear_stiffness(physics_rid); +} + +real_t SoftDynamicBody3D::get_pressure_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_pressure_coefficient(physics_rid); +} + +void SoftDynamicBody3D::set_pressure_coefficient(real_t p_pressure_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_pressure_coefficient(physics_rid, p_pressure_coefficient); +} + +real_t SoftDynamicBody3D::get_damping_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_damping_coefficient(physics_rid); +} + +void SoftDynamicBody3D::set_damping_coefficient(real_t p_damping_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_damping_coefficient(physics_rid, p_damping_coefficient); +} + +real_t SoftDynamicBody3D::get_drag_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_drag_coefficient(physics_rid); +} + +void SoftDynamicBody3D::set_drag_coefficient(real_t p_drag_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_drag_coefficient(physics_rid, p_drag_coefficient); +} + +Vector3 SoftDynamicBody3D::get_point_transform(int p_point_index) { + return PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index); +} + +void SoftDynamicBody3D::pin_point_toggle(int p_point_index) { + pin_point(p_point_index, !(-1 != _has_pinned_point(p_point_index))); +} + +void SoftDynamicBody3D::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) { + _pin_point_on_physics_server(p_point_index, pin); + if (pin) { + _add_pinned_point(p_point_index, p_spatial_attachment_path); + } else { + _remove_pinned_point(p_point_index); + } +} + +bool SoftDynamicBody3D::is_point_pinned(int p_point_index) const { + return -1 != _has_pinned_point(p_point_index); +} + +void SoftDynamicBody3D::set_ray_pickable(bool p_ray_pickable) { + ray_pickable = p_ray_pickable; + _update_pickable(); +} + +bool SoftDynamicBody3D::is_ray_pickable() const { + return ray_pickable; +} + +SoftDynamicBody3D::SoftDynamicBody3D() : + physics_rid(PhysicsServer3D::get_singleton()->soft_body_create()) { + PhysicsServer3D::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id()); +} + +SoftDynamicBody3D::~SoftDynamicBody3D() { + PhysicsServer3D::get_singleton()->free(physics_rid); +} + +void SoftDynamicBody3D::_make_cache_dirty() { + pinned_points_cache_dirty = true; +} + +void SoftDynamicBody3D::_update_cache_pin_points_datas() { + if (!pinned_points_cache_dirty) { + return; + } + + pinned_points_cache_dirty = false; + + PinnedPoint *w = pinned_points.ptrw(); + for (int i = pinned_points.size() - 1; 0 <= i; --i) { + if (!w[i].spatial_attachment_path.is_empty()) { + w[i].spatial_attachment = Object::cast_to(get_node(w[i].spatial_attachment_path)); + } + if (!w[i].spatial_attachment) { + ERR_PRINT("Node3D node not defined in the pinned point, this is undefined behavior for SoftDynamicBody3D!"); + } + } +} + +void SoftDynamicBody3D::_pin_point_on_physics_server(int p_point_index, bool pin) { + PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin); +} + +void SoftDynamicBody3D::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) { + SoftDynamicBody3D::PinnedPoint *pinned_point; + if (-1 == _get_pinned_point(p_point_index, pinned_point)) { + // Create new + PinnedPoint pp; + pp.point_index = p_point_index; + pp.spatial_attachment_path = p_spatial_attachment_path; + + if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { + pp.spatial_attachment = Object::cast_to(get_node(p_spatial_attachment_path)); + pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index)); + } + + pinned_points.push_back(pp); + + } else { + pinned_point->point_index = p_point_index; + pinned_point->spatial_attachment_path = p_spatial_attachment_path; + + if (!p_spatial_attachment_path.is_empty() && has_node(p_spatial_attachment_path)) { + pinned_point->spatial_attachment = Object::cast_to(get_node(p_spatial_attachment_path)); + pinned_point->offset = (pinned_point->spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, pinned_point->point_index)); + } + } +} + +void SoftDynamicBody3D::_reset_points_offsets() { + if (!Engine::get_singleton()->is_editor_hint()) { + return; + } + + const PinnedPoint *r = pinned_points.ptr(); + PinnedPoint *w = pinned_points.ptrw(); + for (int i = pinned_points.size() - 1; 0 <= i; --i) { + if (!r[i].spatial_attachment) { + if (!r[i].spatial_attachment_path.is_empty() && has_node(r[i].spatial_attachment_path)) { + w[i].spatial_attachment = Object::cast_to(get_node(r[i].spatial_attachment_path)); + } + } + + if (!r[i].spatial_attachment) { + continue; + } + + w[i].offset = (r[i].spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer3D::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index)); + } +} + +void SoftDynamicBody3D::_remove_pinned_point(int p_point_index) { + const int id(_has_pinned_point(p_point_index)); + if (-1 != id) { + pinned_points.remove(id); + } +} + +int SoftDynamicBody3D::_get_pinned_point(int p_point_index, SoftDynamicBody3D::PinnedPoint *&r_point) const { + const int id = _has_pinned_point(p_point_index); + if (-1 == id) { + r_point = nullptr; + return -1; + } else { + r_point = const_cast(&pinned_points.ptr()[id]); + return id; + } +} + +int SoftDynamicBody3D::_has_pinned_point(int p_point_index) const { + const PinnedPoint *r = pinned_points.ptr(); + for (int i = pinned_points.size() - 1; 0 <= i; --i) { + if (p_point_index == r[i].point_index) { + return i; + } + } + return -1; +} diff --git a/scene/3d/soft_dynamic_body_3d.h b/scene/3d/soft_dynamic_body_3d.h new file mode 100644 index 0000000000..0b4b3021cd --- /dev/null +++ b/scene/3d/soft_dynamic_body_3d.h @@ -0,0 +1,203 @@ +/*************************************************************************/ +/* soft_dynamic_body_3d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef SOFT_DYNAMIC_BODY_H +#define SOFT_DYNAMIC_BODY_H + +#include "scene/3d/mesh_instance_3d.h" +#include "servers/physics_server_3d.h" + +class SoftDynamicBody3D; + +class SoftDynamicBodyRenderingServerHandler : public RenderingServerHandler { + friend class SoftDynamicBody3D; + + RID mesh; + int surface = 0; + Vector buffer; + uint32_t stride = 0; + uint32_t offset_vertices = 0; + uint32_t offset_normal = 0; + + uint8_t *write_buffer = nullptr; + +private: + SoftDynamicBodyRenderingServerHandler(); + bool is_ready() { return mesh.is_valid(); } + void prepare(RID p_mesh_rid, int p_surface); + void clear(); + void open(); + void close(); + void commit_changes(); + +public: + void set_vertex(int p_vertex_id, const void *p_vector3) override; + void set_normal(int p_vertex_id, const void *p_vector3) override; + void set_aabb(const AABB &p_aabb) override; +}; + +class SoftDynamicBody3D : public MeshInstance3D { + GDCLASS(SoftDynamicBody3D, MeshInstance3D); + +public: + enum DisableMode { + DISABLE_MODE_REMOVE, + DISABLE_MODE_KEEP_ACTIVE, + }; + + struct PinnedPoint { + int point_index = -1; + NodePath spatial_attachment_path; + Node3D *spatial_attachment = nullptr; // Cache + Vector3 offset; + + PinnedPoint(); + PinnedPoint(const PinnedPoint &obj_tocopy); + PinnedPoint &operator=(const PinnedPoint &obj); + }; + +private: + SoftDynamicBodyRenderingServerHandler rendering_server_handler; + + RID physics_rid; + + DisableMode disable_mode = DISABLE_MODE_REMOVE; + + bool mesh_owner = false; + uint32_t collision_mask = 1; + uint32_t collision_layer = 1; + NodePath parent_collision_ignore; + Vector pinned_points; + bool simulation_started = false; + bool pinned_points_cache_dirty = true; + + Ref debug_mesh_cache; + class MeshInstance3D *debug_mesh = nullptr; + + bool capture_input_on_drag = false; + bool ray_pickable = true; + + void _update_pickable(); + +protected: + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List *p_list) const; + + bool _set_property_pinned_points_indices(const Array &p_indices); + bool _set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value); + bool _get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const; + + void _notification(int p_what); + static void _bind_methods(); + + TypedArray get_configuration_warnings() const override; + +protected: + void _update_physics_server(); + void _draw_soft_mesh(); + +public: + void prepare_physics_server(); + void become_mesh_owner(); + + RID get_physics_rid() const { return physics_rid; } + + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_layer(uint32_t p_layer); + uint32_t get_collision_layer() const; + + void set_collision_layer_value(int p_layer_number, bool p_value); + bool get_collision_layer_value(int p_layer_number) const; + + void set_collision_mask_value(int p_layer_number, bool p_value); + bool get_collision_mask_value(int p_layer_number) const; + + void set_disable_mode(DisableMode p_mode); + DisableMode get_disable_mode() const; + + void set_parent_collision_ignore(const NodePath &p_parent_collision_ignore); + const NodePath &get_parent_collision_ignore() const; + + void set_pinned_points_indices(Vector p_pinned_points_indices); + Vector get_pinned_points_indices(); + + void set_simulation_precision(int p_simulation_precision); + int get_simulation_precision(); + + void set_total_mass(real_t p_total_mass); + real_t get_total_mass(); + + void set_linear_stiffness(real_t p_linear_stiffness); + real_t get_linear_stiffness(); + + void set_pressure_coefficient(real_t p_pressure_coefficient); + real_t get_pressure_coefficient(); + + void set_damping_coefficient(real_t p_damping_coefficient); + real_t get_damping_coefficient(); + + void set_drag_coefficient(real_t p_drag_coefficient); + real_t get_drag_coefficient(); + + Array get_collision_exceptions(); + void add_collision_exception_with(Node *p_node); + void remove_collision_exception_with(Node *p_node); + + Vector3 get_point_transform(int p_point_index); + + void pin_point_toggle(int p_point_index); + void pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path = NodePath()); + bool is_point_pinned(int p_point_index) const; + + void set_ray_pickable(bool p_ray_pickable); + bool is_ray_pickable() const; + + SoftDynamicBody3D(); + ~SoftDynamicBody3D(); + +private: + void _make_cache_dirty(); + void _update_cache_pin_points_datas(); + + void _pin_point_on_physics_server(int p_point_index, bool pin); + void _add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path); + void _reset_points_offsets(); + + void _remove_pinned_point(int p_point_index); + int _get_pinned_point(int p_point_index, PinnedPoint *&r_point) const; + int _has_pinned_point(int p_point_index) const; +}; + +VARIANT_ENUM_CAST(SoftDynamicBody3D::DisableMode); + +#endif // SOFT_DYNAMIC_BODY_H diff --git a/scene/3d/vehicle_body_3d.cpp b/scene/3d/vehicle_body_3d.cpp index daeea81891..bc3bb81ed4 100644 --- a/scene/3d/vehicle_body_3d.cpp +++ b/scene/3d/vehicle_body_3d.cpp @@ -803,7 +803,7 @@ void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) { } void VehicleBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) { - RigidBody3D::_body_state_changed(p_state); + RigidDynamicBody3D::_body_state_changed(p_state); real_t step = p_state->get_step(); diff --git a/scene/3d/vehicle_body_3d.h b/scene/3d/vehicle_body_3d.h index f29c3d89b7..a798c76c1f 100644 --- a/scene/3d/vehicle_body_3d.h +++ b/scene/3d/vehicle_body_3d.h @@ -150,8 +150,8 @@ public: VehicleWheel3D(); }; -class VehicleBody3D : public RigidBody3D { - GDCLASS(VehicleBody3D, RigidBody3D); +class VehicleBody3D : public RigidDynamicBody3D { + GDCLASS(VehicleBody3D, RigidDynamicBody3D); real_t engine_force = 0.0; real_t brake = 0.0; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 25c8e3e0b7..3a4a814330 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -234,7 +234,7 @@ #include "scene/3d/remote_transform_3d.h" #include "scene/3d/skeleton_3d.h" #include "scene/3d/skeleton_ik_3d.h" -#include "scene/3d/soft_body_3d.h" +#include "scene/3d/soft_dynamic_body_3d.h" #include "scene/3d/spring_arm_3d.h" #include "scene/3d/sprite_3d.h" #include "scene/3d/vehicle_body_3d.h" @@ -489,13 +489,13 @@ void register_scene_types() { GDREGISTER_VIRTUAL_CLASS(PhysicsBody3D); GDREGISTER_CLASS(StaticBody3D); GDREGISTER_CLASS(AnimatableBody3D); - GDREGISTER_CLASS(RigidBody3D); + GDREGISTER_CLASS(RigidDynamicBody3D); GDREGISTER_CLASS(KinematicCollision3D); GDREGISTER_CLASS(CharacterBody3D); GDREGISTER_CLASS(SpringArm3D); GDREGISTER_CLASS(PhysicalBone3D); - GDREGISTER_CLASS(SoftBody3D); + GDREGISTER_CLASS(SoftDynamicBody3D); GDREGISTER_CLASS(SkeletonIK3D); GDREGISTER_CLASS(BoneAttachment3D); @@ -649,7 +649,7 @@ void register_scene_types() { GDREGISTER_VIRTUAL_CLASS(PhysicsBody2D); GDREGISTER_CLASS(StaticBody2D); GDREGISTER_CLASS(AnimatableBody2D); - GDREGISTER_CLASS(RigidBody2D); + GDREGISTER_CLASS(RigidDynamicBody2D); GDREGISTER_CLASS(CharacterBody2D); GDREGISTER_CLASS(KinematicCollision2D); GDREGISTER_CLASS(Area2D); @@ -955,13 +955,14 @@ void register_scene_types() { ClassDB::add_compatibility_class("RayShape", "SeparationRayShape3D"); ClassDB::add_compatibility_class("RayShape2D", "SeparationRayShape2D"); ClassDB::add_compatibility_class("RemoteTransform", "RemoteTransform3D"); - ClassDB::add_compatibility_class("RigidBody", "RigidBody3D"); + ClassDB::add_compatibility_class("RigidBody", "RigidDynamicBody3D"); + ClassDB::add_compatibility_class("RigidBody2D", "RigidDynamicBody2D"); ClassDB::add_compatibility_class("Shape", "Shape3D"); ClassDB::add_compatibility_class("ShortCut", "Shortcut"); ClassDB::add_compatibility_class("Skeleton", "Skeleton3D"); ClassDB::add_compatibility_class("SkeletonIK", "SkeletonIK3D"); ClassDB::add_compatibility_class("SliderJoint", "SliderJoint3D"); - ClassDB::add_compatibility_class("SoftBody", "SoftBody3D"); + ClassDB::add_compatibility_class("SoftBody", "SoftDynamicBody3D"); ClassDB::add_compatibility_class("Spatial", "Node3D"); ClassDB::add_compatibility_class("SpatialGizmo", "Node3DGizmo"); ClassDB::add_compatibility_class("SpatialMaterial", "StandardMaterial3D"); diff --git a/scene/resources/immediate_mesh.cpp b/scene/resources/immediate_mesh.cpp index 05d1a7bf94..fe7124de9e 100644 --- a/scene/resources/immediate_mesh.cpp +++ b/scene/resources/immediate_mesh.cpp @@ -335,9 +335,6 @@ int ImmediateMesh::surface_get_array_len(int p_idx) const { int ImmediateMesh::surface_get_array_index_len(int p_idx) const { return 0; } -bool ImmediateMesh::surface_is_softbody_friendly(int p_idx) const { - return false; -} Array ImmediateMesh::surface_get_arrays(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, int(surfaces.size()), Array()); return RS::get_singleton()->mesh_surface_get_arrays(mesh, p_surface); diff --git a/scene/resources/immediate_mesh.h b/scene/resources/immediate_mesh.h index 7010d40719..6673ee6f3d 100644 --- a/scene/resources/immediate_mesh.h +++ b/scene/resources/immediate_mesh.h @@ -94,7 +94,6 @@ public: virtual int get_surface_count() const override; virtual int surface_get_array_len(int p_idx) const override; virtual int surface_get_array_index_len(int p_idx) const override; - virtual bool surface_is_softbody_friendly(int p_idx) const override; virtual Array surface_get_arrays(int p_surface) const override; virtual Array surface_get_blend_shape_arrays(int p_surface) const override; virtual Dictionary surface_get_lods(int p_surface) const override; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index ad589a605e..98f584855d 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -156,11 +156,6 @@ void Mesh::generate_debug_mesh_indices(Vector &r_points) { } } -bool Mesh::surface_is_softbody_friendly(int p_idx) const { - const uint32_t surface_format = surface_get_format(p_idx); - return (surface_format & Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE); -} - Vector Mesh::get_faces() const { Ref tm = generate_triangle_mesh(); if (tm.is_valid()) { diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h index 27b0eb098b..0ddc2054fb 100644 --- a/scene/resources/mesh.h +++ b/scene/resources/mesh.h @@ -131,7 +131,6 @@ public: virtual int get_surface_count() const = 0; virtual int surface_get_array_len(int p_idx) const = 0; virtual int surface_get_array_index_len(int p_idx) const = 0; - virtual bool surface_is_softbody_friendly(int p_idx) const; virtual Array surface_get_arrays(int p_surface) const = 0; virtual Array surface_get_blend_shape_arrays(int p_surface) const = 0; virtual Dictionary surface_get_lods(int p_surface) const = 0; -- cgit v1.2.3