ok the mesh look like this:
now the code look like this
#include "SpaceGame.h"
#include "APlanetGeneratedActor.h"
AAPlanetGeneratedActor::AAPlanetGeneratedActor(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
TSubobjectPtr<UGeneratedMeshComponent> mesh = PCIP.CreateDefaultSubobject<UGeneratedMeshComponent>(this, TEXT("GeneratedMesh"));
int radius = 50;
int separators = 30;
int e;
//Contains the points describing the polyline we are going to rotate
TArray<FVector> points;
/*
points.Add(FVector(20, 5, 0));
points.Add(FVector(15, 6, 0));
points.Add(FVector(12, 7, 0));
points.Add(FVector(11, 8, 0));
points.Add(FVector(8, 7, 0));
points.Add(FVector(7, 6, 0));
points.Add(FVector(4, 5, 0));
points.Add(FVector(3, 4, 0));
points.Add(FVector(2, 3, 0));
points.Add(FVector(1, 4, 0));
*/
double segmentRad = PI / 2 / (separators + 1);
for (e = -separators; e <= separators; e++)
{
double r_e = radius * FMath::Cos(segmentRad * e);
double y_e = radius * FMath::Sin(segmentRad * e);
for (int s = 0; s <= (4 * separators + 4 - 1); s++)
{
double z_s = r_e * FMath::Sin(segmentRad * s) * (-1);
double x_s = r_e * FMath::Cos(segmentRad * s);
points.Add(FVector(x_s, y_e, z_s));
}
}
points.Add(FVector(0, radius, 0));
points.Add(FVector(0, -1 * radius, 0));
TArray<FGeneratedMeshTriangle> triangles;
Shpare(points, triangles, separators, radius);
mesh->SetGeneratedMeshTriangles(triangles);
//RootComponent = Shpare(vector);
}
void AAPlanetGeneratedActor::Shpare(const TArray<FVector>& points, TArray<FGeneratedMeshTriangle>& triangles, int separators, int radius) {
UE_LOG(LogClass, Log, TEXT("AGameGeneratedActor::Sphare POINTS %d"), points.Num());
FGeneratedMeshTriangle tri;
int e = 0;
/*
for (e = 0; e < 2 * separators; e++)
{
for (int i = 0; i < (4 * separators + 4); i++)
{
triangleIndices.Add(e * (4 * separators + 4) + i);
triangleIndices.Add(e * (4 * separators + 4) + i + (4 * separators + 4));
triangleIndices.Add(e * (4 * separators + 4) + (i + 1) % (4 * separators + 4) + (4 * separators + 4));
triangleIndices.Add(e * (4 * separators + 4) + (i + 1) % (4 * separators + 4) + (4 * separators + 4));
triangleIndices.Add(e * (4 * separators + 4) + (i + 1) % (4 * separators + 4));
triangleIndices.Add(e * (4 * separators + 4) + i);
}
}
for (int i = 0; i < (4 * separators + 4); i++)
{
triangleIndices.Add(e * (4 * separators + 4) + i);
triangleIndices.Add(e * (4 * separators + 4) + (i + 1) % (4 * separators + 4));
triangleIndices.Add((4 * separators + 4) * (2 * separators + 1));
}
for (int i = 0; i < (4 * separators + 4); i++)
{
triangleIndices.Add(i);
triangleIndices.Add((i + 1) % (4 * separators + 4));
triangleIndices.Add((4 * separators + 4) * (2 * separators + 1) + 1);
}
for (int i = 0; i < triangleIndices.Num(); i = i + 3) {
//vectorInSpace.Add(FVector(triangleIndices[i], triangleIndices[i + 1], triangleIndices[i + 2]));
}*/
TArray<FVector> wp;
for (int i = 0; i < points.Num(); i++) {
wp.Add(points[i]);
}
for (int i = 0; i < points.Num(); i= i+3) {
FVector p1 = wp[i];
FVector p2 = wp[i + 1];
FVector p3 = wp[i + 2];
tri.Vertex0 = p1;
tri.Vertex1 = p2;
tri.Vertex2 = p3;
triangles.Add(tri);
}/*
for (int i = 0; i < vectorInSpace.Num(); i = i + 3) {
tri.Vertex0 = (FVector)triangleIndices[i];
tri.Vertex1 = (FVector)triangleIndices[i + 1];
tri.Vertex2 = (FVector)triangleIndices[i + 2];
triangles.Add(tri);
*/
}
now what i am missing why its not show