I am trying to draw 4 polygons(4 triangles). For this point I am using a component implemented from PrimitiveComponent and own SceneProxy.
So:
FHexagonSceneProxy::FHexagonSceneProxy(const UHexagonHUDComponent* InComponent)
: FPrimitiveSceneProxy(InComponent)
{
auto NonConstInComponent = const_cast<UHexagonHUDComponent*>(InComponent);
thickness = NonConstInComponent->GetThickness();
radius = NonConstInComponent->GetRadius();
b_only_outline = NonConstInComponent->IsOutLineOnly();
std::tie(main_color, outline_color) = NonConstInComponent->GetColor();
MaterialInterface = NonConstInComponent->GetMaterial(0);
if (NonConstInComponent->IsXRay()) {
// Doesn't work
// depth = SDPG_Foreground;
bOccluded = true;
}
if (!b_only_outline) {
const float delta_rad = 1.047198f;
VertexBuffer.Vertices.SetNumUninitialized(6);
IndexBuffer.Indices16.SetNumUninitialized(12);
//Initialize Vertices
{
float angle_one = 0;
for (int i = 0; i < 6; i++) {
FVector start_pos = FVector::ZeroVector;
//Calculate first point of the line
start_pos.X += cosf(angle_one) * radius;
start_pos.Y += sinf(angle_one) * radius;
angle_one += delta_rad;
VertexBuffer.Vertices[i].Position = start_pos;
VertexBuffer.Vertices[i].TangentX = FVector(0);
VertexBuffer.Vertices[i].TangentZ = FVector(0);
VertexBuffer.Vertices[i].TextureCoordinate = FVector2D(start_pos.X, start_pos.Y);
}
}
//Initialize Index Buffer
{
IndexBuffer.Indices16[0] = 0;
IndexBuffer.Indices16[1] = 1;
IndexBuffer.Indices16[2] = 2;
IndexBuffer.Indices16[3] = 5;
IndexBuffer.Indices16[4] = 4;
IndexBuffer.Indices16[5] = 3;
IndexBuffer.Indices16[6] = 5;
IndexBuffer.Indices16[7] = 0;
IndexBuffer.Indices16[8] = 3;
IndexBuffer.Indices16[9] = 2;
IndexBuffer.Indices16[10] = 0;
IndexBuffer.Indices16[11] = 3;
}
InitResources();
}
}
void FHexagonSceneProxy::MakeMeshBatch(FMeshBatch& Mesh) const
{
FMaterialRenderProxy * MaterialProxy = MaterialInterface->GetRenderProxy(IsSelected());//MaterialInstance->GetRenderProxy(IsSelected());
FMeshBatchElement& BatchElement = Mesh.Elements[0];
BatchElement.IndexBuffer = &IndexBuffer;
Mesh.bWireframe = false;
Mesh.VertexFactory = &VertexFactory;
Mesh.MaterialRenderProxy = MaterialProxy;
Mesh.CastShadow = true;
BatchElement.PrimitiveUniformBuffer = CreatePrimitiveUniformBufferImmediate(GetLocalToWorld(), GetBounds(), GetLocalBounds(), true, UseEditorDepthTest());
BatchElement.FirstIndex = 0;
const int IndexCount = FMath::Max(IndexBuffer.Indices16.Num(), IndexBuffer.Indices32.Num());
BatchElement.NumPrimitives = IndexCount / 3;
BatchElement.MinVertexIndex = 0;
BatchElement.MaxVertexIndex = VertexBuffer.Vertices.Num() - 1;
Mesh.ReverseCulling = IsLocalToWorldDeterminantNegative();
Mesh.Type = PT_TriangleList;
Mesh.DepthPriorityGroup = SDPG_World;
}
void FHexagonSceneProxy::DrawStaticElements(class FStaticPrimitiveDrawInterface* PDI)
{
const float ScreenSize = 1.0f;
FMeshBatch MeshBatch;
MakeMeshBatch(MeshBatch);
PDI->DrawMesh(MeshBatch, ScreenSize);
}
However I have 6 Vertices and 12 Indexies at the game I see only 2 polygons. I have to skip much code to make it more readable. What can be the reason of it?