zoukankan      html  css  js  c++  java
  • 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)

  • 相关阅读:
    Git安装及配置-拉取远程仓库代码
    Leangoo领歌敏捷项目管理工具新增测试管理功能
    Xcode中的Vim--XVim
    npm安装报错:源文本中存在无法识别的标记
    给找不到类型文件的依赖增加TypeScript类型声明
    输入框为空时,按钮灰色不可点
    Django settings.py设置 DEBUG=False后静态文件无法加载解决
    mongodb系列~开发规范
    mongodb系列~升级版本
    CIM基础平台性能指标
  • 原文地址:https://www.cnblogs.com/k5bg/p/15239465.html
Copyright © 2011-2022 走看看