x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

FStaticPrimitiveDrawInterface::DrawMesh draws only 2 polygons

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?

Product Version: UE 4.17
Tags:
more ▼

asked Oct 07 '17 at 07:43 PM in C++ Programming

avatar image

Ice_Eagle
1 3

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

I found the solution The index buffer must look like this

             IndexBuffer.Indices16[0] = 2;
             IndexBuffer.Indices16[1] = 1;
             IndexBuffer.Indices16[2] = 0;
 
             IndexBuffer.Indices16[3] = 3;
             IndexBuffer.Indices16[4] = 2;
             IndexBuffer.Indices16[5] = 0;
 
             IndexBuffer.Indices16[6] = 5;
             IndexBuffer.Indices16[7] = 3;
             IndexBuffer.Indices16[8] = 0;
 
             IndexBuffer.Indices16[9] = 5;
             IndexBuffer.Indices16[10] = 4;
             IndexBuffer.Indices16[11] = 3;

As I understand, the first index of the triangle must be the biggest one, second smaller, third the smallest one.

more ▼

answered Oct 08 '17 at 09:40 AM

avatar image

Ice_Eagle
1 3

avatar image epernod Oct 08 '17 at 09:52 AM

ok, I think it is more the positions of the points and not really the index that count. The triangle must be created in clockwise order to see it from your point of view. Like in basic opengl: https://www.khronos.org/opengl/wiki/Face_Culling

(comments are locked)
10|2000 characters needed characters left

Did you check the value of Indexcount? And simple question, did you turn around you drawing, if the triangles are not draw both side, it might be there but invisible from one point of view.

more ▼

answered Oct 08 '17 at 08:40 AM

avatar image

epernod
6 1 2

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question