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"

Read Static Mesh Data into Procedural Mesh

Hey Guys, So I'm currently working on reading in the render data from a static mesh and using it to create a procedural mesh so I can deform it at runtime, but running into issues with getting the mesh to render properly. Here's the current function I have for reading in the render data using it:

 void AProceduralLandscape::GenerateLandscape()
 {
     TArray<FVector> vertices;
     TArray<int32> triangles;
     TArray<FVector> normals;
     TArray<FVector2D> UV0;
     TArray<FColor> vertexColors;
     TArray<FProcMeshTangent> tangents;
 
     if (LandscapeReference)
     {
         FPositionVertexBuffer* vertexPositionBuffer = &LandscapeReference->RenderData->LODResources[0].PositionVertexBuffer;
         FRawStaticIndexBuffer* indexBuffer = &LandscapeReference->RenderData->LODResources[0].IndexBuffer;
         FStaticMeshVertexBuffer* vertexBuffer = &LandscapeReference->RenderData->LODResources[0].VertexBuffer;
 
         if (vertexPositionBuffer)
         {
 
             const int32 vertexCount = vertexPositionBuffer->GetNumVertices();
             for (int32 i = 0; i < vertexCount; i++)
             {
                 vertices.Add(vertexPositionBuffer->VertexPosition(i));
                 triangles.Add(indexBuffer->GetArrayView()[i]);
                 normals.Add(FVector(1, 0, 0));
                 UV0.Add(vertexBuffer->GetVertexUV(i,0));
                 vertexColors.Add(FColor(100, 100, 100, 100));
                 tangents.Add(FProcMeshTangent(vertexBuffer->VertexTangentX(i).Vector.X, vertexBuffer->VertexTangentX(i).Vector.Y, vertexBuffer->VertexTangentX(i).Vector.Z));
 
             }
         }
         LandscapeMesh->CreateMeshSection(1, vertices, triangles, normals, UV0, vertexColors, tangents, false); 
         UE_LOG(LogTemp, Warning, TEXT("CREATED LANDSCAPE"));
 
     }
 }

 

Currently it'll render only the first 1/3 of the mesh. My hunch is the hard-coded normals I'm using for generation, but I can't really find any normal info inside FStaticMeshLODResources. Any ideas? Thanks

Product Version: UE 4.11
Tags:
more ▼

asked May 09 '16 at 04:25 AM in C++ Programming

avatar image

Regalith
156 12 9 17

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You're not getting all of the indices. With a triangle list that actually uses the indices correctly it will have quite a few more indices than vertices. Best thing to do is a separate loop that looks at indexBuffer.GetNumIndices() and copies all of them to the triangles array you have.

For an example, it's possible to have a cube with only 8 vertices but still need 36 indices to makeup all 12 triangles.

To copy the indices, something like this should get them all.

 for (int32 = 0; i < indexBuffer.GetNumIndices(); i++)
 {
      triangles.Add(indexBuffer->GetArrayView()[i]);
 }  
more ▼

answered May 09 '16 at 05:07 AM

avatar image

Koderz
313 6 7 23

avatar image Regalith May 09 '16 at 05:57 AM

That was exactly the issue, thanks! I should probably find a book on graphics since I never realized the reason behind indices.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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