示例#1
0
        public override object Execute(List <string> args)
        {
            if (args.Count != 3)
            {
                return(false);
            }

            var variantName   = args[0];
            var fileType      = args[1].ToLower();
            var modelFileName = args[2];

            switch (fileType)
            {
            case "obj":
            case "amf":
            case "dae":
                break;

            default:
                throw new NotImplementedException(fileType);
            }

            //
            // Find the variant to extract
            //

            if (Definition.RenderModel == null)
            {
                Console.WriteLine("The model does not have a render model associated with it.");
                return(true);
            }


            var modelVariant = Definition.Variants.FirstOrDefault(v => (CacheContext.GetString(v.Name) ?? v.Name.ToString()) == variantName);

            if (modelVariant == null && Definition.Variants.Count > 0 && fileType != "dae")
            {
                Console.WriteLine("Unable to find variant \"{0}\"", variantName);
                Console.WriteLine("Use \"listvariants\" to list available variants.");
                return(true);
            }

            //
            // Deserialize the render model tag
            //

            RenderModel renderModel;

            using (var cacheStream = CacheContext.TagCacheFile.OpenRead())
            {
                renderModel = CacheContext.Deserialize <RenderModel>(cacheStream, Definition.RenderModel);
            }

            if (renderModel.Geometry.Resource == null)
            {
                Console.WriteLine("Render model does not have a resource associated with it");
                return(true);
            }

            //
            // Deserialize the resource definition
            //

            var resourceContext    = new ResourceSerializationContext(CacheContext, renderModel.Geometry.Resource);
            var resourceDefinition = CacheContext.Deserialize <RenderGeometryApiResourceDefinition>(resourceContext);

            using (var resourceStream = new MemoryStream())
            {
                //
                // Extract the resource data
                //

                CacheContext.ExtractResource(renderModel.Geometry.Resource, resourceStream);

                var modelFile = new FileInfo(modelFileName);

                if (!modelFile.Directory.Exists)
                {
                    modelFile.Directory.Create();
                }

                switch (fileType)
                {
                case "obj":
                    ExtractObj(modelFile, renderModel, modelVariant, resourceDefinition, resourceStream);
                    break;

                case "amf":
                    ExtractAmf(modelFile, renderModel, modelVariant, resourceDefinition, resourceStream);
                    break;

                case "dae":
                    ModelExtractor extractor = new ModelExtractor(CacheContext, renderModel);
                    extractor.ExtractRenderModel();
                    extractor.ExportCollada(modelFile);
                    break;

                default:
                    throw new NotImplementedException(fileType);
                }
            }

            Console.WriteLine("Done!");

            return(true);
        }
示例#2
0
        public override object Execute(List <string> args)
        {
            string variantName;
            string fileType;
            string modelFileName;

            if (args.Count == 2)
            {
                variantName   = "*";
                fileType      = args[0].ToLower();
                modelFileName = args[1];
            }
            else if (args.Count == 3)
            {
                variantName   = args[0];
                fileType      = args[1].ToLower();
                modelFileName = args[2];
            }
            else
            {
                return(false);
            }

            switch (fileType)
            {
            case "obj":
            case "dae":
                break;

            default:
                throw new NotImplementedException(fileType);
            }

            if (Definition.Geometry.Resource == null)
            {
                Console.WriteLine("Render model does not have a resource associated with it");
                return(true);
            }

            //
            // Deserialize the resource definition
            //

            var resourceContext    = new ResourceSerializationContext(CacheContext, Definition.Geometry.Resource);
            var resourceDefinition = CacheContext.Deserializer.Deserialize <RenderGeometryApiResourceDefinition>(resourceContext);

            using (var resourceStream = new MemoryStream())
            {
                //
                // Extract the resource data
                //

                CacheContext.ExtractResource(Definition.Geometry.Resource, resourceStream);

                var modelFile = new FileInfo(modelFileName);

                if (!modelFile.Directory.Exists)
                {
                    modelFile.Directory.Create();
                }

                ModelExtractor extractor = new ModelExtractor(CacheContext, Definition);
                extractor.ExtractRenderModel(variantName);

                switch (fileType)
                {
                case "obj":
                    return(extractor.ExportObject(modelFile));

                case "dae":
                    return(extractor.ExportCollada(modelFile));

                default:
                    throw new NotImplementedException(fileType);
                }
            }
        }