Exemple #1
0
        public void ReplaceTexture(int idx, ImportedTexture image)
        {
            String texh_folder = rem.TexturePathFromREM(Parser.RemPath);

            if (texh_folder == null)
            {
                Report.ReportLog("TEXH folder could not be located.");
                return;
            }

            var oldImg = image.Name;

            image.Name = Path.GetFileNameWithoutExtension(Textures[idx]) + Path.GetExtension(image.Name);
            rem.CreateTexture(image, texh_folder);

            remId newTex = new remId(image.Name);

            foreach (remMaterial mat in Parser.MATC)
            {
                if (mat.texture == Textures[idx])
                {
                    mat.texture = newTex;
                }
            }

            Textures.RemoveAt(idx);
            Textures.Insert(idx, image.Name);

            image.Name = oldImg;
        }
Exemple #2
0
            public Mesh(remMesh mesh, remSkin skin)
            {
                name = mesh.name;
                InitChildren(mesh.numMats);

                for (int i = 0; i < mesh.numMats; i++)
                {
                    Submesh submesh = new Submesh(mesh, skin, i);
                    AddChild(submesh);
                }
            }
Exemple #3
0
        public void SetMeshName(int idx, string name)
        {
            remId   newName = new remId(name);
            remMesh mesh    = Parser.MESC[idx];
            remSkin skin    = rem.FindSkin(mesh.name, Parser.SKIC);

            if (skin != null)
            {
                skin.mesh = newName;
            }
            Parser.MESC[idx].name = newName;
        }
Exemple #4
0
        public static remMaterial FindMaterial(remId materialId, remMATCsection mats)
        {
            foreach (remMaterial mat in mats)
            {
                if (mat.name == materialId)
                {
                    return(mat);
                }
            }

            return(null);
        }
Exemple #5
0
        public static remMaterial FindMaterial(remMATCsection mats, remId textureId)
        {
            foreach (remMaterial mat in mats)
            {
                if (mat.texture == textureId)
                {
                    return(mat);
                }
            }

            return(null);
        }
Exemple #6
0
        public static reaAnimationTrack FindTrack(remId trackName, reaParser parser)
        {
            foreach (reaAnimationTrack track in parser.ANIC)
            {
                if (track.boneFrame == trackName)
                {
                    return(track);
                }
            }

            return(null);
        }
Exemple #7
0
        public static remMesh FindMesh(remId meshName, remMESCsection meshSection)
        {
            foreach (remMesh mesh in meshSection)
            {
                if (mesh.name == meshName)
                {
                    return(mesh);
                }
            }

            return(null);
        }
Exemple #8
0
        public static remSkin FindSkin(remId meshId, remSKICsection skins)
        {
            foreach (remSkin skin in skins)
            {
                if (skin.mesh == meshId)
                {
                    return(skin);
                }
            }

            return(null);
        }
Exemple #9
0
        public static remBoneWeights FindBoneWeights(remSkin skin, remId boneFrame)
        {
            for (int i = 0; i < skin.Count; i++)
            {
                remBoneWeights boneWeights = skin[i];
                if (boneWeights.bone == boneFrame)
                {
                    return(boneWeights);
                }
            }

            return(null);
        }
Exemple #10
0
        public void SetBoneFrame(int meshIdx, int boneIdx, string frame)
        {
            remId   newBoneFrameId = new remId(frame);
            remBone boneFrame      = rem.FindFrame(newBoneFrameId, Parser.BONC.rootFrame);

            if (boneFrame == null)
            {
                throw new FormatException("Frame not found");
            }

            remSkin        skin        = rem.FindSkin(Parser.MESC[meshIdx].name, Parser.SKIC);
            remBoneWeights boneWeights = skin[boneIdx];

            boneWeights.bone = boneFrame.name;
        }
