///------------------------------------------------------------------------------------------------- /// <summary> Create the markers. </summary> ///------------------------------------------------------------------------------------------------- void CreateMarkerList() { var markerInstances = mModelDataProvider.GetMarkerInstances(); var markerList = new List <Marker>(); // create a list of generic marker definitions foreach (var markerInstance in markerInstances) { // if multiple permutations are being exported, append the marker permutation to its name string name = ColladaUtilities.FormatName(markerInstance.MarkerType.Name, " ", "_"); name += "-perm" + markerInstance.Permutation.ToString(); var common_marker = new Marker(name, markerInstance.Position.ToPoint3D(100), TagInterface.RealQuaternion.Invert(markerInstance.Rotation), markerInstance.Bone); markerList.Add(common_marker); } // create the marker node elements CreateMarkers(markerList , new LowLevel.Math.real_vector3d(1, 0, 0) , new LowLevel.Math.real_vector3d(0, 0, 1) , new LowLevel.Math.real_vector3d(0, 1, 0) , ColladaUtilities.ColladaRotationOrder.ZYX ); }
/// <summary> /// Creates geometries for the relevant meshes that are to be included in the collada file /// </summary> void CreateGeometryList() { H2.Tags.render_model_group definition = tagManager.TagDefinition as H2.Tags.render_model_group; // create a list of shader names List <string> shader_names = new List <string>(); foreach (var material in definition.Materials) { shader_names.Add(Path.GetFileNameWithoutExtension(material.Shader.ToString())); } // create a geometry element for each geometry in the modelInfo for (int i = 0; i < modelInfo.GetGeometryCount(); i++) { string name = ColladaUtilities.FormatName(modelInfo.GetGeometryName(i), " ", "_"); var section = definition.Sections[modelInfo.GetGeometryIndex(i)]; // create the geometry element CreateGeometryHalo2(name, true, section.SectionInfo, section.SectionData[0].Section, shader_names); } }
/// <summary> /// Creates geometries for the relevant lightmap meshes that are to be included in the collada file /// </summary> void CreateGeometryList() { H2.Tags.scenario_structure_bsp_group definition = tagManager.TagDefinition as H2.Tags.scenario_structure_bsp_group; if (bspInfo.IncludeRenderMesh()) { // create a list of all the shaders used List <string> shader_list = new List <string>(); foreach (var material in definition.Materials) { shader_list.Add(Path.GetFileNameWithoutExtension(material.Shader.ToString())); } // create a geometry element for each cluster for (int i = 0; i < definition.Clusters.Count; i++) { string name = String.Format("{0}-{1}", ColladaUtilities.FormatName(tagName, " ", "_"), i); // create the geometry element CreateGeometryHalo2(name, false, definition.Clusters[i].SectionInfo, definition.Clusters[i].ClusterData[0].Section.Value, shader_list); } } if (bspInfo.IncludePortalsMesh()) { // create a geometry element for each cluster portal for (int i = 0; i < definition.ClusterPortals.Count; i++) { CreatePortalsGeometry(i); } } }
///------------------------------------------------------------------------------------------------- /// <summary> Creates the node list. </summary> ///------------------------------------------------------------------------------------------------- private void CreateNodeList() { // Get all of the object instances to include var objectInstances = mScenarioDataProvider.GetObjectInstances(); for (int i = 0; i < objectInstances.Count; i++) { var objectInstance = objectInstances[i]; // Create a node for the object instance ColladaNCName nodeName = ""; if (objectInstance.ObjectName == null) { if (!TagIndex.IsValid(objectInstance.ObjectType.ObjectTagDatum)) { throw new ColladaException("Failed to load the object type tag {0}", objectInstance.ObjectType.ObjectTagPath); } ColladaNCName objectName = Path.GetFileNameWithoutExtension(mTagIndex[objectInstance.ObjectType.ObjectTagDatum].Name); nodeName = i.ToString() + "-" + objectName; } else { nodeName = objectInstance.ObjectName.Name; } var node = CreateNode(nodeName, "", "", Enums.ColladaNodeType.NODE); // Set the nodes position var translate = new Core.ColladaTranslate(); translate.SetTranslate(objectInstance.Position, 100); node.Add(translate); // Set the nodes rotation node.AddRange( ColladaUtilities.CreateRotationSet(objectInstance.Rotation.R, objectInstance.Rotation.P, objectInstance.Rotation.Y , new LowLevel.Math.real_vector3d(1, 0, 0) , new LowLevel.Math.real_vector3d(0, -1, 0) , new LowLevel.Math.real_vector3d(0, 0, 1) , ColladaUtilities.ColladaRotationOrder.XYZ) ); var nodeIdList = GetNodeReferences(objectInstance.ObjectType, objectInstance.Permutation.ToString("D2")); if (nodeIdList.Count > 0) { node.InstanceNode = new List <ColladaInstanceNode>(); foreach (var nodeId in nodeIdList) { node.InstanceNode.Add(new ColladaInstanceNode() { URL = "#" + nodeId }); } } listNode.Add(node); } }
/// <summary> /// Creates nodes for all the geometry elements in the collada file /// </summary> void CreateNodeList() { H1.Tags.structure_bsp_group definition = tagManager.TagDefinition as H1.Tags.structure_bsp_group; // create a list of ever shader used List <string> shader_list = new List <string>(); for (int shader_index = 0; shader_index < shaderInfo.GetShaderCount(); shader_index++) { shader_list.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(shaderInfo.GetShaderName(shader_index)), " ", "_")); } // if portals are included add the portals shader to the names if (bspInfo.IncludePortalsMesh()) { shader_list.Add("portals"); } // if fogplanes are included add the fogplanes shader to the names if (bspInfo.IncludeFogPlanesMesh()) { shader_list.Add("fogplanes"); } int geometry_offset = 0; if (bspInfo.IncludeRenderMesh()) { // create geometry instance for all of the lightmaps for (int i = 0; i < definition.Lightmaps.Count; i++) { CreateNodeInstanceGeometry(listGeometry[geometry_offset + i].Name, geometry_offset + i, shader_list); } geometry_offset += definition.Lightmaps.Count; } if (bspInfo.IncludePortalsMesh()) { // create geometry instance for all of the portal meshes for (int i = 0; i < definition.ClusterPortals.Count; i++) { CreateNodeInstanceGeometry(listGeometry[geometry_offset + i].Name, geometry_offset + i, shader_list); } geometry_offset += definition.ClusterPortals.Count; } if (bspInfo.IncludeFogPlanesMesh()) { // create geometry instance for all of the fogplane meshes for (int i = 0; i < definition.FogPlanes.Count; i++) { CreateNodeInstanceGeometry(listGeometry[geometry_offset + i].Name, geometry_offset + i, shader_list); } geometry_offset += definition.FogPlanes.Count; } }
///------------------------------------------------------------------------------------------------- /// <summary> Creates instances of all the controllers. </summary> ///------------------------------------------------------------------------------------------------- void CreateNodeList() { var materialReferences = new MaterialReferenceList(); if (mShaderDataProvider != null) { // create a list of every shader used foreach (var effect in mShaderDataProvider.GetEffects()) { string effectName = ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(effect.Name), " ", "_"); materialReferences.Add(new MaterialReference( effectName, ColladaUtilities.BuildUri(ColladaElement.FormatID <Fx.ColladaMaterial>(effectName)), effectName)); } } // create the controller instances var geometrySetList = mModelDataProvider.GetGeometries(); for (int i = 0; i < geometrySetList.Count; i++) { var node = CreateNode(geometrySetList[i].Name, "", geometrySetList[i].Name, Enums.ColladaNodeType.NODE); // If there are no bones instance the static geometry, otherwise create a skinned instance string name = ColladaUtilities.FormatName(geometrySetList[i].Name, " ", "_"); if (mModelDataProvider.GetBones().Count == 0) { node.Add( CreateInstanceGeometry( ColladaUtilities.BuildUri(ColladaElement.FormatID <Core.ColladaGeometry>(name)), name, materialReferences ) ); } else { node.Add( CreateInstanceController( ColladaUtilities.BuildUri(ColladaElement.FormatID <Core.ColladaController>(name)), name, materialReferences ) ); } listNode.Add(node); } }
/// <summary> /// Creates nodes for all the geometry elements in the collada file /// </summary> void CreateNodeList() { // create a geometry instance for each geometry that has been created for (int i = 0; i < listGeometry.Count; i++) { string url = ColladaUtilities.BuildUri(listGeometry[i].ID); string name = listGeometry[i].ID; Core.ColladaNode node = CreateNode(name, "", name, Enums.ColladaNodeType.NODE); node.Add(CreateInstanceGeometry(url, listGeometry[i].Name, new MaterialReferenceList())); listNode.Add(node); } }
/// <summary> /// Creates instances of all the controllers /// </summary> void CreateNodeList() { // create a string list of all the shaders being used List <string> shader_list = new List <string>(); for (int shader_index = 0; shader_index < shaderInfo.GetShaderCount(); shader_index++) { shader_list.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(shaderInfo.GetShaderName(shader_index)), " ", "_")); } // create the controller instances for (int i = 0; i < modelInfo.GetGeometryCount(); i++) { CreateNodeInstanceController(modelInfo.GetGeometryName(i), i, shader_list); } }
/// <summary> /// Creates nodes for all the geometry elements in the collada file /// </summary> void CreateNodeList() { // create a list of all the shaders used in the file List <string> shader_list = new List <string>(); for (int shader_index = 0; shader_index < shaderInfo.GetShaderCount(); shader_index++) { shader_list.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(shaderInfo.GetShaderName(shader_index)), " ", "_")); } // create a controller instance for each geometry for (int i = 0; i < listGeometry.Count; i++) { CreateNodeInstanceController(listGeometry[i].Name, i, shader_list); } }
/// <summary> /// Creates nodes for the models marker instances /// </summary> void CreateMarkerList() { H2.Tags.render_model_group definition = tagManager.TagDefinition as H2.Tags.render_model_group; List <Marker> marker_list = new List <Marker>(); // create a list of generic marker definitions foreach (var marker in definition.MarkerGroups) { string marker_name = ColladaUtilities.FormatName(marker.Name.ToString(), " ", "_"); foreach (var instance in marker.Markers) { string name = marker_name; // the permutation index is 255 it is valid for all permutations so add it regardless if (instance.PermutationIndex.Value != 255) { // if exporting a single permutation and the instance permutation doesnt match, continue // otherwise if we are exporting multiple permutations append the instances permutation index to its name if (!modelInfo.GetIsMultiplePerms()) { if (modelInfo.GetPermutation() != instance.PermutationIndex.Value) { continue; } } else { name += "-perm" + instance.PermutationIndex.Value.ToString(); } } Marker common_marker = new Marker(name, instance.Translation.ToPoint3D(100), instance.Rotation.ToQuaternion(), instance.NodeIndex); marker_list.Add(common_marker); } } // create the marker node elements CreateMarkers(marker_list, RotationVectorY, RotationVectorP, RotationVectorR); }
/// <summary> /// Creates nodes for all the geometry elements in the collada file /// </summary> void CreateNodeList() { // create a list of all the shaders used in the file //List<string> shader_list = new List<string>(); //for (int shader_index = 0; shader_index < shaderInfo.GetShaderCount(); shader_index++) // shader_list.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(shaderInfo.GetShaderName(shader_index)), " ", "_")); // create a controller instance for each geometry for (int i = 0; i < listGeometry.Count; i++) { string url = ColladaUtilities.BuildUri(listGeometry[i].ID); string name = listGeometry[i].ID; Core.ColladaNode node = CreateNode(name, "", name, Enums.ColladaNodeType.NODE); node.Add(CreateInstanceGeometry(url, listGeometry[i].Name, new MaterialReferenceList())); listNode.Add(node); } }
/// <summary> /// Creates geometries for the relevant lightmap meshes that are to be included in the collada file /// </summary> void CreateGeometryList() { H2.Tags.scenario_structure_lightmap_group definition = tagManager.TagDefinition as H2.Tags.scenario_structure_lightmap_group; // create a geometry for each lightmap cluster for (int i = 0; i < definition.LightmapGroups.Count; i++) { var lm_group = definition.LightmapGroups[i]; for (int j = 0; j < lm_group.Clusters.Count; j++) { string name = String.Format("{0}-group{1}-cluster{2}", ColladaUtilities.FormatName(tagName, " ", "_"), i, j); // create the geometry element CreateGeometryHalo2(name, false, lm_group.Clusters[j].GeometryInfo, lm_group.Clusters[j].CacheData[0].Geometry.Value, new List <string>()); } } }
/// <summary> /// Creates nodes for all the geometry elements in the collada file /// </summary> void CreateNodeList() { H2.Tags.scenario_structure_bsp_group definition = tagManager.TagDefinition as H2.Tags.scenario_structure_bsp_group; // create a list of all the shaders used List <string> shader_list = new List <string>(); for (int shader_index = 0; shader_index < shaderInfo.GetShaderCount(); shader_index++) { shader_list.Add(ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(shaderInfo.GetShaderName(shader_index)), " ", "_")); } // if portals are included and the portals material to the list if (bspInfo.IncludePortalsMesh()) { shader_list.Add("portals"); } // create a geometry instances for the render geometry int geometry_offset = 0; if (bspInfo.IncludeRenderMesh()) { for (int i = 0; i < definition.Clusters.Count; i++) { CreateNodeInstanceGeometry(listGeometry[geometry_offset + i].Name, geometry_offset + i, shader_list); } geometry_offset += definition.Clusters.Count; } // create a geometry instances for the portal geometry if (bspInfo.IncludePortalsMesh()) { for (int i = 0; i < definition.ClusterPortals.Count; i++) { CreateNodeInstanceGeometry(listGeometry[geometry_offset + i].Name, geometry_offset + i, shader_list); } geometry_offset += definition.ClusterPortals.Count; } }
/// <summary> /// Create the markers /// </summary> void CreateMarkerList() { H1.Tags.gbxmodel_group definition = tagManager.TagDefinition as H1.Tags.gbxmodel_group; List <Marker> marker_list = new List <Marker>(); // create a list of generic marker definitions foreach (var marker in definition.Markers) { foreach (var instance in marker.Instances) { // if we are only exporting one permutation and the marker permunation doesnt match, skip it if (!modelInfo.GetIsMultiplePerms()) { if (modelInfo.GetPermutation() != instance.PermutationIndex.Value) { continue; } } // if multiple permutations are being exported, append the marker permutation to its name string name = ColladaUtilities.FormatName(marker.Name, " ", "_"); if (modelInfo.GetIsMultiplePerms()) { name += "-perm" + instance.PermutationIndex.Value.ToString(); } Marker common_marker = new Marker(name, instance.Translation.ToPoint3D(100), TagInterface.RealQuaternion.Invert(instance.Rotation), instance.NodeIndex); marker_list.Add(common_marker); } } // create the marker node elements CreateMarkers(marker_list, RotationVectorY, RotationVectorP, RotationVectorR); }
/// <summary> /// Creates a geometry element for a BSP lightmap /// </summary> /// <param name="index">The lightmap index to create a geometry from</param> /// <returns></returns> void CreateRenderGeometry(int index) { H1.Tags.structure_bsp_group definition = tagManager.TagDefinition as H1.Tags.structure_bsp_group; List <Vertex> common_vertices = new List <Vertex>(); // 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.VertexBuffersCount1; for (int vertex_index = 0; vertex_index < vertex_count; vertex_index++) { Vertex common_vertex = new 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.VertexBuffersCount2 != 0) { int position = (int)uncompressed_reader.BaseStream.Position; uncompressed_reader.BaseStream.Position = (material.VertexBuffersCount1 * 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)); } common_vertices.Add(common_vertex); } ; } List <Part> common_parts = new List <Part>(); // 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) { Part common_part = new Part(Path.GetFileNameWithoutExtension(material.Shader.ToString())); common_part.AddIndices(CreateIndicesBSP(definition, material.Surfaces, material.SurfaceCount, index_offset)); index_offset += material.VertexBuffersCount1; common_parts.Add(common_part); } // create the geometry element CreateGeometry(ColladaUtilities.FormatName(tagName, " ", "_") + "-" + definition.Lightmaps[index].Bitmap.ToString(), 2, VertexComponent.POSITION | VertexComponent.NORMAL | VertexComponent.BINORMAL | VertexComponent.TANGENT | VertexComponent.TEXCOORD, common_vertices, common_parts); }
private List <string> GetNodeReferences(ScenarioData.ScenarioObject objectType, string permutation) { var nodeIds = new List <string>(); // Add geometry instances to the node if (!TagIndex.IsValid(objectType.ObjectTagDatum)) { throw new ColladaException("Failed to load the object type tag {0}", objectType.ObjectTagPath); } var objectName = Path.GetFileNameWithoutExtension(objectType.ObjectTagPath); objectName += "-perm" + permutation; // Collect data about the object var objectData = new ObjectData(); objectData.CollectData(mTagIndex, mTagIndex[objectType.ObjectTagDatum]); if (!TagIndex.IsValid(objectData.Model)) { return(nodeIds); } if (COLLADAFile.LibraryNodes == null) { AddLibraryNodes(); } // Collect data about the model var modelData = new ModelData(); modelData.CollectData(mTagIndex, mTagIndex[objectData.Model]); // Get all of the geometries that make up the permutation at the highest lod var geometryList = modelData.GetGeometries(permutation, Blam.Halo1.TypeEnums.LevelOfDetailEnum.SuperHigh); // Add geometry instances for all geometries foreach (var geometrySet in geometryList) { var name = objectName + "-" + geometrySet.Name; ColladaNCName nodeName = name; ColladaID <ColladaNode> nodeId = name; nodeIds.Add(nodeId); if (COLLADAFile.LibraryNodes.Node.Exists(node => node.ID == nodeId.ToString())) { break; } // Create shader references for all shaders used by the geometry var materialReferences = new MaterialReferenceList(); foreach (var shader in geometrySet.Shaders) { ColladaNCName symbolName = shader.MaterialName; ColladaID <Fx.ColladaMaterial> shaderName = shader.MaterialName; var url = ColladaUtilities.BuildExternalReference(modelData, colladaSettings.RootDirectory, shaderName); materialReferences.Add(new MaterialReference(shaderName, url, symbolName)); } // Build the geometry reference URL and add the geometry instance string geometryURL = ColladaUtilities.BuildExternalReference(modelData, colladaSettings.RootDirectory, new ColladaID <Core.ColladaGeometry>(geometrySet.Name)); var nodeType = CreateNode(nodeName, "", nodeId, Enums.ColladaNodeType.NODE); nodeType.Add(CreateInstanceGeometry(geometryURL, geometrySet.Name, materialReferences)); COLLADAFile.LibraryNodes.Node.Add(nodeType); } return(nodeIds); }
///------------------------------------------------------------------------------------------------- /// <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 override string ToString() { return(ColladaUtilities.FormatName(mValue, " ", "_")); }
///------------------------------------------------------------------------------------------------- /// <summary> Builds external reference URI. </summary> /// <param name="externalReference"> The external reference source. </param> /// <param name="rootDirectory"> Pathname of the root directory. </param> /// <param name="id"> The identifier of the element to referenec. </param> /// <returns> The absolute URI of the external element reference. </returns> ///------------------------------------------------------------------------------------------------- public static string BuildExternalReference(IColladaExternalReference externalReference, string rootDirectory, string id) { return(ColladaUtilities.BuildUri("file://", Path.Combine(rootDirectory, externalReference.GetRelativeURL()) + ".dae", id)); }
///------------------------------------------------------------------------------------------------- /// <summary> Creates nodes for all the geometry elements in the collada file. </summary> ///------------------------------------------------------------------------------------------------- private void CreateNodeList() { // Create the list of materials for the geometry to use var materialReferences = new MaterialReferenceList(); Action <string> addMaterialRef = effectName => { string name = ColladaUtilities.FormatName(Path.GetFileNameWithoutExtension(effectName), " ", "_"); materialReferences.Add(new MaterialReference( effectName, ColladaUtilities.BuildUri(ColladaElement.FormatID <Fx.ColladaMaterial>(name)), name)); }; if (mShaderDataProvider != null) { // create a list of every shader used if (mBSPDataProvider.IncludeRenderMesh) { foreach (var effect in mShaderDataProvider.GetEffects()) { addMaterialRef(effect.Name); } } // if portals are included add the portals shader to the names if (mBSPDataProvider.IncludePortals) { addMaterialRef("portals"); } // if fogplanes are included add the fogplanes shader to the names if (mBSPDataProvider.IncludeFogPlanes) { addMaterialRef("fogplanes"); } } // Create a node with a geometry instance for all included geometry var definition = mTagManager.TagDefinition as H1.Tags.structure_bsp_group; Func <int, Core.ColladaNode> addGeometryInstance = geometryIndex => { string name = listGeometry[geometryIndex].Name; var node = CreateNode(name, "", name, Enums.ColladaNodeType.NODE); string url = ColladaUtilities.BuildUri(listGeometry[geometryIndex].ID); node.Add(CreateInstanceGeometry(url, name, materialReferences)); return(node); }; int geometry_offset = 0; if (mBSPDataProvider.IncludeRenderMesh) { // create geometry instance for all of the lightmaps for (int i = 0; i < definition.Lightmaps.Count; i++) { listNode.Add(addGeometryInstance(geometry_offset + i)); } geometry_offset += definition.Lightmaps.Count; } if (mBSPDataProvider.IncludePortals) { // create geometry instance for all of the portal meshes for (int i = 0; i < definition.ClusterPortals.Count; i++) { listNode.Add(addGeometryInstance(geometry_offset + i)); } geometry_offset += definition.ClusterPortals.Count; } if (mBSPDataProvider.IncludeFogPlanes) { // create geometry instance for all of the fogplane meshes for (int i = 0; i < definition.FogPlanes.Count; i++) { listNode.Add(addGeometryInstance(geometry_offset + i)); } geometry_offset += definition.FogPlanes.Count; } }
/// <summary> /// Creates geometry elements for all of the included geometry blocks /// </summary> void CreateGeometryList() { H1.Tags.gbxmodel_group definition = tagManager.TagDefinition as H1.Tags.gbxmodel_group; // create a list contining the names of all the shaders being used List <string> shader_names = new List <string>(); foreach (var shader in definition.Shaders) { shader_names.Add(Path.GetFileNameWithoutExtension(shader.Shader.ToString())); } for (int i = 0; i < modelInfo.GetGeometryCount(); i++) { string name = ColladaUtilities.FormatName(modelInfo.GetGeometryName(i), " ", "_"); List <Vertex> common_vertices = new List <Vertex>(); H1.Tags.gbxmodel_group.model_geometry_block geometry = definition.Geometries[modelInfo.GetGeometryIndex(i)]; // collect the vertices for all of the geometries parts foreach (var part in geometry.Parts) { foreach (var vertex in part.UncompressedVertices) { Vertex common_vertex = new 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)); common_vertices.Add(common_vertex); } } List <Part> common_parts = new List <Part>(); // create a new Part for each geometry part int index_offset = 0; foreach (var part in geometry.Parts) { Part common_part = new Part(shader_names[part.ShaderIndex]); common_part.AddIndices(CreateIndicesModel(part, index_offset)); index_offset += part.UncompressedVertices.Count; common_parts.Add(common_part); } // create the geometry element CreateGeometry(name, 1, VertexComponent.POSITION | VertexComponent.NORMAL | VertexComponent.BINORMAL | VertexComponent.TANGENT | VertexComponent.TEXCOORD, common_vertices, common_parts); } }