public static MeshGeometry AssimpToLdd(Scene scene, Mesh mesh) { bool hasUVs = mesh.HasTextureCoords(0); var builder = new GeometryBuilder(); var meshNode = Assimp.AssimpHelper.GetMeshNode(scene, mesh); var meshTransform = Assimp.AssimpHelper.GetFinalTransform(meshNode).ToLDD(); for (int i = 0; i < mesh.VertexCount; i++) { builder.AddVertex(new Vertex() { Position = meshTransform.TransformPosition(mesh.Vertices[i].ToLDD()), Normal = meshTransform.TransformNormal(mesh.Normals[i].ToLDD()), TexCoord = hasUVs ? mesh.TextureCoordinateChannels[0][i].ToLDD().Xy : Simple3D.Vector2.Empty }, false); } for (int i = 0; i < mesh.FaceCount; i++) { if (mesh.Faces[i].IndexCount != 3) { continue; } builder.AddTriangle(mesh.Faces[i].Indices[0], mesh.Faces[i].Indices[1], mesh.Faces[i].Indices[2]); } var geometry = builder.GetGeometry(); geometry.SimplifyVertices(); return(geometry); }
public static MeshGeometry AssimpToLdd(Scene scene, Mesh mesh) { bool hasUVs = mesh.HasTextureCoords(0); var builder = new GeometryBuilder(); var meshNode = Assimp.AssimpHelper.GetMeshNode(scene, mesh); var meshTransform = Assimp.AssimpHelper.GetFinalTransform(meshNode).ToLDD(); for (int i = 0; i < mesh.VertexCount; i++) { builder.AddVertex(new Vertex() { Position = meshTransform.TransformPosition(mesh.Vertices[i].ToLDD()), Normal = meshTransform.TransformNormal(mesh.Normals[i].ToLDD()), TexCoord = hasUVs ? mesh.TextureCoordinateChannels[0][i].ToLDD().Xy : Simple3D.Vector2.Empty }, false); } for (int i = 0; i < mesh.FaceCount; i++) { if (mesh.Faces[i].IndexCount != 3) { continue; } builder.AddTriangle(mesh.Faces[i].Indices[0], mesh.Faces[i].Indices[1], mesh.Faces[i].Indices[2]); } if (mesh.HasBones) { var boneNames = scene.Meshes.SelectMany(x => x.Bones).Select(x => x.Name).Distinct().ToList(); var boneNodes = Assimp.AssimpHelper.GetNodeHierarchy(scene.RootNode) .Where(x => boneNames.Contains(x.Name)) /*.OrderBy(x => x.GetLevel())*/.ToList(); boneNames = boneNodes.Select(x => x.Name).ToList();//names in order for (int i = 0; i < mesh.BoneCount; i++) { int boneIndex = boneNames.IndexOf(mesh.Bones[i].Name); foreach (var vw in mesh.Bones[i].VertexWeights) { builder.Vertices[vw.VertexID].BoneWeights.Add(new BoneWeight(boneIndex, vw.Weight)); } } } var geometry = builder.GetGeometry(); geometry.SimplifyVertices(); return(geometry); }
internal override void FillCullingInformation(MeshCulling culling) { base.FillCullingInformation(culling); if (ReplacementMeshes.Any()) { var builder = new GeometryBuilder(); foreach (var meshRef in ReplacementMeshes) { builder.CombineGeometry(meshRef.GetGeometry(true)); } if (Surface.SurfaceID == 0) { builder.RemoveTextureCoords(); } culling.ReplacementMesh = builder.GetGeometry(); } }