Пример #1
0
        bool ReconstructRawPcaData(Blam.CacheFile c,
                                   geometry_block_info_struct gbi)
        {
            int index = 0;
            int x;

            byte[][] data = gbi.GeometryBlock;

            if (data == null)
            {
                return(false);
            }

            foreach (geometry_block_resource_block gb in gbi.Resources)
            {
                using (IO.EndianReader er = new BlamLib.IO.EndianReader(data[index]))
                {
                    switch (gb.Type.Value)
                    {
                        #region TagBlock
                    case (int)geometry_block_resource_type.TagBlock:
                        int count = gb.GetCount();
                        switch (gb.PrimaryLocater.Value)
                        {
                        case OffsetVertexBuffers:
                            VertexBuffers.Resize(count);
                            VertexBuffers.Read(er);
                            break;
                        }
                        break;

                        #endregion
                        #region VertexBuffer
                    case (int)geometry_block_resource_type.VertexBuffer:
                        var vb_defs = (c.TagIndexManager as InternalCacheTagIndex).kVertexBuffers;

                        // HACK: Figure out why we PRT stores the vertex buffer in the geometry block info's
                        // "section data" and not in a tag block resource
                        if (VertexBuffers.Count == 0 && !ReadVertexBufferHack(c, gbi))
                        {
                            break;
                        }

                        var stream_readers = new Render.VertexBufferInterface.StreamReader[VertexBuffers.Count];
                        for (x = 0; x < VertexBuffers.Count; x++)
                        {
                            VertexBuffers[x].VertexBuffer.InitializeStreamReader(vb_defs, out stream_readers[x]);
                        }

                        int vertex_count = gb.Size.Value / VertexBuffers[0].VertexBuffer.StrideSize;
                        if (RawPcaData.Count == 0)
                        {
                            RawPcaData.Resize(vertex_count * 5);                                     // 5x as there are 5 fields in the Pca data
                        }
                        for (x = 0; x < vertex_count; x++)
                        {
                            ReconstructRawPcaData(x, gb, er, stream_readers);
                        }
                        break;
                        #endregion
                    }
                }
                index++;
            }

            VertexBuffers.DeleteAll();

            return(true);
        }
Пример #2
0
        /// <summary></summary>
        /// <param name="c"></param>
        /// <param name="section_info">Can be null if tag data doesn't have it</param>
        /// <param name="gbi"></param>
        /// <returns></returns>
        internal bool Reconstruct(Blam.CacheFile c,
                                  global_geometry_section_info_struct section_info,
                                  geometry_block_info_struct gbi)
        {
            int index = 0;
            int x;

            byte[][] data = gbi.GeometryBlock;

            if (data == null)
            {
                return(false);
            }

            foreach (geometry_block_resource_block gb in gbi.Resources)
            {
                using (IO.EndianReader er = new BlamLib.IO.EndianReader(data[index]))
                {
                    switch (gb.Type.Value)
                    {
                        #region TagBlock
                    case (int)geometry_block_resource_type.TagBlock:
                        int count = gb.GetCount();
                        switch (gb.PrimaryLocater.Value)
                        {
                        case OffsetParts:
                            Parts.Resize(count);
                            Parts.Read(er);
                            break;

                        case OffsetSubparts:
                            Subparts.Resize(count);
                            Subparts.Read(er);
                            break;

                        case OffsetVisibilityBounds:
                            VisibilityBounds.Resize(count);
                            VisibilityBounds.Read(er);
                            break;

                        case OffsetStripIndices:
                            StripIndices.Resize(count);
                            StripIndices.Read(er);
                            break;

                        case OffsetMoppReorderTable:
                            MoppReorderTable.Resize(count);
                            MoppReorderTable.Read(er);
                            break;

                        case OffsetVertexBuffers:
                            VertexBuffers.Resize(count);
                            VertexBuffers.Read(er);
                            break;
                        }
                        break;

                        #endregion
                        #region TagData
                    case (int)geometry_block_resource_type.TagData:
                        switch (gb.PrimaryLocater.Value)
                        {
                        case OffsetVisibilityMoppCode:
                            VisibilityMoppCode.Reset(er.ReadBytes(gb.Size));
                            break;
                        }
                        break;

                        #endregion
                        #region VertexBuffer
                    case (int)geometry_block_resource_type.VertexBuffer:
                        var vb_defs = (c.TagIndexManager as InternalCacheTagIndex).kVertexBuffers;

                        var stream_readers = new Render.VertexBufferInterface.StreamReader[VertexBuffers.Count];
                        for (x = 0; x < VertexBuffers.Count; x++)
                        {
                            VertexBuffers[x].VertexBuffer.InitializeStreamReader(vb_defs, out stream_readers[x]);
                        }

                        if (RawVertices.Count == 0)
                        {
                            int vertex_count = section_info != null ?
                                               section_info.TotalVertexCount :
                                               gb.Size.Value / VertexBuffers[0].VertexBuffer.StrideSize;

                            RawVertices.Resize(vertex_count);
                        }

                        for (x = 0; x < RawVertices.Count; x++)
                        {
                            RawVertices[x].Reconstruct(section_info, gb,
                                                       er, stream_readers);
                        }
                        break;
                        #endregion
                    }
                }

                index++;
            }

            VertexBuffers.DeleteAll();

            return(true);
        }
Пример #3
0
                internal bool Reconstruct(Blam.CacheFile c,
                                          lightmap_vertex_buffer_bucket_block buffer_bucket,
                                          geometry_block_info_struct gbi)
                {
                    int index = 0;
                    int x;

                    byte[][] data = gbi.GeometryBlock;

                    if (data == null)
                    {
                        return(false);
                    }

                    foreach (geometry_block_resource_block gb in gbi.Resources)
                    {
                        using (IO.EndianReader er = new BlamLib.IO.EndianReader(data[index]))
                        {
                            switch (gb.Type.Value)
                            {
                                #region TagBlock
                            case (int)geometry_block_resource_type.TagBlock:
                                int count = gb.GetCount();
                                switch (gb.PrimaryLocater.Value)
                                {
                                case OffsetVertexBuffers:
                                    VertexBuffers.Resize(count);
                                    VertexBuffers.Read(er);
                                    break;
                                }
                                break;

                                #endregion
                                #region VertexBuffer
                            case (int)geometry_block_resource_type.VertexBuffer:
                                var vb_defs = (c.TagIndexManager as InternalCacheTagIndex).kVertexBuffers;

                                var stream_readers = new Render.VertexBufferInterface.StreamReader[VertexBuffers.Count];
                                for (x = 0; x < VertexBuffers.Count; x++)
                                {
                                    VertexBuffers[x].VertexBuffer.InitializeStreamReader(vb_defs, out stream_readers[x]);
                                }

                                int vertex_count = gb.Size.Value / VertexBuffers[0].VertexBuffer.StrideSize;
                                if (buffer_bucket.RawVertices.Count == 0)
                                {
                                    buffer_bucket.RawVertices.Resize(vertex_count);
                                }
                                for (x = 0; x < vertex_count; x++)
                                {
                                    buffer_bucket.RawVertices[x].Reconstruct(buffer_bucket, gb,
                                                                             er, stream_readers);
                                }
                                break;
                                #endregion
                            }
                        }

                        index++;
                    }

                    VertexBuffers.DeleteAll();

                    return(true);
                }