UE4 CableMesh

UE4 CableMesh

UE4 CableComponent 生成绳索效果的Mesh。

绳索网格

基本思路

给定起始点内插一系列点,然后物理模拟调整点的位置,最后在点周围生成一系列三角网。

生成三角网的代码如下:

/** The vertex type used for dynamic meshes. */
struct FDynamicMeshVertex
{
    FDynamicMeshVertex() {}
    FDynamicMeshVertex( const FVector& InPosition ):
        Position(InPosition),
        TangentX(FVector(1,0,0)),
        TangentZ(FVector(0,0,1)),
        Color(FColor(255,255,255)) 
    {
        //..............................
    }

    FDynamicMeshVertex(const FVector& InPosition, const FVector2D& InTexCoord, const FColor& InColor) :
        Position(InPosition),
        TangentX(FVector(1, 0, 0)),
        TangentZ(FVector(0, 0, 1)),
        Color(InColor)
    {
        //...................................
    }

    FDynamicMeshVertex(const FVector& InPosition,const FVector& InTangentX,const FVector& InTangentZ,const FVector2D& InTexCoord, const FColor& InColor):
        Position(InPosition),
        TangentX(InTangentX),
        TangentZ(InTangentZ),
        Color(InColor)
    {
        //.......................
    }

    FDynamicMeshVertex(const FVector& InPosition, const FVector& LayerTexcoords, const FVector2D& WeightmapTexcoords)
        : Position(InPosition)
        , TangentX(FVector(1, 0, 0))
        , TangentZ(FVector(0, 0, 1))
        , Color(FColor::White)
    {
        //...............
    }
   //顶点位置
    FVector Position;
   //纹理坐标
    FVector2D TextureCoordinate[MAX_STATIC_TEXCOORDS];
   //切线
    FPackedNormal TangentX;
   //法线
    FPackedNormal TangentZ;
    FColor Color;
};
void BuildCableMesh(const TArray& InPoints, TArray& OutVertices, TArray& OutIndices)
    {
        const FColor VertexColor(255,255,255);
        const int32 NumPoints = InPoints.Num();
        const int32 SegmentCount = NumPoints-1;

        // Build vertices

        // We double up the first and last vert of the ring, because the UVs are different
        int32 NumRingVerts = NumSides+1;

        // For each point along spline..
        for(int32 PointIdx=0; PointIdx

参考链接

UE4 CableMesh

你可能感兴趣的:(UE4 CableMesh)