Example #1
0
        public bool AddSVI(xxFrame meshFrame, int submeshIdx, bool positions, bool bones, bool normals, bool uvs)
        {
            sviParser svi = FindSVI(meshFrame.Name, submeshIdx);
            if (svi != null)
            {
                return false;
            }

            svi = new sviParser();
            svi.meshName = meshFrame.Name;
            svi.submeshIdx = submeshIdx;
            svi.indices = new ushort[meshFrame.Mesh.SubmeshList[submeshIdx].VertexList.Count];
            for (ushort i = 0; i < svi.indices.Length; i++)
            {
                svi.indices[i] = i;
            }
            if (positions)
            {
                svi.positionsPresent = 1;
                svi.positions = new Vector3[svi.indices.Length];
                List<xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.positions.Length; i++)
                {
                    svi.positions[i] = verts[i].Position;
                }
            }
            if (bones)
            {
                svi.bonesPresent = 1;
                svi.boneWeights3 = new float[svi.indices.Length][];
                svi.boneIndices = new byte[svi.indices.Length][];
                List<xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.boneWeights3.Length; i++)
                {
                    svi.boneWeights3[i] = (float[])verts[i].Weights3.Clone();
                    svi.boneIndices[i] = (byte[])verts[i].BoneIndices.Clone();
                }
                svi.bones = new sviParser.sviBone[meshFrame.Mesh.BoneList.Count];
                for (ushort i = 0; i < svi.bones.Length; i++)
                {
                    sviParser.sviBone bone = new sviParser.sviBone();
                    bone.name = (string)meshFrame.Mesh.BoneList[i].Name.Clone();
                    bone.boneIdx = meshFrame.Mesh.BoneList[i].Index;
                    bone.matrix = meshFrame.Mesh.BoneList[i].Matrix;
                    svi.bones[i] = bone;
                }
            }
            if (normals)
            {
                svi.normalsPresent = 1;
                svi.normals = new Vector3[svi.indices.Length];
                List<xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.normals.Length; i++)
                {
                    svi.normals[i] = verts[i].Normal;
                }
            }
            if (uvs)
            {
                svi.uvsPresent = 1;
                svi.uvs = new Vector2[svi.indices.Length];
                List<xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.uvs.Length; i++)
                {
                    svi.uvs[i].X = verts[i].UV[0];
                    svi.uvs[i].Y = verts[i].UV[1];
                }
            }
            Parser.sections.Add(svi);
            return true;
        }
Example #2
0
        public bool AddSVI(xxFrame meshFrame, int submeshIdx, bool positions, bool bones, bool normals, bool uvs)
        {
            sviParser svi = FindSVI(meshFrame.Name, submeshIdx);

            if (svi != null)
            {
                return(false);
            }

            svi            = new sviParser();
            svi.meshName   = meshFrame.Name;
            svi.submeshIdx = submeshIdx;
            svi.indices    = new ushort[meshFrame.Mesh.SubmeshList[submeshIdx].VertexList.Count];
            for (ushort i = 0; i < svi.indices.Length; i++)
            {
                svi.indices[i] = i;
            }
            if (positions)
            {
                svi.positionsPresent = 1;
                svi.positions        = new Vector3[svi.indices.Length];
                List <xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.positions.Length; i++)
                {
                    svi.positions[i] = verts[i].Position;
                }
            }
            if (bones)
            {
                svi.bonesPresent = 1;
                svi.boneWeights3 = new float[svi.indices.Length][];
                svi.boneIndices  = new byte[svi.indices.Length][];
                List <xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.boneWeights3.Length; i++)
                {
                    svi.boneWeights3[i] = (float[])verts[i].Weights3.Clone();
                    svi.boneIndices[i]  = (byte[])verts[i].BoneIndices.Clone();
                }
                svi.bones = new sviParser.sviBone[meshFrame.Mesh.BoneList.Count];
                for (ushort i = 0; i < svi.bones.Length; i++)
                {
                    sviParser.sviBone bone = new sviParser.sviBone();
                    bone.name    = (string)meshFrame.Mesh.BoneList[i].Name.Clone();
                    bone.boneIdx = meshFrame.Mesh.BoneList[i].Index;
                    bone.matrix  = meshFrame.Mesh.BoneList[i].Matrix;
                    svi.bones[i] = bone;
                }
            }
            if (normals)
            {
                svi.normalsPresent = 1;
                svi.normals        = new Vector3[svi.indices.Length];
                List <xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.normals.Length; i++)
                {
                    svi.normals[i] = verts[i].Normal;
                }
            }
            if (uvs)
            {
                svi.uvsPresent = 1;
                svi.uvs        = new Vector2[svi.indices.Length];
                List <xxVertex> verts = meshFrame.Mesh.SubmeshList[submeshIdx].VertexList;
                for (int i = 0; i < svi.uvs.Length; i++)
                {
                    svi.uvs[i].X = verts[i].UV[0];
                    svi.uvs[i].Y = verts[i].UV[1];
                }
            }
            Parser.sections.Add(svi);
            return(true);
        }
