///------------------------------------------------------------------------------------------------- /// <summary> Creates a geometry element for a single fog plane. </summary> /// <param name="index"> Index of the fog plane to create a geometry element for. </param> ///------------------------------------------------------------------------------------------------- private void CreateFogPlaneGeometry(int index) { H1.Tags.structure_bsp_group definition = mTagManager.TagDefinition as H1.Tags.structure_bsp_group; Geometry geometryData = new Geometry("fogplane-" + index.ToString() , 0 , Geometry.VertexComponent.POSITION); foreach (var vertex in definition.FogPlanes[index].Vertices) { geometryData.AddVertex(new Geometry.Vertex(vertex.Value.ToPoint3D(100))); } // we only have one part since it only has one material Geometry.Part common_part = new Geometry.Part("fogplanes"); common_part.AddIndices(BuildFaceIndices(definition.FogPlanes[index].Vertices.Count)); geometryData.AddPart(common_part); // create the geometry element CreateGeometry(geometryData); }
///------------------------------------------------------------------------------------------------- /// <summary> Creates a geometry element for a single cluster portal. </summary> /// <param name="index"> The lightmap index to create a geometry from. </param> ///------------------------------------------------------------------------------------------------- private void CreatePortalsGeometry(int index) { H1.Tags.structure_bsp_group definition = mTagManager.TagDefinition as H1.Tags.structure_bsp_group; Geometry geometryData = new Geometry("portal-" + index.ToString() , 0 , Geometry.VertexComponent.POSITION | Geometry.VertexComponent.NORMAL); foreach (var vertex in definition.ClusterPortals[index].Vertices) { geometryData.AddVertex(new Geometry.Vertex(vertex.Value.ToPoint3D(100), new LowLevel.Math.real_vector3d(0, 0, 1))); } // we only have one part since it only has one material Geometry.Part common_part = new Geometry.Part("portals"); common_part.AddIndices(BuildFaceIndices(definition.ClusterPortals[index].Vertices.Count)); geometryData.AddPart(common_part); // create the geometry element CreateGeometry(geometryData); }
///------------------------------------------------------------------------------------------------- /// <summary> Creates geometry elements for all of the included geometry blocks. </summary> ///------------------------------------------------------------------------------------------------- void CreateGeometryList() { var shaderList = new List <string>(); if (mShaderDataProvider != null) { // Create a list of every shader used foreach (var effect in mShaderDataProvider.GetEffectsMap()) { shaderList.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(effect.Name), " ", "_")); } } var definition = mTagManager.TagDefinition as H1.Tags.gbxmodel_group; var geometrySetList = mModelDataProvider.GetGeometries(); foreach (var geometrySet in geometrySetList) { string name = ColladaUtilities.FormatName(geometrySet.Name, " ", "_"); var geometryData = new Geometry(name , 1 , Geometry.VertexComponent.POSITION | Geometry.VertexComponent.NORMAL | Geometry.VertexComponent.BINORMAL | Geometry.VertexComponent.TANGENT | Geometry.VertexComponent.TEXCOORD); // collect the vertices for all of the geometries parts foreach (var part in geometrySet.Geometry.Parts) { foreach (var vertex in part.UncompressedVertices) { var common_vertex = new Geometry.Vertex(vertex.Position.ToPoint3D(100), vertex.Normal.ToVector3D(), vertex.Binormal.ToVector3D(), vertex.Tangent.ToVector3D()); // if the texture coordinate scale is 0.0, default to 1.0 float u_scale = (definition.BaseMapUScale.Value == 0.0f ? 1.0f : definition.BaseMapUScale.Value); float v_scale = (definition.BaseMapVScale.Value == 0.0f ? 1.0f : definition.BaseMapVScale.Value); // add the texture coordinate data common_vertex.AddTexcoord(new LowLevel.Math.real_point2d( vertex.TextureCoords.X * u_scale, ((vertex.TextureCoords.Y * v_scale) * -1) + 1)); geometryData.AddVertex(common_vertex); } } // create a new Part for each geometry part int index_offset = 0; foreach (var part in geometrySet.Geometry.Parts) { var shader_index = part.ShaderIndex; if (shader_index >= shaderList.Count) { shader_index.Value = shaderList.Count - 1; } var common_part = new Geometry.Part(shaderList[shader_index]); common_part.AddIndices(CreateIndicesModel(part, index_offset)); index_offset += part.UncompressedVertices.Count; geometryData.AddPart(common_part); } // create the geometry element CreateGeometry(geometryData); } }
///------------------------------------------------------------------------------------------------- /// <summary> Creates geometry elements for all of the included geometry blocks. </summary> ///------------------------------------------------------------------------------------------------- void CreateGeometryList() { var shaderList = new List<string>(); if (mShaderDataProvider != null) { // Create a list of every shader used foreach (var effect in mShaderDataProvider.GetEffectsMap()) { shaderList.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(effect.Name), " ", "_")); } } var definition = mTagManager.TagDefinition as H1.Tags.gbxmodel_group; var geometrySetList = mModelDataProvider.GetGeometries(); foreach(var geometrySet in geometrySetList) { string name = ColladaUtilities.FormatName(geometrySet.Name, " ", "_"); var geometryData = new Geometry(name , 1 , Geometry.VertexComponent.POSITION | Geometry.VertexComponent.NORMAL | Geometry.VertexComponent.BINORMAL | Geometry.VertexComponent.TANGENT | Geometry.VertexComponent.TEXCOORD); // collect the vertices for all of the geometries parts foreach (var part in geometrySet.Geometry.Parts) { foreach(var vertex in part.UncompressedVertices) { var common_vertex = new Geometry.Vertex(vertex.Position.ToPoint3D(100), vertex.Normal.ToVector3D(), vertex.Binormal.ToVector3D(), vertex.Tangent.ToVector3D()); // if the texture coordinate scale is 0.0, default to 1.0 float u_scale = (definition.BaseMapUScale.Value == 0.0f ? 1.0f : definition.BaseMapUScale.Value); float v_scale = (definition.BaseMapVScale.Value == 0.0f ? 1.0f : definition.BaseMapVScale.Value); // add the texture coordinate data common_vertex.AddTexcoord(new LowLevel.Math.real_point2d( vertex.TextureCoords.X * u_scale, ((vertex.TextureCoords.Y * v_scale) * -1) + 1)); geometryData.AddVertex(common_vertex); } } // create a new Part for each geometry part int index_offset = 0; foreach (var part in geometrySet.Geometry.Parts) { var shader_index = part.ShaderIndex; if(shader_index >= shaderList.Count) { shader_index.Value = shaderList.Count - 1; } var common_part = new Geometry.Part(shaderList[shader_index]); common_part.AddIndices(CreateIndicesModel(part, index_offset)); index_offset += part.UncompressedVertices.Count; geometryData.AddPart(common_part); } // create the geometry element CreateGeometry(geometryData); } }
///------------------------------------------------------------------------------------------------- /// <summary> Creates a geometry element for a BSP lightmap. </summary> /// <param name="index"> The lightmap index to create a geometry from. </param> ///------------------------------------------------------------------------------------------------- private void CreateRenderGeometry(int index) { H1.Tags.structure_bsp_group definition = mTagManager.TagDefinition as H1.Tags.structure_bsp_group; Geometry geometryData = new Geometry(ColladaUtilities.FormatName(TagName, " ", "_") + "_" + definition.Lightmaps[index].Bitmap.ToString() , 2 , Geometry.VertexComponent.POSITION | Geometry.VertexComponent.NORMAL | Geometry.VertexComponent.BINORMAL | Geometry.VertexComponent.TANGENT | Geometry.VertexComponent.TEXCOORD); // add all of the vertices used in the render geometry foreach (var material in definition.Lightmaps[index].Materials) { // read vertex information from the uncompressed vertex data System.IO.BinaryReader uncompressed_reader = new System.IO.BinaryReader( new System.IO.MemoryStream(material.UncompressedVertices.Value)); int vertex_count = material.VerticesCount; for (int vertex_index = 0; vertex_index < vertex_count; vertex_index++) { Geometry.Vertex common_vertex = new Geometry.Vertex( //RealPoint3D position new LowLevel.Math.real_point3d( uncompressed_reader.ReadSingle() * 100, uncompressed_reader.ReadSingle() * 100, uncompressed_reader.ReadSingle() * 100), //RealVector3D normal new LowLevel.Math.real_vector3d( uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle()), //RealVector3D binormal new LowLevel.Math.real_vector3d( uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle()), //RealVector3D tangent new LowLevel.Math.real_vector3d( uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle())); //RealPoint2D texcoord0 common_vertex.AddTexcoord(new LowLevel.Math.real_point2d( uncompressed_reader.ReadSingle(), (uncompressed_reader.ReadSingle() * -1) + 1)); //RealPoint2D texcoord1 if (material.LightmapVerticesCount != 0) { int position = (int)uncompressed_reader.BaseStream.Position; uncompressed_reader.BaseStream.Position = (material.VerticesCount * 56) + (vertex_index * 20) + 12; common_vertex.AddTexcoord(new LowLevel.Math.real_point2d( uncompressed_reader.ReadSingle(), (uncompressed_reader.ReadSingle() * -1) + 1)); uncompressed_reader.BaseStream.Position = position; } else { common_vertex.AddTexcoord(new LowLevel.Math.real_point2d(0, 1)); } geometryData.AddVertex(common_vertex); } ; } // add part definitions for the lightmap materials // an index offset is necessary since the vertex list is global for this geometry, rather than local to each material int index_offset = 0; foreach (var material in definition.Lightmaps[index].Materials) { Geometry.Part common_part = new Geometry.Part(Path.GetFileNameWithoutExtension(material.Shader.ToString())); common_part.AddIndices(CreateIndicesBSP(definition, material.Surfaces, material.SurfaceCount, index_offset)); index_offset += material.VerticesCount; geometryData.AddPart(common_part); } // create the geometry element CreateGeometry(geometryData); }
///------------------------------------------------------------------------------------------------- /// <summary> Creates a geometry element for a BSP lightmap. </summary> /// <param name="index"> The lightmap index to create a geometry from. </param> ///------------------------------------------------------------------------------------------------- private void CreateRenderGeometry(int index) { H1.Tags.structure_bsp_group definition = mTagManager.TagDefinition as H1.Tags.structure_bsp_group; Geometry geometryData = new Geometry(ColladaUtilities.FormatName(TagName, " ", "_") + "_" + definition.Lightmaps[index].Bitmap.ToString() , 2 , Geometry.VertexComponent.POSITION | Geometry.VertexComponent.NORMAL | Geometry.VertexComponent.BINORMAL | Geometry.VertexComponent.TANGENT | Geometry.VertexComponent.TEXCOORD); // add all of the vertices used in the render geometry foreach (var material in definition.Lightmaps[index].Materials) { // read vertex information from the uncompressed vertex data System.IO.BinaryReader uncompressed_reader = new System.IO.BinaryReader( new System.IO.MemoryStream(material.UncompressedVertices.Value)); int vertex_count = material.VerticesCount; for (int vertex_index = 0; vertex_index < vertex_count; vertex_index++) { Geometry.Vertex common_vertex = new Geometry.Vertex( //RealPoint3D position new LowLevel.Math.real_point3d( uncompressed_reader.ReadSingle() * 100, uncompressed_reader.ReadSingle() * 100, uncompressed_reader.ReadSingle() * 100), //RealVector3D normal new LowLevel.Math.real_vector3d( uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle()), //RealVector3D binormal new LowLevel.Math.real_vector3d( uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle()), //RealVector3D tangent new LowLevel.Math.real_vector3d( uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle(), uncompressed_reader.ReadSingle())); //RealPoint2D texcoord0 common_vertex.AddTexcoord(new LowLevel.Math.real_point2d( uncompressed_reader.ReadSingle(), (uncompressed_reader.ReadSingle() * -1) + 1)); //RealPoint2D texcoord1 if (material.LightmapVerticesCount != 0) { int position = (int)uncompressed_reader.BaseStream.Position; uncompressed_reader.BaseStream.Position = (material.VerticesCount * 56) + (vertex_index * 20) + 12; common_vertex.AddTexcoord(new LowLevel.Math.real_point2d( uncompressed_reader.ReadSingle(), (uncompressed_reader.ReadSingle() * -1) + 1)); uncompressed_reader.BaseStream.Position = position; } else { common_vertex.AddTexcoord(new LowLevel.Math.real_point2d(0, 1)); } geometryData.AddVertex(common_vertex); }; } // add part definitions for the lightmap materials // an index offset is necessary since the vertex list is global for this geometry, rather than local to each material int index_offset = 0; foreach (var material in definition.Lightmaps[index].Materials) { Geometry.Part common_part = new Geometry.Part(Path.GetFileNameWithoutExtension(material.Shader.ToString())); common_part.AddIndices(CreateIndicesBSP(definition, material.Surfaces, material.SurfaceCount, index_offset)); index_offset += material.VerticesCount; geometryData.AddPart(common_part); } // create the geometry element CreateGeometry(geometryData); }