public static MeshSplitter Split(agx.Vec3Vector vertices, agx.UInt32Vector indices, Func <agx.Vec3, Vector3> transformer, int maxNumVertices = Int16.MaxValue) { var splitter = new MeshSplitter(); splitter.m_vertices = new List <Vector3>(vertices.Count); for (int i = 0; i < vertices.Count; ++i) { splitter.m_vertices.Add(transformer(vertices[i])); } for (int i = 0; i < indices.Count; i += 3) { if (i == 0 || splitter.m_subMeshData.Last().NumVertices >= maxNumVertices) { splitter.m_subMeshData.Add(new SubMeshData(maxNumVertices)); } splitter.m_subMeshData.Last().Add(splitter.m_vertices[Convert.ToInt32(indices[i + 0])], splitter.m_vertices[Convert.ToInt32(indices[i + 2])], splitter.m_vertices[Convert.ToInt32(indices[i + 1])]); } foreach (var data in splitter.m_subMeshData) { data.CreateMesh(); } return(splitter); }
public static MeshSplitter Split(agx.Vec3Vector vertices, agx.UInt32Vector indices, agx.Vec2Vector uvs, Func <agx.Vec3, Vector3> vertexTransformer, int maxNumVertices = Int16.MaxValue) { var splitter = new MeshSplitter(); if (vertices.Count < maxNumVertices) { splitter.m_subMeshData.Add(new SubMeshData(uvs != null, vertices.Count)); splitter.m_subMeshData.Last().CreateMesh(vertices, indices, uvs, vertexTransformer); return(splitter); } // This works but isn't correct. It's not possible to recover // the triangles list for a mesh with #vertices < MaxValue. splitter.m_vertices = new List <Vector3>(vertices.Count); for (int i = 0; i < vertices.Count; ++i) { splitter.m_vertices.Add(vertexTransformer(vertices[i])); } var hasUvs = uvs != null && uvs.Count == vertices.Count; for (int i = 0; i < indices.Count; i += 3) { if (i == 0 || splitter.m_subMeshData.Last().NumVertices >= maxNumVertices) { splitter.m_subMeshData.Add(new SubMeshData(hasUvs, maxNumVertices)); } if (hasUvs) { splitter.m_subMeshData.Last().Add(splitter.m_vertices[Convert.ToInt32(indices[i + 0])], splitter.m_vertices[Convert.ToInt32(indices[i + 2])], splitter.m_vertices[Convert.ToInt32(indices[i + 1])], uvs[Convert.ToInt32(indices[i + 0])].ToVector2(), uvs[Convert.ToInt32(indices[i + 2])].ToVector2(), uvs[Convert.ToInt32(indices[i + 1])].ToVector2()); } else { splitter.m_subMeshData.Last().Add(splitter.m_vertices[Convert.ToInt32(indices[i + 0])], splitter.m_vertices[Convert.ToInt32(indices[i + 2])], splitter.m_vertices[Convert.ToInt32(indices[i + 1])]); } } foreach (var data in splitter.m_subMeshData) { data.CreateMesh(); } return(splitter); }