Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize AABB calculation in software skinning #53190

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions scene/3d/mesh_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ void MeshInstance::_update_skinning() {
RID skeleton = skin_ref->get_skeleton();
ERR_FAIL_COND(!skeleton.is_valid());

AABB aabb;
bool first_vertex = true;
Vector3 aabb_min = Vector3(FLT_MAX, FLT_MAX, FLT_MAX);
Vector3 aabb_max = Vector3(-FLT_MAX, -FLT_MAX, -FLT_MAX);

VisualServer *visual_server = VisualServer::get_singleton();

Expand Down Expand Up @@ -503,18 +503,18 @@ void MeshInstance::_update_skinning() {
}
}

if (first_vertex) {
aabb.position = vertex;
first_vertex = false;
} else {
aabb.expand_to(vertex);
}
aabb_min.x = MIN(aabb_min.x, vertex.x);
aabb_min.y = MIN(aabb_min.y, vertex.y);
aabb_min.z = MIN(aabb_min.z, vertex.z);
aabb_max.x = MAX(aabb_max.x, vertex.x);
aabb_max.y = MAX(aabb_max.y, vertex.y);
aabb_max.z = MAX(aabb_max.z, vertex.z);
}

visual_server->mesh_surface_update_region(mesh_rid, surface_index, 0, buffer);
}

visual_server->mesh_set_custom_aabb(mesh_rid, aabb);
visual_server->mesh_set_custom_aabb(mesh_rid, AABB(aabb_min, aabb_max - aabb_min));

software_skinning_flags |= SoftwareSkinning::FLAG_BONES_READY;
}
Expand Down