SpiecsEngine
 
Loading...
Searching...
No Matches

◆ BuildKDTree()

bool Spices::MeshProcessor::BuildKDTree ( MeshPack * meshPack,
const std::vector< glm::uvec3 > & primVertices,
scl::kd_tree< 6 > & kdTree )
staticprivate

Build KDTree use specific meshlets.

Parameters
[in]meshPackMeshPack.
[in]primVerticesPrimVertices.
[in,out]kdTree.
Returns
Returns true if succeed.

Definition at line 763 of file MeshProcessor.cpp.

768 {
770
771 std::unordered_map<uint32_t, bool> primVerticesMap;
772 for (auto& primVertex : primVertices)
773 {
774 primVerticesMap[primVertex.x] = true;
775 primVerticesMap[primVertex.y] = true;
776 primVerticesMap[primVertex.z] = true;
777 }
778
779 auto& positions = *meshPack->m_MeshResource.positions.attributes;
780 auto& texCoords = *meshPack->m_MeshResource.texCoords.attributes;
781 auto& vertices = *meshPack->m_MeshResource.vertices .attributes;
782
783 std::vector<scl::kd_tree<6>::item> items;
784 items.resize(primVerticesMap.size());
785
786 uint32_t i = 0;
787 for (auto& [primVertex, ignore] : primVerticesMap)
788 {
789 glm::uvec4 vertex = vertices[primVertex];
790
791 items[i] =
792 {
793 positions[vertex.x].x,
794 positions[vertex.x].y,
795 positions[vertex.x].z,
796 texCoords[vertex.w].x,
797 texCoords[vertex.w].y,
798 (float)primVertex
799 };
800
801 ++i;
802 }
803
804 kdTree.insert(items);
805
806 return true;
807 }
#define SPICES_PROFILE_ZONE
void insert(const std::vector< item > &points)
Insert a point into the kd_tree. Start at the root, comparing the new point’s first dimension with th...
Definition KDTree.h:602