diff options
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/SCsub | 11 | ||||
-rw-r--r-- | scene/3d/area_3d.cpp (renamed from scene/3d/area.cpp) | 280 | ||||
-rw-r--r-- | scene/3d/area_3d.h (renamed from scene/3d/area.h) | 22 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.cpp | 33 | ||||
-rw-r--r-- | scene/3d/audio_stream_player_3d.h | 14 | ||||
-rw-r--r-- | scene/3d/baked_lightmap.cpp | 36 | ||||
-rw-r--r-- | scene/3d/bone_attachment_3d.cpp (renamed from scene/3d/bone_attachment.cpp) | 30 | ||||
-rw-r--r-- | scene/3d/bone_attachment_3d.h (renamed from scene/3d/bone_attachment.h) | 10 | ||||
-rw-r--r-- | scene/3d/camera_3d.cpp (renamed from scene/3d/camera.cpp) | 357 | ||||
-rw-r--r-- | scene/3d/camera_3d.h (renamed from scene/3d/camera.h) | 56 | ||||
-rw-r--r-- | scene/3d/collision_object_3d.cpp (renamed from scene/3d/collision_object.cpp) | 160 | ||||
-rw-r--r-- | scene/3d/collision_object_3d.h (renamed from scene/3d/collision_object.h) | 28 | ||||
-rw-r--r-- | scene/3d/collision_polygon_3d.cpp (renamed from scene/3d/collision_polygon.cpp) | 66 | ||||
-rw-r--r-- | scene/3d/collision_polygon_3d.h (renamed from scene/3d/collision_polygon.h) | 20 | ||||
-rw-r--r-- | scene/3d/collision_shape_3d.cpp (renamed from scene/3d/collision_shape.cpp) | 114 | ||||
-rw-r--r-- | scene/3d/collision_shape_3d.h (renamed from scene/3d/collision_shape.h) | 24 | ||||
-rw-r--r-- | scene/3d/cpu_particles_3d.cpp (renamed from scene/3d/cpu_particles.cpp) | 326 | ||||
-rw-r--r-- | scene/3d/cpu_particles_3d.h (renamed from scene/3d/cpu_particles.h) | 20 | ||||
-rw-r--r-- | scene/3d/decal.cpp | 235 | ||||
-rw-r--r-- | scene/3d/decal.h | 114 | ||||
-rw-r--r-- | scene/3d/gi_probe.cpp | 63 | ||||
-rw-r--r-- | scene/3d/gi_probe.h | 10 | ||||
-rw-r--r-- | scene/3d/gpu_particles_3d.cpp (renamed from scene/3d/particles.cpp) | 234 | ||||
-rw-r--r-- | scene/3d/gpu_particles_3d.h (renamed from scene/3d/particles.h) | 14 | ||||
-rw-r--r-- | scene/3d/immediate_geometry_3d.cpp (renamed from scene/3d/immediate_geometry.cpp) | 78 | ||||
-rw-r--r-- | scene/3d/immediate_geometry_3d.h (renamed from scene/3d/immediate_geometry.h) | 18 | ||||
-rw-r--r-- | scene/3d/interpolated_camera.cpp | 155 | ||||
-rw-r--r-- | scene/3d/interpolated_camera.h | 63 | ||||
-rw-r--r-- | scene/3d/light_3d.cpp (renamed from scene/3d/light.cpp) | 275 | ||||
-rw-r--r-- | scene/3d/light_3d.h (renamed from scene/3d/light.h) | 96 | ||||
-rw-r--r-- | scene/3d/listener_3d.cpp (renamed from scene/3d/listener.cpp) | 46 | ||||
-rw-r--r-- | scene/3d/listener_3d.h (renamed from scene/3d/listener.h) | 18 | ||||
-rw-r--r-- | scene/3d/mesh_instance_3d.cpp (renamed from scene/3d/mesh_instance.cpp) | 159 | ||||
-rw-r--r-- | scene/3d/mesh_instance_3d.h (renamed from scene/3d/mesh_instance.h) | 15 | ||||
-rw-r--r-- | scene/3d/multimesh_instance_3d.cpp (renamed from scene/3d/multimesh_instance.cpp) | 22 | ||||
-rw-r--r-- | scene/3d/multimesh_instance_3d.h (renamed from scene/3d/multimesh_instance.h) | 16 | ||||
-rw-r--r-- | scene/3d/navigation_3d.cpp (renamed from scene/3d/navigation.cpp) | 80 | ||||
-rw-r--r-- | scene/3d/navigation_3d.h (renamed from scene/3d/navigation.h) | 18 | ||||
-rw-r--r-- | scene/3d/navigation_agent_3d.cpp (renamed from scene/3d/navigation_agent.cpp) | 197 | ||||
-rw-r--r-- | scene/3d/navigation_agent_3d.h (renamed from scene/3d/navigation_agent.h) | 22 | ||||
-rw-r--r-- | scene/3d/navigation_obstacle_3d.cpp (renamed from scene/3d/navigation_obstacle.cpp) | 86 | ||||
-rw-r--r-- | scene/3d/navigation_obstacle_3d.h (renamed from scene/3d/navigation_obstacle.h) | 18 | ||||
-rw-r--r-- | scene/3d/navigation_region_3d.cpp (renamed from scene/3d/navigation_region.cpp) | 101 | ||||
-rw-r--r-- | scene/3d/navigation_region_3d.h (renamed from scene/3d/navigation_region.h) | 16 | ||||
-rw-r--r-- | scene/3d/node_3d.cpp (renamed from scene/3d/spatial.cpp) | 292 | ||||
-rw-r--r-- | scene/3d/node_3d.h (renamed from scene/3d/spatial.h) | 42 | ||||
-rw-r--r-- | scene/3d/path_3d.cpp (renamed from scene/3d/path.cpp) | 120 | ||||
-rw-r--r-- | scene/3d/path_3d.h (renamed from scene/3d/path.h) | 20 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.cpp (renamed from scene/3d/physics_body.cpp) | 1174 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.h (renamed from scene/3d/physics_body.h) | 124 | ||||
-rw-r--r-- | scene/3d/physics_joint.h | 343 | ||||
-rw-r--r-- | scene/3d/physics_joint_3d.cpp (renamed from scene/3d/physics_joint.cpp) | 342 | ||||
-rw-r--r-- | scene/3d/physics_joint_3d.h | 343 | ||||
-rw-r--r-- | scene/3d/position_3d.h | 6 | ||||
-rw-r--r-- | scene/3d/proximity_group_3d.cpp (renamed from scene/3d/proximity_group.cpp) | 52 | ||||
-rw-r--r-- | scene/3d/proximity_group_3d.h (renamed from scene/3d/proximity_group.h) | 14 | ||||
-rw-r--r-- | scene/3d/ray_cast_3d.cpp (renamed from scene/3d/ray_cast.cpp) | 158 | ||||
-rw-r--r-- | scene/3d/ray_cast_3d.h (renamed from scene/3d/ray_cast.h) | 14 | ||||
-rw-r--r-- | scene/3d/reflection_probe.cpp | 34 | ||||
-rw-r--r-- | scene/3d/reflection_probe.h | 8 | ||||
-rw-r--r-- | scene/3d/remote_transform_3d.cpp (renamed from scene/3d/remote_transform.cpp) | 68 | ||||
-rw-r--r-- | scene/3d/remote_transform_3d.h (renamed from scene/3d/remote_transform.h) | 10 | ||||
-rw-r--r-- | scene/3d/skeleton_3d.cpp (renamed from scene/3d/skeleton.cpp) | 218 | ||||
-rw-r--r-- | scene/3d/skeleton_3d.h (renamed from scene/3d/skeleton.h) | 43 | ||||
-rw-r--r-- | scene/3d/skeleton_ik_3d.cpp | 578 | ||||
-rw-r--r-- | scene/3d/skeleton_ik_3d.h | 220 | ||||
-rw-r--r-- | scene/3d/soft_body_3d.cpp (renamed from scene/3d/soft_body.cpp) | 393 | ||||
-rw-r--r-- | scene/3d/soft_body_3d.h (renamed from scene/3d/soft_body.h) | 26 | ||||
-rw-r--r-- | scene/3d/spring_arm_3d.cpp (renamed from scene/3d/spring_arm.cpp) | 78 | ||||
-rw-r--r-- | scene/3d/spring_arm_3d.h (renamed from scene/3d/spring_arm.h) | 16 | ||||
-rw-r--r-- | scene/3d/sprite_3d.cpp | 52 | ||||
-rw-r--r-- | scene/3d/sprite_3d.h | 8 | ||||
-rw-r--r-- | scene/3d/vehicle_body_3d.cpp (renamed from scene/3d/vehicle_body.cpp) | 242 | ||||
-rw-r--r-- | scene/3d/vehicle_body_3d.h (renamed from scene/3d/vehicle_body.h) | 48 | ||||
-rw-r--r-- | scene/3d/velocity_tracker_3d.cpp (renamed from scene/3d/spatial_velocity_tracker.cpp) | 28 | ||||
-rw-r--r-- | scene/3d/velocity_tracker_3d.h (renamed from scene/3d/spatial_velocity_tracker.h) | 10 | ||||
-rw-r--r-- | scene/3d/visibility_notifier_3d.cpp (renamed from scene/3d/visibility_notifier.cpp) | 68 | ||||
-rw-r--r-- | scene/3d/visibility_notifier_3d.h (renamed from scene/3d/visibility_notifier.h) | 26 | ||||
-rw-r--r-- | scene/3d/visual_instance_3d.cpp (renamed from scene/3d/visual_instance.cpp) | 249 | ||||
-rw-r--r-- | scene/3d/visual_instance_3d.h (renamed from scene/3d/visual_instance.h) | 50 | ||||
-rw-r--r-- | scene/3d/voxelizer.cpp | 18 | ||||
-rw-r--r-- | scene/3d/voxelizer.h | 2 | ||||
-rw-r--r-- | scene/3d/world_environment.cpp | 6 | ||||
-rw-r--r-- | scene/3d/world_environment.h | 2 | ||||
-rw-r--r-- | scene/3d/xr_nodes.cpp (renamed from scene/3d/arvr_nodes.cpp) | 368 | ||||
-rw-r--r-- | scene/3d/xr_nodes.h (renamed from scene/3d/arvr_nodes.h) | 68 |
86 files changed, 5472 insertions, 4285 deletions
diff --git a/scene/3d/SCsub b/scene/3d/SCsub index 31a443bad1..ce69e8aa19 100644 --- a/scene/3d/SCsub +++ b/scene/3d/SCsub @@ -1,12 +1,9 @@ #!/usr/bin/env python -Import('env') +Import("env") -if env['disable_3d']: - env.add_source_files(env.scene_sources, "spatial.cpp") - env.add_source_files(env.scene_sources, "skeleton.cpp") - env.add_source_files(env.scene_sources, "particles.cpp") - env.add_source_files(env.scene_sources, "visual_instance.cpp") - env.add_source_files(env.scene_sources, "world_environment.cpp") +if env["disable_3d"]: + env.add_source_files(env.scene_sources, "node_3d.cpp") + env.add_source_files(env.scene_sources, "skeleton_3d.cpp") else: env.add_source_files(env.scene_sources, "*.cpp") diff --git a/scene/3d/area.cpp b/scene/3d/area_3d.cpp index 321926d841..b72483d71b 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* area.cpp */ +/* area_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,93 +28,93 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "area.h" +#include "area_3d.h" #include "scene/scene_string_names.h" #include "servers/audio_server.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -void Area::set_space_override_mode(SpaceOverride p_mode) { +void Area3D::set_space_override_mode(SpaceOverride p_mode) { space_override = p_mode; - PhysicsServer::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer::AreaSpaceOverrideMode(p_mode)); + PhysicsServer3D::get_singleton()->area_set_space_override_mode(get_rid(), PhysicsServer3D::AreaSpaceOverrideMode(p_mode)); } -Area::SpaceOverride Area::get_space_override_mode() const { +Area3D::SpaceOverride Area3D::get_space_override_mode() const { return space_override; } -void Area::set_gravity_is_point(bool p_enabled) { +void Area3D::set_gravity_is_point(bool p_enabled) { gravity_is_point = p_enabled; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_IS_POINT, p_enabled); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_IS_POINT, p_enabled); } -bool Area::is_gravity_a_point() const { +bool Area3D::is_gravity_a_point() const { return gravity_is_point; } -void Area::set_gravity_distance_scale(real_t p_scale) { +void Area3D::set_gravity_distance_scale(real_t p_scale) { gravity_distance_scale = p_scale; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale); } -real_t Area::get_gravity_distance_scale() const { +real_t Area3D::get_gravity_distance_scale() const { return gravity_distance_scale; } -void Area::set_gravity_vector(const Vector3 &p_vec) { +void Area3D::set_gravity_vector(const Vector3 &p_vec) { gravity_vec = p_vec; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY_VECTOR, p_vec); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY_VECTOR, p_vec); } -Vector3 Area::get_gravity_vector() const { +Vector3 Area3D::get_gravity_vector() const { return gravity_vec; } -void Area::set_gravity(real_t p_gravity) { +void Area3D::set_gravity(real_t p_gravity) { gravity = p_gravity; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_GRAVITY, p_gravity); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_GRAVITY, p_gravity); } -real_t Area::get_gravity() const { +real_t Area3D::get_gravity() const { return gravity; } -void Area::set_linear_damp(real_t p_linear_damp) { +void Area3D::set_linear_damp(real_t p_linear_damp) { linear_damp = p_linear_damp; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_LINEAR_DAMP, p_linear_damp); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, p_linear_damp); } -real_t Area::get_linear_damp() const { +real_t Area3D::get_linear_damp() const { return linear_damp; } -void Area::set_angular_damp(real_t p_angular_damp) { +void Area3D::set_angular_damp(real_t p_angular_damp) { angular_damp = p_angular_damp; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_ANGULAR_DAMP, p_angular_damp); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, p_angular_damp); } -real_t Area::get_angular_damp() const { +real_t Area3D::get_angular_damp() const { return angular_damp; } -void Area::set_priority(real_t p_priority) { +void Area3D::set_priority(real_t p_priority) { priority = p_priority; - PhysicsServer::get_singleton()->area_set_param(get_rid(), PhysicsServer::AREA_PARAM_PRIORITY, p_priority); + PhysicsServer3D::get_singleton()->area_set_param(get_rid(), PhysicsServer3D::AREA_PARAM_PRIORITY, p_priority); } -real_t Area::get_priority() const { +real_t Area3D::get_priority() const { return priority; } -void Area::_body_enter_tree(ObjectID p_id) { +void Area3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -132,7 +132,7 @@ void Area::_body_enter_tree(ObjectID p_id) { } } -void Area::_body_exit_tree(ObjectID p_id) { +void Area3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -148,9 +148,9 @@ void Area::_body_exit_tree(ObjectID p_id) { } } -void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape) { +void Area3D::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int p_body_shape, int p_area_shape) { - bool body_in = p_status == PhysicsServer::AREA_BODY_ADDED; + bool body_in = p_status == PhysicsServer3D::AREA_BODY_ADDED; ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); @@ -171,8 +171,8 @@ void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int 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, &Area::_body_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_body_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree), make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -198,8 +198,8 @@ void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int if (E->get().rc == 0) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree)); if (E->get().in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, obj); } @@ -217,7 +217,7 @@ void Area::_body_inout(int p_status, const RID &p_body, ObjectID p_instance, int locked = false; } -void Area::_clear_monitoring() { +void Area3D::_clear_monitoring() { ERR_FAIL_COND_MSG(locked, "This function can't be used during the in/out signal."); @@ -245,8 +245,8 @@ void Area::_clear_monitoring() { emit_signal(SceneStringNames::get_singleton()->body_exited, node); - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_body_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_body_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_body_exit_tree)); } } @@ -275,19 +275,19 @@ void Area::_clear_monitoring() { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_area_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_area_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_area_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_area_exit_tree)); } } } -void Area::_notification(int p_what) { +void Area3D::_notification(int p_what) { if (p_what == NOTIFICATION_EXIT_TREE) { _clear_monitoring(); } } -void Area::set_monitoring(bool p_enable) { +void Area3D::set_monitoring(bool p_enable) { ERR_FAIL_COND_MSG(locked, "Function blocked during in/out signal. Use set_deferred(\"monitoring\", true/false)."); @@ -298,16 +298,16 @@ void Area::set_monitoring(bool p_enable) { if (monitoring) { - PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout); - PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout); + PhysicsServer3D::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout); + PhysicsServer3D::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout); } else { - PhysicsServer::get_singleton()->area_set_monitor_callback(get_rid(), NULL, StringName()); - PhysicsServer::get_singleton()->area_set_area_monitor_callback(get_rid(), NULL, StringName()); + PhysicsServer3D::get_singleton()->area_set_monitor_callback(get_rid(), nullptr, StringName()); + PhysicsServer3D::get_singleton()->area_set_area_monitor_callback(get_rid(), nullptr, StringName()); _clear_monitoring(); } } -void Area::_area_enter_tree(ObjectID p_id) { +void Area3D::_area_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -325,7 +325,7 @@ void Area::_area_enter_tree(ObjectID p_id) { } } -void Area::_area_exit_tree(ObjectID p_id) { +void Area3D::_area_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -341,9 +341,9 @@ void Area::_area_exit_tree(ObjectID p_id) { } } -void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape) { +void Area3D::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int p_area_shape, int p_self_shape) { - bool area_in = p_status == PhysicsServer::AREA_BODY_ADDED; + bool area_in = p_status == PhysicsServer3D::AREA_BODY_ADDED; ObjectID objid = p_instance; Object *obj = ObjectDB::get_instance(objid); @@ -364,8 +364,8 @@ void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int 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, &Area::_area_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_area_exit_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_area_enter_tree), make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_area_exit_tree), make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_entered, node); } @@ -391,8 +391,8 @@ void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int if (E->get().rc == 0) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area::_area_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area::_area_exit_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &Area3D::_area_enter_tree)); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &Area3D::_area_exit_tree)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); } @@ -411,12 +411,12 @@ void Area::_area_inout(int p_status, const RID &p_area, ObjectID p_instance, int locked = false; } -bool Area::is_monitoring() const { +bool Area3D::is_monitoring() const { return monitoring; } -Array Area::get_overlapping_bodies() const { +TypedArray<Node3D> Area3D::get_overlapping_bodies() const { ERR_FAIL_COND_V(!monitoring, Array()); Array ret; @@ -434,24 +434,24 @@ Array Area::get_overlapping_bodies() const { return ret; } -void Area::set_monitorable(bool p_enable) { +void Area3D::set_monitorable(bool p_enable) { - ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); + ERR_FAIL_COND_MSG(locked || (is_inside_tree() && PhysicsServer3D::get_singleton()->is_flushing_queries()), "Function blocked during in/out signal. Use set_deferred(\"monitorable\", true/false)."); if (p_enable == monitorable) return; monitorable = p_enable; - PhysicsServer::get_singleton()->area_set_monitorable(get_rid(), monitorable); + PhysicsServer3D::get_singleton()->area_set_monitorable(get_rid(), monitorable); } -bool Area::is_monitorable() const { +bool Area3D::is_monitorable() const { return monitorable; } -Array Area::get_overlapping_areas() const { +TypedArray<Area3D> Area3D::get_overlapping_areas() const { ERR_FAIL_COND_V(!monitoring, Array()); Array ret; @@ -469,7 +469,7 @@ Array Area::get_overlapping_areas() const { return ret; } -bool Area::overlaps_area(Node *p_area) const { +bool Area3D::overlaps_area(Node *p_area) const { ERR_FAIL_NULL_V(p_area, false); const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_id()); @@ -478,7 +478,7 @@ bool Area::overlaps_area(Node *p_area) const { return E->get().in_tree; } -bool Area::overlaps_body(Node *p_body) const { +bool Area3D::overlaps_body(Node *p_body) const { ERR_FAIL_NULL_V(p_body, false); const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_id()); @@ -486,28 +486,28 @@ bool Area::overlaps_body(Node *p_body) const { return false; return E->get().in_tree; } -void Area::set_collision_mask(uint32_t p_mask) { +void Area3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - PhysicsServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask); + PhysicsServer3D::get_singleton()->area_set_collision_mask(get_rid(), p_mask); } -uint32_t Area::get_collision_mask() const { +uint32_t Area3D::get_collision_mask() const { return collision_mask; } -void Area::set_collision_layer(uint32_t p_layer) { +void Area3D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - PhysicsServer::get_singleton()->area_set_collision_layer(get_rid(), p_layer); + PhysicsServer3D::get_singleton()->area_set_collision_layer(get_rid(), p_layer); } -uint32_t Area::get_collision_layer() const { +uint32_t Area3D::get_collision_layer() const { return collision_layer; } -void Area::set_collision_mask_bit(int p_bit, bool p_value) { +void Area3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -517,12 +517,12 @@ void Area::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool Area::get_collision_mask_bit(int p_bit) const { +bool Area3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void Area::set_collision_layer_bit(int p_bit, bool p_value) { +void Area3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); if (p_value) @@ -532,26 +532,26 @@ void Area::set_collision_layer_bit(int p_bit, bool p_value) { set_collision_layer(layer); } -bool Area::get_collision_layer_bit(int p_bit) const { +bool Area3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -void Area::set_audio_bus_override(bool p_override) { +void Area3D::set_audio_bus_override(bool p_override) { audio_bus_override = p_override; } -bool Area::is_overriding_audio_bus() const { +bool Area3D::is_overriding_audio_bus() const { return audio_bus_override; } -void Area::set_audio_bus(const StringName &p_audio_bus) { +void Area3D::set_audio_bus(const StringName &p_audio_bus) { audio_bus = p_audio_bus; } -StringName Area::get_audio_bus() const { +StringName Area3D::get_audio_bus() const { for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) { @@ -561,20 +561,20 @@ StringName Area::get_audio_bus() const { return "Master"; } -void Area::set_use_reverb_bus(bool p_enable) { +void Area3D::set_use_reverb_bus(bool p_enable) { use_reverb_bus = p_enable; } -bool Area::is_using_reverb_bus() const { +bool Area3D::is_using_reverb_bus() const { return use_reverb_bus; } -void Area::set_reverb_bus(const StringName &p_audio_bus) { +void Area3D::set_reverb_bus(const StringName &p_audio_bus) { reverb_bus = p_audio_bus; } -StringName Area::get_reverb_bus() const { +StringName Area3D::get_reverb_bus() const { for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) { if (AudioServer::get_singleton()->get_bus_name(i) == reverb_bus) { @@ -584,25 +584,25 @@ StringName Area::get_reverb_bus() const { return "Master"; } -void Area::set_reverb_amount(float p_amount) { +void Area3D::set_reverb_amount(float p_amount) { reverb_amount = p_amount; } -float Area::get_reverb_amount() const { +float Area3D::get_reverb_amount() const { return reverb_amount; } -void Area::set_reverb_uniformity(float p_uniformity) { +void Area3D::set_reverb_uniformity(float p_uniformity) { reverb_uniformity = p_uniformity; } -float Area::get_reverb_uniformity() const { +float Area3D::get_reverb_uniformity() const { return reverb_uniformity; } -void Area::_validate_property(PropertyInfo &property) const { +void Area3D::_validate_property(PropertyInfo &property) const { if (property.name == "audio_bus_name" || property.name == "reverb_bus_name") { @@ -618,85 +618,85 @@ void Area::_validate_property(PropertyInfo &property) const { } } -void Area::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area::set_space_override_mode); - ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area::get_space_override_mode); +void Area3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area3D::set_space_override_mode); + ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area3D::get_space_override_mode); - ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area::set_gravity_is_point); - ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area::is_gravity_a_point); + ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area3D::set_gravity_is_point); + ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area3D::is_gravity_a_point); - ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area::set_gravity_distance_scale); - ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area::get_gravity_distance_scale); + ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area3D::set_gravity_distance_scale); + ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area3D::get_gravity_distance_scale); - ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area::set_gravity_vector); - ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area::get_gravity_vector); + ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area3D::set_gravity_vector); + ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area3D::get_gravity_vector); - ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area::set_gravity); - ClassDB::bind_method(D_METHOD("get_gravity"), &Area::get_gravity); + ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area3D::set_gravity); + ClassDB::bind_method(D_METHOD("get_gravity"), &Area3D::get_gravity); - ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area::set_angular_damp); - ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area::get_angular_damp); + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area3D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area3D::get_angular_damp); - ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area::set_linear_damp); - ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area::get_linear_damp); + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area3D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area3D::get_linear_damp); - ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area::set_priority); - ClassDB::bind_method(D_METHOD("get_priority"), &Area::get_priority); + ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area3D::set_priority); + ClassDB::bind_method(D_METHOD("get_priority"), &Area3D::get_priority); - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area::get_collision_layer); + ClassDB::bind_method(D_METHOD("set_collision_layer", "collision_layer"), &Area3D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &Area3D::get_collision_layer); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &Area3D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &Area3D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area::set_monitorable); - ClassDB::bind_method(D_METHOD("is_monitorable"), &Area::is_monitorable); + ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area3D::set_monitorable); + ClassDB::bind_method(D_METHOD("is_monitorable"), &Area3D::is_monitorable); - ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area::set_monitoring); - ClassDB::bind_method(D_METHOD("is_monitoring"), &Area::is_monitoring); + ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area3D::set_monitoring); + ClassDB::bind_method(D_METHOD("is_monitoring"), &Area3D::is_monitoring); - ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area::get_overlapping_bodies); - ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area::get_overlapping_areas); + ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area3D::get_overlapping_bodies); + ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area3D::get_overlapping_areas); - ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area::overlaps_body); - ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area::overlaps_area); + ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area3D::overlaps_body); + ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area3D::overlaps_area); - ClassDB::bind_method(D_METHOD("_body_inout"), &Area::_body_inout); - ClassDB::bind_method(D_METHOD("_area_inout"), &Area::_area_inout); + ClassDB::bind_method(D_METHOD("_body_inout"), &Area3D::_body_inout); + ClassDB::bind_method(D_METHOD("_area_inout"), &Area3D::_area_inout); - ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area::set_audio_bus_override); - ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area::is_overriding_audio_bus); + ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area3D::set_audio_bus_override); + ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area3D::is_overriding_audio_bus); - ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area::set_audio_bus); - ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area::get_audio_bus); + ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area3D::set_audio_bus); + ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area3D::get_audio_bus); - ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area::set_use_reverb_bus); - ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area::is_using_reverb_bus); + ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area3D::set_use_reverb_bus); + ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area3D::is_using_reverb_bus); - ClassDB::bind_method(D_METHOD("set_reverb_bus", "name"), &Area::set_reverb_bus); - ClassDB::bind_method(D_METHOD("get_reverb_bus"), &Area::get_reverb_bus); + ClassDB::bind_method(D_METHOD("set_reverb_bus", "name"), &Area3D::set_reverb_bus); + ClassDB::bind_method(D_METHOD("get_reverb_bus"), &Area3D::get_reverb_bus); - ClassDB::bind_method(D_METHOD("set_reverb_amount", "amount"), &Area::set_reverb_amount); - ClassDB::bind_method(D_METHOD("get_reverb_amount"), &Area::get_reverb_amount); + ClassDB::bind_method(D_METHOD("set_reverb_amount", "amount"), &Area3D::set_reverb_amount); + ClassDB::bind_method(D_METHOD("get_reverb_amount"), &Area3D::get_reverb_amount); - ClassDB::bind_method(D_METHOD("set_reverb_uniformity", "amount"), &Area::set_reverb_uniformity); - ClassDB::bind_method(D_METHOD("get_reverb_uniformity"), &Area::get_reverb_uniformity); + ClassDB::bind_method(D_METHOD("set_reverb_uniformity", "amount"), &Area3D::set_reverb_uniformity); + ClassDB::bind_method(D_METHOD("get_reverb_uniformity"), &Area3D::get_reverb_uniformity); ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape"))); ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape"))); ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); - ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); - ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); - ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"))); - ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area"))); + ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); + ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape"))); + ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"))); + ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area3D"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point"); @@ -727,8 +727,8 @@ void Area::_bind_methods() { BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE_COMBINE); } -Area::Area() : - CollisionObject(PhysicsServer::get_singleton()->area_create(), true) { +Area3D::Area3D() : + CollisionObject3D(PhysicsServer3D::get_singleton()->area_create(), true) { space_override = SPACE_OVERRIDE_DISABLED; set_gravity(9.8); @@ -755,5 +755,5 @@ Area::Area() : reverb_uniformity = 0.0; } -Area::~Area() { +Area3D::~Area3D() { } diff --git a/scene/3d/area.h b/scene/3d/area_3d.h index 7fe61430fa..f6503c6d2d 100644 --- a/scene/3d/area.h +++ b/scene/3d/area_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* area.h */ +/* area_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef AREA_H -#define AREA_H +#ifndef AREA_3D_H +#define AREA_3D_H #include "core/vset.h" -#include "scene/3d/collision_object.h" +#include "scene/3d/collision_object_3d.h" -class Area : public CollisionObject { +class Area3D : public CollisionObject3D { - GDCLASS(Area, CollisionObject); + GDCLASS(Area3D, CollisionObject3D); public: enum SpaceOverride { @@ -184,8 +184,8 @@ public: void set_collision_layer_bit(int p_bit, bool p_value); bool get_collision_layer_bit(int p_bit) const; - Array get_overlapping_bodies() const; - Array get_overlapping_areas() const; //function for script + TypedArray<Node3D> get_overlapping_bodies() const; + TypedArray<Area3D> get_overlapping_areas() const; //function for script bool overlaps_area(Node *p_area) const; bool overlaps_body(Node *p_body) const; @@ -208,10 +208,10 @@ public: void set_reverb_uniformity(float p_uniformity); float get_reverb_uniformity() const; - Area(); - ~Area(); + Area3D(); + ~Area3D(); }; -VARIANT_ENUM_CAST(Area::SpaceOverride); +VARIANT_ENUM_CAST(Area3D::SpaceOverride); #endif // AREA__H diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 855d254bd6..097368853e 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -29,11 +29,12 @@ /*************************************************************************/ #include "audio_stream_player_3d.h" + #include "core/engine.h" -#include "scene/3d/area.h" -#include "scene/3d/camera.h" -#include "scene/3d/listener.h" -#include "scene/main/viewport.h" +#include "scene/3d/area_3d.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/listener_3d.h" +#include "scene/main/window.h" // Based on "A Novel Multichannel Panning Method for Standard and Arbitrary Loudspeaker Configurations" by Ramy Sadek and Chris Kyriakakis (2004) // Speaker-Placement Correction Amplitude Panning (SPCAP) @@ -96,7 +97,7 @@ static const Vector3 speaker_directions[7] = { }; void AudioStreamPlayer3D::_calc_output_vol(const Vector3 &source_dir, real_t tightness, AudioStreamPlayer3D::Output &output) { - unsigned int speaker_count; // only main speakers (no LFE) + unsigned int speaker_count = 0; // only main speakers (no LFE) switch (AudioServer::get_singleton()->get_speaker_mode()) { case AudioServer::SPEAKER_MODE_STEREO: speaker_count = 2; @@ -213,7 +214,7 @@ void AudioStreamPlayer3D::_mix_audio() { AudioFrame target_volume = stream_paused_fade_out ? AudioFrame(0.f, 0.f) : current.vol[k]; AudioFrame vol_prev = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : prev_outputs[i].vol[k]; AudioFrame vol_inc = (target_volume - vol_prev) / float(buffer_size); - AudioFrame vol = stream_paused_fade_in ? AudioFrame(0.f, 0.f) : current.vol[k]; + AudioFrame vol = vol_prev; if (!AudioServer::get_singleton()->thread_has_channel_mix_buffer(current.bus_index, k)) continue; //may have been deleted, will be updated on process @@ -384,7 +385,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { linear_velocity = velocity_tracker->get_tracked_linear_velocity(); } - Ref<World> world = get_world(); + Ref<World3D> world = get_world(); ERR_FAIL_COND(world.is_null()); int new_output_count = 0; @@ -395,18 +396,18 @@ void AudioStreamPlayer3D::_notification(int p_what) { //check if any area is diverting sound into a bus - PhysicsDirectSpaceState *space_state = PhysicsServer::get_singleton()->space_get_direct_state(world->get_space()); + PhysicsDirectSpaceState3D *space_state = PhysicsServer3D::get_singleton()->space_get_direct_state(world->get_space()); - PhysicsDirectSpaceState::ShapeResult sr[MAX_INTERSECT_AREAS]; + PhysicsDirectSpaceState3D::ShapeResult sr[MAX_INTERSECT_AREAS]; int areas = space_state->intersect_point(global_pos, sr, MAX_INTERSECT_AREAS, Set<RID>(), area_mask, false, true); - Area *area = NULL; + Area3D *area = nullptr; for (int i = 0; i < areas; i++) { if (!sr[i].collider) continue; - Area *tarea = Object::cast_to<Area>(sr[i].collider); + Area3D *tarea = Object::cast_to<Area3D>(sr[i].collider); if (!tarea) continue; @@ -417,20 +418,20 @@ void AudioStreamPlayer3D::_notification(int p_what) { break; } - List<Camera *> cameras; + List<Camera3D *> cameras; world->get_camera_list(&cameras); - for (List<Camera *>::Element *E = cameras.front(); E; E = E->next()) { + for (List<Camera3D *>::Element *E = cameras.front(); E; E = E->next()) { - Camera *camera = E->get(); + Camera3D *camera = E->get(); Viewport *vp = camera->get_viewport(); if (!vp->is_audio_listener()) continue; bool listener_is_camera = true; - Spatial *listener_node = camera; + Node3D *listener_node = camera; - Listener *listener = vp->get_listener(); + Listener3D *listener = vp->get_listener(); if (listener) { listener_node = listener; listener_is_camera = false; diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 5b4c865475..13e08339e2 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -31,16 +31,16 @@ #ifndef AUDIO_STREAM_PLAYER_3D_H #define AUDIO_STREAM_PLAYER_3D_H -#include "scene/3d/spatial.h" -#include "scene/3d/spatial_velocity_tracker.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/velocity_tracker_3d.h" #include "servers/audio/audio_filter_sw.h" #include "servers/audio/audio_stream.h" #include "servers/audio_server.h" -class Camera; -class AudioStreamPlayer3D : public Spatial { +class Camera3D; +class AudioStreamPlayer3D : public Node3D { - GDCLASS(AudioStreamPlayer3D, Spatial); + GDCLASS(AudioStreamPlayer3D, Node3D); public: enum AttenuationModel { @@ -82,7 +82,7 @@ private: Output() { filter_gain = 0; - viewport = NULL; + viewport = nullptr; reverb_bus_index = -1; bus_index = -1; } @@ -134,7 +134,7 @@ private: float max_distance; - Ref<SpatialVelocityTracker> velocity_tracker; + Ref<VelocityTracker3D> velocity_tracker; DopplerTracking doppler_tracking; diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index 73b1d450f0..6bde56104e 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -39,7 +39,7 @@ void BakedLightmapData::set_bounds(const AABB &p_bounds) { bounds = p_bounds; - VS::get_singleton()->lightmap_capture_set_bounds(baked_light, p_bounds); + RS::get_singleton()->lightmap_capture_set_bounds(baked_light, p_bounds); } AABB BakedLightmapData::get_bounds() const { @@ -49,18 +49,18 @@ AABB BakedLightmapData::get_bounds() const { void BakedLightmapData::set_octree(const Vector<uint8_t> &p_octree) { - VS::get_singleton()->lightmap_capture_set_octree(baked_light, p_octree); + RS::get_singleton()->lightmap_capture_set_octree(baked_light, p_octree); } Vector<uint8_t> BakedLightmapData::get_octree() const { - return VS::get_singleton()->lightmap_capture_get_octree(baked_light); + return RS::get_singleton()->lightmap_capture_get_octree(baked_light); } void BakedLightmapData::set_cell_space_transform(const Transform &p_xform) { cell_space_xform = p_xform; - VS::get_singleton()->lightmap_capture_set_octree_cell_transform(baked_light, p_xform); + RS::get_singleton()->lightmap_capture_set_octree_cell_transform(baked_light, p_xform); } Transform BakedLightmapData::get_cell_space_transform() const { @@ -69,7 +69,7 @@ Transform BakedLightmapData::get_cell_space_transform() const { void BakedLightmapData::set_cell_subdiv(int p_cell_subdiv) { cell_subdiv = p_cell_subdiv; - VS::get_singleton()->lightmap_capture_set_octree_cell_subdiv(baked_light, p_cell_subdiv); + RS::get_singleton()->lightmap_capture_set_octree_cell_subdiv(baked_light, p_cell_subdiv); } int BakedLightmapData::get_cell_subdiv() const { @@ -79,7 +79,7 @@ int BakedLightmapData::get_cell_subdiv() const { void BakedLightmapData::set_energy(float p_energy) { energy = p_energy; - VS::get_singleton()->lightmap_capture_set_energy(baked_light, energy); + RS::get_singleton()->lightmap_capture_set_energy(baked_light, energy); } float BakedLightmapData::get_energy() const { @@ -181,21 +181,21 @@ void BakedLightmapData::_bind_methods() { BakedLightmapData::BakedLightmapData() { - baked_light = VS::get_singleton()->lightmap_capture_create(); + baked_light = RS::get_singleton()->lightmap_capture_create(); energy = 1; cell_subdiv = 1; } BakedLightmapData::~BakedLightmapData() { - VS::get_singleton()->free(baked_light); + RS::get_singleton()->free(baked_light); } /////////////////////////// -BakedLightmap::BakeBeginFunc BakedLightmap::bake_begin_function = NULL; -BakedLightmap::BakeStepFunc BakedLightmap::bake_step_function = NULL; -BakedLightmap::BakeEndFunc BakedLightmap::bake_end_function = NULL; +BakedLightmap::BakeBeginFunc BakedLightmap::bake_begin_function = nullptr; +BakedLightmap::BakeStepFunc BakedLightmap::bake_step_function = nullptr; +BakedLightmap::BakeEndFunc BakedLightmap::bake_end_function = nullptr; void BakedLightmap::set_bake_cell_size(float p_cell_size) { bake_cell_size = p_cell_size; @@ -425,13 +425,13 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi pmc++; PlotLight pl = E->get(); switch (pl.light->get_light_type()) { - case VS::LIGHT_DIRECTIONAL: { + case RS::LIGHT_DIRECTIONAL: { baker.plot_light_directional(-pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_bake_mode() == Light::BAKE_ALL); } break; - case VS::LIGHT_OMNI: { + case RS::LIGHT_OMNI: { baker.plot_light_omni(pl.local_xform.origin, pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL); } break; - case VS::LIGHT_SPOT: { + case RS::LIGHT_SPOT: { baker.plot_light_spot(pl.local_xform.origin, pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_param(Light::PARAM_SPOT_ANGLE), pl.light->get_param(Light::PARAM_SPOT_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL); } break; @@ -675,12 +675,12 @@ void BakedLightmap::_assign_lightmaps() { if (instance_idx >= 0) { RID instance = node->call("get_bake_mesh_instance", instance_idx); if (instance.is_valid()) { - VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid()); + RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid()); } } else { VisualInstance *vi = Object::cast_to<VisualInstance>(node); ERR_CONTINUE(!vi); - VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); + RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid()); } } } @@ -693,12 +693,12 @@ void BakedLightmap::_clear_lightmaps() { if (instance_idx >= 0) { RID instance = node->call("get_bake_mesh_instance", instance_idx); if (instance.is_valid()) { - VS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID()); + RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID()); } } else { VisualInstance *vi = Object::cast_to<VisualInstance>(node); ERR_CONTINUE(!vi); - VS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID()); + RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID()); } } } diff --git a/scene/3d/bone_attachment.cpp b/scene/3d/bone_attachment_3d.cpp index b1cd9bfe8b..825cb39e2d 100644 --- a/scene/3d/bone_attachment.cpp +++ b/scene/3d/bone_attachment_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* bone_attachment.cpp */ +/* bone_attachment_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "bone_attachment.h" +#include "bone_attachment_3d.h" -void BoneAttachment::_validate_property(PropertyInfo &property) const { +void BoneAttachment3D::_validate_property(PropertyInfo &property) const { if (property.name == "bone_name") { - Skeleton *parent = Object::cast_to<Skeleton>(get_parent()); + Skeleton3D *parent = Object::cast_to<Skeleton3D>(get_parent()); if (parent) { @@ -54,9 +54,9 @@ void BoneAttachment::_validate_property(PropertyInfo &property) const { } } -void BoneAttachment::_check_bind() { +void BoneAttachment3D::_check_bind() { - Skeleton *sk = Object::cast_to<Skeleton>(get_parent()); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(get_parent()); if (sk) { int idx = sk->find_bone(bone_name); @@ -68,11 +68,11 @@ void BoneAttachment::_check_bind() { } } -void BoneAttachment::_check_unbind() { +void BoneAttachment3D::_check_unbind() { if (bound) { - Skeleton *sk = Object::cast_to<Skeleton>(get_parent()); + Skeleton3D *sk = Object::cast_to<Skeleton3D>(get_parent()); if (sk) { int idx = sk->find_bone(bone_name); @@ -84,7 +84,7 @@ void BoneAttachment::_check_unbind() { } } -void BoneAttachment::set_bone_name(const String &p_name) { +void BoneAttachment3D::set_bone_name(const String &p_name) { if (is_inside_tree()) _check_unbind(); @@ -95,12 +95,12 @@ void BoneAttachment::set_bone_name(const String &p_name) { _check_bind(); } -String BoneAttachment::get_bone_name() const { +String BoneAttachment3D::get_bone_name() const { return bone_name; } -void BoneAttachment::_notification(int p_what) { +void BoneAttachment3D::_notification(int p_what) { switch (p_what) { @@ -115,13 +115,13 @@ void BoneAttachment::_notification(int p_what) { } } -BoneAttachment::BoneAttachment() { +BoneAttachment3D::BoneAttachment3D() { bound = false; } -void BoneAttachment::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment::set_bone_name); - ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment::get_bone_name); +void BoneAttachment3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_bone_name", "bone_name"), &BoneAttachment3D::set_bone_name); + ClassDB::bind_method(D_METHOD("get_bone_name"), &BoneAttachment3D::get_bone_name); ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bone_name"), "set_bone_name", "get_bone_name"); } diff --git a/scene/3d/bone_attachment.h b/scene/3d/bone_attachment_3d.h index 43c46dd759..d2a3ffec90 100644 --- a/scene/3d/bone_attachment.h +++ b/scene/3d/bone_attachment_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* bone_attachment.h */ +/* bone_attachment_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef BONE_ATTACHMENT_H #define BONE_ATTACHMENT_H -#include "scene/3d/skeleton.h" +#include "scene/3d/skeleton_3d.h" -class BoneAttachment : public Spatial { +class BoneAttachment3D : public Node3D { - GDCLASS(BoneAttachment, Spatial); + GDCLASS(BoneAttachment3D, Node3D); bool bound; String bone_name; @@ -53,7 +53,7 @@ public: void set_bone_name(const String &p_name); String get_bone_name() const; - BoneAttachment(); + BoneAttachment3D(); }; #endif // BONE_ATTACHMENT_H diff --git a/scene/3d/camera.cpp b/scene/3d/camera_3d.cpp index 741712025c..706c49b43b 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* camera.cpp */ +/* camera_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,22 +28,22 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "camera.h" +#include "camera_3d.h" -#include "collision_object.h" +#include "collision_object_3d.h" #include "core/engine.h" #include "core/math/camera_matrix.h" #include "scene/resources/material.h" #include "scene/resources/surface_tool.h" -void Camera::_update_audio_listener_state() { +void Camera3D::_update_audio_listener_state() { } -void Camera::_request_camera_update() { +void Camera3D::_request_camera_update() { _update_camera(); } -void Camera::_update_camera_mode() { +void Camera3D::_update_camera_mode() { force_change = true; switch (mode) { @@ -61,7 +61,7 @@ void Camera::_update_camera_mode() { } } -void Camera::_validate_property(PropertyInfo &p_property) const { +void Camera3D::_validate_property(PropertyInfo &p_property) const { if (p_property.name == "fov") { if (mode != PROJECTION_PERSPECTIVE) { p_property.usage = PROPERTY_USAGE_NOEDITOR; @@ -77,12 +77,12 @@ void Camera::_validate_property(PropertyInfo &p_property) const { } } -void Camera::_update_camera() { +void Camera3D::_update_camera() { if (!is_inside_tree()) return; - VisualServer::get_singleton()->camera_set_transform(camera, get_camera_transform()); + RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform()); // here goes listener stuff /* @@ -100,7 +100,7 @@ void Camera::_update_camera() { } } -void Camera::_notification(int p_what) { +void Camera3D::_notification(int p_what) { switch (p_what) { @@ -138,7 +138,7 @@ void Camera::_notification(int p_what) { if (viewport) { viewport->_camera_remove(this); - viewport = NULL; + viewport = nullptr; } } break; @@ -155,7 +155,7 @@ void Camera::_notification(int p_what) { } } -Transform Camera::get_camera_transform() const { +Transform Camera3D::get_camera_transform() const { Transform tr = get_global_transform().orthonormalized(); tr.origin += tr.basis.get_axis(1) * v_offset; @@ -163,7 +163,7 @@ Transform Camera::get_camera_transform() const { return tr; } -void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) { +void Camera3D::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far) { if (!force_change && fov == p_fovy_degrees && p_z_near == near && p_z_far == far && mode == PROJECTION_PERSPECTIVE) return; @@ -173,11 +173,11 @@ void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far far = p_z_far; mode = PROJECTION_PERSPECTIVE; - VisualServer::get_singleton()->camera_set_perspective(camera, fov, near, far); + RenderingServer::get_singleton()->camera_set_perspective(camera, fov, near, far); update_gizmo(); force_change = false; } -void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { +void Camera3D::set_orthogonal(float p_size, float p_z_near, float p_z_far) { if (!force_change && size == p_size && p_z_near == near && p_z_far == far && mode == PROJECTION_ORTHOGONAL) return; @@ -189,11 +189,11 @@ void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) { mode = PROJECTION_ORTHOGONAL; force_change = false; - VisualServer::get_singleton()->camera_set_orthogonal(camera, size, near, far); + RenderingServer::get_singleton()->camera_set_orthogonal(camera, size, near, far); update_gizmo(); } -void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { +void Camera3D::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) { if (!force_change && size == p_size && frustum_offset == p_offset && p_z_near == near && p_z_far == far && mode == PROJECTION_FRUSTUM) return; @@ -205,11 +205,11 @@ void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p mode = PROJECTION_FRUSTUM; force_change = false; - VisualServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far); + RenderingServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far); update_gizmo(); } -void Camera::set_projection(Camera::Projection p_mode) { +void Camera3D::set_projection(Camera3D::Projection p_mode) { if (p_mode == PROJECTION_PERSPECTIVE || p_mode == PROJECTION_ORTHOGONAL || p_mode == PROJECTION_FRUSTUM) { mode = p_mode; _update_camera_mode(); @@ -217,12 +217,12 @@ void Camera::set_projection(Camera::Projection p_mode) { } } -RID Camera::get_camera() const { +RID Camera3D::get_camera() const { return camera; }; -void Camera::make_current() { +void Camera3D::make_current() { current = true; @@ -234,14 +234,14 @@ void Camera::make_current() { //get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,camera_group,"_camera_make_current",this); } -void Camera::clear_current(bool p_enable_next) { +void Camera3D::clear_current(bool p_enable_next) { current = false; if (!is_inside_tree()) return; if (get_viewport()->get_camera() == this) { - get_viewport()->_camera_set(NULL); + get_viewport()->_camera_set(nullptr); if (p_enable_next) { get_viewport()->_camera_make_next_current(this); @@ -249,7 +249,7 @@ void Camera::clear_current(bool p_enable_next) { } } -void Camera::set_current(bool p_current) { +void Camera3D::set_current(bool p_current) { if (p_current) { make_current(); } else { @@ -257,7 +257,7 @@ void Camera::set_current(bool p_current) { } } -bool Camera::is_current() const { +bool Camera3D::is_current() const { if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { @@ -266,18 +266,18 @@ bool Camera::is_current() const { return current; } -bool Camera::_can_gizmo_scale() const { +bool Camera3D::_can_gizmo_scale() const { return false; } -Vector3 Camera::project_ray_normal(const Point2 &p_pos) const { +Vector3 Camera3D::project_ray_normal(const Point2 &p_pos) const { Vector3 ray = project_local_ray_normal(p_pos); return get_camera_transform().basis.xform(ray).normalized(); }; -Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const { +Vector3 Camera3D::project_local_ray_normal(const Point2 &p_pos) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -298,7 +298,7 @@ Vector3 Camera::project_local_ray_normal(const Point2 &p_pos) const { return ray; }; -Vector3 Camera::project_ray_origin(const Point2 &p_pos) const { +Vector3 Camera3D::project_ray_origin(const Point2 &p_pos) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -330,14 +330,14 @@ Vector3 Camera::project_ray_origin(const Point2 &p_pos) const { }; }; -bool Camera::is_position_behind(const Vector3 &p_pos) const { +bool Camera3D::is_position_behind(const Vector3 &p_pos) const { Transform t = get_global_transform(); Vector3 eyedir = -get_global_transform().basis.get_axis(2).normalized(); return eyedir.dot(p_pos) < (eyedir.dot(t.origin) + near); } -Vector<Vector3> Camera::get_near_plane_points() const { +Vector<Vector3> Camera3D::get_near_plane_points() const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector<Vector3>(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; @@ -360,7 +360,7 @@ Vector<Vector3> Camera::get_near_plane_points() const { return points; } -Point2 Camera::unproject_position(const Vector3 &p_pos) const { +Point2 Camera3D::unproject_position(const Vector3 &p_pos) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); @@ -385,7 +385,7 @@ Point2 Camera::unproject_position(const Vector3 &p_pos) const { return res; } -Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { +Vector3 Camera3D::project_position(const Point2 &p_point, float p_z_depth) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -413,66 +413,49 @@ Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { return get_camera_transform().xform(p); } -/* -void Camera::_camera_make_current(Node *p_camera) { - - - if (p_camera==this) { - VisualServer::get_singleton()->viewport_attach_camera(viewport_id,camera); - active=true; - } else { - if (active && p_camera==NULL) { - //detech camera because no one else will claim it - VisualServer::get_singleton()->viewport_attach_camera(viewport_id,RID()); - } - active=false; - } -} -*/ - -void Camera::set_environment(const Ref<Environment> &p_environment) { +void Camera3D::set_environment(const Ref<Environment> &p_environment) { environment = p_environment; if (environment.is_valid()) - VS::get_singleton()->camera_set_environment(camera, environment->get_rid()); + RS::get_singleton()->camera_set_environment(camera, environment->get_rid()); else - VS::get_singleton()->camera_set_environment(camera, RID()); + RS::get_singleton()->camera_set_environment(camera, RID()); _update_camera_mode(); } -Ref<Environment> Camera::get_environment() const { +Ref<Environment> Camera3D::get_environment() const { return environment; } -void Camera::set_effects(const Ref<CameraEffects> &p_effects) { +void Camera3D::set_effects(const Ref<CameraEffects> &p_effects) { effects = p_effects; if (effects.is_valid()) - VS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid()); + RS::get_singleton()->camera_set_camera_effects(camera, effects->get_rid()); else - VS::get_singleton()->camera_set_camera_effects(camera, RID()); + RS::get_singleton()->camera_set_camera_effects(camera, RID()); _update_camera_mode(); } -Ref<CameraEffects> Camera::get_effects() const { +Ref<CameraEffects> Camera3D::get_effects() const { return effects; } -void Camera::set_keep_aspect_mode(KeepAspect p_aspect) { +void Camera3D::set_keep_aspect_mode(KeepAspect p_aspect) { keep_aspect = p_aspect; - VisualServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH); + RenderingServer::get_singleton()->camera_set_use_vertical_aspect(camera, p_aspect == KEEP_WIDTH); _update_camera_mode(); _change_notify(); } -Camera::KeepAspect Camera::get_keep_aspect_mode() const { +Camera3D::KeepAspect Camera3D::get_keep_aspect_mode() const { return keep_aspect; } -void Camera::set_doppler_tracking(DopplerTracking p_tracking) { +void Camera3D::set_doppler_tracking(DopplerTracking p_tracking) { if (doppler_tracking == p_tracking) return; @@ -487,57 +470,57 @@ void Camera::set_doppler_tracking(DopplerTracking p_tracking) { _update_camera_mode(); } -Camera::DopplerTracking Camera::get_doppler_tracking() const { +Camera3D::DopplerTracking Camera3D::get_doppler_tracking() const { return doppler_tracking; } -void Camera::_bind_methods() { - - ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera::project_ray_normal); - ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera::project_local_ray_normal); - ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera::project_ray_origin); - ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera::unproject_position); - ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera::is_position_behind); - ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera::project_position); - ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera::set_perspective); - ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera::set_orthogonal); - ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera::set_frustum); - ClassDB::bind_method(D_METHOD("make_current"), &Camera::make_current); - ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera::clear_current, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("set_current"), &Camera::set_current); - ClassDB::bind_method(D_METHOD("is_current"), &Camera::is_current); - ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera::get_camera_transform); - ClassDB::bind_method(D_METHOD("get_fov"), &Camera::get_fov); - ClassDB::bind_method(D_METHOD("get_frustum_offset"), &Camera::get_frustum_offset); - ClassDB::bind_method(D_METHOD("get_size"), &Camera::get_size); - ClassDB::bind_method(D_METHOD("get_zfar"), &Camera::get_zfar); - ClassDB::bind_method(D_METHOD("get_znear"), &Camera::get_znear); - ClassDB::bind_method(D_METHOD("set_fov"), &Camera::set_fov); - ClassDB::bind_method(D_METHOD("set_frustum_offset"), &Camera::set_frustum_offset); - ClassDB::bind_method(D_METHOD("set_size"), &Camera::set_size); - ClassDB::bind_method(D_METHOD("set_zfar"), &Camera::set_zfar); - ClassDB::bind_method(D_METHOD("set_znear"), &Camera::set_znear); - ClassDB::bind_method(D_METHOD("get_projection"), &Camera::get_projection); - ClassDB::bind_method(D_METHOD("set_projection"), &Camera::set_projection); - ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera::set_h_offset); - ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera::get_h_offset); - ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera::set_v_offset); - ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera::get_v_offset); - ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera::set_cull_mask); - ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera::get_cull_mask); - ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera::set_environment); - ClassDB::bind_method(D_METHOD("get_environment"), &Camera::get_environment); - ClassDB::bind_method(D_METHOD("set_effects", "env"), &Camera::set_effects); - ClassDB::bind_method(D_METHOD("get_effects"), &Camera::get_effects); - ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera::set_keep_aspect_mode); - ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera::get_keep_aspect_mode); - ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera::set_doppler_tracking); - ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera::get_doppler_tracking); - ClassDB::bind_method(D_METHOD("get_frustum"), &Camera::get_frustum); - ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera::get_camera); - - ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera::set_cull_mask_bit); - ClassDB::bind_method(D_METHOD("get_cull_mask_bit", "layer"), &Camera::get_cull_mask_bit); +void Camera3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("project_ray_normal", "screen_point"), &Camera3D::project_ray_normal); + ClassDB::bind_method(D_METHOD("project_local_ray_normal", "screen_point"), &Camera3D::project_local_ray_normal); + ClassDB::bind_method(D_METHOD("project_ray_origin", "screen_point"), &Camera3D::project_ray_origin); + ClassDB::bind_method(D_METHOD("unproject_position", "world_point"), &Camera3D::unproject_position); + ClassDB::bind_method(D_METHOD("is_position_behind", "world_point"), &Camera3D::is_position_behind); + ClassDB::bind_method(D_METHOD("project_position", "screen_point", "z_depth"), &Camera3D::project_position); + ClassDB::bind_method(D_METHOD("set_perspective", "fov", "z_near", "z_far"), &Camera3D::set_perspective); + ClassDB::bind_method(D_METHOD("set_orthogonal", "size", "z_near", "z_far"), &Camera3D::set_orthogonal); + ClassDB::bind_method(D_METHOD("set_frustum", "size", "offset", "z_near", "z_far"), &Camera3D::set_frustum); + ClassDB::bind_method(D_METHOD("make_current"), &Camera3D::make_current); + ClassDB::bind_method(D_METHOD("clear_current", "enable_next"), &Camera3D::clear_current, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_current"), &Camera3D::set_current); + ClassDB::bind_method(D_METHOD("is_current"), &Camera3D::is_current); + ClassDB::bind_method(D_METHOD("get_camera_transform"), &Camera3D::get_camera_transform); + ClassDB::bind_method(D_METHOD("get_fov"), &Camera3D::get_fov); + ClassDB::bind_method(D_METHOD("get_frustum_offset"), &Camera3D::get_frustum_offset); + ClassDB::bind_method(D_METHOD("get_size"), &Camera3D::get_size); + ClassDB::bind_method(D_METHOD("get_zfar"), &Camera3D::get_zfar); + ClassDB::bind_method(D_METHOD("get_znear"), &Camera3D::get_znear); + ClassDB::bind_method(D_METHOD("set_fov"), &Camera3D::set_fov); + ClassDB::bind_method(D_METHOD("set_frustum_offset"), &Camera3D::set_frustum_offset); + ClassDB::bind_method(D_METHOD("set_size"), &Camera3D::set_size); + ClassDB::bind_method(D_METHOD("set_zfar"), &Camera3D::set_zfar); + ClassDB::bind_method(D_METHOD("set_znear"), &Camera3D::set_znear); + ClassDB::bind_method(D_METHOD("get_projection"), &Camera3D::get_projection); + ClassDB::bind_method(D_METHOD("set_projection"), &Camera3D::set_projection); + ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera3D::set_h_offset); + ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera3D::get_h_offset); + ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera3D::set_v_offset); + ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera3D::get_v_offset); + ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Camera3D::set_cull_mask); + ClassDB::bind_method(D_METHOD("get_cull_mask"), &Camera3D::get_cull_mask); + ClassDB::bind_method(D_METHOD("set_environment", "env"), &Camera3D::set_environment); + ClassDB::bind_method(D_METHOD("get_environment"), &Camera3D::get_environment); + ClassDB::bind_method(D_METHOD("set_effects", "env"), &Camera3D::set_effects); + ClassDB::bind_method(D_METHOD("get_effects"), &Camera3D::get_effects); + ClassDB::bind_method(D_METHOD("set_keep_aspect_mode", "mode"), &Camera3D::set_keep_aspect_mode); + ClassDB::bind_method(D_METHOD("get_keep_aspect_mode"), &Camera3D::get_keep_aspect_mode); + ClassDB::bind_method(D_METHOD("set_doppler_tracking", "mode"), &Camera3D::set_doppler_tracking); + ClassDB::bind_method(D_METHOD("get_doppler_tracking"), &Camera3D::get_doppler_tracking); + ClassDB::bind_method(D_METHOD("get_frustum"), &Camera3D::get_frustum); + ClassDB::bind_method(D_METHOD("get_camera_rid"), &Camera3D::get_camera); + + ClassDB::bind_method(D_METHOD("set_cull_mask_bit", "layer", "enable"), &Camera3D::set_cull_mask_bit); + ClassDB::bind_method(D_METHOD("get_cull_mask_bit", "layer"), &Camera3D::get_cull_mask_bit); //ClassDB::bind_method(D_METHOD("_camera_make_current"),&Camera::_camera_make_current ); @@ -568,76 +551,76 @@ void Camera::_bind_methods() { BIND_ENUM_CONSTANT(DOPPLER_TRACKING_PHYSICS_STEP); } -float Camera::get_fov() const { +float Camera3D::get_fov() const { return fov; } -float Camera::get_size() const { +float Camera3D::get_size() const { return size; } -float Camera::get_znear() const { +float Camera3D::get_znear() const { return near; } -Vector2 Camera::get_frustum_offset() const { +Vector2 Camera3D::get_frustum_offset() const { return frustum_offset; } -float Camera::get_zfar() const { +float Camera3D::get_zfar() const { return far; } -Camera::Projection Camera::get_projection() const { +Camera3D::Projection Camera3D::get_projection() const { return mode; } -void Camera::set_fov(float p_fov) { +void Camera3D::set_fov(float p_fov) { ERR_FAIL_COND(p_fov < 1 || p_fov > 179); fov = p_fov; _update_camera_mode(); _change_notify("fov"); } -void Camera::set_size(float p_size) { +void Camera3D::set_size(float p_size) { ERR_FAIL_COND(p_size < 0.1 || p_size > 16384); size = p_size; _update_camera_mode(); _change_notify("size"); } -void Camera::set_znear(float p_znear) { +void Camera3D::set_znear(float p_znear) { near = p_znear; _update_camera_mode(); } -void Camera::set_frustum_offset(Vector2 p_offset) { +void Camera3D::set_frustum_offset(Vector2 p_offset) { frustum_offset = p_offset; _update_camera_mode(); } -void Camera::set_zfar(float p_zfar) { +void Camera3D::set_zfar(float p_zfar) { far = p_zfar; _update_camera_mode(); } -void Camera::set_cull_mask(uint32_t p_layers) { +void Camera3D::set_cull_mask(uint32_t p_layers) { layers = p_layers; - VisualServer::get_singleton()->camera_set_cull_mask(camera, layers); + RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); _update_camera_mode(); } -uint32_t Camera::get_cull_mask() const { +uint32_t Camera3D::get_cull_mask() const { return layers; } -void Camera::set_cull_mask_bit(int p_layer, bool p_enable) { +void Camera3D::set_cull_mask_bit(int p_layer, bool p_enable) { ERR_FAIL_INDEX(p_layer, 32); if (p_enable) { set_cull_mask(layers | (1 << p_layer)); @@ -646,12 +629,12 @@ void Camera::set_cull_mask_bit(int p_layer, bool p_enable) { } } -bool Camera::get_cull_mask_bit(int p_layer) const { +bool Camera3D::get_cull_mask_bit(int p_layer) const { ERR_FAIL_INDEX_V(p_layer, 32, false); return (layers & (1 << p_layer)); } -Vector<Plane> Camera::get_frustum() const { +Vector<Plane> Camera3D::get_frustum() const { ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); @@ -665,28 +648,28 @@ Vector<Plane> Camera::get_frustum() const { return cm.get_projection_planes(get_camera_transform()); } -void Camera::set_v_offset(float p_offset) { +void Camera3D::set_v_offset(float p_offset) { v_offset = p_offset; _update_camera(); } -float Camera::get_v_offset() const { +float Camera3D::get_v_offset() const { return v_offset; } -void Camera::set_h_offset(float p_offset) { +void Camera3D::set_h_offset(float p_offset) { h_offset = p_offset; _update_camera(); } -float Camera::get_h_offset() const { +float Camera3D::get_h_offset() const { return h_offset; } -Vector3 Camera::get_doppler_tracked_velocity() const { +Vector3 Camera3D::get_doppler_tracked_velocity() const { if (doppler_tracking != DOPPLER_TRACKING_DISABLED) { return velocity_tracker->get_tracked_linear_velocity(); @@ -694,16 +677,16 @@ Vector3 Camera::get_doppler_tracked_velocity() const { return Vector3(); } } -Camera::Camera() { +Camera3D::Camera3D() { - camera = VisualServer::get_singleton()->camera_create(); + camera = RenderingServer::get_singleton()->camera_create(); size = 1; fov = 0; frustum_offset = Vector2(); near = 0; far = 0; current = false; - viewport = NULL; + viewport = nullptr; force_change = false; mode = PROJECTION_PERSPECTIVE; set_perspective(70.0, 0.05, 100.0); @@ -711,7 +694,7 @@ Camera::Camera() { layers = 0xfffff; v_offset = 0; h_offset = 0; - VisualServer::get_singleton()->camera_set_cull_mask(camera, layers); + RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); //active=false; velocity_tracker.instance(); doppler_tracking = DOPPLER_TRACKING_DISABLED; @@ -719,20 +702,20 @@ Camera::Camera() { set_disable_scale(true); } -Camera::~Camera() { +Camera3D::~Camera3D() { - VisualServer::get_singleton()->free(camera); + RenderingServer::get_singleton()->free(camera); } //////////////////////////////////////// -void ClippedCamera::set_margin(float p_margin) { +void ClippedCamera3D::set_margin(float p_margin) { margin = p_margin; } -float ClippedCamera::get_margin() const { +float ClippedCamera3D::get_margin() const { return margin; } -void ClippedCamera::set_process_mode(ProcessMode p_mode) { +void ClippedCamera3D::set_process_mode(ProcessMode p_mode) { if (process_mode == p_mode) { return; @@ -741,26 +724,26 @@ void ClippedCamera::set_process_mode(ProcessMode p_mode) { set_process_internal(process_mode == CLIP_PROCESS_IDLE); set_physics_process_internal(process_mode == CLIP_PROCESS_PHYSICS); } -ClippedCamera::ProcessMode ClippedCamera::get_process_mode() const { +ClippedCamera3D::ProcessMode ClippedCamera3D::get_process_mode() const { return process_mode; } -Transform ClippedCamera::get_camera_transform() const { +Transform ClippedCamera3D::get_camera_transform() const { - Transform t = Camera::get_camera_transform(); + Transform t = Camera3D::get_camera_transform(); t.origin += -t.basis.get_axis(Vector3::AXIS_Z).normalized() * clip_offset; return t; } -void ClippedCamera::_notification(int p_what) { +void ClippedCamera3D::_notification(int p_what) { if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { - Spatial *parent = Object::cast_to<Spatial>(get_parent()); + Node3D *parent = Object::cast_to<Node3D>(get_parent()); if (!parent) { return; } - PhysicsDirectSpaceState *dspace = get_world()->get_direct_space_state(); + PhysicsDirectSpaceState3D *dspace = get_world()->get_direct_space_state(); ERR_FAIL_COND(!dspace); // most likely physics set to threads Vector3 cam_fw = -get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized(); @@ -791,7 +774,7 @@ void ClippedCamera::_notification(int p_what) { } if (!all_equal) { - PhysicsServer::get_singleton()->shape_set_data(pyramid_shape, local_points); + PhysicsServer3D::get_singleton()->shape_set_data(pyramid_shape, local_points); points = local_points; } } @@ -813,17 +796,17 @@ void ClippedCamera::_notification(int p_what) { } } -void ClippedCamera::set_collision_mask(uint32_t p_mask) { +void ClippedCamera3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; } -uint32_t ClippedCamera::get_collision_mask() const { +uint32_t ClippedCamera3D::get_collision_mask() const { return collision_mask; } -void ClippedCamera::set_collision_mask_bit(int p_bit, bool p_value) { +void ClippedCamera3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -833,98 +816,98 @@ void ClippedCamera::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool ClippedCamera::get_collision_mask_bit(int p_bit) const { +bool ClippedCamera3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void ClippedCamera::add_exception_rid(const RID &p_rid) { +void ClippedCamera3D::add_exception_rid(const RID &p_rid) { exclude.insert(p_rid); } -void ClippedCamera::add_exception(const Object *p_object) { +void ClippedCamera3D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; add_exception_rid(co->get_rid()); } -void ClippedCamera::remove_exception_rid(const RID &p_rid) { +void ClippedCamera3D::remove_exception_rid(const RID &p_rid) { exclude.erase(p_rid); } -void ClippedCamera::remove_exception(const Object *p_object) { +void ClippedCamera3D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; remove_exception_rid(co->get_rid()); } -void ClippedCamera::clear_exceptions() { +void ClippedCamera3D::clear_exceptions() { exclude.clear(); } -float ClippedCamera::get_clip_offset() const { +float ClippedCamera3D::get_clip_offset() const { return clip_offset; } -void ClippedCamera::set_clip_to_areas(bool p_clip) { +void ClippedCamera3D::set_clip_to_areas(bool p_clip) { clip_to_areas = p_clip; } -bool ClippedCamera::is_clip_to_areas_enabled() const { +bool ClippedCamera3D::is_clip_to_areas_enabled() const { return clip_to_areas; } -void ClippedCamera::set_clip_to_bodies(bool p_clip) { +void ClippedCamera3D::set_clip_to_bodies(bool p_clip) { clip_to_bodies = p_clip; } -bool ClippedCamera::is_clip_to_bodies_enabled() const { +bool ClippedCamera3D::is_clip_to_bodies_enabled() const { return clip_to_bodies; } -void ClippedCamera::_bind_methods() { +void ClippedCamera3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera::set_margin); - ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera::get_margin); + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &ClippedCamera3D::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &ClippedCamera3D::get_margin); - ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_mode", "process_mode"), &ClippedCamera3D::set_process_mode); + ClassDB::bind_method(D_METHOD("get_process_mode"), &ClippedCamera3D::get_process_mode); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &ClippedCamera3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &ClippedCamera3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &ClippedCamera3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &ClippedCamera3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera::add_exception_rid); - ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera::add_exception); + ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &ClippedCamera3D::add_exception_rid); + ClassDB::bind_method(D_METHOD("add_exception", "node"), &ClippedCamera3D::add_exception); - ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera::remove_exception_rid); - ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera::remove_exception); + ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &ClippedCamera3D::remove_exception_rid); + ClassDB::bind_method(D_METHOD("remove_exception", "node"), &ClippedCamera3D::remove_exception); - ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera::set_clip_to_areas); - ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera::is_clip_to_areas_enabled); + ClassDB::bind_method(D_METHOD("set_clip_to_areas", "enable"), &ClippedCamera3D::set_clip_to_areas); + ClassDB::bind_method(D_METHOD("is_clip_to_areas_enabled"), &ClippedCamera3D::is_clip_to_areas_enabled); - ClassDB::bind_method(D_METHOD("get_clip_offset"), &ClippedCamera::get_clip_offset); + ClassDB::bind_method(D_METHOD("get_clip_offset"), &ClippedCamera3D::get_clip_offset); - ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera::set_clip_to_bodies); - ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera::is_clip_to_bodies_enabled); + ClassDB::bind_method(D_METHOD("set_clip_to_bodies", "enable"), &ClippedCamera3D::set_clip_to_bodies); + ClassDB::bind_method(D_METHOD("is_clip_to_bodies_enabled"), &ClippedCamera3D::is_clip_to_bodies_enabled); - ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera::clear_exceptions); + ClassDB::bind_method(D_METHOD("clear_exceptions"), &ClippedCamera3D::clear_exceptions); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_margin", "get_margin"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_process_mode", "get_process_mode"); @@ -937,7 +920,7 @@ void ClippedCamera::_bind_methods() { BIND_ENUM_CONSTANT(CLIP_PROCESS_PHYSICS); BIND_ENUM_CONSTANT(CLIP_PROCESS_IDLE); } -ClippedCamera::ClippedCamera() { +ClippedCamera3D::ClippedCamera3D() { margin = 0; clip_offset = 0; process_mode = CLIP_PROCESS_PHYSICS; @@ -945,10 +928,10 @@ ClippedCamera::ClippedCamera() { collision_mask = 1; set_notify_local_transform(Engine::get_singleton()->is_editor_hint()); points.resize(5); - pyramid_shape = PhysicsServer::get_singleton()->shape_create(PhysicsServer::SHAPE_CONVEX_POLYGON); + pyramid_shape = PhysicsServer3D::get_singleton()->shape_create(PhysicsServer3D::SHAPE_CONVEX_POLYGON); clip_to_areas = false; clip_to_bodies = true; } -ClippedCamera::~ClippedCamera() { - PhysicsServer::get_singleton()->free(pyramid_shape); +ClippedCamera3D::~ClippedCamera3D() { + PhysicsServer3D::get_singleton()->free(pyramid_shape); } diff --git a/scene/3d/camera.h b/scene/3d/camera_3d.h index 6ac3ece798..9a005226cb 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* camera.h */ +/* camera_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,17 +28,17 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef CAMERA_H -#define CAMERA_H +#ifndef CAMERA_3D_H +#define CAMERA_3D_H -#include "scene/3d/spatial.h" -#include "scene/3d/spatial_velocity_tracker.h" -#include "scene/main/viewport.h" +#include "scene/3d/node_3d.h" +#include "scene/3d/velocity_tracker_3d.h" +#include "scene/main/window.h" #include "scene/resources/environment.h" -class Camera : public Spatial { +class Camera3D : public Node3D { - GDCLASS(Camera, Spatial); + GDCLASS(Camera3D, Node3D); public: enum Projection { @@ -48,10 +48,8 @@ public: PROJECTION_FRUSTUM }; - enum KeepAspect { - KEEP_WIDTH, - KEEP_HEIGHT - }; + enum KeepAspect { KEEP_WIDTH, + KEEP_HEIGHT }; enum DopplerTracking { DOPPLER_TRACKING_DISABLED, @@ -77,7 +75,7 @@ private: RID camera; RID scenario_id; - //String camera_group; + // String camera_group; uint32_t layers; @@ -86,12 +84,12 @@ private: virtual bool _can_gizmo_scale() const; - //void _camera_make_current(Node *p_camera); + // void _camera_make_current(Node *p_camera); friend class Viewport; void _update_audio_listener_state(); DopplerTracking doppler_tracking; - Ref<SpatialVelocityTracker> velocity_tracker; + Ref<VelocityTracker3D> velocity_tracker; protected: void _update_camera(); @@ -112,8 +110,9 @@ public: void set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far); void set_orthogonal(float p_size, float p_z_near, float p_z_far); - void set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far); - void set_projection(Camera::Projection p_mode); + void set_frustum(float p_size, Vector2 p_offset, float p_z_near, + float p_z_far); + void set_projection(Camera3D::Projection p_mode); void make_current(); void clear_current(bool p_enable_next = true); @@ -143,7 +142,8 @@ public: virtual Vector3 project_local_ray_normal(const Point2 &p_pos) const; virtual Point2 unproject_position(const Vector3 &p_pos) const; bool is_position_behind(const Vector3 &p_pos) const; - virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const; + virtual Vector3 project_position(const Point2 &p_point, + float p_z_depth) const; Vector<Vector3> get_near_plane_points() const; @@ -175,17 +175,17 @@ public: Vector3 get_doppler_tracked_velocity() const; - Camera(); - ~Camera(); + Camera3D(); + ~Camera3D(); }; -VARIANT_ENUM_CAST(Camera::Projection); -VARIANT_ENUM_CAST(Camera::KeepAspect); -VARIANT_ENUM_CAST(Camera::DopplerTracking); +VARIANT_ENUM_CAST(Camera3D::Projection); +VARIANT_ENUM_CAST(Camera3D::KeepAspect); +VARIANT_ENUM_CAST(Camera3D::DopplerTracking); -class ClippedCamera : public Camera { +class ClippedCamera3D : public Camera3D { - GDCLASS(ClippedCamera, Camera); + GDCLASS(ClippedCamera3D, Camera3D); public: enum ProcessMode { @@ -238,9 +238,9 @@ public: float get_clip_offset() const; - ClippedCamera(); - ~ClippedCamera(); + ClippedCamera3D(); + ~ClippedCamera3D(); }; -VARIANT_ENUM_CAST(ClippedCamera::ProcessMode); +VARIANT_ENUM_CAST(ClippedCamera3D::ProcessMode); #endif diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object_3d.cpp index c067ef34a6..e6cd7bfe7e 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_object.cpp */ +/* collision_object_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,27 +28,27 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collision_object.h" +#include "collision_object_3d.h" #include "scene/scene_string_names.h" -#include "servers/physics_server.h" +#include "servers/physics_server_3d.h" -void CollisionObject::_notification(int p_what) { +void CollisionObject3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { if (area) - PhysicsServer::get_singleton()->area_set_transform(rid, get_global_transform()); + PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform()); else - PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); + PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); RID space = get_world()->get_space(); if (area) { - PhysicsServer::get_singleton()->area_set_space(rid, space); + PhysicsServer3D::get_singleton()->area_set_space(rid, space); } else - PhysicsServer::get_singleton()->body_set_space(rid, space); + PhysicsServer3D::get_singleton()->body_set_space(rid, space); _update_pickable(); //get space @@ -57,9 +57,9 @@ void CollisionObject::_notification(int p_what) { case NOTIFICATION_TRANSFORM_CHANGED: { if (area) - PhysicsServer::get_singleton()->area_set_transform(rid, get_global_transform()); + PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform()); else - PhysicsServer::get_singleton()->body_set_state(rid, PhysicsServer::BODY_STATE_TRANSFORM, get_global_transform()); + PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -70,15 +70,15 @@ void CollisionObject::_notification(int p_what) { case NOTIFICATION_EXIT_WORLD: { if (area) { - PhysicsServer::get_singleton()->area_set_space(rid, RID()); + PhysicsServer3D::get_singleton()->area_set_space(rid, RID()); } else - PhysicsServer::get_singleton()->body_set_space(rid, RID()); + PhysicsServer3D::get_singleton()->body_set_space(rid, RID()); } break; } } -void CollisionObject::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { +void CollisionObject3D::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); @@ -86,7 +86,7 @@ void CollisionObject::_input_event(Node *p_camera, const Ref<InputEvent> &p_inpu emit_signal(SceneStringNames::get_singleton()->input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); } -void CollisionObject::_mouse_enter() { +void CollisionObject3D::_mouse_enter() { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter); @@ -94,7 +94,7 @@ void CollisionObject::_mouse_enter() { emit_signal(SceneStringNames::get_singleton()->mouse_entered); } -void CollisionObject::_mouse_exit() { +void CollisionObject3D::_mouse_exit() { if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit); @@ -102,50 +102,50 @@ void CollisionObject::_mouse_exit() { emit_signal(SceneStringNames::get_singleton()->mouse_exited); } -void CollisionObject::_update_pickable() { +void CollisionObject3D::_update_pickable() { if (!is_inside_tree()) return; bool pickable = ray_pickable && is_visible_in_tree(); if (area) - PhysicsServer::get_singleton()->area_set_ray_pickable(rid, pickable); + PhysicsServer3D::get_singleton()->area_set_ray_pickable(rid, pickable); else - PhysicsServer::get_singleton()->body_set_ray_pickable(rid, pickable); + PhysicsServer3D::get_singleton()->body_set_ray_pickable(rid, pickable); } -void CollisionObject::set_ray_pickable(bool p_ray_pickable) { +void CollisionObject3D::set_ray_pickable(bool p_ray_pickable) { ray_pickable = p_ray_pickable; _update_pickable(); } -bool CollisionObject::is_ray_pickable() const { +bool CollisionObject3D::is_ray_pickable() const { return ray_pickable; } -void CollisionObject::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject::set_ray_pickable); - ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject::is_ray_pickable); - ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject::set_capture_input_on_drag); - ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"), &CollisionObject::get_capture_input_on_drag); - ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject::get_rid); - ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject::create_shape_owner); - ClassDB::bind_method(D_METHOD("remove_shape_owner", "owner_id"), &CollisionObject::remove_shape_owner); - ClassDB::bind_method(D_METHOD("get_shape_owners"), &CollisionObject::_get_shape_owners); - ClassDB::bind_method(D_METHOD("shape_owner_set_transform", "owner_id", "transform"), &CollisionObject::shape_owner_set_transform); - ClassDB::bind_method(D_METHOD("shape_owner_get_transform", "owner_id"), &CollisionObject::shape_owner_get_transform); - ClassDB::bind_method(D_METHOD("shape_owner_get_owner", "owner_id"), &CollisionObject::shape_owner_get_owner); - ClassDB::bind_method(D_METHOD("shape_owner_set_disabled", "owner_id", "disabled"), &CollisionObject::shape_owner_set_disabled); - ClassDB::bind_method(D_METHOD("is_shape_owner_disabled", "owner_id"), &CollisionObject::is_shape_owner_disabled); - ClassDB::bind_method(D_METHOD("shape_owner_add_shape", "owner_id", "shape"), &CollisionObject::shape_owner_add_shape); - ClassDB::bind_method(D_METHOD("shape_owner_get_shape_count", "owner_id"), &CollisionObject::shape_owner_get_shape_count); - ClassDB::bind_method(D_METHOD("shape_owner_get_shape", "owner_id", "shape_id"), &CollisionObject::shape_owner_get_shape); - ClassDB::bind_method(D_METHOD("shape_owner_get_shape_index", "owner_id", "shape_id"), &CollisionObject::shape_owner_get_shape_index); - ClassDB::bind_method(D_METHOD("shape_owner_remove_shape", "owner_id", "shape_id"), &CollisionObject::shape_owner_remove_shape); - ClassDB::bind_method(D_METHOD("shape_owner_clear_shapes", "owner_id"), &CollisionObject::shape_owner_clear_shapes); - ClassDB::bind_method(D_METHOD("shape_find_owner", "shape_index"), &CollisionObject::shape_find_owner); +void CollisionObject3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject3D::set_ray_pickable); + ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject3D::is_ray_pickable); + ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject3D::set_capture_input_on_drag); + ClassDB::bind_method(D_METHOD("get_capture_input_on_drag"), &CollisionObject3D::get_capture_input_on_drag); + ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject3D::get_rid); + ClassDB::bind_method(D_METHOD("create_shape_owner", "owner"), &CollisionObject3D::create_shape_owner); + ClassDB::bind_method(D_METHOD("remove_shape_owner", "owner_id"), &CollisionObject3D::remove_shape_owner); + ClassDB::bind_method(D_METHOD("get_shape_owners"), &CollisionObject3D::_get_shape_owners); + ClassDB::bind_method(D_METHOD("shape_owner_set_transform", "owner_id", "transform"), &CollisionObject3D::shape_owner_set_transform); + ClassDB::bind_method(D_METHOD("shape_owner_get_transform", "owner_id"), &CollisionObject3D::shape_owner_get_transform); + ClassDB::bind_method(D_METHOD("shape_owner_get_owner", "owner_id"), &CollisionObject3D::shape_owner_get_owner); + ClassDB::bind_method(D_METHOD("shape_owner_set_disabled", "owner_id", "disabled"), &CollisionObject3D::shape_owner_set_disabled); + ClassDB::bind_method(D_METHOD("is_shape_owner_disabled", "owner_id"), &CollisionObject3D::is_shape_owner_disabled); + ClassDB::bind_method(D_METHOD("shape_owner_add_shape", "owner_id", "shape"), &CollisionObject3D::shape_owner_add_shape); + ClassDB::bind_method(D_METHOD("shape_owner_get_shape_count", "owner_id"), &CollisionObject3D::shape_owner_get_shape_count); + ClassDB::bind_method(D_METHOD("shape_owner_get_shape", "owner_id", "shape_id"), &CollisionObject3D::shape_owner_get_shape); + ClassDB::bind_method(D_METHOD("shape_owner_get_shape_index", "owner_id", "shape_id"), &CollisionObject3D::shape_owner_get_shape_index); + ClassDB::bind_method(D_METHOD("shape_owner_remove_shape", "owner_id", "shape_id"), &CollisionObject3D::shape_owner_remove_shape); + ClassDB::bind_method(D_METHOD("shape_owner_clear_shapes", "owner_id"), &CollisionObject3D::shape_owner_clear_shapes); + ClassDB::bind_method(D_METHOD("shape_find_owner", "shape_index"), &CollisionObject3D::shape_find_owner); BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "camera"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::VECTOR3, "click_position"), PropertyInfo(Variant::VECTOR3, "click_normal"), PropertyInfo(Variant::INT, "shape_idx"))); @@ -157,7 +157,7 @@ void CollisionObject::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_capture_on_drag"), "set_capture_input_on_drag", "get_capture_input_on_drag"); } -uint32_t CollisionObject::create_shape_owner(Object *p_owner) { +uint32_t CollisionObject3D::create_shape_owner(Object *p_owner) { ShapeData sd; uint32_t id; @@ -175,7 +175,7 @@ uint32_t CollisionObject::create_shape_owner(Object *p_owner) { return id; } -void CollisionObject::remove_shape_owner(uint32_t owner) { +void CollisionObject3D::remove_shape_owner(uint32_t owner) { ERR_FAIL_COND(!shapes.has(owner)); @@ -184,35 +184,35 @@ void CollisionObject::remove_shape_owner(uint32_t owner) { shapes.erase(owner); } -void CollisionObject::shape_owner_set_disabled(uint32_t p_owner, bool p_disabled) { +void CollisionObject3D::shape_owner_set_disabled(uint32_t p_owner, bool p_disabled) { ERR_FAIL_COND(!shapes.has(p_owner)); ShapeData &sd = shapes[p_owner]; sd.disabled = p_disabled; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - PhysicsServer::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); + PhysicsServer3D::get_singleton()->area_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); } else { - PhysicsServer::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); + PhysicsServer3D::get_singleton()->body_set_shape_disabled(rid, sd.shapes[i].index, p_disabled); } } } -bool CollisionObject::is_shape_owner_disabled(uint32_t p_owner) const { +bool CollisionObject3D::is_shape_owner_disabled(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), false); return shapes[p_owner].disabled; } -void CollisionObject::get_shape_owners(List<uint32_t> *r_owners) { +void CollisionObject3D::get_shape_owners(List<uint32_t> *r_owners) { for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { r_owners->push_back(E->key()); } } -Array CollisionObject::_get_shape_owners() { +Array CollisionObject3D::_get_shape_owners() { Array ret; for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { @@ -222,7 +222,7 @@ Array CollisionObject::_get_shape_owners() { return ret; } -void CollisionObject::shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform) { +void CollisionObject3D::shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform) { ERR_FAIL_COND(!shapes.has(p_owner)); @@ -230,27 +230,27 @@ void CollisionObject::shape_owner_set_transform(uint32_t p_owner, const Transfor sd.xform = p_transform; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - PhysicsServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, p_transform); + PhysicsServer3D::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, p_transform); } else { - PhysicsServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, p_transform); + PhysicsServer3D::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, p_transform); } } } -Transform CollisionObject::shape_owner_get_transform(uint32_t p_owner) const { +Transform CollisionObject3D::shape_owner_get_transform(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), Transform()); return shapes[p_owner].xform; } -Object *CollisionObject::shape_owner_get_owner(uint32_t p_owner) const { +Object *CollisionObject3D::shape_owner_get_owner(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), NULL); + ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr); return shapes[p_owner].owner; } -void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape) { +void CollisionObject3D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3D> &p_shape) { ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_COND(p_shape.is_null()); @@ -260,28 +260,28 @@ void CollisionObject::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> & s.index = total_subshapes; s.shape = p_shape; if (area) { - PhysicsServer::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); + PhysicsServer3D::get_singleton()->area_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); } else { - PhysicsServer::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); + PhysicsServer3D::get_singleton()->body_add_shape(rid, p_shape->get_rid(), sd.xform, sd.disabled); } sd.shapes.push_back(s); total_subshapes++; } -int CollisionObject::shape_owner_get_shape_count(uint32_t p_owner) const { +int CollisionObject3D::shape_owner_get_shape_count(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), 0); return shapes[p_owner].shapes.size(); } -Ref<Shape> CollisionObject::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { +Ref<Shape3D> CollisionObject3D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape>()); - ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape>()); + ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape3D>()); + ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape3D>()); return shapes[p_owner].shapes[p_shape].shape; } -int CollisionObject::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { +int CollisionObject3D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { ERR_FAIL_COND_V(!shapes.has(p_owner), -1); ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), -1); @@ -289,16 +289,16 @@ int CollisionObject::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) return shapes[p_owner].shapes[p_shape].index; } -void CollisionObject::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { +void CollisionObject3D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_INDEX(p_shape, shapes[p_owner].shapes.size()); int index_to_remove = shapes[p_owner].shapes[p_shape].index; if (area) { - PhysicsServer::get_singleton()->area_remove_shape(rid, index_to_remove); + PhysicsServer3D::get_singleton()->area_remove_shape(rid, index_to_remove); } else { - PhysicsServer::get_singleton()->body_remove_shape(rid, index_to_remove); + PhysicsServer3D::get_singleton()->body_remove_shape(rid, index_to_remove); } shapes[p_owner].shapes.remove(p_shape); @@ -314,7 +314,7 @@ void CollisionObject::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { total_subshapes--; } -void CollisionObject::shape_owner_clear_shapes(uint32_t p_owner) { +void CollisionObject3D::shape_owner_clear_shapes(uint32_t p_owner) { ERR_FAIL_COND(!shapes.has(p_owner)); @@ -323,7 +323,7 @@ void CollisionObject::shape_owner_clear_shapes(uint32_t p_owner) { } } -uint32_t CollisionObject::shape_find_owner(int p_shape_index) const { +uint32_t CollisionObject3D::shape_find_owner(int p_shape_index) const { ERR_FAIL_INDEX_V(p_shape_index, total_subshapes, 0); @@ -339,7 +339,7 @@ uint32_t CollisionObject::shape_find_owner(int p_shape_index) const { return 0; } -CollisionObject::CollisionObject(RID p_rid, bool p_area) { +CollisionObject3D::CollisionObject3D(RID p_rid, bool p_area) { rid = p_rid; area = p_area; @@ -349,38 +349,38 @@ CollisionObject::CollisionObject(RID p_rid, bool p_area) { total_subshapes = 0; if (p_area) { - PhysicsServer::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer3D::get_singleton()->area_attach_object_instance_id(rid, get_instance_id()); } else { - PhysicsServer::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); + PhysicsServer3D::get_singleton()->body_attach_object_instance_id(rid, get_instance_id()); } //set_transform_notify(true); } -void CollisionObject::set_capture_input_on_drag(bool p_capture) { +void CollisionObject3D::set_capture_input_on_drag(bool p_capture) { capture_input_on_drag = p_capture; } -bool CollisionObject::get_capture_input_on_drag() const { +bool CollisionObject3D::get_capture_input_on_drag() const { return capture_input_on_drag; } -String CollisionObject::get_configuration_warning() const { +String CollisionObject3D::get_configuration_warning() const { - String warning = Spatial::get_configuration_warning(); + String warning = Node3D::get_configuration_warning(); if (shapes.empty()) { if (!warning.empty()) { warning += "\n\n"; } - warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape or CollisionPolygon as a child to define its shape."); + warning += TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape3D or CollisionPolygon3D as a child to define its shape."); } return warning; } -CollisionObject::CollisionObject() { +CollisionObject3D::CollisionObject3D() { capture_input_on_drag = false; ray_pickable = true; @@ -390,7 +390,7 @@ CollisionObject::CollisionObject() { //set_transform_notify(true); } -CollisionObject::~CollisionObject() { +CollisionObject3D::~CollisionObject3D() { - PhysicsServer::get_singleton()->free(rid); + PhysicsServer3D::get_singleton()->free(rid); } diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object_3d.h index 572e73d51b..67d3aed3c8 100644 --- a/scene/3d/collision_object.h +++ b/scene/3d/collision_object_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_object.h */ +/* collision_object_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COLLISION_OBJECT_H -#define COLLISION_OBJECT_H +#ifndef COLLISION_OBJECT_3D_H +#define COLLISION_OBJECT_3D_H -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" +#include "scene/3d/node_3d.h" +#include "scene/resources/shape_3d.h" -class CollisionObject : public Spatial { +class CollisionObject3D : public Node3D { - GDCLASS(CollisionObject, Spatial); + GDCLASS(CollisionObject3D, Node3D); bool area; @@ -47,7 +47,7 @@ class CollisionObject : public Spatial { Object *owner; Transform xform; struct ShapeBase { - Ref<Shape> shape; + Ref<Shape3D> shape; int index; }; @@ -56,7 +56,7 @@ class CollisionObject : public Spatial { ShapeData() { disabled = false; - owner = NULL; + owner = nullptr; } }; @@ -70,7 +70,7 @@ class CollisionObject : public Spatial { void _update_pickable(); protected: - CollisionObject(RID p_rid, bool p_area); + CollisionObject3D(RID p_rid, bool p_area); void _notification(int p_what); static void _bind_methods(); @@ -92,9 +92,9 @@ public: void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled); bool is_shape_owner_disabled(uint32_t p_owner) const; - void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape> &p_shape); + void shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3D> &p_shape); int shape_owner_get_shape_count(uint32_t p_owner) const; - Ref<Shape> shape_owner_get_shape(uint32_t p_owner, int p_shape) const; + Ref<Shape3D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const; int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const; void shape_owner_remove_shape(uint32_t p_owner, int p_shape); @@ -112,8 +112,8 @@ public: virtual String get_configuration_warning() const; - CollisionObject(); - ~CollisionObject(); + CollisionObject3D(); + ~CollisionObject3D(); }; #endif // COLLISION_OBJECT__H diff --git a/scene/3d/collision_polygon.cpp b/scene/3d/collision_polygon_3d.cpp index 24c3a9eb41..66bd903eeb 100644 --- a/scene/3d/collision_polygon.cpp +++ b/scene/3d/collision_polygon_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_polygon.cpp */ +/* collision_polygon_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collision_polygon.h" +#include "collision_polygon_3d.h" -#include "collision_object.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" +#include "collision_object_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" -void CollisionPolygon::_build_polygon() { +void CollisionPolygon3D::_build_polygon() { if (!parent) return; @@ -52,7 +52,7 @@ void CollisionPolygon::_build_polygon() { //decompose concave into multiple convex polygons and add them for (int i = 0; i < decomp.size(); i++) { - Ref<ConvexPolygonShape> convex = memnew(ConvexPolygonShape); + Ref<ConvexPolygonShape3D> convex = memnew(ConvexPolygonShape3D); Vector<Vector3> cp; int cs = decomp[i].size(); cp.resize(cs * 2); @@ -73,7 +73,7 @@ void CollisionPolygon::_build_polygon() { } } -void CollisionPolygon::_update_in_shape_owner(bool p_xform_only) { +void CollisionPolygon3D::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) @@ -81,12 +81,12 @@ void CollisionPolygon::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_disabled(owner_id, disabled); } -void CollisionPolygon::_notification(int p_what) { +void CollisionPolygon3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to<CollisionObject>(get_parent()); + parent = Object::cast_to<CollisionObject3D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); _build_polygon(); @@ -112,12 +112,12 @@ void CollisionPolygon::_notification(int p_what) { parent->remove_shape_owner(owner_id); } owner_id = 0; - parent = NULL; + parent = nullptr; } break; } } -void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) { +void CollisionPolygon3D::set_polygon(const Vector<Point2> &p_polygon) { polygon = p_polygon; if (parent) { @@ -127,29 +127,29 @@ void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) { update_gizmo(); } -Vector<Point2> CollisionPolygon::get_polygon() const { +Vector<Point2> CollisionPolygon3D::get_polygon() const { return polygon; } -AABB CollisionPolygon::get_item_rect() const { +AABB CollisionPolygon3D::get_item_rect() const { return aabb; } -void CollisionPolygon::set_depth(float p_depth) { +void CollisionPolygon3D::set_depth(float p_depth) { depth = p_depth; _build_polygon(); update_gizmo(); } -float CollisionPolygon::get_depth() const { +float CollisionPolygon3D::get_depth() const { return depth; } -void CollisionPolygon::set_disabled(bool p_disabled) { +void CollisionPolygon3D::set_disabled(bool p_disabled) { disabled = p_disabled; update_gizmo(); @@ -158,50 +158,50 @@ void CollisionPolygon::set_disabled(bool p_disabled) { } } -bool CollisionPolygon::is_disabled() const { +bool CollisionPolygon3D::is_disabled() const { return disabled; } -String CollisionPolygon::get_configuration_warning() const { +String CollisionPolygon3D::get_configuration_warning() const { - if (!Object::cast_to<CollisionObject>(get_parent())) { - return TTR("CollisionPolygon only serves to provide a collision shape to a CollisionObject derived node. Please only use it as a child of Area, StaticBody, RigidBody, KinematicBody, etc. to give them a shape."); + if (!Object::cast_to<CollisionObject3D>(get_parent())) { + return 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, KinematicBody3D, etc. to give them a shape."); } if (polygon.empty()) { - return TTR("An empty CollisionPolygon has no effect on collision."); + return TTR("An empty CollisionPolygon3D has no effect on collision."); } return String(); } -bool CollisionPolygon::_is_editable_3d_polygon() const { +bool CollisionPolygon3D::_is_editable_3d_polygon() const { return true; } -void CollisionPolygon::_bind_methods() { +void CollisionPolygon3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_depth", "depth"), &CollisionPolygon::set_depth); - ClassDB::bind_method(D_METHOD("get_depth"), &CollisionPolygon::get_depth); + ClassDB::bind_method(D_METHOD("set_depth", "depth"), &CollisionPolygon3D::set_depth); + ClassDB::bind_method(D_METHOD("get_depth"), &CollisionPolygon3D::get_depth); - ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon::set_polygon); - ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon::get_polygon); + ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon3D::set_polygon); + ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon3D::get_polygon); - ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &CollisionPolygon::set_disabled); - ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionPolygon::is_disabled); + ClassDB::bind_method(D_METHOD("set_disabled", "disabled"), &CollisionPolygon3D::set_disabled); + ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionPolygon3D::is_disabled); - ClassDB::bind_method(D_METHOD("_is_editable_3d_polygon"), &CollisionPolygon::_is_editable_3d_polygon); + ClassDB::bind_method(D_METHOD("_is_editable_3d_polygon"), &CollisionPolygon3D::_is_editable_3d_polygon); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "depth"), "set_depth", "get_depth"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon"); } -CollisionPolygon::CollisionPolygon() { +CollisionPolygon3D::CollisionPolygon3D() { aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); depth = 1.0; set_notify_local_transform(true); - parent = NULL; + parent = nullptr; owner_id = 0; disabled = false; } diff --git a/scene/3d/collision_polygon.h b/scene/3d/collision_polygon_3d.h index 9ecdc02697..256aee3d7e 100644 --- a/scene/3d/collision_polygon.h +++ b/scene/3d/collision_polygon_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_polygon.h */ +/* collision_polygon_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,16 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef COLLISION_POLYGON_H -#define COLLISION_POLYGON_H +#ifndef COLLISION_POLYGON_3D_H +#define COLLISION_POLYGON_3D_H -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" +#include "scene/3d/node_3d.h" +#include "scene/resources/shape_3d.h" -class CollisionObject; -class CollisionPolygon : public Spatial { +class CollisionObject3D; +class CollisionPolygon3D : public Node3D { - GDCLASS(CollisionPolygon, Spatial); + GDCLASS(CollisionPolygon3D, Node3D); protected: float depth; @@ -45,7 +45,7 @@ protected: Vector<Point2> polygon; uint32_t owner_id; - CollisionObject *parent; + CollisionObject3D *parent; bool disabled; @@ -73,7 +73,7 @@ public: String get_configuration_warning() const; - CollisionPolygon(); + CollisionPolygon3D(); }; #endif // COLLISION_POLYGON_H diff --git a/scene/3d/collision_shape.cpp b/scene/3d/collision_shape_3d.cpp index d825c8daf7..a66e84ac3c 100644 --- a/scene/3d/collision_shape.cpp +++ b/scene/3d/collision_shape_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_shape.cpp */ +/* collision_shape_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,21 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "collision_shape.h" -#include "scene/resources/box_shape.h" -#include "scene/resources/capsule_shape.h" -#include "scene/resources/concave_polygon_shape.h" -#include "scene/resources/convex_polygon_shape.h" -#include "scene/resources/ray_shape.h" -#include "scene/resources/sphere_shape.h" -#include "scene/resources/world_margin_shape.h" -#include "servers/visual_server.h" -//TODO: Implement CylinderShape and HeightMapShape? +#include "collision_shape_3d.h" + #include "core/math/quick_hull.h" -#include "mesh_instance.h" -#include "physics_body.h" +#include "mesh_instance_3d.h" +#include "physics_body_3d.h" +#include "scene/resources/box_shape_3d.h" +#include "scene/resources/capsule_shape_3d.h" +#include "scene/resources/concave_polygon_shape_3d.h" +#include "scene/resources/convex_polygon_shape_3d.h" +#include "scene/resources/ray_shape_3d.h" +#include "scene/resources/sphere_shape_3d.h" +#include "scene/resources/world_margin_shape_3d.h" +#include "servers/rendering_server.h" + +//TODO: Implement CylinderShape and HeightMapShape? -void CollisionShape::make_convex_from_brothers() { +void CollisionShape3D::make_convex_from_brothers() { Node *p = get_parent(); if (!p) @@ -51,32 +53,32 @@ void CollisionShape::make_convex_from_brothers() { for (int i = 0; i < p->get_child_count(); i++) { Node *n = p->get_child(i); - MeshInstance *mi = Object::cast_to<MeshInstance>(n); + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(n); if (mi) { Ref<Mesh> m = mi->get_mesh(); if (m.is_valid()) { - Ref<Shape> s = m->create_convex_shape(); + Ref<Shape3D> s = m->create_convex_shape(); set_shape(s); } } } } -void CollisionShape::_update_in_shape_owner(bool p_xform_only) { +void CollisionShape3D::_update_in_shape_owner(bool p_xform_only) { parent->shape_owner_set_transform(owner_id, get_transform()); if (p_xform_only) return; parent->shape_owner_set_disabled(owner_id, disabled); } -void CollisionShape::_notification(int p_what) { +void CollisionShape3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_PARENTED: { - parent = Object::cast_to<CollisionObject>(get_parent()); + parent = Object::cast_to<CollisionObject3D>(get_parent()); if (parent) { owner_id = parent->create_shape_owner(this); if (shape.is_valid()) { @@ -103,30 +105,30 @@ void CollisionShape::_notification(int p_what) { parent->remove_shape_owner(owner_id); } owner_id = 0; - parent = NULL; + parent = nullptr; } break; } } -void CollisionShape::resource_changed(RES res) { +void CollisionShape3D::resource_changed(RES res) { update_gizmo(); } -String CollisionShape::get_configuration_warning() const { +String CollisionShape3D::get_configuration_warning() const { - if (!Object::cast_to<CollisionObject>(get_parent())) { - return TTR("CollisionShape only serves to provide a collision shape to a CollisionObject derived node. Please only use it as a child of Area, StaticBody, RigidBody, KinematicBody, etc. to give them a shape."); + if (!Object::cast_to<CollisionObject3D>(get_parent())) { + return 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, KinematicBody3D, etc. to give them a shape."); } if (!shape.is_valid()) { - return TTR("A shape must be provided for CollisionShape to function. Please create a shape resource for it."); + return TTR("A shape must be provided for CollisionShape3D to function. Please create a shape resource for it."); } - if (Object::cast_to<RigidBody>(get_parent())) { - if (Object::cast_to<ConcavePolygonShape>(*shape)) { - if (Object::cast_to<RigidBody>(get_parent())->get_mode() != RigidBody::MODE_STATIC) { - return TTR("ConcavePolygonShape doesn't support RigidBody in another mode than static."); + if (Object::cast_to<RigidBody3D>(get_parent())) { + if (Object::cast_to<ConcavePolygonShape3D>(*shape)) { + if (Object::cast_to<RigidBody3D>(get_parent())->get_mode() != RigidBody3D::MODE_STATIC) { + return TTR("ConcavePolygonShape3D doesn't support RigidBody3D in another mode than static."); } } } @@ -134,33 +136,33 @@ String CollisionShape::get_configuration_warning() const { return String(); } -void CollisionShape::_bind_methods() { +void CollisionShape3D::_bind_methods() { //not sure if this should do anything - ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &CollisionShape::resource_changed); - ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape::set_shape); - ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape::get_shape); - ClassDB::bind_method(D_METHOD("set_disabled", "enable"), &CollisionShape::set_disabled); - ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionShape::is_disabled); - ClassDB::bind_method(D_METHOD("make_convex_from_brothers"), &CollisionShape::make_convex_from_brothers); - ClassDB::set_method_flags("CollisionShape", "make_convex_from_brothers", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("resource_changed", "resource"), &CollisionShape3D::resource_changed); + ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape3D::set_shape); + ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape3D::get_shape); + ClassDB::bind_method(D_METHOD("set_disabled", "enable"), &CollisionShape3D::set_disabled); + ClassDB::bind_method(D_METHOD("is_disabled"), &CollisionShape3D::is_disabled); + ClassDB::bind_method(D_METHOD("make_convex_from_brothers"), &CollisionShape3D::make_convex_from_brothers); + ClassDB::set_method_flags("CollisionShape3D", "make_convex_from_brothers", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); - ClassDB::bind_method(D_METHOD("_update_debug_shape"), &CollisionShape::_update_debug_shape); + ClassDB::bind_method(D_METHOD("_update_debug_shape"), &CollisionShape3D::_update_debug_shape); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disabled"), "set_disabled", "is_disabled"); } -void CollisionShape::set_shape(const Ref<Shape> &p_shape) { +void CollisionShape3D::set_shape(const Ref<Shape3D> &p_shape) { if (!shape.is_null()) { shape->unregister_owner(this); - shape->disconnect("changed", callable_mp(this, &CollisionShape::_shape_changed)); + shape->disconnect("changed", callable_mp(this, &CollisionShape3D::_shape_changed)); } shape = p_shape; if (!shape.is_null()) { shape->register_owner(this); - shape->connect("changed", callable_mp(this, &CollisionShape::_shape_changed)); + shape->connect("changed", callable_mp(this, &CollisionShape3D::_shape_changed)); } update_gizmo(); if (parent) { @@ -175,12 +177,12 @@ void CollisionShape::set_shape(const Ref<Shape> &p_shape) { update_configuration_warning(); } -Ref<Shape> CollisionShape::get_shape() const { +Ref<Shape3D> CollisionShape3D::get_shape() const { return shape; } -void CollisionShape::set_disabled(bool p_disabled) { +void CollisionShape3D::set_disabled(bool p_disabled) { disabled = p_disabled; update_gizmo(); @@ -189,47 +191,47 @@ void CollisionShape::set_disabled(bool p_disabled) { } } -bool CollisionShape::is_disabled() const { +bool CollisionShape3D::is_disabled() const { return disabled; } -CollisionShape::CollisionShape() { +CollisionShape3D::CollisionShape3D() { - //indicator = VisualServer::get_singleton()->mesh_create(); + //indicator = RenderingServer::get_singleton()->mesh_create(); disabled = false; - debug_shape = NULL; - parent = NULL; + debug_shape = nullptr; + parent = nullptr; owner_id = 0; set_notify_local_transform(true); } -CollisionShape::~CollisionShape() { +CollisionShape3D::~CollisionShape3D() { if (!shape.is_null()) shape->unregister_owner(this); - //VisualServer::get_singleton()->free(indicator); + //RenderingServer::get_singleton()->free(indicator); } -void CollisionShape::_update_debug_shape() { +void CollisionShape3D::_update_debug_shape() { debug_shape_dirty = false; if (debug_shape) { debug_shape->queue_delete(); - debug_shape = NULL; + debug_shape = nullptr; } - Ref<Shape> s = get_shape(); + Ref<Shape3D> s = get_shape(); if (s.is_null()) return; Ref<Mesh> mesh = s->get_debug_mesh(); - MeshInstance *mi = memnew(MeshInstance); + MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(mesh); add_child(mi); debug_shape = mi; } -void CollisionShape::_shape_changed() { +void CollisionShape3D::_shape_changed() { // If this is a heightfield shape our center may have changed if (parent) { _update_in_shape_owner(true); diff --git a/scene/3d/collision_shape.h b/scene/3d/collision_shape_3d.h index 3150a41ebf..8515d292af 100644 --- a/scene/3d/collision_shape.h +++ b/scene/3d/collision_shape_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* collision_shape.h */ +/* collision_shape_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,18 +31,18 @@ #ifndef COLLISION_SHAPE_H #define COLLISION_SHAPE_H -#include "scene/3d/spatial.h" -#include "scene/resources/shape.h" -class CollisionObject; -class CollisionShape : public Spatial { +#include "scene/3d/node_3d.h" +#include "scene/resources/shape_3d.h" +class CollisionObject3D; +class CollisionShape3D : public Node3D { - GDCLASS(CollisionShape, Spatial); + GDCLASS(CollisionShape3D, Node3D); OBJ_CATEGORY("3D Physics Nodes"); - Ref<Shape> shape; + Ref<Shape3D> shape; uint32_t owner_id; - CollisionObject *parent; + CollisionObject3D *parent; Node *debug_shape; bool debug_shape_dirty; @@ -63,16 +63,16 @@ protected: public: void make_convex_from_brothers(); - void set_shape(const Ref<Shape> &p_shape); - Ref<Shape> get_shape() const; + void set_shape(const Ref<Shape3D> &p_shape); + Ref<Shape3D> get_shape() const; void set_disabled(bool p_disabled); bool is_disabled() const; String get_configuration_warning() const; - CollisionShape(); - ~CollisionShape(); + CollisionShape3D(); + ~CollisionShape3D(); }; #endif // BODY_VOLUME_H diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles_3d.cpp index bde578d0af..12c105b0f4 100644 --- a/scene/3d/cpu_particles.cpp +++ b/scene/3d/cpu_particles_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cpu_particles.cpp */ +/* cpu_particles_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,23 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "cpu_particles.h" +#include "cpu_particles_3d.h" -#include "scene/3d/camera.h" -#include "scene/3d/particles.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/gpu_particles_3d.h" #include "scene/resources/particles_material.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -AABB CPUParticles::get_aabb() const { +AABB CPUParticles3D::get_aabb() const { return AABB(); } -Vector<Face3> CPUParticles::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> CPUParticles3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void CPUParticles::set_emitting(bool p_emitting) { +void CPUParticles3D::set_emitting(bool p_emitting) { if (emitting == p_emitting) return; @@ -59,7 +59,7 @@ void CPUParticles::set_emitting(bool p_emitting) { } } -void CPUParticles::set_amount(int p_amount) { +void CPUParticles3D::set_amount(int p_amount) { ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles must be greater than 0."); @@ -73,132 +73,132 @@ void CPUParticles::set_amount(int p_amount) { } particle_data.resize((12 + 4 + 4) * p_amount); - VS::get_singleton()->multimesh_allocate(multimesh, p_amount, VS::MULTIMESH_TRANSFORM_3D, true, true); + RS::get_singleton()->multimesh_allocate(multimesh, p_amount, RS::MULTIMESH_TRANSFORM_3D, true, true); particle_order.resize(p_amount); } -void CPUParticles::set_lifetime(float p_lifetime) { +void CPUParticles3D::set_lifetime(float p_lifetime) { ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; } -void CPUParticles::set_one_shot(bool p_one_shot) { +void CPUParticles3D::set_one_shot(bool p_one_shot) { one_shot = p_one_shot; } -void CPUParticles::set_pre_process_time(float p_time) { +void CPUParticles3D::set_pre_process_time(float p_time) { pre_process_time = p_time; } -void CPUParticles::set_explosiveness_ratio(float p_ratio) { +void CPUParticles3D::set_explosiveness_ratio(float p_ratio) { explosiveness_ratio = p_ratio; } -void CPUParticles::set_randomness_ratio(float p_ratio) { +void CPUParticles3D::set_randomness_ratio(float p_ratio) { randomness_ratio = p_ratio; } -void CPUParticles::set_lifetime_randomness(float p_random) { +void CPUParticles3D::set_lifetime_randomness(float p_random) { lifetime_randomness = p_random; } -void CPUParticles::set_use_local_coordinates(bool p_enable) { +void CPUParticles3D::set_use_local_coordinates(bool p_enable) { local_coords = p_enable; } -void CPUParticles::set_speed_scale(float p_scale) { +void CPUParticles3D::set_speed_scale(float p_scale) { speed_scale = p_scale; } -bool CPUParticles::is_emitting() const { +bool CPUParticles3D::is_emitting() const { return emitting; } -int CPUParticles::get_amount() const { +int CPUParticles3D::get_amount() const { return particles.size(); } -float CPUParticles::get_lifetime() const { +float CPUParticles3D::get_lifetime() const { return lifetime; } -bool CPUParticles::get_one_shot() const { +bool CPUParticles3D::get_one_shot() const { return one_shot; } -float CPUParticles::get_pre_process_time() const { +float CPUParticles3D::get_pre_process_time() const { return pre_process_time; } -float CPUParticles::get_explosiveness_ratio() const { +float CPUParticles3D::get_explosiveness_ratio() const { return explosiveness_ratio; } -float CPUParticles::get_randomness_ratio() const { +float CPUParticles3D::get_randomness_ratio() const { return randomness_ratio; } -float CPUParticles::get_lifetime_randomness() const { +float CPUParticles3D::get_lifetime_randomness() const { return lifetime_randomness; } -bool CPUParticles::get_use_local_coordinates() const { +bool CPUParticles3D::get_use_local_coordinates() const { return local_coords; } -float CPUParticles::get_speed_scale() const { +float CPUParticles3D::get_speed_scale() const { return speed_scale; } -void CPUParticles::set_draw_order(DrawOrder p_order) { +void CPUParticles3D::set_draw_order(DrawOrder p_order) { draw_order = p_order; } -CPUParticles::DrawOrder CPUParticles::get_draw_order() const { +CPUParticles3D::DrawOrder CPUParticles3D::get_draw_order() const { return draw_order; } -void CPUParticles::set_mesh(const Ref<Mesh> &p_mesh) { +void CPUParticles3D::set_mesh(const Ref<Mesh> &p_mesh) { mesh = p_mesh; if (mesh.is_valid()) { - VS::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); + RS::get_singleton()->multimesh_set_mesh(multimesh, mesh->get_rid()); } else { - VS::get_singleton()->multimesh_set_mesh(multimesh, RID()); + RS::get_singleton()->multimesh_set_mesh(multimesh, RID()); } } -Ref<Mesh> CPUParticles::get_mesh() const { +Ref<Mesh> CPUParticles3D::get_mesh() const { return mesh; } -void CPUParticles::set_fixed_fps(int p_count) { +void CPUParticles3D::set_fixed_fps(int p_count) { fixed_fps = p_count; } -int CPUParticles::get_fixed_fps() const { +int CPUParticles3D::get_fixed_fps() const { return fixed_fps; } -void CPUParticles::set_fractional_delta(bool p_enable) { +void CPUParticles3D::set_fractional_delta(bool p_enable) { fractional_delta = p_enable; } -bool CPUParticles::get_fractional_delta() const { +bool CPUParticles3D::get_fractional_delta() const { return fractional_delta; } -String CPUParticles::get_configuration_warning() const { +String CPUParticles3D::get_configuration_warning() const { String warnings; @@ -208,13 +208,13 @@ String CPUParticles::get_configuration_warning() const { if (get_mesh().is_valid()) { mesh_found = true; for (int j = 0; j < get_mesh()->get_surface_count(); j++) { - anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != NULL; + anim_material_found = Object::cast_to<ShaderMaterial>(get_mesh()->surface_get_material(j).ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_mesh()->surface_get_material(j).ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); } } - anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != NULL; + anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); @@ -228,13 +228,13 @@ String CPUParticles::get_configuration_warning() const { get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid())) { if (warnings != String()) warnings += "\n"; - warnings += "- " + TTR("CPUParticles animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."); + warnings += "- " + TTR("CPUParticles3D animation requires the usage of a StandardMaterial3D whose Billboard Mode is set to \"Particle Billboard\"."); } return warnings; } -void CPUParticles::restart() { +void CPUParticles3D::restart() { time = 0; inactive_time = 0; @@ -254,55 +254,55 @@ void CPUParticles::restart() { set_emitting(true); } -void CPUParticles::set_direction(Vector3 p_direction) { +void CPUParticles3D::set_direction(Vector3 p_direction) { direction = p_direction; } -Vector3 CPUParticles::get_direction() const { +Vector3 CPUParticles3D::get_direction() const { return direction; } -void CPUParticles::set_spread(float p_spread) { +void CPUParticles3D::set_spread(float p_spread) { spread = p_spread; } -float CPUParticles::get_spread() const { +float CPUParticles3D::get_spread() const { return spread; } -void CPUParticles::set_flatness(float p_flatness) { +void CPUParticles3D::set_flatness(float p_flatness) { flatness = p_flatness; } -float CPUParticles::get_flatness() const { +float CPUParticles3D::get_flatness() const { return flatness; } -void CPUParticles::set_param(Parameter p_param, float p_value) { +void CPUParticles3D::set_param(Parameter p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); parameters[p_param] = p_value; } -float CPUParticles::get_param(Parameter p_param) const { +float CPUParticles3D::get_param(Parameter p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return parameters[p_param]; } -void CPUParticles::set_param_randomness(Parameter p_param, float p_value) { +void CPUParticles3D::set_param_randomness(Parameter p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); randomness[p_param] = p_value; } -float CPUParticles::get_param_randomness(Parameter p_param) const { +float CPUParticles3D::get_param_randomness(Parameter p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); @@ -318,7 +318,7 @@ static void _adjust_curve_range(const Ref<Curve> &p_curve, float p_min, float p_ curve->ensure_default_setup(p_min, p_max); } -void CPUParticles::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) { +void CPUParticles3D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) { ERR_FAIL_INDEX(p_param, PARAM_MAX); @@ -364,34 +364,34 @@ void CPUParticles::set_param_curve(Parameter p_param, const Ref<Curve> &p_curve) } } } -Ref<Curve> CPUParticles::get_param_curve(Parameter p_param) const { +Ref<Curve> CPUParticles3D::get_param_curve(Parameter p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Curve>()); return curve_parameters[p_param]; } -void CPUParticles::set_color(const Color &p_color) { +void CPUParticles3D::set_color(const Color &p_color) { color = p_color; } -Color CPUParticles::get_color() const { +Color CPUParticles3D::get_color() const { return color; } -void CPUParticles::set_color_ramp(const Ref<Gradient> &p_ramp) { +void CPUParticles3D::set_color_ramp(const Ref<Gradient> &p_ramp) { color_ramp = p_ramp; } -Ref<Gradient> CPUParticles::get_color_ramp() const { +Ref<Gradient> CPUParticles3D::get_color_ramp() const { return color_ramp; } -void CPUParticles::set_particle_flag(Flags p_flag, bool p_enable) { +void CPUParticles3D::set_particle_flag(Flags p_flag, bool p_enable) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags[p_flag] = p_enable; if (p_flag == FLAG_DISABLE_Z) { @@ -399,77 +399,77 @@ void CPUParticles::set_particle_flag(Flags p_flag, bool p_enable) { } } -bool CPUParticles::get_particle_flag(Flags p_flag) const { +bool CPUParticles3D::get_particle_flag(Flags p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } -void CPUParticles::set_emission_shape(EmissionShape p_shape) { +void CPUParticles3D::set_emission_shape(EmissionShape p_shape) { ERR_FAIL_INDEX(p_shape, EMISSION_SHAPE_MAX); emission_shape = p_shape; } -void CPUParticles::set_emission_sphere_radius(float p_radius) { +void CPUParticles3D::set_emission_sphere_radius(float p_radius) { emission_sphere_radius = p_radius; } -void CPUParticles::set_emission_box_extents(Vector3 p_extents) { +void CPUParticles3D::set_emission_box_extents(Vector3 p_extents) { emission_box_extents = p_extents; } -void CPUParticles::set_emission_points(const Vector<Vector3> &p_points) { +void CPUParticles3D::set_emission_points(const Vector<Vector3> &p_points) { emission_points = p_points; } -void CPUParticles::set_emission_normals(const Vector<Vector3> &p_normals) { +void CPUParticles3D::set_emission_normals(const Vector<Vector3> &p_normals) { emission_normals = p_normals; } -void CPUParticles::set_emission_colors(const Vector<Color> &p_colors) { +void CPUParticles3D::set_emission_colors(const Vector<Color> &p_colors) { emission_colors = p_colors; } -float CPUParticles::get_emission_sphere_radius() const { +float CPUParticles3D::get_emission_sphere_radius() const { return emission_sphere_radius; } -Vector3 CPUParticles::get_emission_box_extents() const { +Vector3 CPUParticles3D::get_emission_box_extents() const { return emission_box_extents; } -Vector<Vector3> CPUParticles::get_emission_points() const { +Vector<Vector3> CPUParticles3D::get_emission_points() const { return emission_points; } -Vector<Vector3> CPUParticles::get_emission_normals() const { +Vector<Vector3> CPUParticles3D::get_emission_normals() const { return emission_normals; } -Vector<Color> CPUParticles::get_emission_colors() const { +Vector<Color> CPUParticles3D::get_emission_colors() const { return emission_colors; } -CPUParticles::EmissionShape CPUParticles::get_emission_shape() const { +CPUParticles3D::EmissionShape CPUParticles3D::get_emission_shape() const { return emission_shape; } -void CPUParticles::set_gravity(const Vector3 &p_gravity) { +void CPUParticles3D::set_gravity(const Vector3 &p_gravity) { gravity = p_gravity; } -Vector3 CPUParticles::get_gravity() const { +Vector3 CPUParticles3D::get_gravity() const { return gravity; } -void CPUParticles::_validate_property(PropertyInfo &property) const { +void CPUParticles3D::_validate_property(PropertyInfo &property) const { if (property.name == "color" && color_ramp.is_valid()) { property.usage = 0; @@ -517,7 +517,7 @@ static float rand_from_seed(uint32_t &seed) { return float(seed % uint32_t(65536)) / 65535.0; } -void CPUParticles::_update_internal() { +void CPUParticles3D::_update_internal() { if (particles.size() == 0 || !is_visible_in_tree()) { _set_redraw(false); @@ -592,7 +592,7 @@ void CPUParticles::_update_internal() { } } -void CPUParticles::_particles_process(float p_delta) { +void CPUParticles3D::_particles_process(float p_delta) { p_delta *= speed_scale; @@ -1016,13 +1016,13 @@ void CPUParticles::_particles_process(float p_delta) { } } -void CPUParticles::_update_particle_data_buffer() { +void CPUParticles3D::_update_particle_data_buffer() { MutexLock lock(update_mutex); int pc = particles.size(); int *ow; - int *order = NULL; + int *order = nullptr; float *w = particle_data.ptrw(); const Particle *r = particles.ptr(); @@ -1040,7 +1040,7 @@ void CPUParticles::_update_particle_data_buffer() { sorter.compare.particles = r; sorter.sort(order, pc); } else if (draw_order == DRAW_ORDER_VIEW_DEPTH) { - Camera *c = get_viewport()->get_camera(); + Camera3D *c = get_viewport()->get_camera(); if (c) { Vector3 dir = c->get_global_transform().basis.get_axis(2); //far away to close @@ -1106,7 +1106,7 @@ void CPUParticles::_update_particle_data_buffer() { can_update = true; } -void CPUParticles::_set_redraw(bool p_redraw) { +void CPUParticles3D::_set_redraw(bool p_redraw) { if (redraw == p_redraw) return; redraw = p_redraw; @@ -1115,30 +1115,30 @@ void CPUParticles::_set_redraw(bool p_redraw) { MutexLock lock(update_mutex); if (redraw) { - VS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles::_update_render_thread)); - VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); + RS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread)); + RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, true); + RS::get_singleton()->multimesh_set_visible_instances(multimesh, -1); } else { - if (VS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles::_update_render_thread))) { - VS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles::_update_render_thread)); + if (RS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread))) { + RS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &CPUParticles3D::_update_render_thread)); } - VS::get_singleton()->instance_geometry_set_flag(get_instance(), VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false); - VS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + RS::get_singleton()->instance_geometry_set_flag(get_instance(), RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, false); + RS::get_singleton()->multimesh_set_visible_instances(multimesh, 0); } } } -void CPUParticles::_update_render_thread() { +void CPUParticles3D::_update_render_thread() { MutexLock lock(update_mutex); if (can_update) { - VS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); + RS::get_singleton()->multimesh_set_buffer(multimesh, particle_data); can_update = false; //wait for next time } } -void CPUParticles::_notification(int p_what) { +void CPUParticles3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { set_process_internal(emitting); @@ -1203,10 +1203,10 @@ void CPUParticles::_notification(int p_what) { } } -void CPUParticles::convert_from_particles(Node *p_particles) { +void CPUParticles3D::convert_from_particles(Node *p_particles) { - Particles *particles = Object::cast_to<Particles>(p_particles); - ERR_FAIL_COND_MSG(!particles, "Only Particles nodes can be converted to CPUParticles."); + GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_particles); + ERR_FAIL_COND_MSG(!particles, "Only GPUParticles3D nodes can be converted to CPUParticles3D."); set_emitting(particles->is_emitting()); set_amount(particles->get_amount()); @@ -1272,42 +1272,42 @@ void CPUParticles::convert_from_particles(Node *p_particles) { #undef CONVERT_PARAM } -void CPUParticles::_bind_methods() { +void CPUParticles3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles::set_emitting); - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles::set_amount); - ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles::set_lifetime); - ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles::set_one_shot); - ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles::set_pre_process_time); - ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles::set_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles::set_randomness_ratio); - ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles::set_lifetime_randomness); - ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles::set_use_local_coordinates); - ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles::set_fixed_fps); - ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles::set_fractional_delta); - ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles::set_speed_scale); + ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &CPUParticles3D::set_emitting); + ClassDB::bind_method(D_METHOD("set_amount", "amount"), &CPUParticles3D::set_amount); + ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &CPUParticles3D::set_lifetime); + ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &CPUParticles3D::set_one_shot); + ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles3D::set_pre_process_time); + ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles3D::set_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles3D::set_randomness_ratio); + ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles3D::set_lifetime_randomness); + ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles3D::set_use_local_coordinates); + ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles3D::set_fixed_fps); + ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles3D::set_fractional_delta); + ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &CPUParticles3D::set_speed_scale); - ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles::is_emitting); - ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles::get_amount); - ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles::get_lifetime); - ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles::get_one_shot); - ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles::get_pre_process_time); - ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles::get_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles::get_randomness_ratio); - ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles::get_lifetime_randomness); - ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles::get_use_local_coordinates); - ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles::get_fixed_fps); - ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles::get_fractional_delta); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles::get_speed_scale); + ClassDB::bind_method(D_METHOD("is_emitting"), &CPUParticles3D::is_emitting); + ClassDB::bind_method(D_METHOD("get_amount"), &CPUParticles3D::get_amount); + ClassDB::bind_method(D_METHOD("get_lifetime"), &CPUParticles3D::get_lifetime); + ClassDB::bind_method(D_METHOD("get_one_shot"), &CPUParticles3D::get_one_shot); + ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles3D::get_pre_process_time); + ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles3D::get_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles3D::get_randomness_ratio); + ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles3D::get_lifetime_randomness); + ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles3D::get_use_local_coordinates); + ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles3D::get_fixed_fps); + ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles3D::get_fractional_delta); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &CPUParticles3D::get_speed_scale); - ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles::set_draw_order); + ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &CPUParticles3D::set_draw_order); - ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles::get_draw_order); + ClassDB::bind_method(D_METHOD("get_draw_order"), &CPUParticles3D::get_draw_order); - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CPUParticles::set_mesh); - ClassDB::bind_method(D_METHOD("get_mesh"), &CPUParticles::get_mesh); + ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CPUParticles3D::set_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &CPUParticles3D::get_mesh); - ClassDB::bind_method(D_METHOD("restart"), &CPUParticles::restart); + ClassDB::bind_method(D_METHOD("restart"), &CPUParticles3D::restart); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); @@ -1332,55 +1332,55 @@ void CPUParticles::_bind_methods() { //////////////////////////////// - ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles::set_direction); - ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles::get_direction); + ClassDB::bind_method(D_METHOD("set_direction", "direction"), &CPUParticles3D::set_direction); + ClassDB::bind_method(D_METHOD("get_direction"), &CPUParticles3D::get_direction); - ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles::set_spread); - ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles::get_spread); + ClassDB::bind_method(D_METHOD("set_spread", "degrees"), &CPUParticles3D::set_spread); + ClassDB::bind_method(D_METHOD("get_spread"), &CPUParticles3D::get_spread); - ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &CPUParticles::set_flatness); - ClassDB::bind_method(D_METHOD("get_flatness"), &CPUParticles::get_flatness); + ClassDB::bind_method(D_METHOD("set_flatness", "amount"), &CPUParticles3D::set_flatness); + ClassDB::bind_method(D_METHOD("get_flatness"), &CPUParticles3D::get_flatness); - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &CPUParticles::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &CPUParticles::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &CPUParticles3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &CPUParticles3D::get_param); - ClassDB::bind_method(D_METHOD("set_param_randomness", "param", "randomness"), &CPUParticles::set_param_randomness); - ClassDB::bind_method(D_METHOD("get_param_randomness", "param"), &CPUParticles::get_param_randomness); + ClassDB::bind_method(D_METHOD("set_param_randomness", "param", "randomness"), &CPUParticles3D::set_param_randomness); + ClassDB::bind_method(D_METHOD("get_param_randomness", "param"), &CPUParticles3D::get_param_randomness); - ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles::set_param_curve); - ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles::get_param_curve); + ClassDB::bind_method(D_METHOD("set_param_curve", "param", "curve"), &CPUParticles3D::set_param_curve); + ClassDB::bind_method(D_METHOD("get_param_curve", "param"), &CPUParticles3D::get_param_curve); - ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles::set_color); - ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles::get_color); + ClassDB::bind_method(D_METHOD("set_color", "color"), &CPUParticles3D::set_color); + ClassDB::bind_method(D_METHOD("get_color"), &CPUParticles3D::get_color); - ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles::set_color_ramp); - ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles::get_color_ramp); + ClassDB::bind_method(D_METHOD("set_color_ramp", "ramp"), &CPUParticles3D::set_color_ramp); + ClassDB::bind_method(D_METHOD("get_color_ramp"), &CPUParticles3D::get_color_ramp); - ClassDB::bind_method(D_METHOD("set_particle_flag", "flag", "enable"), &CPUParticles::set_particle_flag); - ClassDB::bind_method(D_METHOD("get_particle_flag", "flag"), &CPUParticles::get_particle_flag); + ClassDB::bind_method(D_METHOD("set_particle_flag", "flag", "enable"), &CPUParticles3D::set_particle_flag); + ClassDB::bind_method(D_METHOD("get_particle_flag", "flag"), &CPUParticles3D::get_particle_flag); - ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles::set_emission_shape); - ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles::get_emission_shape); + ClassDB::bind_method(D_METHOD("set_emission_shape", "shape"), &CPUParticles3D::set_emission_shape); + ClassDB::bind_method(D_METHOD("get_emission_shape"), &CPUParticles3D::get_emission_shape); - ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles::set_emission_sphere_radius); - ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles::get_emission_sphere_radius); + ClassDB::bind_method(D_METHOD("set_emission_sphere_radius", "radius"), &CPUParticles3D::set_emission_sphere_radius); + ClassDB::bind_method(D_METHOD("get_emission_sphere_radius"), &CPUParticles3D::get_emission_sphere_radius); - ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &CPUParticles::set_emission_box_extents); - ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &CPUParticles::get_emission_box_extents); + ClassDB::bind_method(D_METHOD("set_emission_box_extents", "extents"), &CPUParticles3D::set_emission_box_extents); + ClassDB::bind_method(D_METHOD("get_emission_box_extents"), &CPUParticles3D::get_emission_box_extents); - ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles::set_emission_points); - ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles::get_emission_points); + ClassDB::bind_method(D_METHOD("set_emission_points", "array"), &CPUParticles3D::set_emission_points); + ClassDB::bind_method(D_METHOD("get_emission_points"), &CPUParticles3D::get_emission_points); - ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles::set_emission_normals); - ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles::get_emission_normals); + ClassDB::bind_method(D_METHOD("set_emission_normals", "array"), &CPUParticles3D::set_emission_normals); + ClassDB::bind_method(D_METHOD("get_emission_normals"), &CPUParticles3D::get_emission_normals); - ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles::set_emission_colors); - ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles::get_emission_colors); + ClassDB::bind_method(D_METHOD("set_emission_colors", "array"), &CPUParticles3D::set_emission_colors); + ClassDB::bind_method(D_METHOD("get_emission_colors"), &CPUParticles3D::get_emission_colors); - ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles::get_gravity); - ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles::set_gravity); + ClassDB::bind_method(D_METHOD("get_gravity"), &CPUParticles3D::get_gravity); + ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &CPUParticles3D::set_gravity); - ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles::convert_from_particles); + ClassDB::bind_method(D_METHOD("convert_from_particles", "particles"), &CPUParticles3D::convert_from_particles); ADD_GROUP("Emission Shape", "emission_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "emission_shape", PROPERTY_HINT_ENUM, "Point,Sphere,Box,Points,Directed Points"), "set_emission_shape", "get_emission_shape"); @@ -1477,7 +1477,7 @@ void CPUParticles::_bind_methods() { BIND_ENUM_CONSTANT(EMISSION_SHAPE_MAX); } -CPUParticles::CPUParticles() { +CPUParticles3D::CPUParticles3D() { time = 0; inactive_time = 0; @@ -1488,8 +1488,8 @@ CPUParticles::CPUParticles() { set_notify_transform(true); - multimesh = VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_set_visible_instances(multimesh, 0); + multimesh = RenderingServer::get_singleton()->multimesh_create(); + RenderingServer::get_singleton()->multimesh_set_visible_instances(multimesh, 0); set_base(multimesh); set_emitting(true); @@ -1541,6 +1541,6 @@ CPUParticles::CPUParticles() { set_color(Color(1, 1, 1, 1)); } -CPUParticles::~CPUParticles() { - VS::get_singleton()->free(multimesh); +CPUParticles3D::~CPUParticles3D() { + RS::get_singleton()->free(multimesh); } diff --git a/scene/3d/cpu_particles.h b/scene/3d/cpu_particles_3d.h index 231e1f1ad9..ffe0ecc9a9 100644 --- a/scene/3d/cpu_particles.h +++ b/scene/3d/cpu_particles_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* cpu_particles.h */ +/* cpu_particles_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -32,11 +32,11 @@ #define CPU_PARTICLES_H #include "core/rid.h" -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" -class CPUParticles : public GeometryInstance { +class CPUParticles3D : public GeometryInstance3D { private: - GDCLASS(CPUParticles, GeometryInstance); + GDCLASS(CPUParticles3D, GeometryInstance3D); public: enum DrawOrder { @@ -286,13 +286,13 @@ public: void convert_from_particles(Node *p_particles); - CPUParticles(); - ~CPUParticles(); + CPUParticles3D(); + ~CPUParticles3D(); }; -VARIANT_ENUM_CAST(CPUParticles::DrawOrder) -VARIANT_ENUM_CAST(CPUParticles::Parameter) -VARIANT_ENUM_CAST(CPUParticles::Flags) -VARIANT_ENUM_CAST(CPUParticles::EmissionShape) +VARIANT_ENUM_CAST(CPUParticles3D::DrawOrder) +VARIANT_ENUM_CAST(CPUParticles3D::Parameter) +VARIANT_ENUM_CAST(CPUParticles3D::Flags) +VARIANT_ENUM_CAST(CPUParticles3D::EmissionShape) #endif // CPU_PARTICLES_H diff --git a/scene/3d/decal.cpp b/scene/3d/decal.cpp new file mode 100644 index 0000000000..4c824aedc4 --- /dev/null +++ b/scene/3d/decal.cpp @@ -0,0 +1,235 @@ +/*************************************************************************/ +/* decal.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 "decal.h" + +void Decal::set_extents(const Vector3 &p_extents) { + extents = p_extents; + RS::get_singleton()->decal_set_extents(decal, p_extents); + update_gizmo(); + _change_notify("extents"); +} + +Vector3 Decal::get_extents() const { + return extents; +} + +void Decal::set_texture(DecalTexture p_type, const Ref<Texture2D> &p_texture) { + ERR_FAIL_INDEX(p_type, TEXTURE_MAX); + textures[p_type] = p_texture; + RID texture_rid = p_texture.is_valid() ? p_texture->get_rid() : RID(); + RS::get_singleton()->decal_set_texture(decal, RS::DecalTexture(p_type), texture_rid); +} +Ref<Texture2D> Decal::get_texture(DecalTexture p_type) const { + ERR_FAIL_INDEX_V(p_type, TEXTURE_MAX, Ref<Texture2D>()); + return textures[p_type]; +} + +void Decal::set_emission_energy(float p_energy) { + emission_energy = p_energy; + RS::get_singleton()->decal_set_emission_energy(decal, emission_energy); +} +float Decal::get_emission_energy() const { + return emission_energy; +} + +void Decal::set_albedo_mix(float p_mix) { + albedo_mix = p_mix; + RS::get_singleton()->decal_set_albedo_mix(decal, albedo_mix); +} +float Decal::get_albedo_mix() const { + return albedo_mix; +} + +void Decal::set_upper_fade(float p_fade) { + upper_fade = p_fade; + RS::get_singleton()->decal_set_fade(decal, upper_fade, lower_fade); +} +float Decal::get_upper_fade() const { + return upper_fade; +} + +void Decal::set_lower_fade(float p_fade) { + lower_fade = p_fade; + RS::get_singleton()->decal_set_fade(decal, upper_fade, lower_fade); +} +float Decal::get_lower_fade() const { + return lower_fade; +} + +void Decal::set_normal_fade(float p_fade) { + normal_fade = p_fade; + RS::get_singleton()->decal_set_normal_fade(decal, normal_fade); +} +float Decal::get_normal_fade() const { + return normal_fade; +} + +void Decal::set_modulate(Color p_modulate) { + modulate = p_modulate; + RS::get_singleton()->decal_set_modulate(decal, p_modulate); +} + +Color Decal::get_modulate() const { + return modulate; +} + +void Decal::set_enable_distance_fade(bool p_enable) { + distance_fade_enabled = p_enable; + RS::get_singleton()->decal_set_distance_fade(decal, distance_fade_enabled, distance_fade_begin, distance_fade_length); +} +bool Decal::is_distance_fade_enabled() const { + return distance_fade_enabled; +} + +void Decal::set_distance_fade_begin(float p_distance) { + distance_fade_begin = p_distance; + RS::get_singleton()->decal_set_distance_fade(decal, distance_fade_enabled, distance_fade_begin, distance_fade_length); +} +float Decal::get_distance_fade_begin() const { + return distance_fade_begin; +} + +void Decal::set_distance_fade_length(float p_length) { + distance_fade_length = p_length; + RS::get_singleton()->decal_set_distance_fade(decal, distance_fade_enabled, distance_fade_begin, distance_fade_length); +} +float Decal::get_distance_fade_length() const { + return distance_fade_length; +} + +void Decal::set_cull_mask(uint32_t p_layers) { + cull_mask = p_layers; + RS::get_singleton()->decal_set_cull_mask(decal, cull_mask); +} +uint32_t Decal::get_cull_mask() const { + return cull_mask; +} + +AABB Decal::get_aabb() const { + + AABB aabb; + aabb.position = -extents; + aabb.size = extents * 2.0; + return aabb; +} +Vector<Face3> Decal::get_faces(uint32_t p_usage_flags) const { + + return Vector<Face3>(); +} + +void Decal::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_extents", "extents"), &Decal::set_extents); + ClassDB::bind_method(D_METHOD("get_extents"), &Decal::get_extents); + + ClassDB::bind_method(D_METHOD("set_texture", "type", "texture"), &Decal::set_texture); + ClassDB::bind_method(D_METHOD("get_texture", "type"), &Decal::get_texture); + + ClassDB::bind_method(D_METHOD("set_emission_energy", "energy"), &Decal::set_emission_energy); + ClassDB::bind_method(D_METHOD("get_emission_energy"), &Decal::get_emission_energy); + + ClassDB::bind_method(D_METHOD("set_albedo_mix", "energy"), &Decal::set_albedo_mix); + ClassDB::bind_method(D_METHOD("get_albedo_mix"), &Decal::get_albedo_mix); + + ClassDB::bind_method(D_METHOD("set_modulate", "color"), &Decal::set_modulate); + ClassDB::bind_method(D_METHOD("get_modulate"), &Decal::get_modulate); + + ClassDB::bind_method(D_METHOD("set_upper_fade", "fade"), &Decal::set_upper_fade); + ClassDB::bind_method(D_METHOD("get_upper_fade"), &Decal::get_upper_fade); + + ClassDB::bind_method(D_METHOD("set_lower_fade", "fade"), &Decal::set_lower_fade); + ClassDB::bind_method(D_METHOD("get_lower_fade"), &Decal::get_lower_fade); + + ClassDB::bind_method(D_METHOD("set_normal_fade", "fade"), &Decal::set_normal_fade); + ClassDB::bind_method(D_METHOD("get_normal_fade"), &Decal::get_normal_fade); + + ClassDB::bind_method(D_METHOD("set_enable_distance_fade", "enable"), &Decal::set_enable_distance_fade); + ClassDB::bind_method(D_METHOD("is_distance_fade_enabled"), &Decal::is_distance_fade_enabled); + + ClassDB::bind_method(D_METHOD("set_distance_fade_begin", "distance"), &Decal::set_distance_fade_begin); + ClassDB::bind_method(D_METHOD("get_distance_fade_begin"), &Decal::get_distance_fade_begin); + + ClassDB::bind_method(D_METHOD("set_distance_fade_length", "distance"), &Decal::set_distance_fade_length); + ClassDB::bind_method(D_METHOD("get_distance_fade_length"), &Decal::get_distance_fade_length); + + ClassDB::bind_method(D_METHOD("set_cull_mask", "mask"), &Decal::set_cull_mask); + ClassDB::bind_method(D_METHOD("get_cull_mask"), &Decal::get_cull_mask); + + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "extents", PROPERTY_HINT_RANGE, "0,1024,0.001,or_greater"), "set_extents", "get_extents"); + ADD_GROUP("Textures", "texture_"); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_albedo", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ALBEDO); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_NORMAL); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_orm", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_ORM); + ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "texture_emission", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_EMISSION); + ADD_GROUP("Parameters", ""); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "emission_energy", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_emission_energy", "get_emission_energy"); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "albedo_mix", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_albedo_mix", "get_albedo_mix"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "normal_fade", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_normal_fade", "get_normal_fade"); + ADD_GROUP("Vertical Fade", ""); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "upper_fade", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_upper_fade", "get_upper_fade"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "lower_fade", PROPERTY_HINT_EXP_EASING, "attenuation"), "set_lower_fade", "get_lower_fade"); + ADD_GROUP("Distance Fade", "distance_fade_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "distance_fade_enabled"), "set_enable_distance_fade", "is_distance_fade_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance_fade_begin"), "set_distance_fade_begin", "get_distance_fade_begin"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance_fade_length"), "set_distance_fade_length", "get_distance_fade_length"); + ADD_GROUP("Cull Mask", ""); + ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_cull_mask", "get_cull_mask"); + + BIND_ENUM_CONSTANT(TEXTURE_ALBEDO); + BIND_ENUM_CONSTANT(TEXTURE_NORMAL); + BIND_ENUM_CONSTANT(TEXTURE_ORM); + BIND_ENUM_CONSTANT(TEXTURE_EMISSION); + BIND_ENUM_CONSTANT(TEXTURE_MAX); +} + +Decal::Decal() { + + extents = Vector3(1, 1, 1); + emission_energy = 1.0; + modulate = Color(1, 1, 1, 1); + albedo_mix = 1.0; + cull_mask = (1 << 20) - 1; + upper_fade = 0.3; + lower_fade = 0.3; + normal_fade = 0; + distance_fade_enabled = false; + distance_fade_begin = 10; + distance_fade_length = 1; + + decal = RenderingServer::get_singleton()->decal_create(); + RS::get_singleton()->instance_set_base(get_instance(), decal); +} + +Decal::~Decal() { + + RS::get_singleton()->free(decal); +} diff --git a/scene/3d/decal.h b/scene/3d/decal.h new file mode 100644 index 0000000000..665444829d --- /dev/null +++ b/scene/3d/decal.h @@ -0,0 +1,114 @@ +/*************************************************************************/ +/* decal.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 DECAL_H +#define DECAL_H + +#include "scene/3d/visual_instance_3d.h" +#include "scene/resources/texture.h" +#include "servers/rendering_server.h" + +class Decal : public VisualInstance3D { + GDCLASS(Decal, VisualInstance3D); + +public: + enum DecalTexture { + TEXTURE_ALBEDO, + TEXTURE_NORMAL, + TEXTURE_ORM, + TEXTURE_EMISSION, + TEXTURE_MAX + }; + +private: + RID decal; + Vector3 extents; + Ref<Texture2D> textures[TEXTURE_MAX]; + float emission_energy; + float albedo_mix; + Color modulate; + uint32_t cull_mask; + float normal_fade; + float upper_fade; + float lower_fade; + bool distance_fade_enabled; + float distance_fade_begin; + float distance_fade_length; + +protected: + static void _bind_methods(); + +public: + void set_extents(const Vector3 &p_extents); + Vector3 get_extents() const; + + void set_texture(DecalTexture p_type, const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_texture(DecalTexture p_type) const; + + void set_emission_energy(float p_energy); + float get_emission_energy() const; + + void set_albedo_mix(float p_mix); + float get_albedo_mix() const; + + void set_modulate(Color p_modulate); + Color get_modulate() const; + + void set_upper_fade(float p_energy); + float get_upper_fade() const; + + void set_lower_fade(float p_fade); + float get_lower_fade() const; + + void set_normal_fade(float p_fade); + float get_normal_fade() const; + + void set_enable_distance_fade(bool p_enable); + bool is_distance_fade_enabled() const; + + void set_distance_fade_begin(float p_distance); + float get_distance_fade_begin() const; + + void set_distance_fade_length(float p_length); + float get_distance_fade_length() const; + + void set_cull_mask(uint32_t p_layers); + uint32_t get_cull_mask() const; + + virtual AABB get_aabb() const; + virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; + + Decal(); + ~Decal(); +}; + +VARIANT_ENUM_CAST(Decal::DecalTexture); + +#endif // DECAL_H diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index c3f039ae85..6d571ee4f2 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -33,7 +33,7 @@ #include "core/os/os.h" #include "core/method_bind_ext.gen.inc" -#include "mesh_instance.h" +#include "mesh_instance_3d.h" #include "voxelizer.h" void GIProbeData::_set_data(const Dictionary &p_data) { @@ -92,7 +92,7 @@ Dictionary GIProbeData::_get_data() const { } void GIProbeData::allocate(const Transform &p_to_cell_xform, const AABB &p_aabb, const Vector3 &p_octree_size, const Vector<uint8_t> &p_octree_cells, const Vector<uint8_t> &p_data_cells, const Vector<uint8_t> &p_distance_field, const Vector<int> &p_level_counts) { - VS::get_singleton()->gi_probe_allocate(probe, p_to_cell_xform, p_aabb, p_octree_size, p_octree_cells, p_data_cells, p_distance_field, p_level_counts); + RS::get_singleton()->gi_probe_allocate(probe, p_to_cell_xform, p_aabb, p_octree_size, p_octree_cells, p_data_cells, p_distance_field, p_level_counts); bounds = p_aabb; to_cell_xform = p_to_cell_xform; octree_size = p_octree_size; @@ -105,24 +105,24 @@ Vector3 GIProbeData::get_octree_size() const { return octree_size; } Vector<uint8_t> GIProbeData::get_octree_cells() const { - return VS::get_singleton()->gi_probe_get_octree_cells(probe); + return RS::get_singleton()->gi_probe_get_octree_cells(probe); } Vector<uint8_t> GIProbeData::get_data_cells() const { - return VS::get_singleton()->gi_probe_get_data_cells(probe); + return RS::get_singleton()->gi_probe_get_data_cells(probe); } Vector<uint8_t> GIProbeData::get_distance_field() const { - return VS::get_singleton()->gi_probe_get_distance_field(probe); + return RS::get_singleton()->gi_probe_get_distance_field(probe); } Vector<int> GIProbeData::get_level_counts() const { - return VS::get_singleton()->gi_probe_get_level_counts(probe); + return RS::get_singleton()->gi_probe_get_level_counts(probe); } Transform GIProbeData::get_to_cell_xform() const { return to_cell_xform; } void GIProbeData::set_dynamic_range(float p_range) { - VS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range); + RS::get_singleton()->gi_probe_set_dynamic_range(probe, p_range); dynamic_range = p_range; } @@ -131,7 +131,7 @@ float GIProbeData::get_dynamic_range() const { } void GIProbeData::set_propagation(float p_propagation) { - VS::get_singleton()->gi_probe_set_propagation(probe, p_propagation); + RS::get_singleton()->gi_probe_set_propagation(probe, p_propagation); propagation = p_propagation; } @@ -140,7 +140,7 @@ float GIProbeData::get_propagation() const { } void GIProbeData::set_anisotropy_strength(float p_anisotropy_strength) { - VS::get_singleton()->gi_probe_set_anisotropy_strength(probe, p_anisotropy_strength); + RS::get_singleton()->gi_probe_set_anisotropy_strength(probe, p_anisotropy_strength); anisotropy_strength = p_anisotropy_strength; } @@ -149,7 +149,7 @@ float GIProbeData::get_anisotropy_strength() const { } void GIProbeData::set_energy(float p_energy) { - VS::get_singleton()->gi_probe_set_energy(probe, p_energy); + RS::get_singleton()->gi_probe_set_energy(probe, p_energy); energy = p_energy; } @@ -158,7 +158,7 @@ float GIProbeData::get_energy() const { } void GIProbeData::set_ao(float p_ao) { - VS::get_singleton()->gi_probe_set_ao(probe, p_ao); + RS::get_singleton()->gi_probe_set_ao(probe, p_ao); ao = p_ao; } @@ -167,7 +167,7 @@ float GIProbeData::get_ao() const { } void GIProbeData::set_ao_size(float p_ao_size) { - VS::get_singleton()->gi_probe_set_ao_size(probe, p_ao_size); + RS::get_singleton()->gi_probe_set_ao_size(probe, p_ao_size); ao_size = p_ao_size; } @@ -176,7 +176,7 @@ float GIProbeData::get_ao_size() const { } void GIProbeData::set_bias(float p_bias) { - VS::get_singleton()->gi_probe_set_bias(probe, p_bias); + RS::get_singleton()->gi_probe_set_bias(probe, p_bias); bias = p_bias; } @@ -185,7 +185,7 @@ float GIProbeData::get_bias() const { } void GIProbeData::set_normal_bias(float p_normal_bias) { - VS::get_singleton()->gi_probe_set_normal_bias(probe, p_normal_bias); + RS::get_singleton()->gi_probe_set_normal_bias(probe, p_normal_bias); normal_bias = p_normal_bias; } @@ -194,7 +194,7 @@ float GIProbeData::get_normal_bias() const { } void GIProbeData::set_interior(bool p_enable) { - VS::get_singleton()->gi_probe_set_interior(probe, p_enable); + RS::get_singleton()->gi_probe_set_interior(probe, p_enable); interior = p_enable; } @@ -203,7 +203,7 @@ bool GIProbeData::is_interior() const { } void GIProbeData::set_use_two_bounces(bool p_enable) { - VS::get_singleton()->gi_probe_set_use_two_bounces(probe, p_enable); + RS::get_singleton()->gi_probe_set_use_two_bounces(probe, p_enable); use_two_bounces = p_enable; } @@ -293,13 +293,14 @@ GIProbeData::GIProbeData() { propagation = 0.7; anisotropy_strength = 0.5; interior = false; + use_two_bounces = false; - probe = VS::get_singleton()->gi_probe_create(); + probe = RS::get_singleton()->gi_probe_create(); } GIProbeData::~GIProbeData() { - VS::get_singleton()->free(probe); + RS::get_singleton()->free(probe); } ////////////////////// @@ -308,9 +309,9 @@ GIProbeData::~GIProbeData() { void GIProbe::set_probe_data(const Ref<GIProbeData> &p_data) { if (p_data.is_valid()) { - VS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid()); + RS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid()); } else { - VS::get_singleton()->instance_set_base(get_instance(), RID()); + RS::get_singleton()->instance_set_base(get_instance(), RID()); } probe_data = p_data; @@ -347,8 +348,8 @@ Vector3 GIProbe::get_extents() const { void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) { - MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node); - if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) { + MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node); + if (mi && mi->get_flag(GeometryInstance3D::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) { Ref<Mesh> mesh = mi->get_mesh(); if (mesh.is_valid()) { @@ -369,7 +370,7 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) { } } - Spatial *s = Object::cast_to<Spatial>(p_at_node); + Node3D *s = Object::cast_to<Node3D>(p_at_node); if (s) { if (s->is_visible_in_tree()) { @@ -402,9 +403,9 @@ void GIProbe::_find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes) { } } -GIProbe::BakeBeginFunc GIProbe::bake_begin_function = NULL; -GIProbe::BakeStepFunc GIProbe::bake_step_function = NULL; -GIProbe::BakeEndFunc GIProbe::bake_end_function = NULL; +GIProbe::BakeBeginFunc GIProbe::bake_begin_function = nullptr; +GIProbe::BakeStepFunc GIProbe::bake_step_function = nullptr; +GIProbe::BakeEndFunc GIProbe::bake_end_function = nullptr; Vector3i GIProbe::get_estimated_cell_size() const { static const int subdiv_value[SUBDIV_MAX] = { 6, 7, 8, 9 }; @@ -468,7 +469,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { //create the data for visual server if (p_create_visual_debug) { - MultiMeshInstance *mmi = memnew(MultiMeshInstance); + MultiMeshInstance3D *mmi = memnew(MultiMeshInstance3D); mmi->set_multimesh(baker.create_debug_multimesh()); add_child(mmi); #ifdef TOOLS_ENABLED @@ -511,7 +512,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) { void GIProbe::_debug_bake() { - bake(NULL, true); + bake(nullptr, true); } AABB GIProbe::get_aabb() const { @@ -526,7 +527,7 @@ Vector<Face3> GIProbe::get_faces(uint32_t p_usage_flags) const { String GIProbe::get_configuration_warning() const { - if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) { + if (RenderingServer::get_singleton()->is_low_end()) { return TTR("GIProbes are not supported by the GLES2 video driver.\nUse a BakedLightmap instead."); } return String(); @@ -563,10 +564,10 @@ GIProbe::GIProbe() { subdiv = SUBDIV_128; extents = Vector3(10, 10, 10); - gi_probe = VS::get_singleton()->gi_probe_create(); + gi_probe = RS::get_singleton()->gi_probe_create(); set_disable_scale(true); } GIProbe::~GIProbe() { - VS::get_singleton()->free(gi_probe); + RS::get_singleton()->free(gi_probe); } diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index f991843883..28b533e82d 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -31,8 +31,8 @@ #ifndef GIPROBE_H #define GIPROBE_H -#include "multimesh_instance.h" -#include "scene/3d/visual_instance.h" +#include "multimesh_instance_3d.h" +#include "scene/3d/visual_instance_3d.h" class GIProbeData : public Resource { @@ -108,8 +108,8 @@ public: ~GIProbeData(); }; -class GIProbe : public VisualInstance { - GDCLASS(GIProbe, VisualInstance); +class GIProbe : public VisualInstance3D { + GDCLASS(GIProbe, VisualInstance3D); public: enum Subdiv { @@ -161,7 +161,7 @@ public: Vector3 get_extents() const; Vector3i get_estimated_cell_size() const; - void bake(Node *p_from_node = NULL, bool p_create_visual_debug = false); + void bake(Node *p_from_node = nullptr, bool p_create_visual_debug = false); virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; diff --git a/scene/3d/particles.cpp b/scene/3d/gpu_particles_3d.cpp index e502b0c037..7744c477cb 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/gpu_particles_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* particles.cpp */ +/* gpu_particles_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,25 +28,25 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "particles.h" +#include "gpu_particles_3d.h" #include "core/os/os.h" #include "scene/resources/particles_material.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -AABB Particles::get_aabb() const { +AABB GPUParticles3D::get_aabb() const { return AABB(); } -Vector<Face3> Particles::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> GPUParticles3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void Particles::set_emitting(bool p_emitting) { +void GPUParticles3D::set_emitting(bool p_emitting) { - VS::get_singleton()->particles_set_emitting(particles, p_emitting); + RS::get_singleton()->particles_set_emitting(particles, p_emitting); if (p_emitting && one_shot) { set_process_internal(true); @@ -55,150 +55,150 @@ void Particles::set_emitting(bool p_emitting) { } } -void Particles::set_amount(int p_amount) { +void GPUParticles3D::set_amount(int p_amount) { ERR_FAIL_COND_MSG(p_amount < 1, "Amount of particles cannot be smaller than 1."); amount = p_amount; - VS::get_singleton()->particles_set_amount(particles, amount); + RS::get_singleton()->particles_set_amount(particles, amount); } -void Particles::set_lifetime(float p_lifetime) { +void GPUParticles3D::set_lifetime(float p_lifetime) { ERR_FAIL_COND_MSG(p_lifetime <= 0, "Particles lifetime must be greater than 0."); lifetime = p_lifetime; - VS::get_singleton()->particles_set_lifetime(particles, lifetime); + RS::get_singleton()->particles_set_lifetime(particles, lifetime); } -void Particles::set_one_shot(bool p_one_shot) { +void GPUParticles3D::set_one_shot(bool p_one_shot) { one_shot = p_one_shot; - VS::get_singleton()->particles_set_one_shot(particles, one_shot); + RS::get_singleton()->particles_set_one_shot(particles, one_shot); if (is_emitting()) { set_process_internal(true); if (!one_shot) - VisualServer::get_singleton()->particles_restart(particles); + RenderingServer::get_singleton()->particles_restart(particles); } if (!one_shot) set_process_internal(false); } -void Particles::set_pre_process_time(float p_time) { +void GPUParticles3D::set_pre_process_time(float p_time) { pre_process_time = p_time; - VS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time); + RS::get_singleton()->particles_set_pre_process_time(particles, pre_process_time); } -void Particles::set_explosiveness_ratio(float p_ratio) { +void GPUParticles3D::set_explosiveness_ratio(float p_ratio) { explosiveness_ratio = p_ratio; - VS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio); + RS::get_singleton()->particles_set_explosiveness_ratio(particles, explosiveness_ratio); } -void Particles::set_randomness_ratio(float p_ratio) { +void GPUParticles3D::set_randomness_ratio(float p_ratio) { randomness_ratio = p_ratio; - VS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); + RS::get_singleton()->particles_set_randomness_ratio(particles, randomness_ratio); } -void Particles::set_visibility_aabb(const AABB &p_aabb) { +void GPUParticles3D::set_visibility_aabb(const AABB &p_aabb) { visibility_aabb = p_aabb; - VS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb); + RS::get_singleton()->particles_set_custom_aabb(particles, visibility_aabb); update_gizmo(); _change_notify("visibility_aabb"); } -void Particles::set_use_local_coordinates(bool p_enable) { +void GPUParticles3D::set_use_local_coordinates(bool p_enable) { local_coords = p_enable; - VS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords); + RS::get_singleton()->particles_set_use_local_coordinates(particles, local_coords); } -void Particles::set_process_material(const Ref<Material> &p_material) { +void GPUParticles3D::set_process_material(const Ref<Material> &p_material) { process_material = p_material; RID material_rid; if (process_material.is_valid()) material_rid = process_material->get_rid(); - VS::get_singleton()->particles_set_process_material(particles, material_rid); + RS::get_singleton()->particles_set_process_material(particles, material_rid); update_configuration_warning(); } -void Particles::set_speed_scale(float p_scale) { +void GPUParticles3D::set_speed_scale(float p_scale) { speed_scale = p_scale; - VS::get_singleton()->particles_set_speed_scale(particles, p_scale); + RS::get_singleton()->particles_set_speed_scale(particles, p_scale); } -bool Particles::is_emitting() const { +bool GPUParticles3D::is_emitting() const { - return VS::get_singleton()->particles_get_emitting(particles); + return RS::get_singleton()->particles_get_emitting(particles); } -int Particles::get_amount() const { +int GPUParticles3D::get_amount() const { return amount; } -float Particles::get_lifetime() const { +float GPUParticles3D::get_lifetime() const { return lifetime; } -bool Particles::get_one_shot() const { +bool GPUParticles3D::get_one_shot() const { return one_shot; } -float Particles::get_pre_process_time() const { +float GPUParticles3D::get_pre_process_time() const { return pre_process_time; } -float Particles::get_explosiveness_ratio() const { +float GPUParticles3D::get_explosiveness_ratio() const { return explosiveness_ratio; } -float Particles::get_randomness_ratio() const { +float GPUParticles3D::get_randomness_ratio() const { return randomness_ratio; } -AABB Particles::get_visibility_aabb() const { +AABB GPUParticles3D::get_visibility_aabb() const { return visibility_aabb; } -bool Particles::get_use_local_coordinates() const { +bool GPUParticles3D::get_use_local_coordinates() const { return local_coords; } -Ref<Material> Particles::get_process_material() const { +Ref<Material> GPUParticles3D::get_process_material() const { return process_material; } -float Particles::get_speed_scale() const { +float GPUParticles3D::get_speed_scale() const { return speed_scale; } -void Particles::set_draw_order(DrawOrder p_order) { +void GPUParticles3D::set_draw_order(DrawOrder p_order) { draw_order = p_order; - VS::get_singleton()->particles_set_draw_order(particles, VS::ParticlesDrawOrder(p_order)); + RS::get_singleton()->particles_set_draw_order(particles, RS::ParticlesDrawOrder(p_order)); } -Particles::DrawOrder Particles::get_draw_order() const { +GPUParticles3D::DrawOrder GPUParticles3D::get_draw_order() const { return draw_order; } -void Particles::set_draw_passes(int p_count) { +void GPUParticles3D::set_draw_passes(int p_count) { ERR_FAIL_COND(p_count < 1); draw_passes.resize(p_count); - VS::get_singleton()->particles_set_draw_passes(particles, p_count); + RS::get_singleton()->particles_set_draw_passes(particles, p_count); _change_notify(); } -int Particles::get_draw_passes() const { +int GPUParticles3D::get_draw_passes() const { return draw_passes.size(); } -void Particles::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { +void GPUParticles3D::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { ERR_FAIL_INDEX(p_pass, draw_passes.size()); @@ -208,40 +208,40 @@ void Particles::set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh) { if (p_mesh.is_valid()) mesh_rid = p_mesh->get_rid(); - VS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid); + RS::get_singleton()->particles_set_draw_pass_mesh(particles, p_pass, mesh_rid); update_configuration_warning(); } -Ref<Mesh> Particles::get_draw_pass_mesh(int p_pass) const { +Ref<Mesh> GPUParticles3D::get_draw_pass_mesh(int p_pass) const { ERR_FAIL_INDEX_V(p_pass, draw_passes.size(), Ref<Mesh>()); return draw_passes[p_pass]; } -void Particles::set_fixed_fps(int p_count) { +void GPUParticles3D::set_fixed_fps(int p_count) { fixed_fps = p_count; - VS::get_singleton()->particles_set_fixed_fps(particles, p_count); + RS::get_singleton()->particles_set_fixed_fps(particles, p_count); } -int Particles::get_fixed_fps() const { +int GPUParticles3D::get_fixed_fps() const { return fixed_fps; } -void Particles::set_fractional_delta(bool p_enable) { +void GPUParticles3D::set_fractional_delta(bool p_enable) { fractional_delta = p_enable; - VS::get_singleton()->particles_set_fractional_delta(particles, p_enable); + RS::get_singleton()->particles_set_fractional_delta(particles, p_enable); } -bool Particles::get_fractional_delta() const { +bool GPUParticles3D::get_fractional_delta() const { return fractional_delta; } -String Particles::get_configuration_warning() const { +String GPUParticles3D::get_configuration_warning() const { - if (OS::get_singleton()->get_current_video_driver() == OS::VIDEO_DRIVER_GLES2) { - return TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles node instead. You can use the \"Convert to CPUParticles\" option for this purpose."); + if (RenderingServer::get_singleton()->is_low_end()) { + return TTR("GPU-based particles are not supported by the GLES2 video driver.\nUse the CPUParticles3D node instead. You can use the \"Convert to CPUParticles3D\" option for this purpose."); } String warnings; @@ -253,7 +253,7 @@ String Particles::get_configuration_warning() const { if (draw_passes[i].is_valid()) { meshes_found = true; for (int j = 0; j < draw_passes[i]->get_surface_count(); j++) { - anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != NULL; + anim_material_found = Object::cast_to<ShaderMaterial>(draw_passes[i]->surface_get_material(j).ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(draw_passes[i]->surface_get_material(j).ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); } @@ -261,7 +261,7 @@ String Particles::get_configuration_warning() const { } } - anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != NULL; + anim_material_found = anim_material_found || Object::cast_to<ShaderMaterial>(get_material_override().ptr()) != nullptr; StandardMaterial3D *spat = Object::cast_to<StandardMaterial3D>(get_material_override().ptr()); anim_material_found = anim_material_found || (spat && spat->get_billboard_mode() == StandardMaterial3D::BILLBOARD_PARTICLES); @@ -289,18 +289,18 @@ String Particles::get_configuration_warning() const { return warnings; } -void Particles::restart() { +void GPUParticles3D::restart() { - VisualServer::get_singleton()->particles_restart(particles); - VisualServer::get_singleton()->particles_set_emitting(particles, true); + RenderingServer::get_singleton()->particles_restart(particles); + RenderingServer::get_singleton()->particles_set_emitting(particles, true); } -AABB Particles::capture_aabb() const { +AABB GPUParticles3D::capture_aabb() const { - return VS::get_singleton()->particles_get_current_aabb(particles); + return RS::get_singleton()->particles_get_current_aabb(particles); } -void Particles::_validate_property(PropertyInfo &property) const { +void GPUParticles3D::_validate_property(PropertyInfo &property) const { if (property.name.begins_with("draw_pass_")) { int index = property.name.get_slicec('_', 2).to_int() - 1; @@ -311,14 +311,14 @@ void Particles::_validate_property(PropertyInfo &property) const { } } -void Particles::_notification(int p_what) { +void GPUParticles3D::_notification(int p_what) { if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) { if (can_process()) { - VS::get_singleton()->particles_set_speed_scale(particles, speed_scale); + RS::get_singleton()->particles_set_speed_scale(particles, speed_scale); } else { - VS::get_singleton()->particles_set_speed_scale(particles, 0); + RS::get_singleton()->particles_set_speed_scale(particles, 0); } } @@ -334,54 +334,54 @@ void Particles::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { // make sure particles are updated before rendering occurs if they were active before - if (is_visible_in_tree() && !VS::get_singleton()->particles_is_inactive(particles)) { - VS::get_singleton()->particles_request_process(particles); + if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) { + RS::get_singleton()->particles_request_process(particles); } } } -void Particles::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &Particles::set_emitting); - ClassDB::bind_method(D_METHOD("set_amount", "amount"), &Particles::set_amount); - ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &Particles::set_lifetime); - ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &Particles::set_one_shot); - ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &Particles::set_pre_process_time); - ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &Particles::set_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &Particles::set_randomness_ratio); - ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &Particles::set_visibility_aabb); - ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &Particles::set_use_local_coordinates); - ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &Particles::set_fixed_fps); - ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &Particles::set_fractional_delta); - ClassDB::bind_method(D_METHOD("set_process_material", "material"), &Particles::set_process_material); - ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &Particles::set_speed_scale); - - ClassDB::bind_method(D_METHOD("is_emitting"), &Particles::is_emitting); - ClassDB::bind_method(D_METHOD("get_amount"), &Particles::get_amount); - ClassDB::bind_method(D_METHOD("get_lifetime"), &Particles::get_lifetime); - ClassDB::bind_method(D_METHOD("get_one_shot"), &Particles::get_one_shot); - ClassDB::bind_method(D_METHOD("get_pre_process_time"), &Particles::get_pre_process_time); - ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &Particles::get_explosiveness_ratio); - ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &Particles::get_randomness_ratio); - ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &Particles::get_visibility_aabb); - ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &Particles::get_use_local_coordinates); - ClassDB::bind_method(D_METHOD("get_fixed_fps"), &Particles::get_fixed_fps); - ClassDB::bind_method(D_METHOD("get_fractional_delta"), &Particles::get_fractional_delta); - ClassDB::bind_method(D_METHOD("get_process_material"), &Particles::get_process_material); - ClassDB::bind_method(D_METHOD("get_speed_scale"), &Particles::get_speed_scale); - - ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &Particles::set_draw_order); - - ClassDB::bind_method(D_METHOD("get_draw_order"), &Particles::get_draw_order); - - ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &Particles::set_draw_passes); - ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &Particles::set_draw_pass_mesh); - - ClassDB::bind_method(D_METHOD("get_draw_passes"), &Particles::get_draw_passes); - ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &Particles::get_draw_pass_mesh); - - ClassDB::bind_method(D_METHOD("restart"), &Particles::restart); - ClassDB::bind_method(D_METHOD("capture_aabb"), &Particles::capture_aabb); +void GPUParticles3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_emitting", "emitting"), &GPUParticles3D::set_emitting); + ClassDB::bind_method(D_METHOD("set_amount", "amount"), &GPUParticles3D::set_amount); + ClassDB::bind_method(D_METHOD("set_lifetime", "secs"), &GPUParticles3D::set_lifetime); + ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &GPUParticles3D::set_one_shot); + ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &GPUParticles3D::set_pre_process_time); + ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &GPUParticles3D::set_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &GPUParticles3D::set_randomness_ratio); + ClassDB::bind_method(D_METHOD("set_visibility_aabb", "aabb"), &GPUParticles3D::set_visibility_aabb); + ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles3D::set_use_local_coordinates); + ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles3D::set_fixed_fps); + ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles3D::set_fractional_delta); + ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles3D::set_process_material); + ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles3D::set_speed_scale); + + ClassDB::bind_method(D_METHOD("is_emitting"), &GPUParticles3D::is_emitting); + ClassDB::bind_method(D_METHOD("get_amount"), &GPUParticles3D::get_amount); + ClassDB::bind_method(D_METHOD("get_lifetime"), &GPUParticles3D::get_lifetime); + ClassDB::bind_method(D_METHOD("get_one_shot"), &GPUParticles3D::get_one_shot); + ClassDB::bind_method(D_METHOD("get_pre_process_time"), &GPUParticles3D::get_pre_process_time); + ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &GPUParticles3D::get_explosiveness_ratio); + ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &GPUParticles3D::get_randomness_ratio); + ClassDB::bind_method(D_METHOD("get_visibility_aabb"), &GPUParticles3D::get_visibility_aabb); + ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles3D::get_use_local_coordinates); + ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles3D::get_fixed_fps); + ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles3D::get_fractional_delta); + ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles3D::get_process_material); + ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles3D::get_speed_scale); + + ClassDB::bind_method(D_METHOD("set_draw_order", "order"), &GPUParticles3D::set_draw_order); + + ClassDB::bind_method(D_METHOD("get_draw_order"), &GPUParticles3D::get_draw_order); + + ClassDB::bind_method(D_METHOD("set_draw_passes", "passes"), &GPUParticles3D::set_draw_passes); + ClassDB::bind_method(D_METHOD("set_draw_pass_mesh", "pass", "mesh"), &GPUParticles3D::set_draw_pass_mesh); + + ClassDB::bind_method(D_METHOD("get_draw_passes"), &GPUParticles3D::get_draw_passes); + ClassDB::bind_method(D_METHOD("get_draw_pass_mesh", "pass"), &GPUParticles3D::get_draw_pass_mesh); + + ClassDB::bind_method(D_METHOD("restart"), &GPUParticles3D::restart); + ClassDB::bind_method(D_METHOD("capture_aabb"), &GPUParticles3D::capture_aabb); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting"); ADD_PROPERTY(PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_EXP_RANGE, "1,1000000,1"), "set_amount", "get_amount"); @@ -414,9 +414,9 @@ void Particles::_bind_methods() { BIND_CONSTANT(MAX_DRAW_PASSES); } -Particles::Particles() { +GPUParticles3D::GPUParticles3D() { - particles = VS::get_singleton()->particles_create(); + particles = RS::get_singleton()->particles_create(); set_base(particles); one_shot = false; // Needed so that set_emitting doesn't access uninitialized values set_emitting(true); @@ -435,7 +435,7 @@ Particles::Particles() { set_speed_scale(1); } -Particles::~Particles() { +GPUParticles3D::~GPUParticles3D() { - VS::get_singleton()->free(particles); + RS::get_singleton()->free(particles); } diff --git a/scene/3d/particles.h b/scene/3d/gpu_particles_3d.h index cf461f25e9..0c6653294b 100644 --- a/scene/3d/particles.h +++ b/scene/3d/gpu_particles_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* particles.h */ +/* gpu_particles_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -32,12 +32,12 @@ #define PARTICLES_H #include "core/rid.h" -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/material.h" -class Particles : public GeometryInstance { +class GPUParticles3D : public GeometryInstance3D { private: - GDCLASS(Particles, GeometryInstance); + GDCLASS(GPUParticles3D, GeometryInstance3D); public: enum DrawOrder { @@ -124,10 +124,10 @@ public: void restart(); AABB capture_aabb() const; - Particles(); - ~Particles(); + GPUParticles3D(); + ~GPUParticles3D(); }; -VARIANT_ENUM_CAST(Particles::DrawOrder) +VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder) #endif // PARTICLES_H diff --git a/scene/3d/immediate_geometry.cpp b/scene/3d/immediate_geometry_3d.cpp index f5b08b86e1..63d4b1ac84 100644 --- a/scene/3d/immediate_geometry.cpp +++ b/scene/3d/immediate_geometry_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* immediate_geometry.cpp */ +/* immediate_geometry_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,43 +28,43 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "immediate_geometry.h" +#include "immediate_geometry_3d.h" -void ImmediateGeometry::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture) { +void ImmediateGeometry3D::begin(Mesh::PrimitiveType p_primitive, const Ref<Texture2D> &p_texture) { - VS::get_singleton()->immediate_begin(im, (VS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID()); + RS::get_singleton()->immediate_begin(im, (RS::PrimitiveType)p_primitive, p_texture.is_valid() ? p_texture->get_rid() : RID()); if (p_texture.is_valid()) cached_textures.push_back(p_texture); } -void ImmediateGeometry::set_normal(const Vector3 &p_normal) { +void ImmediateGeometry3D::set_normal(const Vector3 &p_normal) { - VS::get_singleton()->immediate_normal(im, p_normal); + RS::get_singleton()->immediate_normal(im, p_normal); } -void ImmediateGeometry::set_tangent(const Plane &p_tangent) { +void ImmediateGeometry3D::set_tangent(const Plane &p_tangent) { - VS::get_singleton()->immediate_tangent(im, p_tangent); + RS::get_singleton()->immediate_tangent(im, p_tangent); } -void ImmediateGeometry::set_color(const Color &p_color) { +void ImmediateGeometry3D::set_color(const Color &p_color) { - VS::get_singleton()->immediate_color(im, p_color); + RS::get_singleton()->immediate_color(im, p_color); } -void ImmediateGeometry::set_uv(const Vector2 &p_uv) { +void ImmediateGeometry3D::set_uv(const Vector2 &p_uv) { - VS::get_singleton()->immediate_uv(im, p_uv); + RS::get_singleton()->immediate_uv(im, p_uv); } -void ImmediateGeometry::set_uv2(const Vector2 &p_uv2) { +void ImmediateGeometry3D::set_uv2(const Vector2 &p_uv2) { - VS::get_singleton()->immediate_uv2(im, p_uv2); + RS::get_singleton()->immediate_uv2(im, p_uv2); } -void ImmediateGeometry::add_vertex(const Vector3 &p_vertex) { +void ImmediateGeometry3D::add_vertex(const Vector3 &p_vertex) { - VS::get_singleton()->immediate_vertex(im, p_vertex); + RS::get_singleton()->immediate_vertex(im, p_vertex); if (empty) { aabb.position = p_vertex; aabb.size = Vector3(); @@ -74,28 +74,28 @@ void ImmediateGeometry::add_vertex(const Vector3 &p_vertex) { } } -void ImmediateGeometry::end() { +void ImmediateGeometry3D::end() { - VS::get_singleton()->immediate_end(im); + RS::get_singleton()->immediate_end(im); } -void ImmediateGeometry::clear() { +void ImmediateGeometry3D::clear() { - VS::get_singleton()->immediate_clear(im); + RS::get_singleton()->immediate_clear(im); empty = true; cached_textures.clear(); } -AABB ImmediateGeometry::get_aabb() const { +AABB ImmediateGeometry3D::get_aabb() const { return aabb; } -Vector<Face3> ImmediateGeometry::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> ImmediateGeometry3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void ImmediateGeometry::add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv) { +void ImmediateGeometry3D::add_sphere(int p_lats, int p_lons, float p_radius, bool p_add_uv) { for (int i = 1; i <= p_lats; i++) { double lat0 = Math_PI * (-0.5 + (double)(i - 1) / p_lats); @@ -142,28 +142,28 @@ void ImmediateGeometry::add_sphere(int p_lats, int p_lons, float p_radius, bool } } -void ImmediateGeometry::_bind_methods() { - - ClassDB::bind_method(D_METHOD("begin", "primitive", "texture"), &ImmediateGeometry::begin, DEFVAL(Ref<Texture2D>())); - ClassDB::bind_method(D_METHOD("set_normal", "normal"), &ImmediateGeometry::set_normal); - ClassDB::bind_method(D_METHOD("set_tangent", "tangent"), &ImmediateGeometry::set_tangent); - ClassDB::bind_method(D_METHOD("set_color", "color"), &ImmediateGeometry::set_color); - ClassDB::bind_method(D_METHOD("set_uv", "uv"), &ImmediateGeometry::set_uv); - ClassDB::bind_method(D_METHOD("set_uv2", "uv"), &ImmediateGeometry::set_uv2); - ClassDB::bind_method(D_METHOD("add_vertex", "position"), &ImmediateGeometry::add_vertex); - ClassDB::bind_method(D_METHOD("add_sphere", "lats", "lons", "radius", "add_uv"), &ImmediateGeometry::add_sphere, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("end"), &ImmediateGeometry::end); - ClassDB::bind_method(D_METHOD("clear"), &ImmediateGeometry::clear); +void ImmediateGeometry3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("begin", "primitive", "texture"), &ImmediateGeometry3D::begin, DEFVAL(Ref<Texture2D>())); + ClassDB::bind_method(D_METHOD("set_normal", "normal"), &ImmediateGeometry3D::set_normal); + ClassDB::bind_method(D_METHOD("set_tangent", "tangent"), &ImmediateGeometry3D::set_tangent); + ClassDB::bind_method(D_METHOD("set_color", "color"), &ImmediateGeometry3D::set_color); + ClassDB::bind_method(D_METHOD("set_uv", "uv"), &ImmediateGeometry3D::set_uv); + ClassDB::bind_method(D_METHOD("set_uv2", "uv"), &ImmediateGeometry3D::set_uv2); + ClassDB::bind_method(D_METHOD("add_vertex", "position"), &ImmediateGeometry3D::add_vertex); + ClassDB::bind_method(D_METHOD("add_sphere", "lats", "lons", "radius", "add_uv"), &ImmediateGeometry3D::add_sphere, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("end"), &ImmediateGeometry3D::end); + ClassDB::bind_method(D_METHOD("clear"), &ImmediateGeometry3D::clear); } -ImmediateGeometry::ImmediateGeometry() { +ImmediateGeometry3D::ImmediateGeometry3D() { - im = VisualServer::get_singleton()->immediate_create(); + im = RenderingServer::get_singleton()->immediate_create(); set_base(im); empty = true; } -ImmediateGeometry::~ImmediateGeometry() { +ImmediateGeometry3D::~ImmediateGeometry3D() { - VisualServer::get_singleton()->free(im); + RenderingServer::get_singleton()->free(im); } diff --git a/scene/3d/immediate_geometry.h b/scene/3d/immediate_geometry_3d.h index f9222c75fa..6e15450a5b 100644 --- a/scene/3d/immediate_geometry.h +++ b/scene/3d/immediate_geometry_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* immediate_geometry.h */ +/* immediate_geometry_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef IMMEDIATE_GEOMETRY_H -#define IMMEDIATE_GEOMETRY_H +#ifndef IMMEDIATE_GEOMETRY_3D_H +#define IMMEDIATE_GEOMETRY_3D_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/mesh.h" -class ImmediateGeometry : public GeometryInstance { +class ImmediateGeometry3D : public GeometryInstance3D { - GDCLASS(ImmediateGeometry, GeometryInstance); + GDCLASS(ImmediateGeometry3D, GeometryInstance3D); RID im; //a list of textures drawn need to be kept, to avoid references - // in VisualServer from becoming invalid if the texture is no longer used + // in RenderingServer from becoming invalid if the texture is no longer used List<Ref<Texture2D>> cached_textures; bool empty; AABB aabb; @@ -66,8 +66,8 @@ public: virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; - ImmediateGeometry(); - ~ImmediateGeometry(); + ImmediateGeometry3D(); + ~ImmediateGeometry3D(); }; #endif // IMMEDIATE_GEOMETRY_H diff --git a/scene/3d/interpolated_camera.cpp b/scene/3d/interpolated_camera.cpp deleted file mode 100644 index 592d592a38..0000000000 --- a/scene/3d/interpolated_camera.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/*************************************************************************/ -/* interpolated_camera.cpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 "interpolated_camera.h" - -#include "core/engine.h" - -void InterpolatedCamera::_notification(int p_what) { - - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - - if (Engine::get_singleton()->is_editor_hint() && enabled) - set_process_internal(false); - - } break; - case NOTIFICATION_INTERNAL_PROCESS: { - - if (!enabled) - break; - if (has_node(target)) { - - Spatial *node = Object::cast_to<Spatial>(get_node(target)); - if (!node) - break; - - float delta = speed * get_process_delta_time(); - Transform target_xform = node->get_global_transform(); - Transform local_transform = get_global_transform(); - local_transform = local_transform.interpolate_with(target_xform, delta); - set_global_transform(local_transform); - Camera *cam = Object::cast_to<Camera>(node); - if (cam) { - - if (cam->get_projection() == get_projection()) { - - float new_near = Math::lerp(get_znear(), cam->get_znear(), delta); - float new_far = Math::lerp(get_zfar(), cam->get_zfar(), delta); - - if (cam->get_projection() == PROJECTION_ORTHOGONAL) { - - float size = Math::lerp(get_size(), cam->get_size(), delta); - set_orthogonal(size, new_near, new_far); - } else { - - float fov = Math::lerp(get_fov(), cam->get_fov(), delta); - set_perspective(fov, new_near, new_far); - } - } - } - } - - } break; - } -} - -void InterpolatedCamera::_set_target(const Object *p_target) { - - ERR_FAIL_NULL(p_target); - set_target(Object::cast_to<Spatial>(p_target)); -} - -void InterpolatedCamera::set_target(const Spatial *p_target) { - - ERR_FAIL_NULL(p_target); - target = get_path_to(p_target); -} - -void InterpolatedCamera::set_target_path(const NodePath &p_path) { - - target = p_path; -} - -NodePath InterpolatedCamera::get_target_path() const { - - return target; -} - -void InterpolatedCamera::set_interpolation_enabled(bool p_enable) { - - if (enabled == p_enable) - return; - enabled = p_enable; - if (p_enable) { - if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) - return; - set_process_internal(true); - } else - set_process_internal(false); -} - -bool InterpolatedCamera::is_interpolation_enabled() const { - - return enabled; -} - -void InterpolatedCamera::set_speed(real_t p_speed) { - - speed = p_speed; -} - -real_t InterpolatedCamera::get_speed() const { - - return speed; -} - -void InterpolatedCamera::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_target_path", "target_path"), &InterpolatedCamera::set_target_path); - ClassDB::bind_method(D_METHOD("get_target_path"), &InterpolatedCamera::get_target_path); - ClassDB::bind_method(D_METHOD("set_target", "target"), &InterpolatedCamera::_set_target); - - ClassDB::bind_method(D_METHOD("set_speed", "speed"), &InterpolatedCamera::set_speed); - ClassDB::bind_method(D_METHOD("get_speed"), &InterpolatedCamera::get_speed); - - ClassDB::bind_method(D_METHOD("set_interpolation_enabled", "target_path"), &InterpolatedCamera::set_interpolation_enabled); - ClassDB::bind_method(D_METHOD("is_interpolation_enabled"), &InterpolatedCamera::is_interpolation_enabled); - - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target"), "set_target_path", "get_target_path"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed"), "set_speed", "get_speed"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_interpolation_enabled", "is_interpolation_enabled"); -} - -InterpolatedCamera::InterpolatedCamera() { - - enabled = false; - speed = 1; -} diff --git a/scene/3d/interpolated_camera.h b/scene/3d/interpolated_camera.h deleted file mode 100644 index 7b160c66fa..0000000000 --- a/scene/3d/interpolated_camera.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************/ -/* interpolated_camera.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 INTERPOLATED_CAMERA_H -#define INTERPOLATED_CAMERA_H - -#include "scene/3d/camera.h" - -class InterpolatedCamera : public Camera { - - GDCLASS(InterpolatedCamera, Camera); - - bool enabled; - real_t speed; - NodePath target; - -protected: - void _notification(int p_what); - static void _bind_methods(); - void _set_target(const Object *p_target); - -public: - void set_target(const Spatial *p_target); - void set_target_path(const NodePath &p_path); - NodePath get_target_path() const; - - void set_speed(real_t p_speed); - real_t get_speed() const; - - void set_interpolation_enabled(bool p_enable); - bool is_interpolation_enabled() const; - - InterpolatedCamera(); -}; - -#endif // INTERPOLATED_CAMERA_H diff --git a/scene/3d/light.cpp b/scene/3d/light_3d.cpp index 7c922ce1cd..c048f60ebd 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* light.cpp */ +/* light_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,23 +28,23 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "light.h" +#include "light_3d.h" #include "core/engine.h" #include "core/project_settings.h" #include "scene/resources/surface_tool.h" -bool Light::_can_gizmo_scale() const { +bool Light3D::_can_gizmo_scale() const { return false; } -void Light::set_param(Param p_param, float p_value) { +void Light3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); param[p_param] = p_value; - VS::get_singleton()->light_set_param(light, VS::LightParam(p_param), p_value); + RS::get_singleton()->light_set_param(light, RS::LightParam(p_param), p_value); if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) { update_gizmo(); @@ -59,90 +59,90 @@ void Light::set_param(Param p_param, float p_value) { } } -float Light::get_param(Param p_param) const { +float Light3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return param[p_param]; } -void Light::set_shadow(bool p_enable) { +void Light3D::set_shadow(bool p_enable) { shadow = p_enable; - VS::get_singleton()->light_set_shadow(light, p_enable); + RS::get_singleton()->light_set_shadow(light, p_enable); - if (type == VisualServer::LIGHT_SPOT) { + if (type == RenderingServer::LIGHT_SPOT || type == RenderingServer::LIGHT_OMNI) { update_configuration_warning(); } } -bool Light::has_shadow() const { +bool Light3D::has_shadow() const { return shadow; } -void Light::set_negative(bool p_enable) { +void Light3D::set_negative(bool p_enable) { negative = p_enable; - VS::get_singleton()->light_set_negative(light, p_enable); + RS::get_singleton()->light_set_negative(light, p_enable); } -bool Light::is_negative() const { +bool Light3D::is_negative() const { return negative; } -void Light::set_cull_mask(uint32_t p_cull_mask) { +void Light3D::set_cull_mask(uint32_t p_cull_mask) { cull_mask = p_cull_mask; - VS::get_singleton()->light_set_cull_mask(light, p_cull_mask); + RS::get_singleton()->light_set_cull_mask(light, p_cull_mask); } -uint32_t Light::get_cull_mask() const { +uint32_t Light3D::get_cull_mask() const { return cull_mask; } -void Light::set_color(const Color &p_color) { +void Light3D::set_color(const Color &p_color) { color = p_color; - VS::get_singleton()->light_set_color(light, p_color); + RS::get_singleton()->light_set_color(light, p_color); // The gizmo color depends on the light color, so update it. update_gizmo(); } -Color Light::get_color() const { +Color Light3D::get_color() const { return color; } -void Light::set_shadow_color(const Color &p_shadow_color) { +void Light3D::set_shadow_color(const Color &p_shadow_color) { shadow_color = p_shadow_color; - VS::get_singleton()->light_set_shadow_color(light, p_shadow_color); + RS::get_singleton()->light_set_shadow_color(light, p_shadow_color); } -Color Light::get_shadow_color() const { +Color Light3D::get_shadow_color() const { return shadow_color; } -void Light::set_shadow_reverse_cull_face(bool p_enable) { +void Light3D::set_shadow_reverse_cull_face(bool p_enable) { reverse_cull = p_enable; - VS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull); + RS::get_singleton()->light_set_reverse_cull_face_mode(light, reverse_cull); } -bool Light::get_shadow_reverse_cull_face() const { +bool Light3D::get_shadow_reverse_cull_face() const { return reverse_cull; } -AABB Light::get_aabb() const { +AABB Light3D::get_aabb() const { - if (type == VisualServer::LIGHT_DIRECTIONAL) { + if (type == RenderingServer::LIGHT_DIRECTIONAL) { return AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); - } else if (type == VisualServer::LIGHT_OMNI) { + } else if (type == RenderingServer::LIGHT_OMNI) { return AABB(Vector3(-1, -1, -1) * param[PARAM_RANGE], Vector3(2, 2, 2) * param[PARAM_RANGE]); - } else if (type == VisualServer::LIGHT_SPOT) { + } else if (type == RenderingServer::LIGHT_SPOT) { float len = param[PARAM_RANGE]; float size = Math::tan(Math::deg2rad(param[PARAM_SPOT_ANGLE])) * len; @@ -152,21 +152,33 @@ AABB Light::get_aabb() const { return AABB(); } -Vector<Face3> Light::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> Light3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -void Light::set_bake_mode(BakeMode p_mode) { +void Light3D::set_bake_mode(BakeMode p_mode) { bake_mode = p_mode; - VS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED); + RS::get_singleton()->light_set_use_gi(light, p_mode != BAKE_DISABLED); } -Light::BakeMode Light::get_bake_mode() const { +Light3D::BakeMode Light3D::get_bake_mode() const { return bake_mode; } -void Light::_update_visibility() { +void Light3D::set_projector(const Ref<Texture2D> &p_texture) { + + projector = p_texture; + RID tex_id = projector.is_valid() ? projector->get_rid() : RID(); + RS::get_singleton()->light_set_projector(light, tex_id); + update_configuration_warning(); +} + +Ref<Texture2D> Light3D::get_projector() const { + return projector; +} + +void Light3D::_update_visibility() { if (!is_inside_tree()) return; @@ -187,12 +199,12 @@ void Light::_update_visibility() { } #endif - VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok); + RS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree() && editor_ok); _change_notify("geometry/visible"); } -void Light::_notification(int p_what) { +void Light3D::_notification(int p_what) { if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { @@ -204,57 +216,71 @@ void Light::_notification(int p_what) { } } -void Light::set_editor_only(bool p_editor_only) { +void Light3D::set_editor_only(bool p_editor_only) { editor_only = p_editor_only; _update_visibility(); } -bool Light::is_editor_only() const { +bool Light3D::is_editor_only() const { return editor_only; } -void Light::_validate_property(PropertyInfo &property) const { +void Light3D::_validate_property(PropertyInfo &property) const { + + if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_size") { + property.usage = 0; + } + + if (get_light_type() == RS::LIGHT_DIRECTIONAL && property.name == "light_projector") { + property.usage = 0; + } - if (VisualServer::get_singleton()->is_low_end() && property.name == "shadow_contact") { - property.usage = PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL; + if (get_light_type() != RS::LIGHT_DIRECTIONAL && property.name == "light_angular_distance") { + property.usage = 0; } } -void Light::_bind_methods() { +void Light3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light::set_editor_only); - ClassDB::bind_method(D_METHOD("is_editor_only"), &Light::is_editor_only); + ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light3D::set_editor_only); + ClassDB::bind_method(D_METHOD("is_editor_only"), &Light3D::is_editor_only); - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &Light::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Light3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &Light3D::get_param); - ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light::set_shadow); - ClassDB::bind_method(D_METHOD("has_shadow"), &Light::has_shadow); + ClassDB::bind_method(D_METHOD("set_shadow", "enabled"), &Light3D::set_shadow); + ClassDB::bind_method(D_METHOD("has_shadow"), &Light3D::has_shadow); - ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light::set_negative); - ClassDB::bind_method(D_METHOD("is_negative"), &Light::is_negative); + ClassDB::bind_method(D_METHOD("set_negative", "enabled"), &Light3D::set_negative); + ClassDB::bind_method(D_METHOD("is_negative"), &Light3D::is_negative); - ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light::set_cull_mask); - ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light::get_cull_mask); + ClassDB::bind_method(D_METHOD("set_cull_mask", "cull_mask"), &Light3D::set_cull_mask); + ClassDB::bind_method(D_METHOD("get_cull_mask"), &Light3D::get_cull_mask); - ClassDB::bind_method(D_METHOD("set_color", "color"), &Light::set_color); - ClassDB::bind_method(D_METHOD("get_color"), &Light::get_color); + ClassDB::bind_method(D_METHOD("set_color", "color"), &Light3D::set_color); + ClassDB::bind_method(D_METHOD("get_color"), &Light3D::get_color); - ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light::set_shadow_reverse_cull_face); - ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light::get_shadow_reverse_cull_face); + ClassDB::bind_method(D_METHOD("set_shadow_reverse_cull_face", "enable"), &Light3D::set_shadow_reverse_cull_face); + ClassDB::bind_method(D_METHOD("get_shadow_reverse_cull_face"), &Light3D::get_shadow_reverse_cull_face); - ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light::set_shadow_color); - ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light::get_shadow_color); + ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light3D::set_shadow_color); + ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light3D::get_shadow_color); - ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light::set_bake_mode); - ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light::get_bake_mode); + ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &Light3D::set_bake_mode); + ClassDB::bind_method(D_METHOD("get_bake_mode"), &Light3D::get_bake_mode); + + ClassDB::bind_method(D_METHOD("set_projector", "projector"), &Light3D::set_projector); + ClassDB::bind_method(D_METHOD("get_projector"), &Light3D::get_projector); ADD_GROUP("Light", "light_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "light_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_color", "get_color"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_ENERGY); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_indirect_energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_param", "get_param", PARAM_INDIRECT_ENERGY); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_projector", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_projector", "get_projector"); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_size", PROPERTY_HINT_RANGE, "0,64,0.01,or_greater"), "set_param", "get_param", PARAM_SIZE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_angular_distance", PROPERTY_HINT_RANGE, "0,90,0.01"), "set_param", "get_param", PARAM_SIZE); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "light_negative"), "set_negative", "is_negative"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "light_specular", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SPECULAR); ADD_PROPERTY(PropertyInfo(Variant::INT, "light_bake_mode", PROPERTY_HINT_ENUM, "Disable,Indirect,All"), "set_bake_mode", "get_bake_mode"); @@ -262,9 +288,11 @@ void Light::_bind_methods() { ADD_GROUP("Shadow", "shadow_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow", "has_shadow"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_shadow_color", "get_shadow_color"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_contact", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_CONTACT_SHADOW_SIZE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_bias", PROPERTY_HINT_RANGE, "0,10,0.001"), "set_param", "get_param", PARAM_SHADOW_BIAS); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_normal_bias", PROPERTY_HINT_RANGE, "0,10,0.001"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_reverse_cull_face"), "set_shadow_reverse_cull_face", "get_shadow_reverse_cull_face"); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_transmittance_bias", PROPERTY_HINT_RANGE, "-16,16,0.01"), "set_param", "get_param", PARAM_TRANSMITTANCE_BIAS); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "shadow_blur", PROPERTY_HINT_RANGE, "0.1,8,0.01"), "set_param", "get_param", PARAM_SHADOW_BLUR); ADD_GROUP("Editor", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only"); ADD_GROUP("", ""); @@ -273,10 +301,10 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_INDIRECT_ENERGY); BIND_ENUM_CONSTANT(PARAM_SPECULAR); BIND_ENUM_CONSTANT(PARAM_RANGE); + BIND_ENUM_CONSTANT(PARAM_SIZE); BIND_ENUM_CONSTANT(PARAM_ATTENUATION); BIND_ENUM_CONSTANT(PARAM_SPOT_ANGLE); BIND_ENUM_CONSTANT(PARAM_SPOT_ATTENUATION); - BIND_ENUM_CONSTANT(PARAM_CONTACT_SHADOW_SIZE); BIND_ENUM_CONSTANT(PARAM_SHADOW_MAX_DISTANCE); BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_1_OFFSET); BIND_ENUM_CONSTANT(PARAM_SHADOW_SPLIT_2_OFFSET); @@ -284,7 +312,9 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_SHADOW_FADE_START); BIND_ENUM_CONSTANT(PARAM_SHADOW_NORMAL_BIAS); BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS); - BIND_ENUM_CONSTANT(PARAM_SHADOW_BIAS_SPLIT_SCALE); + BIND_ENUM_CONSTANT(PARAM_SHADOW_PANCAKE_SIZE); + BIND_ENUM_CONSTANT(PARAM_SHADOW_BLUR); + BIND_ENUM_CONSTANT(PARAM_TRANSMITTANCE_BIAS); BIND_ENUM_CONSTANT(PARAM_MAX); BIND_ENUM_CONSTANT(BAKE_DISABLED); @@ -292,18 +322,18 @@ void Light::_bind_methods() { BIND_ENUM_CONSTANT(BAKE_ALL); } -Light::Light(VisualServer::LightType p_type) { +Light3D::Light3D(RenderingServer::LightType p_type) { type = p_type; switch (p_type) { - case VS::LIGHT_DIRECTIONAL: light = VisualServer::get_singleton()->directional_light_create(); break; - case VS::LIGHT_OMNI: light = VisualServer::get_singleton()->omni_light_create(); break; - case VS::LIGHT_SPOT: light = VisualServer::get_singleton()->spot_light_create(); break; + case RS::LIGHT_DIRECTIONAL: light = RenderingServer::get_singleton()->directional_light_create(); break; + case RS::LIGHT_OMNI: light = RenderingServer::get_singleton()->omni_light_create(); break; + case RS::LIGHT_SPOT: light = RenderingServer::get_singleton()->spot_light_create(); break; default: { }; } - VS::get_singleton()->instance_set_base(get_instance(), light); + RS::get_singleton()->instance_set_base(get_instance(), light); reverse_cull = false; bake_mode = BAKE_INDIRECT; @@ -318,78 +348,81 @@ Light::Light(VisualServer::LightType p_type) { set_param(PARAM_INDIRECT_ENERGY, 1); set_param(PARAM_SPECULAR, 0.5); set_param(PARAM_RANGE, 5); + set_param(PARAM_SIZE, 0); set_param(PARAM_ATTENUATION, 1); set_param(PARAM_SPOT_ANGLE, 45); set_param(PARAM_SPOT_ATTENUATION, 1); - set_param(PARAM_CONTACT_SHADOW_SIZE, 0); set_param(PARAM_SHADOW_MAX_DISTANCE, 0); set_param(PARAM_SHADOW_SPLIT_1_OFFSET, 0.1); set_param(PARAM_SHADOW_SPLIT_2_OFFSET, 0.2); set_param(PARAM_SHADOW_SPLIT_3_OFFSET, 0.5); set_param(PARAM_SHADOW_FADE_START, 0.8); - set_param(PARAM_SHADOW_NORMAL_BIAS, 0.0); - set_param(PARAM_SHADOW_BIAS, 0.15); + set_param(PARAM_SHADOW_PANCAKE_SIZE, 20.0); + set_param(PARAM_SHADOW_BLUR, 1.0); + set_param(PARAM_SHADOW_BIAS, 0.02); + set_param(PARAM_SHADOW_NORMAL_BIAS, 1.0); + set_param(PARAM_TRANSMITTANCE_BIAS, 0.05); set_param(PARAM_SHADOW_FADE_START, 1); set_disable_scale(true); } -Light::Light() { +Light3D::Light3D() { - type = VisualServer::LIGHT_DIRECTIONAL; - ERR_PRINT("Light should not be instanced directly; use the DirectionalLight, OmniLight or SpotLight subtypes instead."); + type = RenderingServer::LIGHT_DIRECTIONAL; + ERR_PRINT("Light3D should not be instanced directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead."); } -Light::~Light() { +Light3D::~Light3D() { - VS::get_singleton()->instance_set_base(get_instance(), RID()); + RS::get_singleton()->instance_set_base(get_instance(), RID()); if (light.is_valid()) - VisualServer::get_singleton()->free(light); + RenderingServer::get_singleton()->free(light); } ///////////////////////////////////////// -void DirectionalLight::set_shadow_mode(ShadowMode p_mode) { +void DirectionalLight3D::set_shadow_mode(ShadowMode p_mode) { shadow_mode = p_mode; - VS::get_singleton()->light_directional_set_shadow_mode(light, VS::LightDirectionalShadowMode(p_mode)); + RS::get_singleton()->light_directional_set_shadow_mode(light, RS::LightDirectionalShadowMode(p_mode)); } -DirectionalLight::ShadowMode DirectionalLight::get_shadow_mode() const { +DirectionalLight3D::ShadowMode DirectionalLight3D::get_shadow_mode() const { return shadow_mode; } -void DirectionalLight::set_shadow_depth_range(ShadowDepthRange p_range) { +void DirectionalLight3D::set_shadow_depth_range(ShadowDepthRange p_range) { shadow_depth_range = p_range; - VS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, VS::LightDirectionalShadowDepthRangeMode(p_range)); + RS::get_singleton()->light_directional_set_shadow_depth_range_mode(light, RS::LightDirectionalShadowDepthRangeMode(p_range)); } -DirectionalLight::ShadowDepthRange DirectionalLight::get_shadow_depth_range() const { +DirectionalLight3D::ShadowDepthRange DirectionalLight3D::get_shadow_depth_range() const { return shadow_depth_range; } -void DirectionalLight::set_blend_splits(bool p_enable) { +void DirectionalLight3D::set_blend_splits(bool p_enable) { blend_splits = p_enable; - VS::get_singleton()->light_directional_set_blend_splits(light, p_enable); + RS::get_singleton()->light_directional_set_blend_splits(light, p_enable); } -bool DirectionalLight::is_blend_splits_enabled() const { +bool DirectionalLight3D::is_blend_splits_enabled() const { return blend_splits; } -void DirectionalLight::_bind_methods() { +void DirectionalLight3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight::set_shadow_mode); - ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight::get_shadow_mode); + ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &DirectionalLight3D::set_shadow_mode); + ClassDB::bind_method(D_METHOD("get_shadow_mode"), &DirectionalLight3D::get_shadow_mode); - ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight::set_shadow_depth_range); - ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight::get_shadow_depth_range); + ClassDB::bind_method(D_METHOD("set_shadow_depth_range", "mode"), &DirectionalLight3D::set_shadow_depth_range); + ClassDB::bind_method(D_METHOD("get_shadow_depth_range"), &DirectionalLight3D::get_shadow_depth_range); - ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight::set_blend_splits); - ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight::is_blend_splits_enabled); + ClassDB::bind_method(D_METHOD("set_blend_splits", "enabled"), &DirectionalLight3D::set_blend_splits); + ClassDB::bind_method(D_METHOD("is_blend_splits_enabled"), &DirectionalLight3D::is_blend_splits_enabled); ADD_GROUP("Directional Shadow", "directional_shadow_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_mode", PROPERTY_HINT_ENUM, "Orthogonal,PSSM 2 Splits,PSSM 4 Splits"), "set_shadow_mode", "get_shadow_mode"); @@ -398,10 +431,9 @@ void DirectionalLight::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_split_3", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_param", "get_param", PARAM_SHADOW_SPLIT_3_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_fade_start", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_FADE_START); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "directional_shadow_blend_splits"), "set_blend_splits", "is_blend_splits_enabled"); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_normal_bias", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_param", "get_param", PARAM_SHADOW_NORMAL_BIAS); - ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_bias_split_scale", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_SHADOW_BIAS_SPLIT_SCALE); ADD_PROPERTY(PropertyInfo(Variant::INT, "directional_shadow_depth_range", PROPERTY_HINT_ENUM, "Stable,Optimized"), "set_shadow_depth_range", "get_shadow_depth_range"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_max_distance", PROPERTY_HINT_EXP_RANGE, "0,8192,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_MAX_DISTANCE); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "directional_shadow_pancake_size", PROPERTY_HINT_EXP_RANGE, "0,1024,0.1,or_greater"), "set_param", "get_param", PARAM_SHADOW_PANCAKE_SIZE); BIND_ENUM_CONSTANT(SHADOW_ORTHOGONAL); BIND_ENUM_CONSTANT(SHADOW_PARALLEL_2_SPLITS); @@ -411,35 +443,45 @@ void DirectionalLight::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_OPTIMIZED); } -DirectionalLight::DirectionalLight() : - Light(VisualServer::LIGHT_DIRECTIONAL) { +DirectionalLight3D::DirectionalLight3D() : + Light3D(RenderingServer::LIGHT_DIRECTIONAL) { - set_param(PARAM_SHADOW_NORMAL_BIAS, 0.8); - set_param(PARAM_SHADOW_BIAS, 0.1); set_param(PARAM_SHADOW_MAX_DISTANCE, 100); set_param(PARAM_SHADOW_FADE_START, 0.8); - set_param(PARAM_SHADOW_BIAS_SPLIT_SCALE, 0.25); set_shadow_mode(SHADOW_PARALLEL_4_SPLITS); set_shadow_depth_range(SHADOW_DEPTH_RANGE_STABLE); blend_splits = false; } -void OmniLight::set_shadow_mode(ShadowMode p_mode) { +void OmniLight3D::set_shadow_mode(ShadowMode p_mode) { shadow_mode = p_mode; - VS::get_singleton()->light_omni_set_shadow_mode(light, VS::LightOmniShadowMode(p_mode)); + RS::get_singleton()->light_omni_set_shadow_mode(light, RS::LightOmniShadowMode(p_mode)); } -OmniLight::ShadowMode OmniLight::get_shadow_mode() const { +OmniLight3D::ShadowMode OmniLight3D::get_shadow_mode() const { return shadow_mode; } -void OmniLight::_bind_methods() { +String OmniLight3D::get_configuration_warning() const { + String warning = Light3D::get_configuration_warning(); + + if (!has_shadow() && get_projector().is_valid()) { + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("Projector texture only works with shadows active."); + } + + return warning; +} + +void OmniLight3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight::set_shadow_mode); - ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight::get_shadow_mode); + ClassDB::bind_method(D_METHOD("set_shadow_mode", "mode"), &OmniLight3D::set_shadow_mode); + ClassDB::bind_method(D_METHOD("get_shadow_mode"), &OmniLight3D::get_shadow_mode); ADD_GROUP("Omni", "omni_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "omni_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE); @@ -450,27 +492,34 @@ void OmniLight::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_CUBE); } -OmniLight::OmniLight() : - Light(VisualServer::LIGHT_OMNI) { +OmniLight3D::OmniLight3D() : + Light3D(RenderingServer::LIGHT_OMNI) { set_shadow_mode(SHADOW_CUBE); } -String SpotLight::get_configuration_warning() const { - String warning = Light::get_configuration_warning(); +String SpotLight3D::get_configuration_warning() const { + String warning = Light3D::get_configuration_warning(); if (has_shadow() && get_param(PARAM_SPOT_ANGLE) >= 90.0) { if (warning != String()) { warning += "\n\n"; } - warning += TTR("A SpotLight with an angle wider than 90 degrees cannot cast shadows."); + warning += TTR("A SpotLight3D with an angle wider than 90 degrees cannot cast shadows."); + } + + if (!has_shadow() && get_projector().is_valid()) { + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("Projector texture only works with shadows active."); } return warning; } -void SpotLight::_bind_methods() { +void SpotLight3D::_bind_methods() { ADD_GROUP("Spot", "spot_"); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "spot_range", PROPERTY_HINT_EXP_RANGE, "0,4096,0.1,or_greater"), "set_param", "get_param", PARAM_RANGE); diff --git a/scene/3d/light.h b/scene/3d/light_3d.h index 16e0c47083..6e78217342 100644 --- a/scene/3d/light.h +++ b/scene/3d/light_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* light.h */ +/* light_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,34 +31,36 @@ #ifndef LIGHT_H #define LIGHT_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -class Light : public VisualInstance { +class Light3D : public VisualInstance3D { - GDCLASS(Light, VisualInstance); + GDCLASS(Light3D, VisualInstance3D); OBJ_CATEGORY("3D Light Nodes"); public: enum Param { - PARAM_ENERGY = VS::LIGHT_PARAM_ENERGY, - PARAM_INDIRECT_ENERGY = VS::LIGHT_PARAM_INDIRECT_ENERGY, - PARAM_SPECULAR = VS::LIGHT_PARAM_SPECULAR, - PARAM_RANGE = VS::LIGHT_PARAM_RANGE, - PARAM_ATTENUATION = VS::LIGHT_PARAM_ATTENUATION, - PARAM_SPOT_ANGLE = VS::LIGHT_PARAM_SPOT_ANGLE, - PARAM_SPOT_ATTENUATION = VS::LIGHT_PARAM_SPOT_ATTENUATION, - PARAM_CONTACT_SHADOW_SIZE = VS::LIGHT_PARAM_CONTACT_SHADOW_SIZE, - PARAM_SHADOW_MAX_DISTANCE = VS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, - PARAM_SHADOW_SPLIT_1_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, - PARAM_SHADOW_SPLIT_2_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, - PARAM_SHADOW_SPLIT_3_OFFSET = VS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET, - PARAM_SHADOW_FADE_START = VS::LIGHT_PARAM_SHADOW_FADE_START, - PARAM_SHADOW_NORMAL_BIAS = VS::LIGHT_PARAM_SHADOW_NORMAL_BIAS, - PARAM_SHADOW_BIAS = VS::LIGHT_PARAM_SHADOW_BIAS, - PARAM_SHADOW_BIAS_SPLIT_SCALE = VS::LIGHT_PARAM_SHADOW_BIAS_SPLIT_SCALE, - PARAM_MAX = VS::LIGHT_PARAM_MAX + PARAM_ENERGY = RS::LIGHT_PARAM_ENERGY, + PARAM_INDIRECT_ENERGY = RS::LIGHT_PARAM_INDIRECT_ENERGY, + PARAM_SPECULAR = RS::LIGHT_PARAM_SPECULAR, + PARAM_RANGE = RS::LIGHT_PARAM_RANGE, + PARAM_SIZE = RS::LIGHT_PARAM_SIZE, + PARAM_ATTENUATION = RS::LIGHT_PARAM_ATTENUATION, + PARAM_SPOT_ANGLE = RS::LIGHT_PARAM_SPOT_ANGLE, + PARAM_SPOT_ATTENUATION = RS::LIGHT_PARAM_SPOT_ATTENUATION, + PARAM_SHADOW_MAX_DISTANCE = RS::LIGHT_PARAM_SHADOW_MAX_DISTANCE, + PARAM_SHADOW_SPLIT_1_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_1_OFFSET, + PARAM_SHADOW_SPLIT_2_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_2_OFFSET, + PARAM_SHADOW_SPLIT_3_OFFSET = RS::LIGHT_PARAM_SHADOW_SPLIT_3_OFFSET, + PARAM_SHADOW_FADE_START = RS::LIGHT_PARAM_SHADOW_FADE_START, + PARAM_SHADOW_NORMAL_BIAS = RS::LIGHT_PARAM_SHADOW_NORMAL_BIAS, + PARAM_SHADOW_BIAS = RS::LIGHT_PARAM_SHADOW_BIAS, + PARAM_SHADOW_PANCAKE_SIZE = RS::LIGHT_PARAM_SHADOW_PANCAKE_SIZE, + PARAM_SHADOW_BLUR = RS::LIGHT_PARAM_SHADOW_BLUR, + PARAM_TRANSMITTANCE_BIAS = RS::LIGHT_PARAM_TRANSMITTANCE_BIAS, + PARAM_MAX = RS::LIGHT_PARAM_MAX }; enum BakeMode { @@ -75,10 +77,11 @@ private: bool negative; bool reverse_cull; uint32_t cull_mask; - VS::LightType type; + RS::LightType type; bool editor_only; void _update_visibility(); BakeMode bake_mode; + Ref<Texture2D> projector; // bind helpers @@ -91,10 +94,10 @@ protected: void _notification(int p_what); virtual void _validate_property(PropertyInfo &property) const; - Light(VisualServer::LightType p_type); + Light3D(RenderingServer::LightType p_type); public: - VS::LightType get_light_type() const { return type; } + RS::LightType get_light_type() const { return type; } void set_editor_only(bool p_editor_only); bool is_editor_only() const; @@ -123,19 +126,22 @@ public: void set_bake_mode(BakeMode p_mode); BakeMode get_bake_mode() const; + void set_projector(const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_projector() const; + virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; - Light(); - ~Light(); + Light3D(); + ~Light3D(); }; -VARIANT_ENUM_CAST(Light::Param); -VARIANT_ENUM_CAST(Light::BakeMode); +VARIANT_ENUM_CAST(Light3D::Param); +VARIANT_ENUM_CAST(Light3D::BakeMode); -class DirectionalLight : public Light { +class DirectionalLight3D : public Light3D { - GDCLASS(DirectionalLight, Light); + GDCLASS(DirectionalLight3D, Light3D); public: enum ShadowMode { @@ -145,8 +151,8 @@ public: }; enum ShadowDepthRange { - SHADOW_DEPTH_RANGE_STABLE = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE, - SHADOW_DEPTH_RANGE_OPTIMIZED = VS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED, + SHADOW_DEPTH_RANGE_STABLE = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_STABLE, + SHADOW_DEPTH_RANGE_OPTIMIZED = RS::LIGHT_DIRECTIONAL_SHADOW_DEPTH_RANGE_OPTIMIZED, }; private: @@ -167,15 +173,15 @@ public: void set_blend_splits(bool p_enable); bool is_blend_splits_enabled() const; - DirectionalLight(); + DirectionalLight3D(); }; -VARIANT_ENUM_CAST(DirectionalLight::ShadowMode) -VARIANT_ENUM_CAST(DirectionalLight::ShadowDepthRange) +VARIANT_ENUM_CAST(DirectionalLight3D::ShadowMode) +VARIANT_ENUM_CAST(DirectionalLight3D::ShadowDepthRange) -class OmniLight : public Light { +class OmniLight3D : public Light3D { - GDCLASS(OmniLight, Light); + GDCLASS(OmniLight3D, Light3D); public: // omni light @@ -194,14 +200,16 @@ public: void set_shadow_mode(ShadowMode p_mode); ShadowMode get_shadow_mode() const; - OmniLight(); + virtual String get_configuration_warning() const; + + OmniLight3D(); }; -VARIANT_ENUM_CAST(OmniLight::ShadowMode) +VARIANT_ENUM_CAST(OmniLight3D::ShadowMode) -class SpotLight : public Light { +class SpotLight3D : public Light3D { - GDCLASS(SpotLight, Light); + GDCLASS(SpotLight3D, Light3D); protected: static void _bind_methods(); @@ -209,8 +217,8 @@ protected: public: virtual String get_configuration_warning() const; - SpotLight() : - Light(VisualServer::LIGHT_SPOT) {} + SpotLight3D() : + Light3D(RenderingServer::LIGHT_SPOT) {} }; #endif diff --git a/scene/3d/listener.cpp b/scene/3d/listener_3d.cpp index 2779d14b57..426e34ea80 100644 --- a/scene/3d/listener.cpp +++ b/scene/3d/listener_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* listener.cpp */ +/* listener_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "listener.h" +#include "listener_3d.h" #include "scene/resources/mesh.h" -void Listener::_update_audio_listener_state() { +void Listener3D::_update_audio_listener_state() { } -void Listener::_request_listener_update() { +void Listener3D::_request_listener_update() { _update_listener(); } -bool Listener::_set(const StringName &p_name, const Variant &p_value) { +bool Listener3D::_set(const StringName &p_name, const Variant &p_value) { if (p_name == "current") { if (p_value.operator bool()) { @@ -53,7 +53,7 @@ bool Listener::_set(const StringName &p_name, const Variant &p_value) { return true; } -bool Listener::_get(const StringName &p_name, Variant &r_ret) const { +bool Listener3D::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "current") { if (is_inside_tree() && get_tree()->is_node_being_edited(this)) { @@ -67,19 +67,19 @@ bool Listener::_get(const StringName &p_name, Variant &r_ret) const { return true; } -void Listener::_get_property_list(List<PropertyInfo> *p_list) const { +void Listener3D::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::BOOL, "current")); } -void Listener::_update_listener() { +void Listener3D::_update_listener() { if (is_inside_tree() && is_current()) { get_viewport()->_listener_transform_changed_notify(); } } -void Listener::_notification(int p_what) { +void Listener3D::_notification(int p_what) { switch (p_what) { @@ -109,12 +109,12 @@ void Listener::_notification(int p_what) { } } -Transform Listener::get_listener_transform() const { +Transform Listener3D::get_listener_transform() const { return get_global_transform().orthonormalized(); } -void Listener::make_current() { +void Listener3D::make_current() { current = true; @@ -124,19 +124,19 @@ void Listener::make_current() { get_viewport()->_listener_set(this); } -void Listener::clear_current() { +void Listener3D::clear_current() { current = false; if (!is_inside_tree()) return; if (get_viewport()->get_listener() == this) { - get_viewport()->_listener_set(NULL); + get_viewport()->_listener_set(nullptr); get_viewport()->_listener_make_next_current(this); } } -bool Listener::is_current() const { +bool Listener3D::is_current() const { if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) { @@ -147,26 +147,26 @@ bool Listener::is_current() const { return false; } -bool Listener::_can_gizmo_scale() const { +bool Listener3D::_can_gizmo_scale() const { return false; } -RES Listener::_get_gizmo_geometry() const { +RES Listener3D::_get_gizmo_geometry() const { Ref<ArrayMesh> mesh = memnew(ArrayMesh); return mesh; } -void Listener::_bind_methods() { +void Listener3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("make_current"), &Listener::make_current); - ClassDB::bind_method(D_METHOD("clear_current"), &Listener::clear_current); - ClassDB::bind_method(D_METHOD("is_current"), &Listener::is_current); - ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener::get_listener_transform); + ClassDB::bind_method(D_METHOD("make_current"), &Listener3D::make_current); + ClassDB::bind_method(D_METHOD("clear_current"), &Listener3D::clear_current); + ClassDB::bind_method(D_METHOD("is_current"), &Listener3D::is_current); + ClassDB::bind_method(D_METHOD("get_listener_transform"), &Listener3D::get_listener_transform); } -Listener::Listener() { +Listener3D::Listener3D() { current = false; force_change = false; @@ -174,5 +174,5 @@ Listener::Listener() { //active=false; } -Listener::~Listener() { +Listener3D::~Listener3D() { } diff --git a/scene/3d/listener.h b/scene/3d/listener_3d.h index 287e67f31e..3383d6725e 100644 --- a/scene/3d/listener.h +++ b/scene/3d/listener_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* listener.h */ +/* listener_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef LISTENER_H -#define LISTENER_H +#ifndef LISTENER_3D_H +#define LISTENER_3D_H -#include "scene/3d/spatial.h" -#include "scene/main/viewport.h" +#include "scene/3d/node_3d.h" +#include "scene/main/window.h" -class Listener : public Spatial { +class Listener3D : public Node3D { - GDCLASS(Listener, Spatial); + GDCLASS(Listener3D, Node3D); private: bool force_change; @@ -71,8 +71,8 @@ public: void set_visible_layers(uint32_t p_layers); uint32_t get_visible_layers() const; - Listener(); - ~Listener(); + Listener3D(); + ~Listener3D(); }; #endif diff --git a/scene/3d/mesh_instance.cpp b/scene/3d/mesh_instance_3d.cpp index 4ca139ebbc..cdc8db8aea 100644 --- a/scene/3d/mesh_instance.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* mesh_instance.cpp */ +/* mesh_instance_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "mesh_instance.h" +#include "mesh_instance_3d.h" -#include "collision_shape.h" +#include "collision_shape_3d.h" #include "core/core_string_names.h" -#include "physics_body.h" +#include "physics_body_3d.h" #include "scene/resources/material.h" -#include "skeleton.h" +#include "skeleton_3d.h" -bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) { +bool MeshInstance3D::_set(const StringName &p_name, const Variant &p_value) { //this is not _too_ bad performance wise, really. it only arrives here if the property was not set anywhere else. //add to it that it's probably found on first call to _set anyway. @@ -47,7 +47,7 @@ bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) { Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.find(p_name); if (E) { E->get().value = p_value; - VisualServer::get_singleton()->instance_set_blend_shape_weight(get_instance(), E->get().idx, E->get().value); + RenderingServer::get_singleton()->instance_set_blend_shape_weight(get_instance(), E->get().idx, E->get().value); return true; } @@ -63,7 +63,7 @@ bool MeshInstance::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool MeshInstance::_get(const StringName &p_name, Variant &r_ret) const { +bool MeshInstance3D::_get(const StringName &p_name, Variant &r_ret) const { if (!get_instance().is_valid()) return false; @@ -84,7 +84,7 @@ bool MeshInstance::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void MeshInstance::_get_property_list(List<PropertyInfo> *p_list) const { +void MeshInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { List<String> ls; for (const Map<StringName, BlendShapeTrack>::Element *E = blend_shape_tracks.front(); E; E = E->next()) { @@ -105,13 +105,13 @@ void MeshInstance::_get_property_list(List<PropertyInfo> *p_list) const { } } -void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) { +void MeshInstance3D::set_mesh(const Ref<Mesh> &p_mesh) { if (mesh == p_mesh) return; if (mesh.is_valid()) { - mesh->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance::_mesh_changed)); + mesh->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance3D::_mesh_changed)); materials.clear(); } @@ -128,7 +128,7 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) { blend_shape_tracks["blend_shapes/" + String(mesh->get_blend_shape_name(i))] = mt; } - mesh->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance::_mesh_changed)); + mesh->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &MeshInstance3D::_mesh_changed)); materials.resize(mesh->get_surface_count()); set_base(mesh->get_rid()); @@ -141,17 +141,17 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) { _change_notify(); } -Ref<Mesh> MeshInstance::get_mesh() const { +Ref<Mesh> MeshInstance3D::get_mesh() const { return mesh; } -void MeshInstance::_resolve_skeleton_path() { +void MeshInstance3D::_resolve_skeleton_path() { Ref<SkinReference> new_skin_reference; if (!skeleton_path.is_empty()) { - Skeleton *skeleton = Object::cast_to<Skeleton>(get_node(skeleton_path)); + Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(get_node(skeleton_path)); if (skeleton) { new_skin_reference = skeleton->register_skin(skin_internal); if (skin_internal.is_null()) { @@ -165,13 +165,13 @@ void MeshInstance::_resolve_skeleton_path() { skin_ref = new_skin_reference; if (skin_ref.is_valid()) { - VisualServer::get_singleton()->instance_attach_skeleton(get_instance(), skin_ref->get_skeleton()); + RenderingServer::get_singleton()->instance_attach_skeleton(get_instance(), skin_ref->get_skeleton()); } else { - VisualServer::get_singleton()->instance_attach_skeleton(get_instance(), RID()); + RenderingServer::get_singleton()->instance_attach_skeleton(get_instance(), RID()); } } -void MeshInstance::set_skin(const Ref<Skin> &p_skin) { +void MeshInstance3D::set_skin(const Ref<Skin> &p_skin) { skin_internal = p_skin; skin = p_skin; if (!is_inside_tree()) @@ -179,11 +179,11 @@ void MeshInstance::set_skin(const Ref<Skin> &p_skin) { _resolve_skeleton_path(); } -Ref<Skin> MeshInstance::get_skin() const { +Ref<Skin> MeshInstance3D::get_skin() const { return skin; } -void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) { +void MeshInstance3D::set_skeleton_path(const NodePath &p_skeleton) { skeleton_path = p_skeleton; if (!is_inside_tree()) @@ -191,11 +191,11 @@ void MeshInstance::set_skeleton_path(const NodePath &p_skeleton) { _resolve_skeleton_path(); } -NodePath MeshInstance::get_skeleton_path() { +NodePath MeshInstance3D::get_skeleton_path() { return skeleton_path; } -AABB MeshInstance::get_aabb() const { +AABB MeshInstance3D::get_aabb() const { if (!mesh.is_null()) return mesh->get_aabb(); @@ -203,7 +203,7 @@ AABB MeshInstance::get_aabb() const { return AABB(); } -Vector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> MeshInstance3D::get_faces(uint32_t p_usage_flags) const { if (!(p_usage_flags & (FACES_SOLID | FACES_ENCLOSING))) return Vector<Face3>(); @@ -214,103 +214,123 @@ Vector<Face3> MeshInstance::get_faces(uint32_t p_usage_flags) const { return mesh->get_faces(); } -Node *MeshInstance::create_trimesh_collision_node() { +Node *MeshInstance3D::create_trimesh_collision_node() { if (mesh.is_null()) - return NULL; + return nullptr; - Ref<Shape> shape = mesh->create_trimesh_shape(); + Ref<Shape3D> shape = mesh->create_trimesh_shape(); if (shape.is_null()) - return NULL; + return nullptr; - StaticBody *static_body = memnew(StaticBody); - CollisionShape *cshape = memnew(CollisionShape); + StaticBody3D *static_body = memnew(StaticBody3D); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shape); static_body->add_child(cshape); return static_body; } -void MeshInstance::create_trimesh_collision() { +void MeshInstance3D::create_trimesh_collision() { - StaticBody *static_body = Object::cast_to<StaticBody>(create_trimesh_collision_node()); + StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_trimesh_collision_node()); ERR_FAIL_COND(!static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body); if (get_owner()) { - CollisionShape *cshape = Object::cast_to<CollisionShape>(static_body->get_child(0)); + CollisionShape3D *cshape = Object::cast_to<CollisionShape3D>(static_body->get_child(0)); static_body->set_owner(get_owner()); cshape->set_owner(get_owner()); } } -Node *MeshInstance::create_convex_collision_node() { +Node *MeshInstance3D::create_convex_collision_node() { if (mesh.is_null()) - return NULL; + return nullptr; - Ref<Shape> shape = mesh->create_convex_shape(); + Ref<Shape3D> shape = mesh->create_convex_shape(); if (shape.is_null()) - return NULL; + return nullptr; - StaticBody *static_body = memnew(StaticBody); - CollisionShape *cshape = memnew(CollisionShape); + StaticBody3D *static_body = memnew(StaticBody3D); + CollisionShape3D *cshape = memnew(CollisionShape3D); cshape->set_shape(shape); static_body->add_child(cshape); return static_body; } -void MeshInstance::create_convex_collision() { +void MeshInstance3D::create_convex_collision() { - StaticBody *static_body = Object::cast_to<StaticBody>(create_convex_collision_node()); + StaticBody3D *static_body = Object::cast_to<StaticBody3D>(create_convex_collision_node()); ERR_FAIL_COND(!static_body); static_body->set_name(String(get_name()) + "_col"); add_child(static_body); if (get_owner()) { - CollisionShape *cshape = Object::cast_to<CollisionShape>(static_body->get_child(0)); + CollisionShape3D *cshape = Object::cast_to<CollisionShape3D>(static_body->get_child(0)); static_body->set_owner(get_owner()); cshape->set_owner(get_owner()); } } -void MeshInstance::_notification(int p_what) { +void MeshInstance3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { _resolve_skeleton_path(); } } -int MeshInstance::get_surface_material_count() const { +int MeshInstance3D::get_surface_material_count() const { return materials.size(); } -void MeshInstance::set_surface_material(int p_surface, const Ref<Material> &p_material) { +void MeshInstance3D::set_surface_material(int p_surface, const Ref<Material> &p_material) { ERR_FAIL_INDEX(p_surface, materials.size()); materials.write[p_surface] = p_material; if (materials[p_surface].is_valid()) - VS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid()); + RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, materials[p_surface]->get_rid()); else - VS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID()); + RS::get_singleton()->instance_set_surface_material(get_instance(), p_surface, RID()); } -Ref<Material> MeshInstance::get_surface_material(int p_surface) const { +Ref<Material> MeshInstance3D::get_surface_material(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, materials.size(), Ref<Material>()); return materials[p_surface]; } -void MeshInstance::_mesh_changed() { +Ref<Material> MeshInstance3D::get_active_material(int p_surface) const { + + Ref<Material> material_override = get_material_override(); + if (material_override.is_valid()) { + return material_override; + } + + Ref<Material> surface_material = get_surface_material(p_surface); + if (surface_material.is_valid()) { + return surface_material; + } + + Ref<Mesh> mesh = get_mesh(); + if (mesh.is_valid()) { + return mesh->surface_get_material(p_surface); + } + + return Ref<Material>(); +} + +void MeshInstance3D::_mesh_changed() { materials.resize(mesh->get_surface_count()); } -void MeshInstance::create_debug_tangents() { +void MeshInstance3D::create_debug_tangents() { Vector<Vector3> lines; Vector<Color> colors; @@ -371,7 +391,7 @@ void MeshInstance::create_debug_tangents() { am->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a); am->surface_set_material(0, sm); - MeshInstance *mi = memnew(MeshInstance); + MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(am); mi->set_name("DebugTangents"); add_child(mi); @@ -385,37 +405,38 @@ void MeshInstance::create_debug_tangents() { } } -void MeshInstance::_bind_methods() { +void MeshInstance3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance::set_mesh); - ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance::get_mesh); - ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &MeshInstance::set_skeleton_path); - ClassDB::bind_method(D_METHOD("get_skeleton_path"), &MeshInstance::get_skeleton_path); - ClassDB::bind_method(D_METHOD("set_skin", "skin"), &MeshInstance::set_skin); - ClassDB::bind_method(D_METHOD("get_skin"), &MeshInstance::get_skin); + ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &MeshInstance3D::set_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &MeshInstance3D::get_mesh); + ClassDB::bind_method(D_METHOD("set_skeleton_path", "skeleton_path"), &MeshInstance3D::set_skeleton_path); + ClassDB::bind_method(D_METHOD("get_skeleton_path"), &MeshInstance3D::get_skeleton_path); + ClassDB::bind_method(D_METHOD("set_skin", "skin"), &MeshInstance3D::set_skin); + ClassDB::bind_method(D_METHOD("get_skin"), &MeshInstance3D::get_skin); - ClassDB::bind_method(D_METHOD("get_surface_material_count"), &MeshInstance::get_surface_material_count); - ClassDB::bind_method(D_METHOD("set_surface_material", "surface", "material"), &MeshInstance::set_surface_material); - ClassDB::bind_method(D_METHOD("get_surface_material", "surface"), &MeshInstance::get_surface_material); + ClassDB::bind_method(D_METHOD("get_surface_material_count"), &MeshInstance3D::get_surface_material_count); + ClassDB::bind_method(D_METHOD("set_surface_material", "surface", "material"), &MeshInstance3D::set_surface_material); + ClassDB::bind_method(D_METHOD("get_surface_material", "surface"), &MeshInstance3D::get_surface_material); + ClassDB::bind_method(D_METHOD("get_active_material", "surface"), &MeshInstance3D::get_active_material); - ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance::create_trimesh_collision); - ClassDB::set_method_flags("MeshInstance", "create_trimesh_collision", METHOD_FLAGS_DEFAULT); - ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance::create_convex_collision); - ClassDB::set_method_flags("MeshInstance", "create_convex_collision", METHOD_FLAGS_DEFAULT); + ClassDB::bind_method(D_METHOD("create_trimesh_collision"), &MeshInstance3D::create_trimesh_collision); + ClassDB::set_method_flags("MeshInstance3D", "create_trimesh_collision", METHOD_FLAGS_DEFAULT); + ClassDB::bind_method(D_METHOD("create_convex_collision"), &MeshInstance3D::create_convex_collision); + ClassDB::set_method_flags("MeshInstance3D", "create_convex_collision", METHOD_FLAGS_DEFAULT); - ClassDB::bind_method(D_METHOD("create_debug_tangents"), &MeshInstance::create_debug_tangents); - ClassDB::set_method_flags("MeshInstance", "create_debug_tangents", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("create_debug_tangents"), &MeshInstance3D::create_debug_tangents); + ClassDB::set_method_flags("MeshInstance3D", "create_debug_tangents", METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh"); ADD_GROUP("Skeleton", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skin", PROPERTY_HINT_RESOURCE_TYPE, "Skin"), "set_skin", "get_skin"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton"), "set_skeleton_path", "get_skeleton_path"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "skeleton", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Skeleton3D"), "set_skeleton_path", "get_skeleton_path"); ADD_GROUP("", ""); } -MeshInstance::MeshInstance() { +MeshInstance3D::MeshInstance3D() { skeleton_path = NodePath(".."); } -MeshInstance::~MeshInstance() { +MeshInstance3D::~MeshInstance3D() { } diff --git a/scene/3d/mesh_instance.h b/scene/3d/mesh_instance_3d.h index a6190e7660..914148f427 100644 --- a/scene/3d/mesh_instance.h +++ b/scene/3d/mesh_instance_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* mesh_instance.h */ +/* mesh_instance_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,14 +31,14 @@ #ifndef MESH_INSTANCE_H #define MESH_INSTANCE_H -#include "scene/3d/skeleton.h" -#include "scene/3d/visual_instance.h" +#include "scene/3d/skeleton_3d.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/mesh.h" #include "scene/resources/skin.h" -class MeshInstance : public GeometryInstance { +class MeshInstance3D : public GeometryInstance3D { - GDCLASS(MeshInstance, GeometryInstance); + GDCLASS(MeshInstance3D, GeometryInstance3D); protected: Ref<Mesh> mesh; @@ -84,6 +84,7 @@ public: int get_surface_material_count() const; void set_surface_material(int p_surface, const Ref<Material> &p_material); Ref<Material> get_surface_material(int p_surface) const; + Ref<Material> get_active_material(int p_surface) const; Node *create_trimesh_collision_node(); void create_trimesh_collision(); @@ -96,8 +97,8 @@ public: virtual AABB get_aabb() const; virtual Vector<Face3> get_faces(uint32_t p_usage_flags) const; - MeshInstance(); - ~MeshInstance(); + MeshInstance3D(); + ~MeshInstance3D(); }; #endif diff --git a/scene/3d/multimesh_instance.cpp b/scene/3d/multimesh_instance_3d.cpp index 075eb0a1ec..a625a34283 100644 --- a/scene/3d/multimesh_instance.cpp +++ b/scene/3d/multimesh_instance_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* multimesh_instance.cpp */ +/* multimesh_instance_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,16 +28,16 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "multimesh_instance.h" +#include "multimesh_instance_3d.h" -void MultiMeshInstance::_bind_methods() { +void MultiMeshInstance3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_multimesh", "multimesh"), &MultiMeshInstance::set_multimesh); - ClassDB::bind_method(D_METHOD("get_multimesh"), &MultiMeshInstance::get_multimesh); + ClassDB::bind_method(D_METHOD("set_multimesh", "multimesh"), &MultiMeshInstance3D::set_multimesh); + ClassDB::bind_method(D_METHOD("get_multimesh"), &MultiMeshInstance3D::get_multimesh); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "multimesh", PROPERTY_HINT_RESOURCE_TYPE, "MultiMesh"), "set_multimesh", "get_multimesh"); } -void MultiMeshInstance::set_multimesh(const Ref<MultiMesh> &p_multimesh) { +void MultiMeshInstance3D::set_multimesh(const Ref<MultiMesh> &p_multimesh) { multimesh = p_multimesh; if (multimesh.is_valid()) @@ -46,17 +46,17 @@ void MultiMeshInstance::set_multimesh(const Ref<MultiMesh> &p_multimesh) { set_base(RID()); } -Ref<MultiMesh> MultiMeshInstance::get_multimesh() const { +Ref<MultiMesh> MultiMeshInstance3D::get_multimesh() const { return multimesh; } -Vector<Face3> MultiMeshInstance::get_faces(uint32_t p_usage_flags) const { +Vector<Face3> MultiMeshInstance3D::get_faces(uint32_t p_usage_flags) const { return Vector<Face3>(); } -AABB MultiMeshInstance::get_aabb() const { +AABB MultiMeshInstance3D::get_aabb() const { if (multimesh.is_null()) return AABB(); @@ -64,8 +64,8 @@ AABB MultiMeshInstance::get_aabb() const { return multimesh->get_aabb(); } -MultiMeshInstance::MultiMeshInstance() { +MultiMeshInstance3D::MultiMeshInstance3D() { } -MultiMeshInstance::~MultiMeshInstance() { +MultiMeshInstance3D::~MultiMeshInstance3D() { } diff --git a/scene/3d/multimesh_instance.h b/scene/3d/multimesh_instance_3d.h index 2b59c3b96c..87ec9e120e 100644 --- a/scene/3d/multimesh_instance.h +++ b/scene/3d/multimesh_instance_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* multimesh_instance.h */ +/* multimesh_instance_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef MULTIMESH_INSTANCE_H -#define MULTIMESH_INSTANCE_H +#ifndef MULTIMESH_INSTANCE_3D_H +#define MULTIMESH_INSTANCE_3D_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/multimesh.h" -class MultiMeshInstance : public GeometryInstance { - GDCLASS(MultiMeshInstance, GeometryInstance); +class MultiMeshInstance3D : public GeometryInstance3D { + GDCLASS(MultiMeshInstance3D, GeometryInstance3D); Ref<MultiMesh> multimesh; @@ -51,8 +51,8 @@ public: virtual AABB get_aabb() const; - MultiMeshInstance(); - ~MultiMeshInstance(); + MultiMeshInstance3D(); + ~MultiMeshInstance3D(); }; #endif // MULTIMESH_INSTANCE_H diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation_3d.cpp index 8c543bc97f..f880f65d37 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation.cpp */ +/* navigation_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,91 +28,91 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation.h" +#include "navigation_3d.h" -#include "servers/navigation_server.h" +#include "servers/navigation_server_3d.h" -Vector<Vector3> Navigation::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) const { +Vector<Vector3> Navigation3D::get_simple_path(const Vector3 &p_start, const Vector3 &p_end, bool p_optimize) const { - return NavigationServer::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); + return NavigationServer3D::get_singleton()->map_get_path(map, p_start, p_end, p_optimize); } -Vector3 Navigation::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const { - return NavigationServer::get_singleton()->map_get_closest_point_to_segment(map, p_from, p_to, p_use_collision); +Vector3 Navigation3D::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const { + return NavigationServer3D::get_singleton()->map_get_closest_point_to_segment(map, p_from, p_to, p_use_collision); } -Vector3 Navigation::get_closest_point(const Vector3 &p_point) const { - return NavigationServer::get_singleton()->map_get_closest_point(map, p_point); +Vector3 Navigation3D::get_closest_point(const Vector3 &p_point) const { + return NavigationServer3D::get_singleton()->map_get_closest_point(map, p_point); } -Vector3 Navigation::get_closest_point_normal(const Vector3 &p_point) const { - return NavigationServer::get_singleton()->map_get_closest_point_normal(map, p_point); +Vector3 Navigation3D::get_closest_point_normal(const Vector3 &p_point) const { + return NavigationServer3D::get_singleton()->map_get_closest_point_normal(map, p_point); } -RID Navigation::get_closest_point_owner(const Vector3 &p_point) const { - return NavigationServer::get_singleton()->map_get_closest_point_owner(map, p_point); +RID Navigation3D::get_closest_point_owner(const Vector3 &p_point) const { + return NavigationServer3D::get_singleton()->map_get_closest_point_owner(map, p_point); } -void Navigation::set_up_vector(const Vector3 &p_up) { +void Navigation3D::set_up_vector(const Vector3 &p_up) { up = p_up; - NavigationServer::get_singleton()->map_set_up(map, up); + NavigationServer3D::get_singleton()->map_set_up(map, up); } -Vector3 Navigation::get_up_vector() const { +Vector3 Navigation3D::get_up_vector() const { return up; } -void Navigation::set_cell_size(float p_cell_size) { +void Navigation3D::set_cell_size(float p_cell_size) { cell_size = p_cell_size; - NavigationServer::get_singleton()->map_set_cell_size(map, cell_size); + NavigationServer3D::get_singleton()->map_set_cell_size(map, cell_size); } -void Navigation::set_edge_connection_margin(float p_edge_connection_margin) { +void Navigation3D::set_edge_connection_margin(float p_edge_connection_margin) { edge_connection_margin = p_edge_connection_margin; - NavigationServer::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); + NavigationServer3D::get_singleton()->map_set_edge_connection_margin(map, edge_connection_margin); } -void Navigation::_bind_methods() { +void Navigation3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_rid"), &Navigation::get_rid); + ClassDB::bind_method(D_METHOD("get_rid"), &Navigation3D::get_rid); - ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation::get_simple_path, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "start", "end", "use_collision"), &Navigation::get_closest_point_to_segment, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation::get_closest_point); - ClassDB::bind_method(D_METHOD("get_closest_point_normal", "to_point"), &Navigation::get_closest_point_normal); - ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation::get_closest_point_owner); + ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation3D::get_simple_path, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "start", "end", "use_collision"), &Navigation3D::get_closest_point_to_segment, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation3D::get_closest_point); + ClassDB::bind_method(D_METHOD("get_closest_point_normal", "to_point"), &Navigation3D::get_closest_point_normal); + ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation3D::get_closest_point_owner); - ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation::set_up_vector); - ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation::get_up_vector); + ClassDB::bind_method(D_METHOD("set_up_vector", "up"), &Navigation3D::set_up_vector); + ClassDB::bind_method(D_METHOD("get_up_vector"), &Navigation3D::get_up_vector); - ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &Navigation::set_cell_size); - ClassDB::bind_method(D_METHOD("get_cell_size"), &Navigation::get_cell_size); + ClassDB::bind_method(D_METHOD("set_cell_size", "cell_size"), &Navigation3D::set_cell_size); + ClassDB::bind_method(D_METHOD("get_cell_size"), &Navigation3D::get_cell_size); - ClassDB::bind_method(D_METHOD("set_edge_connection_margin", "margin"), &Navigation::set_edge_connection_margin); - ClassDB::bind_method(D_METHOD("get_edge_connection_margin"), &Navigation::get_edge_connection_margin); + ClassDB::bind_method(D_METHOD("set_edge_connection_margin", "margin"), &Navigation3D::set_edge_connection_margin); + ClassDB::bind_method(D_METHOD("get_edge_connection_margin"), &Navigation3D::get_edge_connection_margin); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "up_vector"), "set_up_vector", "get_up_vector"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "cell_size"), "set_cell_size", "get_cell_size"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "edge_connection_margin"), "set_edge_connection_margin", "get_edge_connection_margin"); } -void Navigation::_notification(int p_what) { +void Navigation3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - NavigationServer::get_singleton()->map_set_active(map, true); + NavigationServer3D::get_singleton()->map_set_active(map, true); } break; case NOTIFICATION_EXIT_TREE: { - NavigationServer::get_singleton()->map_set_active(map, false); + NavigationServer3D::get_singleton()->map_set_active(map, false); } break; } } -Navigation::Navigation() { +Navigation3D::Navigation3D() { - map = NavigationServer::get_singleton()->map_create(); + map = NavigationServer3D::get_singleton()->map_create(); set_cell_size(0.3); set_edge_connection_margin(5.0); // Five meters, depends alot on the agents radius @@ -120,6 +120,6 @@ Navigation::Navigation() { up = Vector3(0, 1, 0); } -Navigation::~Navigation() { - NavigationServer::get_singleton()->free(map); +Navigation3D::~Navigation3D() { + NavigationServer3D::get_singleton()->free(map); } diff --git a/scene/3d/navigation.h b/scene/3d/navigation_3d.h index 08f306611f..daa9558125 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation.h */ +/* navigation_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef NAVIGATION_H -#define NAVIGATION_H +#ifndef NAVIGATION_3D_H +#define NAVIGATION_3D_H -#include "scene/3d/navigation_region.h" -#include "scene/3d/spatial.h" +#include "scene/3d/navigation_region_3d.h" +#include "scene/3d/node_3d.h" -class Navigation : public Spatial { +class Navigation3D : public Node3D { - GDCLASS(Navigation, Spatial); + GDCLASS(Navigation3D, Node3D); RID map; @@ -72,8 +72,8 @@ public: Vector3 get_closest_point_normal(const Vector3 &p_point) const; RID get_closest_point_owner(const Vector3 &p_point) const; - Navigation(); - ~Navigation(); + Navigation3D(); + ~Navigation3D(); }; #endif // NAVIGATION_H diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent_3d.cpp index 728fc947e9..0449ab15b7 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_agent.cpp */ +/* navigation_agent_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,57 +28,57 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_agent.h" +#include "navigation_agent_3d.h" #include "core/engine.h" -#include "scene/3d/navigation.h" -#include "servers/navigation_server.h" +#include "scene/3d/navigation_3d.h" +#include "servers/navigation_server_3d.h" -void NavigationAgent::_bind_methods() { +void NavigationAgent3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent::set_target_desired_distance); - ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent::get_target_desired_distance); + ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent3D::set_target_desired_distance); + ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent3D::get_target_desired_distance); - ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationAgent::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &NavigationAgent::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationAgent3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &NavigationAgent3D::get_radius); - ClassDB::bind_method(D_METHOD("set_agent_height_offset", "agent_height_offset"), &NavigationAgent::set_agent_height_offset); - ClassDB::bind_method(D_METHOD("get_agent_height_offset"), &NavigationAgent::get_agent_height_offset); + ClassDB::bind_method(D_METHOD("set_agent_height_offset", "agent_height_offset"), &NavigationAgent3D::set_agent_height_offset); + ClassDB::bind_method(D_METHOD("get_agent_height_offset"), &NavigationAgent3D::get_agent_height_offset); - ClassDB::bind_method(D_METHOD("set_ignore_y", "ignore"), &NavigationAgent::set_ignore_y); - ClassDB::bind_method(D_METHOD("get_ignore_y"), &NavigationAgent::get_ignore_y); + ClassDB::bind_method(D_METHOD("set_ignore_y", "ignore"), &NavigationAgent3D::set_ignore_y); + ClassDB::bind_method(D_METHOD("get_ignore_y"), &NavigationAgent3D::get_ignore_y); - ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationAgent::set_navigation_node); - ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationAgent::get_navigation_node); + ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationAgent3D::set_navigation_node); + ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationAgent3D::get_navigation_node); - ClassDB::bind_method(D_METHOD("set_neighbor_dist", "neighbor_dist"), &NavigationAgent::set_neighbor_dist); - ClassDB::bind_method(D_METHOD("get_neighbor_dist"), &NavigationAgent::get_neighbor_dist); + ClassDB::bind_method(D_METHOD("set_neighbor_dist", "neighbor_dist"), &NavigationAgent3D::set_neighbor_dist); + ClassDB::bind_method(D_METHOD("get_neighbor_dist"), &NavigationAgent3D::get_neighbor_dist); - ClassDB::bind_method(D_METHOD("set_max_neighbors", "max_neighbors"), &NavigationAgent::set_max_neighbors); - ClassDB::bind_method(D_METHOD("get_max_neighbors"), &NavigationAgent::get_max_neighbors); + ClassDB::bind_method(D_METHOD("set_max_neighbors", "max_neighbors"), &NavigationAgent3D::set_max_neighbors); + ClassDB::bind_method(D_METHOD("get_max_neighbors"), &NavigationAgent3D::get_max_neighbors); - ClassDB::bind_method(D_METHOD("set_time_horizon", "time_horizon"), &NavigationAgent::set_time_horizon); - ClassDB::bind_method(D_METHOD("get_time_horizon"), &NavigationAgent::get_time_horizon); + ClassDB::bind_method(D_METHOD("set_time_horizon", "time_horizon"), &NavigationAgent3D::set_time_horizon); + ClassDB::bind_method(D_METHOD("get_time_horizon"), &NavigationAgent3D::get_time_horizon); - ClassDB::bind_method(D_METHOD("set_max_speed", "max_speed"), &NavigationAgent::set_max_speed); - ClassDB::bind_method(D_METHOD("get_max_speed"), &NavigationAgent::get_max_speed); + ClassDB::bind_method(D_METHOD("set_max_speed", "max_speed"), &NavigationAgent3D::set_max_speed); + ClassDB::bind_method(D_METHOD("get_max_speed"), &NavigationAgent3D::get_max_speed); - ClassDB::bind_method(D_METHOD("set_path_max_distance", "max_speed"), &NavigationAgent::set_path_max_distance); - ClassDB::bind_method(D_METHOD("get_path_max_distance"), &NavigationAgent::get_path_max_distance); + ClassDB::bind_method(D_METHOD("set_path_max_distance", "max_speed"), &NavigationAgent3D::set_path_max_distance); + ClassDB::bind_method(D_METHOD("get_path_max_distance"), &NavigationAgent3D::get_path_max_distance); - ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent::set_target_location); - ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent::get_target_location); - ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent::get_next_location); - ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent::distance_to_target); - ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent::set_velocity); - ClassDB::bind_method(D_METHOD("get_nav_path"), &NavigationAgent::get_nav_path); - ClassDB::bind_method(D_METHOD("get_nav_path_index"), &NavigationAgent::get_nav_path_index); - ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent::is_target_reached); - ClassDB::bind_method(D_METHOD("is_target_reachable"), &NavigationAgent::is_target_reachable); - ClassDB::bind_method(D_METHOD("is_navigation_finished"), &NavigationAgent::is_navigation_finished); - ClassDB::bind_method(D_METHOD("get_final_location"), &NavigationAgent::get_final_location); + ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent3D::set_target_location); + ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent3D::get_target_location); + ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent3D::get_next_location); + ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent3D::distance_to_target); + ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent3D::set_velocity); + ClassDB::bind_method(D_METHOD("get_nav_path"), &NavigationAgent3D::get_nav_path); + ClassDB::bind_method(D_METHOD("get_nav_path_index"), &NavigationAgent3D::get_nav_path_index); + ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent3D::is_target_reached); + ClassDB::bind_method(D_METHOD("is_target_reachable"), &NavigationAgent3D::is_target_reachable); + ClassDB::bind_method(D_METHOD("is_navigation_finished"), &NavigationAgent3D::is_navigation_finished); + ClassDB::bind_method(D_METHOD("get_final_location"), &NavigationAgent3D::get_final_location); - ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent::_avoidance_done); + ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent3D::_avoidance_done); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01"), "set_target_desired_distance", "get_target_desired_distance"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.1,100,0.01"), "set_radius", "get_radius"); @@ -96,22 +96,22 @@ void NavigationAgent::_bind_methods() { ADD_SIGNAL(MethodInfo("velocity_computed", PropertyInfo(Variant::VECTOR3, "safe_velocity"))); } -void NavigationAgent::_notification(int p_what) { +void NavigationAgent3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { - agent_parent = Object::cast_to<Spatial>(get_parent()); + agent_parent = Object::cast_to<Node3D>(get_parent()); - NavigationServer::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); + NavigationServer3D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done"); // Search the navigation node and set it { - Navigation *nav = NULL; + Navigation3D *nav = nullptr; Node *p = get_parent(); - while (p != NULL) { - nav = Object::cast_to<Navigation>(p); - if (nav != NULL) - p = NULL; + while (p != nullptr) { + nav = Object::cast_to<Navigation3D>(p); + if (nav != nullptr) + p = nullptr; else p = p->get_parent(); } @@ -122,14 +122,14 @@ void NavigationAgent::_notification(int p_what) { set_physics_process_internal(true); } break; case NOTIFICATION_EXIT_TREE: { - agent_parent = NULL; - set_navigation(NULL); + agent_parent = nullptr; + set_navigation(nullptr); set_physics_process_internal(false); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (agent_parent) { - NavigationServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin); + NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin); if (!target_reached) { if (distance_to_target() < target_desired_distance) { emit_signal("target_reached"); @@ -141,9 +141,9 @@ void NavigationAgent::_notification(int p_what) { } } -NavigationAgent::NavigationAgent() : - agent_parent(NULL), - navigation(NULL), +NavigationAgent3D::NavigationAgent3D() : + agent_parent(nullptr), + navigation(nullptr), agent(RID()), target_desired_distance(1.0), navigation_height_offset(0.0), @@ -151,7 +151,7 @@ NavigationAgent::NavigationAgent() : velocity_submitted(false), target_reached(false), navigation_finished(true) { - agent = NavigationServer::get_singleton()->agent_create(); + agent = NavigationServer3D::get_singleton()->agent_create(); set_neighbor_dist(50.0); set_max_neighbors(10); set_time_horizon(5.0); @@ -160,115 +160,116 @@ NavigationAgent::NavigationAgent() : set_ignore_y(true); } -NavigationAgent::~NavigationAgent() { - NavigationServer::get_singleton()->free(agent); +NavigationAgent3D::~NavigationAgent3D() { + NavigationServer3D::get_singleton()->free(agent); agent = RID(); // Pointless } -void NavigationAgent::set_navigation(Navigation *p_nav) { +void NavigationAgent3D::set_navigation(Navigation3D *p_nav) { if (navigation == p_nav) return; // Pointless navigation = p_nav; - NavigationServer::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid()); + NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); } -void NavigationAgent::set_navigation_node(Node *p_nav) { - Navigation *nav = Object::cast_to<Navigation>(p_nav); - ERR_FAIL_COND(nav == NULL); +void NavigationAgent3D::set_navigation_node(Node *p_nav) { + Navigation3D *nav = Object::cast_to<Navigation3D>(p_nav); + ERR_FAIL_COND(nav == nullptr); set_navigation(nav); } -Node *NavigationAgent::get_navigation_node() const { +Node *NavigationAgent3D::get_navigation_node() const { return Object::cast_to<Node>(navigation); } -void NavigationAgent::set_target_desired_distance(real_t p_dd) { +void NavigationAgent3D::set_target_desired_distance(real_t p_dd) { target_desired_distance = p_dd; } -void NavigationAgent::set_radius(real_t p_radius) { +void NavigationAgent3D::set_radius(real_t p_radius) { radius = p_radius; - NavigationServer::get_singleton()->agent_set_radius(agent, radius); + NavigationServer3D::get_singleton()->agent_set_radius(agent, radius); } -void NavigationAgent::set_agent_height_offset(real_t p_hh) { +void NavigationAgent3D::set_agent_height_offset(real_t p_hh) { navigation_height_offset = p_hh; } -void NavigationAgent::set_ignore_y(bool p_ignore_y) { +void NavigationAgent3D::set_ignore_y(bool p_ignore_y) { ignore_y = p_ignore_y; - NavigationServer::get_singleton()->agent_set_ignore_y(agent, ignore_y); + NavigationServer3D::get_singleton()->agent_set_ignore_y(agent, ignore_y); } -void NavigationAgent::set_neighbor_dist(real_t p_dist) { +void NavigationAgent3D::set_neighbor_dist(real_t p_dist) { neighbor_dist = p_dist; - NavigationServer::get_singleton()->agent_set_neighbor_dist(agent, neighbor_dist); + NavigationServer3D::get_singleton()->agent_set_neighbor_dist(agent, neighbor_dist); } -void NavigationAgent::set_max_neighbors(int p_count) { +void NavigationAgent3D::set_max_neighbors(int p_count) { max_neighbors = p_count; - NavigationServer::get_singleton()->agent_set_max_neighbors(agent, max_neighbors); + NavigationServer3D::get_singleton()->agent_set_max_neighbors(agent, max_neighbors); } -void NavigationAgent::set_time_horizon(real_t p_time) { +void NavigationAgent3D::set_time_horizon(real_t p_time) { time_horizon = p_time; - NavigationServer::get_singleton()->agent_set_time_horizon(agent, time_horizon); + NavigationServer3D::get_singleton()->agent_set_time_horizon(agent, time_horizon); } -void NavigationAgent::set_max_speed(real_t p_max_speed) { +void NavigationAgent3D::set_max_speed(real_t p_max_speed) { max_speed = p_max_speed; - NavigationServer::get_singleton()->agent_set_max_speed(agent, max_speed); + NavigationServer3D::get_singleton()->agent_set_max_speed(agent, max_speed); } -void NavigationAgent::set_path_max_distance(real_t p_pmd) { +void NavigationAgent3D::set_path_max_distance(real_t p_pmd) { path_max_distance = p_pmd; } -real_t NavigationAgent::get_path_max_distance() { +real_t NavigationAgent3D::get_path_max_distance() { return path_max_distance; } -void NavigationAgent::set_target_location(Vector3 p_location) { +void NavigationAgent3D::set_target_location(Vector3 p_location) { target_location = p_location; navigation_path.clear(); target_reached = false; navigation_finished = false; + update_frame_id = 0; } -Vector3 NavigationAgent::get_target_location() const { +Vector3 NavigationAgent3D::get_target_location() const { return target_location; } -Vector3 NavigationAgent::get_next_location() { +Vector3 NavigationAgent3D::get_next_location() { update_navigation(); if (navigation_path.size() == 0) { - ERR_FAIL_COND_V(agent_parent == NULL, Vector3()); + ERR_FAIL_COND_V(agent_parent == nullptr, Vector3()); return agent_parent->get_global_transform().origin; } else { return navigation_path[nav_path_index] - Vector3(0, navigation_height_offset, 0); } } -real_t NavigationAgent::distance_to_target() const { - ERR_FAIL_COND_V(agent_parent == NULL, 0.0); +real_t NavigationAgent3D::distance_to_target() const { + ERR_FAIL_COND_V(agent_parent == nullptr, 0.0); return agent_parent->get_global_transform().origin.distance_to(target_location); } -bool NavigationAgent::is_target_reached() const { +bool NavigationAgent3D::is_target_reached() const { return target_reached; } -bool NavigationAgent::is_target_reachable() { +bool NavigationAgent3D::is_target_reachable() { return target_desired_distance >= get_final_location().distance_to(target_location); } -bool NavigationAgent::is_navigation_finished() { +bool NavigationAgent3D::is_navigation_finished() { update_navigation(); return navigation_finished; } -Vector3 NavigationAgent::get_final_location() { +Vector3 NavigationAgent3D::get_final_location() { update_navigation(); if (navigation_path.size() == 0) { return Vector3(); @@ -276,14 +277,14 @@ Vector3 NavigationAgent::get_final_location() { return navigation_path[navigation_path.size() - 1]; } -void NavigationAgent::set_velocity(Vector3 p_velocity) { +void NavigationAgent3D::set_velocity(Vector3 p_velocity) { target_velocity = p_velocity; - NavigationServer::get_singleton()->agent_set_target_velocity(agent, target_velocity); - NavigationServer::get_singleton()->agent_set_velocity(agent, prev_safe_velocity); + NavigationServer3D::get_singleton()->agent_set_target_velocity(agent, target_velocity); + NavigationServer3D::get_singleton()->agent_set_velocity(agent, prev_safe_velocity); velocity_submitted = true; } -void NavigationAgent::_avoidance_done(Vector3 p_new_velocity) { +void NavigationAgent3D::_avoidance_done(Vector3 p_new_velocity) { prev_safe_velocity = p_new_velocity; if (!velocity_submitted) { @@ -295,18 +296,18 @@ void NavigationAgent::_avoidance_done(Vector3 p_new_velocity) { emit_signal("velocity_computed", p_new_velocity); } -String NavigationAgent::get_configuration_warning() const { - if (!Object::cast_to<Spatial>(get_parent())) { - return TTR("The NavigationAgent can be used only under a spatial node."); +String NavigationAgent3D::get_configuration_warning() const { + if (!Object::cast_to<Node3D>(get_parent())) { + return TTR("The NavigationAgent3D can be used only under a spatial node."); } return String(); } -void NavigationAgent::update_navigation() { +void NavigationAgent3D::update_navigation() { - if (agent_parent == NULL) return; - if (navigation == NULL) return; + if (agent_parent == nullptr) return; + if (navigation == nullptr) return; if (update_frame_id == Engine::get_singleton()->get_physics_frames()) return; update_frame_id = Engine::get_singleton()->get_physics_frames(); @@ -315,7 +316,7 @@ void NavigationAgent::update_navigation() { bool reload_path = false; - if (NavigationServer::get_singleton()->agent_is_map_changed(agent)) { + if (NavigationServer3D::get_singleton()->agent_is_map_changed(agent)) { reload_path = true; } else if (navigation_path.size() == 0) { reload_path = true; @@ -336,7 +337,7 @@ void NavigationAgent::update_navigation() { } if (reload_path) { - navigation_path = NavigationServer::get_singleton()->map_get_path(navigation->get_rid(), o, target_location, true); + navigation_path = NavigationServer3D::get_singleton()->map_get_path(navigation->get_rid(), o, target_location, true); navigation_finished = false; nav_path_index = 0; emit_signal("path_changed"); diff --git a/scene/3d/navigation_agent.h b/scene/3d/navigation_agent_3d.h index 200d5db475..3558b4e51b 100644 --- a/scene/3d/navigation_agent.h +++ b/scene/3d/navigation_agent_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_agent.h */ +/* navigation_agent_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -34,14 +34,14 @@ #include "core/vector.h" #include "scene/main/node.h" -class Spatial; -class Navigation; +class Node3D; +class Navigation3D; -class NavigationAgent : public Node { - GDCLASS(NavigationAgent, Node); +class NavigationAgent3D : public Node { + GDCLASS(NavigationAgent3D, Node); - Spatial *agent_parent; - Navigation *navigation; + Node3D *agent_parent; + Navigation3D *navigation; RID agent; @@ -73,11 +73,11 @@ protected: void _notification(int p_what); public: - NavigationAgent(); - virtual ~NavigationAgent(); + NavigationAgent3D(); + virtual ~NavigationAgent3D(); - void set_navigation(Navigation *p_nav); - const Navigation *get_navigation() const { + void set_navigation(Navigation3D *p_nav); + const Navigation3D *get_navigation() const { return navigation; } diff --git a/scene/3d/navigation_obstacle.cpp b/scene/3d/navigation_obstacle_3d.cpp index befc41eee5..2ee2008799 100644 --- a/scene/3d/navigation_obstacle.cpp +++ b/scene/3d/navigation_obstacle_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_obstacle.cpp */ +/* navigation_obstacle_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,20 +28,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_obstacle.h" +#include "navigation_obstacle_3d.h" -#include "scene/3d/collision_shape.h" -#include "scene/3d/navigation.h" -#include "scene/3d/physics_body.h" -#include "servers/navigation_server.h" +#include "scene/3d/collision_shape_3d.h" +#include "scene/3d/navigation_3d.h" +#include "scene/3d/physics_body_3d.h" +#include "servers/navigation_server_3d.h" -void NavigationObstacle::_bind_methods() { +void NavigationObstacle3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle::set_navigation_node); - ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle::get_navigation_node); + ClassDB::bind_method(D_METHOD("set_navigation", "navigation"), &NavigationObstacle3D::set_navigation_node); + ClassDB::bind_method(D_METHOD("get_navigation"), &NavigationObstacle3D::get_navigation_node); } -void NavigationObstacle::_notification(int p_what) { +void NavigationObstacle3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { @@ -49,12 +49,12 @@ void NavigationObstacle::_notification(int p_what) { // Search the navigation node and set it { - Navigation *nav = NULL; + Navigation3D *nav = nullptr; Node *p = get_parent(); - while (p != NULL) { - nav = Object::cast_to<Navigation>(p); - if (nav != NULL) - p = NULL; + while (p != nullptr) { + nav = Object::cast_to<Navigation3D>(p); + if (nav != nullptr) + p = nullptr; else p = p->get_parent(); } @@ -65,73 +65,73 @@ void NavigationObstacle::_notification(int p_what) { set_physics_process_internal(true); } break; case NOTIFICATION_EXIT_TREE: { - set_navigation(NULL); + set_navigation(nullptr); set_physics_process_internal(false); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - Spatial *spatial = Object::cast_to<Spatial>(get_parent()); + Node3D *spatial = Object::cast_to<Node3D>(get_parent()); if (spatial) { - NavigationServer::get_singleton()->agent_set_position(agent, spatial->get_global_transform().origin); + NavigationServer3D::get_singleton()->agent_set_position(agent, spatial->get_global_transform().origin); } - PhysicsBody *rigid = Object::cast_to<PhysicsBody>(get_parent()); + PhysicsBody3D *rigid = Object::cast_to<PhysicsBody3D>(get_parent()); if (rigid) { Vector3 v = rigid->get_linear_velocity(); - NavigationServer::get_singleton()->agent_set_velocity(agent, v); - NavigationServer::get_singleton()->agent_set_target_velocity(agent, v); + NavigationServer3D::get_singleton()->agent_set_velocity(agent, v); + NavigationServer3D::get_singleton()->agent_set_target_velocity(agent, v); } } break; } } -NavigationObstacle::NavigationObstacle() : - navigation(NULL), +NavigationObstacle3D::NavigationObstacle3D() : + navigation(nullptr), agent(RID()) { - agent = NavigationServer::get_singleton()->agent_create(); + agent = NavigationServer3D::get_singleton()->agent_create(); } -NavigationObstacle::~NavigationObstacle() { - NavigationServer::get_singleton()->free(agent); +NavigationObstacle3D::~NavigationObstacle3D() { + NavigationServer3D::get_singleton()->free(agent); agent = RID(); // Pointless } -void NavigationObstacle::set_navigation(Navigation *p_nav) { +void NavigationObstacle3D::set_navigation(Navigation3D *p_nav) { if (navigation == p_nav) return; // Pointless navigation = p_nav; - NavigationServer::get_singleton()->agent_set_map(agent, navigation == NULL ? RID() : navigation->get_rid()); + NavigationServer3D::get_singleton()->agent_set_map(agent, navigation == nullptr ? RID() : navigation->get_rid()); } -void NavigationObstacle::set_navigation_node(Node *p_nav) { - Navigation *nav = Object::cast_to<Navigation>(p_nav); - ERR_FAIL_COND(nav == NULL); +void NavigationObstacle3D::set_navigation_node(Node *p_nav) { + Navigation3D *nav = Object::cast_to<Navigation3D>(p_nav); + ERR_FAIL_COND(nav == nullptr); set_navigation(nav); } -Node *NavigationObstacle::get_navigation_node() const { +Node *NavigationObstacle3D::get_navigation_node() const { return Object::cast_to<Node>(navigation); } -String NavigationObstacle::get_configuration_warning() const { - if (!Object::cast_to<Spatial>(get_parent())) { +String NavigationObstacle3D::get_configuration_warning() const { + if (!Object::cast_to<Node3D>(get_parent())) { - return TTR("The NavigationObstacle only serves to provide collision avoidance to a spatial object."); + return TTR("The NavigationObstacle3D only serves to provide collision avoidance to a spatial object."); } return String(); } -void NavigationObstacle::update_agent_shape() { +void NavigationObstacle3D::update_agent_shape() { Node *node = get_parent(); // Estimate the radius of this physics body real_t radius = 0.0; for (int i(0); i < node->get_child_count(); i++) { // For each collision shape - CollisionShape *cs = Object::cast_to<CollisionShape>(node->get_child(i)); + CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(node->get_child(i)); if (cs) { // Take the distance between the Body center to the shape center real_t r = cs->get_transform().origin.length(); @@ -145,7 +145,7 @@ void NavigationObstacle::update_agent_shape() { radius = MAX(radius, r); } } - Spatial *spa = Object::cast_to<Spatial>(node); + Node3D *spa = Object::cast_to<Node3D>(node); if (spa) { Vector3 s = spa->get_global_transform().basis.get_scale(); radius *= MAX(s.x, MAX(s.y, s.z)); @@ -155,9 +155,9 @@ void NavigationObstacle::update_agent_shape() { radius = 1.0; // Never a 0 radius // Initialize the Agent as an object - NavigationServer::get_singleton()->agent_set_neighbor_dist(agent, 0.0); - NavigationServer::get_singleton()->agent_set_max_neighbors(agent, 0); - NavigationServer::get_singleton()->agent_set_time_horizon(agent, 0.0); - NavigationServer::get_singleton()->agent_set_radius(agent, radius); - NavigationServer::get_singleton()->agent_set_max_speed(agent, 0.0); + NavigationServer3D::get_singleton()->agent_set_neighbor_dist(agent, 0.0); + NavigationServer3D::get_singleton()->agent_set_max_neighbors(agent, 0); + NavigationServer3D::get_singleton()->agent_set_time_horizon(agent, 0.0); + NavigationServer3D::get_singleton()->agent_set_radius(agent, radius); + NavigationServer3D::get_singleton()->agent_set_max_speed(agent, 0.0); } diff --git a/scene/3d/navigation_obstacle.h b/scene/3d/navigation_obstacle_3d.h index 7257a43150..b58d7c4991 100644 --- a/scene/3d/navigation_obstacle.h +++ b/scene/3d/navigation_obstacle_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_obstacle.h */ +/* navigation_obstacle_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,12 +33,12 @@ #include "scene/main/node.h" -class Navigation; +class Navigation3D; -class NavigationObstacle : public Node { - GDCLASS(NavigationObstacle, Node); +class NavigationObstacle3D : public Node { + GDCLASS(NavigationObstacle3D, Node); - Navigation *navigation; + Navigation3D *navigation; RID agent; @@ -47,11 +47,11 @@ protected: void _notification(int p_what); public: - NavigationObstacle(); - virtual ~NavigationObstacle(); + NavigationObstacle3D(); + virtual ~NavigationObstacle3D(); - void set_navigation(Navigation *p_nav); - const Navigation *get_navigation() const { + void set_navigation(Navigation3D *p_nav); + const Navigation3D *get_navigation() const { return navigation; } diff --git a/scene/3d/navigation_region.cpp b/scene/3d/navigation_region_3d.cpp index 53b707a29a..043b816033 100644 --- a/scene/3d/navigation_region.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_region.cpp */ +/* navigation_region_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,13 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "navigation_region.h" +#include "navigation_region_3d.h" + #include "core/os/thread.h" -#include "mesh_instance.h" -#include "navigation.h" -#include "servers/navigation_server.h" +#include "mesh_instance_3d.h" +#include "navigation_3d.h" +#include "servers/navigation_server_3d.h" -void NavigationRegion::set_enabled(bool p_enabled) { +void NavigationRegion3D::set_enabled(bool p_enabled) { if (enabled == p_enabled) return; @@ -45,17 +46,17 @@ void NavigationRegion::set_enabled(bool p_enabled) { if (!enabled) { - NavigationServer::get_singleton()->region_set_map(region, RID()); + NavigationServer3D::get_singleton()->region_set_map(region, RID()); } else { if (navigation) { - NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer3D::get_singleton()->region_set_map(region, navigation->get_rid()); } } if (debug_view) { - MeshInstance *dm = Object::cast_to<MeshInstance>(debug_view); + MeshInstance3D *dm = Object::cast_to<MeshInstance3D>(debug_view); if (is_enabled()) { dm->set_material_override(get_tree()->get_debug_navigation_material()); } else { @@ -66,27 +67,27 @@ void NavigationRegion::set_enabled(bool p_enabled) { update_gizmo(); } -bool NavigationRegion::is_enabled() const { +bool NavigationRegion3D::is_enabled() const { return enabled; } ///////////////////////////// -void NavigationRegion::_notification(int p_what) { +void NavigationRegion3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - Spatial *c = this; + Node3D *c = this; while (c) { - navigation = Object::cast_to<Navigation>(c); + navigation = Object::cast_to<Navigation3D>(c); if (navigation) { if (enabled) { - NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); + NavigationServer3D::get_singleton()->region_set_map(region, navigation->get_rid()); } break; } @@ -96,7 +97,7 @@ void NavigationRegion::_notification(int p_what) { if (navmesh.is_valid() && get_tree()->is_debugging_navigation_hint()) { - MeshInstance *dm = memnew(MeshInstance); + MeshInstance3D *dm = memnew(MeshInstance3D); dm->set_mesh(navmesh->get_debug_mesh()); if (is_enabled()) { dm->set_material_override(get_tree()->get_debug_navigation_material()); @@ -110,26 +111,26 @@ void NavigationRegion::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - NavigationServer::get_singleton()->region_set_transform(region, get_global_transform()); + NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform()); } break; case NOTIFICATION_EXIT_TREE: { if (navigation) { - NavigationServer::get_singleton()->region_set_map(region, RID()); + NavigationServer3D::get_singleton()->region_set_map(region, RID()); } if (debug_view) { debug_view->queue_delete(); - debug_view = NULL; + debug_view = nullptr; } - navigation = NULL; + navigation = nullptr; } break; } } -void NavigationRegion::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) { +void NavigationRegion3D::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) { if (p_navmesh == navmesh) return; @@ -144,10 +145,10 @@ void NavigationRegion::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) navmesh->add_change_receptor(this); } - NavigationServer::get_singleton()->region_set_navmesh(region, p_navmesh); + NavigationServer3D::get_singleton()->region_set_navmesh(region, p_navmesh); if (debug_view && navmesh.is_valid()) { - Object::cast_to<MeshInstance>(debug_view)->set_mesh(navmesh->get_debug_mesh()); + Object::cast_to<MeshInstance3D>(debug_view)->set_mesh(navmesh->get_debug_mesh()); } emit_signal("navigation_mesh_changed"); @@ -156,13 +157,13 @@ void NavigationRegion::set_navigation_mesh(const Ref<NavigationMesh> &p_navmesh) update_configuration_warning(); } -Ref<NavigationMesh> NavigationRegion::get_navigation_mesh() const { +Ref<NavigationMesh> NavigationRegion3D::get_navigation_mesh() const { return navmesh; } struct BakeThreadsArgs { - NavigationRegion *nav_region; + NavigationRegion3D *nav_region; }; void _bake_navigation_mesh(void *p_user_data) { @@ -171,7 +172,7 @@ void _bake_navigation_mesh(void *p_user_data) { if (args->nav_region->get_navigation_mesh().is_valid()) { Ref<NavigationMesh> nav_mesh = args->nav_region->get_navigation_mesh()->duplicate(); - NavigationServer::get_singleton()->region_bake_navmesh(nav_mesh, args->nav_region); + NavigationServer3D::get_singleton()->region_bake_navmesh(nav_mesh, args->nav_region); args->nav_region->call_deferred("_bake_finished", nav_mesh); memdelete(args); } else { @@ -182,22 +183,22 @@ void _bake_navigation_mesh(void *p_user_data) { } } -void NavigationRegion::bake_navigation_mesh() { - ERR_FAIL_COND(bake_thread != NULL); +void NavigationRegion3D::bake_navigation_mesh() { + ERR_FAIL_COND(bake_thread != nullptr); BakeThreadsArgs *args = memnew(BakeThreadsArgs); args->nav_region = this; bake_thread = Thread::create(_bake_navigation_mesh, args); - ERR_FAIL_COND(bake_thread == NULL); + ERR_FAIL_COND(bake_thread == nullptr); } -void NavigationRegion::_bake_finished(Ref<NavigationMesh> p_nav_mesh) { +void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_nav_mesh) { set_navigation_mesh(p_nav_mesh); - bake_thread = NULL; + bake_thread = nullptr; } -String NavigationRegion::get_configuration_warning() const { +String NavigationRegion3D::get_configuration_warning() const { if (!is_visible_in_tree() || !is_inside_tree()) return String(); @@ -205,28 +206,28 @@ String NavigationRegion::get_configuration_warning() const { if (!navmesh.is_valid()) { return TTR("A NavigationMesh resource must be set or created for this node to work."); } - const Spatial *c = this; + const Node3D *c = this; while (c) { - if (Object::cast_to<Navigation>(c)) + if (Object::cast_to<Navigation3D>(c)) return String(); - c = Object::cast_to<Spatial>(c->get_parent()); + c = Object::cast_to<Node3D>(c->get_parent()); } - return TTR("NavigationRegion must be a child or grandchild to a Navigation node. It only provides navigation data."); + return TTR("NavigationRegion3D must be a child or grandchild to a Navigation3D node. It only provides navigation data."); } -void NavigationRegion::_bind_methods() { +void NavigationRegion3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation_mesh", "navmesh"), &NavigationRegion::set_navigation_mesh); - ClassDB::bind_method(D_METHOD("get_navigation_mesh"), &NavigationRegion::get_navigation_mesh); + ClassDB::bind_method(D_METHOD("set_navigation_mesh", "navmesh"), &NavigationRegion3D::set_navigation_mesh); + ClassDB::bind_method(D_METHOD("get_navigation_mesh"), &NavigationRegion3D::get_navigation_mesh); - ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion::set_enabled); - ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion::is_enabled); + ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion3D::set_enabled); + ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion3D::is_enabled); - ClassDB::bind_method(D_METHOD("bake_navigation_mesh"), &NavigationRegion::bake_navigation_mesh); - ClassDB::bind_method(D_METHOD("_bake_finished", "nav_mesh"), &NavigationRegion::_bake_finished); + ClassDB::bind_method(D_METHOD("bake_navigation_mesh"), &NavigationRegion3D::bake_navigation_mesh); + ClassDB::bind_method(D_METHOD("_bake_finished", "nav_mesh"), &NavigationRegion3D::_bake_finished); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navmesh", PROPERTY_HINT_RESOURCE_TYPE, "NavigationMesh"), "set_navigation_mesh", "get_navigation_mesh"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); @@ -235,24 +236,24 @@ void NavigationRegion::_bind_methods() { ADD_SIGNAL(MethodInfo("bake_finished")); } -void NavigationRegion::_changed_callback(Object *p_changed, const char *p_prop) { +void NavigationRegion3D::_changed_callback(Object *p_changed, const char *p_prop) { update_gizmo(); update_configuration_warning(); } -NavigationRegion::NavigationRegion() { +NavigationRegion3D::NavigationRegion3D() { enabled = true; set_notify_transform(true); - region = NavigationServer::get_singleton()->region_create(); + region = NavigationServer3D::get_singleton()->region_create(); - navigation = NULL; - debug_view = NULL; - bake_thread = NULL; + navigation = nullptr; + debug_view = nullptr; + bake_thread = nullptr; } -NavigationRegion::~NavigationRegion() { +NavigationRegion3D::~NavigationRegion3D() { if (navmesh.is_valid()) navmesh->remove_change_receptor(this); - NavigationServer::get_singleton()->free(region); + NavigationServer3D::get_singleton()->free(region); } diff --git a/scene/3d/navigation_region.h b/scene/3d/navigation_region_3d.h index f215e92c97..ae071e6b7a 100644 --- a/scene/3d/navigation_region.h +++ b/scene/3d/navigation_region_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* navigation_region.h */ +/* navigation_region_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,21 +31,21 @@ #ifndef NAVIGATION_REGION_H #define NAVIGATION_REGION_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/mesh.h" #include "scene/resources/navigation_mesh.h" -class Navigation; +class Navigation3D; -class NavigationRegion : public Spatial { +class NavigationRegion3D : public Node3D { - GDCLASS(NavigationRegion, Spatial); + GDCLASS(NavigationRegion3D, Node3D); bool enabled; RID region; Ref<NavigationMesh> navmesh; - Navigation *navigation; + Navigation3D *navigation; Node *debug_view; Thread *bake_thread; @@ -68,8 +68,8 @@ public: String get_configuration_warning() const; - NavigationRegion(); - ~NavigationRegion(); + NavigationRegion3D(); + ~NavigationRegion3D(); }; #endif // NAVIGATION_REGION_H diff --git a/scene/3d/spatial.cpp b/scene/3d/node_3d.cpp index f1911348ce..0b7407e049 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/node_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial.cpp */ +/* node_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "spatial.h" +#include "node_3d.h" #include "core/engine.h" #include "core/message_queue.h" #include "scene/main/scene_tree.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" #include "scene/scene_string_names.h" /* @@ -70,10 +70,10 @@ future: no idea */ -SpatialGizmo::SpatialGizmo() { +Node3DGizmo::Node3DGizmo() { } -void Spatial::_notify_dirty() { +void Node3D::_notify_dirty() { #ifdef TOOLS_ENABLED if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) { @@ -85,12 +85,12 @@ void Spatial::_notify_dirty() { } } -void Spatial::_update_local_transform() const { +void Node3D::_update_local_transform() const { data.local_transform.basis.set_euler_scale(data.rotation, data.scale); data.dirty &= ~DIRTY_LOCAL; } -void Spatial::_propagate_transform_changed(Spatial *p_origin) { +void Node3D::_propagate_transform_changed(Node3D *p_origin) { if (!is_inside_tree()) { return; @@ -103,7 +103,7 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) { data.children_lock++; - for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) { + for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) { if (E->get()->data.toplevel_active) continue; //don't propagate to a toplevel @@ -121,7 +121,7 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) { data.children_lock--; } -void Spatial::_notification(int p_what) { +void Node3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -129,12 +129,12 @@ void Spatial::_notification(int p_what) { Node *p = get_parent(); if (p) - data.parent = Object::cast_to<Spatial>(p); + data.parent = Object::cast_to<Node3D>(p); if (data.parent) data.C = data.parent->data.children.push_back(this); else - data.C = NULL; + data.C = nullptr; if (data.toplevel && !Engine::get_singleton()->is_editor_hint()) { @@ -158,14 +158,14 @@ void Spatial::_notification(int p_what) { get_tree()->xform_change_list.remove(&xform_change); if (data.C) data.parent->data.children.erase(data.C); - data.parent = NULL; - data.C = NULL; + data.parent = nullptr; + data.C = nullptr; data.toplevel_active = false; } break; case NOTIFICATION_ENTER_WORLD: { data.inside_world = true; - data.viewport = NULL; + data.viewport = nullptr; Node *parent = get_parent(); while (parent && !data.viewport) { data.viewport = Object::cast_to<Viewport>(parent); @@ -176,7 +176,7 @@ void Spatial::_notification(int p_what) { if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, NULL, 0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, nullptr, 0); } #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) { @@ -208,10 +208,10 @@ void Spatial::_notification(int p_what) { if (get_script_instance()) { - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, NULL, 0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, nullptr, 0); } - data.viewport = NULL; + data.viewport = nullptr; data.inside_world = false; } break; @@ -230,7 +230,7 @@ void Spatial::_notification(int p_what) { } } -void Spatial::set_transform(const Transform &p_transform) { +void Node3D::set_transform(const Transform &p_transform) { data.local_transform = p_transform; data.dirty |= DIRTY_VECTORS; @@ -244,7 +244,7 @@ void Spatial::set_transform(const Transform &p_transform) { } } -void Spatial::set_global_transform(const Transform &p_transform) { +void Node3D::set_global_transform(const Transform &p_transform) { Transform xform = (data.parent && !data.toplevel_active) ? @@ -254,7 +254,7 @@ void Spatial::set_global_transform(const Transform &p_transform) { set_transform(xform); } -Transform Spatial::get_transform() const { +Transform Node3D::get_transform() const { if (data.dirty & DIRTY_LOCAL) { @@ -263,7 +263,7 @@ Transform Spatial::get_transform() const { return data.local_transform; } -Transform Spatial::get_global_transform() const { +Transform Node3D::get_global_transform() const { ERR_FAIL_COND_V(!is_inside_tree(), Transform()); @@ -293,21 +293,21 @@ Transform Spatial::get_global_transform() const { } #ifdef TOOLS_ENABLED -Transform Spatial::get_global_gizmo_transform() const { +Transform Node3D::get_global_gizmo_transform() const { return get_global_transform(); } -Transform Spatial::get_local_gizmo_transform() const { +Transform Node3D::get_local_gizmo_transform() const { return get_transform(); } #endif -Spatial *Spatial::get_parent_spatial() const { +Node3D *Node3D::get_parent_spatial() const { return data.parent; } -Transform Spatial::get_relative_transform(const Node *p_parent) const { +Transform Node3D::get_relative_transform(const Node *p_parent) const { if (p_parent == this) return Transform(); @@ -320,7 +320,7 @@ Transform Spatial::get_relative_transform(const Node *p_parent) const { return data.parent->get_relative_transform(p_parent) * get_transform(); } -void Spatial::set_translation(const Vector3 &p_translation) { +void Node3D::set_translation(const Vector3 &p_translation) { data.local_transform.origin = p_translation; _change_notify("transform"); @@ -330,7 +330,7 @@ void Spatial::set_translation(const Vector3 &p_translation) { } } -void Spatial::set_rotation(const Vector3 &p_euler_rad) { +void Node3D::set_rotation(const Vector3 &p_euler_rad) { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -346,12 +346,12 @@ void Spatial::set_rotation(const Vector3 &p_euler_rad) { } } -void Spatial::set_rotation_degrees(const Vector3 &p_euler_deg) { +void Node3D::set_rotation_degrees(const Vector3 &p_euler_deg) { set_rotation(p_euler_deg * Math_PI / 180.0); } -void Spatial::set_scale(const Vector3 &p_scale) { +void Node3D::set_scale(const Vector3 &p_scale) { if (data.dirty & DIRTY_VECTORS) { data.rotation = data.local_transform.basis.get_rotation(); @@ -367,12 +367,12 @@ void Spatial::set_scale(const Vector3 &p_scale) { } } -Vector3 Spatial::get_translation() const { +Vector3 Node3D::get_translation() const { return data.local_transform.origin; } -Vector3 Spatial::get_rotation() const { +Vector3 Node3D::get_rotation() const { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -384,12 +384,12 @@ Vector3 Spatial::get_rotation() const { return data.rotation; } -Vector3 Spatial::get_rotation_degrees() const { +Vector3 Node3D::get_rotation_degrees() const { return get_rotation() * 180.0 / Math_PI; } -Vector3 Spatial::get_scale() const { +Vector3 Node3D::get_scale() const { if (data.dirty & DIRTY_VECTORS) { data.scale = data.local_transform.basis.get_scale(); @@ -401,7 +401,7 @@ Vector3 Spatial::get_scale() const { return data.scale; } -void Spatial::update_gizmo() { +void Node3D::update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) @@ -417,7 +417,7 @@ void Spatial::update_gizmo() { #endif } -void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) { +void Node3D::set_gizmo(const Ref<Node3DGizmo> &p_gizmo) { #ifdef TOOLS_ENABLED @@ -438,18 +438,18 @@ void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) { #endif } -Ref<SpatialGizmo> Spatial::get_gizmo() const { +Ref<Node3DGizmo> Node3D::get_gizmo() const { #ifdef TOOLS_ENABLED return data.gizmo; #else - return Ref<SpatialGizmo>(); + return Ref<Node3DGizmo>(); #endif } -void Spatial::_update_gizmo() { +void Node3D::_update_gizmo() { #ifdef TOOLS_ENABLED if (!is_inside_world()) @@ -465,25 +465,25 @@ void Spatial::_update_gizmo() { } #ifdef TOOLS_ENABLED -void Spatial::set_disable_gizmo(bool p_enabled) { +void Node3D::set_disable_gizmo(bool p_enabled) { data.gizmo_disabled = p_enabled; if (!p_enabled && data.gizmo.is_valid()) - data.gizmo = Ref<SpatialGizmo>(); + data.gizmo = Ref<Node3DGizmo>(); } #endif -void Spatial::set_disable_scale(bool p_enabled) { +void Node3D::set_disable_scale(bool p_enabled) { data.disable_scale = p_enabled; } -bool Spatial::is_scale_disabled() const { +bool Node3D::is_scale_disabled() const { return data.disable_scale; } -void Spatial::set_as_toplevel(bool p_enabled) { +void Node3D::set_as_toplevel(bool p_enabled) { if (data.toplevel == p_enabled) return; @@ -502,20 +502,20 @@ void Spatial::set_as_toplevel(bool p_enabled) { } } -bool Spatial::is_set_as_toplevel() const { +bool Node3D::is_set_as_toplevel() const { return data.toplevel; } -Ref<World> Spatial::get_world() const { +Ref<World3D> Node3D::get_world() const { - ERR_FAIL_COND_V(!is_inside_world(), Ref<World>()); - ERR_FAIL_COND_V(!data.viewport, Ref<World>()); + ERR_FAIL_COND_V(!is_inside_world(), Ref<World3D>()); + ERR_FAIL_COND_V(!data.viewport, Ref<World3D>()); return data.viewport->find_world(); } -void Spatial::_propagate_visibility_changed() { +void Node3D::_propagate_visibility_changed() { notification(NOTIFICATION_VISIBILITY_CHANGED); emit_signal(SceneStringNames::get_singleton()->visibility_changed); @@ -525,16 +525,16 @@ void Spatial::_propagate_visibility_changed() { _update_gizmo(); #endif - for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) { + for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) { - Spatial *c = E->get(); + Node3D *c = E->get(); if (!c || !c->data.visible) continue; c->_propagate_visibility_changed(); } } -void Spatial::show() { +void Node3D::show() { if (data.visible) return; @@ -547,7 +547,7 @@ void Spatial::show() { _propagate_visibility_changed(); } -void Spatial::hide() { +void Node3D::hide() { if (!data.visible) return; @@ -560,9 +560,9 @@ void Spatial::hide() { _propagate_visibility_changed(); } -bool Spatial::is_visible_in_tree() const { +bool Node3D::is_visible_in_tree() const { - const Spatial *s = this; + const Node3D *s = this; while (s) { if (!s->data.visible) { @@ -574,7 +574,7 @@ bool Spatial::is_visible_in_tree() const { return true; } -void Spatial::set_visible(bool p_visible) { +void Node3D::set_visible(bool p_visible) { if (p_visible) show(); @@ -582,52 +582,52 @@ void Spatial::set_visible(bool p_visible) { hide(); } -bool Spatial::is_visible() const { +bool Node3D::is_visible() const { return data.visible; } -void Spatial::rotate_object_local(const Vector3 &p_axis, float p_angle) { +void Node3D::rotate_object_local(const Vector3 &p_axis, float p_angle) { Transform t = get_transform(); t.basis.rotate_local(p_axis, p_angle); set_transform(t); } -void Spatial::rotate(const Vector3 &p_axis, float p_angle) { +void Node3D::rotate(const Vector3 &p_axis, float p_angle) { Transform t = get_transform(); t.basis.rotate(p_axis, p_angle); set_transform(t); } -void Spatial::rotate_x(float p_angle) { +void Node3D::rotate_x(float p_angle) { Transform t = get_transform(); t.basis.rotate(Vector3(1, 0, 0), p_angle); set_transform(t); } -void Spatial::rotate_y(float p_angle) { +void Node3D::rotate_y(float p_angle) { Transform t = get_transform(); t.basis.rotate(Vector3(0, 1, 0), p_angle); set_transform(t); } -void Spatial::rotate_z(float p_angle) { +void Node3D::rotate_z(float p_angle) { Transform t = get_transform(); t.basis.rotate(Vector3(0, 0, 1), p_angle); set_transform(t); } -void Spatial::translate(const Vector3 &p_offset) { +void Node3D::translate(const Vector3 &p_offset) { Transform t = get_transform(); t.translate(p_offset); set_transform(t); } -void Spatial::translate_object_local(const Vector3 &p_offset) { +void Node3D::translate_object_local(const Vector3 &p_offset) { Transform t = get_transform(); Transform s; @@ -635,58 +635,58 @@ void Spatial::translate_object_local(const Vector3 &p_offset) { set_transform(t * s); } -void Spatial::scale(const Vector3 &p_ratio) { +void Node3D::scale(const Vector3 &p_ratio) { Transform t = get_transform(); t.basis.scale(p_ratio); set_transform(t); } -void Spatial::scale_object_local(const Vector3 &p_scale) { +void Node3D::scale_object_local(const Vector3 &p_scale) { Transform t = get_transform(); t.basis.scale_local(p_scale); set_transform(t); } -void Spatial::global_rotate(const Vector3 &p_axis, float p_angle) { +void Node3D::global_rotate(const Vector3 &p_axis, float p_angle) { Transform t = get_global_transform(); t.basis.rotate(p_axis, p_angle); set_global_transform(t); } -void Spatial::global_scale(const Vector3 &p_scale) { +void Node3D::global_scale(const Vector3 &p_scale) { Transform t = get_global_transform(); t.basis.scale(p_scale); set_global_transform(t); } -void Spatial::global_translate(const Vector3 &p_offset) { +void Node3D::global_translate(const Vector3 &p_offset) { Transform t = get_global_transform(); t.origin += p_offset; set_global_transform(t); } -void Spatial::orthonormalize() { +void Node3D::orthonormalize() { Transform t = get_transform(); t.orthonormalize(); set_transform(t); } -void Spatial::set_identity() { +void Node3D::set_identity() { set_transform(Transform()); } -void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) { +void Node3D::look_at(const Vector3 &p_target, const Vector3 &p_up) { Vector3 origin(get_global_transform().origin); look_at_from_position(origin, p_target, p_up); } -void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) { +void Node3D::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) { ERR_FAIL_COND_MSG(p_pos == p_target, "Node origin and target are in the same position, look_at() failed."); ERR_FAIL_COND_MSG(p_up.cross(p_target - p_pos) == Vector3(), "Up vector and direction between node origin and target are aligned, look_at() failed."); @@ -700,33 +700,33 @@ void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_targe set_scale(original_scale); } -Vector3 Spatial::to_local(Vector3 p_global) const { +Vector3 Node3D::to_local(Vector3 p_global) const { return get_global_transform().affine_inverse().xform(p_global); } -Vector3 Spatial::to_global(Vector3 p_local) const { +Vector3 Node3D::to_global(Vector3 p_local) const { return get_global_transform().xform(p_local); } -void Spatial::set_notify_transform(bool p_enable) { +void Node3D::set_notify_transform(bool p_enable) { data.notify_transform = p_enable; } -bool Spatial::is_transform_notification_enabled() const { +bool Node3D::is_transform_notification_enabled() const { return data.notify_transform; } -void Spatial::set_notify_local_transform(bool p_enable) { +void Node3D::set_notify_local_transform(bool p_enable) { data.notify_local_transform = p_enable; } -bool Spatial::is_local_transform_notification_enabled() const { +bool Node3D::is_local_transform_notification_enabled() const { return data.notify_local_transform; } -void Spatial::force_update_transform() { +void Node3D::force_update_transform() { ERR_FAIL_COND(!is_inside_tree()); if (!xform_change.in_list()) { return; //nothing to update @@ -736,67 +736,67 @@ void Spatial::force_update_transform() { notification(NOTIFICATION_TRANSFORM_CHANGED); } -void Spatial::_bind_methods() { - - ClassDB::bind_method(D_METHOD("set_transform", "local"), &Spatial::set_transform); - ClassDB::bind_method(D_METHOD("get_transform"), &Spatial::get_transform); - ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Spatial::set_translation); - ClassDB::bind_method(D_METHOD("get_translation"), &Spatial::get_translation); - ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Spatial::set_rotation); - ClassDB::bind_method(D_METHOD("get_rotation"), &Spatial::get_rotation); - ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Spatial::set_rotation_degrees); - ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Spatial::get_rotation_degrees); - ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Spatial::set_scale); - ClassDB::bind_method(D_METHOD("get_scale"), &Spatial::get_scale); - ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Spatial::set_global_transform); - ClassDB::bind_method(D_METHOD("get_global_transform"), &Spatial::get_global_transform); - ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Spatial::get_parent_spatial); - ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Spatial::set_ignore_transform_notification); - ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Spatial::set_as_toplevel); - ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Spatial::is_set_as_toplevel); - ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Spatial::set_disable_scale); - ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Spatial::is_scale_disabled); - ClassDB::bind_method(D_METHOD("get_world"), &Spatial::get_world); - - ClassDB::bind_method(D_METHOD("force_update_transform"), &Spatial::force_update_transform); - - ClassDB::bind_method(D_METHOD("_update_gizmo"), &Spatial::_update_gizmo); - - ClassDB::bind_method(D_METHOD("update_gizmo"), &Spatial::update_gizmo); - ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Spatial::set_gizmo); - ClassDB::bind_method(D_METHOD("get_gizmo"), &Spatial::get_gizmo); - - ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Spatial::set_visible); - ClassDB::bind_method(D_METHOD("is_visible"), &Spatial::is_visible); - ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Spatial::is_visible_in_tree); - ClassDB::bind_method(D_METHOD("show"), &Spatial::show); - ClassDB::bind_method(D_METHOD("hide"), &Spatial::hide); - - ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Spatial::set_notify_local_transform); - ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Spatial::is_local_transform_notification_enabled); - - ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform); - ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled); - - ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Spatial::rotate); - ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Spatial::global_rotate); - ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Spatial::global_scale); - ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Spatial::global_translate); - ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Spatial::rotate_object_local); - ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Spatial::scale_object_local); - ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Spatial::translate_object_local); - ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Spatial::rotate_x); - ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Spatial::rotate_y); - ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Spatial::rotate_z); - ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate); - ClassDB::bind_method(D_METHOD("orthonormalize"), &Spatial::orthonormalize); - ClassDB::bind_method(D_METHOD("set_identity"), &Spatial::set_identity); - - ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Spatial::look_at); - ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Spatial::look_at_from_position); - - ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Spatial::to_local); - ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Spatial::to_global); +void Node3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform); + ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform); + ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Node3D::set_translation); + ClassDB::bind_method(D_METHOD("get_translation"), &Node3D::get_translation); + ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Node3D::set_rotation); + ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation); + ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Node3D::set_rotation_degrees); + ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node3D::get_rotation_degrees); + ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale); + ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale); + ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Node3D::set_global_transform); + ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform); + ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Node3D::get_parent_spatial); + ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification); + ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Node3D::set_as_toplevel); + ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Node3D::is_set_as_toplevel); + ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale); + ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled); + ClassDB::bind_method(D_METHOD("get_world"), &Node3D::get_world); + + ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform); + + ClassDB::bind_method(D_METHOD("_update_gizmo"), &Node3D::_update_gizmo); + + ClassDB::bind_method(D_METHOD("update_gizmo"), &Node3D::update_gizmo); + ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Node3D::set_gizmo); + ClassDB::bind_method(D_METHOD("get_gizmo"), &Node3D::get_gizmo); + + ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Node3D::set_visible); + ClassDB::bind_method(D_METHOD("is_visible"), &Node3D::is_visible); + ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Node3D::is_visible_in_tree); + ClassDB::bind_method(D_METHOD("show"), &Node3D::show); + ClassDB::bind_method(D_METHOD("hide"), &Node3D::hide); + + ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Node3D::set_notify_local_transform); + ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Node3D::is_local_transform_notification_enabled); + + ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Node3D::set_notify_transform); + ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Node3D::is_transform_notification_enabled); + + ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Node3D::rotate); + ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Node3D::global_rotate); + ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Node3D::global_scale); + ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Node3D::global_translate); + ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Node3D::rotate_object_local); + ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Node3D::scale_object_local); + ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Node3D::translate_object_local); + ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Node3D::rotate_x); + ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Node3D::rotate_y); + ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Node3D::rotate_z); + ClassDB::bind_method(D_METHOD("translate", "offset"), &Node3D::translate); + ClassDB::bind_method(D_METHOD("orthonormalize"), &Node3D::orthonormalize); + ClassDB::bind_method(D_METHOD("set_identity"), &Node3D::set_identity); + + ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Node3D::look_at); + ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Node3D::look_at_from_position); + + ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node3D::to_local); + ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node3D::to_global); BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED); BIND_CONSTANT(NOTIFICATION_ENTER_WORLD); @@ -814,12 +814,12 @@ void Spatial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform"); ADD_GROUP("Visibility", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "Node3DGizmo", 0), "set_gizmo", "get_gizmo"); ADD_SIGNAL(MethodInfo("visibility_changed")); } -Spatial::Spatial() : +Node3D::Node3D() : xform_change(this) { data.dirty = DIRTY_NONE; @@ -829,7 +829,7 @@ Spatial::Spatial() : data.toplevel = false; data.toplevel_active = false; data.scale = Vector3(1, 1, 1); - data.viewport = NULL; + data.viewport = nullptr; data.inside_world = false; data.visible = true; data.disable_scale = false; @@ -840,9 +840,9 @@ Spatial::Spatial() : #endif data.notify_local_transform = false; data.notify_transform = false; - data.parent = NULL; - data.C = NULL; + data.parent = nullptr; + data.C = nullptr; } -Spatial::~Spatial() { +Node3D::~Node3D() { } diff --git a/scene/3d/spatial.h b/scene/3d/node_3d.h index 9d4705700b..f97a8a97dc 100644 --- a/scene/3d/spatial.h +++ b/scene/3d/node_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial.h */ +/* node_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SPATIAL_H -#define SPATIAL_H +#ifndef NODE_3D_H +#define NODE_3D_H #include "scene/main/node.h" #include "scene/main/scene_tree.h" -class SpatialGizmo : public Reference { +class Node3DGizmo : public Reference { - GDCLASS(SpatialGizmo, Reference); + GDCLASS(Node3DGizmo, Reference); public: virtual void create() = 0; @@ -45,13 +45,13 @@ public: virtual void redraw() = 0; virtual void free() = 0; - SpatialGizmo(); - virtual ~SpatialGizmo() {} + Node3DGizmo(); + virtual ~Node3DGizmo() {} }; -class Spatial : public Node { +class Node3D : public Node { - GDCLASS(Spatial, Node); + GDCLASS(Node3D, Node); OBJ_CATEGORY("3D"); enum TransformDirty { @@ -79,9 +79,9 @@ class Spatial : public Node { bool inside_world; int children_lock; - Spatial *parent; - List<Spatial *> children; - List<Spatial *>::Element *C; + Node3D *parent; + List<Node3D *> children; + List<Node3D *>::Element *C; bool ignore_notification; bool notify_local_transform; @@ -91,7 +91,7 @@ class Spatial : public Node { bool disable_scale; #ifdef TOOLS_ENABLED - Ref<SpatialGizmo> gizmo; + Ref<Node3DGizmo> gizmo; bool gizmo_disabled; bool gizmo_dirty; #endif @@ -100,7 +100,7 @@ class Spatial : public Node { void _update_gizmo(); void _notify_dirty(); - void _propagate_transform_changed(Spatial *p_origin); + void _propagate_transform_changed(Node3D *p_origin); void _propagate_visibility_changed(); @@ -122,9 +122,9 @@ public: NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 44, }; - Spatial *get_parent_spatial() const; + Node3D *get_parent_spatial() const; - Ref<World> get_world() const; + Ref<World3D> get_world() const; void set_translation(const Vector3 &p_translation); void set_rotation(const Vector3 &p_euler_rad); @@ -155,8 +155,8 @@ public: void set_disable_gizmo(bool p_enabled); void update_gizmo(); - void set_gizmo(const Ref<SpatialGizmo> &p_gizmo); - Ref<SpatialGizmo> get_gizmo() const; + void set_gizmo(const Ref<Node3DGizmo> &p_gizmo); + Ref<Node3DGizmo> get_gizmo() const; _FORCE_INLINE_ bool is_inside_world() const { return data.inside_world; } @@ -200,8 +200,8 @@ public: void force_update_transform(); - Spatial(); - ~Spatial(); + Node3D(); + ~Node3D(); }; -#endif +#endif // NODE_3D_H diff --git a/scene/3d/path.cpp b/scene/3d/path_3d.cpp index f93485d79f..4a425d1e0e 100644 --- a/scene/3d/path.cpp +++ b/scene/3d/path_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* path.cpp */ +/* path_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "path.h" +#include "path_3d.h" #include "core/engine.h" #include "scene/scene_string_names.h" -void Path::_notification(int p_what) { +void Path3D::_notification(int p_what) { } -void Path::_curve_changed() { +void Path3D::_curve_changed() { if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) update_gizmo(); @@ -48,7 +48,7 @@ void Path::_curve_changed() { // previously used for PathFollowOriented (now enforced orientation is done in PathFollow) if (is_inside_tree()) { for (int i = 0; i < get_child_count(); i++) { - PathFollow *child = Object::cast_to<PathFollow>(get_child(i)); + PathFollow3D *child = Object::cast_to<PathFollow3D>(get_child(i)); if (child) { child->update_configuration_warning(); } @@ -56,43 +56,43 @@ void Path::_curve_changed() { } } -void Path::set_curve(const Ref<Curve3D> &p_curve) { +void Path3D::set_curve(const Ref<Curve3D> &p_curve) { if (curve.is_valid()) { - curve->disconnect("changed", callable_mp(this, &Path::_curve_changed)); + curve->disconnect("changed", callable_mp(this, &Path3D::_curve_changed)); } curve = p_curve; if (curve.is_valid()) { - curve->connect("changed", callable_mp(this, &Path::_curve_changed)); + curve->connect("changed", callable_mp(this, &Path3D::_curve_changed)); } _curve_changed(); } -Ref<Curve3D> Path::get_curve() const { +Ref<Curve3D> Path3D::get_curve() const { return curve; } -void Path::_bind_methods() { +void Path3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Path::set_curve); - ClassDB::bind_method(D_METHOD("get_curve"), &Path::get_curve); + ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Path3D::set_curve); + ClassDB::bind_method(D_METHOD("get_curve"), &Path3D::get_curve); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve3D"), "set_curve", "get_curve"); ADD_SIGNAL(MethodInfo("curve_changed")); } -Path::Path() { +Path3D::Path3D() { set_curve(Ref<Curve3D>(memnew(Curve3D))); //create one by default } ////////////// -void PathFollow::_update_transform() { +void PathFollow3D::_update_transform() { if (!path) return; @@ -212,7 +212,7 @@ void PathFollow::_update_transform() { set_transform(t); } -void PathFollow::_notification(int p_what) { +void PathFollow3D::_notification(int p_what) { switch (p_what) { @@ -220,7 +220,7 @@ void PathFollow::_notification(int p_what) { Node *parent = get_parent(); if (parent) { - path = Object::cast_to<Path>(parent); + path = Object::cast_to<Path3D>(parent); if (path) { _update_transform(); } @@ -229,22 +229,22 @@ void PathFollow::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - path = NULL; + path = nullptr; } break; } } -void PathFollow::set_cubic_interpolation(bool p_enable) { +void PathFollow3D::set_cubic_interpolation(bool p_enable) { cubic = p_enable; } -bool PathFollow::get_cubic_interpolation() const { +bool PathFollow3D::get_cubic_interpolation() const { return cubic; } -void PathFollow::_validate_property(PropertyInfo &property) const { +void PathFollow3D::_validate_property(PropertyInfo &property) const { if (property.name == "offset") { @@ -256,45 +256,45 @@ void PathFollow::_validate_property(PropertyInfo &property) const { } } -String PathFollow::get_configuration_warning() const { +String PathFollow3D::get_configuration_warning() const { if (!is_visible_in_tree() || !is_inside_tree()) return String(); - if (!Object::cast_to<Path>(get_parent())) { - return TTR("PathFollow only works when set as a child of a Path node."); + if (!Object::cast_to<Path3D>(get_parent())) { + return TTR("PathFollow3D only works when set as a child of a Path3D node."); } else { - Path *path = Object::cast_to<Path>(get_parent()); + Path3D *path = Object::cast_to<Path3D>(get_parent()); if (path->get_curve().is_valid() && !path->get_curve()->is_up_vector_enabled() && rotation_mode == ROTATION_ORIENTED) { - return TTR("PathFollow's ROTATION_ORIENTED requires \"Up Vector\" to be enabled in its parent Path's Curve resource."); + return TTR("PathFollow3D's ROTATION_ORIENTED requires \"Up Vector\" to be enabled in its parent Path3D's Curve resource."); } } return String(); } -void PathFollow::_bind_methods() { +void PathFollow3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow::set_offset); - ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow::get_offset); + ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow3D::set_offset); + ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow3D::get_offset); - ClassDB::bind_method(D_METHOD("set_h_offset", "h_offset"), &PathFollow::set_h_offset); - ClassDB::bind_method(D_METHOD("get_h_offset"), &PathFollow::get_h_offset); + ClassDB::bind_method(D_METHOD("set_h_offset", "h_offset"), &PathFollow3D::set_h_offset); + ClassDB::bind_method(D_METHOD("get_h_offset"), &PathFollow3D::get_h_offset); - ClassDB::bind_method(D_METHOD("set_v_offset", "v_offset"), &PathFollow::set_v_offset); - ClassDB::bind_method(D_METHOD("get_v_offset"), &PathFollow::get_v_offset); + ClassDB::bind_method(D_METHOD("set_v_offset", "v_offset"), &PathFollow3D::set_v_offset); + ClassDB::bind_method(D_METHOD("get_v_offset"), &PathFollow3D::get_v_offset); - ClassDB::bind_method(D_METHOD("set_unit_offset", "unit_offset"), &PathFollow::set_unit_offset); - ClassDB::bind_method(D_METHOD("get_unit_offset"), &PathFollow::get_unit_offset); + ClassDB::bind_method(D_METHOD("set_unit_offset", "unit_offset"), &PathFollow3D::set_unit_offset); + ClassDB::bind_method(D_METHOD("get_unit_offset"), &PathFollow3D::get_unit_offset); - ClassDB::bind_method(D_METHOD("set_rotation_mode", "rotation_mode"), &PathFollow::set_rotation_mode); - ClassDB::bind_method(D_METHOD("get_rotation_mode"), &PathFollow::get_rotation_mode); + ClassDB::bind_method(D_METHOD("set_rotation_mode", "rotation_mode"), &PathFollow3D::set_rotation_mode); + ClassDB::bind_method(D_METHOD("get_rotation_mode"), &PathFollow3D::get_rotation_mode); - ClassDB::bind_method(D_METHOD("set_cubic_interpolation", "enable"), &PathFollow::set_cubic_interpolation); - ClassDB::bind_method(D_METHOD("get_cubic_interpolation"), &PathFollow::get_cubic_interpolation); + ClassDB::bind_method(D_METHOD("set_cubic_interpolation", "enable"), &PathFollow3D::set_cubic_interpolation); + ClassDB::bind_method(D_METHOD("get_cubic_interpolation"), &PathFollow3D::get_cubic_interpolation); - ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow::set_loop); - ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow::has_loop); + ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow3D::set_loop); + ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow3D::has_loop); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "offset", PROPERTY_HINT_RANGE, "0,10000,0.01,or_lesser,or_greater"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "unit_offset", PROPERTY_HINT_RANGE, "0,1,0.0001,or_lesser,or_greater", PROPERTY_USAGE_EDITOR), "set_unit_offset", "get_unit_offset"); @@ -311,21 +311,19 @@ void PathFollow::_bind_methods() { BIND_ENUM_CONSTANT(ROTATION_ORIENTED); } -void PathFollow::set_offset(float p_offset) { +void PathFollow3D::set_offset(float p_offset) { delta_offset = p_offset - offset; offset = p_offset; if (path) { - if (path->get_curve().is_valid() && path->get_curve()->get_baked_length()) { + if (path->get_curve().is_valid()) { float path_length = path->get_curve()->get_baked_length(); if (loop) { - while (offset > path_length) - offset -= path_length; - - while (offset < 0) - offset += path_length; - + offset = Math::fposmod(offset, path_length); + if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) { + offset = path_length; + } } else { offset = CLAMP(offset, 0, path_length); } @@ -337,42 +335,42 @@ void PathFollow::set_offset(float p_offset) { _change_notify("unit_offset"); } -void PathFollow::set_h_offset(float p_h_offset) { +void PathFollow3D::set_h_offset(float p_h_offset) { h_offset = p_h_offset; if (path) _update_transform(); } -float PathFollow::get_h_offset() const { +float PathFollow3D::get_h_offset() const { return h_offset; } -void PathFollow::set_v_offset(float p_v_offset) { +void PathFollow3D::set_v_offset(float p_v_offset) { v_offset = p_v_offset; if (path) _update_transform(); } -float PathFollow::get_v_offset() const { +float PathFollow3D::get_v_offset() const { return v_offset; } -float PathFollow::get_offset() const { +float PathFollow3D::get_offset() const { return offset; } -void PathFollow::set_unit_offset(float p_unit_offset) { +void PathFollow3D::set_unit_offset(float p_unit_offset) { if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) set_offset(p_unit_offset * path->get_curve()->get_baked_length()); } -float PathFollow::get_unit_offset() const { +float PathFollow3D::get_unit_offset() const { if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length()) return get_offset() / path->get_curve()->get_baked_length(); @@ -380,7 +378,7 @@ float PathFollow::get_unit_offset() const { return 0; } -void PathFollow::set_rotation_mode(RotationMode p_rotation_mode) { +void PathFollow3D::set_rotation_mode(RotationMode p_rotation_mode) { rotation_mode = p_rotation_mode; @@ -388,28 +386,28 @@ void PathFollow::set_rotation_mode(RotationMode p_rotation_mode) { _update_transform(); } -PathFollow::RotationMode PathFollow::get_rotation_mode() const { +PathFollow3D::RotationMode PathFollow3D::get_rotation_mode() const { return rotation_mode; } -void PathFollow::set_loop(bool p_loop) { +void PathFollow3D::set_loop(bool p_loop) { loop = p_loop; } -bool PathFollow::has_loop() const { +bool PathFollow3D::has_loop() const { return loop; } -PathFollow::PathFollow() { +PathFollow3D::PathFollow3D() { offset = 0; delta_offset = 0; h_offset = 0; v_offset = 0; - path = NULL; + path = nullptr; rotation_mode = ROTATION_XYZ; cubic = true; loop = true; diff --git a/scene/3d/path.h b/scene/3d/path_3d.h index 497913b925..6f0db8c5c2 100644 --- a/scene/3d/path.h +++ b/scene/3d/path_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* path.h */ +/* path_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,12 +31,12 @@ #ifndef PATH_H #define PATH_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/curve.h" -class Path : public Spatial { +class Path3D : public Node3D { - GDCLASS(Path, Spatial); + GDCLASS(Path3D, Node3D); Ref<Curve3D> curve; @@ -50,12 +50,12 @@ public: void set_curve(const Ref<Curve3D> &p_curve); Ref<Curve3D> get_curve() const; - Path(); + Path3D(); }; -class PathFollow : public Spatial { +class PathFollow3D : public Node3D { - GDCLASS(PathFollow, Spatial); + GDCLASS(PathFollow3D, Node3D); public: enum RotationMode { @@ -68,7 +68,7 @@ public: }; private: - Path *path; + Path3D *path; real_t delta_offset; // change in offset since last _update_transform real_t offset; real_t h_offset; @@ -109,9 +109,9 @@ public: String get_configuration_warning() const; - PathFollow(); + PathFollow3D(); }; -VARIANT_ENUM_CAST(PathFollow::RotationMode); +VARIANT_ENUM_CAST(PathFollow3D::RotationMode); #endif // PATH_H diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body_3d.cpp index 2f8dc31cb6..3991efc7c0 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* physics_body.cpp */ +/* physics_body_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "physics_body.h" +#include "physics_body_3d.h" #include "core/core_string_names.h" #include "core/engine.h" @@ -36,51 +36,51 @@ #include "core/method_bind_ext.gen.inc" #include "core/object.h" #include "core/rid.h" -#include "scene/3d/collision_shape.h" +#include "scene/3d/collision_shape_3d.h" #include "scene/scene_string_names.h" -#include "servers/navigation_server.h" +#include "servers/navigation_server_3d.h" #ifdef TOOLS_ENABLED -#include "editor/plugins/spatial_editor_plugin.h" +#include "editor/plugins/node_3d_editor_plugin.h" #endif -Vector3 PhysicsBody::get_linear_velocity() const { +Vector3 PhysicsBody3D::get_linear_velocity() const { return Vector3(); } -Vector3 PhysicsBody::get_angular_velocity() const { +Vector3 PhysicsBody3D::get_angular_velocity() const { return Vector3(); } -float PhysicsBody::get_inverse_mass() const { +float PhysicsBody3D::get_inverse_mass() const { return 0; } -void PhysicsBody::set_collision_layer(uint32_t p_layer) { +void PhysicsBody3D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), p_layer); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), p_layer); } -uint32_t PhysicsBody::get_collision_layer() const { +uint32_t PhysicsBody3D::get_collision_layer() const { return collision_layer; } -void PhysicsBody::set_collision_mask(uint32_t p_mask) { +void PhysicsBody3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), p_mask); } -uint32_t PhysicsBody::get_collision_mask() const { +uint32_t PhysicsBody3D::get_collision_mask() const { return collision_mask; } -void PhysicsBody::set_collision_mask_bit(int p_bit, bool p_value) { +void PhysicsBody3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -90,12 +90,12 @@ void PhysicsBody::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool PhysicsBody::get_collision_mask_bit(int p_bit) const { +bool PhysicsBody3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) { +void PhysicsBody3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_layer(); if (p_value) @@ -105,155 +105,155 @@ void PhysicsBody::set_collision_layer_bit(int p_bit, bool p_value) { set_collision_layer(mask); } -bool PhysicsBody::get_collision_layer_bit(int p_bit) const { +bool PhysicsBody3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -Array PhysicsBody::get_collision_exceptions() { +TypedArray<PhysicsBody3D> PhysicsBody3D::get_collision_exceptions() { List<RID> exceptions; - PhysicsServer::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); + PhysicsServer3D::get_singleton()->body_get_collision_exceptions(get_rid(), &exceptions); Array ret; for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) { RID body = E->get(); - ObjectID instance_id = PhysicsServer::get_singleton()->body_get_object_instance_id(body); + ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); - PhysicsBody *physics_body = Object::cast_to<PhysicsBody>(obj); + PhysicsBody3D *physics_body = Object::cast_to<PhysicsBody3D>(obj); ret.append(physics_body); } return ret; } -void PhysicsBody::add_collision_exception_with(Node *p_node) { +void PhysicsBody3D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->body_add_collision_exception(get_rid(), collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->body_add_collision_exception(get_rid(), collision_object->get_rid()); } -void PhysicsBody::remove_collision_exception_with(Node *p_node) { +void PhysicsBody3D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(p_node); + ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject3Ds."); + PhysicsServer3D::get_singleton()->body_remove_collision_exception(get_rid(), collision_object->get_rid()); } -void PhysicsBody::_set_layers(uint32_t p_mask) { +void PhysicsBody3D::_set_layers(uint32_t p_mask) { set_collision_layer(p_mask); set_collision_mask(p_mask); } -uint32_t PhysicsBody::_get_layers() const { +uint32_t PhysicsBody3D::_get_layers() const { return get_collision_layer(); } -void PhysicsBody::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody::get_collision_layer); +void PhysicsBody3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &PhysicsBody3D::set_collision_layer); + ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody3D::get_collision_layer); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody3D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody3D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody::_set_layers); - ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody::_get_layers); + ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody3D::_set_layers); + ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody3D::_get_layers); 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"); } -PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode) : - CollisionObject(PhysicsServer::get_singleton()->body_create(p_mode), false) { +PhysicsBody3D::PhysicsBody3D(PhysicsServer3D::BodyMode p_mode) : + CollisionObject3D(PhysicsServer3D::get_singleton()->body_create(p_mode), false) { collision_layer = 1; collision_mask = 1; } -void StaticBody::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { +void StaticBody3D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { if (physics_material_override.is_valid()) { - if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody::_reload_physics_characteristics))) { - physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody::_reload_physics_characteristics)); + if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody3D::_reload_physics_characteristics))) { + physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody3D::_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, &StaticBody::_reload_physics_characteristics)); + physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &StaticBody3D::_reload_physics_characteristics)); } _reload_physics_characteristics(); } -Ref<PhysicsMaterial> StaticBody::get_physics_material_override() const { +Ref<PhysicsMaterial> StaticBody3D::get_physics_material_override() const { return physics_material_override; } -void StaticBody::set_constant_linear_velocity(const Vector3 &p_vel) { +void StaticBody3D::set_constant_linear_velocity(const Vector3 &p_vel) { constant_linear_velocity = p_vel; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity); } -void StaticBody::set_constant_angular_velocity(const Vector3 &p_vel) { +void StaticBody3D::set_constant_angular_velocity(const Vector3 &p_vel) { constant_angular_velocity = p_vel; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity); } -Vector3 StaticBody::get_constant_linear_velocity() const { +Vector3 StaticBody3D::get_constant_linear_velocity() const { return constant_linear_velocity; } -Vector3 StaticBody::get_constant_angular_velocity() const { +Vector3 StaticBody3D::get_constant_angular_velocity() const { return constant_angular_velocity; } -void StaticBody::_bind_methods() { +void StaticBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody::set_constant_linear_velocity); - ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody::set_constant_angular_velocity); - ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody::get_constant_linear_velocity); - ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"), &StaticBody::get_constant_angular_velocity); + ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody3D::set_constant_linear_velocity); + ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody3D::set_constant_angular_velocity); + ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody3D::get_constant_linear_velocity); + ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"), &StaticBody3D::get_constant_angular_velocity); - ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &StaticBody::set_physics_material_override); - ClassDB::bind_method(D_METHOD("get_physics_material_override"), &StaticBody::get_physics_material_override); + ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &StaticBody3D::set_physics_material_override); + ClassDB::bind_method(D_METHOD("get_physics_material_override"), &StaticBody3D::get_physics_material_override); - ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody::get_collision_exceptions); - ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody::add_collision_exception_with); - ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody::remove_collision_exception_with); + ClassDB::bind_method(D_METHOD("get_collision_exceptions"), &PhysicsBody3D::get_collision_exceptions); + ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &PhysicsBody3D::add_collision_exception_with); + ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &PhysicsBody3D::remove_collision_exception_with); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "physics_material_override", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsMaterial"), "set_physics_material_override", "get_physics_material_override"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_linear_velocity"), "set_constant_linear_velocity", "get_constant_linear_velocity"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity"); } -StaticBody::StaticBody() : - PhysicsBody(PhysicsServer::BODY_MODE_STATIC) { +StaticBody3D::StaticBody3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_STATIC) { } -StaticBody::~StaticBody() {} +StaticBody3D::~StaticBody3D() {} -void StaticBody::_reload_physics_characteristics() { +void StaticBody3D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, 0); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, 1); + 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); } else { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); } } -void RigidBody::_body_enter_tree(ObjectID p_id) { +void RigidBody3D::_body_enter_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -278,7 +278,7 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody::_body_exit_tree(ObjectID p_id) { +void RigidBody3D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); @@ -301,7 +301,7 @@ void RigidBody::_body_exit_tree(ObjectID p_id) { contact_monitor->locked = false; } -void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) { +void RigidBody3D::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) { bool body_in = p_status == 1; ObjectID objid = p_instance; @@ -321,8 +321,8 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, //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, &RigidBody::_body_enter_tree), make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody::_body_exit_tree), make_binds(objid)); + 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)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -348,8 +348,8 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, if (E->get().shapes.empty()) { if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody::_body_exit_tree)); + 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)); if (in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, node); } @@ -369,12 +369,12 @@ struct _RigidBodyInOut { int local_shape; }; -void RigidBody::_direct_state_changed(Object *p_state) { +void RigidBody3D::_direct_state_changed(Object *p_state) { #ifdef DEBUG_ENABLED - state = Object::cast_to<PhysicsDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); #else - state = (PhysicsDirectBodyState *)p_state; //trust it + state = (PhysicsDirectBodyState3D *)p_state; //trust it #endif set_ignore_transform_notification(true); @@ -406,7 +406,7 @@ void RigidBody::_direct_state_changed(Object *p_state) { _RigidBodyInOut *toadd = (_RigidBodyInOut *)alloca(state->get_contact_count() * sizeof(_RigidBodyInOut)); int toadd_count = 0; //state->get_contact_count(); - RigidBody_RemoveAction *toremove = (RigidBody_RemoveAction *)alloca(rc * sizeof(RigidBody_RemoveAction)); + RigidBody3D_RemoveAction *toremove = (RigidBody3D_RemoveAction *)alloca(rc * sizeof(RigidBody3D_RemoveAction)); int toremove_count = 0; //put the ones to add @@ -474,10 +474,10 @@ void RigidBody::_direct_state_changed(Object *p_state) { contact_monitor->locked = false; } - state = NULL; + state = nullptr; } -void RigidBody::_notification(int p_what) { +void RigidBody3D::_notification(int p_what) { #ifdef TOOLS_ENABLED if (p_what == NOTIFICATION_ENTER_TREE) { @@ -495,111 +495,111 @@ void RigidBody::_notification(int p_what) { #endif } -void RigidBody::set_mode(Mode p_mode) { +void RigidBody3D::set_mode(Mode p_mode) { mode = p_mode; switch (p_mode) { case MODE_RIGID: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_RIGID); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_RIGID); } break; case MODE_STATIC: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_STATIC); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); } break; case MODE_CHARACTER: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_CHARACTER); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_CHARACTER); } break; case MODE_KINEMATIC: { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_KINEMATIC); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); } break; } update_configuration_warning(); } -RigidBody::Mode RigidBody::get_mode() const { +RigidBody3D::Mode RigidBody3D::get_mode() const { return mode; } -void RigidBody::set_mass(real_t p_mass) { +void RigidBody3D::set_mass(real_t p_mass) { ERR_FAIL_COND(p_mass <= 0); mass = p_mass; _change_notify("mass"); _change_notify("weight"); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_MASS, mass); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_MASS, mass); } -real_t RigidBody::get_mass() const { +real_t RigidBody3D::get_mass() const { return mass; } -void RigidBody::set_weight(real_t p_weight) { +void RigidBody3D::set_weight(real_t p_weight) { set_mass(p_weight / real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8))); } -real_t RigidBody::get_weight() const { +real_t RigidBody3D::get_weight() const { return mass * real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8)); } -void RigidBody::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { +void RigidBody3D::set_physics_material_override(const Ref<PhysicsMaterial> &p_physics_material_override) { if (physics_material_override.is_valid()) { - if (physics_material_override->is_connected(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody::_reload_physics_characteristics))) { - physics_material_override->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody::_reload_physics_characteristics)); + 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)); } } physics_material_override = p_physics_material_override; if (physics_material_override.is_valid()) { - physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody::_reload_physics_characteristics)); + physics_material_override->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &RigidBody3D::_reload_physics_characteristics)); } _reload_physics_characteristics(); } -Ref<PhysicsMaterial> RigidBody::get_physics_material_override() const { +Ref<PhysicsMaterial> RigidBody3D::get_physics_material_override() const { return physics_material_override; } -void RigidBody::set_gravity_scale(real_t p_gravity_scale) { +void RigidBody3D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } -real_t RigidBody::get_gravity_scale() const { +real_t RigidBody3D::get_gravity_scale() const { return gravity_scale; } -void RigidBody::set_linear_damp(real_t p_linear_damp) { +void RigidBody3D::set_linear_damp(real_t p_linear_damp) { ERR_FAIL_COND(p_linear_damp < -1); linear_damp = p_linear_damp; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_LINEAR_DAMP, linear_damp); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_LINEAR_DAMP, linear_damp); } -real_t RigidBody::get_linear_damp() const { +real_t RigidBody3D::get_linear_damp() const { return linear_damp; } -void RigidBody::set_angular_damp(real_t p_angular_damp) { +void RigidBody3D::set_angular_damp(real_t p_angular_damp) { ERR_FAIL_COND(p_angular_damp < -1); angular_damp = p_angular_damp; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_ANGULAR_DAMP, angular_damp); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_ANGULAR_DAMP, angular_damp); } -real_t RigidBody::get_angular_damp() const { +real_t RigidBody3D::get_angular_damp() const { return angular_damp; } -void RigidBody::set_axis_velocity(const Vector3 &p_axis) { +void RigidBody3D::set_axis_velocity(const Vector3 &p_axis) { Vector3 v = state ? state->get_linear_velocity() : linear_velocity; Vector3 axis = p_axis.normalized(); @@ -608,121 +608,121 @@ void RigidBody::set_axis_velocity(const Vector3 &p_axis) { if (state) { set_linear_velocity(v); } else { - PhysicsServer::get_singleton()->body_set_axis_velocity(get_rid(), p_axis); + PhysicsServer3D::get_singleton()->body_set_axis_velocity(get_rid(), p_axis); linear_velocity = v; } } -void RigidBody::set_linear_velocity(const Vector3 &p_velocity) { +void RigidBody3D::set_linear_velocity(const Vector3 &p_velocity) { linear_velocity = p_velocity; if (state) state->set_linear_velocity(linear_velocity); else - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_LINEAR_VELOCITY, linear_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_LINEAR_VELOCITY, linear_velocity); } -Vector3 RigidBody::get_linear_velocity() const { +Vector3 RigidBody3D::get_linear_velocity() const { return linear_velocity; } -void RigidBody::set_angular_velocity(const Vector3 &p_velocity) { +void RigidBody3D::set_angular_velocity(const Vector3 &p_velocity) { angular_velocity = p_velocity; if (state) state->set_angular_velocity(angular_velocity); else - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_ANGULAR_VELOCITY, angular_velocity); } -Vector3 RigidBody::get_angular_velocity() const { +Vector3 RigidBody3D::get_angular_velocity() const { return angular_velocity; } -void RigidBody::set_use_custom_integrator(bool p_enable) { +void RigidBody3D::set_use_custom_integrator(bool p_enable) { if (custom_integrator == p_enable) return; custom_integrator = p_enable; - PhysicsServer::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); + PhysicsServer3D::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable); } -bool RigidBody::is_using_custom_integrator() { +bool RigidBody3D::is_using_custom_integrator() { return custom_integrator; } -void RigidBody::set_sleeping(bool p_sleeping) { +void RigidBody3D::set_sleeping(bool p_sleeping) { sleeping = p_sleeping; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_SLEEPING, sleeping); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_SLEEPING, sleeping); } -void RigidBody::set_can_sleep(bool p_active) { +void RigidBody3D::set_can_sleep(bool p_active) { can_sleep = p_active; - PhysicsServer::get_singleton()->body_set_state(get_rid(), PhysicsServer::BODY_STATE_CAN_SLEEP, p_active); + PhysicsServer3D::get_singleton()->body_set_state(get_rid(), PhysicsServer3D::BODY_STATE_CAN_SLEEP, p_active); } -bool RigidBody::is_able_to_sleep() const { +bool RigidBody3D::is_able_to_sleep() const { return can_sleep; } -bool RigidBody::is_sleeping() const { +bool RigidBody3D::is_sleeping() const { return sleeping; } -void RigidBody::set_max_contacts_reported(int p_amount) { +void RigidBody3D::set_max_contacts_reported(int p_amount) { max_contacts_reported = p_amount; - PhysicsServer::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); + PhysicsServer3D::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount); } -int RigidBody::get_max_contacts_reported() const { +int RigidBody3D::get_max_contacts_reported() const { return max_contacts_reported; } -void RigidBody::add_central_force(const Vector3 &p_force) { - PhysicsServer::get_singleton()->body_add_central_force(get_rid(), p_force); +void RigidBody3D::add_central_force(const Vector3 &p_force) { + PhysicsServer3D::get_singleton()->body_add_central_force(get_rid(), p_force); } -void RigidBody::add_force(const Vector3 &p_force, const Vector3 &p_pos) { - PhysicsServer::get_singleton()->body_add_force(get_rid(), p_force, p_pos); +void RigidBody3D::add_force(const Vector3 &p_force, const Vector3 &p_pos) { + PhysicsServer3D::get_singleton()->body_add_force(get_rid(), p_force, p_pos); } -void RigidBody::add_torque(const Vector3 &p_torque) { - PhysicsServer::get_singleton()->body_add_torque(get_rid(), p_torque); +void RigidBody3D::add_torque(const Vector3 &p_torque) { + PhysicsServer3D::get_singleton()->body_add_torque(get_rid(), p_torque); } -void RigidBody::apply_central_impulse(const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); +void RigidBody3D::apply_central_impulse(const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } -void RigidBody::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { +void RigidBody3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); + PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); } -void RigidBody::apply_torque_impulse(const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_torque_impulse(get_rid(), p_impulse); +void RigidBody3D::apply_torque_impulse(const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_torque_impulse(get_rid(), p_impulse); } -void RigidBody::set_use_continuous_collision_detection(bool p_enable) { +void RigidBody3D::set_use_continuous_collision_detection(bool p_enable) { ccd = p_enable; - PhysicsServer::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(), p_enable); + PhysicsServer3D::get_singleton()->body_set_enable_continuous_collision_detection(get_rid(), p_enable); } -bool RigidBody::is_using_continuous_collision_detection() const { +bool RigidBody3D::is_using_continuous_collision_detection() const { return ccd; } -void RigidBody::set_contact_monitor(bool p_enabled) { +void RigidBody3D::set_contact_monitor(bool p_enabled) { if (p_enabled == is_contact_monitor_enabled()) return; @@ -738,13 +738,13 @@ void RigidBody::set_contact_monitor(bool p_enabled) { Node *node = Object::cast_to<Node>(obj); if (node) { - node->disconnect(SceneStringNames::get_singleton()->tree_entered, callable_mp(this, &RigidBody::_body_enter_tree)); - node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &RigidBody::_body_exit_tree)); + 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)); } } memdelete(contact_monitor); - contact_monitor = NULL; + contact_monitor = nullptr; } else { contact_monitor = memnew(ContactMonitor); @@ -752,20 +752,20 @@ void RigidBody::set_contact_monitor(bool p_enabled) { } } -bool RigidBody::is_contact_monitor_enabled() const { +bool RigidBody3D::is_contact_monitor_enabled() const { - return contact_monitor != NULL; + return contact_monitor != nullptr; } -void RigidBody::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock) { - PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); +void RigidBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { + PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); } -bool RigidBody::get_axis_lock(PhysicsServer::BodyAxis p_axis) const { - return PhysicsServer::get_singleton()->body_is_axis_locked(get_rid(), p_axis); +bool RigidBody3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const { + return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis); } -Array RigidBody::get_colliding_bodies() const { +Array RigidBody3D::get_colliding_bodies() const { ERR_FAIL_COND_V(!contact_monitor, Array()); @@ -784,87 +784,87 @@ Array RigidBody::get_colliding_bodies() const { return ret; } -String RigidBody::get_configuration_warning() const { +String RigidBody3D::get_configuration_warning() const { Transform t = get_transform(); - String warning = CollisionObject::get_configuration_warning(); + String warning = CollisionObject3D::get_configuration_warning(); if ((get_mode() == MODE_RIGID || get_mode() == MODE_CHARACTER) && (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)) { if (warning != String()) { warning += "\n\n"; } - warning += TTR("Size changes to RigidBody (in character or rigid modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); + warning += TTR("Size changes to RigidBody3D (in character or rigid modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } return warning; } -void RigidBody::_bind_methods() { +void RigidBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody::set_mode); - ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody::get_mode); + ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody3D::set_mode); + ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody3D::get_mode); - ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody::set_mass); - ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody::get_mass); + 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_weight", "weight"), &RigidBody::set_weight); - ClassDB::bind_method(D_METHOD("get_weight"), &RigidBody::get_weight); + ClassDB::bind_method(D_METHOD("set_weight", "weight"), &RigidBody3D::set_weight); + ClassDB::bind_method(D_METHOD("get_weight"), &RigidBody3D::get_weight); - ClassDB::bind_method(D_METHOD("set_physics_material_override", "physics_material_override"), &RigidBody::set_physics_material_override); - ClassDB::bind_method(D_METHOD("get_physics_material_override"), &RigidBody::get_physics_material_override); + 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_linear_velocity", "linear_velocity"), &RigidBody::set_linear_velocity); - ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody::get_linear_velocity); + 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_angular_velocity", "angular_velocity"), &RigidBody::set_angular_velocity); - ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody::get_angular_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_gravity_scale", "gravity_scale"), &RigidBody::set_gravity_scale); - ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody::get_gravity_scale); + 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_linear_damp", "linear_damp"), &RigidBody::set_linear_damp); - ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody::get_linear_damp); + 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_angular_damp", "angular_damp"), &RigidBody::set_angular_damp); - ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody::get_angular_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_max_contacts_reported", "amount"), &RigidBody::set_max_contacts_reported); - ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody::get_max_contacts_reported); + 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_use_custom_integrator", "enable"), &RigidBody::set_use_custom_integrator); - ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody::is_using_custom_integrator); + 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_contact_monitor", "enabled"), &RigidBody::set_contact_monitor); - ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody::is_contact_monitor_enabled); + 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_use_continuous_collision_detection", "enable"), &RigidBody::set_use_continuous_collision_detection); - ClassDB::bind_method(D_METHOD("is_using_continuous_collision_detection"), &RigidBody::is_using_continuous_collision_detection); + 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_axis_velocity", "axis_velocity"), &RigidBody::set_axis_velocity); + ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody3D::set_axis_velocity); - ClassDB::bind_method(D_METHOD("add_central_force", "force"), &RigidBody::add_central_force); - ClassDB::bind_method(D_METHOD("add_force", "force", "position"), &RigidBody::add_force); - ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody::add_torque); + 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); + ClassDB::bind_method(D_METHOD("add_torque", "torque"), &RigidBody3D::add_torque); - ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody::apply_central_impulse); - ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &RigidBody::apply_impulse); - ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody::apply_torque_impulse); + ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &RigidBody3D::apply_central_impulse); + ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &RigidBody3D::apply_impulse); + ClassDB::bind_method(D_METHOD("apply_torque_impulse", "impulse"), &RigidBody3D::apply_torque_impulse); - ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody::set_sleeping); - ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody::is_sleeping); + 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_can_sleep", "able_to_sleep"), &RigidBody::set_can_sleep); - ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody::is_able_to_sleep); + 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("_direct_state_changed"), &RigidBody::_direct_state_changed); + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &RigidBody3D::_direct_state_changed); - ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &RigidBody::set_axis_lock); - ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &RigidBody::get_axis_lock); + ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &RigidBody3D::set_axis_lock); + ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &RigidBody3D::get_axis_lock); - ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody::get_colliding_bodies); + ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody3D::get_colliding_bodies); - BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState"))); + BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectBodyState3D"))); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Rigid,Static,Character,Kinematic"), "set_mode", "get_mode"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass"); @@ -878,12 +878,12 @@ void RigidBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleeping", "is_sleeping"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep"); ADD_GROUP("Axis Lock", "axis_lock_"); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_ANGULAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Z); ADD_GROUP("Linear", "linear_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); @@ -903,14 +903,14 @@ void RigidBody::_bind_methods() { BIND_ENUM_CONSTANT(MODE_KINEMATIC); } -RigidBody::RigidBody() : - PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { +RigidBody3D::RigidBody3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_RIGID) { mode = MODE_RIGID; mass = 1; max_contacts_reported = 0; - state = NULL; + state = nullptr; gravity_scale = 1; linear_damp = -1; @@ -921,32 +921,32 @@ RigidBody::RigidBody() : ccd = false; custom_integrator = false; - contact_monitor = NULL; + contact_monitor = nullptr; can_sleep = true; - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); } -RigidBody::~RigidBody() { +RigidBody3D::~RigidBody3D() { if (contact_monitor) memdelete(contact_monitor); } -void RigidBody::_reload_physics_characteristics() { +void RigidBody3D::_reload_physics_characteristics() { if (physics_material_override.is_null()) { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, 0); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, 1); + 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); } else { - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, physics_material_override->computed_bounce()); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, physics_material_override->computed_friction()); } } ////////////////////////////////////////////////////// ////////////////////////// -Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { +Ref<KinematicCollision3D> KinematicBody3D::_move(const Vector3 &p_motion, bool p_infinite_inertia, bool p_exclude_raycast_shapes, bool p_test_only) { Collision col; if (move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only)) { @@ -960,22 +960,22 @@ Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_inf return motion_cache; } - return Ref<KinematicCollision>(); + return Ref<KinematicCollision3D>(); } -Vector3 KinematicBody::get_linear_velocity() const { +Vector3 KinematicBody3D::get_linear_velocity() const { return linear_velocity; } -Vector3 KinematicBody::get_angular_velocity() const { +Vector3 KinematicBody3D::get_angular_velocity() const { return angular_velocity; } -bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { +bool KinematicBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, Collision &r_collision, bool p_exclude_raycast_shapes, bool p_test_only) { Transform gt = get_global_transform(); - PhysicsServer::MotionResult result; - bool colliding = PhysicsServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, &result, p_exclude_raycast_shapes); + PhysicsServer3D::MotionResult result; + bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, &result, p_exclude_raycast_shapes); if (colliding) { r_collision.collider_metadata = result.collider_metadata; @@ -1007,7 +1007,7 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, bool p_infinite_in //so, if you pass 45 as limit, avoid numerical precision errors when angle is 45. #define FLOOR_ANGLE_THRESHOLD 0.01 -Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { +Vector3 KinematicBody3D::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { Vector3 body_velocity = p_linear_velocity; Vector3 body_velocity_normal = body_velocity.normalized(); @@ -1101,7 +1101,7 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve return body_velocity; } -Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { +Vector3 KinematicBody3D::move_and_slide_with_snap(const Vector3 &p_linear_velocity, const Vector3 &p_snap, const Vector3 &p_up_direction, bool p_stop_on_slope, int p_max_slides, float p_floor_max_angle, bool p_infinite_inertia) { bool was_on_floor = on_floor; @@ -1140,45 +1140,45 @@ Vector3 KinematicBody::move_and_slide_with_snap(const Vector3 &p_linear_velocity return ret; } -bool KinematicBody::is_on_floor() const { +bool KinematicBody3D::is_on_floor() const { return on_floor; } -bool KinematicBody::is_on_wall() const { +bool KinematicBody3D::is_on_wall() const { return on_wall; } -bool KinematicBody::is_on_ceiling() const { +bool KinematicBody3D::is_on_ceiling() const { return on_ceiling; } -Vector3 KinematicBody::get_floor_normal() const { +Vector3 KinematicBody3D::get_floor_normal() const { return floor_normal; } -Vector3 KinematicBody::get_floor_velocity() const { +Vector3 KinematicBody3D::get_floor_velocity() const { return floor_velocity; } -bool KinematicBody::test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia) { +bool KinematicBody3D::test_move(const Transform &p_from, const Vector3 &p_motion, bool p_infinite_inertia) { ERR_FAIL_COND_V(!is_inside_tree(), false); - return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia); + return PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, p_infinite_inertia); } -bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { +bool KinematicBody3D::separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision) { - PhysicsServer::SeparationResult sep_res[8]; //max 8 rays + PhysicsServer3D::SeparationResult sep_res[8]; //max 8 rays Transform gt = get_global_transform(); Vector3 recover; - int hits = PhysicsServer::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); + int hits = PhysicsServer3D::get_singleton()->body_test_ray_separation(get_rid(), gt, p_infinite_inertia, recover, sep_res, 8, margin); int deepest = -1; float deepest_depth; for (int i = 0; i < hits; i++) { @@ -1208,37 +1208,37 @@ bool KinematicBody::separate_raycast_shapes(bool p_infinite_inertia, Collision & } } -void KinematicBody::set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock) { - PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); +void KinematicBody3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { + PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); } -bool KinematicBody::get_axis_lock(PhysicsServer::BodyAxis p_axis) const { - return PhysicsServer::get_singleton()->body_is_axis_locked(get_rid(), p_axis); +bool KinematicBody3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const { + return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis); } -void KinematicBody::set_safe_margin(float p_margin) { +void KinematicBody3D::set_safe_margin(float p_margin) { margin = p_margin; - PhysicsServer::get_singleton()->body_set_kinematic_safe_margin(get_rid(), margin); + PhysicsServer3D::get_singleton()->body_set_kinematic_safe_margin(get_rid(), margin); } -float KinematicBody::get_safe_margin() const { +float KinematicBody3D::get_safe_margin() const { return margin; } -int KinematicBody::get_slide_count() const { +int KinematicBody3D::get_slide_count() const { return colliders.size(); } -KinematicBody::Collision KinematicBody::get_slide_collision(int p_bounce) const { +KinematicBody3D::Collision KinematicBody3D::get_slide_collision(int p_bounce) const { ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Collision()); return colliders[p_bounce]; } -Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) { +Ref<KinematicCollision3D> KinematicBody3D::_get_slide_collision(int p_bounce) { - ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Ref<KinematicCollision>()); + ERR_FAIL_INDEX_V(p_bounce, colliders.size(), Ref<KinematicCollision3D>()); if (p_bounce >= slide_colliders.size()) { slide_colliders.resize(p_bounce + 1); } @@ -1252,7 +1252,7 @@ Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) { return slide_colliders[p_bounce]; } -void KinematicBody::_notification(int p_what) { +void KinematicBody3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { // Reset move_and_slide() data. on_floor = false; @@ -1264,51 +1264,51 @@ void KinematicBody::_notification(int p_what) { } } -void KinematicBody::_bind_methods() { +void KinematicBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_direct_state_changed"), &KinematicBody::_direct_state_changed); + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &KinematicBody3D::_direct_state_changed); - ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); - ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody::move_and_slide_with_snap, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody3D::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); + ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody3D::move_and_slide, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); + ClassDB::bind_method(D_METHOD("move_and_slide_with_snap", "linear_velocity", "snap", "up_direction", "stop_on_slope", "max_slides", "floor_max_angle", "infinite_inertia"), &KinematicBody3D::move_and_slide_with_snap, DEFVAL(Vector3(0, 0, 0)), DEFVAL(false), DEFVAL(4), DEFVAL(Math::deg2rad((float)45)), DEFVAL(true)); - ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody::test_move, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec", "infinite_inertia"), &KinematicBody3D::test_move, DEFVAL(true)); - ClassDB::bind_method(D_METHOD("is_on_floor"), &KinematicBody::is_on_floor); - ClassDB::bind_method(D_METHOD("is_on_ceiling"), &KinematicBody::is_on_ceiling); - ClassDB::bind_method(D_METHOD("is_on_wall"), &KinematicBody::is_on_wall); - ClassDB::bind_method(D_METHOD("get_floor_normal"), &KinematicBody::get_floor_normal); - ClassDB::bind_method(D_METHOD("get_floor_velocity"), &KinematicBody::get_floor_velocity); + ClassDB::bind_method(D_METHOD("is_on_floor"), &KinematicBody3D::is_on_floor); + ClassDB::bind_method(D_METHOD("is_on_ceiling"), &KinematicBody3D::is_on_ceiling); + ClassDB::bind_method(D_METHOD("is_on_wall"), &KinematicBody3D::is_on_wall); + ClassDB::bind_method(D_METHOD("get_floor_normal"), &KinematicBody3D::get_floor_normal); + ClassDB::bind_method(D_METHOD("get_floor_velocity"), &KinematicBody3D::get_floor_velocity); - ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &KinematicBody::set_axis_lock); - ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &KinematicBody::get_axis_lock); + ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &KinematicBody3D::set_axis_lock); + ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &KinematicBody3D::get_axis_lock); - ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &KinematicBody::set_safe_margin); - ClassDB::bind_method(D_METHOD("get_safe_margin"), &KinematicBody::get_safe_margin); + ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &KinematicBody3D::set_safe_margin); + ClassDB::bind_method(D_METHOD("get_safe_margin"), &KinematicBody3D::get_safe_margin); - ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody::get_slide_count); - ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody::_get_slide_collision); + ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody3D::get_slide_count); + ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody3D::_get_slide_collision); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_x", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_X); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_y", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Y); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_z", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer::BODY_AXIS_LINEAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_x", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_y", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "move_lock_z", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Z); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin"); } -void KinematicBody::_direct_state_changed(Object *p_state) { +void KinematicBody3D::_direct_state_changed(Object *p_state) { #ifdef DEBUG_ENABLED - PhysicsDirectBodyState *state = Object::cast_to<PhysicsDirectBodyState>(p_state); + PhysicsDirectBodyState3D *state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); #else - PhysicsDirectBodyState *state = (PhysicsDirectBodyState *)p_state; //trust it + PhysicsDirectBodyState3D *state = (PhysicsDirectBodyState3D *)p_state; //trust it #endif linear_velocity = state->get_linear_velocity(); angular_velocity = state->get_angular_velocity(); } -KinematicBody::KinematicBody() : - PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC) { +KinematicBody3D::KinematicBody3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_KINEMATIC) { margin = 0.001; locked_axis = 0; @@ -1316,92 +1316,92 @@ KinematicBody::KinematicBody() : on_ceiling = false; on_wall = false; - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); } -KinematicBody::~KinematicBody() { +KinematicBody3D::~KinematicBody3D() { if (motion_cache.is_valid()) { - motion_cache->owner = NULL; + motion_cache->owner = nullptr; } for (int i = 0; i < slide_colliders.size(); i++) { if (slide_colliders[i].is_valid()) { - slide_colliders.write[i]->owner = NULL; + slide_colliders.write[i]->owner = nullptr; } } } /////////////////////////////////////// -Vector3 KinematicCollision::get_position() const { +Vector3 KinematicCollision3D::get_position() const { return collision.collision; } -Vector3 KinematicCollision::get_normal() const { +Vector3 KinematicCollision3D::get_normal() const { return collision.normal; } -Vector3 KinematicCollision::get_travel() const { +Vector3 KinematicCollision3D::get_travel() const { return collision.travel; } -Vector3 KinematicCollision::get_remainder() const { +Vector3 KinematicCollision3D::get_remainder() const { return collision.remainder; } -Object *KinematicCollision::get_local_shape() const { - if (!owner) return NULL; +Object *KinematicCollision3D::get_local_shape() const { + if (!owner) return nullptr; uint32_t ownerid = owner->shape_find_owner(collision.local_shape); return owner->shape_owner_get_owner(ownerid); } -Object *KinematicCollision::get_collider() const { +Object *KinematicCollision3D::get_collider() const { if (collision.collider.is_valid()) { return ObjectDB::get_instance(collision.collider); } - return NULL; + return nullptr; } -ObjectID KinematicCollision::get_collider_id() const { +ObjectID KinematicCollision3D::get_collider_id() const { return collision.collider; } -Object *KinematicCollision::get_collider_shape() const { +Object *KinematicCollision3D::get_collider_shape() const { Object *collider = get_collider(); if (collider) { - CollisionObject *obj2d = Object::cast_to<CollisionObject>(collider); + CollisionObject3D *obj2d = Object::cast_to<CollisionObject3D>(collider); if (obj2d) { uint32_t ownerid = obj2d->shape_find_owner(collision.collider_shape); return obj2d->shape_owner_get_owner(ownerid); } } - return NULL; + return nullptr; } -int KinematicCollision::get_collider_shape_index() const { +int KinematicCollision3D::get_collider_shape_index() const { return collision.collider_shape; } -Vector3 KinematicCollision::get_collider_velocity() const { +Vector3 KinematicCollision3D::get_collider_velocity() const { return collision.collider_vel; } -Variant KinematicCollision::get_collider_metadata() const { +Variant KinematicCollision3D::get_collider_metadata() const { return Variant(); } -void KinematicCollision::_bind_methods() { +void KinematicCollision3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_position"), &KinematicCollision::get_position); - ClassDB::bind_method(D_METHOD("get_normal"), &KinematicCollision::get_normal); - ClassDB::bind_method(D_METHOD("get_travel"), &KinematicCollision::get_travel); - ClassDB::bind_method(D_METHOD("get_remainder"), &KinematicCollision::get_remainder); - ClassDB::bind_method(D_METHOD("get_local_shape"), &KinematicCollision::get_local_shape); - ClassDB::bind_method(D_METHOD("get_collider"), &KinematicCollision::get_collider); - ClassDB::bind_method(D_METHOD("get_collider_id"), &KinematicCollision::get_collider_id); - ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicCollision::get_collider_shape); - ClassDB::bind_method(D_METHOD("get_collider_shape_index"), &KinematicCollision::get_collider_shape_index); - ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicCollision::get_collider_velocity); - ClassDB::bind_method(D_METHOD("get_collider_metadata"), &KinematicCollision::get_collider_metadata); + ClassDB::bind_method(D_METHOD("get_position"), &KinematicCollision3D::get_position); + ClassDB::bind_method(D_METHOD("get_normal"), &KinematicCollision3D::get_normal); + ClassDB::bind_method(D_METHOD("get_travel"), &KinematicCollision3D::get_travel); + ClassDB::bind_method(D_METHOD("get_remainder"), &KinematicCollision3D::get_remainder); + ClassDB::bind_method(D_METHOD("get_local_shape"), &KinematicCollision3D::get_local_shape); + ClassDB::bind_method(D_METHOD("get_collider"), &KinematicCollision3D::get_collider); + ClassDB::bind_method(D_METHOD("get_collider_id"), &KinematicCollision3D::get_collider_id); + ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicCollision3D::get_collider_shape); + ClassDB::bind_method(D_METHOD("get_collider_shape_index"), &KinematicCollision3D::get_collider_shape_index); + ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicCollision3D::get_collider_velocity); + ClassDB::bind_method(D_METHOD("get_collider_metadata"), &KinematicCollision3D::get_collider_metadata); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position"), "", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "normal"), "", "get_normal"); @@ -1416,35 +1416,35 @@ void KinematicCollision::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NIL, "collider_metadata", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "", "get_collider_metadata"); } -KinematicCollision::KinematicCollision() { +KinematicCollision3D::KinematicCollision3D() { collision.collider_shape = 0; collision.local_shape = 0; - owner = NULL; + owner = nullptr; } /////////////////////////////////////// -bool PhysicalBone::JointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::JointData::_set(const StringName &p_name, const Variant &p_value, RID j) { return false; } -bool PhysicalBone::JointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::JointData::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void PhysicalBone::JointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::JointData::_get_property_list(List<PropertyInfo> *p_list) const { } -void PhysicalBone::apply_central_impulse(const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); +void PhysicalBone3D::apply_central_impulse(const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_central_impulse(get_rid(), p_impulse); } -void PhysicalBone::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { - PhysicsServer::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); +void PhysicalBone3D::apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse) { + PhysicsServer3D::get_singleton()->body_apply_impulse(get_rid(), p_pos, p_impulse); } -void PhysicalBone::reset_physics_simulation_state() { +void PhysicalBone3D::reset_physics_simulation_state() { if (simulate_physics) { _start_physics_simulation(); } else { @@ -1452,7 +1452,7 @@ void PhysicalBone::reset_physics_simulation_state() { } } -void PhysicalBone::reset_to_rest_position() { +void PhysicalBone3D::reset_to_rest_position() { if (parent_skeleton) { if (-1 == bone_id) { set_global_transform(parent_skeleton->get_global_transform() * body_offset); @@ -1462,7 +1462,7 @@ void PhysicalBone::reset_to_rest_position() { } } -bool PhysicalBone::PinJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::PinJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1470,17 +1470,17 @@ bool PhysicalBone::PinJointData::_set(const StringName &p_name, const Variant &p if ("joint_constraints/bias" == p_name) { bias = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PIN_JOINT_BIAS, bias); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_BIAS, bias); } else if ("joint_constraints/damping" == p_name) { damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PIN_JOINT_DAMPING, damping); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_DAMPING, damping); } else if ("joint_constraints/impulse_clamp" == p_name) { impulse_clamp = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PIN_JOINT_IMPULSE_CLAMP, impulse_clamp); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP, impulse_clamp); } else { return false; @@ -1489,7 +1489,7 @@ bool PhysicalBone::PinJointData::_set(const StringName &p_name, const Variant &p return true; } -bool PhysicalBone::PinJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::PinJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1507,7 +1507,7 @@ bool PhysicalBone::PinJointData::_get(const StringName &p_name, Variant &r_ret) return true; } -void PhysicalBone::PinJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::PinJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01")); @@ -1515,7 +1515,7 @@ void PhysicalBone::PinJointData::_get_property_list(List<PropertyInfo> *p_list) p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/impulse_clamp", PROPERTY_HINT_RANGE, "0.0,64.0,0.01")); } -bool PhysicalBone::ConeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::ConeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1523,27 +1523,27 @@ bool PhysicalBone::ConeJointData::_set(const StringName &p_name, const Variant & if ("joint_constraints/swing_span" == p_name) { swing_span = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN, swing_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN, swing_span); } else if ("joint_constraints/twist_span" == p_name) { twist_span = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN, twist_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN, twist_span); } else if ("joint_constraints/bias" == p_name) { bias = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_BIAS, bias); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_BIAS, bias); } else if ("joint_constraints/softness" == p_name) { softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_SOFTNESS, softness); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS, softness); } else if ("joint_constraints/relaxation" == p_name) { relaxation = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::CONE_TWIST_JOINT_RELAXATION, relaxation); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION, relaxation); } else { return false; @@ -1552,7 +1552,7 @@ bool PhysicalBone::ConeJointData::_set(const StringName &p_name, const Variant & return true; } -bool PhysicalBone::ConeJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::ConeJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1574,7 +1574,7 @@ bool PhysicalBone::ConeJointData::_get(const StringName &p_name, Variant &r_ret) return true; } -void PhysicalBone::ConeJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::ConeJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/swing_span", PROPERTY_HINT_RANGE, "-180,180,0.01")); @@ -1584,7 +1584,7 @@ void PhysicalBone::ConeJointData::_get_property_list(List<PropertyInfo> *p_list) p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/relaxation", PROPERTY_HINT_RANGE, "0.01,16.0,0.01")); } -bool PhysicalBone::HingeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::HingeJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1592,32 +1592,32 @@ bool PhysicalBone::HingeJointData::_set(const StringName &p_name, const Variant if ("joint_constraints/angular_limit_enabled" == p_name) { angular_limit_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_flag(j, PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT, angular_limit_enabled); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(j, PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, angular_limit_enabled); } else if ("joint_constraints/angular_limit_upper" == p_name) { angular_limit_upper = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_UPPER, angular_limit_upper); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, angular_limit_upper); } else if ("joint_constraints/angular_limit_lower" == p_name) { angular_limit_lower = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_LOWER, angular_limit_lower); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, angular_limit_lower); } else if ("joint_constraints/angular_limit_bias" == p_name) { angular_limit_bias = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_BIAS, angular_limit_bias); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, angular_limit_bias); } else if ("joint_constraints/angular_limit_softness" == p_name) { angular_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS, angular_limit_softness); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, angular_limit_softness); } else if ("joint_constraints/angular_limit_relaxation" == p_name) { angular_limit_relaxation = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION, angular_limit_relaxation); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, angular_limit_relaxation); } else { return false; @@ -1626,7 +1626,7 @@ bool PhysicalBone::HingeJointData::_set(const StringName &p_name, const Variant return true; } -bool PhysicalBone::HingeJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::HingeJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1650,7 +1650,7 @@ bool PhysicalBone::HingeJointData::_get(const StringName &p_name, Variant &r_ret return true; } -void PhysicalBone::HingeJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::HingeJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::BOOL, "joint_constraints/angular_limit_enabled")); @@ -1661,7 +1661,7 @@ void PhysicalBone::HingeJointData::_get_property_list(List<PropertyInfo> *p_list p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/angular_limit_relaxation", PROPERTY_HINT_RANGE, "0.01,16,0.01")); } -bool PhysicalBone::SliderJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::SliderJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1669,52 +1669,52 @@ bool PhysicalBone::SliderJointData::_set(const StringName &p_name, const Variant if ("joint_constraints/linear_limit_upper" == p_name) { linear_limit_upper = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER, linear_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, linear_limit_upper); } else if ("joint_constraints/linear_limit_lower" == p_name) { linear_limit_lower = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER, linear_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, linear_limit_lower); } else if ("joint_constraints/linear_limit_softness" == p_name) { linear_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, linear_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, linear_limit_softness); } else if ("joint_constraints/linear_limit_restitution" == p_name) { linear_limit_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, linear_limit_restitution); } else if ("joint_constraints/linear_limit_damping" == p_name) { linear_limit_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, linear_limit_restitution); } else if ("joint_constraints/angular_limit_upper" == p_name) { angular_limit_upper = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, angular_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, angular_limit_upper); } else if ("joint_constraints/angular_limit_lower" == p_name) { angular_limit_lower = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, angular_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, angular_limit_lower); } else if ("joint_constraints/angular_limit_softness" == p_name) { angular_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); } else if ("joint_constraints/angular_limit_restitution" == p_name) { angular_limit_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, angular_limit_softness); } else if ("joint_constraints/angular_limit_damping" == p_name) { angular_limit_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, angular_limit_damping); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, angular_limit_damping); } else { return false; @@ -1723,7 +1723,7 @@ bool PhysicalBone::SliderJointData::_set(const StringName &p_name, const Variant return true; } -bool PhysicalBone::SliderJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::SliderJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1755,7 +1755,7 @@ bool PhysicalBone::SliderJointData::_get(const StringName &p_name, Variant &r_re return true; } -void PhysicalBone::SliderJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::SliderJointData::_get_property_list(List<PropertyInfo> *p_list) const { JointData::_get_property_list(p_list); p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/linear_limit_upper")); @@ -1771,7 +1771,7 @@ void PhysicalBone::SliderJointData::_get_property_list(List<PropertyInfo> *p_lis p_list->push_back(PropertyInfo(Variant::FLOAT, "joint_constraints/angular_limit_damping", PROPERTY_HINT_RANGE, "0,16.0,0.01")); } -bool PhysicalBone::SixDOFJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { +bool PhysicalBone3D::SixDOFJointData::_set(const StringName &p_name, const Variant &p_value, RID j) { if (JointData::_set(p_name, p_value, j)) { return true; } @@ -1797,107 +1797,107 @@ bool PhysicalBone::SixDOFJointData::_set(const StringName &p_name, const Variant if ("linear_limit_enabled" == var_name) { axis_data[axis].linear_limit_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, axis_data[axis].linear_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, axis_data[axis].linear_limit_enabled); } else if ("linear_limit_upper" == var_name) { axis_data[axis].linear_limit_upper = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT, axis_data[axis].linear_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, axis_data[axis].linear_limit_upper); } else if ("linear_limit_lower" == var_name) { axis_data[axis].linear_limit_lower = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT, axis_data[axis].linear_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, axis_data[axis].linear_limit_lower); } else if ("linear_limit_softness" == var_name) { axis_data[axis].linear_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, axis_data[axis].linear_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, axis_data[axis].linear_limit_softness); } else if ("linear_spring_enabled" == var_name) { axis_data[axis].linear_spring_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, axis_data[axis].linear_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, axis_data[axis].linear_spring_enabled); } else if ("linear_spring_stiffness" == var_name) { axis_data[axis].linear_spring_stiffness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, axis_data[axis].linear_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, axis_data[axis].linear_spring_stiffness); } else if ("linear_spring_damping" == var_name) { axis_data[axis].linear_spring_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING, axis_data[axis].linear_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, axis_data[axis].linear_spring_damping); } else if ("linear_equilibrium_point" == var_name) { axis_data[axis].linear_equilibrium_point = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].linear_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].linear_equilibrium_point); } else if ("linear_restitution" == var_name) { axis_data[axis].linear_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, axis_data[axis].linear_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, axis_data[axis].linear_restitution); } else if ("linear_damping" == var_name) { axis_data[axis].linear_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, axis_data[axis].linear_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, axis_data[axis].linear_damping); } else if ("angular_limit_enabled" == var_name) { axis_data[axis].angular_limit_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, axis_data[axis].angular_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, axis_data[axis].angular_limit_enabled); } else if ("angular_limit_upper" == var_name) { axis_data[axis].angular_limit_upper = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, axis_data[axis].angular_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, axis_data[axis].angular_limit_upper); } else if ("angular_limit_lower" == var_name) { axis_data[axis].angular_limit_lower = Math::deg2rad(real_t(p_value)); if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, axis_data[axis].angular_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, axis_data[axis].angular_limit_lower); } else if ("angular_limit_softness" == var_name) { axis_data[axis].angular_limit_softness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, axis_data[axis].angular_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, axis_data[axis].angular_limit_softness); } else if ("angular_restitution" == var_name) { axis_data[axis].angular_restitution = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION, axis_data[axis].angular_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, axis_data[axis].angular_restitution); } else if ("angular_damping" == var_name) { axis_data[axis].angular_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING, axis_data[axis].angular_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, axis_data[axis].angular_damping); } else if ("erp" == var_name) { axis_data[axis].erp = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_ERP, axis_data[axis].erp); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, axis_data[axis].erp); } else if ("angular_spring_enabled" == var_name) { axis_data[axis].angular_spring_enabled = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, axis_data[axis].angular_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, axis, PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, axis_data[axis].angular_spring_enabled); } else if ("angular_spring_stiffness" == var_name) { axis_data[axis].angular_spring_stiffness = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, axis_data[axis].angular_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, axis_data[axis].angular_spring_stiffness); } else if ("angular_spring_damping" == var_name) { axis_data[axis].angular_spring_damping = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, axis_data[axis].angular_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, axis_data[axis].angular_spring_damping); } else if ("angular_equilibrium_point" == var_name) { axis_data[axis].angular_equilibrium_point = p_value; if (j.is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].angular_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, axis, PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, axis_data[axis].angular_equilibrium_point); } else { return false; @@ -1906,7 +1906,7 @@ bool PhysicalBone::SixDOFJointData::_set(const StringName &p_name, const Variant return true; } -bool PhysicalBone::SixDOFJointData::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::SixDOFJointData::_get(const StringName &p_name, Variant &r_ret) const { if (JointData::_get(p_name, r_ret)) { return true; } @@ -1978,7 +1978,7 @@ bool PhysicalBone::SixDOFJointData::_get(const StringName &p_name, Variant &r_re return true; } -void PhysicalBone::SixDOFJointData::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::SixDOFJointData::_get_property_list(List<PropertyInfo> *p_list) const { const StringName axis_names[] = { "x", "y", "z" }; for (int i = 0; i < 3; ++i) { p_list->push_back(PropertyInfo(Variant::BOOL, "joint_constraints/" + axis_names[i] + "/linear_limit_enabled")); @@ -2005,7 +2005,7 @@ void PhysicalBone::SixDOFJointData::_get_property_list(List<PropertyInfo> *p_lis } } -bool PhysicalBone::_set(const StringName &p_name, const Variant &p_value) { +bool PhysicalBone3D::_set(const StringName &p_name, const Variant &p_value) { if (p_name == "bone_name") { set_bone_name(p_value); return true; @@ -2024,7 +2024,7 @@ bool PhysicalBone::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool PhysicalBone::_get(const StringName &p_name, Variant &r_ret) const { +bool PhysicalBone3D::_get(const StringName &p_name, Variant &r_ret) const { if (p_name == "bone_name") { r_ret = get_bone_name(); return true; @@ -2037,9 +2037,9 @@ bool PhysicalBone::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void PhysicalBone::_get_property_list(List<PropertyInfo> *p_list) const { +void PhysicalBone3D::_get_property_list(List<PropertyInfo> *p_list) const { - Skeleton *parent = find_skeleton_parent(get_parent()); + Skeleton3D *parent = find_skeleton_parent(get_parent()); if (parent) { @@ -2061,7 +2061,7 @@ void PhysicalBone::_get_property_list(List<PropertyInfo> *p_list) const { } } -void PhysicalBone::_notification(int p_what) { +void PhysicalBone3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: parent_skeleton = find_skeleton_parent(get_parent()); @@ -2078,9 +2078,9 @@ void PhysicalBone::_notification(int p_what) { parent_skeleton->unbind_physical_bone_from_bone(bone_id); } } - parent_skeleton = NULL; + parent_skeleton = nullptr; if (joint.is_valid()) { - PhysicsServer::get_singleton()->free(joint); + PhysicsServer3D::get_singleton()->free(joint); joint = RID(); } break; @@ -2093,7 +2093,7 @@ void PhysicalBone::_notification(int p_what) { } } -void PhysicalBone::_direct_state_changed(Object *p_state) { +void PhysicalBone3D::_direct_state_changed(Object *p_state) { if (!simulate_physics || !_internal_simulate_physics) { return; @@ -2101,12 +2101,12 @@ void PhysicalBone::_direct_state_changed(Object *p_state) { /// Update bone transform - PhysicsDirectBodyState *state; + PhysicsDirectBodyState3D *state; #ifdef DEBUG_ENABLED - state = Object::cast_to<PhysicsDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); #else - state = (PhysicsDirectBodyState *)p_state; //trust it + state = (PhysicsDirectBodyState3D *)p_state; //trust it #endif Transform global_transform(state->get_transform()); @@ -2123,45 +2123,63 @@ void PhysicalBone::_direct_state_changed(Object *p_state) { } } -void PhysicalBone::_bind_methods() { - ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicalBone::apply_central_impulse); - ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &PhysicalBone::apply_impulse); +void PhysicalBone3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("apply_central_impulse", "impulse"), &PhysicalBone3D::apply_central_impulse); + ClassDB::bind_method(D_METHOD("apply_impulse", "position", "impulse"), &PhysicalBone3D::apply_impulse); - ClassDB::bind_method(D_METHOD("_direct_state_changed"), &PhysicalBone::_direct_state_changed); + ClassDB::bind_method(D_METHOD("_direct_state_changed"), &PhysicalBone3D::_direct_state_changed); - ClassDB::bind_method(D_METHOD("set_joint_type", "joint_type"), &PhysicalBone::set_joint_type); - ClassDB::bind_method(D_METHOD("get_joint_type"), &PhysicalBone::get_joint_type); + ClassDB::bind_method(D_METHOD("set_joint_type", "joint_type"), &PhysicalBone3D::set_joint_type); + ClassDB::bind_method(D_METHOD("get_joint_type"), &PhysicalBone3D::get_joint_type); - ClassDB::bind_method(D_METHOD("set_joint_offset", "offset"), &PhysicalBone::set_joint_offset); - ClassDB::bind_method(D_METHOD("get_joint_offset"), &PhysicalBone::get_joint_offset); + ClassDB::bind_method(D_METHOD("set_joint_offset", "offset"), &PhysicalBone3D::set_joint_offset); + ClassDB::bind_method(D_METHOD("get_joint_offset"), &PhysicalBone3D::get_joint_offset); + ClassDB::bind_method(D_METHOD("set_joint_rotation", "euler"), &PhysicalBone3D::set_joint_rotation); + ClassDB::bind_method(D_METHOD("get_joint_rotation"), &PhysicalBone3D::get_joint_rotation); + ClassDB::bind_method(D_METHOD("set_joint_rotation_degrees", "euler_degrees"), &PhysicalBone3D::set_joint_rotation_degrees); + ClassDB::bind_method(D_METHOD("get_joint_rotation_degrees"), &PhysicalBone3D::get_joint_rotation_degrees); - ClassDB::bind_method(D_METHOD("set_body_offset", "offset"), &PhysicalBone::set_body_offset); - ClassDB::bind_method(D_METHOD("get_body_offset"), &PhysicalBone::get_body_offset); + ClassDB::bind_method(D_METHOD("set_body_offset", "offset"), &PhysicalBone3D::set_body_offset); + ClassDB::bind_method(D_METHOD("get_body_offset"), &PhysicalBone3D::get_body_offset); - ClassDB::bind_method(D_METHOD("get_simulate_physics"), &PhysicalBone::get_simulate_physics); + ClassDB::bind_method(D_METHOD("get_simulate_physics"), &PhysicalBone3D::get_simulate_physics); - ClassDB::bind_method(D_METHOD("is_simulating_physics"), &PhysicalBone::is_simulating_physics); + ClassDB::bind_method(D_METHOD("is_simulating_physics"), &PhysicalBone3D::is_simulating_physics); - ClassDB::bind_method(D_METHOD("get_bone_id"), &PhysicalBone::get_bone_id); + ClassDB::bind_method(D_METHOD("get_bone_id"), &PhysicalBone3D::get_bone_id); - ClassDB::bind_method(D_METHOD("set_mass", "mass"), &PhysicalBone::set_mass); - ClassDB::bind_method(D_METHOD("get_mass"), &PhysicalBone::get_mass); + ClassDB::bind_method(D_METHOD("set_mass", "mass"), &PhysicalBone3D::set_mass); + ClassDB::bind_method(D_METHOD("get_mass"), &PhysicalBone3D::get_mass); - ClassDB::bind_method(D_METHOD("set_weight", "weight"), &PhysicalBone::set_weight); - ClassDB::bind_method(D_METHOD("get_weight"), &PhysicalBone::get_weight); + ClassDB::bind_method(D_METHOD("set_weight", "weight"), &PhysicalBone3D::set_weight); + ClassDB::bind_method(D_METHOD("get_weight"), &PhysicalBone3D::get_weight); - ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicalBone::set_friction); - ClassDB::bind_method(D_METHOD("get_friction"), &PhysicalBone::get_friction); + ClassDB::bind_method(D_METHOD("set_friction", "friction"), &PhysicalBone3D::set_friction); + ClassDB::bind_method(D_METHOD("get_friction"), &PhysicalBone3D::get_friction); - ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &PhysicalBone::set_bounce); - ClassDB::bind_method(D_METHOD("get_bounce"), &PhysicalBone::get_bounce); + ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &PhysicalBone3D::set_bounce); + ClassDB::bind_method(D_METHOD("get_bounce"), &PhysicalBone3D::get_bounce); - ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &PhysicalBone::set_gravity_scale); - ClassDB::bind_method(D_METHOD("get_gravity_scale"), &PhysicalBone::get_gravity_scale); + ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &PhysicalBone3D::set_gravity_scale); + ClassDB::bind_method(D_METHOD("get_gravity_scale"), &PhysicalBone3D::get_gravity_scale); + + ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &PhysicalBone3D::set_linear_damp); + ClassDB::bind_method(D_METHOD("get_linear_damp"), &PhysicalBone3D::get_linear_damp); + + ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &PhysicalBone3D::set_angular_damp); + ClassDB::bind_method(D_METHOD("get_angular_damp"), &PhysicalBone3D::get_angular_damp); + + ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &PhysicalBone3D::set_can_sleep); + ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &PhysicalBone3D::is_able_to_sleep); + + ClassDB::bind_method(D_METHOD("set_axis_lock", "axis", "lock"), &PhysicalBone3D::set_axis_lock); + ClassDB::bind_method(D_METHOD("get_axis_lock", "axis"), &PhysicalBone3D::get_axis_lock); ADD_GROUP("Joint", "joint_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "joint_type", PROPERTY_HINT_ENUM, "None,PinJoint,ConeJoint,HingeJoint,SliderJoint,6DOFJoint"), "set_joint_type", "get_joint_type"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "joint_offset"), "set_joint_offset", "get_joint_offset"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_joint_rotation_degrees", "get_joint_rotation_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "joint_rotation", PROPERTY_HINT_NONE, "", 0), "set_joint_rotation", "get_joint_rotation"); ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "body_offset"), "set_body_offset", "get_body_offset"); @@ -2170,6 +2188,17 @@ void PhysicalBone::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gravity_scale", PROPERTY_HINT_RANGE, "-10,10,0.01"), "set_gravity_scale", "get_gravity_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "linear_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_linear_damp", "get_linear_damp"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "angular_damp", PROPERTY_HINT_RANGE, "-1,100,0.001,or_greater"), "set_angular_damp", "get_angular_damp"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep"); + + ADD_GROUP("Axis Lock", "axis_lock_"); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_linear_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_LINEAR_Z); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_x"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_X); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_y"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Y); + ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "axis_lock_angular_z"), "set_axis_lock", "get_axis_lock", PhysicsServer3D::BODY_AXIS_ANGULAR_Z); BIND_ENUM_CONSTANT(JOINT_TYPE_NONE); BIND_ENUM_CONSTANT(JOINT_TYPE_PIN); @@ -2179,25 +2208,38 @@ void PhysicalBone::_bind_methods() { BIND_ENUM_CONSTANT(JOINT_TYPE_6DOF); } -Skeleton *PhysicalBone::find_skeleton_parent(Node *p_parent) { +Skeleton3D *PhysicalBone3D::find_skeleton_parent(Node *p_parent) { if (!p_parent) { - return NULL; + return nullptr; } - Skeleton *s = Object::cast_to<Skeleton>(p_parent); + Skeleton3D *s = Object::cast_to<Skeleton3D>(p_parent); return s ? s : find_skeleton_parent(p_parent->get_parent()); } -void PhysicalBone::_fix_joint_offset() { +void PhysicalBone3D::_update_joint_offset() { + _fix_joint_offset(); + + set_ignore_transform_notification(true); + reset_to_rest_position(); + set_ignore_transform_notification(false); + +#ifdef TOOLS_ENABLED + if (get_gizmo().is_valid()) + get_gizmo()->redraw(); +#endif +} + +void PhysicalBone3D::_fix_joint_offset() { // Clamp joint origin to bone origin if (parent_skeleton) { joint_offset.origin = body_offset.affine_inverse().origin; } } -void PhysicalBone::_reload_joint() { +void PhysicalBone3D::_reload_joint() { if (joint.is_valid()) { - PhysicsServer::get_singleton()->free(joint); + PhysicsServer3D::get_singleton()->free(joint); joint = RID(); } @@ -2205,7 +2247,7 @@ void PhysicalBone::_reload_joint() { return; } - PhysicalBone *body_a = parent_skeleton->get_physical_bone_parent(bone_id); + PhysicalBone3D *body_a = parent_skeleton->get_physical_bone_parent(bone_id); if (!body_a) { return; } @@ -2217,78 +2259,78 @@ void PhysicalBone::_reload_joint() { switch (get_joint_type()) { case JOINT_TYPE_PIN: { - joint = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(), local_a.origin, get_rid(), joint_offset.origin); + joint = PhysicsServer3D::get_singleton()->joint_create_pin(body_a->get_rid(), local_a.origin, get_rid(), joint_offset.origin); const PinJointData *pjd(static_cast<const PinJointData *>(joint_data)); - PhysicsServer::get_singleton()->pin_joint_set_param(joint, PhysicsServer::PIN_JOINT_BIAS, pjd->bias); - PhysicsServer::get_singleton()->pin_joint_set_param(joint, PhysicsServer::PIN_JOINT_DAMPING, pjd->damping); - PhysicsServer::get_singleton()->pin_joint_set_param(joint, PhysicsServer::PIN_JOINT_IMPULSE_CLAMP, pjd->impulse_clamp); + PhysicsServer3D::get_singleton()->pin_joint_set_param(joint, PhysicsServer3D::PIN_JOINT_BIAS, pjd->bias); + PhysicsServer3D::get_singleton()->pin_joint_set_param(joint, PhysicsServer3D::PIN_JOINT_DAMPING, pjd->damping); + PhysicsServer3D::get_singleton()->pin_joint_set_param(joint, PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP, pjd->impulse_clamp); } break; case JOINT_TYPE_CONE: { - joint = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, get_rid(), joint_offset); const ConeJointData *cjd(static_cast<const ConeJointData *>(joint_data)); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_SWING_SPAN, cjd->swing_span); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_TWIST_SPAN, cjd->twist_span); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_BIAS, cjd->bias); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_SOFTNESS, cjd->softness); - PhysicsServer::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer::CONE_TWIST_JOINT_RELAXATION, cjd->relaxation); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_SWING_SPAN, cjd->swing_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_TWIST_SPAN, cjd->twist_span); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_BIAS, cjd->bias); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_SOFTNESS, cjd->softness); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(joint, PhysicsServer3D::CONE_TWIST_JOINT_RELAXATION, cjd->relaxation); } break; case JOINT_TYPE_HINGE: { - joint = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, get_rid(), joint_offset); const HingeJointData *hjd(static_cast<const HingeJointData *>(joint_data)); - PhysicsServer::get_singleton()->hinge_joint_set_flag(joint, PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT, hjd->angular_limit_enabled); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_UPPER, hjd->angular_limit_upper); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_LOWER, hjd->angular_limit_lower); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_BIAS, hjd->angular_limit_bias); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS, hjd->angular_limit_softness); - PhysicsServer::get_singleton()->hinge_joint_set_param(joint, PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION, hjd->angular_limit_relaxation); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(joint, PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, hjd->angular_limit_enabled); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, hjd->angular_limit_upper); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, hjd->angular_limit_lower); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, hjd->angular_limit_bias); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, hjd->angular_limit_softness); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(joint, PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, hjd->angular_limit_relaxation); } break; case JOINT_TYPE_SLIDER: { - joint = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, get_rid(), joint_offset); const SliderJointData *sjd(static_cast<const SliderJointData *>(joint_data)); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER, sjd->linear_limit_upper); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER, sjd->linear_limit_lower); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, sjd->linear_limit_softness); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, sjd->linear_limit_restitution); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, sjd->linear_limit_restitution); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, sjd->angular_limit_upper); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, sjd->angular_limit_lower); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); - PhysicsServer::get_singleton()->slider_joint_set_param(joint, PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, sjd->angular_limit_damping); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, sjd->linear_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, sjd->linear_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, sjd->linear_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, sjd->linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, sjd->linear_limit_restitution); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, sjd->angular_limit_upper); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, sjd->angular_limit_lower); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, sjd->angular_limit_softness); + PhysicsServer3D::get_singleton()->slider_joint_set_param(joint, PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, sjd->angular_limit_damping); } break; case JOINT_TYPE_6DOF: { - joint = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, get_rid(), joint_offset); + joint = PhysicsServer3D::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, get_rid(), joint_offset); const SixDOFJointData *g6dofjd(static_cast<const SixDOFJointData *>(joint_data)); for (int axis = 0; axis < 3; ++axis) { - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, g6dofjd->axis_data[axis].linear_limit_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT, g6dofjd->axis_data[axis].linear_limit_upper); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT, g6dofjd->axis_data[axis].linear_limit_lower); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].linear_limit_softness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, g6dofjd->axis_data[axis].linear_spring_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].linear_spring_stiffness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING, g6dofjd->axis_data[axis].linear_spring_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].linear_equilibrium_point); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, g6dofjd->axis_data[axis].linear_restitution); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, g6dofjd->axis_data[axis].linear_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, g6dofjd->axis_data[axis].angular_limit_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, g6dofjd->axis_data[axis].angular_limit_upper); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, g6dofjd->axis_data[axis].angular_limit_lower); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].angular_limit_softness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION, g6dofjd->axis_data[axis].angular_restitution); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING, g6dofjd->axis_data[axis].angular_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_ERP, g6dofjd->axis_data[axis].erp); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, g6dofjd->axis_data[axis].angular_spring_enabled); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].angular_spring_stiffness); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, g6dofjd->axis_data[axis].angular_spring_damping); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].angular_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, g6dofjd->axis_data[axis].linear_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, g6dofjd->axis_data[axis].linear_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, g6dofjd->axis_data[axis].linear_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].linear_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, g6dofjd->axis_data[axis].linear_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].linear_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, g6dofjd->axis_data[axis].linear_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].linear_equilibrium_point); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, g6dofjd->axis_data[axis].linear_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, g6dofjd->axis_data[axis].linear_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, g6dofjd->axis_data[axis].angular_limit_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, g6dofjd->axis_data[axis].angular_limit_upper); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, g6dofjd->axis_data[axis].angular_limit_lower); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, g6dofjd->axis_data[axis].angular_limit_softness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, g6dofjd->axis_data[axis].angular_restitution); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, g6dofjd->axis_data[axis].angular_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, g6dofjd->axis_data[axis].erp); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, g6dofjd->axis_data[axis].angular_spring_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, g6dofjd->axis_data[axis].angular_spring_stiffness); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, g6dofjd->axis_data[axis].angular_spring_damping); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(joint, static_cast<Vector3::Axis>(axis), PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, g6dofjd->axis_data[axis].angular_equilibrium_point); } } break; @@ -2297,43 +2339,43 @@ void PhysicalBone::_reload_joint() { } } -void PhysicalBone::_on_bone_parent_changed() { +void PhysicalBone3D::_on_bone_parent_changed() { _reload_joint(); } -void PhysicalBone::_set_gizmo_move_joint(bool p_move_joint) { +void PhysicalBone3D::_set_gizmo_move_joint(bool p_move_joint) { #ifdef TOOLS_ENABLED gizmo_move_joint = p_move_joint; - SpatialEditor::get_singleton()->update_transform_gizmo(); + Node3DEditor::get_singleton()->update_transform_gizmo(); #endif } #ifdef TOOLS_ENABLED -Transform PhysicalBone::get_global_gizmo_transform() const { +Transform PhysicalBone3D::get_global_gizmo_transform() const { return gizmo_move_joint ? get_global_transform() * joint_offset : get_global_transform(); } -Transform PhysicalBone::get_local_gizmo_transform() const { +Transform PhysicalBone3D::get_local_gizmo_transform() const { return gizmo_move_joint ? get_transform() * joint_offset : get_transform(); } #endif -const PhysicalBone::JointData *PhysicalBone::get_joint_data() const { +const PhysicalBone3D::JointData *PhysicalBone3D::get_joint_data() const { return joint_data; } -Skeleton *PhysicalBone::find_skeleton_parent() { +Skeleton3D *PhysicalBone3D::find_skeleton_parent() { return find_skeleton_parent(this); } -void PhysicalBone::set_joint_type(JointType p_joint_type) { +void PhysicalBone3D::set_joint_type(JointType p_joint_type) { if (p_joint_type == get_joint_type()) return; if (joint_data) memdelete(joint_data); - joint_data = NULL; + joint_data = nullptr; switch (p_joint_type) { case JOINT_TYPE_PIN: joint_data = memnew(PinJointData); @@ -2363,50 +2405,52 @@ void PhysicalBone::set_joint_type(JointType p_joint_type) { #endif } -PhysicalBone::JointType PhysicalBone::get_joint_type() const { +PhysicalBone3D::JointType PhysicalBone3D::get_joint_type() const { return joint_data ? joint_data->get_joint_type() : JOINT_TYPE_NONE; } -void PhysicalBone::set_joint_offset(const Transform &p_offset) { +void PhysicalBone3D::set_joint_offset(const Transform &p_offset) { joint_offset = p_offset; - _fix_joint_offset(); - - set_ignore_transform_notification(true); - reset_to_rest_position(); - set_ignore_transform_notification(false); + _update_joint_offset(); + _change_notify("joint_rotation_degrees"); +} -#ifdef TOOLS_ENABLED - if (get_gizmo().is_valid()) - get_gizmo()->redraw(); -#endif +const Transform &PhysicalBone3D::get_joint_offset() const { + return joint_offset; } -const Transform &PhysicalBone::get_body_offset() const { - return body_offset; +void PhysicalBone3D::set_joint_rotation(const Vector3 &p_euler_rad) { + joint_offset.basis.set_euler_scale(p_euler_rad, joint_offset.basis.get_scale()); + + _update_joint_offset(); + _change_notify("joint_offset"); } -void PhysicalBone::set_body_offset(const Transform &p_offset) { - body_offset = p_offset; - body_offset_inverse = body_offset.affine_inverse(); +Vector3 PhysicalBone3D::get_joint_rotation() const { + return joint_offset.basis.get_rotation(); +} - _fix_joint_offset(); +void PhysicalBone3D::set_joint_rotation_degrees(const Vector3 &p_euler_deg) { + set_joint_rotation(p_euler_deg * Math_PI / 180.0); +} - set_ignore_transform_notification(true); - reset_to_rest_position(); - set_ignore_transform_notification(false); +Vector3 PhysicalBone3D::get_joint_rotation_degrees() const { + return get_joint_rotation() * 180.0 / Math_PI; +} -#ifdef TOOLS_ENABLED - if (get_gizmo().is_valid()) - get_gizmo()->redraw(); -#endif +const Transform &PhysicalBone3D::get_body_offset() const { + return body_offset; } -const Transform &PhysicalBone::get_joint_offset() const { - return joint_offset; +void PhysicalBone3D::set_body_offset(const Transform &p_offset) { + body_offset = p_offset; + body_offset_inverse = body_offset.affine_inverse(); + + _update_joint_offset(); } -void PhysicalBone::set_simulate_physics(bool p_simulate) { +void PhysicalBone3D::set_simulate_physics(bool p_simulate) { if (simulate_physics == p_simulate) { return; } @@ -2415,15 +2459,15 @@ void PhysicalBone::set_simulate_physics(bool p_simulate) { reset_physics_simulation_state(); } -bool PhysicalBone::get_simulate_physics() { +bool PhysicalBone3D::get_simulate_physics() { return simulate_physics; } -bool PhysicalBone::is_simulating_physics() { +bool PhysicalBone3D::is_simulating_physics() { return _internal_simulate_physics; } -void PhysicalBone::set_bone_name(const String &p_name) { +void PhysicalBone3D::set_bone_name(const String &p_name) { bone_name = p_name; bone_id = -1; @@ -2432,77 +2476,114 @@ void PhysicalBone::set_bone_name(const String &p_name) { reset_to_rest_position(); } -const String &PhysicalBone::get_bone_name() const { +const String &PhysicalBone3D::get_bone_name() const { return bone_name; } -void PhysicalBone::set_mass(real_t p_mass) { +void PhysicalBone3D::set_mass(real_t p_mass) { ERR_FAIL_COND(p_mass <= 0); mass = p_mass; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_MASS, mass); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_MASS, mass); } -real_t PhysicalBone::get_mass() const { +real_t PhysicalBone3D::get_mass() const { return mass; } -void PhysicalBone::set_weight(real_t p_weight) { +void PhysicalBone3D::set_weight(real_t p_weight) { set_mass(p_weight / real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8))); } -real_t PhysicalBone::get_weight() const { +real_t PhysicalBone3D::get_weight() const { return mass * real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8)); } -void PhysicalBone::set_friction(real_t p_friction) { +void PhysicalBone3D::set_friction(real_t p_friction) { ERR_FAIL_COND(p_friction < 0 || p_friction > 1); friction = p_friction; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_FRICTION, friction); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_FRICTION, friction); } -real_t PhysicalBone::get_friction() const { +real_t PhysicalBone3D::get_friction() const { return friction; } -void PhysicalBone::set_bounce(real_t p_bounce) { +void PhysicalBone3D::set_bounce(real_t p_bounce) { ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1); bounce = p_bounce; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_BOUNCE, bounce); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_BOUNCE, bounce); } -real_t PhysicalBone::get_bounce() const { +real_t PhysicalBone3D::get_bounce() const { return bounce; } -void PhysicalBone::set_gravity_scale(real_t p_gravity_scale) { +void PhysicalBone3D::set_gravity_scale(real_t p_gravity_scale) { gravity_scale = p_gravity_scale; - PhysicsServer::get_singleton()->body_set_param(get_rid(), PhysicsServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale); + PhysicsServer3D::get_singleton()->body_set_param(get_rid(), PhysicsServer3D::BODY_PARAM_GRAVITY_SCALE, gravity_scale); } -real_t PhysicalBone::get_gravity_scale() const { +real_t PhysicalBone3D::get_gravity_scale() const { return gravity_scale; } -PhysicalBone::PhysicalBone() : - PhysicsBody(PhysicsServer::BODY_MODE_STATIC), +void PhysicalBone3D::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 PhysicalBone3D::get_linear_damp() const { + return linear_damp; +} + +void PhysicalBone3D::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 PhysicalBone3D::get_angular_damp() const { + return angular_damp; +} + +void PhysicalBone3D::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 PhysicalBone3D::is_able_to_sleep() const { + return can_sleep; +} + +void PhysicalBone3D::set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock) { + PhysicsServer3D::get_singleton()->body_set_axis_lock(get_rid(), p_axis, p_lock); +} + +bool PhysicalBone3D::get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const { + return PhysicsServer3D::get_singleton()->body_is_axis_locked(get_rid(), p_axis); +} + +PhysicalBone3D::PhysicalBone3D() : + PhysicsBody3D(PhysicsServer3D::BODY_MODE_STATIC), #ifdef TOOLS_ENABLED gizmo_move_joint(false), #endif - joint_data(NULL), - parent_skeleton(NULL), + joint_data(nullptr), + parent_skeleton(nullptr), simulate_physics(false), _internal_simulate_physics(false), bone_id(-1), @@ -2510,17 +2591,20 @@ PhysicalBone::PhysicalBone() : bounce(0), mass(1), friction(1), - gravity_scale(1) { + gravity_scale(1), + linear_damp(-1), + angular_damp(-1), + can_sleep(true) { reset_physics_simulation_state(); } -PhysicalBone::~PhysicalBone() { +PhysicalBone3D::~PhysicalBone3D() { if (joint_data) memdelete(joint_data); } -void PhysicalBone::update_bone_id() { +void PhysicalBone3D::update_bone_id() { if (!parent_skeleton) { return; } @@ -2543,7 +2627,7 @@ void PhysicalBone::update_bone_id() { } } -void PhysicalBone::update_offset() { +void PhysicalBone3D::update_offset() { #ifdef TOOLS_ENABLED if (parent_skeleton) { @@ -2561,34 +2645,34 @@ void PhysicalBone::update_offset() { #endif } -void PhysicalBone::_start_physics_simulation() { +void PhysicalBone3D::_start_physics_simulation() { if (_internal_simulate_physics || !parent_skeleton) { return; } reset_to_rest_position(); - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_RIGID); - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_RIGID); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); set_as_toplevel(true); _internal_simulate_physics = true; } -void PhysicalBone::_stop_physics_simulation() { +void PhysicalBone3D::_stop_physics_simulation() { if (!parent_skeleton) { return; } if (parent_skeleton->get_animate_physical_bones()) { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_KINEMATIC); - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_KINEMATIC); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), get_collision_layer()); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), get_collision_mask()); } else { - PhysicsServer::get_singleton()->body_set_mode(get_rid(), PhysicsServer::BODY_MODE_STATIC); - PhysicsServer::get_singleton()->body_set_collision_layer(get_rid(), 0); - PhysicsServer::get_singleton()->body_set_collision_mask(get_rid(), 0); + PhysicsServer3D::get_singleton()->body_set_mode(get_rid(), PhysicsServer3D::BODY_MODE_STATIC); + PhysicsServer3D::get_singleton()->body_set_collision_layer(get_rid(), 0); + PhysicsServer3D::get_singleton()->body_set_collision_mask(get_rid(), 0); } if (_internal_simulate_physics) { - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), NULL, ""); + PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), nullptr, ""); parent_skeleton->set_bone_global_pose_override(bone_id, Transform(), 0.0, false); set_as_toplevel(false); _internal_simulate_physics = false; diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body_3d.h index 90de1ffce6..0e719f5108 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* physics_body.h */ +/* physics_body_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,18 +28,18 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef PHYSICS_BODY__H -#define PHYSICS_BODY__H +#ifndef PHYSICS_BODY_3D_H +#define PHYSICS_BODY_3D_H #include "core/vset.h" -#include "scene/3d/collision_object.h" +#include "scene/3d/collision_object_3d.h" #include "scene/resources/physics_material.h" -#include "servers/physics_server.h" -#include "skeleton.h" +#include "servers/physics_server_3d.h" +#include "skeleton_3d.h" -class PhysicsBody : public CollisionObject { +class PhysicsBody3D : public CollisionObject3D { - GDCLASS(PhysicsBody, CollisionObject); + GDCLASS(PhysicsBody3D, CollisionObject3D); uint32_t collision_layer; uint32_t collision_mask; @@ -49,7 +49,7 @@ class PhysicsBody : public CollisionObject { protected: static void _bind_methods(); - PhysicsBody(PhysicsServer::BodyMode p_mode); + PhysicsBody3D(PhysicsServer3D::BodyMode p_mode); public: virtual Vector3 get_linear_velocity() const; @@ -68,16 +68,16 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; - Array get_collision_exceptions(); + TypedArray<PhysicsBody3D> get_collision_exceptions(); void add_collision_exception_with(Node *p_node); //must be physicsbody void remove_collision_exception_with(Node *p_node); - PhysicsBody(); + PhysicsBody3D(); }; -class StaticBody : public PhysicsBody { +class StaticBody3D : public PhysicsBody3D { - GDCLASS(StaticBody, PhysicsBody); + GDCLASS(StaticBody3D, PhysicsBody3D); Vector3 constant_linear_velocity; Vector3 constant_angular_velocity; @@ -97,16 +97,16 @@ public: Vector3 get_constant_linear_velocity() const; Vector3 get_constant_angular_velocity() const; - StaticBody(); - ~StaticBody(); + StaticBody3D(); + ~StaticBody3D(); private: void _reload_physics_characteristics(); }; -class RigidBody : public PhysicsBody { +class RigidBody3D : public PhysicsBody3D { - GDCLASS(RigidBody, PhysicsBody); + GDCLASS(RigidBody3D, PhysicsBody3D); public: enum Mode { @@ -118,7 +118,7 @@ public: protected: bool can_sleep; - PhysicsDirectBodyState *state; + PhysicsDirectBodyState3D *state; Mode mode; real_t mass; @@ -156,7 +156,7 @@ protected: tagged = false; } }; - struct RigidBody_RemoveAction { + struct RigidBody3D_RemoveAction { ObjectID body_id; ShapePair pair; @@ -234,8 +234,8 @@ public: void set_use_continuous_collision_detection(bool p_enable); bool is_using_continuous_collision_detection() const; - void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock); - bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const; + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); + bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const; Array get_colliding_bodies() const; @@ -249,20 +249,20 @@ public: virtual String get_configuration_warning() const; - RigidBody(); - ~RigidBody(); + RigidBody3D(); + ~RigidBody3D(); private: void _reload_physics_characteristics(); }; -VARIANT_ENUM_CAST(RigidBody::Mode); +VARIANT_ENUM_CAST(RigidBody3D::Mode); -class KinematicCollision; +class KinematicCollision3D; -class KinematicBody : public PhysicsBody { +class KinematicBody3D : public PhysicsBody3D { - GDCLASS(KinematicBody, PhysicsBody); + GDCLASS(KinematicBody3D, PhysicsBody3D); public: struct Collision { @@ -293,13 +293,13 @@ private: bool on_ceiling; bool on_wall; Vector<Collision> colliders; - Vector<Ref<KinematicCollision>> slide_colliders; - Ref<KinematicCollision> motion_cache; + Vector<Ref<KinematicCollision3D>> slide_colliders; + Ref<KinematicCollision3D> motion_cache; - _FORCE_INLINE_ bool _ignores_mode(PhysicsServer::BodyMode) const; + _FORCE_INLINE_ bool _ignores_mode(PhysicsServer3D::BodyMode) const; - Ref<KinematicCollision> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false); - Ref<KinematicCollision> _get_slide_collision(int p_bounce); + Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false); + Ref<KinematicCollision3D> _get_slide_collision(int p_bounce); protected: void _notification(int p_what); @@ -316,8 +316,8 @@ public: bool separate_raycast_shapes(bool p_infinite_inertia, Collision &r_collision); - void set_axis_lock(PhysicsServer::BodyAxis p_axis, bool p_lock); - bool get_axis_lock(PhysicsServer::BodyAxis p_axis) const; + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); + bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const; void set_safe_margin(float p_margin); float get_safe_margin() const; @@ -333,17 +333,17 @@ public: int get_slide_count() const; Collision get_slide_collision(int p_bounce) const; - KinematicBody(); - ~KinematicBody(); + KinematicBody3D(); + ~KinematicBody3D(); }; -class KinematicCollision : public Reference { +class KinematicCollision3D : public Reference { - GDCLASS(KinematicCollision, Reference); + GDCLASS(KinematicCollision3D, Reference); - KinematicBody *owner; - friend class KinematicBody; - KinematicBody::Collision collision; + KinematicBody3D *owner; + friend class KinematicBody3D; + KinematicBody3D::Collision collision; protected: static void _bind_methods(); @@ -361,12 +361,12 @@ public: Vector3 get_collider_velocity() const; Variant get_collider_metadata() const; - KinematicCollision(); + KinematicCollision3D(); }; -class PhysicalBone : public PhysicsBody { +class PhysicalBone3D : public PhysicsBody3D { - GDCLASS(PhysicalBone, PhysicsBody); + GDCLASS(PhysicalBone3D, PhysicsBody3D); public: enum JointType { @@ -381,7 +381,7 @@ public: struct JointData { virtual JointType get_joint_type() { return JOINT_TYPE_NONE; } - /// "j" is used to set the parameter inside the PhysicsServer + /// "j" is used to set the parameter inside the PhysicsServer3D virtual bool _set(const StringName &p_name, const Variant &p_value, RID j = RID()); virtual bool _get(const StringName &p_name, Variant &r_ret) const; virtual void _get_property_list(List<PropertyInfo> *p_list) const; @@ -550,7 +550,7 @@ private: Transform joint_offset; RID joint; - Skeleton *parent_skeleton; + Skeleton3D *parent_skeleton; Transform body_offset; Transform body_offset_inverse; bool simulate_physics; @@ -562,6 +562,9 @@ private: real_t mass; real_t friction; real_t gravity_scale; + real_t linear_damp; + real_t angular_damp; + bool can_sleep; protected: bool _set(const StringName &p_name, const Variant &p_value); @@ -573,8 +576,9 @@ protected: static void _bind_methods(); private: - static Skeleton *find_skeleton_parent(Node *p_parent); + static Skeleton3D *find_skeleton_parent(Node *p_parent); + void _update_joint_offset(); void _fix_joint_offset(); void _reload_joint(); @@ -589,7 +593,7 @@ public: #endif const JointData *get_joint_data() const; - Skeleton *find_skeleton_parent(); + Skeleton3D *find_skeleton_parent(); int get_bone_id() const { return bone_id; } @@ -599,6 +603,12 @@ public: void set_joint_offset(const Transform &p_offset); const Transform &get_joint_offset() const; + void set_joint_rotation(const Vector3 &p_euler_rad); + Vector3 get_joint_rotation() const; + + void set_joint_rotation_degrees(const Vector3 &p_euler_deg); + Vector3 get_joint_rotation_degrees() const; + void set_body_offset(const Transform &p_offset); const Transform &get_body_offset() const; @@ -624,14 +634,26 @@ public: void set_gravity_scale(real_t p_gravity_scale); real_t get_gravity_scale() const; + void set_linear_damp(real_t p_linear_damp); + real_t get_linear_damp() const; + + void set_angular_damp(real_t p_angular_damp); + real_t get_angular_damp() const; + + void set_can_sleep(bool p_active); + bool is_able_to_sleep() const; + + void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); + bool get_axis_lock(PhysicsServer3D::BodyAxis p_axis) const; + void apply_central_impulse(const Vector3 &p_impulse); void apply_impulse(const Vector3 &p_pos, const Vector3 &p_impulse); void reset_physics_simulation_state(); void reset_to_rest_position(); - PhysicalBone(); - ~PhysicalBone(); + PhysicalBone3D(); + ~PhysicalBone3D(); private: void update_bone_id(); @@ -641,6 +663,6 @@ private: void _stop_physics_simulation(); }; -VARIANT_ENUM_CAST(PhysicalBone::JointType); +VARIANT_ENUM_CAST(PhysicalBone3D::JointType); #endif // PHYSICS_BODY__H diff --git a/scene/3d/physics_joint.h b/scene/3d/physics_joint.h deleted file mode 100644 index d03dbac392..0000000000 --- a/scene/3d/physics_joint.h +++ /dev/null @@ -1,343 +0,0 @@ -/*************************************************************************/ -/* physics_joint.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 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 PHYSICS_JOINT_H -#define PHYSICS_JOINT_H - -#include "scene/3d/physics_body.h" -#include "scene/3d/spatial.h" - -class Joint : public Spatial { - - GDCLASS(Joint, Spatial); - - RID ba, bb; - - RID joint; - - NodePath a; - NodePath b; - - int solver_priority; - bool exclude_from_collision; - -protected: - void _update_joint(bool p_only_free = false); - - void _notification(int p_what); - - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) = 0; - - static void _bind_methods(); - -public: - void set_node_a(const NodePath &p_node_a); - NodePath get_node_a() const; - - void set_node_b(const NodePath &p_node_b); - NodePath get_node_b() const; - - void set_solver_priority(int p_priority); - int get_solver_priority() const; - - void set_exclude_nodes_from_collision(bool p_enable); - bool get_exclude_nodes_from_collision() const; - - RID get_joint() const { return joint; } - Joint(); -}; - -/////////////////////////////////////////// - -class PinJoint : public Joint { - - GDCLASS(PinJoint, Joint); - -public: - enum Param { - PARAM_BIAS = PhysicsServer::PIN_JOINT_BIAS, - PARAM_DAMPING = PhysicsServer::PIN_JOINT_DAMPING, - PARAM_IMPULSE_CLAMP = PhysicsServer::PIN_JOINT_IMPULSE_CLAMP - }; - -protected: - float params[3]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - PinJoint(); -}; - -VARIANT_ENUM_CAST(PinJoint::Param); - -class HingeJoint : public Joint { - - GDCLASS(HingeJoint, Joint); - -public: - enum Param { - PARAM_BIAS = PhysicsServer::HINGE_JOINT_BIAS, - PARAM_LIMIT_UPPER = PhysicsServer::HINGE_JOINT_LIMIT_UPPER, - PARAM_LIMIT_LOWER = PhysicsServer::HINGE_JOINT_LIMIT_LOWER, - PARAM_LIMIT_BIAS = PhysicsServer::HINGE_JOINT_LIMIT_BIAS, - PARAM_LIMIT_SOFTNESS = PhysicsServer::HINGE_JOINT_LIMIT_SOFTNESS, - PARAM_LIMIT_RELAXATION = PhysicsServer::HINGE_JOINT_LIMIT_RELAXATION, - PARAM_MOTOR_TARGET_VELOCITY = PhysicsServer::HINGE_JOINT_MOTOR_TARGET_VELOCITY, - PARAM_MOTOR_MAX_IMPULSE = PhysicsServer::HINGE_JOINT_MOTOR_MAX_IMPULSE, - PARAM_MAX = PhysicsServer::HINGE_JOINT_MAX - }; - - enum Flag { - FLAG_USE_LIMIT = PhysicsServer::HINGE_JOINT_FLAG_USE_LIMIT, - FLAG_ENABLE_MOTOR = PhysicsServer::HINGE_JOINT_FLAG_ENABLE_MOTOR, - FLAG_MAX = PhysicsServer::HINGE_JOINT_FLAG_MAX - }; - -protected: - float params[PARAM_MAX]; - bool flags[FLAG_MAX]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - - void _set_upper_limit(float p_limit); - float _get_upper_limit() const; - - void _set_lower_limit(float p_limit); - float _get_lower_limit() const; - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - void set_flag(Flag p_flag, bool p_value); - bool get_flag(Flag p_flag) const; - - HingeJoint(); -}; - -VARIANT_ENUM_CAST(HingeJoint::Param); -VARIANT_ENUM_CAST(HingeJoint::Flag); - -class SliderJoint : public Joint { - - GDCLASS(SliderJoint, Joint); - -public: - enum Param { - PARAM_LINEAR_LIMIT_UPPER = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_UPPER, - PARAM_LINEAR_LIMIT_LOWER = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_LOWER, - PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, - PARAM_LINEAR_LIMIT_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, - PARAM_LINEAR_LIMIT_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, - PARAM_LINEAR_MOTION_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS, - PARAM_LINEAR_MOTION_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION, - PARAM_LINEAR_MOTION_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_MOTION_DAMPING, - PARAM_LINEAR_ORTHOGONAL_SOFTNESS = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS, - PARAM_LINEAR_ORTHOGONAL_RESTITUTION = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION, - PARAM_LINEAR_ORTHOGONAL_DAMPING = PhysicsServer::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING, - - PARAM_ANGULAR_LIMIT_UPPER = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, - PARAM_ANGULAR_LIMIT_LOWER = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, - PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, - PARAM_ANGULAR_LIMIT_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION, - PARAM_ANGULAR_LIMIT_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, - PARAM_ANGULAR_MOTION_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS, - PARAM_ANGULAR_MOTION_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION, - PARAM_ANGULAR_MOTION_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_MOTION_DAMPING, - PARAM_ANGULAR_ORTHOGONAL_SOFTNESS = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS, - PARAM_ANGULAR_ORTHOGONAL_RESTITUTION = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION, - PARAM_ANGULAR_ORTHOGONAL_DAMPING = PhysicsServer::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING, - PARAM_MAX = PhysicsServer::SLIDER_JOINT_MAX - - }; - -protected: - void _set_upper_limit_angular(float p_limit_angular); - float _get_upper_limit_angular() const; - - void _set_lower_limit_angular(float p_limit_angular); - float _get_lower_limit_angular() const; - - float params[PARAM_MAX]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - SliderJoint(); -}; - -VARIANT_ENUM_CAST(SliderJoint::Param); - -class ConeTwistJoint : public Joint { - - GDCLASS(ConeTwistJoint, Joint); - -public: - enum Param { - - PARAM_SWING_SPAN, - PARAM_TWIST_SPAN, - PARAM_BIAS, - PARAM_SOFTNESS, - PARAM_RELAXATION, - PARAM_MAX - }; - -protected: - void _set_swing_span(float p_limit_angular); - float _get_swing_span() const; - - void _set_twist_span(float p_limit_angular); - float _get_twist_span() const; - - float params[PARAM_MAX]; - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param(Param p_param, float p_value); - float get_param(Param p_param) const; - - ConeTwistJoint(); -}; - -VARIANT_ENUM_CAST(ConeTwistJoint::Param); - -class Generic6DOFJoint : public Joint { - - GDCLASS(Generic6DOFJoint, Joint); - -public: - enum Param { - - PARAM_LINEAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_LOWER_LIMIT, - PARAM_LINEAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_UPPER_LIMIT, - PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, - PARAM_LINEAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_LINEAR_RESTITUTION, - PARAM_LINEAR_DAMPING = PhysicsServer::G6DOF_JOINT_LINEAR_DAMPING, - PARAM_LINEAR_MOTOR_TARGET_VELOCITY = PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY, - PARAM_LINEAR_MOTOR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT, - PARAM_LINEAR_SPRING_STIFFNESS = PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, - PARAM_LINEAR_SPRING_DAMPING = PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_DAMPING, - PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, - PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, - PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, - PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, - PARAM_ANGULAR_DAMPING = PhysicsServer::G6DOF_JOINT_ANGULAR_DAMPING, - PARAM_ANGULAR_RESTITUTION = PhysicsServer::G6DOF_JOINT_ANGULAR_RESTITUTION, - PARAM_ANGULAR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_FORCE_LIMIT, - PARAM_ANGULAR_ERP = PhysicsServer::G6DOF_JOINT_ANGULAR_ERP, - PARAM_ANGULAR_MOTOR_TARGET_VELOCITY = PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY, - PARAM_ANGULAR_MOTOR_FORCE_LIMIT = PhysicsServer::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT, - PARAM_ANGULAR_SPRING_STIFFNESS = PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, - PARAM_ANGULAR_SPRING_DAMPING = PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, - PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, - PARAM_MAX = PhysicsServer::G6DOF_JOINT_MAX, - }; - - enum Flag { - FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, - FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, - FLAG_ENABLE_LINEAR_SPRING = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, - FLAG_ENABLE_ANGULAR_SPRING = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, - FLAG_ENABLE_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_MOTOR, - FLAG_ENABLE_LINEAR_MOTOR = PhysicsServer::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR, - FLAG_MAX = PhysicsServer::G6DOF_JOINT_FLAG_MAX - }; - -protected: - void _set_angular_hi_limit_x(float p_limit_angular); - float _get_angular_hi_limit_x() const; - - void _set_angular_hi_limit_y(float p_limit_angular); - float _get_angular_hi_limit_y() const; - - void _set_angular_hi_limit_z(float p_limit_angular); - float _get_angular_hi_limit_z() const; - - void _set_angular_lo_limit_x(float p_limit_angular); - float _get_angular_lo_limit_x() const; - - void _set_angular_lo_limit_y(float p_limit_angular); - float _get_angular_lo_limit_y() const; - - void _set_angular_lo_limit_z(float p_limit_angular); - float _get_angular_lo_limit_z() const; - - float params_x[PARAM_MAX]; - bool flags_x[FLAG_MAX]; - float params_y[PARAM_MAX]; - bool flags_y[FLAG_MAX]; - float params_z[PARAM_MAX]; - bool flags_z[FLAG_MAX]; - - int precision; - - virtual RID _configure_joint(PhysicsBody *body_a, PhysicsBody *body_b); - static void _bind_methods(); - -public: - void set_param_x(Param p_param, float p_value); - float get_param_x(Param p_param) const; - - void set_param_y(Param p_param, float p_value); - float get_param_y(Param p_param) const; - - void set_param_z(Param p_param, float p_value); - float get_param_z(Param p_param) const; - - void set_flag_x(Flag p_flag, bool p_enabled); - bool get_flag_x(Flag p_flag) const; - - void set_flag_y(Flag p_flag, bool p_enabled); - bool get_flag_y(Flag p_flag) const; - - void set_flag_z(Flag p_flag, bool p_enabled); - bool get_flag_z(Flag p_flag) const; - - void set_precision(int p_precision); - int get_precision() const { - return precision; - } - - Generic6DOFJoint(); -}; - -VARIANT_ENUM_CAST(Generic6DOFJoint::Param); -VARIANT_ENUM_CAST(Generic6DOFJoint::Flag); - -#endif // PHYSICS_JOINT_H diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint_3d.cpp index 0699e366e0..591c17a91e 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* physics_joint.cpp */ +/* physics_joint_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "physics_joint.h" +#include "physics_joint_3d.h" -void Joint::_update_joint(bool p_only_free) { +void Joint3D::_update_joint(bool p_only_free) { if (joint.is_valid()) { if (ba.is_valid() && bb.is_valid()) - PhysicsServer::get_singleton()->body_remove_collision_exception(ba, bb); + PhysicsServer3D::get_singleton()->body_remove_collision_exception(ba, bb); - PhysicsServer::get_singleton()->free(joint); + PhysicsServer3D::get_singleton()->free(joint); joint = RID(); ba = RID(); bb = RID(); @@ -45,11 +45,11 @@ void Joint::_update_joint(bool p_only_free) { if (p_only_free || !is_inside_tree()) return; - Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL; - Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL; + Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)nullptr; + Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)nullptr; - PhysicsBody *body_a = Object::cast_to<PhysicsBody>(node_a); - PhysicsBody *body_b = Object::cast_to<PhysicsBody>(node_b); + PhysicsBody3D *body_a = Object::cast_to<PhysicsBody3D>(node_a); + PhysicsBody3D *body_b = Object::cast_to<PhysicsBody3D>(node_b); if (!body_a && body_b) SWAP(body_a, body_b); @@ -62,16 +62,16 @@ void Joint::_update_joint(bool p_only_free) { if (!joint.is_valid()) return; - PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); + PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority); ba = body_a->get_rid(); if (body_b) bb = body_b->get_rid(); - PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); + PhysicsServer3D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } -void Joint::set_node_a(const NodePath &p_node_a) { +void Joint3D::set_node_a(const NodePath &p_node_a) { if (a == p_node_a) return; @@ -80,36 +80,36 @@ void Joint::set_node_a(const NodePath &p_node_a) { _update_joint(); } -NodePath Joint::get_node_a() const { +NodePath Joint3D::get_node_a() const { return a; } -void Joint::set_node_b(const NodePath &p_node_b) { +void Joint3D::set_node_b(const NodePath &p_node_b) { if (b == p_node_b) return; b = p_node_b; _update_joint(); } -NodePath Joint::get_node_b() const { +NodePath Joint3D::get_node_b() const { return b; } -void Joint::set_solver_priority(int p_priority) { +void Joint3D::set_solver_priority(int p_priority) { solver_priority = p_priority; if (joint.is_valid()) - PhysicsServer::get_singleton()->joint_set_solver_priority(joint, solver_priority); + PhysicsServer3D::get_singleton()->joint_set_solver_priority(joint, solver_priority); } -int Joint::get_solver_priority() const { +int Joint3D::get_solver_priority() const { return solver_priority; } -void Joint::_notification(int p_what) { +void Joint3D::_notification(int p_what) { switch (p_what) { @@ -124,7 +124,7 @@ void Joint::_notification(int p_what) { } } -void Joint::set_exclude_nodes_from_collision(bool p_enable) { +void Joint3D::set_exclude_nodes_from_collision(bool p_enable) { if (exclude_from_collision == p_enable) return; @@ -132,33 +132,33 @@ void Joint::set_exclude_nodes_from_collision(bool p_enable) { _update_joint(); } -bool Joint::get_exclude_nodes_from_collision() const { +bool Joint3D::get_exclude_nodes_from_collision() const { return exclude_from_collision; } -void Joint::_bind_methods() { +void Joint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint::set_node_a); - ClassDB::bind_method(D_METHOD("get_node_a"), &Joint::get_node_a); + ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint3D::set_node_a); + ClassDB::bind_method(D_METHOD("get_node_a"), &Joint3D::get_node_a); - ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint::set_node_b); - ClassDB::bind_method(D_METHOD("get_node_b"), &Joint::get_node_b); + ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint3D::set_node_b); + ClassDB::bind_method(D_METHOD("get_node_b"), &Joint3D::get_node_b); - ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint::set_solver_priority); - ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint::get_solver_priority); + ClassDB::bind_method(D_METHOD("set_solver_priority", "priority"), &Joint3D::set_solver_priority); + ClassDB::bind_method(D_METHOD("get_solver_priority"), &Joint3D::get_solver_priority); - ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint::set_exclude_nodes_from_collision); - ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint::get_exclude_nodes_from_collision); + ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint3D::set_exclude_nodes_from_collision); + ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint3D::get_exclude_nodes_from_collision); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject"), "set_node_a", "get_node_a"); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject"), "set_node_b", "get_node_b"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_a", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject3D"), "set_node_a", "get_node_a"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "nodes/node_b", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "CollisionObject3D"), "set_node_b", "get_node_b"); ADD_PROPERTY(PropertyInfo(Variant::INT, "solver/priority", PROPERTY_HINT_RANGE, "1,8,1"), "set_solver_priority", "get_solver_priority"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision/exclude_nodes"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision"); } -Joint::Joint() { +Joint3D::Joint3D() { exclude_from_collision = true; solver_priority = 1; @@ -167,10 +167,10 @@ Joint::Joint() { /////////////////////////////////// -void PinJoint::_bind_methods() { +void PinJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &PinJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &PinJoint3D::get_param); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/bias", PROPERTY_HINT_RANGE, "0.01,0.99,0.01"), "set_param", "get_param", PARAM_BIAS); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/damping", PROPERTY_HINT_RANGE, "0.01,8.0,0.01"), "set_param", "get_param", PARAM_DAMPING); @@ -181,20 +181,20 @@ void PinJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_IMPULSE_CLAMP); } -void PinJoint::set_param(Param p_param, float p_value) { +void PinJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, 3); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer::PinJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->pin_joint_set_param(get_joint(), PhysicsServer3D::PinJointParam(p_param), p_value); } -float PinJoint::get_param(Param p_param) const { +float PinJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, 3, 0); return params[p_param]; } -RID PinJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID PinJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Vector3 pinpos = get_global_transform().origin; Vector3 local_a = body_a->get_global_transform().affine_inverse().xform(pinpos); @@ -205,14 +205,14 @@ RID PinJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { else local_b = pinpos; - RID j = PhysicsServer::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_pin(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < 3; i++) { - PhysicsServer::get_singleton()->pin_joint_set_param(j, PhysicsServer::PinJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->pin_joint_set_param(j, PhysicsServer3D::PinJointParam(i), params[i]); } return j; } -PinJoint::PinJoint() { +PinJoint3D::PinJoint3D() { params[PARAM_BIAS] = 0.3; params[PARAM_DAMPING] = 1; @@ -223,39 +223,39 @@ PinJoint::PinJoint() { /////////////////////////////////// -void HingeJoint::_set_upper_limit(float p_limit) { +void HingeJoint3D::_set_upper_limit(float p_limit) { set_param(PARAM_LIMIT_UPPER, Math::deg2rad(p_limit)); } -float HingeJoint::_get_upper_limit() const { +float HingeJoint3D::_get_upper_limit() const { return Math::rad2deg(get_param(PARAM_LIMIT_UPPER)); } -void HingeJoint::_set_lower_limit(float p_limit) { +void HingeJoint3D::_set_lower_limit(float p_limit) { set_param(PARAM_LIMIT_LOWER, Math::deg2rad(p_limit)); } -float HingeJoint::_get_lower_limit() const { +float HingeJoint3D::_get_lower_limit() const { return Math::rad2deg(get_param(PARAM_LIMIT_LOWER)); } -void HingeJoint::_bind_methods() { +void HingeJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &HingeJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &HingeJoint3D::get_param); - ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint::set_flag); - ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint::get_flag); + ClassDB::bind_method(D_METHOD("set_flag", "flag", "enabled"), &HingeJoint3D::set_flag); + ClassDB::bind_method(D_METHOD("get_flag", "flag"), &HingeJoint3D::get_flag); - ClassDB::bind_method(D_METHOD("_set_upper_limit", "upper_limit"), &HingeJoint::_set_upper_limit); - ClassDB::bind_method(D_METHOD("_get_upper_limit"), &HingeJoint::_get_upper_limit); + ClassDB::bind_method(D_METHOD("_set_upper_limit", "upper_limit"), &HingeJoint3D::_set_upper_limit); + ClassDB::bind_method(D_METHOD("_get_upper_limit"), &HingeJoint3D::_get_upper_limit); - ClassDB::bind_method(D_METHOD("_set_lower_limit", "lower_limit"), &HingeJoint::_set_lower_limit); - ClassDB::bind_method(D_METHOD("_get_lower_limit"), &HingeJoint::_get_lower_limit); + ClassDB::bind_method(D_METHOD("_set_lower_limit", "lower_limit"), &HingeJoint3D::_set_lower_limit); + ClassDB::bind_method(D_METHOD("_get_lower_limit"), &HingeJoint3D::_get_lower_limit); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "params/bias", PROPERTY_HINT_RANGE, "0.00,0.99,0.01"), "set_param", "get_param", PARAM_BIAS); @@ -285,37 +285,37 @@ void HingeJoint::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); } -void HingeJoint::set_param(Param p_param, float p_value) { +void HingeJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer::HingeJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer3D::HingeJointParam(p_param), p_value); update_gizmo(); } -float HingeJoint::get_param(Param p_param) const { +float HingeJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params[p_param]; } -void HingeJoint::set_flag(Flag p_flag, bool p_value) { +void HingeJoint3D::set_flag(Flag p_flag, bool p_value) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags[p_flag] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer::HingeJointFlag(p_flag), p_value); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer3D::HingeJointFlag(p_flag), p_value); update_gizmo(); } -bool HingeJoint::get_flag(Flag p_flag) const { +bool HingeJoint3D::get_flag(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } -RID HingeJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID HingeJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); Transform ainv = body_a->get_global_transform().affine_inverse(); @@ -331,18 +331,18 @@ RID HingeJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_hinge(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->hinge_joint_set_param(j, PhysicsServer::HingeJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->hinge_joint_set_param(j, PhysicsServer3D::HingeJointParam(i), params[i]); } for (int i = 0; i < FLAG_MAX; i++) { set_flag(Flag(i), flags[i]); - PhysicsServer::get_singleton()->hinge_joint_set_flag(j, PhysicsServer::HingeJointFlag(i), flags[i]); + PhysicsServer3D::get_singleton()->hinge_joint_set_flag(j, PhysicsServer3D::HingeJointFlag(i), flags[i]); } return j; } -HingeJoint::HingeJoint() { +HingeJoint3D::HingeJoint3D() { params[PARAM_BIAS] = 0.3; params[PARAM_LIMIT_UPPER] = Math_PI * 0.5; @@ -361,36 +361,36 @@ HingeJoint::HingeJoint() { ////////////////////////////////// -void SliderJoint::_set_upper_limit_angular(float p_limit_angular) { +void SliderJoint3D::_set_upper_limit_angular(float p_limit_angular) { set_param(PARAM_ANGULAR_LIMIT_UPPER, Math::deg2rad(p_limit_angular)); } -float SliderJoint::_get_upper_limit_angular() const { +float SliderJoint3D::_get_upper_limit_angular() const { return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_UPPER)); } -void SliderJoint::_set_lower_limit_angular(float p_limit_angular) { +void SliderJoint3D::_set_lower_limit_angular(float p_limit_angular) { set_param(PARAM_ANGULAR_LIMIT_LOWER, Math::deg2rad(p_limit_angular)); } -float SliderJoint::_get_lower_limit_angular() const { +float SliderJoint3D::_get_lower_limit_angular() const { return Math::rad2deg(get_param(PARAM_ANGULAR_LIMIT_LOWER)); } -void SliderJoint::_bind_methods() { +void SliderJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &SliderJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &SliderJoint3D::get_param); - ClassDB::bind_method(D_METHOD("_set_upper_limit_angular", "upper_limit_angular"), &SliderJoint::_set_upper_limit_angular); - ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"), &SliderJoint::_get_upper_limit_angular); + ClassDB::bind_method(D_METHOD("_set_upper_limit_angular", "upper_limit_angular"), &SliderJoint3D::_set_upper_limit_angular); + ClassDB::bind_method(D_METHOD("_get_upper_limit_angular"), &SliderJoint3D::_get_upper_limit_angular); - ClassDB::bind_method(D_METHOD("_set_lower_limit_angular", "lower_limit_angular"), &SliderJoint::_set_lower_limit_angular); - ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"), &SliderJoint::_get_lower_limit_angular); + ClassDB::bind_method(D_METHOD("_set_lower_limit_angular", "lower_limit_angular"), &SliderJoint3D::_set_lower_limit_angular); + ClassDB::bind_method(D_METHOD("_get_lower_limit_angular"), &SliderJoint3D::_get_lower_limit_angular); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/upper_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_UPPER); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit/lower_distance", PROPERTY_HINT_RANGE, "-1024,1024,0.01"), "set_param", "get_param", PARAM_LINEAR_LIMIT_LOWER); @@ -443,21 +443,21 @@ void SliderJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_MAX); } -void SliderJoint::set_param(Param p_param, float p_value) { +void SliderJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer::SliderJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer3D::SliderJointParam(p_param), p_value); update_gizmo(); } -float SliderJoint::get_param(Param p_param) const { +float SliderJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params[p_param]; } -RID SliderJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID SliderJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); Transform ainv = body_a->get_global_transform().affine_inverse(); @@ -473,15 +473,15 @@ RID SliderJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_slider(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->slider_joint_set_param(j, PhysicsServer::SliderJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->slider_joint_set_param(j, PhysicsServer3D::SliderJointParam(i), params[i]); } return j; } -SliderJoint::SliderJoint() { +SliderJoint3D::SliderJoint3D() { params[PARAM_LINEAR_LIMIT_UPPER] = 1.0; params[PARAM_LINEAR_LIMIT_LOWER] = -1.0; @@ -510,36 +510,36 @@ SliderJoint::SliderJoint() { ////////////////////////////////// -void ConeTwistJoint::_set_swing_span(float p_limit_angular) { +void ConeTwistJoint3D::_set_swing_span(float p_limit_angular) { set_param(PARAM_SWING_SPAN, Math::deg2rad(p_limit_angular)); } -float ConeTwistJoint::_get_swing_span() const { +float ConeTwistJoint3D::_get_swing_span() const { return Math::rad2deg(get_param(PARAM_SWING_SPAN)); } -void ConeTwistJoint::_set_twist_span(float p_limit_angular) { +void ConeTwistJoint3D::_set_twist_span(float p_limit_angular) { set_param(PARAM_TWIST_SPAN, Math::deg2rad(p_limit_angular)); } -float ConeTwistJoint::_get_twist_span() const { +float ConeTwistJoint3D::_get_twist_span() const { return Math::rad2deg(get_param(PARAM_TWIST_SPAN)); } -void ConeTwistJoint::_bind_methods() { +void ConeTwistJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint::set_param); - ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint::get_param); + ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &ConeTwistJoint3D::set_param); + ClassDB::bind_method(D_METHOD("get_param", "param"), &ConeTwistJoint3D::get_param); - ClassDB::bind_method(D_METHOD("_set_swing_span", "swing_span"), &ConeTwistJoint::_set_swing_span); - ClassDB::bind_method(D_METHOD("_get_swing_span"), &ConeTwistJoint::_get_swing_span); + ClassDB::bind_method(D_METHOD("_set_swing_span", "swing_span"), &ConeTwistJoint3D::_set_swing_span); + ClassDB::bind_method(D_METHOD("_get_swing_span"), &ConeTwistJoint3D::_get_swing_span); - ClassDB::bind_method(D_METHOD("_set_twist_span", "twist_span"), &ConeTwistJoint::_set_twist_span); - ClassDB::bind_method(D_METHOD("_get_twist_span"), &ConeTwistJoint::_get_twist_span); + ClassDB::bind_method(D_METHOD("_set_twist_span", "twist_span"), &ConeTwistJoint3D::_set_twist_span); + ClassDB::bind_method(D_METHOD("_get_twist_span"), &ConeTwistJoint3D::_get_twist_span); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "swing_span", PROPERTY_HINT_RANGE, "-180,180,0.1"), "_set_swing_span", "_get_swing_span"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "twist_span", PROPERTY_HINT_RANGE, "-40000,40000,0.1"), "_set_twist_span", "_get_twist_span"); @@ -556,22 +556,22 @@ void ConeTwistJoint::_bind_methods() { BIND_ENUM_CONSTANT(PARAM_MAX); } -void ConeTwistJoint::set_param(Param p_param, float p_value) { +void ConeTwistJoint3D::set_param(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer::ConeTwistJointParam(p_param), p_value); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer3D::ConeTwistJointParam(p_param), p_value); update_gizmo(); } -float ConeTwistJoint::get_param(Param p_param) const { +float ConeTwistJoint3D::get_param(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params[p_param]; } -RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID ConeTwistJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); //Vector3 cone_twistpos = gt.origin; @@ -590,15 +590,15 @@ RID ConeTwistJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_cone_twist(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer::ConeTwistJointParam(i), params[i]); + PhysicsServer3D::get_singleton()->cone_twist_joint_set_param(j, PhysicsServer3D::ConeTwistJointParam(i), params[i]); } return j; } -ConeTwistJoint::ConeTwistJoint() { +ConeTwistJoint3D::ConeTwistJoint3D() { params[PARAM_SWING_SPAN] = Math_PI * 0.25; params[PARAM_TWIST_SPAN] = Math_PI; @@ -609,106 +609,106 @@ ConeTwistJoint::ConeTwistJoint() { ///////////////////////////////////////////////////////////////////// -void Generic6DOFJoint::_set_angular_hi_limit_x(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_hi_limit_x(float p_limit_angular) { set_param_x(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_hi_limit_x() const { +float Generic6DOFJoint3D::_get_angular_hi_limit_x() const { return Math::rad2deg(get_param_x(PARAM_ANGULAR_UPPER_LIMIT)); } -void Generic6DOFJoint::_set_angular_lo_limit_x(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_lo_limit_x(float p_limit_angular) { set_param_x(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_lo_limit_x() const { +float Generic6DOFJoint3D::_get_angular_lo_limit_x() const { return Math::rad2deg(get_param_x(PARAM_ANGULAR_LOWER_LIMIT)); } -void Generic6DOFJoint::_set_angular_hi_limit_y(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_hi_limit_y(float p_limit_angular) { set_param_y(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_hi_limit_y() const { +float Generic6DOFJoint3D::_get_angular_hi_limit_y() const { return Math::rad2deg(get_param_y(PARAM_ANGULAR_UPPER_LIMIT)); } -void Generic6DOFJoint::_set_angular_lo_limit_y(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_lo_limit_y(float p_limit_angular) { set_param_y(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_lo_limit_y() const { +float Generic6DOFJoint3D::_get_angular_lo_limit_y() const { return Math::rad2deg(get_param_y(PARAM_ANGULAR_LOWER_LIMIT)); } -void Generic6DOFJoint::_set_angular_hi_limit_z(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_hi_limit_z(float p_limit_angular) { set_param_z(PARAM_ANGULAR_UPPER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_hi_limit_z() const { +float Generic6DOFJoint3D::_get_angular_hi_limit_z() const { return Math::rad2deg(get_param_z(PARAM_ANGULAR_UPPER_LIMIT)); } -void Generic6DOFJoint::_set_angular_lo_limit_z(float p_limit_angular) { +void Generic6DOFJoint3D::_set_angular_lo_limit_z(float p_limit_angular) { set_param_z(PARAM_ANGULAR_LOWER_LIMIT, Math::deg2rad(p_limit_angular)); } -float Generic6DOFJoint::_get_angular_lo_limit_z() const { +float Generic6DOFJoint3D::_get_angular_lo_limit_z() const { return Math::rad2deg(get_param_z(PARAM_ANGULAR_LOWER_LIMIT)); } -void Generic6DOFJoint::_bind_methods() { +void Generic6DOFJoint3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_x); - ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"), &Generic6DOFJoint::_get_angular_hi_limit_x); + ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_x", "angle"), &Generic6DOFJoint3D::_set_angular_hi_limit_x); + ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_x"), &Generic6DOFJoint3D::_get_angular_hi_limit_x); - ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_x); - ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"), &Generic6DOFJoint::_get_angular_lo_limit_x); + ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_x", "angle"), &Generic6DOFJoint3D::_set_angular_lo_limit_x); + ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_x"), &Generic6DOFJoint3D::_get_angular_lo_limit_x); - ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_y); - ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"), &Generic6DOFJoint::_get_angular_hi_limit_y); + ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_y", "angle"), &Generic6DOFJoint3D::_set_angular_hi_limit_y); + ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_y"), &Generic6DOFJoint3D::_get_angular_hi_limit_y); - ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_y); - ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"), &Generic6DOFJoint::_get_angular_lo_limit_y); + ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_y", "angle"), &Generic6DOFJoint3D::_set_angular_lo_limit_y); + ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_y"), &Generic6DOFJoint3D::_get_angular_lo_limit_y); - ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z", "angle"), &Generic6DOFJoint::_set_angular_hi_limit_z); - ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"), &Generic6DOFJoint::_get_angular_hi_limit_z); + ClassDB::bind_method(D_METHOD("_set_angular_hi_limit_z", "angle"), &Generic6DOFJoint3D::_set_angular_hi_limit_z); + ClassDB::bind_method(D_METHOD("_get_angular_hi_limit_z"), &Generic6DOFJoint3D::_get_angular_hi_limit_z); - ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z", "angle"), &Generic6DOFJoint::_set_angular_lo_limit_z); - ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"), &Generic6DOFJoint::_get_angular_lo_limit_z); + ClassDB::bind_method(D_METHOD("_set_angular_lo_limit_z", "angle"), &Generic6DOFJoint3D::_set_angular_lo_limit_z); + ClassDB::bind_method(D_METHOD("_get_angular_lo_limit_z"), &Generic6DOFJoint3D::_get_angular_lo_limit_z); - ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint::set_param_x); - ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint::get_param_x); + ClassDB::bind_method(D_METHOD("set_param_x", "param", "value"), &Generic6DOFJoint3D::set_param_x); + ClassDB::bind_method(D_METHOD("get_param_x", "param"), &Generic6DOFJoint3D::get_param_x); - ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint::set_param_y); - ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint::get_param_y); + ClassDB::bind_method(D_METHOD("set_param_y", "param", "value"), &Generic6DOFJoint3D::set_param_y); + ClassDB::bind_method(D_METHOD("get_param_y", "param"), &Generic6DOFJoint3D::get_param_y); - ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint::set_param_z); - ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint::get_param_z); + ClassDB::bind_method(D_METHOD("set_param_z", "param", "value"), &Generic6DOFJoint3D::set_param_z); + ClassDB::bind_method(D_METHOD("get_param_z", "param"), &Generic6DOFJoint3D::get_param_z); - ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint::set_flag_x); - ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint::get_flag_x); + ClassDB::bind_method(D_METHOD("set_flag_x", "flag", "value"), &Generic6DOFJoint3D::set_flag_x); + ClassDB::bind_method(D_METHOD("get_flag_x", "flag"), &Generic6DOFJoint3D::get_flag_x); - ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint::set_flag_y); - ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint::get_flag_y); + ClassDB::bind_method(D_METHOD("set_flag_y", "flag", "value"), &Generic6DOFJoint3D::set_flag_y); + ClassDB::bind_method(D_METHOD("get_flag_y", "flag"), &Generic6DOFJoint3D::get_flag_y); - ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint::set_flag_z); - ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint::get_flag_z); + ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint3D::set_flag_z); + ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint3D::get_flag_z); - ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint::set_precision); - ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint::get_precision); + ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint3D::set_precision); + ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint3D::get_precision); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT); ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/upper_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT); @@ -827,100 +827,100 @@ void Generic6DOFJoint::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); } -void Generic6DOFJoint::set_param_x(Param p_param, float p_value) { +void Generic6DOFJoint3D::set_param_x(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params_x[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(p_param), p_value); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value); update_gizmo(); } -float Generic6DOFJoint::get_param_x(Param p_param) const { +float Generic6DOFJoint3D::get_param_x(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params_x[p_param]; } -void Generic6DOFJoint::set_param_y(Param p_param, float p_value) { +void Generic6DOFJoint3D::set_param_y(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params_y[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(p_param), p_value); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value); update_gizmo(); } -float Generic6DOFJoint::get_param_y(Param p_param) const { +float Generic6DOFJoint3D::get_param_y(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params_y[p_param]; } -void Generic6DOFJoint::set_param_z(Param p_param, float p_value) { +void Generic6DOFJoint3D::set_param_z(Param p_param, float p_value) { ERR_FAIL_INDEX(p_param, PARAM_MAX); params_z[p_param] = p_value; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(p_param), p_value); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(p_param), p_value); update_gizmo(); } -float Generic6DOFJoint::get_param_z(Param p_param) const { +float Generic6DOFJoint3D::get_param_z(Param p_param) const { ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0); return params_z[p_param]; } -void Generic6DOFJoint::set_flag_x(Flag p_flag, bool p_enabled) { +void Generic6DOFJoint3D::set_flag_x(Flag p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags_x[p_flag] = p_enabled; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled); update_gizmo(); } -bool Generic6DOFJoint::get_flag_x(Flag p_flag) const { +bool Generic6DOFJoint3D::get_flag_x(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags_x[p_flag]; } -void Generic6DOFJoint::set_flag_y(Flag p_flag, bool p_enabled) { +void Generic6DOFJoint3D::set_flag_y(Flag p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags_y[p_flag] = p_enabled; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled); update_gizmo(); } -bool Generic6DOFJoint::get_flag_y(Flag p_flag) const { +bool Generic6DOFJoint3D::get_flag_y(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags_y[p_flag]; } -void Generic6DOFJoint::set_flag_z(Flag p_flag, bool p_enabled) { +void Generic6DOFJoint3D::set_flag_z(Flag p_flag, bool p_enabled) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags_z[p_flag] = p_enabled; if (get_joint().is_valid()) - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(p_flag), p_enabled); update_gizmo(); } -bool Generic6DOFJoint::get_flag_z(Flag p_flag) const { +bool Generic6DOFJoint3D::get_flag_z(Flag p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags_z[p_flag]; } -void Generic6DOFJoint::set_precision(int p_precision) { +void Generic6DOFJoint3D::set_precision(int p_precision) { precision = p_precision; - PhysicsServer::get_singleton()->generic_6dof_joint_set_precision( + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_precision( get_joint(), precision); } -RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) { +RID Generic6DOFJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) { Transform gt = get_global_transform(); //Vector3 cone_twistpos = gt.origin; @@ -939,22 +939,22 @@ RID Generic6DOFJoint::_configure_joint(PhysicsBody *body_a, PhysicsBody *body_b) local_b.orthonormalize(); - RID j = PhysicsServer::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); + RID j = PhysicsServer3D::get_singleton()->joint_create_generic_6dof(body_a->get_rid(), local_a, body_b ? body_b->get_rid() : RID(), local_b); for (int i = 0; i < PARAM_MAX; i++) { - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(i), params_x[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(i), params_y[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(i), params_z[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisParam(i), params_x[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisParam(i), params_y[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_param(j, Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisParam(i), params_z[i]); } for (int i = 0; i < FLAG_MAX; i++) { - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(i), flags_x[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(i), flags_y[i]); - PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(i), flags_z[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_X, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_x[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Y, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_y[i]); + PhysicsServer3D::get_singleton()->generic_6dof_joint_set_flag(j, Vector3::AXIS_Z, PhysicsServer3D::G6DOFJointAxisFlag(i), flags_z[i]); } return j; } -Generic6DOFJoint::Generic6DOFJoint() : +Generic6DOFJoint3D::Generic6DOFJoint3D() : precision(1) { set_param_x(PARAM_LINEAR_LOWER_LIMIT, 0); diff --git a/scene/3d/physics_joint_3d.h b/scene/3d/physics_joint_3d.h new file mode 100644 index 0000000000..ce0c7af5d1 --- /dev/null +++ b/scene/3d/physics_joint_3d.h @@ -0,0 +1,343 @@ +/*************************************************************************/ +/* physics_joint_3d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 PHYSICS_JOINT_H +#define PHYSICS_JOINT_H + +#include "scene/3d/node_3d.h" +#include "scene/3d/physics_body_3d.h" + +class Joint3D : public Node3D { + + GDCLASS(Joint3D, Node3D); + + RID ba, bb; + + RID joint; + + NodePath a; + NodePath b; + + int solver_priority; + bool exclude_from_collision; + +protected: + void _update_joint(bool p_only_free = false); + + void _notification(int p_what); + + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) = 0; + + static void _bind_methods(); + +public: + void set_node_a(const NodePath &p_node_a); + NodePath get_node_a() const; + + void set_node_b(const NodePath &p_node_b); + NodePath get_node_b() const; + + void set_solver_priority(int p_priority); + int get_solver_priority() const; + + void set_exclude_nodes_from_collision(bool p_enable); + bool get_exclude_nodes_from_collision() const; + + RID get_joint() const { return joint; } + Joint3D(); +}; + +/////////////////////////////////////////// + +class PinJoint3D : public Joint3D { + + GDCLASS(PinJoint3D, Joint3D); + +public: + enum Param { + PARAM_BIAS = PhysicsServer3D::PIN_JOINT_BIAS, + PARAM_DAMPING = PhysicsServer3D::PIN_JOINT_DAMPING, + PARAM_IMPULSE_CLAMP = PhysicsServer3D::PIN_JOINT_IMPULSE_CLAMP + }; + +protected: + float params[3]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + PinJoint3D(); +}; + +VARIANT_ENUM_CAST(PinJoint3D::Param); + +class HingeJoint3D : public Joint3D { + + GDCLASS(HingeJoint3D, Joint3D); + +public: + enum Param { + PARAM_BIAS = PhysicsServer3D::HINGE_JOINT_BIAS, + PARAM_LIMIT_UPPER = PhysicsServer3D::HINGE_JOINT_LIMIT_UPPER, + PARAM_LIMIT_LOWER = PhysicsServer3D::HINGE_JOINT_LIMIT_LOWER, + PARAM_LIMIT_BIAS = PhysicsServer3D::HINGE_JOINT_LIMIT_BIAS, + PARAM_LIMIT_SOFTNESS = PhysicsServer3D::HINGE_JOINT_LIMIT_SOFTNESS, + PARAM_LIMIT_RELAXATION = PhysicsServer3D::HINGE_JOINT_LIMIT_RELAXATION, + PARAM_MOTOR_TARGET_VELOCITY = PhysicsServer3D::HINGE_JOINT_MOTOR_TARGET_VELOCITY, + PARAM_MOTOR_MAX_IMPULSE = PhysicsServer3D::HINGE_JOINT_MOTOR_MAX_IMPULSE, + PARAM_MAX = PhysicsServer3D::HINGE_JOINT_MAX + }; + + enum Flag { + FLAG_USE_LIMIT = PhysicsServer3D::HINGE_JOINT_FLAG_USE_LIMIT, + FLAG_ENABLE_MOTOR = PhysicsServer3D::HINGE_JOINT_FLAG_ENABLE_MOTOR, + FLAG_MAX = PhysicsServer3D::HINGE_JOINT_FLAG_MAX + }; + +protected: + float params[PARAM_MAX]; + bool flags[FLAG_MAX]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + + void _set_upper_limit(float p_limit); + float _get_upper_limit() const; + + void _set_lower_limit(float p_limit); + float _get_lower_limit() const; + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + void set_flag(Flag p_flag, bool p_value); + bool get_flag(Flag p_flag) const; + + HingeJoint3D(); +}; + +VARIANT_ENUM_CAST(HingeJoint3D::Param); +VARIANT_ENUM_CAST(HingeJoint3D::Flag); + +class SliderJoint3D : public Joint3D { + + GDCLASS(SliderJoint3D, Joint3D); + +public: + enum Param { + PARAM_LINEAR_LIMIT_UPPER = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_UPPER, + PARAM_LINEAR_LIMIT_LOWER = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_LOWER, + PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS, + PARAM_LINEAR_LIMIT_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION, + PARAM_LINEAR_LIMIT_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_LIMIT_DAMPING, + PARAM_LINEAR_MOTION_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_SOFTNESS, + PARAM_LINEAR_MOTION_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_RESTITUTION, + PARAM_LINEAR_MOTION_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_MOTION_DAMPING, + PARAM_LINEAR_ORTHOGONAL_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS, + PARAM_LINEAR_ORTHOGONAL_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION, + PARAM_LINEAR_ORTHOGONAL_DAMPING = PhysicsServer3D::SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING, + + PARAM_ANGULAR_LIMIT_UPPER = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_UPPER, + PARAM_ANGULAR_LIMIT_LOWER = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_LOWER, + PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS, + PARAM_ANGULAR_LIMIT_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION, + PARAM_ANGULAR_LIMIT_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_LIMIT_DAMPING, + PARAM_ANGULAR_MOTION_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS, + PARAM_ANGULAR_MOTION_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION, + PARAM_ANGULAR_MOTION_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_MOTION_DAMPING, + PARAM_ANGULAR_ORTHOGONAL_SOFTNESS = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS, + PARAM_ANGULAR_ORTHOGONAL_RESTITUTION = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION, + PARAM_ANGULAR_ORTHOGONAL_DAMPING = PhysicsServer3D::SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING, + PARAM_MAX = PhysicsServer3D::SLIDER_JOINT_MAX + + }; + +protected: + void _set_upper_limit_angular(float p_limit_angular); + float _get_upper_limit_angular() const; + + void _set_lower_limit_angular(float p_limit_angular); + float _get_lower_limit_angular() const; + + float params[PARAM_MAX]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + SliderJoint3D(); +}; + +VARIANT_ENUM_CAST(SliderJoint3D::Param); + +class ConeTwistJoint3D : public Joint3D { + + GDCLASS(ConeTwistJoint3D, Joint3D); + +public: + enum Param { + + PARAM_SWING_SPAN, + PARAM_TWIST_SPAN, + PARAM_BIAS, + PARAM_SOFTNESS, + PARAM_RELAXATION, + PARAM_MAX + }; + +protected: + void _set_swing_span(float p_limit_angular); + float _get_swing_span() const; + + void _set_twist_span(float p_limit_angular); + float _get_twist_span() const; + + float params[PARAM_MAX]; + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param(Param p_param, float p_value); + float get_param(Param p_param) const; + + ConeTwistJoint3D(); +}; + +VARIANT_ENUM_CAST(ConeTwistJoint3D::Param); + +class Generic6DOFJoint3D : public Joint3D { + + GDCLASS(Generic6DOFJoint3D, Joint3D); + +public: + enum Param { + + PARAM_LINEAR_LOWER_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_LOWER_LIMIT, + PARAM_LINEAR_UPPER_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_UPPER_LIMIT, + PARAM_LINEAR_LIMIT_SOFTNESS = PhysicsServer3D::G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS, + PARAM_LINEAR_RESTITUTION = PhysicsServer3D::G6DOF_JOINT_LINEAR_RESTITUTION, + PARAM_LINEAR_DAMPING = PhysicsServer3D::G6DOF_JOINT_LINEAR_DAMPING, + PARAM_LINEAR_MOTOR_TARGET_VELOCITY = PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY, + PARAM_LINEAR_MOTOR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT, + PARAM_LINEAR_SPRING_STIFFNESS = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_STIFFNESS, + PARAM_LINEAR_SPRING_DAMPING = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_DAMPING, + PARAM_LINEAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer3D::G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT, + PARAM_ANGULAR_LOWER_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_LOWER_LIMIT, + PARAM_ANGULAR_UPPER_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_UPPER_LIMIT, + PARAM_ANGULAR_LIMIT_SOFTNESS = PhysicsServer3D::G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS, + PARAM_ANGULAR_DAMPING = PhysicsServer3D::G6DOF_JOINT_ANGULAR_DAMPING, + PARAM_ANGULAR_RESTITUTION = PhysicsServer3D::G6DOF_JOINT_ANGULAR_RESTITUTION, + PARAM_ANGULAR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_FORCE_LIMIT, + PARAM_ANGULAR_ERP = PhysicsServer3D::G6DOF_JOINT_ANGULAR_ERP, + PARAM_ANGULAR_MOTOR_TARGET_VELOCITY = PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY, + PARAM_ANGULAR_MOTOR_FORCE_LIMIT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT, + PARAM_ANGULAR_SPRING_STIFFNESS = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS, + PARAM_ANGULAR_SPRING_DAMPING = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_DAMPING, + PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT = PhysicsServer3D::G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT, + PARAM_MAX = PhysicsServer3D::G6DOF_JOINT_MAX, + }; + + enum Flag { + FLAG_ENABLE_LINEAR_LIMIT = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT, + FLAG_ENABLE_ANGULAR_LIMIT = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT, + FLAG_ENABLE_LINEAR_SPRING = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING, + FLAG_ENABLE_ANGULAR_SPRING = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING, + FLAG_ENABLE_MOTOR = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_MOTOR, + FLAG_ENABLE_LINEAR_MOTOR = PhysicsServer3D::G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR, + FLAG_MAX = PhysicsServer3D::G6DOF_JOINT_FLAG_MAX + }; + +protected: + void _set_angular_hi_limit_x(float p_limit_angular); + float _get_angular_hi_limit_x() const; + + void _set_angular_hi_limit_y(float p_limit_angular); + float _get_angular_hi_limit_y() const; + + void _set_angular_hi_limit_z(float p_limit_angular); + float _get_angular_hi_limit_z() const; + + void _set_angular_lo_limit_x(float p_limit_angular); + float _get_angular_lo_limit_x() const; + + void _set_angular_lo_limit_y(float p_limit_angular); + float _get_angular_lo_limit_y() const; + + void _set_angular_lo_limit_z(float p_limit_angular); + float _get_angular_lo_limit_z() const; + + float params_x[PARAM_MAX]; + bool flags_x[FLAG_MAX]; + float params_y[PARAM_MAX]; + bool flags_y[FLAG_MAX]; + float params_z[PARAM_MAX]; + bool flags_z[FLAG_MAX]; + + int precision; + + virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b); + static void _bind_methods(); + +public: + void set_param_x(Param p_param, float p_value); + float get_param_x(Param p_param) const; + + void set_param_y(Param p_param, float p_value); + float get_param_y(Param p_param) const; + + void set_param_z(Param p_param, float p_value); + float get_param_z(Param p_param) const; + + void set_flag_x(Flag p_flag, bool p_enabled); + bool get_flag_x(Flag p_flag) const; + + void set_flag_y(Flag p_flag, bool p_enabled); + bool get_flag_y(Flag p_flag) const; + + void set_flag_z(Flag p_flag, bool p_enabled); + bool get_flag_z(Flag p_flag) const; + + void set_precision(int p_precision); + int get_precision() const { + return precision; + } + + Generic6DOFJoint3D(); +}; + +VARIANT_ENUM_CAST(Generic6DOFJoint3D::Param); +VARIANT_ENUM_CAST(Generic6DOFJoint3D::Flag); + +#endif // PHYSICS_JOINT_H diff --git a/scene/3d/position_3d.h b/scene/3d/position_3d.h index cd5080c95a..9c806723fb 100644 --- a/scene/3d/position_3d.h +++ b/scene/3d/position_3d.h @@ -31,11 +31,11 @@ #ifndef POSITION_3D_H #define POSITION_3D_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class Position3D : public Spatial { +class Position3D : public Node3D { - GDCLASS(Position3D, Spatial); + GDCLASS(Position3D, Node3D); public: Position3D(); diff --git a/scene/3d/proximity_group.cpp b/scene/3d/proximity_group_3d.cpp index 2e1478b1cf..44ffabb655 100644 --- a/scene/3d/proximity_group.cpp +++ b/scene/3d/proximity_group_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* proximity_group.cpp */ +/* proximity_group_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,11 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "proximity_group.h" +#include "proximity_group_3d.h" #include "core/math/math_funcs.h" -void ProximityGroup::clear_groups() { +void ProximityGroup3D::clear_groups() { Map<StringName, uint32_t>::Element *E; @@ -60,7 +60,7 @@ void ProximityGroup::clear_groups() { }; }; -void ProximityGroup::update_groups() { +void ProximityGroup3D::update_groups() { if (grid_radius == Vector3(0, 0, 0)) return; @@ -76,7 +76,7 @@ void ProximityGroup::update_groups() { clear_groups(); }; -void ProximityGroup::add_groups(int *p_cell, String p_base, int p_depth) { +void ProximityGroup3D::add_groups(int *p_cell, String p_base, int p_depth) { p_base = p_base + "|"; if (grid_radius[p_depth] == 0) { @@ -102,7 +102,7 @@ void ProximityGroup::add_groups(int *p_cell, String p_base, int p_depth) { }; }; -void ProximityGroup::_new_group(StringName p_name) { +void ProximityGroup3D::_new_group(StringName p_name) { const Map<StringName, uint32_t>::Element *E = groups.find(p_name); if (!E) { @@ -112,7 +112,7 @@ void ProximityGroup::_new_group(StringName p_name) { groups[p_name] = group_version; }; -void ProximityGroup::_notification(int p_what) { +void ProximityGroup3D::_notification(int p_what) { switch (p_what) { @@ -126,7 +126,7 @@ void ProximityGroup::_notification(int p_what) { }; }; -void ProximityGroup::broadcast(String p_name, Variant p_params) { +void ProximityGroup3D::broadcast(String p_name, Variant p_params) { Map<StringName, uint32_t>::Element *E; E = groups.front(); @@ -137,7 +137,7 @@ void ProximityGroup::broadcast(String p_name, Variant p_params) { }; }; -void ProximityGroup::_proximity_group_broadcast(String p_name, Variant p_params) { +void ProximityGroup3D::_proximity_group_broadcast(String p_name, Variant p_params) { if (dispatch_mode == MODE_PROXY) { @@ -148,46 +148,46 @@ void ProximityGroup::_proximity_group_broadcast(String p_name, Variant p_params) }; }; -void ProximityGroup::set_group_name(const String &p_group_name) { +void ProximityGroup3D::set_group_name(const String &p_group_name) { group_name = p_group_name; }; -String ProximityGroup::get_group_name() const { +String ProximityGroup3D::get_group_name() const { return group_name; }; -void ProximityGroup::set_dispatch_mode(DispatchMode p_mode) { +void ProximityGroup3D::set_dispatch_mode(DispatchMode p_mode) { dispatch_mode = p_mode; }; -ProximityGroup::DispatchMode ProximityGroup::get_dispatch_mode() const { +ProximityGroup3D::DispatchMode ProximityGroup3D::get_dispatch_mode() const { return dispatch_mode; }; -void ProximityGroup::set_grid_radius(const Vector3 &p_radius) { +void ProximityGroup3D::set_grid_radius(const Vector3 &p_radius) { grid_radius = p_radius; }; -Vector3 ProximityGroup::get_grid_radius() const { +Vector3 ProximityGroup3D::get_grid_radius() const { return grid_radius; }; -void ProximityGroup::_bind_methods() { +void ProximityGroup3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_group_name", "name"), &ProximityGroup::set_group_name); - ClassDB::bind_method(D_METHOD("get_group_name"), &ProximityGroup::get_group_name); - ClassDB::bind_method(D_METHOD("set_dispatch_mode", "mode"), &ProximityGroup::set_dispatch_mode); - ClassDB::bind_method(D_METHOD("get_dispatch_mode"), &ProximityGroup::get_dispatch_mode); - ClassDB::bind_method(D_METHOD("set_grid_radius", "radius"), &ProximityGroup::set_grid_radius); - ClassDB::bind_method(D_METHOD("get_grid_radius"), &ProximityGroup::get_grid_radius); - ClassDB::bind_method(D_METHOD("broadcast", "name", "parameters"), &ProximityGroup::broadcast); - ClassDB::bind_method(D_METHOD("_proximity_group_broadcast", "name", "params"), &ProximityGroup::_proximity_group_broadcast); + ClassDB::bind_method(D_METHOD("set_group_name", "name"), &ProximityGroup3D::set_group_name); + ClassDB::bind_method(D_METHOD("get_group_name"), &ProximityGroup3D::get_group_name); + ClassDB::bind_method(D_METHOD("set_dispatch_mode", "mode"), &ProximityGroup3D::set_dispatch_mode); + ClassDB::bind_method(D_METHOD("get_dispatch_mode"), &ProximityGroup3D::get_dispatch_mode); + ClassDB::bind_method(D_METHOD("set_grid_radius", "radius"), &ProximityGroup3D::set_grid_radius); + ClassDB::bind_method(D_METHOD("get_grid_radius"), &ProximityGroup3D::get_grid_radius); + ClassDB::bind_method(D_METHOD("broadcast", "name", "parameters"), &ProximityGroup3D::broadcast); + ClassDB::bind_method(D_METHOD("_proximity_group_broadcast", "name", "params"), &ProximityGroup3D::_proximity_group_broadcast); ADD_PROPERTY(PropertyInfo(Variant::STRING, "group_name"), "set_group_name", "get_group_name"); ADD_PROPERTY(PropertyInfo(Variant::INT, "dispatch_mode", PROPERTY_HINT_ENUM, "Proxy,Signal"), "set_dispatch_mode", "get_dispatch_mode"); @@ -199,7 +199,7 @@ void ProximityGroup::_bind_methods() { BIND_ENUM_CONSTANT(MODE_SIGNAL); }; -ProximityGroup::ProximityGroup() { +ProximityGroup3D::ProximityGroup3D() { group_version = 0; dispatch_mode = MODE_PROXY; @@ -209,6 +209,6 @@ ProximityGroup::ProximityGroup() { set_notify_transform(true); }; -ProximityGroup::~ProximityGroup(){ +ProximityGroup3D::~ProximityGroup3D(){ }; diff --git a/scene/3d/proximity_group.h b/scene/3d/proximity_group_3d.h index 9ff8853178..751bfbdb52 100644 --- a/scene/3d/proximity_group.h +++ b/scene/3d/proximity_group_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* proximity_group.h */ +/* proximity_group_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,11 +31,11 @@ #ifndef PROXIMITY_GROUP_H #define PROXIMITY_GROUP_H -#include "spatial.h" +#include "node_3d.h" -class ProximityGroup : public Spatial { +class ProximityGroup3D : public Node3D { - GDCLASS(ProximityGroup, Spatial); + GDCLASS(ProximityGroup3D, Node3D); OBJ_CATEGORY("3D"); public: @@ -78,10 +78,10 @@ public: void broadcast(String p_name, Variant p_params); - ProximityGroup(); - ~ProximityGroup(); + ProximityGroup3D(); + ~ProximityGroup3D(); }; -VARIANT_ENUM_CAST(ProximityGroup::DispatchMode); +VARIANT_ENUM_CAST(ProximityGroup3D::DispatchMode); #endif diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast_3d.cpp index f6eb3d954a..a18da61656 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* ray_cast.cpp */ +/* ray_cast_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "ray_cast.h" +#include "ray_cast_3d.h" -#include "collision_object.h" +#include "collision_object_3d.h" #include "core/engine.h" -#include "mesh_instance.h" -#include "servers/physics_server.h" +#include "mesh_instance_3d.h" +#include "servers/physics_server_3d.h" -void RayCast::set_cast_to(const Vector3 &p_point) { +void RayCast3D::set_cast_to(const Vector3 &p_point) { cast_to = p_point; if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) @@ -44,22 +44,22 @@ void RayCast::set_cast_to(const Vector3 &p_point) { _update_debug_shape(); } -Vector3 RayCast::get_cast_to() const { +Vector3 RayCast3D::get_cast_to() const { return cast_to; } -void RayCast::set_collision_mask(uint32_t p_mask) { +void RayCast3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; } -uint32_t RayCast::get_collision_mask() const { +uint32_t RayCast3D::get_collision_mask() const { return collision_mask; } -void RayCast::set_collision_mask_bit(int p_bit, bool p_value) { +void RayCast3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) @@ -69,37 +69,37 @@ void RayCast::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool RayCast::get_collision_mask_bit(int p_bit) const { +bool RayCast3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -bool RayCast::is_colliding() const { +bool RayCast3D::is_colliding() const { return collided; } -Object *RayCast::get_collider() const { +Object *RayCast3D::get_collider() const { if (against.is_null()) - return NULL; + return nullptr; return ObjectDB::get_instance(against); } -int RayCast::get_collider_shape() const { +int RayCast3D::get_collider_shape() const { return against_shape; } -Vector3 RayCast::get_collision_point() const { +Vector3 RayCast3D::get_collision_point() const { return collision_point; } -Vector3 RayCast::get_collision_normal() const { +Vector3 RayCast3D::get_collision_normal() const { return collision_normal; } -void RayCast::set_enabled(bool p_enabled) { +void RayCast3D::set_enabled(bool p_enabled) { enabled = p_enabled; update_gizmo(); @@ -117,12 +117,12 @@ void RayCast::set_enabled(bool p_enabled) { } } -bool RayCast::is_enabled() const { +bool RayCast3D::is_enabled() const { return enabled; } -void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) { +void RayCast3D::set_exclude_parent_body(bool p_exclude_parent_body) { if (exclude_parent_body == p_exclude_parent_body) return; @@ -132,20 +132,20 @@ void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) { if (!is_inside_tree()) return; - if (Object::cast_to<CollisionObject>(get_parent())) { + if (Object::cast_to<CollisionObject3D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); } } -bool RayCast::get_exclude_parent_body() const { +bool RayCast3D::get_exclude_parent_body() const { return exclude_parent_body; } -void RayCast::_notification(int p_what) { +void RayCast3D::_notification(int p_what) { switch (p_what) { @@ -159,11 +159,11 @@ void RayCast::_notification(int p_what) { } else set_physics_process_internal(false); - if (Object::cast_to<CollisionObject>(get_parent())) { + if (Object::cast_to<CollisionObject3D>(get_parent())) { if (exclude_parent_body) - exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); else - exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid()); } } break; @@ -195,11 +195,11 @@ void RayCast::_notification(int p_what) { } } -void RayCast::_update_raycast_state() { - Ref<World> w3d = get_world(); +void RayCast3D::_update_raycast_state() { + Ref<World3D> w3d = get_world(); ERR_FAIL_COND(w3d.is_null()); - PhysicsDirectSpaceState *dss = PhysicsServer::get_singleton()->space_get_direct_state(w3d->get_space()); + PhysicsDirectSpaceState3D *dss = PhysicsServer3D::get_singleton()->space_get_direct_state(w3d->get_space()); ERR_FAIL_COND(!dss); Transform gt = get_global_transform(); @@ -208,7 +208,7 @@ void RayCast::_update_raycast_state() { if (to == Vector3()) to = Vector3(0, 0.01, 0); - PhysicsDirectSpaceState::RayResult rr; + PhysicsDirectSpaceState3D::RayResult rr; if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, collision_mask, collide_with_bodies, collide_with_areas)) { @@ -224,101 +224,101 @@ void RayCast::_update_raycast_state() { } } -void RayCast::force_raycast_update() { +void RayCast3D::force_raycast_update() { _update_raycast_state(); } -void RayCast::add_exception_rid(const RID &p_rid) { +void RayCast3D::add_exception_rid(const RID &p_rid) { exclude.insert(p_rid); } -void RayCast::add_exception(const Object *p_object) { +void RayCast3D::add_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; add_exception_rid(co->get_rid()); } -void RayCast::remove_exception_rid(const RID &p_rid) { +void RayCast3D::remove_exception_rid(const RID &p_rid) { exclude.erase(p_rid); } -void RayCast::remove_exception(const Object *p_object) { +void RayCast3D::remove_exception(const Object *p_object) { ERR_FAIL_NULL(p_object); - const CollisionObject *co = Object::cast_to<CollisionObject>(p_object); + const CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_object); if (!co) return; remove_exception_rid(co->get_rid()); } -void RayCast::clear_exceptions() { +void RayCast3D::clear_exceptions() { exclude.clear(); } -void RayCast::set_collide_with_areas(bool p_clip) { +void RayCast3D::set_collide_with_areas(bool p_clip) { collide_with_areas = p_clip; } -bool RayCast::is_collide_with_areas_enabled() const { +bool RayCast3D::is_collide_with_areas_enabled() const { return collide_with_areas; } -void RayCast::set_collide_with_bodies(bool p_clip) { +void RayCast3D::set_collide_with_bodies(bool p_clip) { collide_with_bodies = p_clip; } -bool RayCast::is_collide_with_bodies_enabled() const { +bool RayCast3D::is_collide_with_bodies_enabled() const { return collide_with_bodies; } -void RayCast::_bind_methods() { +void RayCast3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast::set_enabled); - ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast::is_enabled); + ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast3D::set_enabled); + ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast3D::is_enabled); - ClassDB::bind_method(D_METHOD("set_cast_to", "local_point"), &RayCast::set_cast_to); - ClassDB::bind_method(D_METHOD("get_cast_to"), &RayCast::get_cast_to); + ClassDB::bind_method(D_METHOD("set_cast_to", "local_point"), &RayCast3D::set_cast_to); + ClassDB::bind_method(D_METHOD("get_cast_to"), &RayCast3D::get_cast_to); - ClassDB::bind_method(D_METHOD("is_colliding"), &RayCast::is_colliding); - ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast::force_raycast_update); + ClassDB::bind_method(D_METHOD("is_colliding"), &RayCast3D::is_colliding); + ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast3D::force_raycast_update); - ClassDB::bind_method(D_METHOD("get_collider"), &RayCast::get_collider); - ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast::get_collider_shape); - ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast::get_collision_point); - ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast::get_collision_normal); + ClassDB::bind_method(D_METHOD("get_collider"), &RayCast3D::get_collider); + ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast3D::get_collider_shape); + ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast3D::get_collision_point); + ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast3D::get_collision_normal); - ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &RayCast::add_exception_rid); - ClassDB::bind_method(D_METHOD("add_exception", "node"), &RayCast::add_exception); + ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &RayCast3D::add_exception_rid); + ClassDB::bind_method(D_METHOD("add_exception", "node"), &RayCast3D::add_exception); - ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &RayCast::remove_exception_rid); - ClassDB::bind_method(D_METHOD("remove_exception", "node"), &RayCast::remove_exception); + ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &RayCast3D::remove_exception_rid); + ClassDB::bind_method(D_METHOD("remove_exception", "node"), &RayCast3D::remove_exception); - ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast::clear_exceptions); + ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast3D::clear_exceptions); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &RayCast::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &RayCast::get_collision_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &RayCast3D::set_collision_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &RayCast3D::get_collision_mask); - ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast::set_exclude_parent_body); - ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast::get_exclude_parent_body); + ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast3D::set_exclude_parent_body); + ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast3D::get_exclude_parent_body); - ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &RayCast::set_collide_with_areas); - ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &RayCast::is_collide_with_areas_enabled); + ClassDB::bind_method(D_METHOD("set_collide_with_areas", "enable"), &RayCast3D::set_collide_with_areas); + ClassDB::bind_method(D_METHOD("is_collide_with_areas_enabled"), &RayCast3D::is_collide_with_areas_enabled); - ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast::set_collide_with_bodies); - ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast::is_collide_with_bodies_enabled); + ClassDB::bind_method(D_METHOD("set_collide_with_bodies", "enable"), &RayCast3D::set_collide_with_bodies); + ClassDB::bind_method(D_METHOD("is_collide_with_bodies_enabled"), &RayCast3D::is_collide_with_bodies_enabled); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); @@ -330,7 +330,7 @@ void RayCast::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collide_with_bodies", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collide_with_bodies", "is_collide_with_bodies_enabled"); } -void RayCast::_create_debug_shape() { +void RayCast3D::_create_debug_shape() { if (!debug_material.is_valid()) { debug_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D)); @@ -342,14 +342,14 @@ void RayCast::_create_debug_shape() { Ref<ArrayMesh> mesh = memnew(ArrayMesh); - MeshInstance *mi = memnew(MeshInstance); + MeshInstance3D *mi = memnew(MeshInstance3D); mi->set_mesh(mesh); add_child(mi); debug_shape = mi; } -void RayCast::_update_debug_shape() { +void RayCast3D::_update_debug_shape() { if (!enabled) return; @@ -357,7 +357,7 @@ void RayCast::_update_debug_shape() { if (!debug_shape) _create_debug_shape(); - MeshInstance *mi = static_cast<MeshInstance *>(debug_shape); + MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape); if (!mi->get_mesh().is_valid()) return; @@ -376,21 +376,21 @@ void RayCast::_update_debug_shape() { mesh->surface_set_material(0, debug_material); } -void RayCast::_clear_debug_shape() { +void RayCast3D::_clear_debug_shape() { if (!debug_shape) return; - MeshInstance *mi = static_cast<MeshInstance *>(debug_shape); + MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape); if (mi->is_inside_tree()) mi->queue_delete(); else memdelete(mi); - debug_shape = NULL; + debug_shape = nullptr; } -RayCast::RayCast() { +RayCast3D::RayCast3D() { enabled = false; @@ -398,7 +398,7 @@ RayCast::RayCast() { against_shape = 0; collision_mask = 1; cast_to = Vector3(0, -1, 0); - debug_shape = NULL; + debug_shape = nullptr; exclude_parent_body = true; collide_with_areas = false; collide_with_bodies = true; diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast_3d.h index 5cebfe3ac2..f8bfb7846a 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* ray_cast.h */ +/* ray_cast_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,14 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef RAY_CAST_H -#define RAY_CAST_H +#ifndef RAY_CAST_3D_H +#define RAY_CAST_3D_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class RayCast : public Spatial { +class RayCast3D : public Node3D { - GDCLASS(RayCast, Spatial); + GDCLASS(RayCast3D, Node3D); bool enabled; bool collided; @@ -100,7 +100,7 @@ public: void remove_exception(const Object *p_object); void clear_exceptions(); - RayCast(); + RayCast3D(); }; #endif // RAY_CAST_H diff --git a/scene/3d/reflection_probe.cpp b/scene/3d/reflection_probe.cpp index 3cf8e43ec2..24bf8b43d1 100644 --- a/scene/3d/reflection_probe.cpp +++ b/scene/3d/reflection_probe.cpp @@ -33,7 +33,7 @@ void ReflectionProbe::set_intensity(float p_intensity) { intensity = p_intensity; - VS::get_singleton()->reflection_probe_set_intensity(probe, p_intensity); + RS::get_singleton()->reflection_probe_set_intensity(probe, p_intensity); } float ReflectionProbe::get_intensity() const { @@ -44,12 +44,12 @@ float ReflectionProbe::get_intensity() const { void ReflectionProbe::set_interior_ambient(Color p_ambient) { interior_ambient = p_ambient; - VS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient); + RS::get_singleton()->reflection_probe_set_interior_ambient(probe, p_ambient); } void ReflectionProbe::set_interior_ambient_energy(float p_energy) { interior_ambient_energy = p_energy; - VS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy); + RS::get_singleton()->reflection_probe_set_interior_ambient_energy(probe, p_energy); } float ReflectionProbe::get_interior_ambient_energy() const { @@ -64,7 +64,7 @@ Color ReflectionProbe::get_interior_ambient() const { void ReflectionProbe::set_interior_ambient_probe_contribution(float p_contribution) { interior_ambient_probe_contribution = p_contribution; - VS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution); + RS::get_singleton()->reflection_probe_set_interior_ambient_probe_contribution(probe, p_contribution); } float ReflectionProbe::get_interior_ambient_probe_contribution() const { @@ -75,7 +75,7 @@ float ReflectionProbe::get_interior_ambient_probe_contribution() const { void ReflectionProbe::set_max_distance(float p_distance) { max_distance = p_distance; - VS::get_singleton()->reflection_probe_set_max_distance(probe, p_distance); + RS::get_singleton()->reflection_probe_set_max_distance(probe, p_distance); } float ReflectionProbe::get_max_distance() const { @@ -97,8 +97,8 @@ void ReflectionProbe::set_extents(const Vector3 &p_extents) { } } - VS::get_singleton()->reflection_probe_set_extents(probe, extents); - VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); + RS::get_singleton()->reflection_probe_set_extents(probe, extents); + RS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); _change_notify("extents"); update_gizmo(); } @@ -117,8 +117,8 @@ void ReflectionProbe::set_origin_offset(const Vector3 &p_extents) { origin_offset[i] = SGN(origin_offset[i]) * (extents[i] - 0.01); } } - VS::get_singleton()->reflection_probe_set_extents(probe, extents); - VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); + RS::get_singleton()->reflection_probe_set_extents(probe, extents); + RS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset); _change_notify("origin_offset"); update_gizmo(); @@ -131,7 +131,7 @@ Vector3 ReflectionProbe::get_origin_offset() const { void ReflectionProbe::set_enable_box_projection(bool p_enable) { box_projection = p_enable; - VS::get_singleton()->reflection_probe_set_enable_box_projection(probe, p_enable); + RS::get_singleton()->reflection_probe_set_enable_box_projection(probe, p_enable); } bool ReflectionProbe::is_box_projection_enabled() const { @@ -141,7 +141,7 @@ bool ReflectionProbe::is_box_projection_enabled() const { void ReflectionProbe::set_as_interior(bool p_enable) { interior = p_enable; - VS::get_singleton()->reflection_probe_set_as_interior(probe, interior); + RS::get_singleton()->reflection_probe_set_as_interior(probe, interior); _change_notify(); } @@ -153,7 +153,7 @@ bool ReflectionProbe::is_set_as_interior() const { void ReflectionProbe::set_enable_shadows(bool p_enable) { enable_shadows = p_enable; - VS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_enable); + RS::get_singleton()->reflection_probe_set_enable_shadows(probe, p_enable); } bool ReflectionProbe::are_shadows_enabled() const { @@ -163,7 +163,7 @@ bool ReflectionProbe::are_shadows_enabled() const { void ReflectionProbe::set_cull_mask(uint32_t p_layers) { cull_mask = p_layers; - VS::get_singleton()->reflection_probe_set_cull_mask(probe, p_layers); + RS::get_singleton()->reflection_probe_set_cull_mask(probe, p_layers); } uint32_t ReflectionProbe::get_cull_mask() const { @@ -172,7 +172,7 @@ uint32_t ReflectionProbe::get_cull_mask() const { void ReflectionProbe::set_update_mode(UpdateMode p_mode) { update_mode = p_mode; - VS::get_singleton()->reflection_probe_set_update_mode(probe, VS::ReflectionProbeUpdateMode(p_mode)); + RS::get_singleton()->reflection_probe_set_update_mode(probe, RS::ReflectionProbeUpdateMode(p_mode)); } ReflectionProbe::UpdateMode ReflectionProbe::get_update_mode() const { @@ -272,12 +272,12 @@ ReflectionProbe::ReflectionProbe() { cull_mask = (1 << 20) - 1; update_mode = UPDATE_ONCE; - probe = VisualServer::get_singleton()->reflection_probe_create(); - VS::get_singleton()->instance_set_base(get_instance(), probe); + probe = RenderingServer::get_singleton()->reflection_probe_create(); + RS::get_singleton()->instance_set_base(get_instance(), probe); set_disable_scale(true); } ReflectionProbe::~ReflectionProbe() { - VS::get_singleton()->free(probe); + RS::get_singleton()->free(probe); } diff --git a/scene/3d/reflection_probe.h b/scene/3d/reflection_probe.h index 57c1b0a320..3867d13435 100644 --- a/scene/3d/reflection_probe.h +++ b/scene/3d/reflection_probe.h @@ -31,13 +31,13 @@ #ifndef REFLECTIONPROBE_H #define REFLECTIONPROBE_H -#include "scene/3d/visual_instance.h" +#include "scene/3d/visual_instance_3d.h" #include "scene/resources/sky.h" #include "scene/resources/texture.h" -#include "servers/visual_server.h" +#include "servers/rendering_server.h" -class ReflectionProbe : public VisualInstance { - GDCLASS(ReflectionProbe, VisualInstance); +class ReflectionProbe : public VisualInstance3D { + GDCLASS(ReflectionProbe, VisualInstance3D); public: enum UpdateMode { diff --git a/scene/3d/remote_transform.cpp b/scene/3d/remote_transform_3d.cpp index 9ef43647ba..38792bbb58 100644 --- a/scene/3d/remote_transform.cpp +++ b/scene/3d/remote_transform_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* remote_transform.cpp */ +/* remote_transform_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,9 +28,9 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "remote_transform.h" +#include "remote_transform_3d.h" -void RemoteTransform::_update_cache() { +void RemoteTransform3D::_update_cache() { cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); @@ -42,7 +42,7 @@ void RemoteTransform::_update_cache() { } } -void RemoteTransform::_update_remote() { +void RemoteTransform3D::_update_remote() { if (!is_inside_tree()) return; @@ -50,7 +50,7 @@ void RemoteTransform::_update_remote() { if (cache.is_null()) return; - Spatial *n = Object::cast_to<Spatial>(ObjectDB::get_instance(cache)); + Node3D *n = Object::cast_to<Node3D>(ObjectDB::get_instance(cache)); if (!n) return; @@ -101,7 +101,7 @@ void RemoteTransform::_update_remote() { } } -void RemoteTransform::_notification(int p_what) { +void RemoteTransform3D::_notification(int p_what) { switch (p_what) { @@ -123,7 +123,7 @@ void RemoteTransform::_notification(int p_what) { } } -void RemoteTransform::set_remote_node(const NodePath &p_remote_node) { +void RemoteTransform3D::set_remote_node(const NodePath &p_remote_node) { remote_node = p_remote_node; if (is_inside_tree()) { @@ -134,76 +134,76 @@ void RemoteTransform::set_remote_node(const NodePath &p_remote_node) { update_configuration_warning(); } -NodePath RemoteTransform::get_remote_node() const { +NodePath RemoteTransform3D::get_remote_node() const { return remote_node; } -void RemoteTransform::set_use_global_coordinates(const bool p_enable) { +void RemoteTransform3D::set_use_global_coordinates(const bool p_enable) { use_global_coordinates = p_enable; } -bool RemoteTransform::get_use_global_coordinates() const { +bool RemoteTransform3D::get_use_global_coordinates() const { return use_global_coordinates; } -void RemoteTransform::set_update_position(const bool p_update) { +void RemoteTransform3D::set_update_position(const bool p_update) { update_remote_position = p_update; _update_remote(); } -bool RemoteTransform::get_update_position() const { +bool RemoteTransform3D::get_update_position() const { return update_remote_position; } -void RemoteTransform::set_update_rotation(const bool p_update) { +void RemoteTransform3D::set_update_rotation(const bool p_update) { update_remote_rotation = p_update; _update_remote(); } -bool RemoteTransform::get_update_rotation() const { +bool RemoteTransform3D::get_update_rotation() const { return update_remote_rotation; } -void RemoteTransform::set_update_scale(const bool p_update) { +void RemoteTransform3D::set_update_scale(const bool p_update) { update_remote_scale = p_update; _update_remote(); } -bool RemoteTransform::get_update_scale() const { +bool RemoteTransform3D::get_update_scale() const { return update_remote_scale; } -void RemoteTransform::force_update_cache() { +void RemoteTransform3D::force_update_cache() { _update_cache(); } -String RemoteTransform::get_configuration_warning() const { +String RemoteTransform3D::get_configuration_warning() const { - if (!has_node(remote_node) || !Object::cast_to<Spatial>(get_node(remote_node))) { - return TTR("The \"Remote Path\" property must point to a valid Spatial or Spatial-derived node to work."); + if (!has_node(remote_node) || !Object::cast_to<Node3D>(get_node(remote_node))) { + return TTR("The \"Remote Path\" property must point to a valid Node3D or Node3D-derived node to work."); } return String(); } -void RemoteTransform::_bind_methods() { +void RemoteTransform3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform::set_remote_node); - ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform::get_remote_node); - ClassDB::bind_method(D_METHOD("force_update_cache"), &RemoteTransform::force_update_cache); + ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform3D::set_remote_node); + ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform3D::get_remote_node); + ClassDB::bind_method(D_METHOD("force_update_cache"), &RemoteTransform3D::force_update_cache); - ClassDB::bind_method(D_METHOD("set_use_global_coordinates", "use_global_coordinates"), &RemoteTransform::set_use_global_coordinates); - ClassDB::bind_method(D_METHOD("get_use_global_coordinates"), &RemoteTransform::get_use_global_coordinates); + ClassDB::bind_method(D_METHOD("set_use_global_coordinates", "use_global_coordinates"), &RemoteTransform3D::set_use_global_coordinates); + ClassDB::bind_method(D_METHOD("get_use_global_coordinates"), &RemoteTransform3D::get_use_global_coordinates); - ClassDB::bind_method(D_METHOD("set_update_position", "update_remote_position"), &RemoteTransform::set_update_position); - ClassDB::bind_method(D_METHOD("get_update_position"), &RemoteTransform::get_update_position); - ClassDB::bind_method(D_METHOD("set_update_rotation", "update_remote_rotation"), &RemoteTransform::set_update_rotation); - ClassDB::bind_method(D_METHOD("get_update_rotation"), &RemoteTransform::get_update_rotation); - ClassDB::bind_method(D_METHOD("set_update_scale", "update_remote_scale"), &RemoteTransform::set_update_scale); - ClassDB::bind_method(D_METHOD("get_update_scale"), &RemoteTransform::get_update_scale); + ClassDB::bind_method(D_METHOD("set_update_position", "update_remote_position"), &RemoteTransform3D::set_update_position); + ClassDB::bind_method(D_METHOD("get_update_position"), &RemoteTransform3D::get_update_position); + ClassDB::bind_method(D_METHOD("set_update_rotation", "update_remote_rotation"), &RemoteTransform3D::set_update_rotation); + ClassDB::bind_method(D_METHOD("get_update_rotation"), &RemoteTransform3D::get_update_rotation); + ClassDB::bind_method(D_METHOD("set_update_scale", "update_remote_scale"), &RemoteTransform3D::set_update_scale); + ClassDB::bind_method(D_METHOD("get_update_scale"), &RemoteTransform3D::get_update_scale); - ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "remote_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Spatial"), "set_remote_node", "get_remote_node"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "remote_path", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "Node3D"), "set_remote_node", "get_remote_node"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_global_coordinates"), "set_use_global_coordinates", "get_use_global_coordinates"); ADD_GROUP("Update", "update_"); @@ -212,7 +212,7 @@ void RemoteTransform::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "update_scale"), "set_update_scale", "get_update_scale"); } -RemoteTransform::RemoteTransform() { +RemoteTransform3D::RemoteTransform3D() { use_global_coordinates = true; update_remote_position = true; diff --git a/scene/3d/remote_transform.h b/scene/3d/remote_transform_3d.h index 02e448832f..50d7c5a9b2 100644 --- a/scene/3d/remote_transform.h +++ b/scene/3d/remote_transform_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* remote_transform.h */ +/* remote_transform_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,10 +31,10 @@ #ifndef REMOTETRANSFORM_H #define REMOTETRANSFORM_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class RemoteTransform : public Spatial { - GDCLASS(RemoteTransform, Spatial); +class RemoteTransform3D : public Node3D { + GDCLASS(RemoteTransform3D, Node3D); NodePath remote_node; @@ -72,7 +72,7 @@ public: virtual String get_configuration_warning() const; - RemoteTransform(); + RemoteTransform3D(); }; #endif // REMOTETRANSFORM_H diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton_3d.cpp index b2252bcb04..973822653a 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* skeleton.cpp */ +/* skeleton_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "skeleton.h" +#include "skeleton_3d.h" #include "core/engine.h" #include "core/message_queue.h" #include "core/project_settings.h" -#include "scene/3d/physics_body.h" +#include "core/type_info.h" +#include "scene/3d/physics_body_3d.h" #include "scene/resources/surface_tool.h" void SkinReference::_skin_changed() { @@ -62,10 +63,10 @@ SkinReference::~SkinReference() { skeleton_node->skin_bindings.erase(this); } - VS::get_singleton()->free(skeleton); + RS::get_singleton()->free(skeleton); } -bool Skeleton::_set(const StringName &p_path, const Variant &p_value) { +bool Skeleton3D::_set(const StringName &p_path, const Variant &p_value) { String path = p_path; @@ -113,7 +114,7 @@ bool Skeleton::_set(const StringName &p_path, const Variant &p_value) { return true; } -bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { +bool Skeleton3D::_get(const StringName &p_path, Variant &r_ret) const { String path = p_path; @@ -154,7 +155,7 @@ bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { return true; } -void Skeleton::_get_property_list(List<PropertyInfo> *p_list) const { +void Skeleton3D::_get_property_list(List<PropertyInfo> *p_list) const { for (int i = 0; i < bones.size(); i++) { @@ -168,7 +169,7 @@ void Skeleton::_get_property_list(List<PropertyInfo> *p_list) const { } } -void Skeleton::_update_process_order() { +void Skeleton3D::_update_process_order() { if (!process_order_dirty) return; @@ -221,13 +222,13 @@ void Skeleton::_update_process_order() { process_order_dirty = false; } -void Skeleton::_notification(int p_what) { +void Skeleton3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_UPDATE_SKELETON: { - VisualServer *vs = VisualServer::get_singleton(); + RenderingServer *vs = RenderingServer::get_singleton(); Bone *bonesptr = bones.ptrw(); int len = bones.size(); @@ -306,7 +307,7 @@ void Skeleton::_notification(int p_what) { Object *obj = ObjectDB::get_instance(E->get()); ERR_CONTINUE(!obj); - Spatial *sp = Object::cast_to<Spatial>(obj); + Node3D *sp = Object::cast_to<Node3D>(obj); ERR_CONTINUE(!sp); sp->set_transform(b.pose_global); } @@ -320,7 +321,7 @@ void Skeleton::_notification(int p_what) { uint32_t bind_count = skin->get_bind_count(); if (E->get()->bind_count != bind_count) { - VS::get_singleton()->skeleton_allocate(skeleton, bind_count); + RS::get_singleton()->skeleton_allocate(skeleton, bind_count); E->get()->bind_count = bind_count; E->get()->skin_bone_indices.resize(bind_count); E->get()->skin_bone_indices_ptrs = E->get()->skin_bone_indices.ptrw(); @@ -396,7 +397,14 @@ void Skeleton::_notification(int p_what) { } } -void Skeleton::set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent) { +void Skeleton3D::clear_bones_global_pose_override() { + for (int i = 0; i < bones.size(); i += 1) { + bones.write[i].global_pose_override_amount = 0; + } + _make_dirty(); +} + +void Skeleton3D::set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].global_pose_override_amount = p_amount; @@ -405,16 +413,16 @@ void Skeleton::set_bone_global_pose_override(int p_bone, const Transform &p_pose _make_dirty(); } -Transform Skeleton::get_bone_global_pose(int p_bone) const { +Transform Skeleton3D::get_bone_global_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); if (dirty) - const_cast<Skeleton *>(this)->notification(NOTIFICATION_UPDATE_SKELETON); + const_cast<Skeleton3D *>(this)->notification(NOTIFICATION_UPDATE_SKELETON); return bones[p_bone].pose_global; } // skeleton creation api -void Skeleton::add_bone(const String &p_name) { +void Skeleton3D::add_bone(const String &p_name) { ERR_FAIL_COND(p_name == "" || p_name.find(":") != -1 || p_name.find("/") != -1); @@ -431,7 +439,7 @@ void Skeleton::add_bone(const String &p_name) { _make_dirty(); update_gizmo(); } -int Skeleton::find_bone(const String &p_name) const { +int Skeleton3D::find_bone(const String &p_name) const { for (int i = 0; i < bones.size(); i++) { @@ -441,14 +449,14 @@ int Skeleton::find_bone(const String &p_name) const { return -1; } -String Skeleton::get_bone_name(int p_bone) const { +String Skeleton3D::get_bone_name(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), ""); return bones[p_bone].name; } -bool Skeleton::is_bone_parent_of(int p_bone, int p_parent_bone_id) const { +bool Skeleton3D::is_bone_parent_of(int p_bone, int p_parent_bone_id) const { int parent_of_bone = get_bone_parent(p_bone); @@ -461,12 +469,12 @@ bool Skeleton::is_bone_parent_of(int p_bone, int p_parent_bone_id) const { return is_bone_parent_of(parent_of_bone, p_parent_bone_id); } -int Skeleton::get_bone_count() const { +int Skeleton3D::get_bone_count() const { return bones.size(); } -void Skeleton::set_bone_parent(int p_bone, int p_parent) { +void Skeleton3D::set_bone_parent(int p_bone, int p_parent) { ERR_FAIL_INDEX(p_bone, bones.size()); ERR_FAIL_COND(p_parent != -1 && (p_parent < 0)); @@ -476,7 +484,7 @@ void Skeleton::set_bone_parent(int p_bone, int p_parent) { _make_dirty(); } -void Skeleton::unparent_bone_and_rest(int p_bone) { +void Skeleton3D::unparent_bone_and_rest(int p_bone) { ERR_FAIL_INDEX(p_bone, bones.size()); @@ -494,53 +502,53 @@ void Skeleton::unparent_bone_and_rest(int p_bone) { _make_dirty(); } -void Skeleton::set_bone_disable_rest(int p_bone, bool p_disable) { +void Skeleton3D::set_bone_disable_rest(int p_bone, bool p_disable) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].disable_rest = p_disable; } -bool Skeleton::is_bone_rest_disabled(int p_bone) const { +bool Skeleton3D::is_bone_rest_disabled(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), false); return bones[p_bone].disable_rest; } -int Skeleton::get_bone_parent(int p_bone) const { +int Skeleton3D::get_bone_parent(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), -1); return bones[p_bone].parent; } -void Skeleton::set_bone_rest(int p_bone, const Transform &p_rest) { +void Skeleton3D::set_bone_rest(int p_bone, const Transform &p_rest) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].rest = p_rest; _make_dirty(); } -Transform Skeleton::get_bone_rest(int p_bone) const { +Transform Skeleton3D::get_bone_rest(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); return bones[p_bone].rest; } -void Skeleton::set_bone_enabled(int p_bone, bool p_enabled) { +void Skeleton3D::set_bone_enabled(int p_bone, bool p_enabled) { ERR_FAIL_INDEX(p_bone, bones.size()); bones.write[p_bone].enabled = p_enabled; _make_dirty(); } -bool Skeleton::is_bone_enabled(int p_bone) const { +bool Skeleton3D::is_bone_enabled(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), false); return bones[p_bone].enabled; } -void Skeleton::bind_child_node_to_bone(int p_bone, Node *p_node) { +void Skeleton3D::bind_child_node_to_bone(int p_bone, Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX(p_bone, bones.size()); @@ -555,7 +563,7 @@ void Skeleton::bind_child_node_to_bone(int p_bone, Node *p_node) { bones.write[p_bone].nodes_bound.push_back(id); } -void Skeleton::unbind_child_node_from_bone(int p_bone, Node *p_node) { +void Skeleton3D::unbind_child_node_from_bone(int p_bone, Node *p_node) { ERR_FAIL_NULL(p_node); ERR_FAIL_INDEX(p_bone, bones.size()); @@ -563,7 +571,7 @@ void Skeleton::unbind_child_node_from_bone(int p_bone, Node *p_node) { ObjectID id = p_node->get_instance_id(); bones.write[p_bone].nodes_bound.erase(id); } -void Skeleton::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const { +void Skeleton3D::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const { ERR_FAIL_INDEX(p_bone, bones.size()); @@ -575,7 +583,7 @@ void Skeleton::get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) } } -void Skeleton::clear_bones() { +void Skeleton3D::clear_bones() { bones.clear(); process_order_dirty = true; @@ -585,7 +593,7 @@ void Skeleton::clear_bones() { // posing api -void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) { +void Skeleton3D::set_bone_pose(int p_bone, const Transform &p_pose) { ERR_FAIL_INDEX(p_bone, bones.size()); @@ -594,13 +602,13 @@ void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) { _make_dirty(); } } -Transform Skeleton::get_bone_pose(int p_bone) const { +Transform Skeleton3D::get_bone_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); return bones[p_bone].pose; } -void Skeleton::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) { +void Skeleton3D::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) { ERR_FAIL_INDEX(p_bone, bones.size()); //ERR_FAIL_COND( !is_inside_scene() ); @@ -611,13 +619,13 @@ void Skeleton::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) _make_dirty(); } -Transform Skeleton::get_bone_custom_pose(int p_bone) const { +Transform Skeleton3D::get_bone_custom_pose(int p_bone) const { ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); return bones[p_bone].custom_pose; } -void Skeleton::_make_dirty() { +void Skeleton3D::_make_dirty() { if (dirty) return; @@ -626,13 +634,13 @@ void Skeleton::_make_dirty() { dirty = true; } -int Skeleton::get_process_order(int p_idx) { +int Skeleton3D::get_process_order(int p_idx) { ERR_FAIL_INDEX_V(p_idx, bones.size(), -1); _update_process_order(); return process_order[p_idx]; } -void Skeleton::localize_rests() { +void Skeleton3D::localize_rests() { _update_process_order(); @@ -646,7 +654,7 @@ void Skeleton::localize_rests() { #ifndef _3D_DISABLED -void Skeleton::set_animate_physical_bones(bool p_animate) { +void Skeleton3D::set_animate_physical_bones(bool p_animate) { animate_physical_bones = p_animate; if (Engine::get_singleton()->is_editor_hint() == false) { @@ -663,11 +671,11 @@ void Skeleton::set_animate_physical_bones(bool p_animate) { } } -bool Skeleton::get_animate_physical_bones() const { +bool Skeleton3D::get_animate_physical_bones() const { return animate_physical_bones; } -void Skeleton::bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_bone) { +void Skeleton3D::bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physical_bone) { ERR_FAIL_INDEX(p_bone, bones.size()); ERR_FAIL_COND(bones[p_bone].physical_bone); ERR_FAIL_COND(!p_physical_bone); @@ -676,21 +684,21 @@ void Skeleton::bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_b _rebuild_physical_bones_cache(); } -void Skeleton::unbind_physical_bone_from_bone(int p_bone) { +void Skeleton3D::unbind_physical_bone_from_bone(int p_bone) { ERR_FAIL_INDEX(p_bone, bones.size()); - bones.write[p_bone].physical_bone = NULL; + bones.write[p_bone].physical_bone = nullptr; _rebuild_physical_bones_cache(); } -PhysicalBone *Skeleton::get_physical_bone(int p_bone) { - ERR_FAIL_INDEX_V(p_bone, bones.size(), NULL); +PhysicalBone3D *Skeleton3D::get_physical_bone(int p_bone) { + ERR_FAIL_INDEX_V(p_bone, bones.size(), nullptr); return bones[p_bone].physical_bone; } -PhysicalBone *Skeleton::get_physical_bone_parent(int p_bone) { - ERR_FAIL_INDEX_V(p_bone, bones.size(), NULL); +PhysicalBone3D *Skeleton3D::get_physical_bone_parent(int p_bone) { + ERR_FAIL_INDEX_V(p_bone, bones.size(), nullptr); if (bones[p_bone].cache_parent_physical_bone) { return bones[p_bone].cache_parent_physical_bone; @@ -699,15 +707,15 @@ PhysicalBone *Skeleton::get_physical_bone_parent(int p_bone) { return _get_physical_bone_parent(p_bone); } -PhysicalBone *Skeleton::_get_physical_bone_parent(int p_bone) { - ERR_FAIL_INDEX_V(p_bone, bones.size(), NULL); +PhysicalBone3D *Skeleton3D::_get_physical_bone_parent(int p_bone) { + ERR_FAIL_INDEX_V(p_bone, bones.size(), nullptr); const int parent_bone = bones[p_bone].parent; if (0 > parent_bone) { - return NULL; + return nullptr; } - PhysicalBone *pb = bones[parent_bone].physical_bone; + PhysicalBone3D *pb = bones[parent_bone].physical_bone; if (pb) { return pb; } else { @@ -715,10 +723,10 @@ PhysicalBone *Skeleton::_get_physical_bone_parent(int p_bone) { } } -void Skeleton::_rebuild_physical_bones_cache() { +void Skeleton3D::_rebuild_physical_bones_cache() { const int b_size = bones.size(); for (int i = 0; i < b_size; ++i) { - PhysicalBone *parent_pb = _get_physical_bone_parent(i); + PhysicalBone3D *parent_pb = _get_physical_bone_parent(i); if (parent_pb != bones[i].physical_bone) { bones.write[i].cache_parent_physical_bone = parent_pb; if (bones[i].physical_bone) @@ -733,26 +741,26 @@ void _pb_stop_simulation(Node *p_node) { _pb_stop_simulation(p_node->get_child(i)); } - PhysicalBone *pb = Object::cast_to<PhysicalBone>(p_node); + PhysicalBone3D *pb = Object::cast_to<PhysicalBone3D>(p_node); if (pb) { pb->set_simulate_physics(false); } } -void Skeleton::physical_bones_stop_simulation() { +void Skeleton3D::physical_bones_stop_simulation() { _pb_stop_simulation(this); if (Engine::get_singleton()->is_editor_hint() == false && animate_physical_bones) { set_physics_process_internal(true); } } -void _pb_start_simulation(const Skeleton *p_skeleton, Node *p_node, const Vector<int> &p_sim_bones) { +void _pb_start_simulation(const Skeleton3D *p_skeleton, Node *p_node, const Vector<int> &p_sim_bones) { for (int i = p_node->get_child_count() - 1; 0 <= i; --i) { _pb_start_simulation(p_skeleton, p_node->get_child(i), p_sim_bones); } - PhysicalBone *pb = Object::cast_to<PhysicalBone>(p_node); + PhysicalBone3D *pb = Object::cast_to<PhysicalBone3D>(p_node); if (pb) { for (int i = p_sim_bones.size() - 1; 0 <= i; --i) { if (p_sim_bones[i] == pb->get_bone_id() || p_skeleton->is_bone_parent_of(pb->get_bone_id(), p_sim_bones[i])) { @@ -763,7 +771,7 @@ void _pb_start_simulation(const Skeleton *p_skeleton, Node *p_node, const Vector } } -void Skeleton::physical_bones_start_simulation_on(const Array &p_bones) { +void Skeleton3D::physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones) { set_physics_process_internal(false); Vector<int> sim_bones; @@ -773,12 +781,9 @@ void Skeleton::physical_bones_start_simulation_on(const Array &p_bones) { sim_bones.resize(p_bones.size()); int c = 0; for (int i = sim_bones.size() - 1; 0 <= i; --i) { - Variant::Type type = p_bones.get(i).get_type(); - if (Variant::STRING == type || Variant::STRING_NAME == type) { - int bone_id = find_bone(p_bones.get(i)); - if (bone_id != -1) - sim_bones.write[c++] = bone_id; - } + int bone_id = find_bone(p_bones[i]); + if (bone_id != -1) + sim_bones.write[c++] = bone_id; } sim_bones.resize(c); } @@ -792,31 +797,31 @@ void _physical_bones_add_remove_collision_exception(bool p_add, Node *p_node, RI _physical_bones_add_remove_collision_exception(p_add, p_node->get_child(i), p_exception); } - CollisionObject *co = Object::cast_to<CollisionObject>(p_node); + CollisionObject3D *co = Object::cast_to<CollisionObject3D>(p_node); if (co) { if (p_add) { - PhysicsServer::get_singleton()->body_add_collision_exception(co->get_rid(), p_exception); + PhysicsServer3D::get_singleton()->body_add_collision_exception(co->get_rid(), p_exception); } else { - PhysicsServer::get_singleton()->body_remove_collision_exception(co->get_rid(), p_exception); + PhysicsServer3D::get_singleton()->body_remove_collision_exception(co->get_rid(), p_exception); } } } -void Skeleton::physical_bones_add_collision_exception(RID p_exception) { +void Skeleton3D::physical_bones_add_collision_exception(RID p_exception) { _physical_bones_add_remove_collision_exception(true, this, p_exception); } -void Skeleton::physical_bones_remove_collision_exception(RID p_exception) { +void Skeleton3D::physical_bones_remove_collision_exception(RID p_exception) { _physical_bones_add_remove_collision_exception(false, this, p_exception); } #endif // _3D_DISABLED -void Skeleton::_skin_changed() { +void Skeleton3D::_skin_changed() { _make_dirty(); } -Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) { +Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { for (Set<SkinReference *>::Element *E = skin_bindings.front(); E; E = E->next()) { if (E->get()->skin == p_skin) { @@ -864,7 +869,7 @@ Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) { skin_ref->skeleton_node = this; skin_ref->bind_count = 0; - skin_ref->skeleton = VisualServer::get_singleton()->skeleton_create(); + skin_ref->skeleton = RenderingServer::get_singleton()->skeleton_create(); skin_ref->skeleton_node = this; skin_ref->skin = skin; @@ -877,53 +882,54 @@ Ref<SkinReference> Skeleton::register_skin(const Ref<Skin> &p_skin) { return skin_ref; } -void Skeleton::_bind_methods() { +void Skeleton3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("add_bone", "name"), &Skeleton::add_bone); - ClassDB::bind_method(D_METHOD("find_bone", "name"), &Skeleton::find_bone); - ClassDB::bind_method(D_METHOD("get_bone_name", "bone_idx"), &Skeleton::get_bone_name); + ClassDB::bind_method(D_METHOD("add_bone", "name"), &Skeleton3D::add_bone); + ClassDB::bind_method(D_METHOD("find_bone", "name"), &Skeleton3D::find_bone); + ClassDB::bind_method(D_METHOD("get_bone_name", "bone_idx"), &Skeleton3D::get_bone_name); - ClassDB::bind_method(D_METHOD("get_bone_parent", "bone_idx"), &Skeleton::get_bone_parent); - ClassDB::bind_method(D_METHOD("set_bone_parent", "bone_idx", "parent_idx"), &Skeleton::set_bone_parent); + ClassDB::bind_method(D_METHOD("get_bone_parent", "bone_idx"), &Skeleton3D::get_bone_parent); + ClassDB::bind_method(D_METHOD("set_bone_parent", "bone_idx", "parent_idx"), &Skeleton3D::set_bone_parent); - ClassDB::bind_method(D_METHOD("get_bone_count"), &Skeleton::get_bone_count); + ClassDB::bind_method(D_METHOD("get_bone_count"), &Skeleton3D::get_bone_count); - ClassDB::bind_method(D_METHOD("unparent_bone_and_rest", "bone_idx"), &Skeleton::unparent_bone_and_rest); + ClassDB::bind_method(D_METHOD("unparent_bone_and_rest", "bone_idx"), &Skeleton3D::unparent_bone_and_rest); - ClassDB::bind_method(D_METHOD("get_bone_rest", "bone_idx"), &Skeleton::get_bone_rest); - ClassDB::bind_method(D_METHOD("set_bone_rest", "bone_idx", "rest"), &Skeleton::set_bone_rest); + ClassDB::bind_method(D_METHOD("get_bone_rest", "bone_idx"), &Skeleton3D::get_bone_rest); + ClassDB::bind_method(D_METHOD("set_bone_rest", "bone_idx", "rest"), &Skeleton3D::set_bone_rest); - ClassDB::bind_method(D_METHOD("register_skin", "skin"), &Skeleton::register_skin); + ClassDB::bind_method(D_METHOD("register_skin", "skin"), &Skeleton3D::register_skin); - ClassDB::bind_method(D_METHOD("localize_rests"), &Skeleton::localize_rests); + ClassDB::bind_method(D_METHOD("localize_rests"), &Skeleton3D::localize_rests); - ClassDB::bind_method(D_METHOD("set_bone_disable_rest", "bone_idx", "disable"), &Skeleton::set_bone_disable_rest); - ClassDB::bind_method(D_METHOD("is_bone_rest_disabled", "bone_idx"), &Skeleton::is_bone_rest_disabled); + ClassDB::bind_method(D_METHOD("set_bone_disable_rest", "bone_idx", "disable"), &Skeleton3D::set_bone_disable_rest); + ClassDB::bind_method(D_METHOD("is_bone_rest_disabled", "bone_idx"), &Skeleton3D::is_bone_rest_disabled); - ClassDB::bind_method(D_METHOD("bind_child_node_to_bone", "bone_idx", "node"), &Skeleton::bind_child_node_to_bone); - ClassDB::bind_method(D_METHOD("unbind_child_node_from_bone", "bone_idx", "node"), &Skeleton::unbind_child_node_from_bone); - ClassDB::bind_method(D_METHOD("get_bound_child_nodes_to_bone", "bone_idx"), &Skeleton::_get_bound_child_nodes_to_bone); + ClassDB::bind_method(D_METHOD("bind_child_node_to_bone", "bone_idx", "node"), &Skeleton3D::bind_child_node_to_bone); + ClassDB::bind_method(D_METHOD("unbind_child_node_from_bone", "bone_idx", "node"), &Skeleton3D::unbind_child_node_from_bone); + ClassDB::bind_method(D_METHOD("get_bound_child_nodes_to_bone", "bone_idx"), &Skeleton3D::_get_bound_child_nodes_to_bone); - ClassDB::bind_method(D_METHOD("clear_bones"), &Skeleton::clear_bones); + ClassDB::bind_method(D_METHOD("clear_bones"), &Skeleton3D::clear_bones); - ClassDB::bind_method(D_METHOD("get_bone_pose", "bone_idx"), &Skeleton::get_bone_pose); - ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton::set_bone_pose); + ClassDB::bind_method(D_METHOD("get_bone_pose", "bone_idx"), &Skeleton3D::get_bone_pose); + ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton3D::set_bone_pose); - ClassDB::bind_method(D_METHOD("set_bone_global_pose_override", "bone_idx", "pose", "amount", "persistent"), &Skeleton::set_bone_global_pose_override, DEFVAL(false)); - ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton::get_bone_global_pose); + ClassDB::bind_method(D_METHOD("clear_bones_global_pose_override"), &Skeleton3D::clear_bones_global_pose_override); + ClassDB::bind_method(D_METHOD("set_bone_global_pose_override", "bone_idx", "pose", "amount", "persistent"), &Skeleton3D::set_bone_global_pose_override, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton3D::get_bone_global_pose); - ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton::get_bone_custom_pose); - ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton::set_bone_custom_pose); + ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton3D::get_bone_custom_pose); + ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton3D::set_bone_custom_pose); #ifndef _3D_DISABLED - ClassDB::bind_method(D_METHOD("set_animate_physical_bones"), &Skeleton::set_animate_physical_bones); - ClassDB::bind_method(D_METHOD("get_animate_physical_bones"), &Skeleton::get_animate_physical_bones); + ClassDB::bind_method(D_METHOD("set_animate_physical_bones"), &Skeleton3D::set_animate_physical_bones); + ClassDB::bind_method(D_METHOD("get_animate_physical_bones"), &Skeleton3D::get_animate_physical_bones); - ClassDB::bind_method(D_METHOD("physical_bones_stop_simulation"), &Skeleton::physical_bones_stop_simulation); - ClassDB::bind_method(D_METHOD("physical_bones_start_simulation", "bones"), &Skeleton::physical_bones_start_simulation_on, DEFVAL(Array())); - ClassDB::bind_method(D_METHOD("physical_bones_add_collision_exception", "exception"), &Skeleton::physical_bones_add_collision_exception); - ClassDB::bind_method(D_METHOD("physical_bones_remove_collision_exception", "exception"), &Skeleton::physical_bones_remove_collision_exception); + ClassDB::bind_method(D_METHOD("physical_bones_stop_simulation"), &Skeleton3D::physical_bones_stop_simulation); + ClassDB::bind_method(D_METHOD("physical_bones_start_simulation", "bones"), &Skeleton3D::physical_bones_start_simulation_on, DEFVAL(Array())); + ClassDB::bind_method(D_METHOD("physical_bones_add_collision_exception", "exception"), &Skeleton3D::physical_bones_add_collision_exception); + ClassDB::bind_method(D_METHOD("physical_bones_remove_collision_exception", "exception"), &Skeleton3D::physical_bones_remove_collision_exception); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "animate_physical_bones"), "set_animate_physical_bones", "get_animate_physical_bones"); #endif // _3D_DISABLED @@ -931,7 +937,7 @@ void Skeleton::_bind_methods() { BIND_CONSTANT(NOTIFICATION_UPDATE_SKELETON); } -Skeleton::Skeleton() { +Skeleton3D::Skeleton3D() { animate_physical_bones = true; dirty = false; @@ -939,7 +945,7 @@ Skeleton::Skeleton() { process_order_dirty = true; } -Skeleton::~Skeleton() { +Skeleton3D::~Skeleton3D() { //some skins may remain bound for (Set<SkinReference *>::Element *E = skin_bindings.front(); E; E = E->next()) { diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton_3d.h index 76fd96f30a..0bccd3f8fc 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* skeleton.h */ +/* skeleton_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,26 +28,26 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef SKELETON_H -#define SKELETON_H +#ifndef SKELETON_3D_H +#define SKELETON_3D_H #include "core/rid.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/skin.h" #ifndef _3D_DISABLED typedef int BoneId; -class PhysicalBone; +class PhysicalBone3D; #endif // _3D_DISABLED -class Skeleton; +class Skeleton3D; class SkinReference : public Reference { GDCLASS(SkinReference, Reference) - friend class Skeleton; + friend class Skeleton3D; - Skeleton *skeleton_node; + Skeleton3D *skeleton_node; RID skeleton; Ref<Skin> skin; uint32_t bind_count = 0; @@ -65,9 +65,9 @@ public: ~SkinReference(); }; -class Skeleton : public Spatial { +class Skeleton3D : public Node3D { - GDCLASS(Skeleton, Spatial); + GDCLASS(Skeleton3D, Node3D); private: friend class SkinReference; @@ -98,8 +98,8 @@ private: Transform global_pose_override; #ifndef _3D_DISABLED - PhysicalBone *physical_bone; - PhysicalBone *cache_parent_physical_bone; + PhysicalBone3D *physical_bone; + PhysicalBone3D *cache_parent_physical_bone; #endif // _3D_DISABLED List<ObjectID> nodes_bound; @@ -112,8 +112,8 @@ private: global_pose_override_amount = 0; global_pose_override_reset = false; #ifndef _3D_DISABLED - physical_bone = NULL; - cache_parent_physical_bone = NULL; + physical_bone = nullptr; + cache_parent_physical_bone = nullptr; #endif // _3D_DISABLED } }; @@ -178,6 +178,7 @@ public: Transform get_bone_rest(int p_bone) const; Transform get_bone_global_pose(int p_bone) const; + void clear_bones_global_pose_override(); void set_bone_global_pose_override(int p_bone, const Transform &p_pose, float p_amount, bool p_persistent = false); void set_bone_enabled(int p_bone, bool p_enabled); @@ -208,27 +209,27 @@ public: void set_animate_physical_bones(bool p_animate); bool get_animate_physical_bones() const; - void bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_bone); + void bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physical_bone); void unbind_physical_bone_from_bone(int p_bone); - PhysicalBone *get_physical_bone(int p_bone); - PhysicalBone *get_physical_bone_parent(int p_bone); + PhysicalBone3D *get_physical_bone(int p_bone); + PhysicalBone3D *get_physical_bone_parent(int p_bone); private: /// This is a slow API os it's cached - PhysicalBone *_get_physical_bone_parent(int p_bone); + PhysicalBone3D *_get_physical_bone_parent(int p_bone); void _rebuild_physical_bones_cache(); public: void physical_bones_stop_simulation(); - void physical_bones_start_simulation_on(const Array &p_bones); + void physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones); void physical_bones_add_collision_exception(RID p_exception); void physical_bones_remove_collision_exception(RID p_exception); #endif // _3D_DISABLED public: - Skeleton(); - ~Skeleton(); + Skeleton3D(); + ~Skeleton3D(); }; #endif diff --git a/scene/3d/skeleton_ik_3d.cpp b/scene/3d/skeleton_ik_3d.cpp new file mode 100644 index 0000000000..7366290ed3 --- /dev/null +++ b/scene/3d/skeleton_ik_3d.cpp @@ -0,0 +1,578 @@ +/*************************************************************************/ +/* skeleton_ik_3d.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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. */ +/*************************************************************************/ + +/** + * @author AndreaCatania + */ + +#include "skeleton_ik_3d.h" + +#ifndef _3D_DISABLED + +FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::find_child(const BoneId p_bone_id) { + for (int i = children.size() - 1; 0 <= i; --i) { + if (p_bone_id == children[i].bone) { + return &children.write[i]; + } + } + return nullptr; +} + +FabrikInverseKinematic::ChainItem *FabrikInverseKinematic::ChainItem::add_child(const BoneId p_bone_id) { + const int infant_child_id = children.size(); + children.resize(infant_child_id + 1); + children.write[infant_child_id].bone = p_bone_id; + children.write[infant_child_id].parent_item = this; + return &children.write[infant_child_id]; +} + +/// Build a chain that starts from the root to tip +bool FabrikInverseKinematic::build_chain(Task *p_task, bool p_force_simple_chain) { + + ERR_FAIL_COND_V(-1 == p_task->root_bone, false); + + Chain &chain(p_task->chain); + + chain.tips.resize(p_task->end_effectors.size()); + chain.chain_root.bone = p_task->root_bone; + chain.chain_root.initial_transform = p_task->skeleton->get_bone_global_pose(chain.chain_root.bone); + chain.chain_root.current_pos = chain.chain_root.initial_transform.origin; + chain.chain_root.pb = p_task->skeleton->get_physical_bone(chain.chain_root.bone); + chain.middle_chain_item = nullptr; + + // Holds all IDs that are composing a single chain in reverse order + Vector<BoneId> chain_ids; + // This is used to know the chain size + int sub_chain_size; + // Resize only one time in order to fit all joints for performance reason + chain_ids.resize(p_task->skeleton->get_bone_count()); + + for (int x = p_task->end_effectors.size() - 1; 0 <= x; --x) { + + const EndEffector *ee(&p_task->end_effectors[x]); + ERR_FAIL_COND_V(p_task->root_bone >= ee->tip_bone, false); + ERR_FAIL_INDEX_V(ee->tip_bone, p_task->skeleton->get_bone_count(), false); + + sub_chain_size = 0; + // Picks all IDs that composing a single chain in reverse order (except the root) + BoneId chain_sub_tip(ee->tip_bone); + while (chain_sub_tip > p_task->root_bone) { + + chain_ids.write[sub_chain_size++] = chain_sub_tip; + chain_sub_tip = p_task->skeleton->get_bone_parent(chain_sub_tip); + } + + BoneId middle_chain_item_id = (((float)sub_chain_size) * 0.5); + + // Build chain by reading chain ids in reverse order + // For each chain item id will be created a ChainItem if doesn't exists + ChainItem *sub_chain(&chain.chain_root); + for (int i = sub_chain_size - 1; 0 <= i; --i) { + + ChainItem *child_ci(sub_chain->find_child(chain_ids[i])); + if (!child_ci) { + + child_ci = sub_chain->add_child(chain_ids[i]); + + child_ci->pb = p_task->skeleton->get_physical_bone(child_ci->bone); + + child_ci->initial_transform = p_task->skeleton->get_bone_global_pose(child_ci->bone); + child_ci->current_pos = child_ci->initial_transform.origin; + + if (child_ci->parent_item) { + child_ci->length = (child_ci->current_pos - child_ci->parent_item->current_pos).length(); + } + } + + sub_chain = child_ci; + + if (middle_chain_item_id == i) { + chain.middle_chain_item = child_ci; + } + } + + if (!middle_chain_item_id) + chain.middle_chain_item = nullptr; + + // Initialize current tip + chain.tips.write[x].chain_item = sub_chain; + chain.tips.write[x].end_effector = ee; + + if (p_force_simple_chain) { + // NOTE: + // This is an "hack" that force to create only one tip per chain since the solver of multi tip (end effector) + // is not yet created. + // Remove this code when this is done + break; + } + } + return true; +} + +void FabrikInverseKinematic::update_chain(const Skeleton3D *p_sk, ChainItem *p_chain_item) { + + if (!p_chain_item) + return; + + p_chain_item->initial_transform = p_sk->get_bone_global_pose(p_chain_item->bone); + p_chain_item->current_pos = p_chain_item->initial_transform.origin; + + ChainItem *items = p_chain_item->children.ptrw(); + for (int i = 0; i < p_chain_item->children.size(); i += 1) { + update_chain(p_sk, items + i); + } +} + +void FabrikInverseKinematic::solve_simple(Task *p_task, bool p_solve_magnet) { + + real_t distance_to_goal(1e4); + real_t previous_distance_to_goal(0); + int can_solve(p_task->max_iterations); + while (distance_to_goal > p_task->min_distance && Math::abs(previous_distance_to_goal - distance_to_goal) > 0.005 && can_solve) { + previous_distance_to_goal = distance_to_goal; + --can_solve; + + solve_simple_backwards(p_task->chain, p_solve_magnet); + solve_simple_forwards(p_task->chain, p_solve_magnet); + + distance_to_goal = (p_task->chain.tips[0].chain_item->current_pos - p_task->chain.tips[0].end_effector->goal_transform.origin).length(); + } +} + +void FabrikInverseKinematic::solve_simple_backwards(Chain &r_chain, bool p_solve_magnet) { + + if (p_solve_magnet && !r_chain.middle_chain_item) { + return; + } + + Vector3 goal; + ChainItem *sub_chain_tip; + if (p_solve_magnet) { + goal = r_chain.magnet_position; + sub_chain_tip = r_chain.middle_chain_item; + } else { + goal = r_chain.tips[0].end_effector->goal_transform.origin; + sub_chain_tip = r_chain.tips[0].chain_item; + } + + while (sub_chain_tip) { + sub_chain_tip->current_pos = goal; + + if (sub_chain_tip->parent_item) { + // Not yet in the chain root + // So calculate next goal location + + const Vector3 look_parent((sub_chain_tip->parent_item->current_pos - sub_chain_tip->current_pos).normalized()); + goal = sub_chain_tip->current_pos + (look_parent * sub_chain_tip->length); + + // [TODO] Constraints goes here + } + + sub_chain_tip = sub_chain_tip->parent_item; + } +} + +void FabrikInverseKinematic::solve_simple_forwards(Chain &r_chain, bool p_solve_magnet) { + + if (p_solve_magnet && !r_chain.middle_chain_item) { + return; + } + + ChainItem *sub_chain_root(&r_chain.chain_root); + Vector3 origin(r_chain.chain_root.initial_transform.origin); + + while (sub_chain_root) { // Reach the tip + sub_chain_root->current_pos = origin; + + if (!sub_chain_root->children.empty()) { + + ChainItem &child(sub_chain_root->children.write[0]); + + // Is not tip + // So calculate next origin location + + // Look child + sub_chain_root->current_ori = (child.current_pos - sub_chain_root->current_pos).normalized(); + origin = sub_chain_root->current_pos + (sub_chain_root->current_ori * child.length); + + // [TODO] Constraints goes here + + if (p_solve_magnet && sub_chain_root == r_chain.middle_chain_item) { + // In case of magnet solving this is the tip + sub_chain_root = nullptr; + } else { + sub_chain_root = &child; + } + } else { + + // Is tip + sub_chain_root = nullptr; + } + } +} + +FabrikInverseKinematic::Task *FabrikInverseKinematic::create_simple_task(Skeleton3D *p_sk, BoneId root_bone, BoneId tip_bone, const Transform &goal_transform) { + + FabrikInverseKinematic::EndEffector ee; + ee.tip_bone = tip_bone; + + Task *task(memnew(Task)); + task->skeleton = p_sk; + task->root_bone = root_bone; + task->end_effectors.push_back(ee); + task->goal_global_transform = goal_transform; + + if (!build_chain(task)) { + free_task(task); + return nullptr; + } + + return task; +} + +void FabrikInverseKinematic::free_task(Task *p_task) { + if (p_task) + memdelete(p_task); +} + +void FabrikInverseKinematic::set_goal(Task *p_task, const Transform &p_goal) { + p_task->goal_global_transform = p_goal; +} + +void FabrikInverseKinematic::make_goal(Task *p_task, const Transform &p_inverse_transf, real_t blending_delta) { + + if (blending_delta >= 0.99f) { + // Update the end_effector (local transform) without blending + p_task->end_effectors.write[0].goal_transform = p_inverse_transf * p_task->goal_global_transform; + } else { + + // End effector in local transform + const Transform end_effector_pose(p_task->skeleton->get_bone_global_pose(p_task->end_effectors.write[0].tip_bone)); + + // Update the end_effector (local transform) by blending with current pose + p_task->end_effectors.write[0].goal_transform = end_effector_pose.interpolate_with(p_inverse_transf * p_task->goal_global_transform, blending_delta); + } +} + +void FabrikInverseKinematic::solve(Task *p_task, real_t blending_delta, bool override_tip_basis, bool p_use_magnet, const Vector3 &p_magnet_position) { + + if (blending_delta <= 0.01f) { + return; // Skip solving + } + + p_task->skeleton->clear_bones_global_pose_override(); + + make_goal(p_task, p_task->skeleton->get_global_transform().affine_inverse().scaled(p_task->skeleton->get_global_transform().get_basis().get_scale()), blending_delta); + + update_chain(p_task->skeleton, &p_task->chain.chain_root); + + if (p_use_magnet && p_task->chain.middle_chain_item) { + p_task->chain.magnet_position = p_task->chain.middle_chain_item->initial_transform.origin.linear_interpolate(p_magnet_position, blending_delta); + solve_simple(p_task, true); + } + solve_simple(p_task, false); + + // Assign new bone position. + ChainItem *ci(&p_task->chain.chain_root); + while (ci) { + Transform new_bone_pose(ci->initial_transform); + new_bone_pose.origin = ci->current_pos; + + if (!ci->children.empty()) { + + /// Rotate basis + const Vector3 initial_ori((ci->children[0].initial_transform.origin - ci->initial_transform.origin).normalized()); + const Vector3 rot_axis(initial_ori.cross(ci->current_ori).normalized()); + + if (rot_axis[0] != 0 && rot_axis[1] != 0 && rot_axis[2] != 0) { + const real_t rot_angle(Math::acos(CLAMP(initial_ori.dot(ci->current_ori), -1, 1))); + new_bone_pose.basis.rotate(rot_axis, rot_angle); + } + } else { + // Set target orientation to tip + if (override_tip_basis) + new_bone_pose.basis = p_task->chain.tips[0].end_effector->goal_transform.basis; + else + new_bone_pose.basis = new_bone_pose.basis * p_task->chain.tips[0].end_effector->goal_transform.basis; + } + + p_task->skeleton->set_bone_global_pose_override(ci->bone, new_bone_pose, 1.0, true); + + if (!ci->children.empty()) + ci = &ci->children.write[0]; + else + ci = nullptr; + } +} + +void SkeletonIK3D::_validate_property(PropertyInfo &property) const { + + if (property.name == "root_bone" || property.name == "tip_bone") { + + if (skeleton) { + + String names("--,"); + for (int i = 0; i < skeleton->get_bone_count(); i++) { + if (i > 0) + names += ","; + names += skeleton->get_bone_name(i); + } + + property.hint = PROPERTY_HINT_ENUM; + property.hint_string = names; + } else { + + property.hint = PROPERTY_HINT_NONE; + property.hint_string = ""; + } + } +} + +void SkeletonIK3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_root_bone", "root_bone"), &SkeletonIK3D::set_root_bone); + ClassDB::bind_method(D_METHOD("get_root_bone"), &SkeletonIK3D::get_root_bone); + + ClassDB::bind_method(D_METHOD("set_tip_bone", "tip_bone"), &SkeletonIK3D::set_tip_bone); + ClassDB::bind_method(D_METHOD("get_tip_bone"), &SkeletonIK3D::get_tip_bone); + + ClassDB::bind_method(D_METHOD("set_interpolation", "interpolation"), &SkeletonIK3D::set_interpolation); + ClassDB::bind_method(D_METHOD("get_interpolation"), &SkeletonIK3D::get_interpolation); + + ClassDB::bind_method(D_METHOD("set_target_transform", "target"), &SkeletonIK3D::set_target_transform); + ClassDB::bind_method(D_METHOD("get_target_transform"), &SkeletonIK3D::get_target_transform); + + ClassDB::bind_method(D_METHOD("set_target_node", "node"), &SkeletonIK3D::set_target_node); + ClassDB::bind_method(D_METHOD("get_target_node"), &SkeletonIK3D::get_target_node); + + ClassDB::bind_method(D_METHOD("set_override_tip_basis", "override"), &SkeletonIK3D::set_override_tip_basis); + ClassDB::bind_method(D_METHOD("is_override_tip_basis"), &SkeletonIK3D::is_override_tip_basis); + + ClassDB::bind_method(D_METHOD("set_use_magnet", "use"), &SkeletonIK3D::set_use_magnet); + ClassDB::bind_method(D_METHOD("is_using_magnet"), &SkeletonIK3D::is_using_magnet); + + ClassDB::bind_method(D_METHOD("set_magnet_position", "local_position"), &SkeletonIK3D::set_magnet_position); + ClassDB::bind_method(D_METHOD("get_magnet_position"), &SkeletonIK3D::get_magnet_position); + + ClassDB::bind_method(D_METHOD("get_parent_skeleton"), &SkeletonIK3D::get_parent_skeleton); + ClassDB::bind_method(D_METHOD("is_running"), &SkeletonIK3D::is_running); + + ClassDB::bind_method(D_METHOD("set_min_distance", "min_distance"), &SkeletonIK3D::set_min_distance); + ClassDB::bind_method(D_METHOD("get_min_distance"), &SkeletonIK3D::get_min_distance); + + ClassDB::bind_method(D_METHOD("set_max_iterations", "iterations"), &SkeletonIK3D::set_max_iterations); + ClassDB::bind_method(D_METHOD("get_max_iterations"), &SkeletonIK3D::get_max_iterations); + + ClassDB::bind_method(D_METHOD("start", "one_time"), &SkeletonIK3D::start, DEFVAL(false)); + ClassDB::bind_method(D_METHOD("stop"), &SkeletonIK3D::stop); + + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "root_bone"), "set_root_bone", "get_root_bone"); + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "tip_bone"), "set_tip_bone", "get_tip_bone"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "interpolation", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_interpolation", "get_interpolation"); + ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "target"), "set_target_transform", "get_target_transform"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_tip_basis"), "set_override_tip_basis", "is_override_tip_basis"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_magnet"), "set_use_magnet", "is_using_magnet"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "magnet"), "set_magnet_position", "get_magnet_position"); + ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "target_node"), "set_target_node", "get_target_node"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_distance"), "set_min_distance", "get_min_distance"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "max_iterations"), "set_max_iterations", "get_max_iterations"); +} + +void SkeletonIK3D::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + skeleton = Object::cast_to<Skeleton3D>(get_parent()); + set_process_priority(1); + reload_chain(); + } break; + case NOTIFICATION_INTERNAL_PROCESS: { + + if (target_node_override) + reload_goal(); + + _solve_chain(); + + } break; + case NOTIFICATION_EXIT_TREE: { + reload_chain(); + } break; + } +} + +SkeletonIK3D::SkeletonIK3D() : + interpolation(1), + override_tip_basis(true), + use_magnet(false), + min_distance(0.01), + max_iterations(10), + skeleton(nullptr), + target_node_override(nullptr), + task(nullptr) { +} + +SkeletonIK3D::~SkeletonIK3D() { + FabrikInverseKinematic::free_task(task); + task = nullptr; +} + +void SkeletonIK3D::set_root_bone(const StringName &p_root_bone) { + root_bone = p_root_bone; + reload_chain(); +} + +StringName SkeletonIK3D::get_root_bone() const { + return root_bone; +} + +void SkeletonIK3D::set_tip_bone(const StringName &p_tip_bone) { + tip_bone = p_tip_bone; + reload_chain(); +} + +StringName SkeletonIK3D::get_tip_bone() const { + return tip_bone; +} + +void SkeletonIK3D::set_interpolation(real_t p_interpolation) { + interpolation = p_interpolation; +} + +real_t SkeletonIK3D::get_interpolation() const { + return interpolation; +} + +void SkeletonIK3D::set_target_transform(const Transform &p_target) { + target = p_target; + reload_goal(); +} + +const Transform &SkeletonIK3D::get_target_transform() const { + return target; +} + +void SkeletonIK3D::set_target_node(const NodePath &p_node) { + target_node_path_override = p_node; + target_node_override = nullptr; + reload_goal(); +} + +NodePath SkeletonIK3D::get_target_node() { + return target_node_path_override; +} + +void SkeletonIK3D::set_override_tip_basis(bool p_override) { + override_tip_basis = p_override; +} + +bool SkeletonIK3D::is_override_tip_basis() const { + return override_tip_basis; +} + +void SkeletonIK3D::set_use_magnet(bool p_use) { + use_magnet = p_use; +} + +bool SkeletonIK3D::is_using_magnet() const { + return use_magnet; +} + +void SkeletonIK3D::set_magnet_position(const Vector3 &p_local_position) { + magnet_position = p_local_position; +} + +const Vector3 &SkeletonIK3D::get_magnet_position() const { + return magnet_position; +} + +void SkeletonIK3D::set_min_distance(real_t p_min_distance) { + min_distance = p_min_distance; +} + +void SkeletonIK3D::set_max_iterations(int p_iterations) { + max_iterations = p_iterations; +} + +bool SkeletonIK3D::is_running() { + return is_processing_internal(); +} + +void SkeletonIK3D::start(bool p_one_time) { + if (p_one_time) { + set_process_internal(false); + _solve_chain(); + } else { + set_process_internal(true); + } +} + +void SkeletonIK3D::stop() { + set_process_internal(false); +} + +Transform SkeletonIK3D::_get_target_transform() { + + if (!target_node_override && !target_node_path_override.is_empty()) + target_node_override = Object::cast_to<Node3D>(get_node(target_node_path_override)); + + if (target_node_override) + return target_node_override->get_global_transform(); + else + return target; +} + +void SkeletonIK3D::reload_chain() { + + FabrikInverseKinematic::free_task(task); + task = nullptr; + + if (!skeleton) + return; + + task = FabrikInverseKinematic::create_simple_task(skeleton, skeleton->find_bone(root_bone), skeleton->find_bone(tip_bone), _get_target_transform()); + if (task) { + task->max_iterations = max_iterations; + task->min_distance = min_distance; + } +} + +void SkeletonIK3D::reload_goal() { + if (!task) + return; + + FabrikInverseKinematic::set_goal(task, _get_target_transform()); +} + +void SkeletonIK3D::_solve_chain() { + if (!task) + return; + FabrikInverseKinematic::solve(task, interpolation, override_tip_basis, use_magnet, magnet_position); +} + +#endif // _3D_DISABLED diff --git a/scene/3d/skeleton_ik_3d.h b/scene/3d/skeleton_ik_3d.h new file mode 100644 index 0000000000..5fbbe6e9e7 --- /dev/null +++ b/scene/3d/skeleton_ik_3d.h @@ -0,0 +1,220 @@ +/*************************************************************************/ +/* skeleton_ik_3d.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2020 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 SKELETON_IK_H +#define SKELETON_IK_H + +#ifndef _3D_DISABLED + +/** + * @author AndreaCatania + */ + +#include "core/math/transform.h" +#include "scene/3d/skeleton_3d.h" + +class FabrikInverseKinematic { + + struct EndEffector { + BoneId tip_bone; + Transform goal_transform; + }; + + struct ChainItem { + + Vector<ChainItem> children; + ChainItem *parent_item; + + // Bone info + BoneId bone; + PhysicalBone3D *pb; + + real_t length; + /// Positions relative to root bone + Transform initial_transform; + Vector3 current_pos; + // Direction from this bone to child + Vector3 current_ori; + + ChainItem() : + parent_item(nullptr), + bone(-1), + pb(nullptr), + length(0) {} + + ChainItem *find_child(const BoneId p_bone_id); + ChainItem *add_child(const BoneId p_bone_id); + }; + + struct ChainTip { + ChainItem *chain_item; + const EndEffector *end_effector; + + ChainTip() : + chain_item(nullptr), + end_effector(nullptr) {} + + ChainTip(ChainItem *p_chain_item, const EndEffector *p_end_effector) : + chain_item(p_chain_item), + end_effector(p_end_effector) {} + + ChainTip(const ChainTip &p_other_ct) : + chain_item(p_other_ct.chain_item), + end_effector(p_other_ct.end_effector) {} + }; + + struct Chain { + ChainItem chain_root; + ChainItem *middle_chain_item; + Vector<ChainTip> tips; + Vector3 magnet_position; + }; + +public: + struct Task { + RID self; + Skeleton3D *skeleton; + + Chain chain; + + // Settings + real_t min_distance; + int max_iterations; + + // Bone data + BoneId root_bone; + Vector<EndEffector> end_effectors; + + Transform goal_global_transform; + + Task() : + skeleton(nullptr), + min_distance(0.01), + max_iterations(10), + root_bone(-1) {} + }; + +private: + /// Init a chain that starts from the root to tip + static bool build_chain(Task *p_task, bool p_force_simple_chain = true); + + static void update_chain(const Skeleton3D *p_sk, ChainItem *p_chain_item); + + static void solve_simple(Task *p_task, bool p_solve_magnet); + /// Special solvers that solve only chains with one end effector + static void solve_simple_backwards(Chain &r_chain, bool p_solve_magnet); + static void solve_simple_forwards(Chain &r_chain, bool p_solve_magnet); + +public: + static Task *create_simple_task(Skeleton3D *p_sk, BoneId root_bone, BoneId tip_bone, const Transform &goal_transform); + static void free_task(Task *p_task); + // The goal of chain should be always in local space + static void set_goal(Task *p_task, const Transform &p_goal); + static void make_goal(Task *p_task, const Transform &p_inverse_transf, real_t blending_delta); + static void solve(Task *p_task, real_t blending_delta, bool override_tip_basis, bool p_use_magnet, const Vector3 &p_magnet_position); +}; + +class SkeletonIK3D : public Node { + GDCLASS(SkeletonIK3D, Node); + + StringName root_bone; + StringName tip_bone; + real_t interpolation; + Transform target; + NodePath target_node_path_override; + bool override_tip_basis; + bool use_magnet; + Vector3 magnet_position; + + real_t min_distance; + int max_iterations; + + Skeleton3D *skeleton; + Node3D *target_node_override; + FabrikInverseKinematic::Task *task; + +protected: + virtual void + _validate_property(PropertyInfo &property) const; + + static void _bind_methods(); + virtual void _notification(int p_what); + +public: + SkeletonIK3D(); + virtual ~SkeletonIK3D(); + + void set_root_bone(const StringName &p_root_bone); + StringName get_root_bone() const; + + void set_tip_bone(const StringName &p_tip_bone); + StringName get_tip_bone() const; + + void set_interpolation(real_t p_interpolation); + real_t get_interpolation() const; + + void set_target_transform(const Transform &p_target); + const Transform &get_target_transform() const; + + void set_target_node(const NodePath &p_node); + NodePath get_target_node(); + + void set_override_tip_basis(bool p_override); + bool is_override_tip_basis() const; + + void set_use_magnet(bool p_use); + bool is_using_magnet() const; + + void set_magnet_position(const Vector3 &p_local_position); + const Vector3 &get_magnet_position() const; + + void set_min_distance(real_t p_min_distance); + real_t get_min_distance() const { return min_distance; } + + void set_max_iterations(int p_iterations); + int get_max_iterations() const { return max_iterations; } + + Skeleton3D *get_parent_skeleton() const { return skeleton; } + + bool is_running(); + + void start(bool p_one_time = false); + void stop(); + +private: + Transform _get_target_transform(); + void reload_chain(); + void reload_goal(); + void _solve_chain(); +}; + +#endif // _3D_DISABLED + +#endif // SKELETON_IK_H diff --git a/scene/3d/soft_body.cpp b/scene/3d/soft_body_3d.cpp index 65f868aed4..6092818252 100644 --- a/scene/3d/soft_body.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* soft_body.cpp */ +/* soft_body_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,20 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "soft_body.h" +#include "soft_body_3d.h" + #include "core/list.h" #include "core/object.h" #include "core/os/os.h" #include "core/rid.h" -#include "scene/3d/collision_object.h" -#include "scene/3d/physics_body.h" -#include "scene/3d/skeleton.h" -#include "servers/physics_server.h" +#include "scene/3d/collision_object_3d.h" +#include "scene/3d/physics_body_3d.h" +#include "scene/3d/skeleton_3d.h" +#include "servers/physics_server_3d.h" -SoftBodyVisualServerHandler::SoftBodyVisualServerHandler() {} +SoftBodyRenderingServerHandler::SoftBodyRenderingServerHandler() {} -void SoftBodyVisualServerHandler::prepare(RID p_mesh, int p_surface) { +void SoftBodyRenderingServerHandler::prepare(RID p_mesh, int p_surface) { clear(); ERR_FAIL_COND(!p_mesh.is_valid()); @@ -51,19 +52,19 @@ void SoftBodyVisualServerHandler::prepare(RID p_mesh, int p_surface) { #warning Softbody is not working, needs to be redone considering that these functions no longer exist #endif #if 0 - const uint32_t surface_format = VS::get_singleton()->mesh_surface_get_format(mesh, surface); - const int surface_vertex_len = VS::get_singleton()->mesh_surface_get_array_len(mesh, p_surface); - const int surface_index_len = VS::get_singleton()->mesh_surface_get_array_index_len(mesh, p_surface); - uint32_t surface_offsets[VS::ARRAY_MAX]; - - buffer = VS::get_singleton()->mesh_surface_get_array(mesh, surface); - stride = VS::get_singleton()->mesh_surface_make_offsets_from_format(surface_format, surface_vertex_len, surface_index_len, surface_offsets); - offset_vertices = surface_offsets[VS::ARRAY_VERTEX]; - offset_normal = surface_offsets[VS::ARRAY_NORMAL]; + const uint32_t surface_format = RS::get_singleton()->mesh_surface_get_format(mesh, surface); + const int surface_vertex_len = RS::get_singleton()->mesh_surface_get_array_len(mesh, p_surface); + const int surface_index_len = RS::get_singleton()->mesh_surface_get_array_index_len(mesh, p_surface); + uint32_t surface_offsets[RS::ARRAY_MAX]; + + buffer = RS::get_singleton()->mesh_surface_get_array(mesh, surface); + stride = RS::get_singleton()->mesh_surface_make_offsets_from_format(surface_format, surface_vertex_len, surface_index_len, surface_offsets); + offset_vertices = surface_offsets[RS::ARRAY_VERTEX]; + offset_normal = surface_offsets[RS::ARRAY_NORMAL]; #endif } -void SoftBodyVisualServerHandler::clear() { +void SoftBodyRenderingServerHandler::clear() { if (mesh.is_valid()) { buffer.resize(0); @@ -72,43 +73,43 @@ void SoftBodyVisualServerHandler::clear() { mesh = RID(); } -void SoftBodyVisualServerHandler::open() { +void SoftBodyRenderingServerHandler::open() { write_buffer = buffer.ptrw(); } -void SoftBodyVisualServerHandler::close() { +void SoftBodyRenderingServerHandler::close() { //write_buffer.release(); } -void SoftBodyVisualServerHandler::commit_changes() { - VS::get_singleton()->mesh_surface_update_region(mesh, surface, 0, buffer); +void SoftBodyRenderingServerHandler::commit_changes() { + RS::get_singleton()->mesh_surface_update_region(mesh, surface, 0, buffer); } -void SoftBodyVisualServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { +void SoftBodyRenderingServerHandler::set_vertex(int p_vertex_id, const void *p_vector3) { copymem(&write_buffer[p_vertex_id * stride + offset_vertices], p_vector3, sizeof(float) * 3); } -void SoftBodyVisualServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { +void SoftBodyRenderingServerHandler::set_normal(int p_vertex_id, const void *p_vector3) { copymem(&write_buffer[p_vertex_id * stride + offset_normal], p_vector3, sizeof(float) * 3); } -void SoftBodyVisualServerHandler::set_aabb(const AABB &p_aabb) { - VS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb); +void SoftBodyRenderingServerHandler::set_aabb(const AABB &p_aabb) { + RS::get_singleton()->mesh_set_custom_aabb(mesh, p_aabb); } -SoftBody::PinnedPoint::PinnedPoint() : +SoftBody3D::PinnedPoint::PinnedPoint() : point_index(-1), - spatial_attachment(NULL) { + spatial_attachment(nullptr) { } -SoftBody::PinnedPoint::PinnedPoint(const PinnedPoint &obj_tocopy) { +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; } -SoftBody::PinnedPoint SoftBody::PinnedPoint::operator=(const PinnedPoint &obj) { +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; @@ -116,14 +117,14 @@ SoftBody::PinnedPoint SoftBody::PinnedPoint::operator=(const PinnedPoint &obj) { return *this; } -void SoftBody::_update_pickable() { +void SoftBody3D::_update_pickable() { if (!is_inside_tree()) return; bool pickable = ray_pickable && is_visible_in_tree(); - PhysicsServer::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); + PhysicsServer3D::get_singleton()->soft_body_set_ray_pickable(physics_rid, pickable); } -bool SoftBody::_set(const StringName &p_name, const Variant &p_value) { +bool SoftBody3D::_set(const StringName &p_name, const Variant &p_value) { String name = p_name; String which = name.get_slicec('/', 0); @@ -142,7 +143,7 @@ bool SoftBody::_set(const StringName &p_name, const Variant &p_value) { return false; } -bool SoftBody::_get(const StringName &p_name, Variant &r_ret) const { +bool SoftBody3D::_get(const StringName &p_name, Variant &r_ret) const { String name = p_name; String which = name.get_slicec('/', 0); @@ -170,7 +171,7 @@ bool SoftBody::_get(const StringName &p_name, Variant &r_ret) const { return false; } -void SoftBody::_get_property_list(List<PropertyInfo> *p_list) const { +void SoftBody3D::_get_property_list(List<PropertyInfo> *p_list) const { const int pinned_points_indices_size = pinned_points.size(); @@ -183,7 +184,7 @@ void SoftBody::_get_property_list(List<PropertyInfo> *p_list) const { } } -bool SoftBody::_set_property_pinned_points_indices(const Array &p_indices) { +bool SoftBody3D::_set_property_pinned_points_indices(const Array &p_indices) { const int p_indices_size = p_indices.size(); @@ -212,7 +213,7 @@ bool SoftBody::_set_property_pinned_points_indices(const Array &p_indices) { return true; } -bool SoftBody::_set_property_pinned_points_attachment(int p_item, const String &p_what, const Variant &p_value) { +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; } @@ -231,7 +232,7 @@ bool SoftBody::_set_property_pinned_points_attachment(int p_item, const String & return true; } -bool SoftBody::_get_property_pinned_points(int p_item, const String &p_what, Variant &r_ret) const { +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; } @@ -250,7 +251,7 @@ bool SoftBody::_get_property_pinned_points(int p_item, const String &p_what, Var return true; } -void SoftBody::_changed_callback(Object *p_changed, const char *p_prop) { +void SoftBody3D::_changed_callback(Object *p_changed, const char *p_prop) { prepare_physics_server(); _reset_points_offsets(); #ifdef TOOLS_ENABLED @@ -260,7 +261,7 @@ void SoftBody::_changed_callback(Object *p_changed, const char *p_prop) { #endif } -void SoftBody::_notification(int p_what) { +void SoftBody3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { @@ -270,7 +271,7 @@ void SoftBody::_notification(int p_what) { } RID space = get_world()->get_space(); - PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, space); + PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, space); prepare_physics_server(); } break; case NOTIFICATION_READY: { @@ -285,10 +286,10 @@ void SoftBody::_notification(int p_what) { return; } - PhysicsServer::get_singleton()->soft_body_set_transform(physics_rid, get_global_transform()); + 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 VisualServer only to support custom Transform + // Required to be top level with Transform at center of world in order to modify RenderingServer only to support custom Transform set_as_toplevel(true); set_transform(Transform()); set_notify_transform(true); @@ -301,7 +302,7 @@ void SoftBody::_notification(int p_what) { } break; case NOTIFICATION_EXIT_WORLD: { - PhysicsServer::get_singleton()->soft_body_set_space(physics_rid, RID()); + PhysicsServer3D::get_singleton()->soft_body_set_space(physics_rid, RID()); } break; } @@ -317,56 +318,56 @@ void SoftBody::_notification(int p_what) { #endif } -void SoftBody::_bind_methods() { +void SoftBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &SoftBody::set_collision_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &SoftBody::get_collision_mask); + 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"), &SoftBody::set_collision_layer); - ClassDB::bind_method(D_METHOD("get_collision_layer"), &SoftBody::get_collision_layer); + 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_bit", "bit", "value"), &SoftBody::set_collision_mask_bit); - ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &SoftBody::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &SoftBody3D::set_collision_mask_bit); + ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &SoftBody3D::get_collision_mask_bit); - ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &SoftBody::set_collision_layer_bit); - ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &SoftBody::get_collision_layer_bit); + ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &SoftBody3D::set_collision_layer_bit); + ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &SoftBody3D::get_collision_layer_bit); - ClassDB::bind_method(D_METHOD("set_parent_collision_ignore", "parent_collision_ignore"), &SoftBody::set_parent_collision_ignore); - ClassDB::bind_method(D_METHOD("get_parent_collision_ignore"), &SoftBody::get_parent_collision_ignore); + 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("get_collision_exceptions"), &SoftBody::get_collision_exceptions); - ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body"), &SoftBody::add_collision_exception_with); - ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body"), &SoftBody::remove_collision_exception_with); + 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"), &SoftBody::set_simulation_precision); - ClassDB::bind_method(D_METHOD("get_simulation_precision"), &SoftBody::get_simulation_precision); + 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"), &SoftBody::set_total_mass); - ClassDB::bind_method(D_METHOD("get_total_mass"), &SoftBody::get_total_mass); + 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"), &SoftBody::set_linear_stiffness); - ClassDB::bind_method(D_METHOD("get_linear_stiffness"), &SoftBody::get_linear_stiffness); + 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_areaAngular_stiffness", "areaAngular_stiffness"), &SoftBody::set_areaAngular_stiffness); - ClassDB::bind_method(D_METHOD("get_areaAngular_stiffness"), &SoftBody::get_areaAngular_stiffness); + ClassDB::bind_method(D_METHOD("set_areaAngular_stiffness", "areaAngular_stiffness"), &SoftBody3D::set_areaAngular_stiffness); + ClassDB::bind_method(D_METHOD("get_areaAngular_stiffness"), &SoftBody3D::get_areaAngular_stiffness); - ClassDB::bind_method(D_METHOD("set_volume_stiffness", "volume_stiffness"), &SoftBody::set_volume_stiffness); - ClassDB::bind_method(D_METHOD("get_volume_stiffness"), &SoftBody::get_volume_stiffness); + ClassDB::bind_method(D_METHOD("set_volume_stiffness", "volume_stiffness"), &SoftBody3D::set_volume_stiffness); + ClassDB::bind_method(D_METHOD("get_volume_stiffness"), &SoftBody3D::get_volume_stiffness); - ClassDB::bind_method(D_METHOD("set_pressure_coefficient", "pressure_coefficient"), &SoftBody::set_pressure_coefficient); - ClassDB::bind_method(D_METHOD("get_pressure_coefficient"), &SoftBody::get_pressure_coefficient); + 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_pose_matching_coefficient", "pose_matching_coefficient"), &SoftBody::set_pose_matching_coefficient); - ClassDB::bind_method(D_METHOD("get_pose_matching_coefficient"), &SoftBody::get_pose_matching_coefficient); + ClassDB::bind_method(D_METHOD("set_pose_matching_coefficient", "pose_matching_coefficient"), &SoftBody3D::set_pose_matching_coefficient); + ClassDB::bind_method(D_METHOD("get_pose_matching_coefficient"), &SoftBody3D::get_pose_matching_coefficient); - ClassDB::bind_method(D_METHOD("set_damping_coefficient", "damping_coefficient"), &SoftBody::set_damping_coefficient); - ClassDB::bind_method(D_METHOD("get_damping_coefficient"), &SoftBody::get_damping_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"), &SoftBody::set_drag_coefficient); - ClassDB::bind_method(D_METHOD("get_drag_coefficient"), &SoftBody::get_drag_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("set_ray_pickable", "ray_pickable"), &SoftBody::set_ray_pickable); - ClassDB::bind_method(D_METHOD("is_ray_pickable"), &SoftBody::is_ray_pickable); + 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"); @@ -386,9 +387,9 @@ void SoftBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ray_pickable"), "set_ray_pickable", "is_ray_pickable"); } -String SoftBody::get_configuration_warning() const { +String SoftBody3D::get_configuration_warning() const { - String warning = MeshInstance::get_configuration_warning(); + String warning = MeshInstance3D::get_configuration_warning(); if (get_mesh().is_null()) { if (!warning.empty()) @@ -402,13 +403,13 @@ String SoftBody::get_configuration_warning() const { if (!warning.empty()) warning += "\n\n"; - warning += TTR("Size changes to SoftBody will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); + warning += TTR("Size changes to SoftBody3D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } return warning; } -void SoftBody::_update_physics_server() { +void SoftBody3D::_update_physics_server() { if (!simulation_started) return; @@ -418,18 +419,18 @@ void SoftBody::_update_physics_server() { const PinnedPoint *r = pinned_points.ptr(); for (int i = 0; i < pinned_points_indices_size; ++i) { if (r[i].spatial_attachment) { - PhysicsServer::get_singleton()->soft_body_move_point(physics_rid, r[i].point_index, r[i].spatial_attachment->get_global_transform().xform(r[i].offset)); + 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 SoftBody::_draw_soft_mesh() { +void SoftBody3D::_draw_soft_mesh() { if (get_mesh().is_null()) return; - if (!visual_server_handler.is_ready()) { + if (!rendering_server_handler.is_ready()) { - visual_server_handler.prepare(get_mesh()->get_rid(), 0); + 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; @@ -439,21 +440,21 @@ void SoftBody::_draw_soft_mesh() { _update_physics_server(); - visual_server_handler.open(); - PhysicsServer::get_singleton()->soft_body_update_visual_server(physics_rid, &visual_server_handler); - visual_server_handler.close(); + rendering_server_handler.open(); + PhysicsServer3D::get_singleton()->soft_body_update_rendering_server(physics_rid, &rendering_server_handler); + rendering_server_handler.close(); - visual_server_handler.commit_changes(); + rendering_server_handler.commit_changes(); } -void SoftBody::prepare_physics_server() { +void SoftBody3D::prepare_physics_server() { if (Engine::get_singleton()->is_editor_hint()) { if (get_mesh().is_valid()) - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); else - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, NULL); + PhysicsServer3D::get_singleton()->soft_body_set_mesh(physics_rid, nullptr); return; } @@ -461,18 +462,18 @@ void SoftBody::prepare_physics_server() { if (get_mesh().is_valid()) { become_mesh_owner(); - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, get_mesh()); - VS::get_singleton()->connect("frame_pre_draw", callable_mp(this, &SoftBody::_draw_soft_mesh)); + 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 { - PhysicsServer::get_singleton()->soft_body_set_mesh(physics_rid, NULL); - if (VS::get_singleton()->is_connected("frame_pre_draw", callable_mp(this, &SoftBody::_draw_soft_mesh))) { - VS::get_singleton()->disconnect("frame_pre_draw", callable_mp(this, &SoftBody::_draw_soft_mesh)); + 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 SoftBody::become_mesh_owner() { +void SoftBody3D::become_mesh_owner() { if (mesh.is_null()) return; @@ -506,24 +507,24 @@ void SoftBody::become_mesh_owner() { } } -void SoftBody::set_collision_mask(uint32_t p_mask) { +void SoftBody3D::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - PhysicsServer::get_singleton()->soft_body_set_collision_mask(physics_rid, p_mask); + PhysicsServer3D::get_singleton()->soft_body_set_collision_mask(physics_rid, p_mask); } -uint32_t SoftBody::get_collision_mask() const { +uint32_t SoftBody3D::get_collision_mask() const { return collision_mask; } -void SoftBody::set_collision_layer(uint32_t p_layer) { +void SoftBody3D::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - PhysicsServer::get_singleton()->soft_body_set_collision_layer(physics_rid, p_layer); + PhysicsServer3D::get_singleton()->soft_body_set_collision_layer(physics_rid, p_layer); } -uint32_t SoftBody::get_collision_layer() const { +uint32_t SoftBody3D::get_collision_layer() const { return collision_layer; } -void SoftBody::set_collision_mask_bit(int p_bit, bool p_value) { +void SoftBody3D::set_collision_mask_bit(int p_bit, bool p_value) { uint32_t mask = get_collision_mask(); if (p_value) mask |= 1 << p_bit; @@ -532,11 +533,11 @@ void SoftBody::set_collision_mask_bit(int p_bit, bool p_value) { set_collision_mask(mask); } -bool SoftBody::get_collision_mask_bit(int p_bit) const { +bool SoftBody3D::get_collision_mask_bit(int p_bit) const { return get_collision_mask() & (1 << p_bit); } -void SoftBody::set_collision_layer_bit(int p_bit, bool p_value) { +void SoftBody3D::set_collision_layer_bit(int p_bit, bool p_value) { uint32_t layer = get_collision_layer(); if (p_value) layer |= 1 << p_bit; @@ -545,138 +546,138 @@ void SoftBody::set_collision_layer_bit(int p_bit, bool p_value) { set_collision_layer(layer); } -bool SoftBody::get_collision_layer_bit(int p_bit) const { +bool SoftBody3D::get_collision_layer_bit(int p_bit) const { return get_collision_layer() & (1 << p_bit); } -void SoftBody::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { +void SoftBody3D::set_parent_collision_ignore(const NodePath &p_parent_collision_ignore) { parent_collision_ignore = p_parent_collision_ignore; } -const NodePath &SoftBody::get_parent_collision_ignore() const { +const NodePath &SoftBody3D::get_parent_collision_ignore() const { return parent_collision_ignore; } -void SoftBody::set_pinned_points_indices(Vector<SoftBody::PinnedPoint> p_pinned_points_indices) { +void SoftBody3D::set_pinned_points_indices(Vector<SoftBody3D::PinnedPoint> 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<SoftBody::PinnedPoint> SoftBody::get_pinned_points_indices() { +Vector<SoftBody3D::PinnedPoint> SoftBody3D::get_pinned_points_indices() { return pinned_points; } -Array SoftBody::get_collision_exceptions() { +Array SoftBody3D::get_collision_exceptions() { List<RID> exceptions; - PhysicsServer::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); + PhysicsServer3D::get_singleton()->soft_body_get_collision_exceptions(physics_rid, &exceptions); Array ret; for (List<RID>::Element *E = exceptions.front(); E; E = E->next()) { RID body = E->get(); - ObjectID instance_id = PhysicsServer::get_singleton()->body_get_object_instance_id(body); + ObjectID instance_id = PhysicsServer3D::get_singleton()->body_get_object_instance_id(body); Object *obj = ObjectDB::get_instance(instance_id); - PhysicsBody *physics_body = Object::cast_to<PhysicsBody>(obj); + PhysicsBody3D *physics_body = Object::cast_to<PhysicsBody3D>(obj); ret.append(physics_body); } return ret; } -void SoftBody::add_collision_exception_with(Node *p_node) { +void SoftBody3D::add_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->soft_body_add_collision_exception(physics_rid, collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(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 SoftBody::remove_collision_exception_with(Node *p_node) { +void SoftBody3D::remove_collision_exception_with(Node *p_node) { ERR_FAIL_NULL(p_node); - CollisionObject *collision_object = Object::cast_to<CollisionObject>(p_node); - ERR_FAIL_COND_MSG(!collision_object, "Collision exception only works between two CollisionObject."); - PhysicsServer::get_singleton()->soft_body_remove_collision_exception(physics_rid, collision_object->get_rid()); + CollisionObject3D *collision_object = Object::cast_to<CollisionObject3D>(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 SoftBody::get_simulation_precision() { - return PhysicsServer::get_singleton()->soft_body_get_simulation_precision(physics_rid); +int SoftBody3D::get_simulation_precision() { + return PhysicsServer3D::get_singleton()->soft_body_get_simulation_precision(physics_rid); } -void SoftBody::set_simulation_precision(int p_simulation_precision) { - PhysicsServer::get_singleton()->soft_body_set_simulation_precision(physics_rid, p_simulation_precision); +void SoftBody3D::set_simulation_precision(int p_simulation_precision) { + PhysicsServer3D::get_singleton()->soft_body_set_simulation_precision(physics_rid, p_simulation_precision); } -real_t SoftBody::get_total_mass() { - return PhysicsServer::get_singleton()->soft_body_get_total_mass(physics_rid); +real_t SoftBody3D::get_total_mass() { + return PhysicsServer3D::get_singleton()->soft_body_get_total_mass(physics_rid); } -void SoftBody::set_total_mass(real_t p_total_mass) { - PhysicsServer::get_singleton()->soft_body_set_total_mass(physics_rid, p_total_mass); +void SoftBody3D::set_total_mass(real_t p_total_mass) { + PhysicsServer3D::get_singleton()->soft_body_set_total_mass(physics_rid, p_total_mass); } -void SoftBody::set_linear_stiffness(real_t p_linear_stiffness) { - PhysicsServer::get_singleton()->soft_body_set_linear_stiffness(physics_rid, p_linear_stiffness); +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 SoftBody::get_linear_stiffness() { - return PhysicsServer::get_singleton()->soft_body_get_linear_stiffness(physics_rid); +real_t SoftBody3D::get_linear_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_linear_stiffness(physics_rid); } -void SoftBody::set_areaAngular_stiffness(real_t p_areaAngular_stiffness) { - PhysicsServer::get_singleton()->soft_body_set_areaAngular_stiffness(physics_rid, p_areaAngular_stiffness); +void SoftBody3D::set_areaAngular_stiffness(real_t p_areaAngular_stiffness) { + PhysicsServer3D::get_singleton()->soft_body_set_areaAngular_stiffness(physics_rid, p_areaAngular_stiffness); } -real_t SoftBody::get_areaAngular_stiffness() { - return PhysicsServer::get_singleton()->soft_body_get_areaAngular_stiffness(physics_rid); +real_t SoftBody3D::get_areaAngular_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_areaAngular_stiffness(physics_rid); } -void SoftBody::set_volume_stiffness(real_t p_volume_stiffness) { - PhysicsServer::get_singleton()->soft_body_set_volume_stiffness(physics_rid, p_volume_stiffness); +void SoftBody3D::set_volume_stiffness(real_t p_volume_stiffness) { + PhysicsServer3D::get_singleton()->soft_body_set_volume_stiffness(physics_rid, p_volume_stiffness); } -real_t SoftBody::get_volume_stiffness() { - return PhysicsServer::get_singleton()->soft_body_get_volume_stiffness(physics_rid); +real_t SoftBody3D::get_volume_stiffness() { + return PhysicsServer3D::get_singleton()->soft_body_get_volume_stiffness(physics_rid); } -real_t SoftBody::get_pressure_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_pressure_coefficient(physics_rid); +real_t SoftBody3D::get_pressure_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_pressure_coefficient(physics_rid); } -void SoftBody::set_pose_matching_coefficient(real_t p_pose_matching_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_pose_matching_coefficient(physics_rid, p_pose_matching_coefficient); +void SoftBody3D::set_pose_matching_coefficient(real_t p_pose_matching_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_pose_matching_coefficient(physics_rid, p_pose_matching_coefficient); } -real_t SoftBody::get_pose_matching_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_pose_matching_coefficient(physics_rid); +real_t SoftBody3D::get_pose_matching_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_pose_matching_coefficient(physics_rid); } -void SoftBody::set_pressure_coefficient(real_t p_pressure_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_pressure_coefficient(physics_rid, p_pressure_coefficient); +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 SoftBody::get_damping_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_damping_coefficient(physics_rid); +real_t SoftBody3D::get_damping_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_damping_coefficient(physics_rid); } -void SoftBody::set_damping_coefficient(real_t p_damping_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_damping_coefficient(physics_rid, p_damping_coefficient); +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 SoftBody::get_drag_coefficient() { - return PhysicsServer::get_singleton()->soft_body_get_drag_coefficient(physics_rid); +real_t SoftBody3D::get_drag_coefficient() { + return PhysicsServer3D::get_singleton()->soft_body_get_drag_coefficient(physics_rid); } -void SoftBody::set_drag_coefficient(real_t p_drag_coefficient) { - PhysicsServer::get_singleton()->soft_body_set_drag_coefficient(physics_rid, p_drag_coefficient); +void SoftBody3D::set_drag_coefficient(real_t p_drag_coefficient) { + PhysicsServer3D::get_singleton()->soft_body_set_drag_coefficient(physics_rid, p_drag_coefficient); } -Vector3 SoftBody::get_point_transform(int p_point_index) { - return PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, p_point_index); +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 SoftBody::pin_point_toggle(int 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 SoftBody::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_attachment_path) { +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); @@ -685,23 +686,23 @@ void SoftBody::pin_point(int p_point_index, bool pin, const NodePath &p_spatial_ } } -bool SoftBody::is_point_pinned(int p_point_index) const { +bool SoftBody3D::is_point_pinned(int p_point_index) const { return -1 != _has_pinned_point(p_point_index); } -void SoftBody::set_ray_pickable(bool p_ray_pickable) { +void SoftBody3D::set_ray_pickable(bool p_ray_pickable) { ray_pickable = p_ray_pickable; _update_pickable(); } -bool SoftBody::is_ray_pickable() const { +bool SoftBody3D::is_ray_pickable() const { return ray_pickable; } -SoftBody::SoftBody() : - physics_rid(PhysicsServer::get_singleton()->soft_body_create()), +SoftBody3D::SoftBody3D() : + physics_rid(PhysicsServer3D::get_singleton()->soft_body_create()), mesh_owner(false), collision_mask(1), collision_layer(1), @@ -709,26 +710,26 @@ SoftBody::SoftBody() : pinned_points_cache_dirty(true), ray_pickable(true) { - PhysicsServer::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id()); + PhysicsServer3D::get_singleton()->body_attach_object_instance_id(physics_rid, get_instance_id()); } -SoftBody::~SoftBody() { - PhysicsServer::get_singleton()->free(physics_rid); +SoftBody3D::~SoftBody3D() { + PhysicsServer3D::get_singleton()->free(physics_rid); } -void SoftBody::reset_softbody_pin() { - PhysicsServer::get_singleton()->soft_body_remove_all_pinned_points(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) { - PhysicsServer::get_singleton()->soft_body_pin_point(physics_rid, pps[i].point_index, true); + PhysicsServer3D::get_singleton()->soft_body_pin_point(physics_rid, pps[i].point_index, true); } } -void SoftBody::_make_cache_dirty() { +void SoftBody3D::_make_cache_dirty() { pinned_points_cache_dirty = true; } -void SoftBody::_update_cache_pin_points_datas() { +void SoftBody3D::_update_cache_pin_points_datas() { if (!pinned_points_cache_dirty) return; @@ -738,20 +739,20 @@ void SoftBody::_update_cache_pin_points_datas() { 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<Spatial>(get_node(w[i].spatial_attachment_path)); + w[i].spatial_attachment = Object::cast_to<Node3D>(get_node(w[i].spatial_attachment_path)); } if (!w[i].spatial_attachment) { - ERR_PRINT("Spatial node not defined in the pinned point, Softbody undefined behaviour!"); + ERR_PRINT("Node3D node not defined in the pinned point, Softbody undefined behaviour!"); } } } -void SoftBody::_pin_point_on_physics_server(int p_point_index, bool pin) { - PhysicsServer::get_singleton()->soft_body_pin_point(physics_rid, p_point_index, pin); +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 SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_attachment_path) { - SoftBody::PinnedPoint *pinned_point; +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 @@ -760,8 +761,8 @@ void SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_at 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<Spatial>(get_node(p_spatial_attachment_path)); - pp.offset = (pp.spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, pp.point_index)); + pp.spatial_attachment = Object::cast_to<Node3D>(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); @@ -772,13 +773,13 @@ void SoftBody::_add_pinned_point(int p_point_index, const NodePath &p_spatial_at 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<Spatial>(get_node(p_spatial_attachment_path)); - pinned_point->offset = (pinned_point->spatial_attachment->get_global_transform().affine_inverse() * get_global_transform()).xform(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, pinned_point->point_index)); + pinned_point->spatial_attachment = Object::cast_to<Node3D>(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 SoftBody::_reset_points_offsets() { +void SoftBody3D::_reset_points_offsets() { if (!Engine::get_singleton()->is_editor_hint()) return; @@ -788,34 +789,34 @@ void SoftBody::_reset_points_offsets() { for (int i = pinned_points.size() - 1; 0 <= i; --i) { if (!r[i].spatial_attachment) - w[i].spatial_attachment = Object::cast_to<Spatial>(get_node(r[i].spatial_attachment_path)); + w[i].spatial_attachment = Object::cast_to<Node3D>(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(PhysicsServer::get_singleton()->soft_body_get_point_global_position(physics_rid, r[i].point_index)); + 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 SoftBody::_remove_pinned_point(int p_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 SoftBody::_get_pinned_point(int p_point_index, SoftBody::PinnedPoint *&r_point) const { +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 = NULL; + r_point = nullptr; return -1; } else { - r_point = const_cast<SoftBody::PinnedPoint *>(&pinned_points.ptr()[id]); + r_point = const_cast<SoftBody3D::PinnedPoint *>(&pinned_points.ptr()[id]); return id; } } -int SoftBody::_has_pinned_point(int p_point_index) const { +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) { diff --git a/scene/3d/soft_body.h b/scene/3d/soft_body_3d.h index d6c35a5989..7dd5880985 100644 --- a/scene/3d/soft_body.h +++ b/scene/3d/soft_body_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* soft_body.h */ +/* soft_body_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,13 +31,13 @@ #ifndef SOFT_PHYSICS_BODY_H #define SOFT_PHYSICS_BODY_H -#include "scene/3d/mesh_instance.h" +#include "scene/3d/mesh_instance_3d.h" -class SoftBody; +class SoftBody3D; -class SoftBodyVisualServerHandler { +class SoftBodyRenderingServerHandler { - friend class SoftBody; + friend class SoftBody3D; RID mesh; int surface; @@ -49,7 +49,7 @@ class SoftBodyVisualServerHandler { uint8_t *write_buffer; private: - SoftBodyVisualServerHandler(); + SoftBodyRenderingServerHandler(); bool is_ready() { return mesh.is_valid(); } void prepare(RID p_mesh_rid, int p_surface); void clear(); @@ -63,14 +63,14 @@ public: void set_aabb(const AABB &p_aabb); }; -class SoftBody : public MeshInstance { - GDCLASS(SoftBody, MeshInstance); +class SoftBody3D : public MeshInstance3D { + GDCLASS(SoftBody3D, MeshInstance3D); public: struct PinnedPoint { int point_index; NodePath spatial_attachment_path; - Spatial *spatial_attachment; // Cache + Node3D *spatial_attachment; // Cache Vector3 offset; PinnedPoint(); @@ -79,7 +79,7 @@ public: }; private: - SoftBodyVisualServerHandler visual_server_handler; + SoftBodyRenderingServerHandler rendering_server_handler; RID physics_rid; @@ -92,7 +92,7 @@ private: bool pinned_points_cache_dirty; Ref<ArrayMesh> debug_mesh_cache; - class MeshInstance *debug_mesh; + class MeshInstance3D *debug_mesh; bool capture_input_on_drag; bool ray_pickable; @@ -181,8 +181,8 @@ public: void set_ray_pickable(bool p_ray_pickable); bool is_ray_pickable() const; - SoftBody(); - ~SoftBody(); + SoftBody3D(); + ~SoftBody3D(); private: void reset_softbody_pin(); diff --git a/scene/3d/spring_arm.cpp b/scene/3d/spring_arm_3d.cpp index ce277dae5b..0ffde7aa8f 100644 --- a/scene/3d/spring_arm.cpp +++ b/scene/3d/spring_arm_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spring_arm.cpp */ +/* spring_arm_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,115 +28,115 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "spring_arm.h" +#include "spring_arm_3d.h" #include "core/engine.h" -#include "scene/3d/collision_object.h" -#include "scene/resources/sphere_shape.h" -#include "servers/physics_server.h" +#include "scene/3d/collision_object_3d.h" +#include "scene/resources/sphere_shape_3d.h" +#include "servers/physics_server_3d.h" -SpringArm::SpringArm() : +SpringArm3D::SpringArm3D() : spring_length(1), current_spring_length(0), keep_child_basis(false), mask(1), margin(0.01) {} -void SpringArm::_notification(int p_what) { +void SpringArm3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: if (!Engine::get_singleton()->is_editor_hint()) { - set_process_internal(true); + set_physics_process_internal(true); } break; case NOTIFICATION_EXIT_TREE: if (!Engine::get_singleton()->is_editor_hint()) { - set_process_internal(false); + set_physics_process_internal(false); } break; - case NOTIFICATION_INTERNAL_PROCESS: + case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: process_spring(); break; } } -void SpringArm::_bind_methods() { +void SpringArm3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("get_hit_length"), &SpringArm::get_hit_length); + ClassDB::bind_method(D_METHOD("get_hit_length"), &SpringArm3D::get_hit_length); - ClassDB::bind_method(D_METHOD("set_length", "length"), &SpringArm::set_length); - ClassDB::bind_method(D_METHOD("get_length"), &SpringArm::get_length); + ClassDB::bind_method(D_METHOD("set_length", "length"), &SpringArm3D::set_length); + ClassDB::bind_method(D_METHOD("get_length"), &SpringArm3D::get_length); - ClassDB::bind_method(D_METHOD("set_shape", "shape"), &SpringArm::set_shape); - ClassDB::bind_method(D_METHOD("get_shape"), &SpringArm::get_shape); + ClassDB::bind_method(D_METHOD("set_shape", "shape"), &SpringArm3D::set_shape); + ClassDB::bind_method(D_METHOD("get_shape"), &SpringArm3D::get_shape); - ClassDB::bind_method(D_METHOD("add_excluded_object", "RID"), &SpringArm::add_excluded_object); - ClassDB::bind_method(D_METHOD("remove_excluded_object", "RID"), &SpringArm::remove_excluded_object); - ClassDB::bind_method(D_METHOD("clear_excluded_objects"), &SpringArm::clear_excluded_objects); + ClassDB::bind_method(D_METHOD("add_excluded_object", "RID"), &SpringArm3D::add_excluded_object); + ClassDB::bind_method(D_METHOD("remove_excluded_object", "RID"), &SpringArm3D::remove_excluded_object); + ClassDB::bind_method(D_METHOD("clear_excluded_objects"), &SpringArm3D::clear_excluded_objects); - ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &SpringArm::set_mask); - ClassDB::bind_method(D_METHOD("get_collision_mask"), &SpringArm::get_mask); + ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &SpringArm3D::set_mask); + ClassDB::bind_method(D_METHOD("get_collision_mask"), &SpringArm3D::get_mask); - ClassDB::bind_method(D_METHOD("set_margin", "margin"), &SpringArm::set_margin); - ClassDB::bind_method(D_METHOD("get_margin"), &SpringArm::get_margin); + ClassDB::bind_method(D_METHOD("set_margin", "margin"), &SpringArm3D::set_margin); + ClassDB::bind_method(D_METHOD("get_margin"), &SpringArm3D::get_margin); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape"), "set_shape", "get_shape"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape3D"), "set_shape", "get_shape"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "spring_length"), "set_length", "get_length"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "margin"), "set_margin", "get_margin"); } -float SpringArm::get_length() const { +float SpringArm3D::get_length() const { return spring_length; } -void SpringArm::set_length(float p_length) { +void SpringArm3D::set_length(float p_length) { if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) update_gizmo(); spring_length = p_length; } -void SpringArm::set_shape(Ref<Shape> p_shape) { +void SpringArm3D::set_shape(Ref<Shape3D> p_shape) { shape = p_shape; } -Ref<Shape> SpringArm::get_shape() const { +Ref<Shape3D> SpringArm3D::get_shape() const { return shape; } -void SpringArm::set_mask(uint32_t p_mask) { +void SpringArm3D::set_mask(uint32_t p_mask) { mask = p_mask; } -uint32_t SpringArm::get_mask() { +uint32_t SpringArm3D::get_mask() { return mask; } -float SpringArm::get_margin() { +float SpringArm3D::get_margin() { return margin; } -void SpringArm::set_margin(float p_margin) { +void SpringArm3D::set_margin(float p_margin) { margin = p_margin; } -void SpringArm::add_excluded_object(RID p_rid) { +void SpringArm3D::add_excluded_object(RID p_rid) { excluded_objects.insert(p_rid); } -bool SpringArm::remove_excluded_object(RID p_rid) { +bool SpringArm3D::remove_excluded_object(RID p_rid) { return excluded_objects.erase(p_rid); } -void SpringArm::clear_excluded_objects() { +void SpringArm3D::clear_excluded_objects() { excluded_objects.clear(); } -float SpringArm::get_hit_length() { +float SpringArm3D::get_hit_length() { return current_spring_length; } -void SpringArm::process_spring() { +void SpringArm3D::process_spring() { // From real_t motion_delta(1); real_t motion_delta_unsafe(1); @@ -146,7 +146,7 @@ void SpringArm::process_spring() { if (shape.is_null()) { motion = Vector3(cast_direction * (spring_length)); - PhysicsDirectSpaceState::RayResult r; + PhysicsDirectSpaceState3D::RayResult r; bool intersected = get_world()->get_direct_space_state()->intersect_ray(get_global_transform().origin, get_global_transform().origin + motion, r, excluded_objects, mask); if (intersected) { float dist = get_global_transform().origin.distance_to(r.position); @@ -164,7 +164,7 @@ void SpringArm::process_spring() { for (int i = get_child_count() - 1; 0 <= i; --i) { - Spatial *child = Object::cast_to<Spatial>(get_child(i)); + Node3D *child = Object::cast_to<Node3D>(get_child(i)); if (child) { childs_transform.basis = child->get_global_transform().basis; child->set_global_transform(childs_transform); diff --git a/scene/3d/spring_arm.h b/scene/3d/spring_arm_3d.h index 1a12370564..cb8a00ecf9 100644 --- a/scene/3d/spring_arm.h +++ b/scene/3d/spring_arm_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spring_arm.h */ +/* spring_arm_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,12 +31,12 @@ #ifndef SPRING_ARM_H #define SPRING_ARM_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class SpringArm : public Spatial { - GDCLASS(SpringArm, Spatial); +class SpringArm3D : public Node3D { + GDCLASS(SpringArm3D, Node3D); - Ref<Shape> shape; + Ref<Shape3D> shape; Set<RID> excluded_objects; float spring_length; float current_spring_length; @@ -51,8 +51,8 @@ protected: public: void set_length(float p_length); float get_length() const; - void set_shape(Ref<Shape> p_shape); - Ref<Shape> get_shape() const; + void set_shape(Ref<Shape3D> p_shape); + Ref<Shape3D> get_shape() const; void set_mask(uint32_t p_mask); uint32_t get_mask(); void add_excluded_object(RID p_rid); @@ -62,7 +62,7 @@ public: void set_margin(float p_margin); float get_margin(); - SpringArm(); + SpringArm3D(); private: void process_spring(); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index fd22076091..85e5ebc475 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -83,8 +83,8 @@ void SpriteBase3D::_notification(int p_what) { if (parent_sprite) { parent_sprite->children.erase(pI); - pI = NULL; - parent_sprite = NULL; + pI = nullptr; + parent_sprite = nullptr; } } } @@ -364,8 +364,8 @@ SpriteBase3D::SpriteBase3D() { centered = true; hflip = false; vflip = false; - parent_sprite = NULL; - pI = NULL; + parent_sprite = nullptr; + pI = nullptr; for (int i = 0; i < FLAG_MAX; i++) flags[i] = i == FLAG_TRANSPARENT || i == FLAG_DOUBLE_SIDED; @@ -377,13 +377,13 @@ SpriteBase3D::SpriteBase3D() { modulate = Color(1, 1, 1, 1); pending_update = false; opacity = 1.0; - immediate = VisualServer::get_singleton()->immediate_create(); + immediate = RenderingServer::get_singleton()->immediate_create(); set_base(immediate); } SpriteBase3D::~SpriteBase3D() { - VisualServer::get_singleton()->free(immediate); + RenderingServer::get_singleton()->free(immediate); } /////////////////////////////////////////// @@ -392,7 +392,7 @@ void Sprite3D::_draw() { RID immediate = get_immediate(); - VS::get_singleton()->immediate_clear(immediate); + RS::get_singleton()->immediate_clear(immediate); if (!texture.is_valid()) return; Vector2 tsize = texture->get_size(); @@ -441,7 +441,7 @@ void Sprite3D::_draw() { // Properly setup UVs for impostor textures (AtlasTexture). Ref<AtlasTexture> atlas_tex = texture; - if (atlas_tex != NULL) { + if (atlas_tex != nullptr) { src_tsize[0] = atlas_tex->get_atlas()->get_width(); src_tsize[1] = atlas_tex->get_atlas()->get_height(); } @@ -475,9 +475,9 @@ void Sprite3D::_draw() { } RID mat = StandardMaterial3D::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y); - VS::get_singleton()->immediate_set_material(immediate, mat); + RS::get_singleton()->immediate_set_material(immediate, mat); - VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLES, texture->get_rid()); + RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_TRIANGLES, texture->get_rid()); int x_axis = ((axis + 1) % 3); int y_axis = ((axis + 2) % 3); @@ -502,15 +502,15 @@ void Sprite3D::_draw() { static const int index[6] = { 0, 1, 2, 0, 2, 3 }; - VS::get_singleton()->immediate_normal(immediate, normal); - VS::get_singleton()->immediate_tangent(immediate, tangent); - VS::get_singleton()->immediate_color(immediate, color); - VS::get_singleton()->immediate_uv(immediate, uvs[i]); + RS::get_singleton()->immediate_normal(immediate, normal); + RS::get_singleton()->immediate_tangent(immediate, tangent); + RS::get_singleton()->immediate_color(immediate, color); + RS::get_singleton()->immediate_uv(immediate, uvs[i]); Vector3 vtx; vtx[x_axis] = vertices[index[i]][0]; vtx[y_axis] = vertices[index[i]][1]; - VS::get_singleton()->immediate_vertex(immediate, vtx); + RS::get_singleton()->immediate_vertex(immediate, vtx); if (i == 0) { aabb.position = vtx; aabb.size = Vector3(); @@ -519,7 +519,7 @@ void Sprite3D::_draw() { } } set_aabb(aabb); - VS::get_singleton()->immediate_end(immediate); + RS::get_singleton()->immediate_end(immediate); } void Sprite3D::_texture_changed() { @@ -717,7 +717,7 @@ Sprite3D::Sprite3D() { void AnimatedSprite3D::_draw() { RID immediate = get_immediate(); - VS::get_singleton()->immediate_clear(immediate); + RS::get_singleton()->immediate_clear(immediate); if (frames.is_null()) { return; @@ -775,7 +775,7 @@ void AnimatedSprite3D::_draw() { // Properly setup UVs for impostor textures (AtlasTexture). Ref<AtlasTexture> atlas_tex = texture; - if (atlas_tex != NULL) { + if (atlas_tex != nullptr) { src_tsize[0] = atlas_tex->get_atlas()->get_width(); src_tsize[1] = atlas_tex->get_atlas()->get_height(); } @@ -810,9 +810,9 @@ void AnimatedSprite3D::_draw() { RID mat = StandardMaterial3D::get_material_rid_for_2d(get_draw_flag(FLAG_SHADED), get_draw_flag(FLAG_TRANSPARENT), get_draw_flag(FLAG_DOUBLE_SIDED), get_alpha_cut_mode() == ALPHA_CUT_DISCARD, get_alpha_cut_mode() == ALPHA_CUT_OPAQUE_PREPASS, get_billboard_mode() == StandardMaterial3D::BILLBOARD_ENABLED, get_billboard_mode() == StandardMaterial3D::BILLBOARD_FIXED_Y); - VS::get_singleton()->immediate_set_material(immediate, mat); + RS::get_singleton()->immediate_set_material(immediate, mat); - VS::get_singleton()->immediate_begin(immediate, VS::PRIMITIVE_TRIANGLES, texture->get_rid()); + RS::get_singleton()->immediate_begin(immediate, RS::PRIMITIVE_TRIANGLES, texture->get_rid()); int x_axis = ((axis + 1) % 3); int y_axis = ((axis + 2) % 3); @@ -840,15 +840,15 @@ void AnimatedSprite3D::_draw() { 0, 2, 3 }; - VS::get_singleton()->immediate_normal(immediate, normal); - VS::get_singleton()->immediate_tangent(immediate, tangent); - VS::get_singleton()->immediate_color(immediate, color); - VS::get_singleton()->immediate_uv(immediate, uvs[i]); + RS::get_singleton()->immediate_normal(immediate, normal); + RS::get_singleton()->immediate_tangent(immediate, tangent); + RS::get_singleton()->immediate_color(immediate, color); + RS::get_singleton()->immediate_uv(immediate, uvs[i]); Vector3 vtx; vtx[x_axis] = vertices[indices[i]][0]; vtx[y_axis] = vertices[indices[i]][1]; - VS::get_singleton()->immediate_vertex(immediate, vtx); + RS::get_singleton()->immediate_vertex(immediate, vtx); if (i == 0) { aabb.position = vtx; aabb.size = Vector3(); @@ -857,7 +857,7 @@ void AnimatedSprite3D::_draw() { } } set_aabb(aabb); - VS::get_singleton()->immediate_end(immediate); + RS::get_singleton()->immediate_end(immediate); } void AnimatedSprite3D::_validate_property(PropertyInfo &property) const { diff --git a/scene/3d/sprite_3d.h b/scene/3d/sprite_3d.h index 082884c83b..64bef41fd8 100644 --- a/scene/3d/sprite_3d.h +++ b/scene/3d/sprite_3d.h @@ -31,12 +31,12 @@ #ifndef SPRITE_3D_H #define SPRITE_3D_H -#include "scene/2d/animated_sprite.h" -#include "scene/3d/visual_instance.h" +#include "scene/2d/animated_sprite_2d.h" +#include "scene/3d/visual_instance_3d.h" -class SpriteBase3D : public GeometryInstance { +class SpriteBase3D : public GeometryInstance3D { - GDCLASS(SpriteBase3D, GeometryInstance); + GDCLASS(SpriteBase3D, GeometryInstance3D); mutable Ref<TriangleMesh> triangle_mesh; //cached diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body_3d.cpp index c249d844d1..5c2fa59a21 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* vehicle_body.cpp */ +/* vehicle_body_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,7 +28,7 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "vehicle_body.h" +#include "vehicle_body_3d.h" #define ROLLING_INFLUENCE_FIX @@ -78,11 +78,11 @@ public: } }; -void VehicleWheel::_notification(int p_what) { +void VehicleWheel3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - VehicleBody *cb = Object::cast_to<VehicleBody>(get_parent()); + VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); if (!cb) return; body = cb; @@ -95,23 +95,23 @@ void VehicleWheel::_notification(int p_what) { } if (p_what == NOTIFICATION_EXIT_TREE) { - VehicleBody *cb = Object::cast_to<VehicleBody>(get_parent()); + VehicleBody3D *cb = Object::cast_to<VehicleBody3D>(get_parent()); if (!cb) return; cb->wheels.erase(this); - body = NULL; + body = nullptr; } } -String VehicleWheel::get_configuration_warning() const { - if (!Object::cast_to<VehicleBody>(get_parent())) { - return TTR("VehicleWheel serves to provide a wheel system to a VehicleBody. Please use it as a child of a VehicleBody."); +String VehicleWheel3D::get_configuration_warning() const { + if (!Object::cast_to<VehicleBody3D>(get_parent())) { + return TTR("VehicleWheel3D serves to provide a wheel system to a VehicleBody3D. Please use it as a child of a VehicleBody3D."); } return String(); } -void VehicleWheel::_update(PhysicsDirectBodyState *s) { +void VehicleWheel3D::_update(PhysicsDirectBodyState3D *s) { if (m_raycastInfo.m_isInContact) @@ -144,148 +144,148 @@ void VehicleWheel::_update(PhysicsDirectBodyState *s) { } } -void VehicleWheel::set_radius(float p_radius) { +void VehicleWheel3D::set_radius(float p_radius) { m_wheelRadius = p_radius; update_gizmo(); } -float VehicleWheel::get_radius() const { +float VehicleWheel3D::get_radius() const { return m_wheelRadius; } -void VehicleWheel::set_suspension_rest_length(float p_length) { +void VehicleWheel3D::set_suspension_rest_length(float p_length) { m_suspensionRestLength = p_length; update_gizmo(); } -float VehicleWheel::get_suspension_rest_length() const { +float VehicleWheel3D::get_suspension_rest_length() const { return m_suspensionRestLength; } -void VehicleWheel::set_suspension_travel(float p_length) { +void VehicleWheel3D::set_suspension_travel(float p_length) { m_maxSuspensionTravelCm = p_length / 0.01; } -float VehicleWheel::get_suspension_travel() const { +float VehicleWheel3D::get_suspension_travel() const { return m_maxSuspensionTravelCm * 0.01; } -void VehicleWheel::set_suspension_stiffness(float p_value) { +void VehicleWheel3D::set_suspension_stiffness(float p_value) { m_suspensionStiffness = p_value; } -float VehicleWheel::get_suspension_stiffness() const { +float VehicleWheel3D::get_suspension_stiffness() const { return m_suspensionStiffness; } -void VehicleWheel::set_suspension_max_force(float p_value) { +void VehicleWheel3D::set_suspension_max_force(float p_value) { m_maxSuspensionForce = p_value; } -float VehicleWheel::get_suspension_max_force() const { +float VehicleWheel3D::get_suspension_max_force() const { return m_maxSuspensionForce; } -void VehicleWheel::set_damping_compression(float p_value) { +void VehicleWheel3D::set_damping_compression(float p_value) { m_wheelsDampingCompression = p_value; } -float VehicleWheel::get_damping_compression() const { +float VehicleWheel3D::get_damping_compression() const { return m_wheelsDampingCompression; } -void VehicleWheel::set_damping_relaxation(float p_value) { +void VehicleWheel3D::set_damping_relaxation(float p_value) { m_wheelsDampingRelaxation = p_value; } -float VehicleWheel::get_damping_relaxation() const { +float VehicleWheel3D::get_damping_relaxation() const { return m_wheelsDampingRelaxation; } -void VehicleWheel::set_friction_slip(float p_value) { +void VehicleWheel3D::set_friction_slip(float p_value) { m_frictionSlip = p_value; } -float VehicleWheel::get_friction_slip() const { +float VehicleWheel3D::get_friction_slip() const { return m_frictionSlip; } -void VehicleWheel::set_roll_influence(float p_value) { +void VehicleWheel3D::set_roll_influence(float p_value) { m_rollInfluence = p_value; } -float VehicleWheel::get_roll_influence() const { +float VehicleWheel3D::get_roll_influence() const { return m_rollInfluence; } -bool VehicleWheel::is_in_contact() const { +bool VehicleWheel3D::is_in_contact() const { return m_raycastInfo.m_isInContact; } -void VehicleWheel::_bind_methods() { +void VehicleWheel3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel::set_radius); - ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel::get_radius); + ClassDB::bind_method(D_METHOD("set_radius", "length"), &VehicleWheel3D::set_radius); + ClassDB::bind_method(D_METHOD("get_radius"), &VehicleWheel3D::get_radius); - ClassDB::bind_method(D_METHOD("set_suspension_rest_length", "length"), &VehicleWheel::set_suspension_rest_length); - ClassDB::bind_method(D_METHOD("get_suspension_rest_length"), &VehicleWheel::get_suspension_rest_length); + ClassDB::bind_method(D_METHOD("set_suspension_rest_length", "length"), &VehicleWheel3D::set_suspension_rest_length); + ClassDB::bind_method(D_METHOD("get_suspension_rest_length"), &VehicleWheel3D::get_suspension_rest_length); - ClassDB::bind_method(D_METHOD("set_suspension_travel", "length"), &VehicleWheel::set_suspension_travel); - ClassDB::bind_method(D_METHOD("get_suspension_travel"), &VehicleWheel::get_suspension_travel); + ClassDB::bind_method(D_METHOD("set_suspension_travel", "length"), &VehicleWheel3D::set_suspension_travel); + ClassDB::bind_method(D_METHOD("get_suspension_travel"), &VehicleWheel3D::get_suspension_travel); - ClassDB::bind_method(D_METHOD("set_suspension_stiffness", "length"), &VehicleWheel::set_suspension_stiffness); - ClassDB::bind_method(D_METHOD("get_suspension_stiffness"), &VehicleWheel::get_suspension_stiffness); + ClassDB::bind_method(D_METHOD("set_suspension_stiffness", "length"), &VehicleWheel3D::set_suspension_stiffness); + ClassDB::bind_method(D_METHOD("get_suspension_stiffness"), &VehicleWheel3D::get_suspension_stiffness); - ClassDB::bind_method(D_METHOD("set_suspension_max_force", "length"), &VehicleWheel::set_suspension_max_force); - ClassDB::bind_method(D_METHOD("get_suspension_max_force"), &VehicleWheel::get_suspension_max_force); + ClassDB::bind_method(D_METHOD("set_suspension_max_force", "length"), &VehicleWheel3D::set_suspension_max_force); + ClassDB::bind_method(D_METHOD("get_suspension_max_force"), &VehicleWheel3D::get_suspension_max_force); - ClassDB::bind_method(D_METHOD("set_damping_compression", "length"), &VehicleWheel::set_damping_compression); - ClassDB::bind_method(D_METHOD("get_damping_compression"), &VehicleWheel::get_damping_compression); + ClassDB::bind_method(D_METHOD("set_damping_compression", "length"), &VehicleWheel3D::set_damping_compression); + ClassDB::bind_method(D_METHOD("get_damping_compression"), &VehicleWheel3D::get_damping_compression); - ClassDB::bind_method(D_METHOD("set_damping_relaxation", "length"), &VehicleWheel::set_damping_relaxation); - ClassDB::bind_method(D_METHOD("get_damping_relaxation"), &VehicleWheel::get_damping_relaxation); + ClassDB::bind_method(D_METHOD("set_damping_relaxation", "length"), &VehicleWheel3D::set_damping_relaxation); + ClassDB::bind_method(D_METHOD("get_damping_relaxation"), &VehicleWheel3D::get_damping_relaxation); - ClassDB::bind_method(D_METHOD("set_use_as_traction", "enable"), &VehicleWheel::set_use_as_traction); - ClassDB::bind_method(D_METHOD("is_used_as_traction"), &VehicleWheel::is_used_as_traction); + ClassDB::bind_method(D_METHOD("set_use_as_traction", "enable"), &VehicleWheel3D::set_use_as_traction); + ClassDB::bind_method(D_METHOD("is_used_as_traction"), &VehicleWheel3D::is_used_as_traction); - ClassDB::bind_method(D_METHOD("set_use_as_steering", "enable"), &VehicleWheel::set_use_as_steering); - ClassDB::bind_method(D_METHOD("is_used_as_steering"), &VehicleWheel::is_used_as_steering); + ClassDB::bind_method(D_METHOD("set_use_as_steering", "enable"), &VehicleWheel3D::set_use_as_steering); + ClassDB::bind_method(D_METHOD("is_used_as_steering"), &VehicleWheel3D::is_used_as_steering); - ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel::set_friction_slip); - ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel::get_friction_slip); + ClassDB::bind_method(D_METHOD("set_friction_slip", "length"), &VehicleWheel3D::set_friction_slip); + ClassDB::bind_method(D_METHOD("get_friction_slip"), &VehicleWheel3D::get_friction_slip); - ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel::is_in_contact); + ClassDB::bind_method(D_METHOD("is_in_contact"), &VehicleWheel3D::is_in_contact); - ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel::set_roll_influence); - ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel::get_roll_influence); + ClassDB::bind_method(D_METHOD("set_roll_influence", "roll_influence"), &VehicleWheel3D::set_roll_influence); + ClassDB::bind_method(D_METHOD("get_roll_influence"), &VehicleWheel3D::get_roll_influence); - ClassDB::bind_method(D_METHOD("get_skidinfo"), &VehicleWheel::get_skidinfo); + ClassDB::bind_method(D_METHOD("get_skidinfo"), &VehicleWheel3D::get_skidinfo); - ClassDB::bind_method(D_METHOD("get_rpm"), &VehicleWheel::get_rpm); + ClassDB::bind_method(D_METHOD("get_rpm"), &VehicleWheel3D::get_rpm); - ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleWheel::set_engine_force); - ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleWheel::get_engine_force); + ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleWheel3D::set_engine_force); + ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleWheel3D::get_engine_force); - ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleWheel::set_brake); - ClassDB::bind_method(D_METHOD("get_brake"), &VehicleWheel::get_brake); + ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleWheel3D::set_brake); + ClassDB::bind_method(D_METHOD("get_brake"), &VehicleWheel3D::get_brake); - ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleWheel::set_steering); - ClassDB::bind_method(D_METHOD("get_steering"), &VehicleWheel::get_steering); + ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleWheel3D::set_steering); + ClassDB::bind_method(D_METHOD("get_steering"), &VehicleWheel3D::get_steering); ADD_GROUP("Per-Wheel Motion", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "engine_force", PROPERTY_HINT_RANGE, "0.00,1024.0,0.01,or_greater"), "set_engine_force", "get_engine_force"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "brake", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_brake", "get_brake"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "steering", PROPERTY_HINT_RANGE, "-180,180.0,0.01"), "set_steering", "get_steering"); - ADD_GROUP("VehicleBody Motion", ""); + ADD_GROUP("VehicleBody3D Motion", ""); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_traction"), "set_use_as_traction", "is_used_as_traction"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_as_steering"), "set_use_as_steering", "is_used_as_steering"); ADD_GROUP("Wheel", "wheel_"); @@ -302,65 +302,65 @@ void VehicleWheel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "damping_relaxation"), "set_damping_relaxation", "get_damping_relaxation"); } -void VehicleWheel::set_engine_force(float p_engine_force) { +void VehicleWheel3D::set_engine_force(float p_engine_force) { m_engineForce = p_engine_force; } -float VehicleWheel::get_engine_force() const { +float VehicleWheel3D::get_engine_force() const { return m_engineForce; } -void VehicleWheel::set_brake(float p_brake) { +void VehicleWheel3D::set_brake(float p_brake) { m_brake = p_brake; } -float VehicleWheel::get_brake() const { +float VehicleWheel3D::get_brake() const { return m_brake; } -void VehicleWheel::set_steering(float p_steering) { +void VehicleWheel3D::set_steering(float p_steering) { m_steering = p_steering; } -float VehicleWheel::get_steering() const { +float VehicleWheel3D::get_steering() const { return m_steering; } -void VehicleWheel::set_use_as_traction(bool p_enable) { +void VehicleWheel3D::set_use_as_traction(bool p_enable) { engine_traction = p_enable; } -bool VehicleWheel::is_used_as_traction() const { +bool VehicleWheel3D::is_used_as_traction() const { return engine_traction; } -void VehicleWheel::set_use_as_steering(bool p_enabled) { +void VehicleWheel3D::set_use_as_steering(bool p_enabled) { steers = p_enabled; } -bool VehicleWheel::is_used_as_steering() const { +bool VehicleWheel3D::is_used_as_steering() const { return steers; } -float VehicleWheel::get_skidinfo() const { +float VehicleWheel3D::get_skidinfo() const { return m_skidInfo; } -float VehicleWheel::get_rpm() const { +float VehicleWheel3D::get_rpm() const { return m_rpm; } -VehicleWheel::VehicleWheel() { +VehicleWheel3D::VehicleWheel3D() { steers = false; engine_traction = false; @@ -385,10 +385,10 @@ VehicleWheel::VehicleWheel() { m_clippedInvContactDotSuspension = 1.0; m_raycastInfo.m_isInContact = false; - body = NULL; + body = nullptr; } -void VehicleBody::_update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_wheel_transform(VehicleWheel3D &wheel, PhysicsDirectBodyState3D *s) { wheel.m_raycastInfo.m_isInContact = false; @@ -405,9 +405,9 @@ void VehicleBody::_update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBody wheel.m_raycastInfo.m_wheelAxleWS = chassisTrans.get_basis().xform(wheel.m_wheelAxleCS).normalized(); } -void VehicleBody::_update_wheel(int p_idx, PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_wheel(int p_idx, PhysicsDirectBodyState3D *s) { - VehicleWheel &wheel = *wheels[p_idx]; + VehicleWheel3D &wheel = *wheels[p_idx]; _update_wheel_transform(wheel, s); Vector3 up = -wheel.m_raycastInfo.m_wheelDirectionWS; @@ -430,9 +430,9 @@ void VehicleBody::_update_wheel(int p_idx, PhysicsDirectBodyState *s) { wheel.m_raycastInfo.m_hardPointWS + wheel.m_raycastInfo.m_wheelDirectionWS * wheel.m_raycastInfo.m_suspensionLength); } -real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { +real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) { - VehicleWheel &wheel = *wheels[p_idx]; + VehicleWheel3D &wheel = *wheels[p_idx]; _update_wheel_transform(wheel, s); @@ -448,13 +448,13 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { real_t param = real_t(0.); - PhysicsDirectSpaceState::RayResult rr; + PhysicsDirectSpaceState3D::RayResult rr; - PhysicsDirectSpaceState *ss = s->get_space_state(); + PhysicsDirectSpaceState3D *ss = s->get_space_state(); bool col = ss->intersect_ray(source, target, rr, exclude); - wheel.m_raycastInfo.m_groundObject = 0; + wheel.m_raycastInfo.m_groundObject = nullptr; if (col) { param = source.distance_to(rr.position) / source.distance_to(target); @@ -463,7 +463,7 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { wheel.m_raycastInfo.m_isInContact = true; if (rr.collider) - wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody>(rr.collider); + wheel.m_raycastInfo.m_groundObject = Object::cast_to<PhysicsBody3D>(rr.collider); real_t hitDistance = param * raylen; wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelRadius; @@ -513,12 +513,12 @@ real_t VehicleBody::_ray_cast(int p_idx, PhysicsDirectBodyState *s) { return depth; } -void VehicleBody::_update_suspension(PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_suspension(PhysicsDirectBodyState3D *s) { real_t chassisMass = mass; for (int w_it = 0; w_it < wheels.size(); w_it++) { - VehicleWheel &wheel_info = *wheels[w_it]; + VehicleWheel3D &wheel_info = *wheels[w_it]; if (wheel_info.m_raycastInfo.m_isInContact) { real_t force; @@ -558,8 +558,8 @@ void VehicleBody::_update_suspension(PhysicsDirectBodyState *s) { } //bilateral constraint between two dynamic objects -void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3 &pos1, - PhysicsBody *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence) { +void VehicleBody3D::_resolve_single_bilateral(PhysicsDirectBodyState3D *s, const Vector3 &pos1, + PhysicsBody3D *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence) { real_t normalLenSqr = normal.length_squared(); //ERR_FAIL_COND( normalLenSqr < real_t(1.1)); @@ -636,7 +636,7 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec #endif } -VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) : +VehicleBody3D::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState3D *s, PhysicsBody3D *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) : m_s(s), m_body1(body1), m_frictionPositionWorld(frictionPosWorld), @@ -667,7 +667,7 @@ VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirec m_jacDiagABInv = relaxation / (denom0 + denom1); } -real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint &contactPoint) { +real_t VehicleBody3D::_calc_rolling_friction(btVehicleWheelContactPoint &contactPoint) { real_t j1 = 0.f; @@ -698,7 +698,7 @@ real_t VehicleBody::_calc_rolling_friction(btVehicleWheelContactPoint &contactPo } static const real_t sideFrictionStiffness2 = real_t(1.0); -void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { +void VehicleBody3D::_update_friction(PhysicsDirectBodyState3D *s) { //calculate the impulse, so that the wheels don't move sidewards int numWheel = wheels.size(); @@ -720,7 +720,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; if (wheelInfo.m_raycastInfo.m_isInContact) { @@ -754,7 +754,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { bool sliding = false; { for (int wheel = 0; wheel < wheels.size(); wheel++) { - VehicleWheel &wheelInfo = *wheels[wheel]; + VehicleWheel3D &wheelInfo = *wheels[wheel]; //class btRigidBody* groundObject = (class btRigidBody*) wheelInfo.m_raycastInfo.m_groundObject; @@ -816,7 +816,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { // apply the impulses { for (int wheel = 0; wheel < wheels.size(); wheel++) { - VehicleWheel &wheelInfo = *wheels[wheel]; + VehicleWheel3D &wheelInfo = *wheels[wheel]; Vector3 rel_pos = wheelInfo.m_raycastInfo.m_contactPointWS - s->get_transform().origin; @@ -825,7 +825,7 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { s->apply_impulse(rel_pos, m_forwardWS[wheel] * (m_forwardImpulse[wheel])); } if (m_sideImpulse[wheel] != real_t(0.)) { - PhysicsBody *groundObject = wheelInfo.m_raycastInfo.m_groundObject; + PhysicsBody3D *groundObject = wheelInfo.m_raycastInfo.m_groundObject; Vector3 rel_pos2; if (groundObject) { @@ -850,11 +850,11 @@ void VehicleBody::_update_friction(PhysicsDirectBodyState *s) { } } -void VehicleBody::_direct_state_changed(Object *p_state) { +void VehicleBody3D::_direct_state_changed(Object *p_state) { - RigidBody::_direct_state_changed(p_state); + RigidBody3D::_direct_state_changed(p_state); - state = Object::cast_to<PhysicsDirectBodyState>(p_state); + state = Object::cast_to<PhysicsDirectBodyState3D>(p_state); float step = state->get_step(); @@ -874,7 +874,7 @@ void VehicleBody::_direct_state_changed(Object *p_state) { for (int i = 0; i < wheels.size(); i++) { //apply suspension force - VehicleWheel &wheel = *wheels[i]; + VehicleWheel3D &wheel = *wheels[i]; real_t suspensionForce = wheel.m_wheelsSuspensionForce; @@ -891,7 +891,7 @@ void VehicleBody::_direct_state_changed(Object *p_state) { _update_friction(state); for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheel = *wheels[i]; + VehicleWheel3D &wheel = *wheels[i]; Vector3 relpos = wheel.m_raycastInfo.m_hardPointWS - state->get_transform().origin; Vector3 vel = state->get_linear_velocity() + (state->get_angular_velocity()).cross(relpos); // * mPos); @@ -917,61 +917,61 @@ void VehicleBody::_direct_state_changed(Object *p_state) { wheel.m_deltaRotation *= real_t(0.99); //damping of rotation when not in contact } - state = NULL; + state = nullptr; } -void VehicleBody::set_engine_force(float p_engine_force) { +void VehicleBody3D::set_engine_force(float p_engine_force) { engine_force = p_engine_force; for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; if (wheelInfo.engine_traction) wheelInfo.m_engineForce = p_engine_force; } } -float VehicleBody::get_engine_force() const { +float VehicleBody3D::get_engine_force() const { return engine_force; } -void VehicleBody::set_brake(float p_brake) { +void VehicleBody3D::set_brake(float p_brake) { brake = p_brake; for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; wheelInfo.m_brake = p_brake; } } -float VehicleBody::get_brake() const { +float VehicleBody3D::get_brake() const { return brake; } -void VehicleBody::set_steering(float p_steering) { +void VehicleBody3D::set_steering(float p_steering) { m_steeringValue = p_steering; for (int i = 0; i < wheels.size(); i++) { - VehicleWheel &wheelInfo = *wheels[i]; + VehicleWheel3D &wheelInfo = *wheels[i]; if (wheelInfo.steers) wheelInfo.m_steering = p_steering; } } -float VehicleBody::get_steering() const { +float VehicleBody3D::get_steering() const { return m_steeringValue; } -void VehicleBody::_bind_methods() { +void VehicleBody3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleBody::set_engine_force); - ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleBody::get_engine_force); + ClassDB::bind_method(D_METHOD("set_engine_force", "engine_force"), &VehicleBody3D::set_engine_force); + ClassDB::bind_method(D_METHOD("get_engine_force"), &VehicleBody3D::get_engine_force); - ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleBody::set_brake); - ClassDB::bind_method(D_METHOD("get_brake"), &VehicleBody::get_brake); + ClassDB::bind_method(D_METHOD("set_brake", "brake"), &VehicleBody3D::set_brake); + ClassDB::bind_method(D_METHOD("get_brake"), &VehicleBody3D::get_brake); - ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleBody::set_steering); - ClassDB::bind_method(D_METHOD("get_steering"), &VehicleBody::get_steering); + ClassDB::bind_method(D_METHOD("set_steering", "steering"), &VehicleBody3D::set_steering); + ClassDB::bind_method(D_METHOD("get_steering"), &VehicleBody3D::get_steering); ADD_GROUP("Motion", ""); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "engine_force", PROPERTY_HINT_RANGE, "0.00,1024.0,0.01,or_greater"), "set_engine_force", "get_engine_force"); @@ -979,7 +979,7 @@ void VehicleBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "steering", PROPERTY_HINT_RANGE, "-180,180.0,0.01"), "set_steering", "get_steering"); } -VehicleBody::VehicleBody() { +VehicleBody3D::VehicleBody3D() { m_pitchControl = 0; m_currentVehicleSpeedKmHour = real_t(0.); @@ -988,11 +988,11 @@ VehicleBody::VehicleBody() { engine_force = 0; brake = 0; - state = NULL; + state = nullptr; ccd = false; exclude.insert(get_rid()); - //PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); + //PhysicsServer3D::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); set_mass(40); } diff --git a/scene/3d/vehicle_body.h b/scene/3d/vehicle_body_3d.h index c05ea30f94..d5e896263d 100644 --- a/scene/3d/vehicle_body.h +++ b/scene/3d/vehicle_body_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* vehicle_body.h */ +/* vehicle_body_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,15 +31,15 @@ #ifndef VEHICLE_BODY_H #define VEHICLE_BODY_H -#include "scene/3d/physics_body.h" +#include "scene/3d/physics_body_3d.h" -class VehicleBody; +class VehicleBody3D; -class VehicleWheel : public Spatial { +class VehicleWheel3D : public Node3D { - GDCLASS(VehicleWheel, Spatial); + GDCLASS(VehicleWheel3D, Node3D); - friend class VehicleBody; + friend class VehicleBody3D; Transform m_worldTransform; Transform local_xform; @@ -61,7 +61,7 @@ class VehicleWheel : public Spatial { real_t m_maxSuspensionForce; bool m_bIsFrontWheel; - VehicleBody *body; + VehicleBody3D *body; //btVector3 m_wheelAxleCS; // const or modified by steering ? @@ -88,10 +88,10 @@ class VehicleWheel : public Spatial { Vector3 m_wheelDirectionWS; //direction in worldspace Vector3 m_wheelAxleWS; // axle in worldspace bool m_isInContact; - PhysicsBody *m_groundObject; //could be general void* ptr + PhysicsBody3D *m_groundObject; //could be general void* ptr } m_raycastInfo; - void _update(PhysicsDirectBodyState *s); + void _update(PhysicsDirectBodyState3D *s); protected: void _notification(int p_what); @@ -148,12 +148,12 @@ public: String get_configuration_warning() const; - VehicleWheel(); + VehicleWheel3D(); }; -class VehicleBody : public RigidBody { +class VehicleBody3D : public RigidBody3D { - GDCLASS(VehicleBody, RigidBody); + GDCLASS(VehicleBody3D, RigidBody3D); float engine_force; float brake; @@ -170,27 +170,27 @@ class VehicleBody : public RigidBody { Vector<real_t> m_sideImpulse; struct btVehicleWheelContactPoint { - PhysicsDirectBodyState *m_s; - PhysicsBody *m_body1; + PhysicsDirectBodyState3D *m_s; + PhysicsBody3D *m_body1; Vector3 m_frictionPositionWorld; Vector3 m_frictionDirectionWorld; real_t m_jacDiagABInv; real_t m_maxImpulse; - btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse); + btVehicleWheelContactPoint(PhysicsDirectBodyState3D *s, PhysicsBody3D *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse); }; - void _resolve_single_bilateral(PhysicsDirectBodyState *s, const Vector3 &pos1, PhysicsBody *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence); + void _resolve_single_bilateral(PhysicsDirectBodyState3D *s, const Vector3 &pos1, PhysicsBody3D *body2, const Vector3 &pos2, const Vector3 &normal, real_t &impulse, const real_t p_rollInfluence); real_t _calc_rolling_friction(btVehicleWheelContactPoint &contactPoint); - void _update_friction(PhysicsDirectBodyState *s); - void _update_suspension(PhysicsDirectBodyState *s); - real_t _ray_cast(int p_idx, PhysicsDirectBodyState *s); - void _update_wheel_transform(VehicleWheel &wheel, PhysicsDirectBodyState *s); - void _update_wheel(int p_idx, PhysicsDirectBodyState *s); + void _update_friction(PhysicsDirectBodyState3D *s); + void _update_suspension(PhysicsDirectBodyState3D *s); + real_t _ray_cast(int p_idx, PhysicsDirectBodyState3D *s); + void _update_wheel_transform(VehicleWheel3D &wheel, PhysicsDirectBodyState3D *s); + void _update_wheel(int p_idx, PhysicsDirectBodyState3D *s); - friend class VehicleWheel; - Vector<VehicleWheel *> wheels; + friend class VehicleWheel3D; + Vector<VehicleWheel3D *> wheels; static void _bind_methods(); @@ -206,7 +206,7 @@ public: void set_steering(float p_steering); float get_steering() const; - VehicleBody(); + VehicleBody3D(); }; #endif // VEHICLE_BODY_H diff --git a/scene/3d/spatial_velocity_tracker.cpp b/scene/3d/velocity_tracker_3d.cpp index ec1bb1f991..c9b95e6397 100644 --- a/scene/3d/spatial_velocity_tracker.cpp +++ b/scene/3d/velocity_tracker_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial_velocity_tracker.cpp */ +/* velocity_tracker_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,19 +28,19 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "spatial_velocity_tracker.h" +#include "velocity_tracker_3d.h" #include "core/engine.h" -void SpatialVelocityTracker::set_track_physics_step(bool p_track_physics_step) { +void VelocityTracker3D::set_track_physics_step(bool p_track_physics_step) { physics_step = p_track_physics_step; } -bool SpatialVelocityTracker::is_tracking_physics_step() const { +bool VelocityTracker3D::is_tracking_physics_step() const { return physics_step; } -void SpatialVelocityTracker::update_position(const Vector3 &p_position) { +void VelocityTracker3D::update_position(const Vector3 &p_position) { PositionHistory ph; ph.position = p_position; @@ -59,7 +59,7 @@ void SpatialVelocityTracker::update_position(const Vector3 &p_position) { position_history.write[0] = ph; } -Vector3 SpatialVelocityTracker::get_tracked_linear_velocity() const { +Vector3 VelocityTracker3D::get_tracked_linear_velocity() const { Vector3 linear_velocity; @@ -104,7 +104,7 @@ Vector3 SpatialVelocityTracker::get_tracked_linear_velocity() const { return linear_velocity; } -void SpatialVelocityTracker::reset(const Vector3 &p_new_pos) { +void VelocityTracker3D::reset(const Vector3 &p_new_pos) { PositionHistory ph; ph.position = p_new_pos; @@ -118,18 +118,18 @@ void SpatialVelocityTracker::reset(const Vector3 &p_new_pos) { position_history_len = 1; } -void SpatialVelocityTracker::_bind_methods() { +void VelocityTracker3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_track_physics_step", "enable"), &SpatialVelocityTracker::set_track_physics_step); - ClassDB::bind_method(D_METHOD("is_tracking_physics_step"), &SpatialVelocityTracker::is_tracking_physics_step); - ClassDB::bind_method(D_METHOD("update_position", "position"), &SpatialVelocityTracker::update_position); - ClassDB::bind_method(D_METHOD("get_tracked_linear_velocity"), &SpatialVelocityTracker::get_tracked_linear_velocity); - ClassDB::bind_method(D_METHOD("reset", "position"), &SpatialVelocityTracker::reset); + ClassDB::bind_method(D_METHOD("set_track_physics_step", "enable"), &VelocityTracker3D::set_track_physics_step); + ClassDB::bind_method(D_METHOD("is_tracking_physics_step"), &VelocityTracker3D::is_tracking_physics_step); + ClassDB::bind_method(D_METHOD("update_position", "position"), &VelocityTracker3D::update_position); + ClassDB::bind_method(D_METHOD("get_tracked_linear_velocity"), &VelocityTracker3D::get_tracked_linear_velocity); + ClassDB::bind_method(D_METHOD("reset", "position"), &VelocityTracker3D::reset); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "track_physics_step"), "set_track_physics_step", "is_tracking_physics_step"); } -SpatialVelocityTracker::SpatialVelocityTracker() { +VelocityTracker3D::VelocityTracker3D() { position_history.resize(4); // should be configurable position_history_len = 0; physics_step = false; diff --git a/scene/3d/spatial_velocity_tracker.h b/scene/3d/velocity_tracker_3d.h index 92b527b93c..a7ab3dce4d 100644 --- a/scene/3d/spatial_velocity_tracker.h +++ b/scene/3d/velocity_tracker_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* spatial_velocity_tracker.h */ +/* velocity_tracker_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,10 +31,10 @@ #ifndef SPATIAL_VELOCITY_TRACKER_H #define SPATIAL_VELOCITY_TRACKER_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class SpatialVelocityTracker : public Reference { - GDCLASS(SpatialVelocityTracker, Reference); +class VelocityTracker3D : public Reference { + GDCLASS(VelocityTracker3D, Reference); struct PositionHistory { uint64_t frame; @@ -55,7 +55,7 @@ public: void update_position(const Vector3 &p_position); Vector3 get_tracked_linear_velocity() const; - SpatialVelocityTracker(); + VelocityTracker3D(); }; #endif // SPATIAL_VELOCITY_TRACKER_H diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier_3d.cpp index 5bc568bd5d..2f657fe7b1 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier.cpp */ +/* visibility_notifier_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,15 +28,15 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "visibility_notifier.h" +#include "visibility_notifier_3d.h" #include "core/engine.h" -#include "scene/3d/camera.h" -#include "scene/3d/physics_body.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/physics_body_3d.h" #include "scene/animation/animation_player.h" #include "scene/scene_string_names.h" -void VisibilityNotifier::_enter_camera(Camera *p_camera) { +void VisibilityNotifier3D::_enter_camera(Camera3D *p_camera) { ERR_FAIL_COND(cameras.has(p_camera)); cameras.insert(p_camera); @@ -48,7 +48,7 @@ void VisibilityNotifier::_enter_camera(Camera *p_camera) { emit_signal(SceneStringNames::get_singleton()->camera_entered, p_camera); } -void VisibilityNotifier::_exit_camera(Camera *p_camera) { +void VisibilityNotifier3D::_exit_camera(Camera3D *p_camera) { ERR_FAIL_COND(!cameras.has(p_camera)); cameras.erase(p_camera); @@ -61,7 +61,7 @@ void VisibilityNotifier::_exit_camera(Camera *p_camera) { } } -void VisibilityNotifier::set_aabb(const AABB &p_aabb) { +void VisibilityNotifier3D::set_aabb(const AABB &p_aabb) { if (aabb == p_aabb) return; @@ -75,12 +75,12 @@ void VisibilityNotifier::set_aabb(const AABB &p_aabb) { update_gizmo(); } -AABB VisibilityNotifier::get_aabb() const { +AABB VisibilityNotifier3D::get_aabb() const { return aabb; } -void VisibilityNotifier::_notification(int p_what) { +void VisibilityNotifier3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_WORLD: { @@ -98,26 +98,26 @@ void VisibilityNotifier::_notification(int p_what) { } } -bool VisibilityNotifier::is_on_screen() const { +bool VisibilityNotifier3D::is_on_screen() const { return cameras.size() != 0; } -void VisibilityNotifier::_bind_methods() { +void VisibilityNotifier3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier::set_aabb); - ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier::get_aabb); - ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier::is_on_screen); + ClassDB::bind_method(D_METHOD("set_aabb", "rect"), &VisibilityNotifier3D::set_aabb); + ClassDB::bind_method(D_METHOD("get_aabb"), &VisibilityNotifier3D::get_aabb); + ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier3D::is_on_screen); ADD_PROPERTY(PropertyInfo(Variant::AABB, "aabb"), "set_aabb", "get_aabb"); - ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"))); - ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"))); + ADD_SIGNAL(MethodInfo("camera_entered", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"))); + ADD_SIGNAL(MethodInfo("camera_exited", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"))); ADD_SIGNAL(MethodInfo("screen_entered")); ADD_SIGNAL(MethodInfo("screen_exited")); } -VisibilityNotifier::VisibilityNotifier() { +VisibilityNotifier3D::VisibilityNotifier3D() { aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2)); set_notify_transform(true); @@ -125,7 +125,7 @@ VisibilityNotifier::VisibilityNotifier() { ////////////////////////////////////// -void VisibilityEnabler::_screen_enter() { +void VisibilityEnabler3D::_screen_enter() { for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { @@ -135,7 +135,7 @@ void VisibilityEnabler::_screen_enter() { visible = true; } -void VisibilityEnabler::_screen_exit() { +void VisibilityEnabler3D::_screen_exit() { for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) { @@ -145,14 +145,14 @@ void VisibilityEnabler::_screen_exit() { visible = false; } -void VisibilityEnabler::_find_nodes(Node *p_node) { +void VisibilityEnabler3D::_find_nodes(Node *p_node) { bool add = false; Variant meta; { - RigidBody *rb = Object::cast_to<RigidBody>(p_node); - if (rb && ((rb->get_mode() == RigidBody::MODE_CHARACTER || rb->get_mode() == RigidBody::MODE_RIGID))) { + RigidBody3D *rb = Object::cast_to<RigidBody3D>(p_node); + if (rb && ((rb->get_mode() == RigidBody3D::MODE_CHARACTER || rb->get_mode() == RigidBody3D::MODE_RIGID))) { add = true; meta = rb->get_mode(); @@ -168,7 +168,7 @@ void VisibilityEnabler::_find_nodes(Node *p_node) { if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler::_node_removed), varray(p_node), CONNECT_ONESHOT); + p_node->connect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler3D::_node_removed), varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); } @@ -182,7 +182,7 @@ void VisibilityEnabler::_find_nodes(Node *p_node) { } } -void VisibilityEnabler::_notification(int p_what) { +void VisibilityEnabler3D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { @@ -206,19 +206,19 @@ void VisibilityEnabler::_notification(int p_what) { if (!visible) _change_node_state(E->key(), true); - E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler::_node_removed)); + E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &VisibilityEnabler3D::_node_removed)); } nodes.clear(); } } -void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) { +void VisibilityEnabler3D::_change_node_state(Node *p_node, bool p_enabled) { ERR_FAIL_COND(!nodes.has(p_node)); if (enabler[ENABLER_FREEZE_BODIES]) { - RigidBody *rb = Object::cast_to<RigidBody>(p_node); + RigidBody3D *rb = Object::cast_to<RigidBody3D>(p_node); if (rb) rb->set_sleeping(!p_enabled); @@ -234,17 +234,17 @@ void VisibilityEnabler::_change_node_state(Node *p_node, bool p_enabled) { } } -void VisibilityEnabler::_node_removed(Node *p_node) { +void VisibilityEnabler3D::_node_removed(Node *p_node) { if (!visible) _change_node_state(p_node, true); nodes.erase(p_node); } -void VisibilityEnabler::_bind_methods() { +void VisibilityEnabler3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler::set_enabler); - ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler::is_enabler_enabled); + ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler3D::set_enabler); + ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler3D::is_enabler_enabled); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS); ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES); @@ -254,18 +254,18 @@ void VisibilityEnabler::_bind_methods() { BIND_ENUM_CONSTANT(ENABLER_MAX); } -void VisibilityEnabler::set_enabler(Enabler p_enabler, bool p_enable) { +void VisibilityEnabler3D::set_enabler(Enabler p_enabler, bool p_enable) { ERR_FAIL_INDEX(p_enabler, ENABLER_MAX); enabler[p_enabler] = p_enable; } -bool VisibilityEnabler::is_enabler_enabled(Enabler p_enabler) const { +bool VisibilityEnabler3D::is_enabler_enabled(Enabler p_enabler) const { ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false); return enabler[p_enabler]; } -VisibilityEnabler::VisibilityEnabler() { +VisibilityEnabler3D::VisibilityEnabler3D() { for (int i = 0; i < ENABLER_MAX; i++) enabler[i] = true; diff --git a/scene/3d/visibility_notifier.h b/scene/3d/visibility_notifier_3d.h index 71fdfdb78c..19204a6a4e 100644 --- a/scene/3d/visibility_notifier.h +++ b/scene/3d/visibility_notifier_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visibility_notifier.h */ +/* visibility_notifier_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -31,14 +31,14 @@ #ifndef VISIBILITY_NOTIFIER_H #define VISIBILITY_NOTIFIER_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" -class Camera; -class VisibilityNotifier : public Spatial { +class Camera3D; +class VisibilityNotifier3D : public Node3D { - GDCLASS(VisibilityNotifier, Spatial); + GDCLASS(VisibilityNotifier3D, Node3D); - Set<Camera *> cameras; + Set<Camera3D *> cameras; AABB aabb; @@ -50,20 +50,20 @@ protected: static void _bind_methods(); friend struct SpatialIndexer; - void _enter_camera(Camera *p_camera); - void _exit_camera(Camera *p_camera); + void _enter_camera(Camera3D *p_camera); + void _exit_camera(Camera3D *p_camera); public: void set_aabb(const AABB &p_aabb); AABB get_aabb() const; bool is_on_screen() const; - VisibilityNotifier(); + VisibilityNotifier3D(); }; -class VisibilityEnabler : public VisibilityNotifier { +class VisibilityEnabler3D : public VisibilityNotifier3D { - GDCLASS(VisibilityEnabler, VisibilityNotifier); + GDCLASS(VisibilityEnabler3D, VisibilityNotifier3D); public: enum Enabler { @@ -93,9 +93,9 @@ public: void set_enabler(Enabler p_enabler, bool p_enable); bool is_enabler_enabled(Enabler p_enabler) const; - VisibilityEnabler(); + VisibilityEnabler3D(); }; -VARIANT_ENUM_CAST(VisibilityEnabler::Enabler); +VARIANT_ENUM_CAST(VisibilityEnabler3D::Enabler); #endif // VISIBILITY_NOTIFIER_H diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance_3d.cpp index 105ce9ca74..604bc53422 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance_3d.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visual_instance.cpp */ +/* visual_instance_3d.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,27 +28,27 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "visual_instance.h" +#include "visual_instance_3d.h" #include "scene/scene_string_names.h" -#include "servers/visual_server.h" -#include "skeleton.h" +#include "servers/rendering_server.h" +#include "skeleton_3d.h" -AABB VisualInstance::get_transformed_aabb() const { +AABB VisualInstance3D::get_transformed_aabb() const { return get_global_transform().xform(get_aabb()); } -void VisualInstance::_update_visibility() { +void VisualInstance3D::_update_visibility() { if (!is_inside_tree()) return; _change_notify("visible"); - VS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree()); + RS::get_singleton()->instance_set_visible(get_instance(), is_visible_in_tree()); } -void VisualInstance::_notification(int p_what) { +void VisualInstance3D::_notification(int p_what) { switch (p_what) { @@ -58,23 +58,23 @@ void VisualInstance::_notification(int p_what) { /* Skeleton *skeleton=Object::cast_to<Skeleton>(get_parent()); if (skeleton) - VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() ); + RenderingServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() ); */ ERR_FAIL_COND(get_world().is_null()); - VisualServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); + RenderingServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); _update_visibility(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { Transform gt = get_global_transform(); - VisualServer::get_singleton()->instance_set_transform(instance, gt); + RenderingServer::get_singleton()->instance_set_transform(instance, gt); } break; case NOTIFICATION_EXIT_WORLD: { - VisualServer::get_singleton()->instance_set_scenario(instance, RID()); - VisualServer::get_singleton()->instance_attach_skeleton(instance, RID()); - //VS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() ); + RenderingServer::get_singleton()->instance_set_scenario(instance, RID()); + RenderingServer::get_singleton()->instance_attach_skeleton(instance, RID()); + //RS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() ); } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -84,28 +84,28 @@ void VisualInstance::_notification(int p_what) { } } -RID VisualInstance::get_instance() const { +RID VisualInstance3D::get_instance() const { return instance; } -RID VisualInstance::_get_visual_instance_rid() const { +RID VisualInstance3D::_get_visual_instance_rid() const { return instance; } -void VisualInstance::set_layer_mask(uint32_t p_mask) { +void VisualInstance3D::set_layer_mask(uint32_t p_mask) { layers = p_mask; - VisualServer::get_singleton()->instance_set_layer_mask(instance, p_mask); + RenderingServer::get_singleton()->instance_set_layer_mask(instance, p_mask); } -uint32_t VisualInstance::get_layer_mask() const { +uint32_t VisualInstance3D::get_layer_mask() const { return layers; } -void VisualInstance::set_layer_mask_bit(int p_layer, bool p_enable) { +void VisualInstance3D::set_layer_mask_bit(int p_layer, bool p_enable) { ERR_FAIL_INDEX(p_layer, 32); if (p_enable) { set_layer_mask(layers | (1 << p_layer)); @@ -114,184 +114,259 @@ void VisualInstance::set_layer_mask_bit(int p_layer, bool p_enable) { } } -bool VisualInstance::get_layer_mask_bit(int p_layer) const { +bool VisualInstance3D::get_layer_mask_bit(int p_layer) const { ERR_FAIL_INDEX_V(p_layer, 32, false); return (layers & (1 << p_layer)); } -void VisualInstance::_bind_methods() { +void VisualInstance3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance::_get_visual_instance_rid); - ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance::set_base); - ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance::get_base); - ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance::get_instance); - ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &VisualInstance::set_layer_mask); - ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance::get_layer_mask); - ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "layer", "enabled"), &VisualInstance::set_layer_mask_bit); - ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "layer"), &VisualInstance::get_layer_mask_bit); + ClassDB::bind_method(D_METHOD("_get_visual_instance_rid"), &VisualInstance3D::_get_visual_instance_rid); + ClassDB::bind_method(D_METHOD("set_base", "base"), &VisualInstance3D::set_base); + ClassDB::bind_method(D_METHOD("get_base"), &VisualInstance3D::get_base); + ClassDB::bind_method(D_METHOD("get_instance"), &VisualInstance3D::get_instance); + ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &VisualInstance3D::set_layer_mask); + ClassDB::bind_method(D_METHOD("get_layer_mask"), &VisualInstance3D::get_layer_mask); + ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "layer", "enabled"), &VisualInstance3D::set_layer_mask_bit); + ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "layer"), &VisualInstance3D::get_layer_mask_bit); - ClassDB::bind_method(D_METHOD("get_transformed_aabb"), &VisualInstance::get_transformed_aabb); + ClassDB::bind_method(D_METHOD("get_transformed_aabb"), &VisualInstance3D::get_transformed_aabb); ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_3D_RENDER), "set_layer_mask", "get_layer_mask"); } -void VisualInstance::set_base(const RID &p_base) { +void VisualInstance3D::set_base(const RID &p_base) { - VisualServer::get_singleton()->instance_set_base(instance, p_base); + RenderingServer::get_singleton()->instance_set_base(instance, p_base); base = p_base; } -RID VisualInstance::get_base() const { +RID VisualInstance3D::get_base() const { return base; } -VisualInstance::VisualInstance() { +VisualInstance3D::VisualInstance3D() { - instance = VisualServer::get_singleton()->instance_create(); - VisualServer::get_singleton()->instance_attach_object_instance_id(instance, get_instance_id()); + instance = RenderingServer::get_singleton()->instance_create(); + RenderingServer::get_singleton()->instance_attach_object_instance_id(instance, get_instance_id()); layers = 1; set_notify_transform(true); } -VisualInstance::~VisualInstance() { +VisualInstance3D::~VisualInstance3D() { - VisualServer::get_singleton()->free(instance); + RenderingServer::get_singleton()->free(instance); } -void GeometryInstance::set_material_override(const Ref<Material> &p_material) { +void GeometryInstance3D::set_material_override(const Ref<Material> &p_material) { material_override = p_material; - VS::get_singleton()->instance_geometry_set_material_override(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID()); + RS::get_singleton()->instance_geometry_set_material_override(get_instance(), p_material.is_valid() ? p_material->get_rid() : RID()); } -Ref<Material> GeometryInstance::get_material_override() const { +Ref<Material> GeometryInstance3D::get_material_override() const { return material_override; } -void GeometryInstance::set_lod_min_distance(float p_dist) { +void GeometryInstance3D::set_lod_min_distance(float p_dist) { lod_min_distance = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_min_distance() const { +float GeometryInstance3D::get_lod_min_distance() const { return lod_min_distance; } -void GeometryInstance::set_lod_max_distance(float p_dist) { +void GeometryInstance3D::set_lod_max_distance(float p_dist) { lod_max_distance = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_max_distance() const { +float GeometryInstance3D::get_lod_max_distance() const { return lod_max_distance; } -void GeometryInstance::set_lod_min_hysteresis(float p_dist) { +void GeometryInstance3D::set_lod_min_hysteresis(float p_dist) { lod_min_hysteresis = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_min_hysteresis() const { +float GeometryInstance3D::get_lod_min_hysteresis() const { return lod_min_hysteresis; } -void GeometryInstance::set_lod_max_hysteresis(float p_dist) { +void GeometryInstance3D::set_lod_max_hysteresis(float p_dist) { lod_max_hysteresis = p_dist; - VS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); + RS::get_singleton()->instance_geometry_set_draw_range(get_instance(), lod_min_distance, lod_max_distance, lod_min_hysteresis, lod_max_hysteresis); } -float GeometryInstance::get_lod_max_hysteresis() const { +float GeometryInstance3D::get_lod_max_hysteresis() const { return lod_max_hysteresis; } -void GeometryInstance::_notification(int p_what) { +void GeometryInstance3D::_notification(int p_what) { } -void GeometryInstance::set_flag(Flags p_flag, bool p_value) { +const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const { + StringName *r = instance_uniform_property_remap.getptr(p_name); + if (!r) { + String s = p_name; + if (s.begins_with("shader_params/")) { + StringName name = s.replace("shader_params/", ""); + instance_uniform_property_remap[p_name] = name; + return instance_uniform_property_remap.getptr(p_name); + } + + return nullptr; + } + + return r; +} + +bool GeometryInstance3D::_set(const StringName &p_name, const Variant &p_value) { + const StringName *r = _instance_uniform_get_remap(p_name); + if (r) { + set_shader_instance_uniform(*r, p_value); + return true; + } + + return false; +} + +bool GeometryInstance3D::_get(const StringName &p_name, Variant &r_ret) const { + const StringName *r = _instance_uniform_get_remap(p_name); + if (r) { + r_ret = get_shader_instance_uniform(*r); + return true; + } + + return false; +} +void GeometryInstance3D::_get_property_list(List<PropertyInfo> *p_list) const { + List<PropertyInfo> pinfo; + RS::get_singleton()->instance_geometry_get_shader_parameter_list(get_instance(), &pinfo); + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + PropertyInfo pi = E->get(); + bool has_def_value = false; + Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), pi.name); + if (def_value.get_type() != Variant::NIL) { + has_def_value = true; + } + if (instance_uniforms.has(pi.name)) { + pi.usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE | (has_def_value ? (PROPERTY_USAGE_CHECKABLE | PROPERTY_USAGE_CHECKED) : 0); + } else { + pi.usage = PROPERTY_USAGE_EDITOR | (has_def_value ? PROPERTY_USAGE_CHECKABLE : 0); //do not save if not changed + } + + pi.name = "shader_params/" + pi.name; + p_list->push_back(pi); + } +} + +void GeometryInstance3D::set_flag(Flags p_flag, bool p_value) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); if (flags[p_flag] == p_value) return; flags[p_flag] = p_value; - VS::get_singleton()->instance_geometry_set_flag(get_instance(), (VS::InstanceFlags)p_flag, p_value); + RS::get_singleton()->instance_geometry_set_flag(get_instance(), (RS::InstanceFlags)p_flag, p_value); } -bool GeometryInstance::get_flag(Flags p_flag) const { +bool GeometryInstance3D::get_flag(Flags p_flag) const { ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false); return flags[p_flag]; } -void GeometryInstance::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) { +void GeometryInstance3D::set_cast_shadows_setting(ShadowCastingSetting p_shadow_casting_setting) { shadow_casting_setting = p_shadow_casting_setting; - VS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), (VS::ShadowCastingSetting)p_shadow_casting_setting); + RS::get_singleton()->instance_geometry_set_cast_shadows_setting(get_instance(), (RS::ShadowCastingSetting)p_shadow_casting_setting); } -GeometryInstance::ShadowCastingSetting GeometryInstance::get_cast_shadows_setting() const { +GeometryInstance3D::ShadowCastingSetting GeometryInstance3D::get_cast_shadows_setting() const { return shadow_casting_setting; } -void GeometryInstance::set_extra_cull_margin(float p_margin) { +void GeometryInstance3D::set_extra_cull_margin(float p_margin) { ERR_FAIL_COND(p_margin < 0); extra_cull_margin = p_margin; - VS::get_singleton()->instance_set_extra_visibility_margin(get_instance(), extra_cull_margin); + RS::get_singleton()->instance_set_extra_visibility_margin(get_instance(), extra_cull_margin); } -float GeometryInstance::get_extra_cull_margin() const { +float GeometryInstance3D::get_extra_cull_margin() const { return extra_cull_margin; } -void GeometryInstance::set_custom_aabb(AABB aabb) { +void GeometryInstance3D::set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value) { - VS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb); + if (p_value.get_type() == Variant::NIL) { + Variant def_value = RS::get_singleton()->instance_geometry_get_shader_parameter_default_value(get_instance(), p_uniform); + RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, def_value); + instance_uniforms.erase(p_value); + } else { + instance_uniforms[p_uniform] = p_value; + RS::get_singleton()->instance_geometry_set_shader_parameter(get_instance(), p_uniform, p_value); + } } -void GeometryInstance::_bind_methods() { +Variant GeometryInstance3D::get_shader_instance_uniform(const StringName &p_uniform) const { + + return RS::get_singleton()->instance_geometry_get_shader_parameter(get_instance(), p_uniform); +} +void GeometryInstance3D::set_custom_aabb(AABB aabb) { + + RS::get_singleton()->instance_set_custom_aabb(get_instance(), aabb); +} + +void GeometryInstance3D::_bind_methods() { + + ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance3D::set_material_override); + ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance3D::get_material_override); - ClassDB::bind_method(D_METHOD("set_material_override", "material"), &GeometryInstance::set_material_override); - ClassDB::bind_method(D_METHOD("get_material_override"), &GeometryInstance::get_material_override); + ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance3D::set_flag); + ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance3D::get_flag); - ClassDB::bind_method(D_METHOD("set_flag", "flag", "value"), &GeometryInstance::set_flag); - ClassDB::bind_method(D_METHOD("get_flag", "flag"), &GeometryInstance::get_flag); + ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance3D::set_cast_shadows_setting); + ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance3D::get_cast_shadows_setting); - ClassDB::bind_method(D_METHOD("set_cast_shadows_setting", "shadow_casting_setting"), &GeometryInstance::set_cast_shadows_setting); - ClassDB::bind_method(D_METHOD("get_cast_shadows_setting"), &GeometryInstance::get_cast_shadows_setting); + ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance3D::set_lod_max_hysteresis); + ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance3D::get_lod_max_hysteresis); - ClassDB::bind_method(D_METHOD("set_lod_max_hysteresis", "mode"), &GeometryInstance::set_lod_max_hysteresis); - ClassDB::bind_method(D_METHOD("get_lod_max_hysteresis"), &GeometryInstance::get_lod_max_hysteresis); + ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance3D::set_lod_max_distance); + ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance3D::get_lod_max_distance); - ClassDB::bind_method(D_METHOD("set_lod_max_distance", "mode"), &GeometryInstance::set_lod_max_distance); - ClassDB::bind_method(D_METHOD("get_lod_max_distance"), &GeometryInstance::get_lod_max_distance); + ClassDB::bind_method(D_METHOD("set_shader_instance_uniform", "uniform", "value"), &GeometryInstance3D::set_shader_instance_uniform); + ClassDB::bind_method(D_METHOD("get_shader_instance_uniform", "uniform"), &GeometryInstance3D::get_shader_instance_uniform); - ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance::set_lod_min_hysteresis); - ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance::get_lod_min_hysteresis); + ClassDB::bind_method(D_METHOD("set_lod_min_hysteresis", "mode"), &GeometryInstance3D::set_lod_min_hysteresis); + ClassDB::bind_method(D_METHOD("get_lod_min_hysteresis"), &GeometryInstance3D::get_lod_min_hysteresis); - ClassDB::bind_method(D_METHOD("set_lod_min_distance", "mode"), &GeometryInstance::set_lod_min_distance); - ClassDB::bind_method(D_METHOD("get_lod_min_distance"), &GeometryInstance::get_lod_min_distance); + ClassDB::bind_method(D_METHOD("set_lod_min_distance", "mode"), &GeometryInstance3D::set_lod_min_distance); + ClassDB::bind_method(D_METHOD("get_lod_min_distance"), &GeometryInstance3D::get_lod_min_distance); - ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance::set_extra_cull_margin); - ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance::get_extra_cull_margin); + ClassDB::bind_method(D_METHOD("set_extra_cull_margin", "margin"), &GeometryInstance3D::set_extra_cull_margin); + ClassDB::bind_method(D_METHOD("get_extra_cull_margin"), &GeometryInstance3D::get_extra_cull_margin); - ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance::set_custom_aabb); + ClassDB::bind_method(D_METHOD("set_custom_aabb", "aabb"), &GeometryInstance3D::set_custom_aabb); - ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance::get_aabb); + ClassDB::bind_method(D_METHOD("get_aabb"), &GeometryInstance3D::get_aabb); ADD_GROUP("Geometry", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material_override", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,StandardMaterial3D", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_DEFERRED_SET_RESOURCE), "set_material_override", "get_material_override"); @@ -319,7 +394,7 @@ void GeometryInstance::_bind_methods() { BIND_ENUM_CONSTANT(FLAG_MAX); } -GeometryInstance::GeometryInstance() { +GeometryInstance3D::GeometryInstance3D() { lod_min_distance = 0; lod_max_distance = 0; lod_min_hysteresis = 0; @@ -331,5 +406,5 @@ GeometryInstance::GeometryInstance() { shadow_casting_setting = SHADOW_CASTING_SETTING_ON; extra_cull_margin = 0; - //VS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0); + //RS::get_singleton()->instance_geometry_set_baked_light_texture_index(get_instance(),0); } diff --git a/scene/3d/visual_instance.h b/scene/3d/visual_instance_3d.h index fee6787c87..cc5f92066f 100644 --- a/scene/3d/visual_instance.h +++ b/scene/3d/visual_instance_3d.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* visual_instance.h */ +/* visual_instance_3d.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,12 +33,12 @@ #include "core/math/face3.h" #include "core/rid.h" -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" #include "scene/resources/material.h" -class VisualInstance : public Spatial { +class VisualInstance3D : public Node3D { - GDCLASS(VisualInstance, Spatial); + GDCLASS(VisualInstance3D, Node3D); OBJ_CATEGORY("3D Visual Nodes"); RID base; @@ -76,27 +76,27 @@ public: void set_layer_mask_bit(int p_layer, bool p_enable); bool get_layer_mask_bit(int p_layer) const; - VisualInstance(); - ~VisualInstance(); + VisualInstance3D(); + ~VisualInstance3D(); }; -class GeometryInstance : public VisualInstance { +class GeometryInstance3D : public VisualInstance3D { - GDCLASS(GeometryInstance, VisualInstance); + GDCLASS(GeometryInstance3D, VisualInstance3D); public: enum Flags { - FLAG_USE_BAKED_LIGHT = VS::INSTANCE_FLAG_USE_BAKED_LIGHT, - FLAG_USE_DYNAMIC_GI = VS::INSTANCE_FLAG_USE_DYNAMIC_GI, - FLAG_DRAW_NEXT_FRAME_IF_VISIBLE = VS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, - FLAG_MAX = VS::INSTANCE_FLAG_MAX, + FLAG_USE_BAKED_LIGHT = RS::INSTANCE_FLAG_USE_BAKED_LIGHT, + FLAG_USE_DYNAMIC_GI = RS::INSTANCE_FLAG_USE_DYNAMIC_GI, + FLAG_DRAW_NEXT_FRAME_IF_VISIBLE = RS::INSTANCE_FLAG_DRAW_NEXT_FRAME_IF_VISIBLE, + FLAG_MAX = RS::INSTANCE_FLAG_MAX, }; enum ShadowCastingSetting { - SHADOW_CASTING_SETTING_OFF = VS::SHADOW_CASTING_SETTING_OFF, - SHADOW_CASTING_SETTING_ON = VS::SHADOW_CASTING_SETTING_ON, - SHADOW_CASTING_SETTING_DOUBLE_SIDED = VS::SHADOW_CASTING_SETTING_DOUBLE_SIDED, - SHADOW_CASTING_SETTING_SHADOWS_ONLY = VS::SHADOW_CASTING_SETTING_SHADOWS_ONLY + SHADOW_CASTING_SETTING_OFF = RS::SHADOW_CASTING_SETTING_OFF, + SHADOW_CASTING_SETTING_ON = RS::SHADOW_CASTING_SETTING_ON, + SHADOW_CASTING_SETTING_DOUBLE_SIDED = RS::SHADOW_CASTING_SETTING_DOUBLE_SIDED, + SHADOW_CASTING_SETTING_SHADOWS_ONLY = RS::SHADOW_CASTING_SETTING_SHADOWS_ONLY }; private: @@ -108,9 +108,18 @@ private: float lod_min_hysteresis; float lod_max_hysteresis; + mutable HashMap<StringName, Variant> instance_uniforms; + mutable HashMap<StringName, StringName> instance_uniform_property_remap; + float extra_cull_margin; + const StringName *_instance_uniform_get_remap(const StringName p_name) const; + 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<PropertyInfo> *p_list) const; + void _notification(int p_what); static void _bind_methods(); @@ -139,12 +148,15 @@ public: void set_extra_cull_margin(float p_margin); float get_extra_cull_margin() const; + void set_shader_instance_uniform(const StringName &p_uniform, const Variant &p_value); + Variant get_shader_instance_uniform(const StringName &p_uniform) const; + void set_custom_aabb(AABB aabb); - GeometryInstance(); + GeometryInstance3D(); }; -VARIANT_ENUM_CAST(GeometryInstance::Flags); -VARIANT_ENUM_CAST(GeometryInstance::ShadowCastingSetting); +VARIANT_ENUM_CAST(GeometryInstance3D::Flags); +VARIANT_ENUM_CAST(GeometryInstance3D::ShadowCastingSetting); #endif diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp index 203c3cd812..f30c58be55 100644 --- a/scene/3d/voxelizer.cpp +++ b/scene/3d/voxelizer.cpp @@ -592,22 +592,16 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec Vector<Vector3> vertices = a[Mesh::ARRAY_VERTEX]; const Vector3 *vr = vertices.ptr(); Vector<Vector2> uv = a[Mesh::ARRAY_TEX_UV]; - const Vector2 *uvr; + const Vector2 *uvr = nullptr; Vector<Vector3> normals = a[Mesh::ARRAY_NORMAL]; - const Vector3 *nr; + const Vector3 *nr = nullptr; Vector<int> index = a[Mesh::ARRAY_INDEX]; - bool read_uv = false; - bool read_normals = false; - if (uv.size()) { - uvr = uv.ptr(); - read_uv = true; } if (normals.size()) { - read_normals = true; nr = normals.ptr(); } @@ -626,13 +620,13 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec vtxs[k] = p_xform.xform(vr[ir[j * 3 + k]]); } - if (read_uv) { + if (uvr) { for (int k = 0; k < 3; k++) { uvs[k] = uvr[ir[j * 3 + k]]; } } - if (read_normals) { + if (nr) { for (int k = 0; k < 3; k++) { normal[k] = nr[ir[j * 3 + k]]; } @@ -659,13 +653,13 @@ void Voxelizer::plot_mesh(const Transform &p_xform, Ref<Mesh> &p_mesh, const Vec vtxs[k] = p_xform.xform(vr[j * 3 + k]); } - if (read_uv) { + if (uvr) { for (int k = 0; k < 3; k++) { uvs[k] = uvr[j * 3 + k]; } } - if (read_normals) { + if (nr) { for (int k = 0; k < 3; k++) { normal[k] = nr[j * 3 + k]; } diff --git a/scene/3d/voxelizer.h b/scene/3d/voxelizer.h index af9237ae7b..1fde6237a2 100644 --- a/scene/3d/voxelizer.h +++ b/scene/3d/voxelizer.h @@ -32,7 +32,7 @@ #define VOXEL_LIGHT_BAKER_H #include "core/math/vector3i.h" -#include "scene/3d/mesh_instance.h" +#include "scene/3d/mesh_instance_3d.h" #include "scene/resources/multimesh.h" class Voxelizer { diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index 83a7243906..8cf4554653 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -29,11 +29,11 @@ /*************************************************************************/ #include "world_environment.h" -#include "scene/main/viewport.h" +#include "scene/main/window.h" void WorldEnvironment::_notification(int p_what) { - if (p_what == Spatial::NOTIFICATION_ENTER_WORLD || p_what == Spatial::NOTIFICATION_ENTER_TREE) { + if (p_what == Node3D::NOTIFICATION_ENTER_WORLD || p_what == Node3D::NOTIFICATION_ENTER_TREE) { if (environment.is_valid()) { if (get_viewport()->find_world()->get_environment().is_valid()) { @@ -51,7 +51,7 @@ void WorldEnvironment::_notification(int p_what) { add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world()->get_scenario().get_id())); } - } else if (p_what == Spatial::NOTIFICATION_EXIT_WORLD || p_what == Spatial::NOTIFICATION_EXIT_TREE) { + } else if (p_what == Node3D::NOTIFICATION_EXIT_WORLD || p_what == Node3D::NOTIFICATION_EXIT_TREE) { if (environment.is_valid() && get_viewport()->find_world()->get_environment() == environment) { get_viewport()->find_world()->set_environment(Ref<Environment>()); diff --git a/scene/3d/world_environment.h b/scene/3d/world_environment.h index 0c590bfc07..e4c9fc071d 100644 --- a/scene/3d/world_environment.h +++ b/scene/3d/world_environment.h @@ -31,7 +31,7 @@ #ifndef SCENARIO_FX_H #define SCENARIO_FX_H -#include "scene/3d/spatial.h" +#include "scene/3d/node_3d.h" class WorldEnvironment : public Node { diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/xr_nodes.cpp index d23e5ffa08..0373114e7d 100644 --- a/scene/3d/arvr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* arvr_nodes.cpp */ +/* xr_nodes.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,54 +28,54 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "arvr_nodes.h" -#include "core/os/input.h" -#include "servers/arvr/arvr_interface.h" -#include "servers/arvr_server.h" +#include "xr_nodes.h" +#include "core/input/input_filter.h" +#include "servers/xr/xr_interface.h" +#include "servers/xr_server.h" //////////////////////////////////////////////////////////////////////////////////////////////////// -void ARVRCamera::_notification(int p_what) { +void XRCamera3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - // need to find our ARVROrigin parent and let it know we're its camera! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin != NULL) { + // need to find our XROrigin3D parent and let it know we're its camera! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin != nullptr) { origin->set_tracked_camera(this); } }; break; case NOTIFICATION_EXIT_TREE: { - // need to find our ARVROrigin parent and let it know we're no longer its camera! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin != NULL) { + // need to find our XROrigin3D parent and let it know we're no longer its camera! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin != nullptr) { origin->clear_tracked_camera_if(this); } }; break; }; }; -String ARVRCamera::get_configuration_warning() const { +String XRCamera3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - // must be child node of ARVROrigin! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin == NULL) { - return TTR("ARVRCamera must have an ARVROrigin node as its parent."); + // must be child node of XROrigin3D! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin == nullptr) { + return TTR("XRCamera3D must have an XROrigin3D node as its parent."); }; return String(); }; -Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector3()); +Vector3 XRCamera3D::project_local_ray_normal(const Point2 &p_pos) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector3()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::project_local_ray_normal(p_pos); + return Camera3D::project_local_ray_normal(p_pos); } ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); @@ -84,29 +84,29 @@ Vector3 ARVRCamera::project_local_ray_normal(const Point2 &p_pos) const { Vector2 cpos = get_viewport()->get_camera_coords(p_pos); Vector3 ray; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); Vector2 screen_he = cm.get_viewport_half_extents(); ray = Vector3(((cpos.x / viewport_size.width) * 2.0 - 1.0) * screen_he.x, ((1.0 - (cpos.y / viewport_size.height)) * 2.0 - 1.0) * screen_he.y, -get_znear()).normalized(); return ray; }; -Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector2()); +Point2 XRCamera3D::unproject_position(const Vector3 &p_pos) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector2()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::unproject_position(p_pos); + return Camera3D::unproject_position(p_pos); } ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector2(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); Plane p(get_camera_transform().xform_inv(p_pos), 1.0); @@ -120,22 +120,22 @@ Point2 ARVRCamera::unproject_position(const Vector3 &p_pos) const { return res; }; -Vector3 ARVRCamera::project_position(const Point2 &p_point, float p_z_depth) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector3()); +Vector3 XRCamera3D::project_position(const Point2 &p_point, float p_z_depth) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector3()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::project_position(p_point, p_z_depth); + return Camera3D::project_position(p_point, p_z_depth); } ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); Size2 viewport_size = get_viewport()->get_visible_rect().size; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); Vector2 vp_he = cm.get_viewport_half_extents(); @@ -149,35 +149,35 @@ Vector3 ARVRCamera::project_position(const Point2 &p_point, float p_z_depth) con return get_camera_transform().xform(p); }; -Vector<Plane> ARVRCamera::get_frustum() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, Vector<Plane>()); +Vector<Plane> XRCamera3D::get_frustum() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, Vector<Plane>()); - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_null()) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_null()) { // we might be in the editor or have VR turned off, just call superclass - return Camera::get_frustum(); + return Camera3D::get_frustum(); } ERR_FAIL_COND_V(!is_inside_world(), Vector<Plane>()); Size2 viewport_size = get_viewport()->get_visible_rect().size; - CameraMatrix cm = arvr_interface->get_projection_for_eye(ARVRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); + CameraMatrix cm = xr_interface->get_projection_for_eye(XRInterface::EYE_MONO, viewport_size.aspect(), get_znear(), get_zfar()); return cm.get_projection_planes(get_camera_transform()); }; -ARVRCamera::ARVRCamera(){ +XRCamera3D::XRCamera3D(){ // nothing to do here yet for now.. }; -ARVRCamera::~ARVRCamera(){ +XRCamera3D::~XRCamera3D(){ // nothing to do here yet for now.. }; //////////////////////////////////////////////////////////////////////////////////////////////////// -void ARVRController::_notification(int p_what) { +void XRController3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { set_process_internal(true); @@ -186,13 +186,13 @@ void ARVRController::_notification(int p_what) { set_process_internal(false); }; break; case NOTIFICATION_INTERNAL_PROCESS: { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); // find the tracker for our controller - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { // this controller is currently turned off is_active = false; button_states = 0; @@ -206,7 +206,7 @@ void ARVRController::_notification(int p_what) { // check button states for (int i = 0; i < 16; i++) { bool was_pressed = (button_states & mask) == mask; - bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i); + bool is_pressed = InputFilter::get_singleton()->is_joy_button_pressed(joy_id, i); if (!was_pressed && is_pressed) { emit_signal("button_pressed", i); @@ -236,63 +236,63 @@ void ARVRController::_notification(int p_what) { }; }; -void ARVRController::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_controller_id", "controller_id"), &ARVRController::set_controller_id); - ClassDB::bind_method(D_METHOD("get_controller_id"), &ARVRController::get_controller_id); +void XRController3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_controller_id", "controller_id"), &XRController3D::set_controller_id); + ClassDB::bind_method(D_METHOD("get_controller_id"), &XRController3D::get_controller_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "controller_id", PROPERTY_HINT_RANGE, "0,32,1"), "set_controller_id", "get_controller_id"); - ClassDB::bind_method(D_METHOD("get_controller_name"), &ARVRController::get_controller_name); + ClassDB::bind_method(D_METHOD("get_controller_name"), &XRController3D::get_controller_name); // passthroughs to information about our related joystick - ClassDB::bind_method(D_METHOD("get_joystick_id"), &ARVRController::get_joystick_id); - ClassDB::bind_method(D_METHOD("is_button_pressed", "button"), &ARVRController::is_button_pressed); - ClassDB::bind_method(D_METHOD("get_joystick_axis", "axis"), &ARVRController::get_joystick_axis); + ClassDB::bind_method(D_METHOD("get_joystick_id"), &XRController3D::get_joystick_id); + ClassDB::bind_method(D_METHOD("is_button_pressed", "button"), &XRController3D::is_button_pressed); + ClassDB::bind_method(D_METHOD("get_joystick_axis", "axis"), &XRController3D::get_joystick_axis); - ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRController::get_is_active); - ClassDB::bind_method(D_METHOD("get_hand"), &ARVRController::get_hand); + ClassDB::bind_method(D_METHOD("get_is_active"), &XRController3D::get_is_active); + ClassDB::bind_method(D_METHOD("get_hand"), &XRController3D::get_hand); - ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRController::get_rumble); - ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble); + ClassDB::bind_method(D_METHOD("get_rumble"), &XRController3D::get_rumble); + ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &XRController3D::set_rumble); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble"); ADD_PROPERTY_DEFAULT("rumble", 0.0); - ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRController::get_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &XRController3D::get_mesh); ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::INT, "button"))); ADD_SIGNAL(MethodInfo("button_release", PropertyInfo(Variant::INT, "button"))); ADD_SIGNAL(MethodInfo("mesh_updated", PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"))); }; -void ARVRController::set_controller_id(int p_controller_id) { +void XRController3D::set_controller_id(int p_controller_id) { // We don't check any bounds here, this controller may not yet be active and just be a place holder until it is. // Note that setting this to 0 means this node is not bound to a controller yet. controller_id = p_controller_id; update_configuration_warning(); }; -int ARVRController::get_controller_id(void) const { +int XRController3D::get_controller_id(void) const { return controller_id; }; -String ARVRController::get_controller_name(void) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, String()); +String XRController3D::get_controller_name(void) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, String()); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { return String("Not connected"); }; return tracker->get_name(); }; -int ARVRController::get_joystick_id() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 0); +int XRController3D::get_joystick_id() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 0); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { // No tracker? no joystick id... (0 is our first joystick) return -1; }; @@ -300,77 +300,77 @@ int ARVRController::get_joystick_id() const { return tracker->get_joy_id(); }; -bool ARVRController::is_button_pressed(int p_button) const { +bool XRController3D::is_button_pressed(int p_button) const { int joy_id = get_joystick_id(); if (joy_id == -1) { return false; }; - return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button); + return InputFilter::get_singleton()->is_joy_button_pressed(joy_id, p_button); }; -float ARVRController::get_joystick_axis(int p_axis) const { +float XRController3D::get_joystick_axis(int p_axis) const { int joy_id = get_joystick_id(); if (joy_id == -1) { return 0.0; }; - return Input::get_singleton()->get_joy_axis(joy_id, p_axis); + return InputFilter::get_singleton()->get_joy_axis(joy_id, p_axis); }; -real_t ARVRController::get_rumble() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 0.0); +real_t XRController3D::get_rumble() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 0.0); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { return 0.0; }; return tracker->get_rumble(); }; -void ARVRController::set_rumble(real_t p_rumble) { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); +void XRController3D::set_rumble(real_t p_rumble) { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker != NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker != nullptr) { tracker->set_rumble(p_rumble); }; }; -Ref<Mesh> ARVRController::get_mesh() const { +Ref<Mesh> XRController3D::get_mesh() const { return mesh; } -bool ARVRController::get_is_active() const { +bool XRController3D::get_is_active() const { return is_active; }; -ARVRPositionalTracker::TrackerHand ARVRController::get_hand() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, ARVRPositionalTracker::TRACKER_HAND_UNKNOWN); +XRPositionalTracker::TrackerHand XRController3D::get_hand() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, XRPositionalTracker::TRACKER_HAND_UNKNOWN); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_CONTROLLER, controller_id); - if (tracker == NULL) { - return ARVRPositionalTracker::TRACKER_HAND_UNKNOWN; + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_CONTROLLER, controller_id); + if (tracker == nullptr) { + return XRPositionalTracker::TRACKER_HAND_UNKNOWN; }; return tracker->get_hand(); }; -String ARVRController::get_configuration_warning() const { +String XRController3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - // must be child node of ARVROrigin! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin == NULL) { - return TTR("ARVRController must have an ARVROrigin node as its parent."); + // must be child node of XROrigin! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin == nullptr) { + return TTR("XRController3D must have an XROrigin3D node as its parent."); }; if (controller_id == 0) { @@ -380,19 +380,19 @@ String ARVRController::get_configuration_warning() const { return String(); }; -ARVRController::ARVRController() { +XRController3D::XRController3D() { controller_id = 1; is_active = true; button_states = 0; }; -ARVRController::~ARVRController(){ +XRController3D::~XRController3D(){ // nothing to do here yet for now.. }; //////////////////////////////////////////////////////////////////////////////////////////////////// -void ARVRAnchor::_notification(int p_what) { +void XRAnchor3D::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { set_process_internal(true); @@ -401,13 +401,13 @@ void ARVRAnchor::_notification(int p_what) { set_process_internal(false); }; break; case NOTIFICATION_INTERNAL_PROCESS: { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); // find the tracker for our anchor - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_ANCHOR, anchor_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_ANCHOR, anchor_id); + if (tracker == nullptr) { // this anchor is currently not available is_active = false; } else { @@ -415,7 +415,7 @@ void ARVRAnchor::_notification(int p_what) { Transform transform; // we'll need our world_scale - real_t world_scale = arvr_server->get_world_scale(); + real_t world_scale = xr_server->get_world_scale(); // get our info from our tracker transform.basis = tracker->get_orientation(); @@ -427,7 +427,7 @@ void ARVRAnchor::_notification(int p_what) { transform.basis.orthonormalize(); // apply our reference frame and set our transform - set_transform(arvr_server->get_reference_frame() * transform); + set_transform(xr_server->get_reference_frame() * transform); // check for an updated mesh Ref<Mesh> trackerMesh = tracker->get_mesh(); @@ -442,62 +442,62 @@ void ARVRAnchor::_notification(int p_what) { }; }; -void ARVRAnchor::_bind_methods() { +void XRAnchor3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_anchor_id", "anchor_id"), &ARVRAnchor::set_anchor_id); - ClassDB::bind_method(D_METHOD("get_anchor_id"), &ARVRAnchor::get_anchor_id); + ClassDB::bind_method(D_METHOD("set_anchor_id", "anchor_id"), &XRAnchor3D::set_anchor_id); + ClassDB::bind_method(D_METHOD("get_anchor_id"), &XRAnchor3D::get_anchor_id); ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_id", PROPERTY_HINT_RANGE, "0,32,1"), "set_anchor_id", "get_anchor_id"); - ClassDB::bind_method(D_METHOD("get_anchor_name"), &ARVRAnchor::get_anchor_name); + ClassDB::bind_method(D_METHOD("get_anchor_name"), &XRAnchor3D::get_anchor_name); - ClassDB::bind_method(D_METHOD("get_is_active"), &ARVRAnchor::get_is_active); - ClassDB::bind_method(D_METHOD("get_size"), &ARVRAnchor::get_size); + ClassDB::bind_method(D_METHOD("get_is_active"), &XRAnchor3D::get_is_active); + ClassDB::bind_method(D_METHOD("get_size"), &XRAnchor3D::get_size); - ClassDB::bind_method(D_METHOD("get_plane"), &ARVRAnchor::get_plane); + ClassDB::bind_method(D_METHOD("get_plane"), &XRAnchor3D::get_plane); - ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRAnchor::get_mesh); + ClassDB::bind_method(D_METHOD("get_mesh"), &XRAnchor3D::get_mesh); ADD_SIGNAL(MethodInfo("mesh_updated", PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"))); }; -void ARVRAnchor::set_anchor_id(int p_anchor_id) { +void XRAnchor3D::set_anchor_id(int p_anchor_id) { // We don't check any bounds here, this anchor may not yet be active and just be a place holder until it is. // Note that setting this to 0 means this node is not bound to an anchor yet. anchor_id = p_anchor_id; update_configuration_warning(); }; -int ARVRAnchor::get_anchor_id(void) const { +int XRAnchor3D::get_anchor_id(void) const { return anchor_id; }; -Vector3 ARVRAnchor::get_size() const { +Vector3 XRAnchor3D::get_size() const { return size; }; -String ARVRAnchor::get_anchor_name(void) const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, String()); +String XRAnchor3D::get_anchor_name(void) const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, String()); - ARVRPositionalTracker *tracker = arvr_server->find_by_type_and_id(ARVRServer::TRACKER_ANCHOR, anchor_id); - if (tracker == NULL) { + XRPositionalTracker *tracker = xr_server->find_by_type_and_id(XRServer::TRACKER_ANCHOR, anchor_id); + if (tracker == nullptr) { return String("Not connected"); }; return tracker->get_name(); }; -bool ARVRAnchor::get_is_active() const { +bool XRAnchor3D::get_is_active() const { return is_active; }; -String ARVRAnchor::get_configuration_warning() const { +String XRAnchor3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - // must be child node of ARVROrigin! - ARVROrigin *origin = Object::cast_to<ARVROrigin>(get_parent()); - if (origin == NULL) { - return TTR("ARVRAnchor must have an ARVROrigin node as its parent."); + // must be child node of XROrigin3D! + XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent()); + if (origin == nullptr) { + return TTR("XRAnchor3D must have an XROrigin3D node as its parent."); }; if (anchor_id == 0) { @@ -507,7 +507,7 @@ String ARVRAnchor::get_configuration_warning() const { return String(); }; -Plane ARVRAnchor::get_plane() const { +Plane XRAnchor3D::get_plane() const { Vector3 location = get_translation(); Basis orientation = get_transform().basis; @@ -516,67 +516,67 @@ Plane ARVRAnchor::get_plane() const { return plane; }; -Ref<Mesh> ARVRAnchor::get_mesh() const { +Ref<Mesh> XRAnchor3D::get_mesh() const { return mesh; } -ARVRAnchor::ARVRAnchor() { +XRAnchor3D::XRAnchor3D() { anchor_id = 1; is_active = true; }; -ARVRAnchor::~ARVRAnchor(){ +XRAnchor3D::~XRAnchor3D(){ // nothing to do here yet for now.. }; //////////////////////////////////////////////////////////////////////////////////////////////////// -String ARVROrigin::get_configuration_warning() const { +String XROrigin3D::get_configuration_warning() const { if (!is_visible() || !is_inside_tree()) return String(); - if (tracked_camera == NULL) - return TTR("ARVROrigin requires an ARVRCamera child node."); + if (tracked_camera == nullptr) + return TTR("XROrigin3D requires an XRCamera3D child node."); return String(); }; -void ARVROrigin::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_world_scale", "world_scale"), &ARVROrigin::set_world_scale); - ClassDB::bind_method(D_METHOD("get_world_scale"), &ARVROrigin::get_world_scale); +void XROrigin3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_world_scale", "world_scale"), &XROrigin3D::set_world_scale); + ClassDB::bind_method(D_METHOD("get_world_scale"), &XROrigin3D::get_world_scale); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "world_scale"), "set_world_scale", "get_world_scale"); }; -void ARVROrigin::set_tracked_camera(ARVRCamera *p_tracked_camera) { +void XROrigin3D::set_tracked_camera(XRCamera3D *p_tracked_camera) { tracked_camera = p_tracked_camera; }; -void ARVROrigin::clear_tracked_camera_if(ARVRCamera *p_tracked_camera) { +void XROrigin3D::clear_tracked_camera_if(XRCamera3D *p_tracked_camera) { if (tracked_camera == p_tracked_camera) { - tracked_camera = NULL; + tracked_camera = nullptr; }; }; -float ARVROrigin::get_world_scale() const { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL_V(arvr_server, 1.0); +float XROrigin3D::get_world_scale() const { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL_V(xr_server, 1.0); - return arvr_server->get_world_scale(); + return xr_server->get_world_scale(); }; -void ARVROrigin::set_world_scale(float p_world_scale) { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); +void XROrigin3D::set_world_scale(float p_world_scale) { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); - arvr_server->set_world_scale(p_world_scale); + xr_server->set_world_scale(p_world_scale); }; -void ARVROrigin::_notification(int p_what) { - // get our ARVRServer - ARVRServer *arvr_server = ARVRServer::get_singleton(); - ERR_FAIL_NULL(arvr_server); +void XROrigin3D::_notification(int p_what) { + // get our XRServer + XRServer *xr_server = XRServer::get_singleton(); + ERR_FAIL_NULL(xr_server); switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -587,13 +587,13 @@ void ARVROrigin::_notification(int p_what) { }; break; case NOTIFICATION_INTERNAL_PROCESS: { // set our world origin to our node transform - arvr_server->set_world_origin(get_global_transform()); + xr_server->set_world_origin(get_global_transform()); // check if we have a primary interface - Ref<ARVRInterface> arvr_interface = arvr_server->get_primary_interface(); - if (arvr_interface.is_valid() && tracked_camera != NULL) { + Ref<XRInterface> xr_interface = xr_server->get_primary_interface(); + if (xr_interface.is_valid() && tracked_camera != nullptr) { // get our positioning transform for our headset - Transform t = arvr_interface->get_transform_for_eye(ARVRInterface::EYE_MONO, Transform()); + Transform t = xr_interface->get_transform_for_eye(XRInterface::EYE_MONO, Transform()); // now apply this to our camera tracked_camera->set_transform(t); @@ -603,19 +603,19 @@ void ARVROrigin::_notification(int p_what) { break; }; - // send our notification to all active ARVR interfaces, they may need to react to it also - for (int i = 0; i < arvr_server->get_interface_count(); i++) { - Ref<ARVRInterface> interface = arvr_server->get_interface(i); + // send our notification to all active XE interfaces, they may need to react to it also + for (int i = 0; i < xr_server->get_interface_count(); i++) { + Ref<XRInterface> interface = xr_server->get_interface(i); if (interface.is_valid() && interface->is_initialized()) { interface->notification(p_what); } } }; -ARVROrigin::ARVROrigin() { - tracked_camera = NULL; +XROrigin3D::XROrigin3D() { + tracked_camera = nullptr; }; -ARVROrigin::~ARVROrigin(){ +XROrigin3D::~XROrigin3D(){ // nothing to do here yet for now.. }; diff --git a/scene/3d/arvr_nodes.h b/scene/3d/xr_nodes.h index e968e33c9d..a2f16545d1 100644 --- a/scene/3d/arvr_nodes.h +++ b/scene/3d/xr_nodes.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* arvr_nodes.h */ +/* xr_nodes.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,24 +28,24 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef ARVR_NODES_H -#define ARVR_NODES_H +#ifndef XR_NODES_H +#define XR_NODES_H -#include "scene/3d/camera.h" -#include "scene/3d/spatial.h" +#include "scene/3d/camera_3d.h" +#include "scene/3d/node_3d.h" #include "scene/resources/mesh.h" -#include "servers/arvr/arvr_positional_tracker.h" +#include "servers/xr/xr_positional_tracker.h" /** @author Bastiaan Olij <mux213@gmail.com> **/ /* - ARVRCamera is a subclass of camera which will register itself with its parent ARVROrigin and as a result is automatically positioned + XRCamera is a subclass of camera which will register itself with its parent XROrigin and as a result is automatically positioned */ -class ARVRCamera : public Camera { +class XRCamera3D : public Camera3D { - GDCLASS(ARVRCamera, Camera); + GDCLASS(XRCamera3D, Camera3D); protected: void _notification(int p_what); @@ -58,19 +58,19 @@ public: virtual Vector3 project_position(const Point2 &p_point, float p_z_depth) const; virtual Vector<Plane> get_frustum() const; - ARVRCamera(); - ~ARVRCamera(); + XRCamera3D(); + ~XRCamera3D(); }; /* - ARVRController is a helper node that automatically updates its position based on tracker data. + XRController3D is a helper node that automatically updates its position based on tracker data. - It must be a child node of our ARVROrigin node + It must be a child node of our XROrigin node */ -class ARVRController : public Spatial { +class XRController3D : public Node3D { - GDCLASS(ARVRController, Spatial); + GDCLASS(XRController3D, Node3D); private: int controller_id; @@ -95,23 +95,23 @@ public: void set_rumble(real_t p_rumble); bool get_is_active() const; - ARVRPositionalTracker::TrackerHand get_hand() const; + XRPositionalTracker::TrackerHand get_hand() const; Ref<Mesh> get_mesh(void) const; String get_configuration_warning() const; - ARVRController(); - ~ARVRController(); + XRController3D(); + ~XRController3D(); }; /* - ARVRAnchor is a helper node that automatically updates its position based on anchor data, it represents a real world location. - It must be a child node of our ARVROrigin node + XRAnchor3D is a helper node that automatically updates its position based on anchor data, it represents a real world location. + It must be a child node of our XROrigin3D node */ -class ARVRAnchor : public Spatial { - GDCLASS(ARVRAnchor, Spatial); +class XRAnchor3D : public Node3D { + GDCLASS(XRAnchor3D, Node3D); private: int anchor_id; @@ -137,24 +137,24 @@ public: String get_configuration_warning() const; - ARVRAnchor(); - ~ARVRAnchor(); + XRAnchor3D(); + ~XRAnchor3D(); }; /* - ARVROrigin is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world. + XROrigin3D is special spatial node that acts as our origin point mapping our real world center of our tracking volume into our virtual world. It is this point that you will move around the world as the player 'moves while standing still', i.e. the player moves through teleporting or controller inputs as opposed to physically moving. Our camera and controllers will always be child nodes and thus place relative to this origin point. - This node will automatically locate any camera child nodes and update its position while our ARVRController node will handle tracked controllers. + This node will automatically locate any camera child nodes and update its position while our XRController3D node will handle tracked controllers. */ -class ARVROrigin : public Spatial { +class XROrigin3D : public Node3D { - GDCLASS(ARVROrigin, Spatial); + GDCLASS(XROrigin3D, Node3D); private: - ARVRCamera *tracked_camera; + XRCamera3D *tracked_camera; protected: void _notification(int p_what); @@ -163,14 +163,14 @@ protected: public: String get_configuration_warning() const; - void set_tracked_camera(ARVRCamera *p_tracked_camera); - void clear_tracked_camera_if(ARVRCamera *p_tracked_camera); + void set_tracked_camera(XRCamera3D *p_tracked_camera); + void clear_tracked_camera_if(XRCamera3D *p_tracked_camera); float get_world_scale() const; void set_world_scale(float p_world_scale); - ARVROrigin(); - ~ARVROrigin(); + XROrigin3D(); + ~XROrigin3D(); }; -#endif /* ARVR_NODES_H */ +#endif /* XR_NODES_H */ |