Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }