Exemplo n.º 1
0
        public void WriteToFile(FrameObjectBase Frame)
        {
            ModelAttachments = new Dictionary <ulong, List <int> >();

            string FrameName  = Frame.Name.String;
            string ExportPath = Path.Combine(ToolkitSettings.ExportPath, FrameName);
            string ExportName = ExportPath + ".framedata";

            if (!Directory.Exists(ExportPath))
            {
                Directory.CreateDirectory(ExportPath);
            }

            using (BinaryWriter writer = new BinaryWriter(File.Open(ExportName, FileMode.Create)))
            {
                SaveFrame(Frame, writer);

                writer.Write(ModelAttachments.Count);
                foreach (var Entry in ModelAttachments)
                {
                    writer.Write(Entry.Key);
                    writer.Write(Entry.Value.Count);
                    foreach (var ListEntry in Entry.Value)
                    {
                        writer.Write(ListEntry);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ReadFramesFromFile(string FileName)
        {
            FrameObjects           = new Dictionary <int, object>();
            FrameMaterials         = new Dictionary <int, FrameMaterial>();
            FrameGeometries        = new Dictionary <int, FrameGeometry>();
            FrameSkeletonHierarchy = new Dictionary <int, FrameSkeletonHierachy>();
            FrameBlendInfos        = new Dictionary <int, FrameBlendInfo>();
            FrameSkeletons         = new Dictionary <int, FrameSkeleton>();
            ModelAttachments       = new Dictionary <ulong, List <int> >();
            OldRefIDLookupTable    = new Dictionary <int, FrameObjectBase>();

            using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(FileName)))
            {
                RootFrame = ReadFrame(stream);

                uint NumModelAttachments = stream.ReadUInt32(false);
                for (int i = 0; i < NumModelAttachments; i++)
                {
                    List <int> AttachmentRefs = new List <int>();

                    ulong ModelHash             = stream.ReadUInt64(false);
                    uint  NumAttachmentsInModel = stream.ReadUInt32(false);
                    for (int z = 0; z < NumAttachmentsInModel; z++)
                    {
                        int AttachmentRefID = stream.ReadInt32(false);
                        AttachmentRefs.Add(AttachmentRefID);
                    }

                    ModelAttachments.Add(ModelHash, AttachmentRefs);
                }
            }
        }
Exemplo n.º 3
0
        public void PushPacketIntoFrameResource(FrameResource FrameResource)
        {
            Dictionary <int, FrameObjectBase> AttachmentRefLookup = new Dictionary <int, FrameObjectBase>();

            FrameResource.FrameBlendInfos.AddRange(FrameBlendInfos);
            FrameResource.FrameGeometries.AddRange(FrameGeometries);
            FrameResource.FrameMaterials.AddRange(FrameMaterials);
            FrameResource.FrameSkeletonHierachies.AddRange(FrameSkeletonHierarchy);
            FrameResource.FrameSkeletons.AddRange(FrameSkeletons);
            FrameResource.FrameObjects.AddRange(FrameObjects);

            // Update child relations
            // Then push Object and hash to AttachmentRefLookup
            foreach (var Pair in FrameObjects)
            {
                FrameObjectBase CurrentObject = (Pair.Value as FrameObjectBase);
                UpdateParentChildRelations(FrameResource, CurrentObject);
            }

            // Update AttachmentReferences on FrameObjectModels
            foreach (var Pair in FrameObjects)
            {
                if (Pair.Value is FrameObjectModel)
                {
                    FrameObjectModel ModelObject    = (Pair.Value as FrameObjectModel);
                    List <int>       AttachmentRefs = ModelAttachments[ModelObject.Name.Hash];

                    for (int i = 0; i < AttachmentRefs.Count; i++)
                    {
                        ModelObject.AttachmentReferences[i].Attachment = OldRefIDLookupTable[AttachmentRefs[i]];
                    }
                }
            }
        }
Exemplo n.º 4
0
        public bool DeleteFrame(FrameEntry EntryToDelete)
        {
            // Early return out if its invalid
            if (EntryToDelete == null)
            {
                return(false);
            }

            // Remove Parent reference
            FrameObjectBase BaseObject = (EntryToDelete as FrameObjectBase);

            if (BaseObject != null)
            {
                FrameObjectBase ParentObject = BaseObject.Parent;
                if (ParentObject != null)
                {
                    bool bDeleted = ParentObject.Children.Remove(BaseObject);
                    Debug.Assert(bDeleted, "Failed to delete an object which should be in the child array.");

                    BaseObject.Parent = null;
                }
            }

            return(FrameObjects.Remove(EntryToDelete.RefID));
        }
Exemplo n.º 5
0
        public TreeNode BuildTree(FrameNameTable.FrameNameTable table)
        {
            TreeNode root = new TreeNode("FrameResource Contents");

            root.Tag = header;

            int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;
            Dictionary <int, TreeNode> parsedNodes   = new Dictionary <int, TreeNode>();
            Dictionary <int, TreeNode> notAddedNodes = new Dictionary <int, TreeNode>();

            //Add scene groups into the scene viewer.
            for (int i = 0; i != frameScenes.Count; i++)
            {
                FrameHeaderScene scene = frameScenes.Values.ElementAt(i);
                TreeNode         node  = new TreeNode(scene.ToString());
                node.Tag  = scene;
                node.Name = scene.RefID.ToString();
                parsedNodes.Add(scene.RefID, node);
                root.Nodes.Add(node);

                AddChildren(parsedNodes, scene.Children, node);
            }

            foreach (var pair in frameObjects)
            {
                FrameObjectBase frame = (pair.Value as FrameObjectBase);
                TreeNode        node;

                if (parsedNodes.ContainsKey(pair.Key))
                {
                    continue;
                }

                if (frame.ParentIndex1.Index == -1 && frame.ParentIndex2.Index == -1)
                {
                    node      = new TreeNode(frame.ToString());
                    node.Tag  = frame;
                    node.Name = frame.RefID.ToString();
                    root.Nodes.Add(node);
                    parsedNodes.Add(frame.RefID, node);
                    AddChildren(parsedNodes, frame.Children, node);
                }
            }

            foreach (var pair in frameObjects)
            {
                if (!parsedNodes.ContainsKey(pair.Key))
                {
                    FrameObjectBase frame = (pair.Value as FrameObjectBase);
                    Debug.WriteLine("Failed " + frame.ToString());
                    TreeNode node = new TreeNode(frame.ToString());
                    node.Tag  = frame;
                    node.Name = frame.RefID.ToString();
                    root.Nodes.Add(node);
                    //throw new FormatException("Unhandled frame! Name is: " + pair.Value.ToString());
                }
            }
            return(root);
        }
Exemplo n.º 6
0
 public TreeNode ReadFramesFromFile(string filename)
 {
     using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(filename)))
     {
         FrameObjectBase parent = ReadFrame(stream);
         return(BuildFromFrames(null, parent));
     }
 }
Exemplo n.º 7
0
        public void SaveFramesToFile(FrameObjectBase frame, string file)
        {
            string filename = frame.Name.String;

            using (BinaryWriter writer = new BinaryWriter(File.Open(Path.Combine(ToolkitSettings.ExportPath, filename) + ".framedata", FileMode.Create)))
            {
                SaveFrame(frame, writer);
            }
        }
