/// <summary> /// Imports the model. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="importParameters">The parameters used to import the model.</param> /// <returns>A collection of assets.</returns> public override IEnumerable<AssetItem> Import(UFile localPath, AssetImporterParameters importParameters) { var rawAssetReferences = new List<AssetItem>(); // the asset references without subdirectory path var entityInfo = GetEntityInfo(localPath, importParameters.Logger); //var isImportingEntity = importParameters.IsTypeSelectedForOutput<EntityAsset>(); var isImportingModel = importParameters.IsTypeSelectedForOutput<ModelAsset>(); var isImportingMaterial = importParameters.IsTypeSelectedForOutput<MaterialAsset>() || isImportingModel; var isImportingTexture = importParameters.IsTypeSelectedForOutput<TextureAsset>() || isImportingMaterial; // 1. Textures if (isImportingTexture) { ImportTextures(entityInfo.TextureDependencies, rawAssetReferences); } // 2. Skeleton AssetItem skeletonAsset = null; if (importParameters.IsTypeSelectedForOutput<SkeletonAsset>()) { skeletonAsset = ImportSkeleton(rawAssetReferences, localPath, localPath, entityInfo); } // 3. Animation if (importParameters.IsTypeSelectedForOutput<AnimationAsset>()) { ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel, skeletonAsset); } // 4. Materials if (isImportingMaterial) { ImportMaterials(rawAssetReferences, entityInfo.Materials); } // 5. Model if (isImportingModel) { var modelItem = ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false, skeletonAsset); // 5. Entity (currently disabled) //if (isImportingEntity) //{ // var entityAssetItem = ImportEntity(rawAssetReferences, localPath, modelItem); // // // Apply EntityAnalysis // EntityAnalysis.UpdateEntityReferences(((EntityAsset)entityAssetItem.Asset).Hierarchy); //} } return rawAssetReferences; }
public override IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { var asset = new TextureAsset { Source = rawAssetPath }; // Creates the url to the texture var textureUrl = new UFile(rawAssetPath.GetFileName(), null); yield return new AssetItem(textureUrl, asset); }
/// <inheritdoc/> public override EntityInfo GetEntityInfo(UFile localPath, Logger logger, AssetImporterParameters importParameters) { var meshConverter = new Importer.AssimpNET.MeshConverter(logger); if (!importParameters.InputParameters.TryGet(DeduplicateMaterialsKey, out var deduplicateMaterials)) { deduplicateMaterials = true; // Dedupe is the default value } var entityInfo = meshConverter.ExtractEntity(localPath.FullPath, null, importParameters.IsTypeSelectedForOutput(typeof(TextureAsset)), deduplicateMaterials); return(entityInfo); }
protected override IEnumerable <AssetItem> CreateAssets(AssetTemplateGeneratorParameters parameters) { var files = parameters.Tags.Get(SourceFilesPathKey); if (files == null) { return(base.CreateAssets(parameters)); } var importMaterials = parameters.Tags.Get(ImportMaterialsKey); var deduplicateMaterials = parameters.Tags.Get(DeduplicateMaterialsKey); var importTextures = parameters.Tags.Get(ImportTexturesKey); var importSkeleton = parameters.Tags.Get(ImportSkeletonKey); var skeletonToReuse = parameters.Tags.Get(SkeletonToUseKey); var importParameters = new AssetImporterParameters { Logger = parameters.Logger }; importParameters.InputParameters.Set(ModelAssetImporter.DeduplicateMaterialsKey, deduplicateMaterials); importParameters.SelectedOutputTypes.Add(typeof(ModelAsset), true); importParameters.SelectedOutputTypes.Add(typeof(MaterialAsset), importMaterials); importParameters.SelectedOutputTypes.Add(typeof(TextureAsset), importTextures); importParameters.SelectedOutputTypes.Add(typeof(SkeletonAsset), importSkeleton); var importedAssets = new List <AssetItem>(); foreach (var file in files) { // TODO: should we allow to select the importer? var importer = AssetRegistry.FindImporterForFile(file).OfType <ModelAssetImporter>().FirstOrDefault(); if (importer == null) { parameters.Logger.Warning($"No importer found for file \"{file}\""); continue; } var assets = importer.Import(file, importParameters).Select(x => new AssetItem(UPath.Combine(parameters.TargetLocation, x.Location), x.Asset)).ToList(); foreach (var model in assets.Select(x => x.Asset).OfType <ModelAsset>()) { if (skeletonToReuse != null) { model.Skeleton = skeletonToReuse; } } // Create unique names amongst the list of assets importedAssets.AddRange(MakeUniqueNames(assets)); } return(importedAssets); }
public override IEnumerable <AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { var outputAssets = new List <AssetItem>(); if (!SpriteStudioXmlImport.SanityCheck(rawAssetPath)) { importParameters.Logger.Error("Invalid xml file or some required files are missing."); return(null); } //pre-process models var nodes = new List <SpriteStudioNode>(); string modelName; if (!SpriteStudioXmlImport.ParseModel(rawAssetPath, nodes, out modelName)) { importParameters.Logger.Error("Failed to parse SpriteStudio model."); return(null); } if (importParameters.IsTypeSelectedForOutput <SpriteStudioModelAsset>()) { var model = new SpriteStudioModelAsset { Source = rawAssetPath }; foreach (var node in nodes) { model.NodeNames.Add(node.Name); } outputAssets.Add(new AssetItem(modelName, model)); } if (importParameters.IsTypeSelectedForOutput <SpriteStudioAnimationAsset>()) { //pre-process anims var anims = new List <SpriteStudioAnim>(); if (!SpriteStudioXmlImport.ParseAnimations(rawAssetPath, anims)) { importParameters.Logger.Error("Failed to parse SpriteStudio animations."); return(null); } foreach (var studioAnim in anims) { var anim = new SpriteStudioAnimationAsset { Source = rawAssetPath, AnimationName = studioAnim.Name }; outputAssets.Add(new AssetItem(modelName + "_" + studioAnim.Name, anim)); } } return(outputAssets); }
/// <summary> /// Imports the model. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="importParameters">The parameters used to import the model.</param> /// <returns>A collection of assets.</returns> public override IEnumerable <AssetItem> Import(UFile localPath, AssetImporterParameters importParameters) { var rawAssetReferences = new List <AssetItem>(); // the asset references without subdirectory path var entityInfo = GetEntityInfo(localPath, importParameters.Logger); //var isImportingEntity = importParameters.IsTypeSelectedForOutput<EntityAsset>(); var isImportingModel = importParameters.IsTypeSelectedForOutput <ModelAsset>(); var isImportingMaterial = importParameters.IsTypeSelectedForOutput <MaterialAsset>() || isImportingModel; var isImportingTexture = importParameters.IsTypeSelectedForOutput <TextureAsset>() || isImportingMaterial; // 1. Textures if (isImportingTexture) { ImportTextures(entityInfo.TextureDependencies, rawAssetReferences); } // 2. Animation if (importParameters.IsTypeSelectedForOutput <AnimationAsset>()) { ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel); } // 3. Materials if (isImportingMaterial) { ImportMaterials(rawAssetReferences, entityInfo.Materials); } // 4. Model if (isImportingModel) { var modelItem = ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false); // 5. Entity (currently disabled) //if (isImportingEntity) //{ // var entityAssetItem = ImportEntity(rawAssetReferences, localPath, modelItem); // // // Apply EntityAnalysis // EntityAnalysis.UpdateEntityReferences(((EntityAsset)entityAssetItem.Asset).Hierarchy); //} } return(rawAssetReferences); }
/// <summary> /// Imports the model. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="importParameters">The parameters used to import the model.</param> /// <returns>A collection of assets.</returns> public override IEnumerable <AssetItem> Import(UFile localPath, AssetImporterParameters importParameters) { var rawAssetReferences = new List <AssetItem>(); // the asset references without subdirectory path var entityInfo = GetEntityInfo(localPath, importParameters.Logger, importParameters); //var isImportingEntity = importParameters.IsTypeSelectedForOutput<PrefabAsset>(); var isImportingModel = importParameters.IsTypeSelectedForOutput <ModelAsset>(); var isImportingMaterial = importParameters.IsTypeSelectedForOutput <MaterialAsset>(); var isImportingTexture = importParameters.IsTypeSelectedForOutput <TextureAsset>(); // 1. Textures if (isImportingTexture) { ImportTextures(entityInfo.TextureDependencies, rawAssetReferences); } // 2. Skeleton AssetItem skeletonAsset = null; if (importParameters.IsTypeSelectedForOutput <SkeletonAsset>()) { skeletonAsset = ImportSkeleton(rawAssetReferences, localPath, localPath, entityInfo); } // 3. Animation if (importParameters.IsTypeSelectedForOutput <AnimationAsset>()) { TimeSpan startTime, endTime; GetAnimationDuration(localPath, importParameters.Logger, importParameters, out startTime, out endTime); ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel, skeletonAsset, startTime, endTime); } // 4. Materials if (isImportingMaterial) { ImportMaterials(rawAssetReferences, entityInfo.Materials); } // 5. Model if (isImportingModel) { ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false, skeletonAsset); } return(rawAssetReferences); }
public override IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { var outputAssets = new List<AssetItem>(); if (!SpriteStudioXmlImport.SanityCheck(rawAssetPath)) { importParameters.Logger.Error("Invalid xml file or some required files are missing."); return null; } //pre-process models var nodes = new List<SpriteStudioNode>(); string modelName; if (!SpriteStudioXmlImport.ParseModel(rawAssetPath, nodes, out modelName)) { importParameters.Logger.Error("Failed to parse Sprite Studio model."); return null; } if (importParameters.IsTypeSelectedForOutput<SpriteStudioModelAsset>()) { var model = new SpriteStudioModelAsset { Source = rawAssetPath }; foreach (var node in nodes) { model.NodeNames.Add(node.Name); } outputAssets.Add(new AssetItem(modelName, model)); } if (importParameters.IsTypeSelectedForOutput<SpriteStudioAnimationAsset>()) { //pre-process anims var anims = new List<SpriteStudioAnim>(); if (!SpriteStudioXmlImport.ParseAnimations(rawAssetPath, anims)) { importParameters.Logger.Error("Failed to parse Sprite Studio animations."); return null; } foreach (var studioAnim in anims) { var anim = new SpriteStudioAnimationAsset { Source = rawAssetPath, AnimationName = studioAnim.Name }; outputAssets.Add(new AssetItem(modelName + "_" + studioAnim.Name, anim)); } } return outputAssets; }
/// <summary> /// Imports the model. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="importParameters">The parameters used to import the model.</param> /// <returns>A collection of assets.</returns> public override IEnumerable<AssetItem> Import(UFile localPath, AssetImporterParameters importParameters) { var rawAssetReferences = new List<AssetItem>(); // the asset references without subdirectory path var entityInfo = GetEntityInfo(localPath, importParameters.Logger, importParameters); //var isImportingEntity = importParameters.IsTypeSelectedForOutput<PrefabAsset>(); var isImportingModel = importParameters.IsTypeSelectedForOutput<ModelAsset>(); var isImportingMaterial = importParameters.IsTypeSelectedForOutput<MaterialAsset>(); var isImportingTexture = importParameters.IsTypeSelectedForOutput<TextureAsset>(); // 1. Textures if (isImportingTexture) { ImportTextures(entityInfo.TextureDependencies, rawAssetReferences); } // 2. Skeleton AssetItem skeletonAsset = null; if (importParameters.IsTypeSelectedForOutput<SkeletonAsset>()) { skeletonAsset = ImportSkeleton(rawAssetReferences, localPath, localPath, entityInfo); } // 3. Animation if (importParameters.IsTypeSelectedForOutput<AnimationAsset>()) { ImportAnimation(rawAssetReferences, localPath, entityInfo.AnimationNodes, isImportingModel, skeletonAsset); } // 4. Materials if (isImportingMaterial) { ImportMaterials(rawAssetReferences, entityInfo.Materials); } // 5. Model if (isImportingModel) { ImportModel(rawAssetReferences, localPath, localPath, entityInfo, false, skeletonAsset); } return rawAssetReferences; }
public override IEnumerable <AssetItem> Import(UFile localPath, AssetImporterParameters importParameters) { var assetItems = base.Import(localPath, importParameters); // Need to remember the DeduplicateMaterials setting per ModelAsset since the importer may be rerun on this asset if (!importParameters.InputParameters.TryGet(DeduplicateMaterialsKey, out var deduplicateMaterials)) { deduplicateMaterials = true; // Dedupe is the default value } foreach (var item in assetItems) { if (item.Asset is ModelAsset modelAsset) { modelAsset.DeduplicateMaterials = deduplicateMaterials; } } return(assetItems); }
/// <inheritdoc/> public override EntityInfo GetEntityInfo(UFile localPath, Logger logger, AssetImporterParameters importParameters) { var meshConverter = new Importer.AssimpNET.MeshConverter(logger); var entityInfo = meshConverter.ExtractEntity(localPath.FullPath, null, importParameters.IsTypeSelectedForOutput(typeof(TextureAsset))); return entityInfo; }
/// <summary> /// Get the total animation clip duration. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="logger">The logger to use to log import message.</param> /// <param name="importParameters">The import parameters.</param> /// <param name="startTime">Returns the first (start) keyframe's time for the animation</param> /// <param name="endTime">Returns the last (end) keyframe's time for the animation</param> public abstract void GetAnimationDuration(UFile localPath, Logger logger, AssetImporterParameters importParameters, out TimeSpan startTime, out TimeSpan endTime);
/// <summary> /// Get the entity information. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="logger">The logger to use to log import message.</param> /// <param name="importParameters">The import parameters.</param> /// <returns>The EntityInfo.</returns> public abstract EntityInfo GetEntityInfo(UFile localPath, Logger logger, AssetImporterParameters importParameters);
public abstract IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters);
public override IEnumerable<AssetItem> Import(UFile rawAssetPath, AssetImporterParameters importParameters) { // Creates the url to the texture var asset = new AssetImportObjectTest { Source = rawAssetPath, Name = rawAssetPath.GetFileName() + "Name" }; var assetUrl = new UFile(rawAssetPath.GetFileName(), null); // Emulate a change in a sub-asset var subAsset = new AssetObjectTestSub() { Value = value }; value++; var subAssetItem = new AssetItem(rawAssetPath.GetFileName() + "_SubAsset", subAsset); asset.References.Add("Test", new AssetReference<AssetObjectTestSub>(subAsset.Id, subAssetItem.Location)); var list = new List<AssetItem> { new AssetItem(assetUrl, asset), subAssetItem }; return list; }
/// <summary> /// Imports the model. /// </summary> /// <param name="localPath">The path of the asset.</param> /// <param name="importParameters">The parameters used to import the model.</param> /// <returns>A collection of assets.</returns> public override IEnumerable <AssetItem> Import(UFile localPath, AssetImporterParameters importParameters) { var assetReferences = new List <AssetItem>(); var entityInfo = GetEntityInfo(localPath, importParameters.Logger); var isImportingEntity = importParameters.IsTypeSelectedForOutput <EntityAsset>(); var isImportingModel = importParameters.IsTypeSelectedForOutput <ModelAsset>() || isImportingEntity; var isImportingMaterial = importParameters.IsTypeSelectedForOutput <MaterialAsset>() || isImportingModel; var isImportingTexture = importParameters.IsTypeSelectedForOutput <TextureAsset>() || isImportingMaterial; var isImportingCamera = importParameters.IsTypeSelectedForOutput <CameraAsset>(); var isImportingLight = importParameters.IsTypeSelectedForOutput <LightAsset>(); // 1. Textures if (isImportingTexture) { ImportTextures(assetReferences, localPath, entityInfo.TextureDependencies); } // 2. Animation if (importParameters.IsTypeSelectedForOutput <AnimationAsset>()) { ImportAnimation(assetReferences, localPath, entityInfo.AnimationNodes); } // 3. Materials if (isImportingMaterial) { ImportMaterials(assetReferences, localPath, entityInfo.Materials); } // 4. Model if (isImportingModel) { var modelItem = ImportModel(assetReferences, localPath, localPath, entityInfo); // 4. Entity if (isImportingEntity) { var entityAsset = ImportEntity(assetReferences, localPath, modelItem, entityInfo); // 5. Camera if (isImportingCamera) { ImportCameras(assetReferences, localPath, entityInfo, entityAsset, modelItem); } // 6. Lights if (isImportingLight) { ImportLights(assetReferences, localPath, entityInfo, entityAsset, modelItem); } } } return(assetReferences); }