Example #3
0
        public bool CopyIntoSVI(xxFrame meshFrame, int submeshIdx, bool positions, bool bones, bool normals, bool uvs, bool unrestricted, bool nearestBones, bool nearestNormals, bool nearestUVs)
        {
            bool argPositions = positions, argBones = bones, argNormals = normals, argUVs = uvs;
            foreach (sviParser submeshSection in Parser.sections)
            {
                if (submeshSection.meshName == meshFrame.Name && submeshSection.submeshIdx == submeshIdx)
                {
                    xxSubmesh submesh = meshFrame.Mesh.SubmeshList[submeshIdx];
                    int[] nearestVertexIndices = null;
                    if (nearestBones || nearestNormals || nearestUVs)
                    {
                        if (submeshSection.positionsPresent == 1)
                        {
                            nearestVertexIndices = new int[submesh.VertexList.Count];
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                int bestIdx = -1;
                                double nearestDist = Double.MaxValue;
                                for (ushort j = 0; j < submeshSection.positions.Length; j++)
                                {
                                    double distSquare = (submeshSection.positions[j].X - submesh.VertexList[i].Position.X) * (submeshSection.positions[j].X - submesh.VertexList[i].Position.X)
                                        + (submeshSection.positions[j].Y - submesh.VertexList[i].Position.Y) * (submeshSection.positions[j].Y - submesh.VertexList[i].Position.Y)
                                        + (submeshSection.positions[j].Z - submesh.VertexList[i].Position.Z) * (submeshSection.positions[j].Z - submesh.VertexList[i].Position.Z);
                                    if (distSquare < nearestDist)
                                    {
                                        bestIdx = j;
                                        nearestDist = distSquare;
                                    }
                                }
                                nearestVertexIndices[i] = bestIdx;
                            }
                        }
                        else
                        {
                            Report.ReportLog(meshFrame.Name + "[" + submeshIdx + "] has no positions in " + Parser.Name + ".");
                            return false;
                        }
                    }
                    Vector3[] newNormals = submeshSection.normals;
                    Vector2[] newUVs = submeshSection.uvs;
                    byte[][] newBoneIndices = submeshSection.boneIndices;
                    float[][] newBoneWeights3 = submeshSection.boneWeights3;
                    if (submeshSection.indices.Length != submesh.VertexList.Count)
                    {
                        if (unrestricted)
                        {
                            submeshSection.indices = new ushort[submesh.VertexList.Count];
                            for (ushort i = 0; i < submeshSection.indices.Length; i++)
                            {
                                submeshSection.indices[i] = i;
                            }
                            if (submeshSection.positionsPresent == 1)
                            {
                                submeshSection.positions = new Vector3[submesh.VertexList.Count];
                            }
                            if (submeshSection.bonesPresent == 1)
                            {
                                newBoneWeights3 = new float[submesh.VertexList.Count][];
                                newBoneIndices = new byte[submesh.VertexList.Count][];
                            }
                            if (submeshSection.normalsPresent == 1)
                            {
                                newNormals = new Vector3[submesh.VertexList.Count];
                            }
                            if (submeshSection.uvsPresent == 1)
                            {
                                newUVs = new Vector2[submesh.VertexList.Count];
                            }

                            positions = bones = normals = uvs = true;
                        }
                        else
                        {
                            Report.ReportLog(meshFrame.Name + "[" + submeshIdx + "] has a different number of vertices than defined in the sviex(" + submesh.VertexList.Count + "/" + submeshSection.indices.Length + ").");
                            return false;
                        }
                    }
                    if (positions && submeshSection.positionsPresent == 1)
                    {
                        for (ushort i = 0; i < submeshSection.positions.Length; i++)
                        {
                            submeshSection.positions[i] = submesh.VertexList[submeshSection.indices[i]].Position;
                        }
                    }
                    if (bones && submeshSection.bonesPresent == 1)
                    {
                        if (nearestBones)
                        {
                            for (ushort i = 0; i < newBoneWeights3.Length; i++)
                            {
                                newBoneWeights3[i] = (float[])submeshSection.boneWeights3[nearestVertexIndices[submeshSection.indices[i]]].Clone();
                                newBoneIndices[i] = (byte[])submeshSection.boneIndices[nearestVertexIndices[submeshSection.indices[i]]].Clone();
                            }
                        }
                        else
                        {
                            for (ushort i = 0; i < newBoneWeights3.Length; i++)
                            {
                                newBoneWeights3[i] = (float[])submesh.VertexList[submeshSection.indices[i]].Weights3.Clone();
                                newBoneIndices[i] = (byte[])submesh.VertexList[submeshSection.indices[i]].BoneIndices.Clone();
                            }

                            submeshSection.bones = new sviParser.sviBone[meshFrame.Mesh.BoneList.Count];
                            for (ushort i = 0; i < submeshSection.bones.Length; i++)
                            {
                                sviParser.sviBone bone = new sviParser.sviBone();
                                bone.name = (string)meshFrame.Mesh.BoneList[i].Name.Clone();
                                bone.boneIdx = meshFrame.Mesh.BoneList[i].Index;
                                bone.matrix = meshFrame.Mesh.BoneList[i].Matrix;
                                submeshSection.bones[i] = bone;
                            }
                        }
                        submeshSection.boneWeights3 = newBoneWeights3;
                        submeshSection.boneIndices = newBoneIndices;
                    }
                    if (normals && submeshSection.normalsPresent == 1)
                    {
                        if (nearestNormals)
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                newNormals[i] = submeshSection.normals[nearestVertexIndices[submeshSection.indices[i]]];
                            }
                        }
                        else
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                newNormals[i] = submesh.VertexList[submeshSection.indices[i]].Normal;
                            }
                        }
                        submeshSection.normals = newNormals;
                    }
                    if (uvs && submeshSection.uvsPresent == 1)
                    {
                        if (nearestUVs)
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                newUVs[i] = submeshSection.uvs[nearestVertexIndices[submeshSection.indices[i]]];
                            }
                        }
                        else
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                float[] uv = submesh.VertexList[submeshSection.indices[i]].UV;
                                newUVs[i] = new Vector2(uv[0], uv[1]);
                            }
                        }
                        submeshSection.uvs = newUVs;
                    }
                    return true;
                }
            }
            return false;
        }