Exemple #11
0
        public void SetFrameName(int idx, string name)
        {
            remId newName = new remId(name);

            foreach (remMesh mesh in Parser.MESC)
            {
                if (mesh.frame == Parser.BONC[idx].name)
                {
                    mesh.frame = newName;
                    break;
                }
            }

            Parser.BONC[idx].name = newName;
        }
Exemple #12
0
        private static void AddParentBone(remBONCsection sec, remBone parent, List <remId> childNames)
        {
            for (int i = 0; i < childNames.Count; i++)
            {
                remId child = childNames[i];
                for (int j = 0; j < sec.Count; j++)
                {
                    if (sec[j].name == child)
                    {
                        parent.AddChild(sec[j]);
                        break;
                    }
                }
            }

            sec.ChildList.Add(parent);
        }
Exemple #13
0
        public void SetBoneSRT(string boneFrame, double sX, double sY, double sZ, double rX, double rY, double rZ, double tX, double tY, double tZ)
        {
            remId  boneFrameId = new remId(boneFrame);
            Matrix m           = FbxUtility.SRTToMatrix(new Vector3((float)sX, (float)sY, (float)sZ), new Vector3((float)rX, (float)rY, (float)rZ), new Vector3((float)tX, (float)tY, (float)tZ));

            foreach (remSkin skin in Parser.SKIC)
            {
                foreach (remBoneWeights boneWeights in skin)
                {
                    if (boneWeights.bone == boneFrameId)
                    {
                        boneWeights.matrix = m;
                        break;
                    }
                }
            }
        }
Exemple #14
0
        public void SetMaterialName(int idx, string name)
        {
            remId newName = new remId(name);

            foreach (remMesh mesh in Parser.MESC)
            {
                for (int i = 0; i < mesh.materials.Count; i++)
                {
                    if (mesh.materials[i] == Parser.MATC[idx].name)
                    {
                        mesh.materials[i] = newName;
                    }
                }
            }

            Parser.MATC[idx].name = newName;
        }
Exemple #15
0
        public static remBone FindFrame(remId frameId, remBone frame)
        {
            if (frame.name == frameId)
            {
                return(frame);
            }

            for (int i = 0; i < frame.Count; i++)
            {
                remBone foundFrame = FindFrame(frameId, frame[i]);
                if (foundFrame != null)
                {
                    return(foundFrame);
                }
            }

            return(null);
        }
Exemple #16
0
        public void RemoveMaterial(int idx)
        {
            remMaterial mat = Parser.MATC[idx];

            for (int i = 0; i < Parser.MESC.Count; i++)
            {
                remMesh mesh = Parser.MESC[i];
                for (int j = 0; j < mesh.numMats; j++)
                {
                    remId matId = mesh.materials[j];
                    if (matId == mat.name)
                    {
                        mesh.materials[j] = null;
                    }
                }
            }

            Parser.MATC.RemoveChild(idx);
        }
Exemple #17
0
        public void SetBoneMatrix(string boneFrame,
                                  double m11, double m12, double m13, double m14,
                                  double m21, double m22, double m23, double m24,
                                  double m31, double m32, double m33, double m34,
                                  double m41, double m42, double m43, double m44)
        {
            remId  boneFrameId = new remId(boneFrame);
            Matrix m           = new Matrix();

            m.M11 = (float)m11;
            m.M12 = (float)m12;
            m.M13 = (float)m13;
            m.M14 = (float)m14;

            m.M21 = (float)m21;
            m.M22 = (float)m22;
            m.M23 = (float)m23;
            m.M24 = (float)m24;

            m.M31 = (float)m31;
            m.M32 = (float)m32;
            m.M33 = (float)m33;
            m.M34 = (float)m34;

            m.M41 = (float)m41;
            m.M42 = (float)m42;
            m.M43 = (float)m43;
            m.M44 = (float)m44;

            foreach (remSkin skin in Parser.SKIC)
            {
                foreach (remBoneWeights boneWeights in skin)
                {
                    if (boneWeights.bone == boneFrameId)
                    {
                        boneWeights.matrix = m;
                        break;
                    }
                }
            }
        }
