diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-10-01 08:42:47 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-10-01 08:42:47 -0700 |
commit | b8eeb34b4e18304ce24bda6001c6f120b99ddeec (patch) | |
tree | db3af96a27ceb15562692de0777007fdc87da5a5 /modules | |
parent | 77721b35ba21f2e7e8bb42cf415fccb018517843 (diff) |
Remove scene code in physics servers
Replaced Mesh with mesh RID in Godot Physics 3D and Bullet.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/bullet/bullet_physics_server.cpp | 2 | ||||
-rw-r--r-- | modules/bullet/bullet_physics_server.h | 2 | ||||
-rw-r--r-- | modules/bullet/soft_body_bullet.cpp | 33 | ||||
-rw-r--r-- | modules/bullet/soft_body_bullet.h | 8 |
4 files changed, 24 insertions, 21 deletions
diff --git a/modules/bullet/bullet_physics_server.cpp b/modules/bullet/bullet_physics_server.cpp index 6b2b0c4ad0..bb2db49c87 100644 --- a/modules/bullet/bullet_physics_server.cpp +++ b/modules/bullet/bullet_physics_server.cpp @@ -903,7 +903,7 @@ RID BulletPhysicsServer3D::soft_body_get_space(RID p_body) const { return space->get_self(); } -void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, const REF &p_mesh) { +void BulletPhysicsServer3D::soft_body_set_mesh(RID p_body, RID p_mesh) { SoftBodyBullet *body = soft_body_owner.get_or_null(p_body); ERR_FAIL_COND(!body); diff --git a/modules/bullet/bullet_physics_server.h b/modules/bullet/bullet_physics_server.h index 7f0934e679..7c146de0c3 100644 --- a/modules/bullet/bullet_physics_server.h +++ b/modules/bullet/bullet_physics_server.h @@ -265,7 +265,7 @@ public: virtual void soft_body_set_space(RID p_body, RID p_space) override; virtual RID soft_body_get_space(RID p_body) const override; - virtual void soft_body_set_mesh(RID p_body, const REF &p_mesh) override; + virtual void soft_body_set_mesh(RID p_body, RID p_mesh) override; virtual AABB soft_body_get_bounds(RID p_body) const override; diff --git a/modules/bullet/soft_body_bullet.cpp b/modules/bullet/soft_body_bullet.cpp index bbbb0e7851..94b7e0ce38 100644 --- a/modules/bullet/soft_body_bullet.cpp +++ b/modules/bullet/soft_body_bullet.cpp @@ -32,9 +32,10 @@ #include "bullet_types_converter.h" #include "bullet_utilities.h" -#include "scene/3d/soft_body_3d.h" #include "space_bullet.h" +#include "servers/rendering_server.h" + SoftBodyBullet::SoftBodyBullet() : CollisionObjectBullet(CollisionObjectBullet::TYPE_SOFT_BODY) {} @@ -105,24 +106,26 @@ void SoftBodyBullet::update_rendering_server(RenderingServerHandler *p_rendering p_rendering_server_handler->set_aabb(aabb); } -void SoftBodyBullet::set_soft_mesh(const Ref<Mesh> &p_mesh) { - if (p_mesh.is_null()) { - soft_mesh.unref(); - } else { - soft_mesh = p_mesh; - } +void SoftBodyBullet::set_soft_mesh(RID p_mesh) { + destroy_soft_body(); + + soft_mesh = p_mesh; if (soft_mesh.is_null()) { - destroy_soft_body(); return; } - Array arrays = soft_mesh->surface_get_arrays(0); - ERR_FAIL_COND(!(soft_mesh->surface_get_format(0) & RS::ARRAY_FORMAT_INDEX)); - set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]); + Array arrays = RenderingServer::get_singleton()->mesh_surface_get_arrays(soft_mesh, 0); + + bool success = set_trimesh_body_shape(arrays[RS::ARRAY_INDEX], arrays[RS::ARRAY_VERTEX]); + if (!success) { + destroy_soft_body(); + } } void SoftBodyBullet::destroy_soft_body() { + soft_mesh = RID(); + if (!bt_soft_body) { return; } @@ -289,9 +292,9 @@ void SoftBodyBullet::set_drag_coefficient(real_t p_val) { } } -void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices) { - /// Assert the current soft body is destroyed - destroy_soft_body(); +bool SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices) { + ERR_FAIL_COND_V(p_indices.is_empty(), false); + ERR_FAIL_COND_V(p_vertices.is_empty(), false); /// Parse visual server indices to physical indices. /// Merge all overlapping vertices and create a map of physical vertices to visual server @@ -363,6 +366,8 @@ void SoftBodyBullet::set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector bt_soft_body = btSoftBodyHelpers::CreateFromTriMesh(fake_world_info, &bt_vertices[0], &bt_triangles[0], triangles_size, false); setup_soft_body(); } + + return true; } void SoftBodyBullet::setup_soft_body() { diff --git a/modules/bullet/soft_body_bullet.h b/modules/bullet/soft_body_bullet.h index 63708b57a7..84da56ae69 100644 --- a/modules/bullet/soft_body_bullet.h +++ b/modules/bullet/soft_body_bullet.h @@ -32,7 +32,6 @@ #define SOFT_BODY_BULLET_H #include "collision_object_bullet.h" -#include "scene/resources/material.h" // TODO remove this please #ifdef None /// This is required to remove the macro None defined by x11 compiler because this word "None" is used internally by Bullet @@ -42,7 +41,6 @@ #include "BulletSoftBody/btSoftBodyHelpers.h" #include "collision_object_bullet.h" -#include "scene/resources/mesh.h" #include "servers/physics_server_3d.h" #ifdef x11_None @@ -64,7 +62,7 @@ private: btSoftBody::Material *mat0 = nullptr; // This is just a copy of pointer managed by btSoftBody bool isScratched = false; - Ref<Mesh> soft_mesh; + RID soft_mesh; int simulation_precision = 5; real_t total_mass = 1.; @@ -100,7 +98,7 @@ public: void update_rendering_server(RenderingServerHandler *p_rendering_server_handler); - void set_soft_mesh(const Ref<Mesh> &p_mesh); + void set_soft_mesh(RID p_mesh); void destroy_soft_body(); // Special function. This function has bad performance @@ -139,7 +137,7 @@ public: _FORCE_INLINE_ real_t get_drag_coefficient() const { return drag_coefficient; } private: - void set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices); + bool set_trimesh_body_shape(Vector<int> p_indices, Vector<Vector3> p_vertices); void setup_soft_body(); void pin_node(int p_node_index); |