Example #4
0
        public bool CopyIntoSVI(xxFrame meshFrame, int submeshIdx, bool positions, bool bones, bool normals, bool uvs, bool unrestricted, bool nearestBones, bool nearestNormals, bool nearestUVs)
        {
            bool argPositions = positions, argBones = bones, argNormals = normals, argUVs = uvs;

            foreach (sviParser submeshSection in Parser.sections)
            {
                if (submeshSection.meshName == meshFrame.Name && submeshSection.submeshIdx == submeshIdx)
                {
                    xxSubmesh submesh = meshFrame.Mesh.SubmeshList[submeshIdx];
                    int[]     nearestVertexIndices = null;
                    if (nearestBones || nearestNormals || nearestUVs)
                    {
                        if (submeshSection.positionsPresent == 1)
                        {
                            nearestVertexIndices = new int[submesh.VertexList.Count];
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                int    bestIdx     = -1;
                                double nearestDist = Double.MaxValue;
                                for (ushort j = 0; j < submeshSection.positions.Length; j++)
                                {
                                    double distSquare = (submeshSection.positions[j].X - submesh.VertexList[i].Position.X) * (submeshSection.positions[j].X - submesh.VertexList[i].Position.X)
                                                        + (submeshSection.positions[j].Y - submesh.VertexList[i].Position.Y) * (submeshSection.positions[j].Y - submesh.VertexList[i].Position.Y)
                                                        + (submeshSection.positions[j].Z - submesh.VertexList[i].Position.Z) * (submeshSection.positions[j].Z - submesh.VertexList[i].Position.Z);
                                    if (distSquare < nearestDist)
                                    {
                                        bestIdx     = j;
                                        nearestDist = distSquare;
                                    }
                                }
                                nearestVertexIndices[i] = bestIdx;
                            }
                        }
                        else
                        {
                            Report.ReportLog(meshFrame.Name + "[" + submeshIdx + "] has no positions in " + Parser.Name + ".");
                            return(false);
                        }
                    }
                    Vector3[] newNormals      = submeshSection.normals;
                    Vector2[] newUVs          = submeshSection.uvs;
                    byte[][]  newBoneIndices  = submeshSection.boneIndices;
                    float[][] newBoneWeights3 = submeshSection.boneWeights3;
                    if (submeshSection.indices.Length != submesh.VertexList.Count)
                    {
                        if (unrestricted)
                        {
                            submeshSection.indices = new ushort[submesh.VertexList.Count];
                            for (ushort i = 0; i < submeshSection.indices.Length; i++)
                            {
                                submeshSection.indices[i] = i;
                            }
                            if (submeshSection.positionsPresent == 1)
                            {
                                submeshSection.positions = new Vector3[submesh.VertexList.Count];
                            }
                            if (submeshSection.bonesPresent == 1)
                            {
                                newBoneWeights3 = new float[submesh.VertexList.Count][];
                                newBoneIndices  = new byte[submesh.VertexList.Count][];
                            }
                            if (submeshSection.normalsPresent == 1)
                            {
                                newNormals = new Vector3[submesh.VertexList.Count];
                            }
                            if (submeshSection.uvsPresent == 1)
                            {
                                newUVs = new Vector2[submesh.VertexList.Count];
                            }

                            positions = bones = normals = uvs = true;
                        }
                        else
                        {
                            Report.ReportLog(meshFrame.Name + "[" + submeshIdx + "] has a different number of vertices than defined in the sviex(" + submesh.VertexList.Count + "/" + submeshSection.indices.Length + ").");
                            return(false);
                        }
                    }
                    if (positions && submeshSection.positionsPresent == 1)
                    {
                        for (ushort i = 0; i < submeshSection.positions.Length; i++)
                        {
                            submeshSection.positions[i] = submesh.VertexList[submeshSection.indices[i]].Position;
                        }
                    }
                    if (bones && submeshSection.bonesPresent == 1)
                    {
                        if (nearestBones)
                        {
                            for (ushort i = 0; i < newBoneWeights3.Length; i++)
                            {
                                newBoneWeights3[i] = (float[])submeshSection.boneWeights3[nearestVertexIndices[submeshSection.indices[i]]].Clone();
                                newBoneIndices[i]  = (byte[])submeshSection.boneIndices[nearestVertexIndices[submeshSection.indices[i]]].Clone();
                            }
                        }
                        else
                        {
                            for (ushort i = 0; i < newBoneWeights3.Length; i++)
                            {
                                newBoneWeights3[i] = (float[])submesh.VertexList[submeshSection.indices[i]].Weights3.Clone();
                                newBoneIndices[i]  = (byte[])submesh.VertexList[submeshSection.indices[i]].BoneIndices.Clone();
                            }

                            submeshSection.bones = new sviParser.sviBone[meshFrame.Mesh.BoneList.Count];
                            for (ushort i = 0; i < submeshSection.bones.Length; i++)
                            {
                                sviParser.sviBone bone = new sviParser.sviBone();
                                bone.name               = (string)meshFrame.Mesh.BoneList[i].Name.Clone();
                                bone.boneIdx            = meshFrame.Mesh.BoneList[i].Index;
                                bone.matrix             = meshFrame.Mesh.BoneList[i].Matrix;
                                submeshSection.bones[i] = bone;
                            }
                        }
                        submeshSection.boneWeights3 = newBoneWeights3;
                        submeshSection.boneIndices  = newBoneIndices;
                    }
                    if (normals && submeshSection.normalsPresent == 1)
                    {
                        if (nearestNormals)
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                newNormals[i] = submeshSection.normals[nearestVertexIndices[submeshSection.indices[i]]];
                            }
                        }
                        else
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                newNormals[i] = submesh.VertexList[submeshSection.indices[i]].Normal;
                            }
                        }
                        submeshSection.normals = newNormals;
                    }
                    if (uvs && submeshSection.uvsPresent == 1)
                    {
                        if (nearestUVs)
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                newUVs[i] = submeshSection.uvs[nearestVertexIndices[submeshSection.indices[i]]];
                            }
                        }
                        else
                        {
                            for (ushort i = 0; i < submesh.VertexList.Count; i++)
                            {
                                float[] uv = submesh.VertexList[submeshSection.indices[i]].UV;
                                newUVs[i] = new Vector2(uv[0], uv[1]);
                            }
                        }
                        submeshSection.uvs = newUVs;
                    }
                    return(true);
                }
            }
            return(false);
        }