Exemplo n.º 8
0
        public void SetParentOfObject(int parentId, FrameEntry childEntry, FrameEntry parentEntry)
        {
            //get the index and child object
            FrameObjectBase obj = (childEntry as FrameObjectBase);

            //fix any parent-children relationships.
            if (obj.Parent != null)
            {
                obj.Parent.Children.Remove(obj);
                obj.Parent = null;
            }

            if (parentEntry != null) //this is if the user wants to change parent
            {
                int             index     = (parentEntry is FrameHeaderScene) ? frameScenes.IndexOfValue(parentEntry.RefID) : GetIndexOfObject(parentEntry.RefID);
                FrameObjectBase parentObj = (parentEntry as FrameObjectBase);

                //fix any parent relationships only if ParentObj is not null.
                if (parentObj != null)
                {
                    parentObj.Children.Add(obj);
                    obj.Parent = parentObj;
                }

                //set parent indexes.
                if (parentId == 0)
                {
                    obj.ParentIndex1.SetParent(index, parentEntry);
                    obj.ReplaceRef(FrameEntryRefTypes.Parent1, parentEntry.RefID);
                }
                else if (parentId == 1)
                {
                    obj.ParentIndex2.SetParent(index, parentEntry);
                    obj.ReplaceRef(FrameEntryRefTypes.Parent2, parentEntry.RefID);
                }
            }
            else //this is if the user wants to remove the parent relationship, therefore -1 = root.
            {
                if (parentId == 0)
                {
                    obj.ParentIndex1.SetParent(-1, "root", 0);
                    obj.SubRef(FrameEntryRefTypes.Parent1);
                }
                else if (parentId == 1)
                {
                    obj.ParentIndex2.SetParent(-1, "root", 0);
                    obj.SubRef(FrameEntryRefTypes.Parent2);
                }
            }
            foreach (var pair in frameObjects)
            {
                (pair.Value as FrameObjectBase).SetWorldTransform();
            }
        }
Exemplo n.º 9
0
 public FrameObjectBase(FrameObjectBase other) : base(other)
 {
     name           = new Hash(other.name.String);
     secondaryFlags = other.secondaryFlags;
     localTransform = new Matrix(other.localTransform.ToArray());
     unk3           = other.unk3;
     parentIndex1   = new ParentStruct(other.parentIndex1);
     parentIndex2   = new ParentStruct(other.parentIndex2);
     unk6           = -1;
     isOnTable      = other.isOnTable;
     nameTableFlags = other.nameTableFlags;
 }
Exemplo n.º 10
0
        public void DefineFrameBlockParents()
        {
            int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;

            for (int i = 0; i != NewFrames.Count; i++)
            {
                FrameObjectBase obj = (GetEntryFromIdx(i).Data as FrameObjectBase);

                if (obj == null)
                {
                    continue;
                }

                if (obj.ParentIndex1.Index > -1)
                {
                    if (obj.ParentIndex1.Index <= (frameScenes.Count - 1) && (frameScenes.Count - 1) != -1)
                    {
                        obj.ParentIndex1.RefID = (frameScenes.ElementAt(obj.ParentIndex1.Index).Value as FrameHeaderScene).RefID;
                        obj.ParentIndex1.Name  = (frameScenes.ElementAt(obj.ParentIndex1.Index).Value as FrameHeaderScene).Name.String;
                    }
                    else if (obj.ParentIndex1.Index >= numBlocks)
                    {
                        obj.ParentIndex1.RefID = (GetEntryFromIdx(obj.ParentIndex1.Index).Data as FrameObjectBase).RefID;
                        obj.ParentIndex1.Name  = (GetEntryFromIdx(obj.ParentIndex1.Index).Data as FrameObjectBase).Name.String;
                    }
                    obj.AddRef(FrameEntryRefTypes.Parent1, obj.ParentIndex1.RefID);
                }

                if (obj.ParentIndex2.Index > -1)
                {
                    if (obj.ParentIndex2.Index <= (frameScenes.Count - 1) && (frameScenes.Count - 1) != -1)
                    {
                        obj.ParentIndex2.RefID = (frameScenes.ElementAt(obj.ParentIndex2.Index).Value as FrameHeaderScene).RefID;
                        obj.ParentIndex2.Name  = (frameScenes.ElementAt(obj.ParentIndex2.Index).Value as FrameHeaderScene).Name.String;
                    }
                    else if (obj.ParentIndex2.Index >= numBlocks)
                    {
                        obj.ParentIndex2.RefID = (GetEntryFromIdx(obj.ParentIndex2.Index).Data as FrameObjectBase).RefID;
                        obj.ParentIndex2.Name  = (GetEntryFromIdx(obj.ParentIndex2.Index).Data as FrameObjectBase).Name.String;
                    }

                    obj.AddRef(FrameEntryRefTypes.Parent2, obj.ParentIndex2.RefID);
                }
            }
        }
Exemplo n.º 11
0
        private TreeNode BuildFromFrames(TreeNode parent, FrameObjectBase frame)
        {
            // Create our new node for the frame.
            TreeNode node = new TreeNode(frame.ToString());

            node.Tag  = frame;
            node.Name = frame.RefID.ToString();

            // If our parent exists, add it into the node.
            if (parent != null)
            {
                parent.Nodes.Add(node);
            }

            // Iterate and create the frames from our parent frame.
            foreach (var child in frame.Children)
            {
                BuildFromFrames(node, child);
            }

            return(node);
        }
Exemplo n.º 12
0
        private void UpdateParentChildRelations(FrameResource FrameResource, FrameObjectBase ObjectToUpdate)
        {
            FrameObjectBase Child = ObjectToUpdate;

            // Parent Frames
            FrameObjectBase Parent1 = null;
            FrameObjectBase Parent2 = null;

            if (Child.Refs.ContainsKey(FrameEntryRefTypes.Parent1))
            {
                if (OldRefIDLookupTable.TryGetValue(Child.Refs[FrameEntryRefTypes.Parent1], out Parent1))
                {
                    Child.SubRef(FrameEntryRefTypes.Parent1);
                    FrameResource.SetParentOfObject(0, Child, Parent1);
                }
                else
                {
                    Child.SubRef(FrameEntryRefTypes.Parent1);
                    FrameResource.SetParentOfObject(0, Child, null);
                }
            }

            if (Child.Refs.ContainsKey(FrameEntryRefTypes.Parent2))
            {
                if (OldRefIDLookupTable.TryGetValue(Child.Refs[FrameEntryRefTypes.Parent2], out Parent2))
                {
                    Child.SubRef(FrameEntryRefTypes.Parent2);
                    FrameResource.SetParentOfObject(1, Child, Parent2);
                }
                else
                {
                    Child.SubRef(FrameEntryRefTypes.Parent2);
                    FrameResource.SetParentOfObject(1, Child, null);
                }
            }
        }
Exemplo n.º 13
0
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            header = new FrameHeader();
            header.ReadFromFile(reader, isBigEndian);
            List <int> refs = new List <int>();

            for (int i = 0; i != header.SceneFolders.Count; i++)
            {
                frameScenes.Add(header.SceneFolders[i].RefID, header.SceneFolders[i]);
                refs.Add(header.SceneFolders[i].RefID);
            }
            for (int i = 0; i != header.NumGeometries; i++)
            {
                FrameGeometry geo = new FrameGeometry(reader, isBigEndian);
                frameGeometries.Add(geo.RefID, geo);
                refs.Add(geo.RefID);
            }
            for (int i = 0; i != header.NumMaterialResources; i++)
            {
                FrameMaterial mat = new FrameMaterial(reader, isBigEndian);
                frameMaterials.Add(mat.RefID, mat);
                refs.Add(mat.RefID);
            }
            for (int i = 0; i != header.NumBlendInfos; i++)
            {
                FrameBlendInfo blendInfo = new FrameBlendInfo(reader, isBigEndian);
                frameBlendInfos.Add(blendInfo.RefID, blendInfo);
                refs.Add(blendInfo.RefID);
            }
            for (int i = 0; i != header.NumSkeletons; i++)
            {
                FrameSkeleton skeleton = new FrameSkeleton(reader, isBigEndian);
                frameSkeletons.Add(skeleton.RefID, skeleton);
                refs.Add(skeleton.RefID);
            }
            for (int i = 0; i != header.NumSkelHierachies; i++)
            {
                FrameSkeletonHierachy skeletonHierachy = new FrameSkeletonHierachy(reader, isBigEndian);
                frameSkeletonHierachies.Add(skeletonHierachy.RefID, skeletonHierachy);
                refs.Add(skeletonHierachy.RefID);
            }

            int[] objectTypes = new int[header.NumObjects];

            if (header.NumObjects > 0)
            {
                for (int i = 0; i != header.NumObjects; i++)
                {
                    objectTypes[i] = reader.ReadInt32(isBigEndian);
                }

                for (int i = 0; i != header.NumObjects; i++)
                {
                    FrameObjectBase newObject = FrameFactory.ReadFrameByObjectID(reader, (ObjectType)objectTypes[i], isBigEndian);

                    if (objectTypes[i] == (int)ObjectType.SingleMesh)
                    {
                        FrameObjectSingleMesh mesh = newObject as FrameObjectSingleMesh;

                        if (mesh.MeshIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Geometry, refs[mesh.MeshIndex]);
                            mesh.Geometry = frameGeometries[mesh.Refs[FrameEntry.GeometryRef]];
                        }

                        if (mesh.MaterialIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Material, refs[mesh.MaterialIndex]);
                            mesh.Material = frameMaterials[mesh.Refs[FrameEntry.MaterialRef]];
                        }
                    }
                    else if (objectTypes[i] == (int)ObjectType.Model)
                    {
                        FrameObjectModel mesh = newObject as FrameObjectModel;
                        mesh.AddRef(FrameEntryRefTypes.Geometry, refs[mesh.MeshIndex]);
                        mesh.Geometry = frameGeometries[mesh.Refs[FrameEntry.GeometryRef]];
                        mesh.AddRef(FrameEntryRefTypes.Material, refs[mesh.MaterialIndex]);
                        mesh.Material = frameMaterials[mesh.Refs[FrameEntry.MaterialRef]];
                        mesh.AddRef(FrameEntryRefTypes.BlendInfo, refs[mesh.BlendInfoIndex]);
                        mesh.BlendInfo = frameBlendInfos[mesh.Refs[FrameEntry.BlendInfoRef]];
                        mesh.AddRef(FrameEntryRefTypes.Skeleton, refs[mesh.SkeletonIndex]);
                        mesh.Skeleton = frameSkeletons[mesh.Refs[FrameEntry.SkeletonRef]];
                        mesh.AddRef(FrameEntryRefTypes.SkeletonHierachy, refs[mesh.SkeletonHierachyIndex]);
                        mesh.SkeletonHierarchy = frameSkeletonHierachies[mesh.Refs[FrameEntry.SkeletonHierRef]];

                        mesh.ReadFromFilePart2(reader, isBigEndian);

                        newObject = mesh;
                    }

                    frameObjects.Add(newObject.RefID, newObject);
                }
            }
            objectTypes = null;
            DefineFrameBlockParents();
        }
Exemplo n.º 14
0
        private void SaveFrame(FrameObjectBase frame, BinaryWriter writer)
        {
            //is this even needed? hmm.
            writer.Write(frame.RefID); // Save old RefID
            Debug.WriteLine(frame.ToString());
            if (frame.GetType() == typeof(FrameObjectArea))
            {
                writer.Write((ushort)ObjectType.Area);
                (frame as FrameObjectArea).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectCamera))
            {
                writer.Write((ushort)ObjectType.Camera);
                (frame as FrameObjectCamera).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectCollision))
            {
                writer.Write((ushort)ObjectType.Collision);
                (frame as FrameObjectCollision).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectComponent_U005))
            {
                writer.Write((ushort)ObjectType.Component_U00000005);
                (frame as FrameObjectComponent_U005).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectDummy))
            {
                writer.Write((ushort)ObjectType.Dummy);
                (frame as FrameObjectDummy).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectDeflector))
            {
                writer.Write((ushort)ObjectType.ParticleDeflector);
                (frame as FrameObjectDeflector).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectFrame))
            {
                writer.Write((ushort)ObjectType.Frame);
                (frame as FrameObjectFrame).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectJoint))
            {
                writer.Write((ushort)ObjectType.Joint);
                (frame as FrameObjectJoint).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectLight))
            {
                writer.Write((ushort)ObjectType.Light);
                (frame as FrameObjectLight).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectModel))
            {
                var mesh = (frame as FrameObjectModel);
                writer.Write((ushort)ObjectType.Model);
                mesh.WriteToFilePart1(writer);
                mesh.Geometry.WriteToFile(writer);
                mesh.Material.WriteToFile(writer);
                mesh.BlendInfo.WriteToFile(writer);
                mesh.Skeleton.WriteToFile(writer);
                mesh.SkeletonHierarchy.WriteToFile(writer);
                mesh.WriteToFilePart2(writer);

                // Write Attachment hashes to the dictionary
                List <int> AttachmentHashes = new List <int>();
                foreach (FrameObjectModel.AttachmentReference Attachment in mesh.AttachmentReferences)
                {
                    AttachmentHashes.Add(Attachment.Attachment.RefID);
                }

                ModelAttachments.Add(mesh.Name.Hash, AttachmentHashes);

                foreach (var lod in mesh.Geometry.LOD)
                {
                    using (var stream = new MemoryStream())
                    {
                        SceneData.IndexBufferPool.GetBuffer(lod.IndexBufferRef.Hash).WriteToFile(stream, false);
                        SceneData.VertexBufferPool.GetBuffer(lod.VertexBufferRef.Hash).WriteToFile(stream, false);
                        writer.Write(stream.ToArray());
                    }
                }
            }
            else if (frame.GetType() == typeof(FrameObjectSector))
            {
                writer.Write((ushort)ObjectType.Sector);
                (frame as FrameObjectSector).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectSingleMesh))
            {
                var mesh = (frame as FrameObjectSingleMesh);
                writer.Write((ushort)ObjectType.SingleMesh);
                mesh.WriteToFile(writer);
                mesh.Geometry.WriteToFile(writer);
                mesh.Material.WriteToFile(writer);

                foreach (var lod in mesh.Geometry.LOD)
                {
                    using (var stream = new MemoryStream())
                    {
                        SceneData.IndexBufferPool.GetBuffer(lod.IndexBufferRef.Hash).WriteToFile(stream, false);
                        SceneData.VertexBufferPool.GetBuffer(lod.VertexBufferRef.Hash).WriteToFile(stream, false);
                        writer.Write(stream.ToArray());
                    }
                }
            }
            else if (frame.GetType() == typeof(FrameObjectTarget))
            {
                writer.Write((ushort)ObjectType.Target);
                (frame as FrameObjectTarget).WriteToFile(writer);
            }
            else
            {
                writer.Write(frame.Type);
                frame.WriteToFile(writer);
            }

            // write FrameNameTable info
            writer.Write(frame.IsOnFrameTable);
            writer.Write((uint)frame.FrameNameTableFlags);

            // Write ParentIndex1 and ParentIndex2 info
            writer.Write(frame.ParentIndex1.RefID);
            writer.Write(frame.ParentIndex2.RefID);

            writer.Write(frame.Children.Count);
            for (int i = 0; i < frame.Children.Count; i++)
            {
                SaveFrame(frame.Children[i], writer);
            }
        }
Exemplo n.º 15
0
        public void WriteToFile(BinaryWriter writer)
        {
            //BEFORE WE WRITE, WE NEED TO COMPILE AND UPDATE THE FRAME.
            UpdateFrameData();
            header.WriteToFile(writer);

            foreach (var pair in frameGeometries)
            {
                pair.Value.WriteToFile(writer);
            }

            foreach (var pair in frameMaterials)
            {
                pair.Value.WriteToFile(writer);
            }

            foreach (var pair in frameBlendInfos)
            {
                pair.Value.WriteToFile(writer);
            }

            foreach (var pair in frameSkeletons)
            {
                pair.Value.WriteToFile(writer);
            }

            foreach (var pair in frameSkeletonHierachies)
            {
                pair.Value.WriteToFile(writer);
            }

            foreach (var pair in frameObjects)
            {
                FrameObjectBase entry = (pair.Value as FrameObjectBase);
                if (entry.GetType() == typeof(FrameObjectJoint))
                {
                    writer.Write((int)ObjectType.Joint);
                }
                else if (entry.GetType() == typeof(FrameObjectSingleMesh))
                {
                    writer.Write((int)ObjectType.SingleMesh);
                }
                else if (entry.GetType() == typeof(FrameObjectFrame))
                {
                    writer.Write((int)ObjectType.Frame);
                }
                else if (entry.GetType() == typeof(FrameObjectLight))
                {
                    writer.Write((int)ObjectType.Light);
                }
                else if (entry.GetType() == typeof(FrameObjectCamera))
                {
                    writer.Write((int)ObjectType.Camera);
                }
                else if (entry.GetType() == typeof(FrameObjectComponent_U005))
                {
                    writer.Write((int)ObjectType.Component_U00000005);
                }
                else if (entry.GetType() == typeof(FrameObjectSector))
                {
                    writer.Write((int)ObjectType.Sector);
                }
                else if (entry.GetType() == typeof(FrameObjectDummy))
                {
                    writer.Write((int)ObjectType.Dummy);
                }
                else if (entry.GetType() == typeof(FrameObjectDeflector))
                {
                    writer.Write((int)ObjectType.ParticleDeflector);
                }
                else if (entry.GetType() == typeof(FrameObjectArea))
                {
                    writer.Write((int)ObjectType.Area);
                }
                else if (entry.GetType() == typeof(FrameObjectTarget))
                {
                    writer.Write((int)ObjectType.Target);
                }
                else if (entry.GetType() == typeof(FrameObjectModel))
                {
                    writer.Write((int)ObjectType.Model);
                }
                else if (entry.GetType() == typeof(FrameObjectCollision))
                {
                    writer.Write((int)ObjectType.Collision);
                }
            }

            foreach (var pair in frameObjects)
            {
                FrameObjectBase entry = (pair.Value as FrameObjectBase);
                entry.WriteToFile(writer);
            }
        }
Exemplo n.º 16
0
        private FrameObjectBase ReadFrame(MemoryStream stream)
        {
            ObjectType      frameType = (ObjectType)stream.ReadInt16(false);
            FrameObjectBase parent    = FrameFactory.ReadFrameByObjectID(stream, frameType, false);

            Debug.WriteLine(parent.ToString());

            if (parent is FrameObjectSingleMesh || parent is FrameObjectModel)
            {
                // Read the required blocks;
                FrameGeometry geometry = new FrameGeometry();
                geometry.ReadFromFile(stream, false);
                FrameMaterial material = new FrameMaterial();
                material.ReadFromFile(stream, false);

                // Add them into our pool of blocks
                frameGeometries.Add(geometry.RefID, geometry);
                frameMaterials.Add(material.RefID, material);

                // Add our references onto our mesh
                FrameObjectSingleMesh mesh = (parent as FrameObjectSingleMesh);
                mesh.AddRef(FrameEntryRefTypes.Geometry, geometry.RefID);
                mesh.Geometry = frameGeometries[geometry.RefID];
                mesh.AddRef(FrameEntryRefTypes.Material, material.RefID);
                mesh.Material = frameMaterials[material.RefID];

                //mesh.Parent.ParentIndex1

                if (parent is FrameObjectModel)
                {
                    // Read the rigged specific blocks
                    FrameBlendInfo blendInfo = new FrameBlendInfo();
                    blendInfo.ReadFromFile(stream, false);
                    FrameSkeleton skeleton = new FrameSkeleton();
                    skeleton.ReadFromFile(stream, false);
                    FrameSkeletonHierachy hierarchy = new FrameSkeletonHierachy();
                    hierarchy.ReadFromFile(stream, false);

                    // Add our new rigged specific blocks into our pools
                    frameBlendInfos.Add(blendInfo.RefID, blendInfo);
                    frameSkeletons.Add(skeleton.RefID, skeleton);
                    frameSkeletonHierachies.Add(hierarchy.RefID, hierarchy);

                    // Finally, add our references to the model.
                    FrameObjectModel model = (parent as FrameObjectModel);
                    model.AddRef(FrameEntryRefTypes.BlendInfo, blendInfo.RefID);
                    model.BlendInfo = frameBlendInfos[blendInfo.RefID];
                    model.AddRef(FrameEntryRefTypes.Skeleton, skeleton.RefID);
                    model.Skeleton = frameSkeletons[skeleton.RefID];
                    model.AddRef(FrameEntryRefTypes.SkeletonHierachy, hierarchy.RefID);
                    model.SkeletonHierarchy = frameSkeletonHierachies[hierarchy.RefID];
                }

                // Read the buffers;
                IndexBuffer  indexBuffer  = new IndexBuffer(stream, false);
                VertexBuffer vertexBuffer = new VertexBuffer(stream, false);

                // We have to make sure we have index and buffer pools available
                // We have to do it for all LODs too; if any more than 1.
                foreach (var lod in geometry.LOD)
                {
                    SceneData.IndexBufferPool.TryAddBuffer(indexBuffer);
                    SceneData.VertexBufferPool.TryAddBuffer(vertexBuffer);
                }
            }

            // We can finally add our new frame object
            frameObjects.Add(parent.RefID, parent);

            // Read how many children this frame has, and proceed to read them too.
            int count = stream.ReadInt32(false);

            for (int i = 0; i < count; i++)
            {
                FrameObjectBase child = ReadFrame(stream);

                // Add References early..
                child.AddRef(FrameEntryRefTypes.Parent1, parent.RefID);
                child.AddRef(FrameEntryRefTypes.Parent2, parent.RefID);

                SetParentOfObject(0, child, parent);
                SetParentOfObject(1, child, parent);
            }

            return(parent);
        }
Exemplo n.º 17
0
        private FrameObjectBase ReadFrame(MemoryStream stream)
        {
            int OldRefID = stream.ReadInt32(false); // read old RefID so we can make lookup dictionary

            ObjectType      frameType = (ObjectType)stream.ReadInt16(false);
            FrameObjectBase parent    = FrameFactory.ReadFrameByObjectID(stream, frameType, false);

            Debug.WriteLine(parent.ToString());

            if (parent is FrameObjectSingleMesh || parent is FrameObjectModel)
            {
                // Read the required blocks;
                FrameGeometry geometry = new FrameGeometry();
                geometry.ReadFromFile(stream, false);
                FrameMaterial material = new FrameMaterial();
                material.ReadFromFile(stream, false);

                // Add them into our pool of blocks
                FrameGeometries.Add(geometry.RefID, geometry);
                FrameMaterials.Add(material.RefID, material);

                // Add our references onto our mesh
                FrameObjectSingleMesh mesh = (parent as FrameObjectSingleMesh);
                mesh.AddRef(FrameEntryRefTypes.Geometry, geometry.RefID);
                mesh.Geometry = FrameGeometries[geometry.RefID];
                mesh.AddRef(FrameEntryRefTypes.Material, material.RefID);
                mesh.Material = FrameMaterials[material.RefID];

                if (parent is FrameObjectModel)
                {
                    // Read the rigged specific blocks
                    FrameBlendInfo blendInfo = new FrameBlendInfo();
                    blendInfo.ReadFromFile(stream, false);
                    FrameSkeleton skeleton = new FrameSkeleton();
                    skeleton.ReadFromFile(stream, false);
                    FrameSkeletonHierachy hierarchy = new FrameSkeletonHierachy();
                    hierarchy.ReadFromFile(stream, false);

                    // Add our new rigged specific blocks into our pools
                    FrameBlendInfos.Add(blendInfo.RefID, blendInfo);
                    FrameSkeletons.Add(skeleton.RefID, skeleton);
                    FrameSkeletonHierarchy.Add(hierarchy.RefID, hierarchy);

                    // Finally, add our references to the model.
                    FrameObjectModel model = (parent as FrameObjectModel);
                    model.AddRef(FrameEntryRefTypes.BlendInfo, blendInfo.RefID);
                    model.BlendInfo = FrameBlendInfos[blendInfo.RefID];
                    model.AddRef(FrameEntryRefTypes.Skeleton, skeleton.RefID);
                    model.Skeleton = FrameSkeletons[skeleton.RefID];
                    model.AddRef(FrameEntryRefTypes.SkeletonHierachy, hierarchy.RefID);
                    model.SkeletonHierarchy = FrameSkeletonHierarchy[hierarchy.RefID];
                    model.ReadFromFilePart2(stream, false);
                }

                // We have to make sure we have index and buffer pools available
                // We have to do it for all LODs too; if any more than 1.
                foreach (var lod in geometry.LOD)
                {
                    IndexBuffer  indexBuffer  = new IndexBuffer(stream, false);
                    VertexBuffer vertexBuffer = new VertexBuffer(stream, false);

                    SceneData.IndexBufferPool.TryAddBuffer(indexBuffer);
                    SceneData.VertexBufferPool.TryAddBuffer(vertexBuffer);
                }
            }

            // Read FrameNameTable data
            parent.IsOnFrameTable      = stream.ReadBoolean();
            parent.FrameNameTableFlags = (FrameNameTable.NameTableFlags)stream.ReadUInt32(false);

            // Read ParentIndex from previous SDS
            int OldParentIndex1RefId = stream.ReadInt32(false);
            int OldParentIndex2RefId = stream.ReadInt32(false);

            // Temporarily store it as a reference.
            parent.AddRef(FrameEntryRefTypes.Parent1, OldParentIndex1RefId);
            parent.AddRef(FrameEntryRefTypes.Parent2, OldParentIndex2RefId);

            // We can finally add our new frame object
            FrameObjects.Add(parent.RefID, parent);

            // Push new FrameObject int OldRefLookupTable
            OldRefIDLookupTable.Add(OldRefID, parent);

            // Read how many children this frame has, and proceed to read them too.
            int count = stream.ReadInt32(false);

            for (int i = 0; i < count; i++)
            {
                FrameObjectBase child = ReadFrame(stream);
            }

            return(parent);
        }
Exemplo n.º 18
0
        public void SaveFramesToFile(FrameObjectBase frame)
        {
            FramePack Packet = new FramePack();

            Packet.WriteToFile(frame);
        }
Exemplo n.º 19
0
        public void ReadFromFile(MemoryStream reader, bool isBigEndian)
        {
            header = new FrameHeader();
            header.ReadFromFile(reader, isBigEndian);

            int j = 0;

            for (int i = 0; i != header.SceneFolders.Count; i++)
            {
                frameScenes.Add(header.SceneFolders[i].RefID, header.SceneFolders[i]);
                NewFrames.Add(new FrameHolder(j++, header.SceneFolders[i]));
            }
            for (int i = 0; i != header.NumGeometries; i++)
            {
                FrameGeometry geo = new FrameGeometry(reader, isBigEndian);
                frameGeometries.Add(geo.RefID, geo);
                NewFrames.Add(new FrameHolder(j++, geo));
            }
            for (int i = 0; i != header.NumMaterialResources; i++)
            {
                FrameMaterial mat = new FrameMaterial(reader, isBigEndian);
                frameMaterials.Add(mat.RefID, mat);
                NewFrames.Add(new FrameHolder(j++, mat));
            }
            for (int i = 0; i != header.NumBlendInfos; i++)
            {
                FrameBlendInfo blendInfo = new FrameBlendInfo(reader, isBigEndian);
                frameBlendInfos.Add(blendInfo.RefID, blendInfo);
                NewFrames.Add(new FrameHolder(j++, blendInfo));
            }
            for (int i = 0; i != header.NumSkeletons; i++)
            {
                FrameSkeleton skeleton = new FrameSkeleton(reader, isBigEndian);
                frameSkeletons.Add(skeleton.RefID, skeleton);
                NewFrames.Add(new FrameHolder(j++, skeleton));
            }
            for (int i = 0; i != header.NumSkelHierachies; i++)
            {
                FrameSkeletonHierachy skeletonHierachy = new FrameSkeletonHierachy(reader, isBigEndian);
                frameSkeletonHierachies.Add(skeletonHierachy.RefID, skeletonHierachy);
                NewFrames.Add(new FrameHolder(j++, skeletonHierachy));
            }

            int[] objectTypes = new int[header.NumObjects];
            int   numBlocks   = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;

            if (header.NumObjects > 0)
            {
                for (int i = 0; i != header.NumObjects; i++)
                {
                    objectTypes[i] = reader.ReadInt32(isBigEndian);
                }

                for (int i = 0; i != header.NumObjects; i++)
                {
                    FrameObjectBase newObject = new FrameObjectBase();
                    if (objectTypes[i] == (int)ObjectType.Joint)
                    {
                        newObject = new FrameObjectJoint(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.SingleMesh)
                    {
                        newObject = new FrameObjectSingleMesh(reader, isBigEndian);
                        FrameObjectSingleMesh mesh = newObject as FrameObjectSingleMesh;

                        if (mesh.MeshIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Mesh, GetEntryFromIdx(mesh.MeshIndex).Data.RefID);
                            mesh.Geometry = frameGeometries[mesh.Refs["Mesh"]];
                        }

                        if (mesh.MaterialIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Material, GetEntryFromIdx(mesh.MaterialIndex).Data.RefID);
                            mesh.Material = frameMaterials[mesh.Refs["Material"]];
                        }
                    }
                    else if (objectTypes[i] == (int)ObjectType.Frame)
                    {
                        newObject = new FrameObjectFrame(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Light)
                    {
                        newObject = new FrameObjectLight(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Camera)
                    {
                        newObject = new FrameObjectCamera(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Component_U00000005)
                    {
                        newObject = new FrameObjectComponent_U005(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Sector)
                    {
                        newObject = new FrameObjectSector(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Dummy)
                    {
                        newObject = new FrameObjectDummy(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.ParticleDeflector)
                    {
                        newObject = new FrameObjectDeflector(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Area)
                    {
                        newObject = new FrameObjectArea(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Target)
                    {
                        newObject = new FrameObjectTarget(reader, isBigEndian);
                    }

                    else if (objectTypes[i] == (int)ObjectType.Model)
                    {
                        FrameObjectModel mesh = new FrameObjectModel(reader, isBigEndian);
                        mesh.ReadFromFile(reader, isBigEndian);
                        mesh.ReadFromFilePart2(reader, isBigEndian, (FrameSkeleton)GetEntryFromIdx(mesh.SkeletonIndex).Data, (FrameBlendInfo)GetEntryFromIdx(mesh.BlendInfoIndex).Data);
                        mesh.AddRef(FrameEntryRefTypes.Mesh, GetEntryFromIdx(mesh.MeshIndex).Data.RefID);
                        mesh.Geometry = frameGeometries[mesh.Refs[FrameEntry.MeshRef]];
                        mesh.AddRef(FrameEntryRefTypes.Material, GetEntryFromIdx(mesh.MaterialIndex).Data.RefID);
                        mesh.Material = frameMaterials[mesh.Refs[FrameEntry.MaterialRef]];
                        mesh.AddRef(FrameEntryRefTypes.BlendInfo, GetEntryFromIdx(mesh.BlendInfoIndex).Data.RefID);
                        mesh.BlendInfo = frameBlendInfos[mesh.Refs[FrameEntry.BlendInfoRef]];
                        mesh.AddRef(FrameEntryRefTypes.Skeleton, GetEntryFromIdx(mesh.SkeletonIndex).Data.RefID);
                        mesh.Skeleton = frameSkeletons[mesh.Refs[FrameEntry.SkeletonRef]];
                        mesh.AddRef(FrameEntryRefTypes.SkeletonHierachy, GetEntryFromIdx(mesh.SkeletonHierachyIndex).Data.RefID);
                        mesh.SkeletonHierarchy = frameSkeletonHierachies[mesh.Refs[FrameEntry.SkeletonHierRef]];
                        newObject = mesh;
                    }
                    else if (objectTypes[i] == (int)ObjectType.Collision)
                    {
                        newObject = new FrameObjectCollision(reader, isBigEndian);
                    }

                    frameObjects.Add(newObject.RefID, newObject);
                    NewFrames.Add(new FrameHolder(i + numBlocks, newObject));
                }
            }
            objectTypes = null;
            DefineFrameBlockParents();
        }
Exemplo n.º 20
0
        private void SaveFrame(FrameObjectBase frame, BinaryWriter writer)
        {
            //is this even needed? hmm.
            Debug.WriteLine(frame.ToString());
            if (frame.GetType() == typeof(FrameObjectArea))
            {
                writer.Write((ushort)ObjectType.Area);
                (frame as FrameObjectArea).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectCamera))
            {
                writer.Write((ushort)ObjectType.Camera);
                (frame as FrameObjectCamera).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectCollision))
            {
                writer.Write((ushort)ObjectType.Collision);
                (frame as FrameObjectCollision).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectComponent_U005))
            {
                writer.Write((ushort)ObjectType.Component_U00000005);
                (frame as FrameObjectComponent_U005).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectDummy))
            {
                writer.Write((ushort)ObjectType.Dummy);
                (frame as FrameObjectDummy).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectDeflector))
            {
                writer.Write((ushort)ObjectType.ParticleDeflector);
                (frame as FrameObjectDeflector).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectFrame))
            {
                writer.Write((ushort)ObjectType.Frame);
                (frame as FrameObjectFrame).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectJoint))
            {
                writer.Write((ushort)ObjectType.Joint);
                (frame as FrameObjectJoint).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectLight))
            {
                writer.Write((ushort)ObjectType.Light);
                (frame as FrameObjectLight).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectModel))
            {
                var mesh = (frame as FrameObjectModel);
                writer.Write((ushort)ObjectType.Model);
                mesh.WriteToFile(writer);
                mesh.Geometry.WriteToFile(writer);
                mesh.Material.WriteToFile(writer);
                mesh.BlendInfo.WriteToFile(writer);
                mesh.Skeleton.WriteToFile(writer);
                mesh.SkeletonHierarchy.WriteToFile(writer);

                foreach (var lod in mesh.Geometry.LOD)
                {
                    using (var stream = new MemoryStream())
                    {
                        SceneData.IndexBufferPool.GetBuffer(lod.IndexBufferRef.Hash).WriteToFile(stream, false);
                        SceneData.VertexBufferPool.GetBuffer(lod.VertexBufferRef.Hash).WriteToFile(stream, false);
                        writer.Write(stream.ToArray());
                    }
                }
            }
            else if (frame.GetType() == typeof(FrameObjectSector))
            {
                writer.Write((ushort)ObjectType.Sector);
                (frame as FrameObjectSector).WriteToFile(writer);
            }
            else if (frame.GetType() == typeof(FrameObjectSingleMesh))
            {
                var mesh = (frame as FrameObjectSingleMesh);
                writer.Write((ushort)ObjectType.SingleMesh);
                mesh.WriteToFile(writer);
                mesh.Geometry.WriteToFile(writer);
                mesh.Material.WriteToFile(writer);

                foreach (var lod in mesh.Geometry.LOD)
                {
                    using (var stream = new MemoryStream())
                    {
                        SceneData.IndexBufferPool.GetBuffer(lod.IndexBufferRef.Hash).WriteToFile(stream, false);
                        SceneData.VertexBufferPool.GetBuffer(lod.VertexBufferRef.Hash).WriteToFile(stream, false);
                        writer.Write(stream.ToArray());
                    }
                }
            }
            else if (frame.GetType() == typeof(FrameObjectTarget))
            {
                writer.Write((ushort)ObjectType.Target);
                (frame as FrameObjectTarget).WriteToFile(writer);
            }
            else
            {
                writer.Write(frame.Type);
                frame.WriteToFile(writer);
            }

            writer.Write(frame.Children.Count);
            for (int i = 0; i < frame.Children.Count; i++)
            {
                SaveFrame(frame.Children[i], writer);
            }
        }
