public Scene MakeScene(ILoader loader)
        {
            Scene scene = new Scene();

            foreach (uint instance in Instances)
            {
                BundleEntry modelEntry = Entry.Archive.GetEntryByID(instance);
                if (modelEntry == null)
                {
                    string file = BundleCache.GetFileByEntryID(instance);
                    if (!string.IsNullOrEmpty(file))
                    {
                        BundleArchive archive = BundleArchive.Read(file);
                        modelEntry = archive.GetEntryByID(instance);
                    }
                }

                if (modelEntry != null)
                {
                    BundleEntry renderableEntry = modelEntry.GetDependencies()[0].Entry;
                    Renderable  renderable      = new Renderable();
                    renderable.Read(renderableEntry, null);                     // TODO: Null Loader
                    SceneObject sceneObject = new SceneObject(instance.ToString("X8"), renderable.Model);
                    //sceneObject.Transform = instance.Transform;

                    scene.AddObject(sceneObject);
                }
            }

            return(scene);
        }
示例#2
0
        private string GetInfo()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("ID: 0x" + _entry.ID.ToString("X8"));
            sb.AppendLine("Type: " + _entry.Type);
            sb.AppendLine("Has Header: " + _entry.HasHeader);
            sb.AppendLine("Has Body: " + _entry.HasBody);
            List <BundleDependency> dependencies = _entry.GetDependencies();

            if (dependencies.Count > 0)
            {
                sb.AppendLine("Dependencies[" + dependencies.Count + "] = {");
                for (int i = 0; i < dependencies.Count; i++)
                {
                    BundleDependency bundleDependency = dependencies[i];
                    sb.AppendLine("    " + bundleDependency.ToString());
                }
                sb.AppendLine("}");
            }
            else
            {
                sb.AppendLine("Dependencies[" + dependencies.Count + "];");
            }

            return(sb.ToString());
        }
        public bool Read(BundleEntry entry, ILoader loader = null)
        {
            Clear();

            Entry = entry;

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            Unknown1 = br.ReadInt32();
            int instanceCount = br.ReadInt32();

            Unknown2 = br.ReadInt32();
            Unknown3 = br.ReadInt32();

            for (int i = 0; i < instanceCount; i++)
            {
                ModelInstance instance = ModelInstance.Read(br);

                instance.ModelEntryID = entry.GetDependencies()[i].EntryID;

                Instances.Add(instance);
            }

            RemainingBytes = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));

            br.Close();
            ms.Close();

            //_scene = MakeScene(loader);

            return(true);
        }
        public static MaterialEntry Read(BundleEntry entry)
        {
            MaterialEntry result = new MaterialEntry();

            List <BundleDependency> dependencies = entry.GetDependencies();

            foreach (BundleDependency dependency in dependencies)
            {
                ulong id = dependency.EntryID;

                //DebugTimer t = DebugTimer.Start("LoadDep");
                BundleEntry descEntry1 = entry.Archive.GetEntryByID(id);
                if (descEntry1 == null)
                {
                    string file = BundleCache.GetFileByEntryID(id);
                    if (!string.IsNullOrEmpty(file))
                    {
                        BundleArchive archive = BundleArchive.Read(file);
                        descEntry1 = archive.GetEntryByID(id);
                    }
                }
                //t.StopLog();

                //DebugTimer t2 = DebugTimer.Start("LoadTextureState");
                if (descEntry1 != null && descEntry1.Type == EntryType.TextureState)
                {
                    TextureState state = TextureState.Read(descEntry1);

                    result.TextureStates.Add(state);
                }
                //t2.StopLog();
            }

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            // TODO: Read Material

            br.Close();
            ms.Close();

            result.Color = Color.White;

            if (result.TextureStates.Count > 0)
            {
                result.DiffuseMap = result.TextureStates[0].Texture;
            }
            if (result.TextureStates.Count > 1)
            {
                result.NormalMap = result.TextureStates[1].Texture;
            }
            if (result.TextureStates.Count > 2)
            {
                result.SpecularMap = result.TextureStates[2].Texture;
            }

            return(result);
        }
        public bool Read(BundleEntry entry, ILoader loader)
        {
            Clear();

            Entry = entry;

            // TODO: Process Data

            for (int i = 0; i < entry.GetDependencies().Count; i++)
            {
                Instances.Add(entry.GetDependencies()[i].EntryID);
            }

            _scene = MakeScene(loader);

            return(true);
        }
        public static TextureState Read(BundleEntry entry)
        {
            TextureState result = new TextureState();

            List <BundleDependency> dependencies = entry.GetDependencies();

            foreach (BundleDependency dependency in dependencies)
            {
                ulong id = dependency.EntryID;

                if (TextureCache.Contains(id))
                {
                    result.Texture = TextureCache.GetTexture(id);
                }
                else
                {
                    BundleEntry descEntry1 = entry.Archive.GetEntryByID(id);
                    if (descEntry1 == null)
                    {
                        string file = BundleCache.GetFileByEntryID(id);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            if (archive != null)
                            {
                                descEntry1 = archive.GetEntryByID(id);
                            }
                        }
                    }

                    if (descEntry1 != null && descEntry1.Type == EntryType.Texture)
                    {
                        if (entry.Console)
                        {
                            result.Texture = GameImage.GetImagePS3(descEntry1.EntryBlocks[0].Data, descEntry1.EntryBlocks[1].Data);
                        }
                        else
                        {
                            result.Texture = GameImage.GetImage(descEntry1.EntryBlocks[0].Data, descEntry1.EntryBlocks[1].Data);
                        }

                        if (result.Texture != null)
                        {
                            TextureCache.AddToCache(id, result.Texture);
                        }

                        break;
                    }
                }
            }

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            // TODO: Read Texture State

            br.Close();
            ms.Close();

            return(result);
        }
        public Scene MakeScene(ILoader loader = null)
        {
            //TextureState.ResetCache();

            Scene scene = new Scene();

            Dictionary <ulong, Renderable> models = new Dictionary <ulong, Renderable>();

            int i     = 0;
            int index = 1;

            foreach (ModelInstance instance in Instances)
            {
                int progress = (index - 1) * 100 / Instances.Count;
                loader?.SetProgress(progress);

                loader?.SetStatus("Loading(" + progress.ToString("D2") + "%): ModelInstance: " + index + "/" + Instances.Count);
                //DebugTimer t = DebugTimer.Start("ModelInstance[" + index + "/" + Instances.Count + "]");
                index++;

                if (!InRange(instance))
                {
                    continue;
                }

                if (models.ContainsKey(instance.ModelEntryID))
                {
                    Renderable  renderable  = models[instance.ModelEntryID];
                    SceneObject sceneObject = new SceneObject(instance.ModelEntryID.ToString("X8"), renderable.Model);
                    sceneObject.ID        = i.ToString();
                    sceneObject.Transform = instance.Transform;

                    scene.AddObject(sceneObject);
                }
                else
                {
                    BundleEntry modelEntry = Entry.Archive.GetEntryByID(instance.ModelEntryID);
                    if (modelEntry == null)
                    {
                        string file = BundleCache.GetFileByEntryID(instance.ModelEntryID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            modelEntry = archive.GetEntryByID(instance.ModelEntryID);
                        }
                    }

                    if (modelEntry != null)
                    {
                        BundleEntry renderableEntry = modelEntry.GetDependencies()[0].Entry;
                        Renderable  renderable      = new Renderable();
                        renderable.Read(renderableEntry, null);                         // TODO: Null Loader
                        models.Add(instance.ModelEntryID, renderable);
                        SceneObject sceneObject =
                            new SceneObject(instance.ModelEntryID.ToString("X8"), renderable.Model);
                        sceneObject.ID        = i.ToString();
                        sceneObject.Transform = instance.Transform;

                        scene.AddObject(sceneObject);
                    }
                }
                i++;
                //t.StopLog();
            }
            loader?.SetProgress(100);

            //TextureState.ResetCache();

            return(scene);
        }
示例#8
0
        public bool Read(BundleEntry entry, ILoader loader)
        {
            Clear();

            List <BundleDependency> dependencies = entry.GetDependencies();

            ID = entry.ID;

            MemoryStream  ms = entry.MakeStream();
            BinaryReader2 br = new BinaryReader2(ms);

            br.BigEndian = entry.Console;

            Unknown1      = br.ReadSingle();
            Unknown2      = br.ReadSingle();
            Unknown3      = br.ReadSingle();
            Unknown4      = br.ReadSingle();
            Unknown5      = br.ReadInt16();
            MeshCount     = br.ReadInt16();
            StartOffset   = br.ReadInt32();
            Unknown8      = br.ReadInt32();
            Unknown9      = br.ReadInt32();
            Unknown10     = br.ReadInt16();
            Unknown10_1   = br.ReadInt16();
            UnknownOffset = br.ReadInt32();
            Unknown12     = br.ReadInt32();
            Unknown13     = br.ReadInt32();

            br.BaseStream.Position = StartOffset;

            for (int i = 0; i < MeshCount; i++)
            {
                int offset = br.ReadInt32();
                MeshVertexOffsets.Add(offset);
            }

            /*if (entry.Platform == BundlePlatform.PS3)
             * {
             *  br.BaseStream.Position += 16 - (br.BaseStream.Position % 16);
             *  result.NumIndices = br.ReadInt16();
             *  result.Unknown = br.ReadInt16();
             * }
             * else
             * {*/
            NumIndices = br.ReadInt32();
            //}

            Unknown15 = br.ReadInt32();
            Unknown16 = br.ReadInt32();
            Unknown17 = br.ReadInt32();
            // some extra data here in BPR

            br.BaseStream.Position = UnknownOffset;
            if (NumIndices == 0) // BPR
            {
                // ???
                br.BaseStream.Position += 12;
            }
            VertexBlockAddress = br.ReadInt32();
            Unknown18          = (NumIndices == 0) ? 0 : br.ReadInt32();
            VertexBlockSize    = br.ReadInt32();


            for (int i = 0; i < MeshCount; i++)
            {
                br.BaseStream.Position = MeshVertexOffsets[i];

                RenderableMesh mesh = new RenderableMesh();

                mesh.RotationMatrix   = br.ReadMatrix4();
                mesh.Unknown19        = br.ReadInt32();
                mesh.Unknown20        = br.ReadInt32();
                mesh.IndexOffsetCount = br.ReadInt32();
                if (NumIndices == 0) // BPR
                {
                    mesh.NumFaces = br.ReadInt32() / 3;
                }
                else
                {
                    mesh.NumVertices       = br.ReadInt32();
                    mesh.VertexOffsetCount = br.ReadInt32();
                    mesh.VertexOffsetCount = 0;
                    mesh.NumFaces          = br.ReadInt32();
                }
                int cPos = (int)br.BaseStream.Position;
                mesh.MaterialIDInternal = br.ReadInt32();
                foreach (BundleDependency dependency in dependencies)
                {
                    if (dependency.EntryPointerOffset == cPos)
                    {
                        mesh.MaterialID = dependency.EntryID;
                        break;
                    }
                }
                mesh.Unknown21         = br.ReadInt16();
                mesh.Unknown22         = br.ReadInt16();
                mesh.NumIndicesOffset  = br.ReadInt32();
                mesh.VerticesOffsetPtr = br.ReadInt32();

                mesh.VertexDescriptionsInternal = new int[6];
                mesh.VertexDescriptionIDs       = new ulong[6];
                for (int j = 0; j < mesh.VertexDescriptionsInternal.Length; j++)
                {
                    int pos = (int)br.BaseStream.Position;
                    foreach (BundleDependency dependency in dependencies)
                    {
                        if (dependency.EntryPointerOffset == pos)
                        {
                            mesh.VertexDescriptionIDs[j] = dependency.EntryID;
                            break;
                        }
                    }

                    mesh.VertexDescriptionsInternal[j] = br.ReadInt32();
                }

                Meshes.Add(mesh);
            }

            br.Close();
            ms.Close();

            loader?.SetStatus("Loading Meshes");
            for (int i = 0; i < Meshes.Count; i++)
            {
                RenderableMesh mesh = Meshes[i];

                int progress = (i + 1) * 100 / Meshes.Count;

                loader?.SetStatus("Loading Meshes: " + (i + 1) + "/" + Meshes.Count);
                loader?.SetProgress(progress);

                if (LoadMaterials)
                {
                    BundleEntry descEntry1 = entry.Archive.GetEntryByID(mesh.MaterialID);
                    if (descEntry1 == null)
                    {
                        string file = BundleCache.GetFileByEntryID(mesh.MaterialID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            descEntry1 = archive.GetEntryByID(mesh.MaterialID);
                        }
                    }

                    if (descEntry1 != null)
                    {
                        mesh.Material = MaterialEntry.Read(descEntry1);
                    }
                }

                mesh.VertexDescriptions = new VertexDesc[6];
                for (int j = 0; j < mesh.VertexDescriptions.Length; j++)
                {
                    ulong       vertexDescID = mesh.VertexDescriptionIDs[j];
                    BundleEntry descEntry    = entry.Archive.GetEntryByID(vertexDescID);
                    if (descEntry == null)
                    {
                        string file = BundleCache.GetFileByEntryID(vertexDescID);
                        if (!string.IsNullOrEmpty(file))
                        {
                            BundleArchive archive = BundleArchive.Read(file);
                            descEntry = archive.GetEntryByID(vertexDescID);
                        }
                    }

                    if (descEntry != null)
                    {
                        mesh.VertexDescriptions[j] = VertexDesc.Read(descEntry);
                    }
                }
            }

            ms           = entry.MakeStream(true);
            br           = new BinaryReader2(ms);
            br.BigEndian = entry.Console;
            ReadBody(br);
            br.Close();
            ms.Close();

            BuildModel();

            _scene = MakeScene(loader);

            return(true);
        }