示例#1
0
        /// <summary>
        /// Adds names onto ParentIndex1 and ParentIndex2. Called after the file has been read.
        /// Adds Refs also. These are needed to save a Frame file.
        /// </summary>
        public void DefineFrameBlockParents()
        {
            int numBlocks = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;

            for (int i = 0; i != frameObjects.Count; i++)
            {
                FrameObjectBase obj = (frameObjects.ElementAt(i).Value 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 = (frameObjects.ElementAt(obj.ParentIndex1.Index - numBlocks).Value as FrameObjectBase).RefID;
                        obj.ParentIndex1.Name  = (frameObjects.ElementAt(obj.ParentIndex1.Index - numBlocks).Value as FrameObjectBase).Name.String;
                    }
                    //else
                    //{
                    //    obj.ParentIndex1.RefID = (frameObjects.ElementAt(obj.ParentIndex1.Index).Value as FrameObjectBase).RefID;
                    //    obj.ParentIndex1.Name = (frameObjects.ElementAt(obj.ParentIndex1.Index).Value 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 = (frameObjects.ElementAt(obj.ParentIndex2.Index - numBlocks).Value as FrameObjectBase).RefID;
                        obj.ParentIndex2.Name  = (frameObjects.ElementAt(obj.ParentIndex2.Index - numBlocks).Value as FrameObjectBase).Name.String;
                    }
                    //else
                    //{
                    //    obj.ParentIndex2.RefID = (frameObjects.ElementAt(obj.ParentIndex2.Index).Value as FrameObjectBase).RefID;
                    //    obj.ParentIndex1.Name = (frameObjects.ElementAt(obj.ParentIndex2.Index).Value as FrameObjectBase).Name.String;
                    //}
                    obj.AddRef(FrameEntryRefTypes.Parent2, obj.ParentIndex2.RefID);
                }
            }
        }
        /// <summary>
        /// Builds the file from the FrameResource passed into this function.
        /// </summary>
        /// <param name="resource">the frame resource which the data is coming from.</param>
        public void BuildDataFromResource(FrameResource resource)
        {
            List <Data> tableData = new List <Data>();

            int[]    scenePos;
            string[] sceneNames;
            int      totalNumBlocks = resource.Header.SceneFolders.Length + resource.Header.NumGeometries + resource.Header.NumMaterialResources + resource.Header.NumBlendInfos + resource.Header.NumSkeletons + resource.Header.NumSkelHierachies;

            if (resource.Header.IsScene)
            {
                scenePos   = new int[resource.Header.NumFolderNames + 1];
                sceneNames = new string[resource.Header.NumFolderNames + 1];

                //add the actual scenes from the header, and then the <scenes> one.
                for (int i = 0; i != resource.Header.NumFolderNames; i++)
                {
                    names        += resource.Header.SceneFolders[i].Name.String;
                    names        += "\0";
                    scenePos[i]   = names.Length - resource.Header.SceneFolders[i].Name.String.Length - 1;
                    sceneNames[i] = resource.Header.SceneFolders[i].Name.String;
                }

                string scene = "<scene>\0";
                names += scene;
                scenePos[scenePos.Length - 1]     = names.Length - scene.Length;
                sceneNames[sceneNames.Length - 1] = scene;
            }
            else
            {
                scenePos      = new int[1];
                sceneNames    = new string[1];
                names        += "<scene>\0";
                scenePos[0]   = 0;
                sceneNames[0] = "<scene>\0";
            }

            for (int i = 0; i != resource.FrameObjects.Count; i++)
            {
                bool   addToTable = false;
                object block      = resource.FrameObjects.ElementAt(i).Value;

                //possible types to save? might change in the future however.
                if (block.GetType().BaseType == typeof(FrameObjectBase) || block.GetType().BaseType == typeof(FrameObjectJoint) || block.GetType().BaseType == typeof(FrameObjectSingleMesh))
                {
                    if ((block as FrameObjectBase).IsOnFrameTable)
                    {
                        addToTable = true;
                    }
                }

                if (addToTable)
                {
                    FrameObjectBase fBase = (block as FrameObjectBase);

                    if (fBase.ParentIndex1.Index == -1)
                    {
                        Data data = new Data();
                        data.Flags = fBase.FrameNameTableFlags;

                        //auto <scene>
                        int sceneIndex = scenePos.Length - 1;

                        //check if this is a scene. If it is, then we get the index for the scene names and pos.
                        if (resource.Header.IsScene && fBase.ParentIndex2.Index != -1)
                        {
                            sceneIndex = fBase.ParentIndex2.Index;
                        }

                        //set parent index.
                        data.Parent = (short)scenePos[sceneIndex];

                        //add name to string and set namepos1 For namepos2, check if this is a scene. If so, then use 0xFFFF.
                        data.NamePos1 = (ushort)names.Length;
                        names        += fBase.Name.String;
                        names        += "\0";
                        data.NamePos2 = (resource.Header.IsScene) ? (ushort)0xFFFF : data.NamePos1;

                        //set frameIndex. minus the blockID and then subtract it from the total number of blocks.
                        data.FrameIndex = (short)i;

                        tableData.Add(data);
                    }
                }
            }

            frameData    = tableData.ToArray();
            dataSize     = tableData.Count;
            stringLength = names.Length;
        }
示例#3
0
        /// <summary>
        /// Reads the file into the memory.
        /// </summary>
        /// <param name="reader"></param>
        public void ReadFromFile(BinaryReader reader)
        {
            header = new FrameHeader();
            header.ReadFromFile(reader);

            objectTypes = new int[header.NumObjects];
            frameBlocks = new int[header.SceneFolders.Length + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies];

            int j = 0;

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

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

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

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

                        if (mesh.MeshIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Mesh, frameBlocks[mesh.MeshIndex]);
                        }

                        if (mesh.MaterialIndex != -1)
                        {
                            mesh.AddRef(FrameEntryRefTypes.Material, frameBlocks[mesh.MaterialIndex]);
                        }
                    }
                    else if (objectTypes[i] == (int)ObjectType.Frame)
                    {
                        newObject = new FrameObjectFrame(reader);
                    }

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

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

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

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

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

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

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

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

                    else if (objectTypes[i] == (int)ObjectType.Model)
                    {
                        FrameObjectModel mesh = new FrameObjectModel(reader);
                        mesh.ReadFromFile(reader);
                        mesh.ReadFromFilePart2(reader, frameSkeletons[frameBlocks[mesh.SkeletonIndex]], frameBlendInfos[frameBlocks[mesh.BlendInfoIndex]]);
                        mesh.AddRef(FrameEntryRefTypes.Mesh, frameBlocks[mesh.MeshIndex]);
                        mesh.AddRef(FrameEntryRefTypes.Material, frameBlocks[mesh.MaterialIndex]);
                        mesh.AddRef(FrameEntryRefTypes.BlendInfo, frameBlocks[mesh.BlendInfoIndex]);
                        mesh.AddRef(FrameEntryRefTypes.Skeleton, frameBlocks[mesh.SkeletonIndex]);
                        mesh.AddRef(FrameEntryRefTypes.SkeletonHierachy, frameBlocks[mesh.SkeletonHierachyIndex]);
                        newObject = mesh;
                    }
                    else if (objectTypes[i] == (int)ObjectType.Collision)
                    {
                        newObject = new FrameObjectCollision(reader);
                    }

                    frameObjects.Add(newObject.RefID, newObject);
                }
            }
            DefineFrameBlockParents();
        }
示例#4
0
        /// <summary>
        /// This reconstructs the data.
        /// </summary>
        public void UpdateFrameData()
        {
            int totalResources = header.NumFolderNames + header.NumGeometries + header.NumMaterialResources + header.NumBlendInfos + header.NumSkeletons + header.NumSkelHierachies;

            Dictionary <int, object> newFrame = new Dictionary <int, object>();

            foreach (KeyValuePair <int, FrameHeaderScene> entry in frameScenes)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameGeometry> entry in frameGeometries)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameMaterial> entry in frameMaterials)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameBlendInfo> entry in frameBlendInfos)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameSkeleton> entry in frameSkeletons)
            {
                newFrame.Add(entry.Key, entry.Value);
            }
            foreach (KeyValuePair <int, FrameSkeletonHierachy> entry in frameSkeletonHierachies)
            {
                newFrame.Add(entry.Key, 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 = newFrame.Count;

            for (int i = 0; i != frameObjects.Count; i++)
            {
                FrameObjectBase block = (frameObjects.ElementAt(i).Value as FrameObjectBase);
                newFrame.Add(block.RefID, block);
            }
            for (int i = objectPosStart; i != newFrame.Count; i++)
            {
                FrameObjectBase block = (newFrame.ElementAt(i).Value as FrameObjectBase);
                Console.WriteLine("Working on block " + block.Name.String);

                if (block.Refs.ContainsKey("Parent1"))
                {
                    block.ParentIndex1.Index = newFrame.IndexOfValue(block.Refs["Parent1"]);
                }
                else
                {
                    block.ParentIndex1.Index = -1;
                }

                if (block.Refs.ContainsKey("Parent2"))
                {
                    block.ParentIndex2.Index = newFrame.IndexOfValue(block.Refs["Parent2"]);
                }
                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 = newFrame.IndexOfValue(mesh.Refs["Material"]);
                    }

                    if (mesh.MeshIndex != -1)
                    {
                        mesh.MeshIndex = newFrame.IndexOfValue(mesh.Refs["Mesh"]);
                    }

                    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         = newFrame.IndexOfValue(mesh.Refs["Material"]);
                    mesh.MeshIndex             = newFrame.IndexOfValue(mesh.Refs["Mesh"]);
                    mesh.BlendInfoIndex        = newFrame.IndexOfValue(mesh.Refs["BlendInfo"]);
                    mesh.SkeletonIndex         = newFrame.IndexOfValue(mesh.Refs["Skeleton"]);
                    mesh.SkeletonHierachyIndex = newFrame.IndexOfValue(mesh.Refs["SkeletonHierachy"]);
                    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;
        }