Created
February 8, 2018 14:44
-
-
Save coderespawn/d20ede2c6a33b2e198a9df556506cc39 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "MyMeshExporter.h" | |
#include "RawIndexBuffer.h" | |
#include "StaticMeshVertexBuffer.h" | |
#include "PositionVertexBuffer.h" | |
void UMyMeshExporter::ExportStaticMesh(UStaticMesh* StaticMesh) | |
{ | |
const FStaticMeshVertexBuffer& VertexBuffer = StaticMesh->RenderData->LODResources[0].VertexBuffer; | |
const FPositionVertexBuffer& PositionVertexBuffer = StaticMesh->RenderData->LODResources[0].PositionVertexBuffer; | |
// Build the vertex list | |
TArray<FVector> Vertices; | |
const int32 VertexCount = PositionVertexBuffer.GetNumVertices(); | |
for (int32 i = 0; i < VertexCount; i++) | |
{ | |
FVector Vertex = PositionVertexBuffer.VertexPosition(i); | |
FVector Normal = VertexBuffer.VertexTangentZ(i); | |
// save in your vertex array | |
Vertices.Add(Vertex); | |
} | |
// Build the index list | |
TArray<uint32> Indices; // << Result saved here | |
const FRawStaticIndexBuffer& IndexBuffer = StaticMesh->RenderData->LODResources[0].IndexBuffer; | |
IndexBuffer.GetCopy(Indices); | |
// Optional: If you want the triangle vertices | |
{ | |
int NumIndices = Indices.Num(); | |
for (int i = 0; i < NumIndices; i += 3) { | |
uint32 i0 = Indices[i + 0]; | |
uint32 i1 = Indices[i + 1]; | |
uint32 i2 = Indices[i + 2]; | |
const FVector& v0 = Vertices[i0]; | |
const FVector& v1 = Vertices[i1]; | |
const FVector& v2 = Vertices[i2]; | |
/// ... | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "CoreMinimal.h" | |
#include "MyMeshExporter.generated.h" | |
class UStaticMesh; | |
UCLASS(Blueprintable) | |
class UMyMeshExporter : public UObject { | |
GENERATED_BODY() | |
UFUNCTION(BlueprintCallable, Category="Exporter") | |
static void ExportStaticMesh(UStaticMesh* StaticMesh); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment