Example #1
0
 public void Render(
     global_geometry_section_info_struct section_info,
     TI.Block <global_geometry_material_block> materials
     )
 {
     Section.Value.Render(section_info, materials);
 }
Example #2
0
        public void Render(
            global_geometry_section_info_struct section_info,
            TI.Block <global_geometry_material_block> materials
            )
        {
            // TODO: update this shit fool
//          D3D.Device d = Editor.Renderer.GetDevice();
//          foreach(global_geometry_section_vertex_buffer_block svb in VertexBuffers)
//          {
//              TI.VertexBuffer vb = svb.VertexBuffer;
//              d.SetStreamSource(vb.StreamIndex, vb.Buffer, 0);
//          }
//          d.VertexDeclaration = Declaration;
//          d.Indices = IndexBuffer;
//          global_geometry_material_block mat;
//          foreach(global_geometry_part_block_new part in Parts)
//          {
//              d.DrawIndexedPrimitives(
//                  D3D.PrimitiveType.TriangleStrip,
//                  0, 0,
//                  section_info.TotalVertexCount,
//                  part.StripStartIndex,
//                  part.StripLength);
//              mat = materials[part.Material];
//          }
        }
Example #3
0
            internal bool Reconstruct(Blam.CacheFile c,
                                      global_geometry_section_info_struct section,
                                      geometry_block_info_struct gbi)
            {
                Section.Value.Reconstruct(c, section, gbi);
                PointData.Value.Reconstruct(c, section, gbi);

                int index = 0;

                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 OffsetNodeMap:
                                NodeMap.Resize(count);
                                NodeMap.Read(er);
                                break;
                            }
                            break;
                            #endregion
                        }

                        index++;
                    }
                }

                return(true);
            }
Example #4
0
        internal void Reconstruct(global_geometry_section_info_struct section_info,
                                  geometry_block_resource_block gb,
                                  IO.EndianReader er,
                                  BlamLib.Render.VertexBufferInterface.StreamReader[] stream_readers)
        {
            short stream_source = gb.SecondaryLocater.Value;

            if (stream_source == 0)
            {
                Default();
            }

            var stream_r = stream_readers[stream_source];

            if (!stream_r.UsesNullDefinition)
            {
                stream_r.Read(er);
                stream_r.Denormalize();
                ReconstructRawVertex(section_info, stream_source, stream_r);
            }
        }
Example #5
0
        internal bool Reconstruct(
            BlamLib.Blam.CacheFile c,
            global_geometry_section_info_struct section,
            geometry_block_info_struct gbi
            )
        {
            int index = 0;

            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 OffsetRawPoints:
                            RawPoints.Resize(count);
                            RawPoints.Read(er);
                            break;

                        case OffsetRigidPointGroups:
                            RigidPointGroups.Resize(count);
                            RigidPointGroups.Read(er);
                            break;

                        case OffsetVertexPointIndices:
                            VertexPointIndices.Resize(count);
                            VertexPointIndices.Read(er);
                            break;
                        }
                        break;

                        #endregion
                        #region TagData
                    case (int)geometry_block_resource_type.TagData:
                        switch (gb.PrimaryLocater.Value)
                        {
                        case OffsetRuntimePointData:
                            RuntimePointData.Reset(er.ReadBytes(gb.Size));
                            break;
                        }
                        break;
                        #endregion
                        #region VertexBuffer
                        //case (int)geometry_block_resource_type.VertexBuffer:
                        #endregion
                    }

                    index++;
                }
            }

            return(true);
        }
Example #6
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);
        }
Example #7
0
        void ReconstructRawVertex(global_geometry_section_info_struct section_info,
                                  int stream_source, BlamLib.Render.VertexBufferInterface.StreamReader stream_reader)
        {
            LowLevel.Math.real_quaternion quat = new LowLevel.Math.real_quaternion();

            if (stream_source == 0)
            {
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypePosition,
                                                      ref quat))
                {
                    Point.Position.X = quat.Vector.I;
                    Point.Position.Y = quat.Vector.J;
                    Point.Position.Z = quat.Vector.K;
                }
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeNodeIndices,
                                                      ref quat))
                {
                    Point.NodeIndex[0].Value = ((int)quat.Vector.I) - 1;
                    Point.NodeIndex[1].Value = ((int)quat.Vector.J) - 1;
                    Point.NodeIndex[2].Value = ((int)quat.Vector.K) - 1;
                    Point.NodeIndex[3].Value = ((int)quat.W) - 1;
                }
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeNodeWeights,
                                                      ref quat))
                {
                    Point.NodeWeight[0].Value = quat.Vector.I;
                    Point.NodeWeight[1].Value = quat.Vector.J;
                    Point.NodeWeight[2].Value = quat.Vector.K;
                    Point.NodeWeight[3].Value = quat.W;
                }
            }
            else if (stream_source == 1)
            {
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeTexCoord,
                                                      ref quat))
                {
                    Texcoord.X = quat.Vector.I;
                    Texcoord.Y = quat.Vector.J;
                }
            }
            else if (stream_source == 2)
            {
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeNormal,
                                                      ref quat))
                {
                    Normal.I = quat.Vector.I;
                    Normal.J = quat.Vector.J;
                    Normal.K = quat.Vector.K;
                }
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeBinormal,
                                                      ref quat))
                {
                    Binormal.I = quat.Vector.I;
                    Binormal.J = quat.Vector.J;
                    Binormal.K = quat.Vector.K;
                }
                if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeTangent,
                                                      ref quat))
                {
                    Tangent.I = quat.Vector.I;
                    Tangent.J = quat.Vector.J;
                    Tangent.K = quat.Vector.K;
                }
            }

            if (section_info != null && stream_source > 2)
            {
                int x = 2;

                // The following LM vertex sources only have one element, so we can call this here
                stream_reader.GetStreamedElement(0, ref quat);

                if (section_info.SectionLightingFlags.Test(k_lighting_flags_HasLmTexCoords) &&
                    stream_source == ++x)
                {
                    PrimaryLightmapTexcoord.X = quat.Vector.I;
                    PrimaryLightmapTexcoord.Y = quat.Vector.J;
                }
                else if (section_info.SectionLightingFlags.Test(k_lighting_flags_HasLmIncRad) &&
                         stream_source == ++x)
                {
                    PrimaryLightmapIncidentDirection.I = quat.Vector.I;
                    PrimaryLightmapIncidentDirection.J = quat.Vector.J;
                    PrimaryLightmapIncidentDirection.K = quat.Vector.K;
                }
                else if (section_info.SectionLightingFlags.Test(k_lighting_flags_HasLmColor) &&
                         stream_source == ++x)
                {
                    // alpha is quad.W, which LM color doesn't use
                    PrimaryLightmapColor.R = quat.Vector.I;
                    PrimaryLightmapColor.G = quat.Vector.J;
                    PrimaryLightmapColor.B = quat.Vector.K;
                }
            }

            #region Unused vertex elements
//          if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.VertexBuffersHalo2.kTypeAnisoBinormal,
//              ref quat))
//          {
//              AnisotropicBinormal.I = quat.Vector.I;
//              AnisotropicBinormal.J = quat.Vector.J;
//              AnisotropicBinormal.K = quat.Vector.K;
//          }
//
//          if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.VertexBuffersHalo2.kTypeSecondaryTexCoord,
//              ref quat))
//          {
//              SecondaryTexcoord.X = quat.Vector.I;
//              SecondaryTexcoord.Y = quat.Vector.J;
//          }
            #endregion
        }
Example #8
0
		public void Render(global_geometry_section_info_struct section_info,
					TI.Block<global_geometry_material_block> materials)
		{
			Section.Value.Render(section_info, materials);
		}
