private MeshElement ConstructExampleMesh() { var mesh = new Mesh(); var gridSize = 10; for (var u = 0; u < gridSize; u += 1) { for (var v = 0; v < gridSize; v += 1) { var sinu = Math.Sin(-Math.PI + 2 * ((double)u / (double)gridSize * Math.PI)); var sinv = Math.Sin(-Math.PI + 2 * ((double)v / (double)gridSize * Math.PI)); var z = sinu + sinv; var vertex = new Geometry.Vertex(new Vector3(u, v, z), color: Colors.Mint); mesh.AddVertex(vertex); if (u > 0 && v > 0) { var index = u * gridSize + v; var a = mesh.Vertices[index]; var b = mesh.Vertices[index - gridSize]; var c = mesh.Vertices[index - 1]; var d = mesh.Vertices[index - gridSize - 1]; var tri1 = new Triangle(a, b, c); var tri2 = new Triangle(c, b, d); mesh.AddTriangle(tri1); mesh.AddTriangle(tri2); } } } mesh.ComputeNormals(); var meshElement = new MeshElement(mesh, new Material("Lime", Colors.Lime), new Transform(new Vector3(-7, -8, 0), new Vector3(-5, 3, 2))); return(meshElement); }
public Face CreateFace(Geometry.Vertex vertex) { Face face; if (faces.TryGet(out face)) { face.id = vertex.id; face.generator = vertex; face.edge = null; return(face); } face = new Face(vertex); faces.Put(face); return(face); }
///------------------------------------------------------------------------------------------------- /// <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); } }
public Face CreateFace(Geometry.Vertex vertex) { return(new Face(vertex)); }
///------------------------------------------------------------------------------------------------- /// <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); }