示例#1
0
        public void LoadTagData()
        {
            int          i;
            BinaryReader br = new BinaryReader(m_stream);

            // Load the header
            m_Header.Load(ref br);

            //Load Chunks for R1 (model bounds)
            m_ModelBounds = new H2_MODEL_BOUNDS[m_Header.Bounds.Count];
            for (i = 0; i < m_Header.Bounds.Count; i++)
            {
                m_ModelBounds[i] = new H2_MODEL_BOUNDS();
                m_ModelBounds[i].Load(ref br);
            }
            m_BoundingBox.min[0] = m_ModelBounds[0].minX;
            m_BoundingBox.min[1] = m_ModelBounds[0].minY;
            m_BoundingBox.min[2] = m_ModelBounds[0].minZ;
            m_BoundingBox.max[0] = m_ModelBounds[0].maxX;
            m_BoundingBox.max[1] = m_ModelBounds[0].maxY;
            m_BoundingBox.max[2] = m_ModelBounds[0].maxZ;

            //Load Chunks/Subchunks for R2 (regions)
            m_Regions = new H2_MODEL_REGION[m_Header.Region.Count];
            for (i = 0; i < m_Header.Region.Count; i++)
            {
                m_Regions[i] = new H2_MODEL_REGION();
                m_Regions[i].Load(ref br);
            }

            for (i = 0; i < m_Header.Region.Count; i++)
            {
                m_Regions[i].LoadScriptRef(ref br);
                m_Regions[i].LoadPermutations(ref br);
            }
            //Load Chunks/Subchunks for R3 (geometry)
            m_Geometry = new H2_MODEL_GEOMETRY[m_Header.Geometry.Count];
            for (i = 0; i < m_Header.Geometry.Count; i++)
            {
                m_Geometry[i] = new H2_MODEL_GEOMETRY();
                m_Geometry[i].Load(ref br);
            }

            long geometry_start_pos = br.BaseStream.Position;

            for (i = 0; i < m_Header.Geometry.Count; i++)
            {
                br.BaseStream.Position += m_Geometry[i].ModelResourceBlockSize;
            }

            for (i = 0; i < m_Header.Geometry.Count; i++)
            {
                m_Geometry[i].LoadRawDescriptors(ref br);
            }

            long geometry_end_pos = br.BaseStream.Position;

            br.BaseStream.Position = geometry_start_pos;
            for (i = 0; i < m_Header.Geometry.Count; i++)
            {
                m_Geometry[i].LoadRawData(ref br, ref m_ModelBounds[0]);
            }

            br.BaseStream.Position = geometry_end_pos;

            //skip past R4, R5
            br.BaseStream.Position += (m_Header.r4.Count * 4);
            br.BaseStream.Position += (m_Header.r5.Count * 12);
            //load Nodes
            //br.BaseStream.Position += (m_Header.Nodes.Count*96);
            m_Nodes = new H2_MODEL_NODE[m_Header.Nodes.Count];
            for (i = 0; i < m_Header.Nodes.Count; i++)
            {
                m_Nodes[i] = new H2_MODEL_NODE();
                m_Nodes[i].Load(ref br);
            }
            for (i = 0; i < m_Header.Nodes.Count; i++)
            {
                m_Nodes[i].LoadScriptRef(ref br);
            }
            //load Markers
            m_Markers = new H2_MODEL_MARKER[m_Header.Markers.Count];
            for (i = 0; i < m_Header.Markers.Count; i++)
            {
                m_Markers[i] = new H2_MODEL_MARKER();
                m_Markers[i].Load(ref br);
            }

            for (i = 0; i < m_Header.Markers.Count; i++)
            {
                m_Markers[i].LoadMarkerName(ref br);
                m_Markers[i].LoadSub(ref br);
            }
            //load Shaders
            m_Shaders = new H2_MODEL_SHADER[m_Header.Shaders.Count];
            for (i = 0; i < m_Header.Shaders.Count; i++)
            {
                br.BaseStream.Position += 8;
                m_Shaders[i]            = new H2_MODEL_SHADER();
                m_Shaders[i].TagRef.Load(ref br);
                br.BaseStream.Position += 16;
            }

            for (i = 0; i < m_Header.Shaders.Count; i++)
            {
                m_Shaders[i].TagRef.ReadString(ref br);
                m_Shaders[i].ShaderManagerIndex = MdxRender.SM.RegisterShader(new TagFileName(m_Shaders[i].TagRef.data, "dahs", this.m_PromHeader.GameVersion));
            }

            //update data structs so we can get the shader activated during draw
            for (i = 0; i < m_Header.Geometry.Count; i++)
            {
                for (int j = 0; j < m_Geometry[i].ResourceInfo.Length; j++)
                {
                    m_Geometry[i].ResourceInfo[j].ShaderManagerIndex =
                        m_Shaders[m_Geometry[i].ResourceInfo[j].ShaderIndex].ShaderManagerIndex;
                }
            }

            this.m_bModelLoaded = true;
        }
示例#2
0
        public void LoadRawData(ref BinaryReader br, ref H2_MODEL_BOUNDS bBox)
        {
            RelativeOffset           = (uint)br.BaseStream.Position + ModelHeaderSize + 8;
            TagVertexCount           = VertexCount;
            ModelResourceBlockOffset = (uint)br.BaseStream.Position;
            ResourceHeader.Load(ref br);
            TagTriangleCount = (int)ResourceHeader.IndexChunkCount;
            //RawData = new byte[ModelResourceBlockSize - 0x78];  //0x78 = blkh size
            //RawData = br.ReadBytes((int)(ModelResourceBlockSize - 0x78));

            if (IndexListCount * 3 == ResourceHeader.IndexChunkCount)
            {
                UsesList = true;
            }
            else
            {
                UsesList = false;
            }

            //Load Resource Info
            br.BaseStream.Position = RelativeOffset + m_RawDescriptors[0].offset; //skip "rsrc" identifier
            ResourceInfo           = new H2_MODEL_RSRC_INFO[ResourceHeader.InfoChunkCount];

            for (int i = 0; i < ResourceHeader.InfoChunkCount; i++)
            {
                ResourceInfo[i] = new H2_MODEL_RSRC_INFO();
                ResourceInfo[i].Load(ref br);
            }


            //Indice Data
            br.BaseStream.Position = RelativeOffset + m_RawDescriptors[ResourceHeader.indexRSRC].offset; //skip "rsrc" identifier

            INDICES = new short[ResourceHeader.IndexChunkCount];
            for (int i = 0; i < ResourceHeader.IndexChunkCount; i++)
            {
                INDICES[i] = br.ReadInt16();
            }


            //Vertex Data
            br.BaseStream.Position = RelativeOffset + m_RawDescriptors[ResourceHeader.indexRSRC + 2].offset; //skip "rsrc" identifier

            VERTS = new PCMODEL2_VERT[VertexCount];

            for (int v = 0; v < VertexCount; v++)
            {
                VERTS[v]       = new PCMODEL2_VERT();
                VERTS[v].dxv.X = TagHalo2Model.Signed16ToFloat(br.ReadInt16(), bBox.minX, bBox.maxX);
                VERTS[v].dxv.Y = TagHalo2Model.Signed16ToFloat(br.ReadInt16(), bBox.minY, bBox.maxY);
                VERTS[v].dxv.Z = TagHalo2Model.Signed16ToFloat(br.ReadInt16(), bBox.minZ, bBox.maxZ);
                //VERTS[v].dxv.Nx = 0;
                //VERTS[v].dxv.Ny = 0;
                //VERTS[v].dxv.Nz = 1;



                if (BytesPerVertex == 1)
                {
                }
                else if ((BytesPerVertex == 2) || (BytesPerVertex == 3 && Type == 1))
                {
                    br.BaseStream.Position += 2;
                }
                else if (BytesPerVertex == 3)
                {
                    if (Type == 0 || Type == 2)
                    {
                        br.BaseStream.Position += 6;
                    }
                    else if (Type == 4)
                    {
                        br.BaseStream.Position += 10;
                    }
                    else if (Type == 3)
                    {
                        br.BaseStream.Position += 6;
                    }
                    else
                    {
                    }
                }
            }

            //Texture Coord Data
            br.BaseStream.Position = RelativeOffset + m_RawDescriptors[ResourceHeader.indexRSRC + 3].offset; //skip "rsrc" identifier

            for (int v = 0; v < VertexCount; v++)
            {
                //VERTS[v].dxv.Tu = Halo2Model.Signed32ToFloat(br.ReadInt32(), bBox.minU , bBox.maxU );
                //VERTS[v].dxv.Tv = Halo2Model.Signed32ToFloat(br.ReadInt32(), bBox.minV , bBox.maxV );

                float uv1 = TagHalo2Model.Signed16ToFloat(br.ReadInt16(), bBox.minU, bBox.maxU);
                float uv2 = TagHalo2Model.Signed16ToFloat(br.ReadInt16(), bBox.minV, bBox.maxV);

                if (uv1 < 0.0F)
                {
                    uv1 += 1.0F;
                }
                if (uv2 < 0.0F)
                {
                    uv2 += 1.0F;
                }

                VERTS[v].dxv.Tu = uv1;
                VERTS[v].dxv.Tv = uv2;
            }

            br.BaseStream.Position = ModelResourceBlockOffset + ModelResourceBlockSize;

            //Create DirectX resources
            IndexData          = new IndexBuffer(typeof(short), INDICES.Length, MdxRender.Dev, Usage.WriteOnly, Pool.Default);
            IndexData.Created += new EventHandler(this.OnIndexBufferCreate);
            OnIndexBufferCreate(IndexData, null);

            VertData = new VertexBuffer(typeof(CustomVertex.PositionNormalTextured), VertexCount, MdxRender.Dev,
                                        Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionNormalTextured.Format, Pool.Default);
            VertData.Created += new EventHandler(this.OnVertexBufferCreate);
            OnVertexBufferCreate(VertData, null);
        }