Exemple #18
0
        public int CompareTo(object obj)
        {
            if (!(obj is remId))
            {
                return(-1);
            }

            remId arg = (remId)obj;

            if (arg.buffer == null || buffer == null || buffer.Length != arg.buffer.Length)
            {
                return(-1);
            }
            for (int i = 0; i < buffer.Length; i++)
            {
                int diff = buffer[i] - arg.buffer[i];
                if (diff != 0)
                {
                    return(diff);
                }
            }
            return(0);
        }
Exemple #19
0
        public static void ReplaceMesh(remBone frame, remParser parser, WorkspaceMesh mesh, List <ImportedMaterial> materials, List <ImportedTexture> textures, bool merge, CopyMeshMethod normalsMethod, CopyMeshMethod bonesMethod, bool meshFrameCorrection)
        {
            remMesh frameREMMesh = rem.FindMesh(frame, parser.MESC);

            int startPos = 0;

            if (meshFrameCorrection)
            {
                // frame.matrix = Matrix.Scaling(-1f, 1f, 1f) * Matrix.RotationYawPitchRoll(0f, (float)(Math.PI / 2), (float)Math.PI);
                frame.matrix     = Matrix.Identity;
                frame.matrix.M22 = frame.matrix.M33 = 0f;
                frame.matrix.M23 = frame.matrix.M32 = 1f;
                startPos         = mesh.Name.IndexOf("(Scale");
                if (startPos > 0)
                {
                    int   endPos = mesh.Name.IndexOf(')');
                    float scale;
                    if (Single.TryParse(mesh.Name.Substring(startPos + 7, endPos - startPos - 7), out scale))
                    {
                        frame.matrix *= Matrix.Scaling(new Vector3(scale));
                    }
                    remId newFrameName = new remId(mesh.Name.Substring(0, startPos));
                    if (newFrameName != frame.name)
                    {
                        if (rem.FindFrame(newFrameName, parser.BONC.rootFrame) == null)
                        {
                            frame.name = newFrameName;
                        }
                        else
                        {
                            Report.ReportLog("Warning! Cant rename frame (and mesh) " + mesh.Name + " automatically to " + newFrameName + ".");
                        }
                    }
                }
            }

            Matrix  transform      = Matrix.Scaling(-1f, 1f, 1f);
            remBone transformFrame = frame;

            while (transformFrame != parser.BONC.rootFrame)
            {
                transform     *= transformFrame.matrix;
                transformFrame = transformFrame.Parent as remBone;
            }
            transform.Invert();

            string[] materialNames;
            int[]    indices;
            bool[]   worldCoords;
            bool[]   replaceSubmeshesOption;
            remMesh  newREMMesh = CreateMesh(mesh, out materialNames, out indices, out worldCoords, out replaceSubmeshesOption);

            if (startPos > 0)
            {
                newREMMesh.name = frame.name;
            }
            Mesh newMesh = new Mesh(newREMMesh, CreateBoneList(mesh, transform));

            remSkin frameMeshSkin = null;
            Mesh    frameMesh     = null;

            if (frameREMMesh != null)
            {
                newMesh.name  = frameREMMesh.name;
                frameMeshSkin = rem.FindSkin(frameREMMesh.name, parser.SKIC);
                frameMesh     = new Mesh(frameREMMesh, frameMeshSkin);
            }

            Submesh[]      replaceSubmeshes = frameMesh != null ? new Submesh[frameMesh.Count] : null;
            List <Submesh> addSubmeshes     = new List <Submesh>(newMesh.Count);

            for (int i = 0; i < newMesh.Count; i++)
            {
                remMaterial mat = rem.FindMaterial(new remId(materialNames[i]), parser.MATC);
                if (materials != null)
                {
                    if (mat == null)
                    {
                        mat = CreateMaterial(ImportedHelpers.FindMaterial(materialNames[i], materials));
                        parser.MATC.AddChild(mat);
                    }

/*					if (textures != null)
 *                                      {
 *                                              string texName = materials[i].Textures[0];
 *                                              remMaterial texMat = rem.FindMaterial(parser.MATC, new remId(texName));
 *                                              if (texMat == null)
 *                                              {
 *                                                      for (int k = 0; k < textures.Count; k++)
 *                                                      {
 *                                                              if (textures[k].Name == texName)
 *                                                              {
 * //									texMat = CreateTexture(textures[k], Path.GetDirectoryName(parser.ODFPath));
 *                                                                      break;
 *                                                              }
 *                                                      }
 *                                              }
 *                                      }*/
                }

                Submesh newSubmesh = newMesh[i];
                if (mat != null)
                {
                    newSubmesh.MaterialName = mat.name;
                }

                if (worldCoords[i])
                {
                    List <remVertex> newVertexList = newSubmesh.VertexList;
                    for (int j = 0; j < newVertexList.Count; j++)
                    {
                        newVertexList[j].Position = Vector3.TransformCoordinate(newVertexList[j].Position, transform);
                    }
                }

                Submesh baseSubmesh            = null;
                List <remBoneWeights> newBones = null;
                int idx = indices[i];
                if ((frameMesh != null) && (idx >= 0) && (idx < frameMesh.Count))
                {
                    baseSubmesh = frameMesh[idx];

                    if ((bonesMethod == CopyMeshMethod.CopyOrder) || (bonesMethod == CopyMeshMethod.CopyNear))
                    {
                        List <remBoneWeights> baseBones = baseSubmesh.BoneList;
                        if (baseBones != null)
                        {
                            newBones = new List <remBoneWeights>(baseBones.Count);
                            foreach (remBoneWeights boneWeights in baseBones)
                            {
                                remBoneWeights copy = boneWeights.Clone();
                                newBones.Add(copy);
                            }
                            newSubmesh.BoneList = newBones;
                        }
                    }
                    else if (bonesMethod == CopyMeshMethod.Replace)
                    {
                        newBones = newSubmesh.BoneList;
                    }
                }
                else
                {
                    newBones = newSubmesh.BoneList;
                }

                if (baseSubmesh != null)
                {
                    if (normalsMethod == CopyMeshMethod.CopyOrder)
                    {
                        rem.CopyNormalsOrder(baseSubmesh.VertexList, newSubmesh.VertexList);
                    }
                    else if (normalsMethod == CopyMeshMethod.CopyNear)
                    {
                        rem.CopyNormalsNear(baseSubmesh.VertexList, newSubmesh.VertexList);
                    }

                    if (bonesMethod == CopyMeshMethod.CopyOrder)
                    {
                        rem.CopyBonesOrder(baseSubmesh.VertexList, newSubmesh.VertexList, newBones);
                    }
                    else if (bonesMethod == CopyMeshMethod.CopyNear)
                    {
                        rem.CopyBonesNear(baseSubmesh.VertexList, newSubmesh.VertexList, newBones);
                    }
                }

                if ((baseSubmesh != null) && merge && replaceSubmeshesOption[i])
                {
                    replaceSubmeshes[idx] = newSubmesh;
                }
                else
                {
                    addSubmeshes.Add(newSubmesh);
                }
            }

            if ((frameMesh != null) && merge)
            {
                newMesh.ChildList.Clear();
                newMesh.ChildList.Capacity = replaceSubmeshes.Length + addSubmeshes.Count;
                for (int i = 0, submeshesRemoved = 0; i < replaceSubmeshes.Length; i++)
                {
                    if (replaceSubmeshes[i] == null)
                    {
                        Submesh newSubmesh = frameMesh[i - submeshesRemoved++];
                        newMesh.AddChild(newSubmesh);
                    }
                    else
                    {
                        newMesh.AddChild(replaceSubmeshes[i]);
                    }
                }
                newMesh.ChildList.AddRange(addSubmeshes);
            }

            remSkin skin;

            newREMMesh       = newMesh.CreateMesh(out skin);
            newREMMesh.frame = frame.name;
            if (frameREMMesh != null)
            {
                CopyUnknowns(frameREMMesh, newREMMesh);
                parser.MESC.InsertChild(parser.MESC.IndexOf(frameREMMesh), newREMMesh);

                RemoveMesh(parser, frameREMMesh);
            }
            else
            {
                CreateUnknowns(newREMMesh);
                parser.MESC.AddChild(newREMMesh);
            }
            if (skin.Count > 0)
            {
                parser.SKIC.AddChild(skin);
            }
        }
Exemple #20
0
        private static remMESCsection ReadMeshes(string sectionName, int sectionLength, int numMeshes, byte[] sectionBuffer)
        {
            remMESCsection meshSec   = new remMESCsection(numMeshes);
            int            secBufIdx = 0;

            for (int subSection = 0; subSection < numMeshes; subSection++)
            {
                byte[] type = new byte[4] {
                    sectionBuffer[secBufIdx + 0], sectionBuffer[secBufIdx + 1], sectionBuffer[secBufIdx + 2], sectionBuffer[secBufIdx + 3]
                };
                int length = BitConverter.ToInt32(sectionBuffer, secBufIdx + 4);

                remMesh mesh = new remMesh(5);
                Trace.Assert(TypeCheck(remMesh.ClassType, type));
                mesh.frame = GetIdentifier(sectionBuffer, secBufIdx + 8);

                int numMats = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256);
                mesh.name = GetIdentifier(sectionBuffer, secBufIdx + 8 + 256 + 4);
                int numFaces    = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256);
                int numVertices = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256 + 4);
                for (int i = 0; i < mesh.unknown.Length; i++)
                {
                    mesh.unknown[i] = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256 + 8 + i * 4);
                }
                for (int i = 0; i < numMats; i++)
                {
                    remId mat = GetIdentifier(sectionBuffer, secBufIdx + 8 + 256 + 4 + 256 + 4 * 4 + i * 256);
                    mesh.AddMaterial(mat);
                }

                mesh.vertices = new remVertex[numVertices];
                int vertBufIdx = secBufIdx + 8 + 256 + 4 + 256 + 4 * 4 + mesh.numMats * 256;
                for (int i = 0; i < numVertices; i++)
                {
                    remVertex vertex = new remVertex();
                    vertex.Position    = new Vector3();
                    vertex.Position[0] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 0);
                    vertex.Position[1] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 4);
                    vertex.Position[2] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 8);

                    vertex.UV    = new Vector2();
                    vertex.UV[0] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 12);
                    vertex.UV[1] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 16);

                    vertex.Normal    = new Vector3();
                    vertex.Normal[0] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 20);
                    vertex.Normal[1] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 24);
                    vertex.Normal[2] = BitConverter.ToSingle(sectionBuffer, vertBufIdx + 28);

                    vertex.RGBA = new Color4(BitConverter.ToInt32(sectionBuffer, vertBufIdx + 32));

                    mesh.vertices[i] = vertex;
                    vertBufIdx      += 36;
                }

                mesh.faces = new int[numFaces * 3];
                int faceBufIdx = vertBufIdx;
                for (int i = 0; i < numFaces; i++)
                {
                    mesh.faces[i * 3 + 0] = BitConverter.ToInt32(sectionBuffer, faceBufIdx + 0);
                    mesh.faces[i * 3 + 1] = BitConverter.ToInt32(sectionBuffer, faceBufIdx + 4);
                    mesh.faces[i * 3 + 2] = BitConverter.ToInt32(sectionBuffer, faceBufIdx + 8);
                    faceBufIdx           += 12;
                }

                mesh.faceMarks = new int[numFaces];
                int faceExtraIdx = faceBufIdx;
                for (int i = 0; i < numFaces; i++)
                {
                    mesh.faceMarks[i] = BitConverter.ToInt32(sectionBuffer, faceExtraIdx);
                    faceExtraIdx     += 4;
                }

                meshSec.AddChild(mesh);

                secBufIdx += length;
            }
            if (secBufIdx != sectionLength)
            {
                Report.ReportLog("Warning! MESC section has wrong length.");
            }
            return(meshSec);
        }
Exemple #21
0
        private static remSKICsection ReadSkin(string sectionName, int sectionLength, int numSkins, byte[] sectionBuffer)
        {
            remSKICsection skinSec   = new remSKICsection(numSkins);
            int            secBufIdx = 0;

            for (int subSection = 0; subSection < numSkins; subSection++)
            {
                byte[] type = new byte[4] {
                    sectionBuffer[secBufIdx + 0], sectionBuffer[secBufIdx + 1], sectionBuffer[secBufIdx + 2], sectionBuffer[secBufIdx + 3]
                };
                int length = BitConverter.ToInt32(sectionBuffer, secBufIdx + 4);

                remId   mesh       = GetIdentifier(sectionBuffer, secBufIdx + 8);
                int     numWeights = BitConverter.ToInt32(sectionBuffer, secBufIdx + 8 + 256);
                remSkin skin       = new remSkin(numWeights);
                Trace.Assert(TypeCheck(remSkin.ClassType, type));
                skin.mesh = mesh;
                int weightBufIdx = secBufIdx + 8 + 256 + 4;
                for (int weightIdx = 0; weightIdx < numWeights; weightIdx++)
                {
                    remBoneWeights weights = new remBoneWeights();
                    weights.bone  = GetIdentifier(sectionBuffer, weightBufIdx);
                    weightBufIdx += 256;
                    int numVertIdxWts = BitConverter.ToInt32(sectionBuffer, weightBufIdx);
                    weightBufIdx += 4;

                    Matrix matrix = new Matrix();
                    for (int i = 0; i < 4; i++)
                    {
                        Vector4 row = new Vector4();
                        for (int j = 0; j < 4; j++)
                        {
                            row[j]        = BitConverter.ToSingle(sectionBuffer, weightBufIdx);
                            weightBufIdx += 4;
                        }
                        matrix.set_Rows(i, row);
                    }
                    weights.matrix = matrix;

                    weights.vertexIndices = new int[numVertIdxWts];
                    for (int i = 0; i < numVertIdxWts; i++)
                    {
                        weights.vertexIndices[i] = BitConverter.ToInt32(sectionBuffer, weightBufIdx);
                        weightBufIdx            += 4;
                    }
                    weights.vertexWeights = new float[weights.numVertIdxWts];
                    for (int i = 0; i < numVertIdxWts; i++)
                    {
                        weights.vertexWeights[i] = BitConverter.ToSingle(sectionBuffer, weightBufIdx);
                        weightBufIdx            += 4;
                    }

                    skin.AddChild(weights);
                }

                skinSec.AddChild(skin);

                secBufIdx += length;
            }
            if (secBufIdx != sectionLength)
            {
                Report.ReportLog("Warning! SKIC section has wrong length.");
            }
            return(skinSec);
        }
Exemple #22
0
        public static ImportedTexture ImportedTexture(remId texture, string remPath, bool diffuse_else_ambient)
        {
            string matTexName  = texture.ToString();
            String texh_folder = TexturePathFromREM(remPath);

            if (texh_folder == null)
            {
                try
                {
                    return(new ImportedTexture(Path.GetDirectoryName(remPath) + @"\" + matTexName));
                }
                catch
                {
                    Report.ReportLog("TEXH folder could not be located. " + matTexName + " also not found in the folder of " + remPath);
                    return(null);
                }
            }

            int lastDotPos = matTexName.LastIndexOf('.');

            if (lastDotPos < 0)
            {
                Report.ReportLog("bad texture " + matTexName);
                return(null);
            }
            String body    = texture.ToString().Substring(0, lastDotPos);
            String ext     = texture.ToString().Substring(lastDotPos);
            String pattern = body + (diffuse_else_ambient ? "" : "_mask01") + ext;

            String[] files = null;
            try
            {
                files = Directory.GetFiles(texh_folder, pattern);
            }
            catch (DirectoryNotFoundException) { }
            if (files == null || files.Length == 0)
            {
                texh_folder += "TexH(v2)\\";
                String pre = "zlc-";
                pattern = diffuse_else_ambient ? " *" : "_mask01*";
                try
                {
                    files = Directory.GetFiles(texh_folder, pre + body + pattern + ext);
                }
                catch (DirectoryNotFoundException) { }
                if (files == null || files.Length == 0)
                {
                    try
                    {
                        return(new ImportedTexture(Path.GetDirectoryName(remPath) + @"\" + matTexName));
                    }
                    catch
                    {
                        Report.ReportLog(
                            (diffuse_else_ambient ? body : body + "_mask01") + ext +
                            " neither found in TEXH nor in TEXH\\TexH(v2) folder and also not in the folder of " + remPath
                            );
                        return(null);
                    }
                }
            }
            return(new ImportedTexture(files[0]));
        }
Exemple #23
0
            public Submesh(remMesh mesh, remSkin skin, int submeshIdx)
            {
                MaterialName = mesh.materials[submeshIdx];
                VertexList   = new List <remVertex>(mesh.numVertices);
                FaceList     = new List <int>(mesh.numFaces * 3);
                int[] vertIndices = new int[mesh.numVertices];
                for (int i = 0; i < mesh.numVertices; i++)
                {
                    vertIndices[i] = -1;
                }
                for (int i = 0; i < mesh.numFaces; i++)
                {
                    if (mesh.faceMarks[i] != submeshIdx)
                    {
                        continue;
                    }

                    for (int j = 0; j < 3; j++)
                    {
                        int vertIdx = mesh.faces[i * 3 + j];
                        if (vertIndices[vertIdx] < 0)
                        {
                            vertIndices[vertIdx] = VertexList.Count;
                            VertexList.Add(mesh.vertices[vertIdx]);
                        }
                        FaceList.Add(vertIndices[vertIdx]);
                    }
                }
                VertexList.TrimExcess();
                FaceList.TrimExcess();

                if (skin == null)
                {
                    return;
                }
                BoneList = new List <remBoneWeights>(skin.Count);
                foreach (remBoneWeights boneWeights in skin)
                {
                    Dictionary <int, float> boneDic = new Dictionary <int, float>(boneWeights.numVertIdxWts);
                    for (int i = 0; i < boneWeights.numVertIdxWts; i++)
                    {
                        int oldVertIdx = boneWeights.vertexIndices[i];
                        int newVertIdx = vertIndices[oldVertIdx];
                        if (newVertIdx >= 0)
                        {
                            boneDic.Add(newVertIdx, boneWeights.vertexWeights[i]);
                        }
                    }
                    if (boneDic.Count == 0)
                    {
                        continue;
                    }

                    remBoneWeights newBoneWeights = new remBoneWeights();
                    newBoneWeights.bone          = boneWeights.bone;
                    newBoneWeights.matrix        = boneWeights.matrix;
                    newBoneWeights.vertexIndices = new int[boneDic.Count];
                    boneDic.Keys.CopyTo(newBoneWeights.vertexIndices, 0);
                    newBoneWeights.vertexWeights = new float[boneDic.Count];
                    boneDic.Values.CopyTo(newBoneWeights.vertexWeights, 0);
                    BoneList.Add(newBoneWeights);
                }
            }
Exemple #24
0
 public void AddMaterial(remId material)
 {
     materials.Add(material);
 }