Example #9
0
				internal bool Reconstruct(Blam.CacheFile c,
					global_geometry_section_info_struct section_info,
					geometry_block_info_struct gbi)
				{
					return Geometry.Value.Reconstruct(c, section_info, gbi);
				}
Example #10
0
			internal bool Reconstruct(Blam.CacheFile c,
				global_geometry_section_info_struct section,
				geometry_block_info_struct gbi)
			{
				Section.Value.Reconstruct(c, section, gbi);
				PointData.Value.Reconstruct(c, section, gbi);

				int index = 0;
				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 OffsetNodeMap:
										NodeMap.Resize(count);
										NodeMap.Read(er);
										break;
								}
								break;
							#endregion
						}

						index++;
					}
				}

				return true;
			}
Example #11
0
 internal bool Reconstruct(Blam.CacheFile c,
                           global_geometry_section_info_struct section_info,
                           geometry_block_info_struct gbi)
 {
     return(Geometry.Value.Reconstruct(c, section_info, gbi));
 }
Example #12
0
		internal bool Reconstruct(
			BlamLib.Blam.CacheFile c,
			global_geometry_section_info_struct section,
			geometry_block_info_struct gbi
			)
		{
			int index = 0;
			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 OffsetRawPoints:
									RawPoints.Resize(count);
									RawPoints.Read(er);
									break;

								case OffsetRigidPointGroups:
									RigidPointGroups.Resize(count);
									RigidPointGroups.Read(er);
									break;

								case OffsetVertexPointIndices:
									VertexPointIndices.Resize(count);
									VertexPointIndices.Read(er);
									break;
							}
							break;
						#endregion
						#region TagData
						case (int)geometry_block_resource_type.TagData:
							switch (gb.PrimaryLocater.Value)
							{
								case OffsetRuntimePointData:
									RuntimePointData.Reset(er.ReadBytes(gb.Size));
									break;
							}
							break;
						#endregion
						#region VertexBuffer
						//case (int)geometry_block_resource_type.VertexBuffer:
						#endregion
					}

					index++;
				}
			}

			return true;
		}
Example #13
0
		public void Render(
			global_geometry_section_info_struct section_info,
			TI.Block<global_geometry_material_block> materials
			)
		{
			// TODO: update this shit fool
// 			D3D.Device d = Editor.Renderer.GetDevice();
// 			foreach(global_geometry_section_vertex_buffer_block svb in VertexBuffers)
// 			{
// 				TI.VertexBuffer vb = svb.VertexBuffer;
// 				d.SetStreamSource(vb.StreamIndex, vb.Buffer, 0);
// 			}
// 			d.VertexDeclaration = Declaration;
// 			d.Indices = IndexBuffer;
// 			global_geometry_material_block mat;
// 			foreach(global_geometry_part_block_new part in Parts)
// 			{
// 				d.DrawIndexedPrimitives(
// 					D3D.PrimitiveType.TriangleStrip,
// 					0, 0,
// 					section_info.TotalVertexCount,
// 					part.StripStartIndex,
// 					part.StripLength);
// 				mat = materials[part.Material];
// 			}
		}
Example #14
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;
		}
Example #15
0
		internal void Reconstruct(global_geometry_section_info_struct section_info,
			geometry_block_resource_block gb,
			IO.EndianReader er,
			BlamLib.Render.VertexBufferInterface.StreamReader[] stream_readers)
		{
			short stream_source = gb.SecondaryLocater.Value;

			if(stream_source == 0)
				Default();

			var stream_r = stream_readers[stream_source];
			if (!stream_r.UsesNullDefinition)
			{
				stream_r.Read(er);
				stream_r.Denormalize();
				ReconstructRawVertex(section_info, stream_source, stream_r);
			}
		}
