Example #1
0
        public static List <xxFrame> FindMeshFrames(xxFrame frame, List <string> nameList)
        {
            List <xxFrame> frameList = new List <xxFrame>(nameList.Count);

            FindMeshFrames(frame, frameList, nameList);
            return(frameList);
        }
Example #2
0
        public void SetFrameMatrix(int id,
                                   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)
        {
            xxFrame frame = Frames[id];
            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;

            frame.Matrix = m;
        }
Example #3
0
        public static HashSet <string> SearchHierarchy(xxFrame frame, HashSet <string> meshNames)
        {
            HashSet <string> exportFrames = new HashSet <string>();

            SearchHierarchy(frame, frame, meshNames, exportFrames);
            return(exportFrames);
        }
Example #4
0
        public static List <xxFrame> FindMeshFrames(xxFrame frame)
        {
            List <xxFrame> frameList = new List <xxFrame>();

            FindMeshFrames(frame, frameList);
            return(frameList);
        }
Example #5
0
        void ReplaceFrame(xxFrame newFrame, int destParentId)
        {
            if (destParentId < 0)
            {
                Parser.Frame = newFrame;
            }
            else
            {
                var  destParent = Frames[destParentId];
                bool found      = false;
                for (int i = 0; i < destParent.Count; i++)
                {
                    var dest = destParent[i];
                    if (dest.Name == newFrame.Name)
                    {
                        destParent.RemoveChild(i);
                        destParent.InsertChild(i, newFrame);
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    destParent.AddChild(newFrame);
                }
            }

            Frames.Clear();
            Meshes.Clear();
            InitFrames(Parser.Frame);
        }
Example #6
0
 void MeshMatOffset(xxFrame frame, int offset)
 {
     if (offset != 0)
     {
         MeshMatOffsetIfNotZero(frame, offset);
     }
 }
Example #7
0
        static void SearchHierarchy(xxFrame root, xxFrame frame, HashSet <string> meshNames, HashSet <string> exportFrames)
        {
            if (frame.Mesh != null)
            {
                if (meshNames.Contains(frame.Name))
                {
                    xxFrame parent = frame;
                    while (parent != null)
                    {
                        exportFrames.Add(parent.Name);
                        parent = (xxFrame)parent.Parent;
                    }

                    xxMesh        meshListSome = frame.Mesh;
                    List <xxBone> boneList     = meshListSome.BoneList;
                    for (int i = 0; i < boneList.Count; i++)
                    {
                        if (!exportFrames.Contains(boneList[i].Name))
                        {
                            xxFrame boneParent = FindFrame(boneList[i].Name, root);
                            while (boneParent != null)
                            {
                                exportFrames.Add(boneParent.Name);
                                boneParent = (xxFrame)boneParent.Parent;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < frame.Count; i++)
            {
                SearchHierarchy(root, frame[i], meshNames, exportFrames);
            }
        }
Example #8
0
        public void SetFrameUnknowns(int id, byte[] unknown1, byte[] unknown2)
        {
            xxFrame frame = Frames[id];

            frame.Unknown1 = (byte[])unknown1.Clone();
            frame.Unknown2 = (byte[])unknown2.Clone();
        }
Example #9
0
        public bool RenameSkeletonProfile(string pattern, string replacement)
        {
            bool anyRenaming = false;

            for (int i = 0; i < Frames.Count; i++)
            {
                xxFrame frame = Frames[i];
                string  name  = System.Text.RegularExpressions.Regex.Replace(frame.Name, pattern, replacement, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                if (name != frame.Name)
                {
                    SetFrameName(i, name);
                    Changed     = true;
                    anyRenaming = true;
                }
            }
            if (anyRenaming)
            {
                for (int i = 0; i < Meshes.Count; i++)
                {
                    xxFrame meshFrame = Meshes[i];
                    for (int j = 0; j < meshFrame.Mesh.BoneList.Count; j++)
                    {
                        xxBone bone = meshFrame.Mesh.BoneList[j];
                        string name = System.Text.RegularExpressions.Regex.Replace(bone.Name, pattern, replacement, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        if (name != bone.Name)
                        {
                            SetBoneName(i, j, name);
                            Changed     = true;
                            anyRenaming = true;
                        }
                    }
                }
            }
            return(anyRenaming);
        }
Example #10
0
        void MergeFrame(xxFrame newFrame, int destParentId)
        {
            xxFrame srcParent = new xxFrame();

            srcParent.InitChildren(1);
            srcParent.AddChild(newFrame);

            xxFrame destParent;

            if (destParentId < 0)
            {
                destParent = new xxFrame();
                destParent.InitChildren(1);
                destParent.AddChild(Parser.Frame);
            }
            else
            {
                destParent = Frames[destParentId];
            }

            MergeFrame(srcParent, destParent);

            if (destParentId < 0)
            {
                Parser.Frame = srcParent[0];
                srcParent.RemoveChild(0);
            }

            Frames.Clear();
            Meshes.Clear();
            InitFrames(Parser.Frame);
        }
Example #11
0
        public static void MergeFrame(xxFrame oldFrame, xxFrame newFrame)
        {
            for (int i = oldFrame.Count - 1; i >= 0; i--)
            {
                xxFrame oldChild = oldFrame[i];
                xxFrame newChild = null;
                for (int j = 0; j < newFrame.Count; j++)
                {
                    if (oldChild.Name == newFrame[j].Name)
                    {
                        newChild = newFrame[j];
                        break;
                    }
                }

                if (newChild == null)
                {
                    newFrame.InsertChild(0, oldChild.Clone(true, true));
                }
                else
                {
                    if ((newChild.Mesh == null) && (oldChild.Mesh != null))
                    {
                        newChild.Mesh   = oldChild.Mesh.Clone(true, true, true);
                        newChild.Bounds = oldChild.Bounds;
                    }
                    CopyUnknowns(oldChild, newChild);

                    MergeFrame(oldChild, newChild);
                }
            }
        }
Example #12
0
 public static void SetBoundingBox(xxFrame frame)
 {
     if (frame.Mesh == null)
     {
         frame.Bounds = new BoundingBox();
     }
     else
     {
         xxMesh  meshList = frame.Mesh;
         Vector3 min      = new Vector3(Single.MaxValue, Single.MaxValue, Single.MaxValue);
         Vector3 max      = new Vector3(Single.MinValue, Single.MinValue, Single.MinValue);
         for (int i = 0; i < meshList.SubmeshList.Count; i++)
         {
             List <xxVertex> vertList = meshList.SubmeshList[i].VertexList;
             for (int j = 0; j < vertList.Count; j++)
             {
                 xxVertex vert = vertList[j];
                 Vector3  pos  = vert.Position;
                 min = Vector3.Minimize(min, pos);
                 max = Vector3.Maximize(max, pos);
             }
         }
         frame.Bounds = new BoundingBox(min, max);
     }
 }
Example #13
0
            public static void Export(string dirPath, xxParser xxParser, xxFrame meshFrame, xaParser xaParser, xaMorphClip clip)
            {
                DirectoryInfo dir      = new DirectoryInfo(dirPath);
                ExporterMorph exporter = new ExporterMorph(dir, xxParser, xaParser, clip);

                exporter.Export(dir, meshFrame);
            }
Example #14
0
        public void SetMeshUnknowns(int id, byte[] numVector2, byte[] vertListDup)
        {
            xxFrame frame = Meshes[id];

            xx.SetNumVector2PerVertex(frame.Mesh, numVector2[0]);
            frame.Mesh.VertexListDuplicateUnknown = (byte[])vertListDup.Clone();
        }
Example #15
0
            private void Export(DirectoryInfo dir, xxFrame meshFrame)
            {
                try
                {
                    xaMorphSection  morphSection = xaParser.MorphSection;
                    xaMorphIndexSet indexSet     = xa.FindMorphIndexSet(clip.Name, morphSection);
                    ushort[]        meshIndices  = indexSet.MeshIndices;
                    ushort[]        morphIndices = indexSet.MorphIndices;

                    xxMesh meshList   = meshFrame.Mesh;
                    int    meshObjIdx = xa.MorphMeshObjIdx(meshIndices, meshList);
                    if (meshObjIdx < 0)
                    {
                        throw new Exception("no valid mesh object was found for the morph");
                    }

                    xxSubmesh meshObjBase = meshList.SubmeshList[meshObjIdx];
                    colorVertex = new bool[meshObjBase.VertexList.Count];
                    for (int i = 0; i < meshIndices.Length; i++)
                    {
                        colorVertex[meshIndices[i]] = true;
                    }

                    string dest = Utility.GetDestFile(dir, meshFrame.Name + "-" + clip.Name + "-", ".morph.mqo");

                    List <xaMorphKeyframeRef> refList = clip.KeyframeRefList;
                    morphNames = new List <string>(refList.Count);
                    vertLists  = new List <List <ImportedVertex> >(refList.Count);
                    for (int i = 0; i < refList.Count; i++)
                    {
                        if (!morphNames.Contains(refList[i].Name))
                        {
                            List <ImportedVertex> vertList = xx.ImportedVertexList(meshObjBase.VertexList, xx.IsSkinned(meshList));
                            vertLists.Add(vertList);

                            xaMorphKeyframe keyframe = xa.FindMorphKeyFrame(refList[i].Name, morphSection);
                            for (int j = 0; j < meshIndices.Length; j++)
                            {
                                ImportedVertex vert = vertList[meshIndices[j]];
                                vert.Position = keyframe.PositionList[morphIndices[j]];
                            }
                            morphNames.Add(keyframe.Name);
                        }
                    }

                    faceList = xx.ImportedFaceList(meshObjBase.FaceList);
                    Export(dest, meshObjBase.MaterialIndex);
                    foreach (xxTexture tex in usedTextures)
                    {
                        xx.ExportTexture(tex, dir.FullName + @"\" + Path.GetFileName(tex.Name));
                    }
                    Report.ReportLog("Finished exporting morph to " + dest);
                }
                catch (Exception ex)
                {
                    Report.ReportLog("Error exporting morph: " + ex.Message);
                }
            }
Example #16
0
        public void MergeFrame(xxFrame srcFrame, int srcFormat, int destParentId, int meshMatOffset)
        {
            var newFrame = srcFrame.Clone(true, true);

            xx.ConvertFormat(newFrame, srcFormat, Parser.Format);
            MeshMatOffset(newFrame, meshMatOffset);

            MergeFrame(newFrame, destParentId);
        }
Example #17
0
        public void MergeFrame(xxFrame srcFrame, int srcFormat, List <xxMaterial> srcMaterials, List <xxTexture> srcTextures, bool appendIfMissing, int destParentId)
        {
            int[] matTranslation = CreateMaterialTranslation(srcMaterials, srcFormat, srcTextures, appendIfMissing);
            var   newFrame       = srcFrame.Clone(true, true, matTranslation);

            xx.ConvertFormat(newFrame, srcFormat, Parser.Format);

            MergeFrame(newFrame, destParentId);
        }
Example #18
0
        public void MergeFrame(ImportedFrame srcFrame, int destParentId, int meshMatOffset)
        {
            xxFrame newFrame = xx.CreateFrame(srcFrame);

            xx.CopyOrCreateUnknowns(newFrame, Parser.Frame, Parser.Format);
            MeshMatOffset(newFrame, meshMatOffset);

            MergeFrame(newFrame, destParentId);
        }
Example #19
0
        public void RemoveMesh(int id)
        {
            xxFrame frame = Meshes[id];

            frame.Mesh   = null;
            frame.Bounds = new BoundingBox();

            Frames.Clear();
            Meshes.Clear();
            InitFrames(Parser.Frame);
        }
Example #20
0
        static void FindMeshFrames(xxFrame frame, List <xxFrame> frameList, List <string> nameList)
        {
            if ((frame.Mesh != null) && nameList.Contains(frame.Name))
            {
                frameList.Add(frame);
            }

            for (int i = 0; i < frame.Count; i++)
            {
                FindMeshFrames(frame[i], frameList, nameList);
            }
        }
Example #21
0
        static void FindMeshFrames(xxFrame frame, List <xxFrame> frameList)
        {
            if (frame.Mesh != null)
            {
                frameList.Add(frame);
            }

            for (int i = 0; i < frame.Count; i++)
            {
                FindMeshFrames(frame[i], frameList);
            }
        }
Example #22
0
 public void AddBone(int id, object[] meshes)
 {
     string[] meshFrameNames = Utility.Convert <string>(meshes);
     foreach (string meshName in meshFrameNames)
     {
         xxFrame meshFrame = xx.FindFrame(meshName, Parser.Frame);
         if (xx.FindBone(meshFrame.Mesh.BoneList, Frames[id].Name) == null)
         {
             xx.CreateBone(Frames[id], meshFrame.Mesh);
         }
     }
     Changed = true;
 }
Example #23
0
        private void InitTables()
        {
            xxTable.Rows.Add(new object[] { 0, "Header", Utility.BytesToString(parser.Header) });
            xxTable.Rows.Add(new object[] { 1, "MaterialSection", Utility.BytesToString(parser.MaterialSectionUnknown) });
            if (parser.Format >= 2)
            {
                xxTable.Rows.Add(new object[] { 2, "Footer", Utility.BytesToString(parser.Footer) });                 // 3
            }

            for (int i = 0; i < editor.Frames.Count; i++)
            {
                xxFrame frame = editor.Frames[i];
                frameTable.Rows.Add(new object[] { i, frame.Name, Utility.BytesToString(frame.Unknown1), Utility.BytesToString(frame.Unknown2) });
            }

            for (int i = 0; i < editor.Meshes.Count; i++)
            {
                xxFrame frame = editor.Meshes[i];
                meshTable.Rows.Add(new object[] { i, frame.Name, frame.Mesh.NumVector2PerVertex.ToString("X2"), Utility.BytesToString(frame.Mesh.VertexListDuplicateUnknown) });

                for (int j = 0; j < frame.Mesh.SubmeshList.Count; j++)
                {
                    xxSubmesh submesh = frame.Mesh.SubmeshList[j];
                    submeshTable.Rows.Add(new object[] { new int[] { i, j }, frame.Name + "[" + j + "]",
                                                         Utility.BytesToString(submesh.Unknown1),
                                                         Utility.BytesToString(submesh.Unknown2),
                                                         Utility.BytesToString(submesh.Unknown3),
                                                         Utility.BytesToString(submesh.Unknown4),
                                                         Utility.BytesToString(submesh.Unknown5),
                                                         Utility.BytesToString(submesh.Unknown6) });
                }
            }

            for (int i = 0; i < parser.MaterialList.Count; i++)
            {
                xxMaterial mat = parser.MaterialList[i];
                materialTable.Rows.Add(new object[] { i, mat.Name,
                                                      Utility.BytesToString(mat.Unknown1),
                                                      Utility.BytesToString(mat.Textures[0].Unknown1),
                                                      Utility.BytesToString(mat.Textures[1].Unknown1),
                                                      Utility.BytesToString(mat.Textures[2].Unknown1),
                                                      Utility.BytesToString(mat.Textures[3].Unknown1) });
            }

            for (int i = 0; i < parser.TextureList.Count; i++)
            {
                xxTexture tex = parser.TextureList[i];
                textureTable.Rows.Add(new object[] { i, tex.Name,
                                                     Utility.BytesToString(tex.Unknown1) });
            }
        }
Example #24
0
        void InitFrames(xxFrame frame)
        {
            Frames.Add(frame);

            if (frame.Mesh != null)
            {
                Meshes.Add(frame);
            }

            for (int i = 0; i < frame.Count; i++)
            {
                InitFrames(frame[i]);
            }
        }
Example #25
0
        public void CopyBone(int meshId, int boneId)
        {
            xxFrame       frame    = Meshes[meshId];
            List <xxBone> boneList = frame.Mesh.BoneList;
            xxBone        root     = xx.FindBone(boneList, Frames[0].Name);

            if (root != null)
            {
                throw new Exception("One bone already targets the root frame.");
            }
            xxBone copy = boneList[boneId].Clone();

            copy.Name = Frames[0].Name;
            boneList.Add(copy);
        }
Example #26
0
        void AddFrame(xxFrame newFrame, int destParentId)
        {
            if (destParentId < 0)
            {
                Parser.Frame = newFrame;
            }
            else
            {
                Frames[destParentId].AddChild(newFrame);
            }

            Frames.Clear();
            Meshes.Clear();
            InitFrames(Parser.Frame);
        }
Example #27
0
        public static xxFrame CreateFrame(ImportedFrame frame)
        {
            xxFrame xxFrame = new xxFrame();

            xxFrame.Matrix = frame.Matrix;
            xxFrame.Bounds = new BoundingBox();
            xxFrame.Name   = frame.Name;

            xxFrame.InitChildren(frame.Count);
            for (int i = 0; i < frame.Count; i++)
            {
                xxFrame.AddChild(CreateFrame(frame[i]));
            }

            return(xxFrame);
        }
Example #28
0
        void MeshMatOffset(xxFrame frame, int offset)
        {
            if (frame.Mesh != null)
            {
                var submeshes = frame.Mesh.SubmeshList;
                for (int i = 0; i < submeshes.Count; i++)
                {
                    submeshes[i].MaterialIndex += offset;
                }
            }

            for (int i = 0; i < frame.Count; i++)
            {
                MeshMatOffset(frame[i], offset);
            }
        }
Example #29
0
        public void ZeroWeights(int meshId, int boneId)
        {
            xxMesh  mesh          = Meshes[meshId].Mesh;
            xxBone  bone          = mesh.BoneList[boneId];
            xxFrame parentFrame   = xx.FindFrame(bone.Name, Parser.Frame).Parent;
            xxBone  parentBone    = xx.FindBone(mesh.BoneList, parentFrame.Name);
            byte    parentBoneIdx = (byte)mesh.BoneList.IndexOf(parentBone);

            foreach (xxSubmesh submesh in mesh.SubmeshList)
            {
                foreach (xxVertex vertex in submesh.VertexList)
                {
                    int parentIdx = -1;
                    for (int i = 0; i < vertex.BoneIndices.Length; i++)
                    {
                        if (vertex.BoneIndices[i] == parentBoneIdx)
                        {
                            parentIdx = i;
                            break;
                        }
                    }
                    for (int i = 0; i < vertex.BoneIndices.Length; i++)
                    {
                        if (vertex.BoneIndices[i] == boneId)
                        {
                            if (parentIdx >= 0)
                            {
                                float[] w4 = vertex.Weights4(true);
                                w4[parentIdx]     += w4[i];
                                w4[i]              = 0;
                                vertex.Weights3[0] = w4[0];
                                vertex.Weights3[1] = w4[1];
                                vertex.Weights3[2] = w4[2];
                            }
                            else
                            {
                                vertex.BoneIndices[i] = parentBoneIdx;
                            }
                            break;
                        }
                    }
                }
            }
            Changed = true;
        }
Example #30
0
        public static void CopyOrCreateUnknowns(xxFrame dest, xxFrame root, int xxFormat)
        {
            xxFrame src = FindFrame(dest.Name, root);

            if (src == null)
            {
                CreateUnknowns(dest, xxFormat);
            }
            else
            {
                CopyUnknowns(src, dest);
            }

            for (int i = 0; i < dest.Count; i++)
            {
                CopyOrCreateUnknowns(dest[i], root, xxFormat);
            }
        }