Optimize AABB calculation in software skinning
Using min/max instead of regular AABB for optimal processing.
This commit is contained in:
parent
9147a6a401
commit
304102f66f
1 changed files with 9 additions and 9 deletions
|
@ -390,8 +390,8 @@ void MeshInstance::_update_skinning() {
|
||||||
RID skeleton = skin_ref->get_skeleton();
|
RID skeleton = skin_ref->get_skeleton();
|
||||||
ERR_FAIL_COND(!skeleton.is_valid());
|
ERR_FAIL_COND(!skeleton.is_valid());
|
||||||
|
|
||||||
AABB aabb;
|
Vector3 aabb_min = Vector3(FLT_MAX, FLT_MAX, FLT_MAX);
|
||||||
bool first_vertex = true;
|
Vector3 aabb_max = Vector3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
|
||||||
|
|
||||||
VisualServer *visual_server = VisualServer::get_singleton();
|
VisualServer *visual_server = VisualServer::get_singleton();
|
||||||
|
|
||||||
|
@ -503,18 +503,18 @@ void MeshInstance::_update_skinning() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (first_vertex) {
|
aabb_min.x = MIN(aabb_min.x, vertex.x);
|
||||||
aabb.position = vertex;
|
aabb_min.y = MIN(aabb_min.y, vertex.y);
|
||||||
first_vertex = false;
|
aabb_min.z = MIN(aabb_min.z, vertex.z);
|
||||||
} else {
|
aabb_max.x = MAX(aabb_max.x, vertex.x);
|
||||||
aabb.expand_to(vertex);
|
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_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;
|
software_skinning_flags |= SoftwareSkinning::FLAG_BONES_READY;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue