예제 #1
0
        public CachedTag ConvertGeometry(int geometryIndex, string desiredTagName = null, bool iscluster = false)
        {
            //return null tag and skip to next bsp if bsp resources is null
            if (StructureBspResources == null)
            {
                return(null);
            }

            var scenarioFolder = Path.GetDirectoryName(Scenario.StructureBsps[StructureBspIndex].StructureBsp.Name);
            var bspName        = Path.GetFileName(Scenario.StructureBsps[StructureBspIndex].StructureBsp.Name);

            var tagName = $"objects\\{scenarioFolder}\\instanced\\instance_{StructureBspIndex}_{geometryIndex}";

            if (iscluster)
            {
                tagName = $"objects\\{scenarioFolder}\\clusters\\cluster_{StructureBspIndex}_{geometryIndex}";
            }

            if (desiredTagName != null)
            {
                tagName = desiredTagName;
            }

            // reset state
            CollisionMaterialMapping = new Dictionary <short, short>();

            // check if we've already converted the tag, if so just return it
            CachedTag scenTag;

            if (DestCache.TryGetTag <Scenery>(tagName, out scenTag))
            {
                return(scenTag);
            }

            // allocate tags
            var modelTag          = DestCache.TagCache.AllocateTag <Model>(tagName);
            var renderModelTag    = DestCache.TagCache.AllocateTag <RenderModel>(tagName);
            var collisionModelTag = DestCache.TagCache.AllocateTag <CollisionModel>(tagName);

            scenTag = DestCache.TagCache.AllocateTag <Scenery>(tagName);

            // generate the definitions
            var renderModel    = GenerateRenderModel(geometryIndex, iscluster);
            var collisionModel = GenerateCollisionModel(modelTag, geometryIndex, iscluster);
            var model          = GenerateModel(renderModel, collisionModel);
            var gameObject     = GenerateObject(geometryIndex, ComputeRenderModelEnclosingRadius(renderModel));

            // fixup tag refs
            model.CollisionModel = collisionModelTag;
            model.RenderModel    = renderModelTag;
            gameObject.Model     = modelTag;

            // finally serialize all the tags
            DestCache.Serialize(DestStream, renderModelTag, renderModel);
            DestCache.Serialize(DestStream, collisionModelTag, collisionModel);
            DestCache.Serialize(DestStream, modelTag, model);
            DestCache.Serialize(DestStream, scenTag, gameObject);

            Console.WriteLine($"['{renderModelTag.Group}', 0x{renderModelTag.Index:X04}] {renderModelTag.Name}");
            Console.WriteLine($"['{collisionModelTag.Group}', 0x{collisionModelTag.Index:X04}] {collisionModelTag.Name}");
            Console.WriteLine($"['{modelTag.Group}', 0x{modelTag.Index:X04}] {modelTag.Name}");
            Console.WriteLine($"['{scenTag.Group}', 0x{scenTag.Index:X04}] {scenTag.Name}");

            return(scenTag);
        }