Esempio n. 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;
        }
Esempio n. 2
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, SkeletonAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourcesExist(result, asset, assetAbsolutePath))
            {
                return;
            }

            var assetSource = GetAbsolutePath(assetAbsolutePath, 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 '{0}. The model '{1}' can't be imported.", extension, assetSource);
                return;
            }

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

            buildStep.Add(importModelCommand);

            result.BuildSteps = buildStep;
        }
Esempio n. 3
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           = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_9_2;
            var maxInputSlots             = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_10_1 ? 32 : 16;
            var allowUnsignedBlendIndices = context.GetGraphicsPlatform(assetItem.Package) != GraphicsPlatform.OpenGLES;
            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 == 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;

            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);
        }
Esempio n. 4
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourcesExist(result, asset, assetAbsolutePath))
            {
                return;
            }

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

            var gameSettingsAsset         = context.GetGameSettingsAsset();
            var renderingSettings         = gameSettingsAsset.Get <RenderingSettings>();
            var allow32BitIndex           = renderingSettings.DefaultGraphicsProfile >= GraphicsProfile.Level_9_2;
            var allowUnsignedBlendIndices = context.GetGraphicsPlatform(AssetItem.Package) != GraphicsPlatform.OpenGLES;
            var extension = asset.Source.GetFileExtension();

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

            if (asset.Skeleton != null)
            {
                skeleton = AssetItem.Package.FindAssetFromAttachedReference(asset.Skeleton);
            }

            var importModelCommand = ImportModelCommand.Create(extension);

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

            importModelCommand.Mode                      = ImportModelCommand.ExportMode.Model;
            importModelCommand.SourcePath                = assetSource;
            importModelCommand.Location                  = urlInStorage;
            importModelCommand.Allow32BitIndex           = allow32BitIndex;
            importModelCommand.AllowUnsignedBlendIndices = allowUnsignedBlendIndices;
            importModelCommand.Materials                 = asset.Materials;
            importModelCommand.ScaleImport               = asset.ScaleImport;
            importModelCommand.PivotPosition             = asset.PivotPosition;
            importModelCommand.SkeletonUrl               = skeleton?.Location;

            result.BuildSteps = new AssetBuildStep(AssetItem)
            {
                importModelCommand
            };
        }
Esempio n. 5
0
        protected override void Compile(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 sourceBuildStep = ImportModelCommand.Create(extension);

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

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

            if (asset.Type.Type == AnimationAssetTypeEnum.AnimationClip)
            {
                // Import the main animation
                buildStep.Add(sourceBuildStep);
            }
            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();

                sourceBuildStep.Location = sourceUrlInStorage;

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

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

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

                baseBuildStep.ScaleImport   = asset.ScaleImport;
                baseBuildStep.PivotPosition = asset.PivotPosition;
                baseBuildStep.SkeletonUrl   = skeleton?.Location;

                // Import base and main animation
                buildStep.Add(sourceBuildStep);
                buildStep.Add(baseBuildStep);

                // Wait for both import fbx commands to be completed
                buildStep.Add(new WaitBuildStep());

                // Generate the diff of those two animations
                buildStep.Add(new AdditiveAnimationCommand(targetUrlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, rebaseMode)));
            }
            else
            {
                throw new NotImplementedException("This type of animation asset is not supported yet!");
            }


            result.BuildSteps = buildStep;
        }
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, AnimationAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourcesExist(result, asset, assetAbsolutePath))
            {
                return;
            }

            // Get absolute path of asset source on disk
            var assetDirectory = assetAbsolutePath.GetParent();
            var assetSource    = GetAbsolutePath(assetAbsolutePath, 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.FindAssetFromAttachedReference(asset.Skeleton);
            }

            var sourceBuildStep = ImportModelCommand.Create(extension);

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

            sourceBuildStep.Mode                = ImportModelCommand.ExportMode.Animation;
            sourceBuildStep.SourcePath          = assetSource;
            sourceBuildStep.Location            = urlInStorage;
            sourceBuildStep.AnimationRepeatMode = asset.RepeatMode;
            sourceBuildStep.AnimationRootMotion = asset.RootMotion;
            sourceBuildStep.ScaleImport         = asset.ScaleImport;
            sourceBuildStep.PivotPosition       = asset.PivotPosition;
            sourceBuildStep.SkeletonUrl         = skeleton?.Location;

            var additiveAnimationAsset = asset as AdditiveAnimationAsset;

            if (additiveAnimationAsset != null)
            {
                var baseUrlInStorage   = urlInStorage + "_animation_base";
                var sourceUrlInStorage = urlInStorage + "_animation_source";

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

                sourceBuildStep.Location = sourceUrlInStorage;

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

                baseBuildStep.Mode                = ImportModelCommand.ExportMode.Animation;
                baseBuildStep.SourcePath          = baseAssetSource;
                baseBuildStep.Location            = baseUrlInStorage;
                baseBuildStep.AnimationRepeatMode = asset.RepeatMode;
                baseBuildStep.AnimationRootMotion = asset.RootMotion;
                baseBuildStep.ScaleImport         = asset.ScaleImport;
                baseBuildStep.PivotPosition       = asset.PivotPosition;
                baseBuildStep.SkeletonUrl         = skeleton?.Location;

                // Import base and main animation
                buildStep.Add(sourceBuildStep);
                buildStep.Add(baseBuildStep);

                // Wait for both import fbx commands to be completed
                buildStep.Add(new WaitBuildStep());

                // Generate the diff of those two animations
                buildStep.Add(new AdditiveAnimationCommand(urlInStorage, new AdditiveAnimationParameters(baseUrlInStorage, sourceUrlInStorage, additiveAnimationAsset.Mode)));
            }
            else
            {
                // Import the main animation
                buildStep.Add(sourceBuildStep);
            }

            result.BuildSteps = buildStep;
        }