public STGenericObject CreateGenericObject(Node parentNode, Mesh msh, int Index, Matrix4 transform) { STGenericObject obj = new STGenericObject(); obj.BoneIndex = 0; if (msh.MaterialIndex != -1) { obj.MaterialIndex = msh.MaterialIndex; } else { scene.Materials.Add(new Material() { Name = msh.Name }); } if (scene.Materials[msh.MaterialIndex].Name == "") { scene.Materials[msh.MaterialIndex].Name = msh.Name; } obj.HasPos = msh.HasVertices; obj.HasNrm = msh.HasNormals; obj.HasUv0 = msh.HasTextureCoords(0); obj.HasUv1 = msh.HasTextureCoords(1); obj.HasUv2 = msh.HasTextureCoords(2); obj.HasIndices = msh.HasBones; if (msh.HasBones && msh.BoneCount > 1) { obj.HasWeights = msh.Bones[0].HasVertexWeights; } obj.HasTans = msh.HasTangentBasis; obj.HasBitans = msh.HasTangentBasis; obj.HasVertColors = msh.HasVertexColors(0); obj.HasVertColors2 = msh.HasVertexColors(1); obj.ObjectName = msh.Name; if (parentNode != null && msh.Name == string.Empty) { obj.ObjectName = parentNode.Name; } obj.boneList = GetBoneList(msh); obj.VertexSkinCount = (byte)GetVertexSkinCount(msh); STGenericObject.LOD_Mesh lod = new STGenericObject.LOD_Mesh(); lod.faces = GetFaces(msh); lod.IndexFormat = STIndexFormat.UInt16; lod.PrimativeType = STPrimitiveType.Triangles; lod.GenerateSubMesh(); obj.lodMeshes.Add(lod); obj.vertices = GetVertices(msh, transform, obj); obj.VertexBufferIndex = Index; return(obj); }
public STGenericObject CreateGenericObject(SELib.SEModel seModel, SELib.SEModelMesh seMesh) { int Index = seModel.Meshes.IndexOf(seMesh); STGenericObject mesh = new STGenericObject(); mesh.ObjectName = $"Mesh_{Index}"; if (seMesh.MaterialReferenceIndicies.Count > 0) { mesh.MaterialIndex = seMesh.MaterialReferenceIndicies[0]; } mesh.HasPos = true; for (int v = 0; v < seMesh.VertexCount; v++) { if (seMesh.Verticies[v].UVSets.Count > 0) { mesh.HasUv0 = true; } if (seMesh.Verticies[v].Weights.Count > 0) { mesh.HasIndices = true; for (int w = 0; w < seMesh.Verticies[v].WeightCount; w++) { if (seMesh.Verticies[v].Weights[w].BoneWeight != 0) { mesh.HasWeights = true; } } } if (seMesh.Verticies[v].VertexColor != SELib.Utilities.Color.White) { mesh.HasVertColors = true; } if (seMesh.Verticies[v].VertexNormal != SELib.Utilities.Vector3.Zero) { mesh.HasNrm = true; } Vertex vertex = new Vertex(); mesh.vertices.Add(vertex); vertex.pos = ToTKVector3(seMesh.Verticies[v].Position); vertex.nrm = ToTKVector3(seMesh.Verticies[v].VertexNormal); vertex.col = ToTKVector4(seMesh.Verticies[v].VertexColor); for (int u = 0; u < seMesh.Verticies[v].UVSetCount; u++) { if (u == 0) { vertex.uv0 = ToTKVector2(seMesh.Verticies[v].UVSets[u]); } if (u == 1) { vertex.uv1 = ToTKVector2(seMesh.Verticies[v].UVSets[u]); } if (u == 2) { vertex.uv2 = ToTKVector2(seMesh.Verticies[v].UVSets[u]); } } for (int w = 0; w < seMesh.Verticies[v].WeightCount; w++) { //Get the bone name from the index. Indices for formats get set after the importer string BoneName = seModel.Bones[(int)seMesh.Verticies[v].Weights[w].BoneIndex].BoneName; float BoneWeight = seMesh.Verticies[v].Weights[w].BoneWeight; vertex.boneNames.Add(BoneName); vertex.boneWeights.Add(BoneWeight); } } mesh.lodMeshes = new List <STGenericObject.LOD_Mesh>(); var lodMesh = new STGenericObject.LOD_Mesh(); lodMesh.PrimativeType = STPrimitiveType.Triangles; mesh.lodMeshes.Add(lodMesh); for (int f = 0; f < seMesh.FaceCount; f++) { lodMesh.faces.Add((int)seMesh.Faces[f].FaceIndex1); lodMesh.faces.Add((int)seMesh.Faces[f].FaceIndex2); lodMesh.faces.Add((int)seMesh.Faces[f].FaceIndex3); } return(mesh); }