Example #16
0
		void ReconstructRawVertex(global_geometry_section_info_struct section_info,
			int stream_source, BlamLib.Render.VertexBufferInterface.StreamReader stream_reader)
		{
			LowLevel.Math.real_quaternion quat = new LowLevel.Math.real_quaternion();

			if (stream_source == 0)
			{
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypePosition,
					ref quat))
				{
					Point.Position.X = quat.Vector.I;
					Point.Position.Y = quat.Vector.J;
					Point.Position.Z = quat.Vector.K;
				}
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeNodeIndices,
					ref quat))
				{
					Point.NodeIndex[0].Value = ((int)quat.Vector.I) - 1;
					Point.NodeIndex[1].Value = ((int)quat.Vector.J) - 1;
					Point.NodeIndex[2].Value = ((int)quat.Vector.K) - 1;
					Point.NodeIndex[3].Value = ((int)quat.W) - 1;
				}
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeNodeWeights,
					ref quat))
				{
					Point.NodeWeight[0].Value = quat.Vector.I;
					Point.NodeWeight[1].Value = quat.Vector.J;
					Point.NodeWeight[2].Value = quat.Vector.K;
					Point.NodeWeight[3].Value = quat.W;
				}
			}
			else if (stream_source == 1)
			{
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeTexCoord,
					ref quat))
				{
					Texcoord.X = quat.Vector.I;
					Texcoord.Y = quat.Vector.J;
				}
			}
			else if (stream_source == 2)
			{
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeNormal,
					ref quat))
				{
					Normal.I = quat.Vector.I;
					Normal.J = quat.Vector.J;
					Normal.K = quat.Vector.K;
				}
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeBinormal,
					ref quat))
				{
					Binormal.I = quat.Vector.I;
					Binormal.J = quat.Vector.J;
					Binormal.K = quat.Vector.K;
				}
				if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.kTypeTangent,
					ref quat))
				{
					Tangent.I = quat.Vector.I;
					Tangent.J = quat.Vector.J;
					Tangent.K = quat.Vector.K;
				}
			}

			if (section_info != null && stream_source > 2)
			{
				int x = 2;

				// The following LM vertex sources only have one element, so we can call this here
				stream_reader.GetStreamedElement(0, ref quat);

				if (section_info.SectionLightingFlags.Test(k_lighting_flags_HasLmTexCoords) 
					&& stream_source == ++x)
				{
					PrimaryLightmapTexcoord.X = quat.Vector.I;
					PrimaryLightmapTexcoord.Y = quat.Vector.J;
				}
				else if (section_info.SectionLightingFlags.Test(k_lighting_flags_HasLmIncRad)
					&& stream_source == ++x)
				{
					PrimaryLightmapIncidentDirection.I = quat.Vector.I;
					PrimaryLightmapIncidentDirection.J = quat.Vector.J;
					PrimaryLightmapIncidentDirection.K = quat.Vector.K;
				}
				else if (section_info.SectionLightingFlags.Test(k_lighting_flags_HasLmColor)
					&& stream_source == ++x)
				{
					// alpha is quad.W, which LM color doesn't use
					PrimaryLightmapColor.R = quat.Vector.I;
					PrimaryLightmapColor.G = quat.Vector.J;
					PrimaryLightmapColor.B = quat.Vector.K;
				}
			}

			#region Unused vertex elements
// 			if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.VertexBuffersHalo2.kTypeAnisoBinormal,
// 				ref quat))
// 			{
// 				AnisotropicBinormal.I = quat.Vector.I;
// 				AnisotropicBinormal.J = quat.Vector.J;
// 				AnisotropicBinormal.K = quat.Vector.K;
// 			}
// 
// 			if (stream_reader.FindStreamedElement(BlamLib.Render.VertexBufferInterface.VertexBuffersHalo2.kTypeSecondaryTexCoord,
// 				ref quat))
// 			{
// 				SecondaryTexcoord.X = quat.Vector.I;
// 				SecondaryTexcoord.Y = quat.Vector.J;
// 			}
			#endregion
		}