/// <summary> /// 调整前后枝干的顶点 /// </summary> private void AdjustBranch() { if (m_PairedBranchIndexes.Count == 1 && m_PairedBranchIndexes[0].PreIndex == null) { AdjustFreshBranch(); return; } /* * 获取前后两个关键帧的枝干对象 * 用于后续获取顶点以及更改顶点 */ GameObject preBranch = m_PairedBranchIndexes[0].PreIndex.Belong; GameObject curBranch = m_PairedBranchIndexes[0].CurIndex.Belong; Vector3[] preVertices = GameObjectOperation.GetVertices(preBranch); Vector3[] vertices = new Vector3[GameObjectOperation.GetVertices(curBranch).Length]; //该顶点数组用于存放修改后的前关键帧顶点 /* * 遍历已经匹配好的Index * 根据PairedIndex中记录的前后Index的数据 * 对前后关键帧中枝干的数据进行修改 */ foreach (PairedIndex <BranchIndex> pairedBranchIndex in m_PairedBranchIndexes) { BranchIndex preBranchIndex = pairedBranchIndex.PreIndex; BranchIndex curBranchIndex = pairedBranchIndex.CurIndex; if (curBranchIndex.IsFirstBranch() && preBranchIndex.IsFirstBranch()) //均为第一个枝干 { CopyVertices(preVertices, preBranchIndex.BottomVerticesIndex, vertices, curBranchIndex.BottomVerticesIndex, 40); } else if (preBranchIndex != null) //若存在匹配的第一个关键帧的枝干索引,则将第一个关键帧枝干索引指向的顶点插入到第二个关键帧枝干索引指向的顶点位置中 { CopyVertices(preVertices, preBranchIndex.TopVerticesIndex, vertices, curBranchIndex.TopVerticesIndex); } else//若第二个关键帧枝干不存在匹配的第一个关键帧枝干索引,则遍历其前驱,直至有存在的第一个关键帧枝干索引,并将该枝干索引指向的顶点插入到第二个关键帧枝干索引指向的顶点位置中 { CopyVertices(vertices, curBranchIndex.Previous.TopVerticesIndex, vertices, curBranchIndex.TopVerticesIndex); } } //更新对象 GameObjectOperation.UpdateMeshInfo(preBranch, vertices, GameObjectOperation.GetUV(curBranch), GameObjectOperation.GetTriangleIndexes(curBranch)); AddPreObject(preBranch); AddCurObject(curBranch); }