feat: 添加顶点属性层基础结构和各向异性参数

- Task 1: 添加顶点属性层基础结构
  - 在头文件中添加顶点属性数组声明
  - 添加 InitializeVertexAttributes() 和 ReleaseVertexAttributes() 函数
  - 在 InitializeBoxMesh() 中调用初始化
  - 在 EndPlay() 中调用释放

- Task 2: 实现顶点属性初始化
  - 实现 InitializeVertexAttributes() 函数
  - 实现 ReleaseVertexAttributes() 函数
  - 使用简单数组存储顶点属性(初始位置、累积应变、硬度系数、打磨度)

- Task 3: 添加各向异性流动参数
  - 添加 AnisotropyRatio 参数(各向异性比)
  - 添加 bEnableEdgeConstraint 参数(边缘约束开关)
  - 添加 EdgeThreshold 参数(边缘阈值)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-23 22:41:30 +08:00
parent 10e831efb9
commit bfb9be2256
2 changed files with 106 additions and 0 deletions
+72
View File
@@ -116,6 +116,9 @@ void ADynamicIronBlock::Tick(float DeltaTime)
void ADynamicIronBlock::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
// 释放顶点属性层
ReleaseVertexAttributes();
// 释放GPU缓冲区
ReleaseGPUBuffers();
@@ -234,6 +237,9 @@ void ADynamicIronBlock::InitializeBoxMesh()
UE_LOG(LogTemp, Log, TEXT("DynamicIronBlock: Initial vertex colors set based on ambient temperature"));
}
// 初始化顶点属性层
InitializeVertexAttributes();
UE_LOG(LogTemp, Log, TEXT("DynamicIronBlock: Box mesh initialized with size (%f, %f, %f)"),
BoxSize.X, BoxSize.Y, BoxSize.Z);
}
@@ -1295,3 +1301,69 @@ void ADynamicIronBlock::DispatchTemperatureCompute(float DeltaTime)
GroupCount.X, GroupCount.Y, GroupCount.Z);
});
}
// ========== 顶点属性层实现(阶段1) ==========
void ADynamicIronBlock::InitializeVertexAttributes()
{
UDynamicMeshComponent* DynMeshComp = GetDynamicMeshComponent();
if (!DynMeshComp)
{
UE_LOG(LogTemp, Error, TEXT("DynamicIronBlock: Failed to get DynamicMeshComponent for vertex attributes"));
return;
}
UDynamicMesh* DynMesh = DynMeshComp->GetDynamicMesh();
if (!DynMesh)
{
UE_LOG(LogTemp, Error, TEXT("DynamicIronBlock: Failed to get DynamicMesh for vertex attributes"));
return;
}
// 读取网格以访问底层数据
DynMesh->ProcessMesh([&](const FDynamicMesh3& ReadMesh)
{
// 获取顶点数量
int32 VertexCount = ReadMesh.MaxVertexID();
UE_LOG(LogTemp, Log, TEXT("DynamicIronBlock: Initializing vertex attributes for %d vertices"), VertexCount);
// 预分配数组空间
InitialPositionsArray.SetNumZeroed(VertexCount);
AccumulatedStrainArray.SetNumZeroed(VertexCount);
HardnessCoefficientArray.SetNumZeroed(VertexCount);
PolishAmountArray.SetNumZeroed(VertexCount);
// 初始化所有顶点的属性值
for (int32 VertexID : ReadMesh.VertexIndicesItr())
{
FVector3d VertexPos = ReadMesh.GetVertex(VertexID);
// 初始位置 = 当前位置
InitialPositionsArray[VertexID] = FVector3f(VertexPos.X, VertexPos.Y, VertexPos.Z);
// 累积应变 = 0
AccumulatedStrainArray[VertexID] = 0.0f;
// 硬度系数 = 1.0 (未硬化)
HardnessCoefficientArray[VertexID] = 1.0f;
// 打磨度 = 0.2 (轻微生锈)
PolishAmountArray[VertexID] = 0.2f;
}
bVertexAttributesInitialized = true;
});
UE_LOG(LogTemp, Log, TEXT("DynamicIronBlock: Vertex attributes initialized successfully"));
}
void ADynamicIronBlock::ReleaseVertexAttributes()
{
InitialPositionsArray.Empty();
AccumulatedStrainArray.Empty();
HardnessCoefficientArray.Empty();
PolishAmountArray.Empty();
bVertexAttributesInitialized = false;
UE_LOG(LogTemp, Log, TEXT("DynamicIronBlock: Vertex attributes released"));
}
+34
View File
@@ -74,6 +74,18 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Iron Block|Material Properties")
float BulgeStrength = 0.5f;
// 各向异性比(主方向/次方向流动强度比,1.0=均匀,>1.0=方向性)
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Iron Block|Material Properties", meta = (ClampMin = "1.0", ClampMax = "10.0"))
float AnisotropyRatio = 3.0f;
// 是否启用边缘约束
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Iron Block|Material Properties")
bool bEnableEdgeConstraint = false;
// 边缘阈值(cm)- 用于检测边缘顶点
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Iron Block|Material Properties", meta = (ClampMin = "0.1", ClampMax = "5.0"))
float EdgeThreshold = 0.5f;
// ========== 温度系统参数 ==========
// 温度体素大小(毫米)
@@ -278,6 +290,28 @@ private:
*/
void UpdateVertexColors();
// ========== 顶点属性层(阶段1) ==========
// 顶点属性存储 - 使用简单数组存储,避免复杂的模板前向声明
// 这些数组在网格初始化时创建,索引与顶点ID对应
TArray<FVector3f> InitialPositionsArray; // 初始位置(不变,用于无漂移纹理采样)
TArray<float> AccumulatedStrainArray; // 累积塑性应变
TArray<float> HardnessCoefficientArray; // 硬度系数(影响形变阻力)
TArray<float> PolishAmountArray; // 打磨度(0=生锈,1=光亮)
// 标志位:顶点属性是否已初始化
bool bVertexAttributesInitialized = false;
/**
* 初始化顶点属性层
*/
void InitializeVertexAttributes();
/**
* 释放顶点属性层
*/
void ReleaseVertexAttributes();
// ========== GPU计算系统(Phase 2) ==========
// GPU缓冲区(Ping-Pong双缓冲)