Exemplo n.º 21
0
        public TreeNode BuildTree(FrameNameTable.FrameNameTable table)
        {
            TreeNode root = new TreeNode("FrameResource Contents");

            root.Tag = header;

            int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;
            Dictionary <int, TreeNode> parsedNodes   = new Dictionary <int, TreeNode>();
            Dictionary <int, TreeNode> notAddedNodes = new Dictionary <int, TreeNode>();

            //Add scene groups into the scene viewer.
            for (int i = 0; i != frameScenes.Count; i++)
            {
                FrameHeaderScene scene = frameScenes.Values.ElementAt(i);
                TreeNode         node  = new TreeNode(scene.ToString());
                node.Tag  = scene;
                node.Name = scene.RefID.ToString();
                parsedNodes.Add(i, node);
                root.Nodes.Add(node);
            }

            ////add entries from the table, add table data and then add to scene viewer.
            for (int i = 0; i != table.FrameData.Length; i++)
            {
                if (table.FrameData[i].FrameIndex == -1)
                {
                    continue;
                }

                var             frameData = table.FrameData[i];
                FrameObjectBase fObject   = (GetEntryFromIdx(numBlocks + frameData.FrameIndex).Data as FrameObjectBase);
                fObject.IsOnFrameTable      = true;
                fObject.FrameNameTableFlags = table.FrameData[i].Flags;
                int p1idx   = numBlocks + fObject.ParentIndex1.Index;
                int p2idx   = numBlocks + fObject.ParentIndex2.Index;
                int thisKey = numBlocks + table.FrameData[i].FrameIndex;

                TreeNode node = (!parsedNodes.ContainsKey(thisKey)) ? new TreeNode(fObject.ToString()) : parsedNodes[thisKey];
                node.Tag  = fObject;
                node.Name = fObject.RefID.ToString();

                if (p1idx == -1 && p2idx == -1)
                {
                    //might be temp? it fixes cars loading in or non binded entries.
                    root.Nodes.Add(node);
                    continue;
                }
                else
                {
                    FrameEntry pBase = (GetEntryFromIdx(p2idx).Data as FrameEntry);
                    TreeNode[] nodes = root.Nodes.Find(pBase.RefID.ToString(), true);

                    if (nodes.Length > 0)
                    {
                        nodes[0].Nodes.Add(node);
                    }
                }

                if (!parsedNodes.ContainsKey(thisKey))
                {
                    parsedNodes.Add(thisKey, node);
                }
            }

            foreach (FrameHolder holder in NewFrames)
            {
                FrameObjectBase fObject = holder.Data as FrameObjectBase;

                if (fObject == null)
                {
                    continue;
                }

                TreeNode node = (!parsedNodes.ContainsKey(holder.Idx)) ? new TreeNode(fObject.ToString()) : parsedNodes[holder.Idx];
                node.Tag  = fObject;
                node.Name = fObject.RefID.ToString();

                if (!parsedNodes.ContainsKey(holder.Idx))
                {
                    parsedNodes.Add(holder.Idx, node);
                }
            }

            foreach (FrameHolder holder in NewFrames)
            {
                FrameObjectBase fObject = holder.Data as FrameObjectBase;

                if (fObject == null)
                {
                    continue;
                }

                if (fObject.ParentIndex1.Index != -1)
                {
                    parsedNodes[fObject.ParentIndex1.Index].Nodes.Add(parsedNodes[holder.Idx]);
                }
                else if (fObject.ParentIndex2.Index != -1)
                {
                    parsedNodes[fObject.ParentIndex2.Index].Nodes.Add(parsedNodes[holder.Idx]);
                }
                else if (fObject.ParentIndex1.Index == -1 && fObject.ParentIndex2.Index == -1)
                {
                    root.Nodes.Add(parsedNodes[holder.Idx]);
                }
                else
                {
                    Debug.WriteLine("Not added {0}", holder.Data);
                }
            }
            return(root);
        }
Exemplo n.º 22
0
        public void DefineFrameBlockParents()
        {
            for (int i = 0; i < frameObjects.Count; i++)
            {
                var             entry = (frameObjects.ElementAt(i));
                FrameObjectBase obj   = (entry.Value as FrameObjectBase);

                if (obj == null)
                {
                    continue;
                }

                if (obj is FrameObjectModel)
                {
                    FrameObjectModel model = (obj as FrameObjectModel);

                    foreach (var attachment in model.AttachmentReferences)
                    {
                        attachment.Attachment = (frameObjects.ElementAt(attachment.AttachmentIndex - GetBlockCount).Value as FrameObjectBase);
                    }
                }

                if (obj.ParentIndex1.Index > -1)
                {
                    if (obj.ParentIndex1.Index <= (frameScenes.Count - 1) && (frameScenes.Count - 1) != -1)
                    {
                        FrameHeaderScene scene = (frameScenes.ElementAt(obj.ParentIndex1.Index).Value as FrameHeaderScene);
                        obj.ParentIndex1.RefID = scene.RefID;
                        obj.ParentIndex1.Name  = scene.Name.ToString();
                        scene.Children.Add(obj);
                    }
                    else if (obj.ParentIndex1.Index >= GetBlockCount)
                    {
                        FrameObjectBase parent = GetObjectFromIndex(obj.ParentIndex1.Index - GetBlockCount);
                        obj.ParentIndex1.RefID = parent.RefID;
                        obj.ParentIndex1.Name  = parent.Name.ToString();
                        obj.Parent             = parent;
                        parent.Children.Add(obj);
                    }
                    else
                    {
                        throw new Exception("Unhandled Frame!");
                    }
                    obj.AddRef(FrameEntryRefTypes.Parent1, obj.ParentIndex1.RefID);
                }

                if (obj.ParentIndex2.Index > -1)
                {
                    if (obj.ParentIndex2.Index <= (frameScenes.Count - 1) && (frameScenes.Count - 1) != -1)
                    {
                        FrameHeaderScene scene = (frameScenes.ElementAt(obj.ParentIndex2.Index).Value as FrameHeaderScene);
                        obj.ParentIndex2.RefID = scene.RefID;
                        obj.ParentIndex2.Name  = scene.Name.ToString();
                        if (obj.Parent == null)
                        {
                            scene.Children.Add(obj);
                        }
                    }
                    else if (obj.ParentIndex2.Index >= GetBlockCount)
                    {
                        FrameObjectBase parent = GetObjectFromIndex(obj.ParentIndex2.Index - GetBlockCount);
                        obj.ParentIndex2.RefID = parent.RefID;
                        obj.ParentIndex2.Name  = parent.Name.ToString();
                        obj.Root = parent;
                        if (obj.Parent == null)
                        {
                            parent.Children.Add(obj);
                        }
                    }
                    else
                    {
                        throw new Exception("Unhandled Frame!");
                    }

                    obj.AddRef(FrameEntryRefTypes.Parent2, obj.ParentIndex2.RefID);
                }
                obj.SetWorldTransform();
            }
        }
Exemplo n.º 23
0
        public void UpdateFrameData()
        {
            SanitizeFrameData();
            int currentCount = 0;

            List <FrameHolder> updatedFrames = new List <FrameHolder>();

            foreach (KeyValuePair <int, FrameHeaderScene> entry in frameScenes)
            {
                updatedFrames.Add(new FrameHolder(currentCount++, entry.Value));
            }

            foreach (KeyValuePair <int, FrameGeometry> entry in frameGeometries)
            {
                updatedFrames.Add(new FrameHolder(currentCount++, entry.Value));
            }

            foreach (KeyValuePair <int, FrameMaterial> entry in frameMaterials)
            {
                updatedFrames.Add(new FrameHolder(currentCount++, entry.Value));
            }

            foreach (KeyValuePair <int, FrameBlendInfo> entry in frameBlendInfos)
            {
                updatedFrames.Add(new FrameHolder(currentCount++, entry.Value));
            }

            foreach (KeyValuePair <int, FrameSkeleton> entry in frameSkeletons)
            {
                updatedFrames.Add(new FrameHolder(currentCount++, entry.Value));
            }

            foreach (KeyValuePair <int, FrameSkeletonHierachy> entry in frameSkeletonHierachies)
            {
                updatedFrames.Add(new FrameHolder(currentCount++, entry.Value));
            }

            //We have to add the objects to the new frame AND THEN update refs. This is kind of odd, and I think i've done something wrong.
            int objectPosStart = currentCount;

            for (int i = 0; i != frameObjects.Count; i++)
            {
                FrameObjectBase block = (frameObjects.ElementAt(i).Value as FrameObjectBase);
                updatedFrames.Add(new FrameHolder(currentCount++, block));
            }
            for (int i = objectPosStart; i != updatedFrames.Count; i++)
            {
                FrameObjectBase block = (updatedFrames[i].Data as FrameObjectBase);
                Console.WriteLine("Working on block " + block.Name.String);

                if (block.Refs.ContainsKey("Parent1"))
                {
                    block.ParentIndex1.Index = GetLocalEntryFromRefID(updatedFrames, block.Refs["Parent1"]).Idx;
                }
                else
                {
                    block.ParentIndex1.Index = -1;
                }

                if (block.Refs.ContainsKey("Parent2"))
                {
                    block.ParentIndex2.Index = GetLocalEntryFromRefID(updatedFrames, block.Refs["Parent2"]).Idx;
                }
                else
                {
                    block.ParentIndex2.Index = -1;
                }

                if (block.Type == typeof(FrameObjectSingleMesh).ToString())
                {
                    FrameObjectSingleMesh mesh = (block as FrameObjectSingleMesh);
                    Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));

                    if (mesh.MaterialIndex != -1)
                    {
                        mesh.MaterialIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Material"]).Idx;
                    }

                    if (mesh.MeshIndex != -1)
                    {
                        mesh.MeshIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["Mesh"]).Idx;
                    }

                    block = mesh;
                    Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                }
                if (block.Type == typeof(FrameObjectModel).ToString())
                {
                    FrameObjectModel mesh = (block as FrameObjectModel);
                    Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                    mesh.MaterialIndex         = GetLocalEntryFromRefID(updatedFrames, block.Refs["Material"]).Idx;
                    mesh.MeshIndex             = GetLocalEntryFromRefID(updatedFrames, block.Refs["Mesh"]).Idx;
                    mesh.BlendInfoIndex        = GetLocalEntryFromRefID(updatedFrames, block.Refs["BlendInfo"]).Idx;
                    mesh.SkeletonIndex         = GetLocalEntryFromRefID(updatedFrames, block.Refs["Skeleton"]).Idx;
                    mesh.SkeletonHierachyIndex = GetLocalEntryFromRefID(updatedFrames, block.Refs["SkeletonHierachy"]).Idx;
                    block = mesh;
                    Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                }
            }

            header.NumFolderNames       = frameScenes.Count;
            header.NumGeometries        = frameGeometries.Count;
            header.NumMaterialResources = frameMaterials.Count;
            header.NumBlendInfos        = frameBlendInfos.Count;
            header.NumSkeletons         = frameSkeletons.Count;
            header.NumSkelHierachies    = frameSkeletonHierachies.Count;
            header.NumObjects           = frameObjects.Count;
            header.NumFolderNames       = header.SceneFolders.Count;
            NewFrames = updatedFrames;
        }
Exemplo n.º 24
0
        public void UpdateFrameData()
        {
            SanitizeFrameData();

            int[] offsets = new int[7];
            offsets[0] = 0;
            offsets[1] = offsets[0] + frameScenes.Count;
            offsets[2] = offsets[1] + frameGeometries.Count;
            offsets[3] = offsets[2] + frameMaterials.Count;
            offsets[4] = offsets[3] + frameBlendInfos.Count;
            offsets[5] = offsets[4] + frameSkeletons.Count;
            offsets[6] = offsets[5] + frameSkeletonHierachies.Count;

            for (int i = 0; i < frameObjects.Count; i++)
            {
                FrameObjectBase block = (frameObjects.ElementAt(i).Value as FrameObjectBase);
                Console.WriteLine("Working on block " + block.Name.String);

                if (block.Refs.ContainsKey(FrameEntry.Parent1Ref))
                {
                    if (frameScenes.ContainsKey(block.Refs[FrameEntry.Parent1Ref]))
                    {
                        block.ParentIndex1.Index = frameScenes.IndexOfValue(block.Refs[FrameEntry.Parent1Ref]);
                    }
                    else
                    {
                        block.ParentIndex1.Index = offsets[6] + (block.Refs.ContainsKey(FrameEntry.Parent1Ref) ? frameObjects.IndexOfValue(block.Refs[FrameEntry.Parent1Ref]) : -1);
                    }
                }


                if (block.Refs.ContainsKey(FrameEntry.Parent2Ref))
                {
                    if (frameScenes.ContainsKey(block.Refs[FrameEntry.Parent2Ref]))
                    {
                        block.ParentIndex2.Index = frameScenes.IndexOfValue(block.Refs[FrameEntry.Parent2Ref]);
                    }
                    else
                    {
                        block.ParentIndex2.Index = offsets[6] + (block.Refs.ContainsKey(FrameEntry.Parent2Ref) ? frameObjects.IndexOfValue(block.Refs[FrameEntry.Parent2Ref]) : -1);
                    }
                }


                if (block.Type == typeof(FrameObjectSingleMesh).ToString())
                {
                    FrameObjectSingleMesh mesh = (block as FrameObjectSingleMesh);
                    Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                    if (mesh.MeshIndex != -1)
                    {
                        mesh.MeshIndex = offsets[1] + frameGeometries.IndexOfValue(mesh.Refs[FrameEntry.GeometryRef]);
                    }
                    if (mesh.MaterialIndex != -1)
                    {
                        mesh.MaterialIndex = offsets[2] + frameMaterials.IndexOfValue(mesh.Refs[FrameEntry.MaterialRef]);
                    }
                    block = mesh;
                    Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                }
                if (block.Type == typeof(FrameObjectModel).ToString())
                {
                    FrameObjectModel mesh = (block as FrameObjectModel);
                    Console.WriteLine(string.Format("Updating: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                    if (mesh.MeshIndex != -1)
                    {
                        mesh.MeshIndex = offsets[1] + frameGeometries.IndexOfValue(mesh.Refs[FrameEntry.GeometryRef]);
                    }
                    if (mesh.MaterialIndex != -1)
                    {
                        mesh.MaterialIndex = offsets[2] + frameMaterials.IndexOfValue(mesh.Refs[FrameEntry.MaterialRef]);
                    }
                    if (mesh.BlendInfoIndex != -1)
                    {
                        mesh.BlendInfoIndex = offsets[3] + frameBlendInfos.IndexOfValue(mesh.Refs[FrameEntry.BlendInfoRef]);
                    }
                    if (mesh.SkeletonIndex != -1)
                    {
                        mesh.SkeletonIndex = offsets[4] + frameSkeletons.IndexOfValue(mesh.Refs[FrameEntry.SkeletonRef]);
                    }
                    if (mesh.SkeletonHierachyIndex != -1)
                    {
                        mesh.SkeletonHierachyIndex = offsets[5] + frameSkeletonHierachies.IndexOfValue(mesh.Refs[FrameEntry.SkeletonHierRef]);
                    }

                    foreach (var attachment in mesh.AttachmentReferences)
                    {
                        attachment.AttachmentIndex = offsets[6] + frameObjects.IndexOfValue(attachment.Attachment.RefID);
                    }

                    block = mesh;
                    Console.WriteLine(string.Format("Updated: {0}, {1}, {2}", block.Name, mesh.MaterialIndex, mesh.MeshIndex));
                }
            }

            header.SceneFolders = frameScenes.Values.ToList();

            header.NumFolderNames       = frameScenes.Count;
            header.NumGeometries        = frameGeometries.Count;
            header.NumMaterialResources = frameMaterials.Count;
            header.NumBlendInfos        = frameBlendInfos.Count;
            header.NumSkeletons         = frameSkeletons.Count;
            header.NumSkelHierachies    = frameSkeletonHierachies.Count;
            header.NumObjects           = frameObjects.Count;
            header.NumFolderNames       = frameScenes.Count;
        }