///-------------------------------------------------------------------------------------------------
        /// <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);
            }
        }
Exemplo n.º 2
0
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 ///     Performs application-defined tasks associated with freeing, releasing, or resetting
 ///     unmanaged resources.
 /// </summary>
 public void Dispose()
 {
     if (TagIndex.IsValid(mIndexHandle))
     {
         BlamLib.Program.GetManager(mGameVersion).CloseTagIndex(mIndexHandle);
         mIndexInterface = null;
         mIndexHandle    = DatumIndex.Null;
     }
 }
        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);
        }
Exemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>   Exports the provided bsp's lightmap sizes with a multiplier. </summary>
        ///
        /// <param name="tagIndex">         Tag index the bsp belongs to. </param>
        /// <param name="tagManager">       The bsp tag's manager. </param>
        /// <param name="sizeMultiplier">   The lightmap size multiplier. </param>
        /// <param name="outputFile">       The bsp's output file. </param>
        public void Export(TagIndexBase tagIndex, BlamLib.Managers.TagManager tagManager, int sizeMultiplier, string outputFile)
        {
            // Collect the necessary data
            var structureBSP = tagManager.TagDefinition as BlamLib.Blam.Halo1.Tags.structure_bsp_group;

            if (!TagIndex.IsValid(structureBSP.LightmapBitmaps.Datum))
            {
                mMessageHandler.SendMessage("Failed to open lightmap bitmap {0}", structureBSP.LightmapBitmaps.ToString());
                return;
            }

            var bitmapManager = tagIndex[structureBSP.LightmapBitmaps.Datum];

            if (bitmapManager == null)
            {
                mMessageHandler.SendMessage("Failed to open lightmap bitmap {0}", structureBSP.LightmapBitmaps.ToString());
                return;
            }

            if (structureBSP.Lightmaps.Count == 0)
            {
                mMessageHandler.SendMessage("BSP has no lightmaps {0}", tagManager.Name);
                return;
            }

            var bitmap = bitmapManager.TagDefinition as BlamLib.Blam.Halo1.Tags.bitmap_group;

            if (bitmap == null)
            {
                mMessageHandler.SendMessage("Failed to open lightmap bitmap {0}", structureBSP.LightmapBitmaps.ToString());
                return;
            }

            // Build the lightmap size list
            var lightmapSizeList = new List <string>();
            var bspName          = Path.GetFileNameWithoutExtension(tagManager.Name);

            foreach (var lightmap in structureBSP.Lightmaps)
            {
                if (lightmap.Bitmap.Value == -1)
                {
                    continue;
                }

                if (lightmap.Bitmap.Value >= bitmap.Bitmaps.Count)
                {
                    mMessageHandler.SendMessage("Failed to export lightmap sizes. A lightmap bitmap and bsp do not have matching lightmap counts {0}", tagManager.Name);
                    return;
                }

                var bitmapInfo = bitmap.Bitmaps[lightmap.Bitmap.Value];

                lightmapSizeList.Add(String.Format("{0}_{1}\t[{2},{3}]"
                                                   , bspName
                                                   , lightmap.Bitmap.Value
                                                   , bitmapInfo.Width * sizeMultiplier
                                                   , bitmapInfo.Height * sizeMultiplier));
            }

            // Save the sizes to file
            var sizeFileName = Path.ChangeExtension(outputFile, "lmsz");

            try
            {
                using (var outputStream = File.OpenWrite(sizeFileName))
                {
                    var writer = new StreamWriter(outputStream);
                    writer.Write(String.Join("\r\n", lightmapSizeList));
                    writer.Flush();
                }
                mMessageHandler.SendMessage("BSP lightmap sizes saved");
            }
            catch (IOException)
            {
                mMessageHandler.SendMessage("Failed to open the lightmap sizes file");
            }
        }