• 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)

  • 相关阅读:
    【Python】错误、调试和测试
    【c++ primer, 5e】函数指针
    【英语学习】【17/4/1】
    【c++ primer, 5e】函数匹配
    FIRST GAME.
    【Thinking in Java, 4e】访问权限控制
    【c++ primer, 5e】特殊用途语言特性
    Top-Down笔记 #01# 计算机网络概述
    NHibernate之映射文件配置说明
    Web Service 部署到IIS服务器
  • 原文地址:https://www.cnblogs.com/k5bg/p/15239465.html
Copyright © 2020-2023  润新知