Example #1
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset       = (SkeletonAsset)assetItem.Asset;
            var assetSource = GetAbsolutePath(assetItem, asset.Source);
            var extension   = assetSource.GetFileExtension();
            var buildStep   = new AssetBuildStep(assetItem);

            var importModelCommand = ImportModelCommand.Create(extension);

            if (importModelCommand == null)
            {
                result.Error($"No importer found for model extension '{extension}. The model '{assetSource}' can't be imported.");
                return;
            }

            importModelCommand.SourcePath    = assetSource;
            importModelCommand.Location      = targetUrlInStorage;
            importModelCommand.Mode          = ImportModelCommand.ExportMode.Skeleton;
            importModelCommand.ScaleImport   = asset.ScaleImport;
            importModelCommand.PivotPosition = asset.PivotPosition;
            importModelCommand.SkeletonNodesWithPreserveInfo = asset.NodesWithPreserveInfo;

            buildStep.Add(importModelCommand);

            result.BuildSteps = buildStep;
        }
Example #2
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset = (ModelAsset)assetItem.Asset;

            // Get absolute path of asset source on disk
            var assetDirectory = assetItem.FullPath.GetParent();
            var assetSource    = UPath.Combine(assetDirectory, asset.Source);

            var gameSettingsAsset         = context.GetGameSettingsAsset();
            var renderingSettings         = gameSettingsAsset.GetOrCreate <RenderingSettings>();
            var allow32BitIndex           = true;
            var maxInputSlots             = 32;
            var allowUnsignedBlendIndices = true;
            var extension = asset.Source.GetFileExtension();

            // Find skeleton asset, if any
            AssetItem skeleton = null;

            if (asset.Skeleton != null)
            {
                skeleton = assetItem.Package.FindAssetFromProxyObject(asset.Skeleton);
            }

            var importModelCommand = ImportModelCommand.Create(extension);

            if (importModelCommand is null)
            {
                result.Error($"No importer found for model extension '{extension}'. The model '{assetSource}' can't be imported.");
                return;
            }

            importModelCommand.InputFilesGetter          = () => GetInputFiles(assetItem);
            importModelCommand.Mode                      = ImportModelCommand.ExportMode.Model;
            importModelCommand.SourcePath                = assetSource;
            importModelCommand.Location                  = targetUrlInStorage;
            importModelCommand.Allow32BitIndex           = allow32BitIndex;
            importModelCommand.MaxInputSlots             = maxInputSlots;
            importModelCommand.AllowUnsignedBlendIndices = allowUnsignedBlendIndices;
            importModelCommand.Materials                 = asset.Materials;
            importModelCommand.ScaleImport               = asset.ScaleImport;
            importModelCommand.PivotPosition             = asset.PivotPosition;
            importModelCommand.MergeMeshes               = asset.MergeMeshes;
            importModelCommand.DeduplicateMaterials      = asset.DeduplicateMaterials;
            importModelCommand.ModelModifiers            = asset.Modifiers;

            if (skeleton != null)
            {
                importModelCommand.SkeletonUrl = skeleton.Location;
                // NOTE: Skeleton override values
                importModelCommand.ScaleImport   = ((SkeletonAsset)skeleton.Asset).ScaleImport;
                importModelCommand.PivotPosition = ((SkeletonAsset)skeleton.Asset).PivotPosition;
            }

            importModelCommand.Package = assetItem.Package;

            result.BuildSteps = new AssetBuildStep(assetItem);
            result.BuildSteps.Add(importModelCommand);
        }
