Merge pull request #53380 from timothyqiu/soft-body-3.x

This commit is contained in:
Rémi Verschelde 2021-10-04 11:36:48 +02:00 committed by GitHub
commit b301514708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 8 deletions

View File

@ -201,22 +201,24 @@ void SoftBodyBullet::get_node_offset(int p_node_index, btVector3 &r_offset) cons
G_TO_B(off, r_offset); G_TO_B(off, r_offset);
} }
void SoftBodyBullet::set_node_mass(int node_index, btScalar p_mass) { void SoftBodyBullet::set_node_mass(int p_node_index, btScalar p_mass) {
if (0 >= p_mass) { if (0 >= p_mass) {
pin_node(node_index); pin_node(p_node_index);
} else { } else {
unpin_node(node_index); unpin_node(p_node_index);
} }
if (bt_soft_body) { if (bt_soft_body) {
bt_soft_body->setMass(node_index, p_mass); ERR_FAIL_INDEX(p_node_index, bt_soft_body->m_nodes.size());
bt_soft_body->setMass(p_node_index, p_mass);
} }
} }
btScalar SoftBodyBullet::get_node_mass(int node_index) const { btScalar SoftBodyBullet::get_node_mass(int p_node_index) const {
if (bt_soft_body) { if (bt_soft_body) {
return bt_soft_body->getMass(node_index); ERR_FAIL_INDEX_V(p_node_index, bt_soft_body->m_nodes.size(), 1);
return bt_soft_body->getMass(p_node_index);
} else { } else {
return -1 == search_node_pinned(node_index) ? 1 : 0; return -1 == search_node_pinned(p_node_index) ? 1 : 0;
} }
} }
@ -455,17 +457,25 @@ void SoftBodyBullet::setup_soft_body() {
// Set pinned nodes // Set pinned nodes
for (int i = pinned_nodes.size() - 1; 0 <= i; --i) { for (int i = pinned_nodes.size() - 1; 0 <= i; --i) {
bt_soft_body->setMass(pinned_nodes[i], 0); const int node_index = pinned_nodes[i];
ERR_CONTINUE(0 > node_index || bt_soft_body->m_nodes.size() <= node_index);
bt_soft_body->setMass(node_index, 0);
} }
} }
void SoftBodyBullet::pin_node(int p_node_index) { void SoftBodyBullet::pin_node(int p_node_index) {
if (bt_soft_body) {
ERR_FAIL_INDEX(p_node_index, bt_soft_body->m_nodes.size());
}
if (-1 == search_node_pinned(p_node_index)) { if (-1 == search_node_pinned(p_node_index)) {
pinned_nodes.push_back(p_node_index); pinned_nodes.push_back(p_node_index);
} }
} }
void SoftBodyBullet::unpin_node(int p_node_index) { void SoftBodyBullet::unpin_node(int p_node_index) {
if (bt_soft_body) {
ERR_FAIL_INDEX(p_node_index, bt_soft_body->m_nodes.size());
}
const int id = search_node_pinned(p_node_index); const int id = search_node_pinned(p_node_index);
if (-1 != id) { if (-1 != id) {
pinned_nodes.remove(id); pinned_nodes.remove(id);