Mesh CreateEditedMesh(MeshData data, SplitData split, bool noTopologyUpdate = false, Mesh prev = null) { if (noTopologyUpdate) { if (data.numPoints != prev.vertexCount) { return(null); } } var mesh = noTopologyUpdate ? Instantiate <Mesh>(prev) : new Mesh(); var flags = data.flags; if (flags.hasPoints) { mesh.vertices = split.points; } if (flags.hasNormals) { mesh.normals = split.normals; } if (flags.hasTangents) { mesh.tangents = split.tangents; } if (flags.hasUV) { mesh.uv = split.uv; } if (flags.hasColors) { mesh.colors = split.colors; } if (flags.hasBones) { mesh.boneWeights = split.boneWeights; mesh.bindposes = data.bindposes; } if (!noTopologyUpdate && flags.hasIndices) { if (split.numSubmeshes == 0) { mesh.SetIndices(split.indices, MeshTopology.Triangles, 0); } else { mesh.subMeshCount = split.numSubmeshes; for (int smi = 0; smi < split.numSubmeshes; ++smi) { var submesh = split.GetSubmesh(smi); mesh.SetIndices(submesh.indices, MeshTopology.Triangles, smi); } } } mesh.RecalculateBounds(); mesh.UploadMeshData(false); return(mesh); }
Mesh CreateEditedMesh(MeshData data, SplitData split) { var mesh = new Mesh(); #if UNITY_2017_3_OR_NEWER mesh.indexFormat = UnityEngine.Rendering.IndexFormat.UInt32; #endif var flags = data.flags; if (flags.hasPoints) { tmpV3.Resize(split.numPoints); data.ReadPoints(tmpV3, split); mesh.SetVertices(tmpV3); } if (flags.hasNormals) { tmpV3.Resize(split.numPoints); data.ReadNormals(tmpV3, split); mesh.SetNormals(tmpV3); } if (flags.hasTangents) { tmpV4.Resize(split.numPoints); data.ReadTangents(tmpV4, split); mesh.SetTangents(tmpV4); } if (flags.hasUV0) { tmpV2.Resize(split.numPoints); data.ReadUV0(tmpV2, split); mesh.SetUVs(0, tmpV2); } if (flags.hasUV1) { tmpV2.Resize(split.numPoints); data.ReadUV1(tmpV2, split); mesh.SetUVs(1, tmpV2); } if (flags.hasColors) { tmpC.Resize(split.numPoints); data.ReadColors(tmpC, split); mesh.SetColors(tmpC); } if (flags.hasBones) { var tmpW = new PinnedList <BoneWeight>(); tmpW.Resize(split.numPoints); data.ReadBoneWeights(tmpW, split); mesh.bindposes = data.bindposes; mesh.boneWeights = tmpW; } if (flags.hasIndices) { if (split.numSubmeshes == 0) { tmpI.Resize(split.numIndices); data.ReadIndices(tmpI, split); mesh.SetIndices(tmpI, MeshTopology.Triangles, 0); } else { mesh.subMeshCount = split.numSubmeshes; for (int smi = 0; smi < split.numSubmeshes; ++smi) { var submesh = split.GetSubmesh(smi); mesh.SetIndices(submesh.indices, MeshTopology.Triangles, smi); } } } if (flags.hasBlendshapes) { tmpV3.Resize(split.numPoints); tmpV3a.Resize(split.numPoints); tmpV3b.Resize(split.numPoints); int numBlendShapes = data.numBlendShapes; for (int bi = 0; bi < numBlendShapes; ++bi) { var bsd = data.GetBlendShapeData(bi); var name = bsd.name; var numFrames = bsd.numFrames; for (int fi = 0; fi < numFrames; ++fi) { bsd.ReadPoints(fi, tmpV3, split); bsd.ReadNormals(fi, tmpV3a, split); bsd.ReadTangents(fi, tmpV3b, split); mesh.AddBlendShapeFrame(name, bsd.GetWeight(fi), tmpV3, tmpV3a, tmpV3b); } } } mesh.RecalculateBounds(); mesh.UploadMeshData(false); return(mesh); }