Example #3
0
        protected override void Prepare(AssetCompilerContext context, AssetItem assetItem, string targetUrlInStorage, AssetCompilerResult result)
        {
            var asset             = (AnimationAsset)assetItem.Asset;
            var assetAbsolutePath = assetItem.FullPath;
            // Get absolute path of asset source on disk
            var assetDirectory = assetAbsolutePath.GetParent();
            var assetSource    = GetAbsolutePath(assetItem, asset.Source);
            var extension      = assetSource.GetFileExtension();
            var buildStep      = new AssetBuildStep(assetItem);

            // Find skeleton asset, if any
            AssetItem skeleton = null;

            if (asset.Skeleton != null)
            {
                skeleton = assetItem.Package.FindAssetFromProxyObject(asset.Skeleton);
            }

            var sourceBuildCommand = ImportModelCommand.Create(extension);

            if (sourceBuildCommand == null)
            {
                result.Error($"No importer found for model extension '{extension}. The model '{assetSource}' can't be imported.");
                return;
            }

            sourceBuildCommand.Mode                   = ImportModelCommand.ExportMode.Animation;
            sourceBuildCommand.SourcePath             = assetSource;
            sourceBuildCommand.Location               = targetUrlInStorage;
            sourceBuildCommand.AnimationRepeatMode    = asset.RepeatMode;
            sourceBuildCommand.AnimationRootMotion    = asset.RootMotion;
            sourceBuildCommand.ImportCustomAttributes = asset.ImportCustomAttributes;
            if (asset.ClipDuration.Enabled)
            {
                sourceBuildCommand.StartFrame = asset.ClipDuration.StartAnimationTime;
                sourceBuildCommand.EndFrame   = asset.ClipDuration.EndAnimationTime;
            }
            else
            {
                sourceBuildCommand.StartFrame = TimeSpan.Zero;
                sourceBuildCommand.EndFrame   = AnimationAsset.LongestTimeSpan;
            }
            sourceBuildCommand.ScaleImport   = asset.ScaleImport;
            sourceBuildCommand.PivotPosition = asset.PivotPosition;

            if (skeleton != null)
            {
                sourceBuildCommand.SkeletonUrl = skeleton.Location;
                // Note: skeleton override values
                sourceBuildCommand.ScaleImport   = ((SkeletonAsset)skeleton.Asset).ScaleImport;
                sourceBuildCommand.PivotPosition = ((SkeletonAsset)skeleton.Asset).PivotPosition;
            }

            if (asset.Type.Type == AnimationAssetTypeEnum.AnimationClip)
            {
                // Import the main animation
                buildStep.Add(sourceBuildCommand);
            }
            else if (asset.Type.Type == AnimationAssetTypeEnum.DifferenceClip)
            {
                var diffAnimationAsset = ((DifferenceAnimationAssetType)asset.Type);
                var referenceClip      = diffAnimationAsset.BaseSource;
                var rebaseMode         = diffAnimationAsset.Mode;

                var baseUrlInStorage   = targetUrlInStorage + RefClipSuffix;
                var sourceUrlInStorage = targetUrlInStorage + SrcClipSuffix;

                var baseAssetSource = UPath.Combine(assetDirectory, referenceClip);
                var baseExtension   = baseAssetSource.GetFileExtension();

                sourceBuildCommand.Location = sourceUrlInStorage;

                var baseBuildCommand = ImportModelCommand.Create(extension);
                if (baseBuildCommand == null)
                {
                    result.Error($"No importer found for model extension '{baseExtension}. The model '{baseAssetSource}' can't be imported.");
                    return;
                }

                baseBuildCommand.FailOnEmptyAnimation = false;
                baseBuildCommand.Mode                = ImportModelCommand.ExportMode.Animation;
                baseBuildCommand.SourcePath          = baseAssetSource;
                baseBuildCommand.Location            = baseUrlInStorage;
                baseBuildCommand.AnimationRepeatMode = asset.RepeatMode;
                baseBuildCommand.AnimationRootMotion = asset.RootMotion;

                if (diffAnimationAsset.ClipDuration.Enabled)
                {
                    baseBuildCommand.StartFrame = diffAnimationAsset.ClipDuration.StartAnimationTimeBox;
                    baseBuildCommand.EndFrame   = diffAnimationAsset.ClipDuration.EndAnimationTimeBox;
                }
                else
                {
                    baseBuildCommand.StartFrame = TimeSpan.Zero;
                    baseBuildCommand.EndFrame   = AnimationAsset.LongestTimeSpan;
                }

                baseBuildCommand.ScaleImport   = asset.ScaleImport;
                baseBuildCommand.PivotPosition = asset.PivotPosition;

                if (skeleton != null)
                {
                    baseBuildCommand.SkeletonUrl = skeleton.Location;
                    // Note: skeleton override values
                    baseBuildCommand.ScaleImport   = ((SkeletonAsset)skeleton.Asset).ScaleImport;
                    baseBuildCommand.PivotPosition = ((SkeletonAsset)skeleton.Asset).PivotPosition;
                }

                // Import base and main animation
                var sourceStep = new CommandBuildStep(sourceBuildCommand);
                buildStep.Add(sourceStep);
                var baseStep = new CommandBuildStep(baseBuildCommand);
                buildStep.Add(baseStep);

                IEnumerable <ObjectUrl> InputFilesGetter()
                {
                    yield return(new ObjectUrl(UrlType.File, GetAbsolutePath(assetItem, diffAnimationAsset.BaseSource)));
                }

                var diffCommand = new AdditiveAnimationCommand(targetUrlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, rebaseMode), assetItem.Package)
                {
                    InputFilesGetter = InputFilesGetter
                };

                var diffStep = new CommandBuildStep(diffCommand);

                BuildStep.LinkBuildSteps(sourceStep, diffStep);
                BuildStep.LinkBuildSteps(baseStep, diffStep);

                // Generate the diff of those two animations
                buildStep.Add(diffStep);
            }
            else
            {
                throw new NotImplementedException("This type of animation asset is not supported yet!");
            }

            result.BuildSteps = buildStep;
        }