예제 #1
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;
        }
예제 #2
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
            };
        }
예제 #3
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, AnimationAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourceExists(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.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.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;
        }