浏览代码

add safety (dry-run with just counts) when rebuilding attachment data + newlines

/main
Lasse Jon Fuglsang Pedersen 5 年前
当前提交
1e853980
共有 3 个文件被更改,包括 82 次插入7 次删除
  1. 1
      Editor/SkinAttachmentTargetEditor.cs
  2. 47
      Runtime/SkinAttachmentDataBuilder.cs
  3. 41
      Runtime/SkinAttachmentTarget.cs

1
Editor/SkinAttachmentTargetEditor.cs


if (driver.attachData == null)
{
EditorGUILayout.HelpBox("Must bind SkinAttachmentData asset before use.", MessageType.Error);
base.OnInspectorGUI();
return;
}

47
Runtime/SkinAttachmentDataBuilder.cs


BuildDataAttachToVertex(attachData, attachmentIndex, attachmentCount, meshInfo, targetPositions, targetOffsets.val, targetNormals, targetVertices.val, targetCount);
}
}
public static unsafe int CountPosesTriangle(in MeshInfo meshInfo, ref Vector3 target, int triangle)
{
SkinAttachmentPose dummyPose;
return BuildPosesTriangle(&dummyPose, meshInfo, ref target, triangle);
}
public static unsafe int CountPosesVertex(in MeshInfo meshInfo, ref Vector3 target, int vertex)
{
int poseCount = 0;
foreach (int triangle in meshInfo.meshAdjacency.vertexTriangles[vertex])
{
poseCount += CountPosesTriangle(meshInfo, ref target, triangle);
}
return poseCount;
}
public static unsafe void CountDataAttachToTriangle(ref int poseCount, ref int itemCount, in MeshInfo meshInfo, Vector3* targetPositions, int* targetTriangles, int targetCount)
{
for (int i = 0; i != targetCount; i++)
{
poseCount += CountPosesTriangle(meshInfo, ref targetPositions[i], targetTriangles[i]);
itemCount += 1;
}
}
public static unsafe void CountDataAttachToVertex(ref int poseCount, ref int itemCount, in MeshInfo meshInfo, Vector3* targetPositions, Vector3* targetOffsets, Vector3* targetNormals, int* targetVertices, int targetCount)
{
for (int i = 0; i != targetCount; i++)
{
poseCount += CountPosesVertex(meshInfo, ref targetPositions[i], targetVertices[i]);
itemCount += 1;
}
}
public static unsafe void CountDataAttachToClosestVertex(ref int poseCount, ref int itemCount, in MeshInfo meshInfo, Vector3* targetPositions, Vector3* targetNormals, int targetCount)
{
using (var targetOffsets = new UnsafeArrayVector3(targetCount))
using (var targetVertices = new UnsafeArrayInt(targetCount))
{
for (int i = 0; i != targetCount; i++)
{
targetVertices.val[i] = meshInfo.meshVertexBSP.FindNearest(ref targetPositions[i]);
}
CountDataAttachToVertex(ref poseCount, ref itemCount, meshInfo, targetPositions, targetOffsets.val, targetNormals, targetVertices.val, targetCount);
}
}
}
}

41
Runtime/SkinAttachmentTarget.cs


{
subjects.RemoveAll(p => (p == null));
// pass 1: build poses
// pass 1: dry run
int dryRunPoseCount = 0;
int dryRunItemCount = 0;
CommitSubject(ref meshInfo, subjects[i]);
CommitSubject(ref meshInfo, subjects[i], dryRun: true, ref dryRunPoseCount, ref dryRunItemCount);
// pass 2: reference poses
dryRunPoseCount = Mathf.NextPowerOfTwo(dryRunPoseCount);
dryRunItemCount = Mathf.NextPowerOfTwo(dryRunItemCount);
ArrayUtils.ResizeCheckedIfLessThan(ref attachData.pose, dryRunPoseCount);
ArrayUtils.ResizeCheckedIfLessThan(ref attachData.item, dryRunItemCount);
// pass 2: build poses
for (int i = 0, n = subjects.Count; i != n; i++)
{
if (subjects[i].attachmentMode == SkinAttachment.AttachmentMode.BuildPoses)
{
CommitSubject(ref meshInfo, subjects[i], dryRun: false, ref dryRunPoseCount, ref dryRunPoseCount);
}
}
// pass 3: reference poses
for (int i = 0, n = subjects.Count; i != n; i++)
{
switch (subjects[i].attachmentMode)

}
}
void CommitSubject(ref MeshInfo meshInfo, SkinAttachment subject)
void CommitSubject(ref MeshInfo meshInfo, SkinAttachment subject, bool dryRun, ref int dryRunPoseCount, ref int dryRunItemCount)
{
Profiler.BeginSample("attach-subj");

fixed (int* attachmentIndex = &subject.attachmentIndex)
fixed (int* attachmentCount = &subject.attachmentCount)
{
BuildDataAttachToClosestVertex(attachData, attachmentIndex, attachmentCount, meshInfo, &targetPosition, &targetNormal, 1);
if (dryRun)
CountDataAttachToClosestVertex(ref dryRunPoseCount, ref dryRunItemCount, meshInfo, &targetPosition, &targetNormal, 1);
else
BuildDataAttachToClosestVertex(attachData, attachmentIndex, attachmentCount, meshInfo, &targetPosition, &targetNormal, 1);
}
}
break;

fixed (int* attachmentIndex = &subject.attachmentIndex)
fixed (int* attachmentCount = &subject.attachmentCount)
{
BuildDataAttachToClosestVertex(attachData, attachmentIndex, attachmentCount, meshInfo, targetPositions.val, targetNormals.val, subjectVertexCount);
if (dryRun)
CountDataAttachToClosestVertex(ref dryRunPoseCount, ref dryRunItemCount, meshInfo, targetPositions.val, targetNormals.val, subjectVertexCount);
else
BuildDataAttachToClosestVertex(attachData, attachmentIndex, attachmentCount, meshInfo, targetPositions.val, targetNormals.val, subjectVertexCount);
}
}
}

fixed (int* attachmentIndex = &subject.attachmentIndex)
fixed (int* attachmentCount = &subject.attachmentCount)
{
BuildDataAttachToVertex(attachData, attachmentIndex, attachmentCount, meshInfo, targetPositions.val, targetOffsets.val, targetNormals.val, targetVertices.val, subjectVertexCount);
if (dryRun)
CountDataAttachToVertex(ref dryRunPoseCount, ref dryRunItemCount, meshInfo, targetPositions.val, targetOffsets.val, targetNormals.val, targetVertices.val, subjectVertexCount);
else
BuildDataAttachToVertex(attachData, attachmentIndex, attachmentCount, meshInfo, targetPositions.val, targetOffsets.val, targetNormals.val, targetVertices.val, subjectVertexCount);
}
}
}

正在加载...
取消
保存