UE4:模型渲染流程

一.Custom Mesh

 

 

二.Procedural Mesh

复制代码
public:
    AMyActor();

protected:
    virtual void BeginPlay() override;

    UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
        UProceduralMeshComponent* CustomMesh;

    /* The vertices of the mesh */
    TArray<FVector> Vertices;

    /* The triangles of the mesh */
    TArray<int32> Triangles;

    /* Creates a triangle that connects the given vertices */
    void AddTriangle(int32 V1, int32 V2, int32 V3);

    void GenerateCubeMesh();

public:

    //Called every frame
    virtual void Tick(float DeltaTime) override;
        
复制代码

 

复制代码
//Sets default values
AMyActor::AMyActor()
{
    // Set this actor to call Tick() every frame. You can turn this off to
    PrimaryActorTick.bCanEverTick = true;

    CustomMesh = CreateDefaultSubobject<UProceduralMeshComponent>("CustomMesh");

    SetRootComponent(CustomMesh);
    CustomMesh->bUseAsyncCooking = true;
 
}

// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
    Super::BeginPlay();
    GenerateCubeMesh();
}

void AMyActor::AddTriangle(int32 V1, int32 V2, int32 V3)
{
    Triangles.Add(V1);
    Triangles.Add(V2);
    Triangles.Add(V3);
}

void AMyActor::GenerateCubeMesh()
{
    //6 sides on cube, 4 verts each(corners)
  
    //These are relative locations to the placed Actor in the world
    Vertices.Add(FVector(0, -100, 0));
    Vertices.Add(FVector(0, -100, 100));
    Vertices.Add(FVector(0, 100, 0));
    Vertices.Add(FVector(0, 100, 100));

    Vertices.Add(FVector(100, -100, 0));
    Vertices.Add(FVector(100, -100, 100));

    Vertices.Add(FVector(100, 100, 100));
    Vertices.Add(FVector(100, 100, 0));

    //Back face
    AddTriangle(0, 2, 3);
    AddTriangle(3, 1, 0);

    //Left face
    AddTriangle(0, 1, 4);
    AddTriangle(4, 1, 5);

    //Front face
    AddTriangle(4, 5, 7);
    AddTriangle(7, 5, 6);

    //Right face
    AddTriangle(7, 6, 3);
    AddTriangle(3, 2, 7);
 
    //Top face
    AddTriangle(1, 3, 5);
    AddTriangle(6, 5, 3);

    //bottom face
    AddTriangle(2, 0, 4);
    AddTrianlgle(4, 7, 2);

    TArray<FLinearColor> VertexColors;
    VertexColors.Add(FLinearColor(0.f, 0.f, 1.f));
    VertexColors.Add(FLinearColor(1.f, 0.f, 0.f));
    VertexColors.Add(FLinearColor(1.f, 0.f, 0.f));
    VertexColors.Add(FLinearColor(0.f, 1.f, 0.f));
    VertexColors.Add(FLinearColor(0.5f, 1.f, 0.5f));
    VertexColors.Add(FLinearColor(0.f, 1.f, 0.f));
    VertexColors.Add(FLinearColor(1.f, 1.f, 0.f));
    VertexColors.Add(FLinearColor(0.f, 1.f, 1.f));

    CustomMesh->CreateMeshSection_LinearColor(0, Vertices, Triangles, TArray<FVector>(),  TArray<FVector2D>(), VertexColors, TArray<FProcMeshTangent>(), true);

}
复制代码

 

 

三.

UActorComponent

USceneComponent

UPrimitiveComponent

UMeshComponent

 

四.底层绘制

复制代码
底层绘制模型的方式有两种:
UMeshComponent PrimitiveDrawInterface(PDI) 渲染模型 UPrimitiveComponent 渲染代理
//根据数组点创建几何体模型 UMeshComponent->PrimitiveDrawInterface->dynamicMesh PDI->UStaticMeshComponent UStaticMesh->FRawMesh->FStaticMeshSourceModel->SaveRawMesh->Build //底层绘制几何体模型 Primitive PrimitiveComponent
复制代码

 

1.PrimitiveDrawInterface(PDI)

 

posted @   言午丶  阅读(631)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示