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

Missing one triangle #21

Open
zuffik opened this issue Feb 14, 2024 · 0 comments
Open

Missing one triangle #21

zuffik opened this issue Feb 14, 2024 · 0 comments

Comments

@zuffik
Copy link

zuffik commented Feb 14, 2024

Hey I'm trying to make low poly rocks in UE5 with random points generated and convex hull calculated around them. Everything works perfectly except that it always generate one triangle less (see picture below).

In code I just take all the vertices generated in BluePrint (UE5 procedural language), populate them into point cloud (as described in readme) and remap back to structure that I use to describe triangles. It happens with any seed. The vertices of empty triangle seem to have random indexes. So far I can work with that by rotating a rock that the empty triangle faces the ground but can be frustrating for future users.

Attachments

Code

#include "ConvexHullGenerator.h"
#include "LowPolyGame/External/QuickHull/QuickHull.hpp"

TArray<FIntVector>& UConvexHullGenerator::CalculateConvexHull(TArray<FVector>& Vertices)
{
    quickhull::QuickHull<float> qh;
    std::vector<quickhull::Vector3<float>> PointCloud;
    for (const auto Vertex : Vertices)
    {
        quickhull::Vector3<float> V3(Vertex.X, Vertex.Y, Vertex.Z);
        PointCloud.push_back(V3);
    }
    auto Hull = qh.getConvexHull(PointCloud, true, true);

    const auto Result = new TArray<FIntVector>();
    const auto IndexBuffer = Hull.getIndexBuffer();
    float Buffer[3];
    for (int i = 0; i < IndexBuffer.size(); i++)
    {
        if (i > 0 && i % 3 == 0)
        {
            FIntVector Vector = FIntVector(Buffer[0], Buffer[1], Buffer[2]);
            Result->Add(Vector);
        }
        Buffer[i % 3] = IndexBuffer[i];
    }

    return *Result;
}

Preview

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant