예제 #1
0
            /// <inheritdoc/>
            public override Task <ResultStatus> Execute(IExecuteContext executeContext, BuilderContext builderContext)
            {
                var steps = new List <BuildStep>();

                var urlRoot = originalSourcePath.GetParent();

                var fileStream            = new FileStream(originalSourcePath.ToWindowsPath(), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                var recordedEffectCompile = new EffectLogStore(fileStream);

                recordedEffectCompile.LoadNewValues();

                foreach (var entry in recordedEffectCompile.GetValues())
                {
                    var effectCompileRequest = entry.Key;

                    var compilerParameters = new CompilerParameters();
                    effectCompileRequest.UsedParameters.CopyTo(compilerParameters);
                    compilerParameters.Platform = context.GetGraphicsPlatform();
                    compilerParameters.Profile  = context.GetGraphicsProfile();
                    steps.Add(new CommandBuildStep(new EffectCompileCommand(context, urlRoot, effectCompileRequest.EffectName, compilerParameters)));
                }

                Steps = steps;

                return(base.Execute(executeContext, builderContext));
            }
예제 #2
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourceExists(result, asset, assetAbsolutePath))
            {
                return;
            }

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

            var allow32BitIndex           = context.GetGraphicsProfile() >= GraphicsProfile.Level_9_2;
            var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES;
            var extension = asset.Source.GetFileExtension();

            if (ImportFbxCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new AssetBuildStep(AssetItem)
                {
                    new ImportFbxCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = asset.Materials,
                        ScaleImport    = asset.ScaleImport,
                    },
                };
            }
            else if (ImportAssimpCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new AssetBuildStep(AssetItem)
                {
                    new ImportAssimpCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = asset.Materials,
                        ScaleImport    = asset.ScaleImport,
                    },
                };
            }
            else
            {
                result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource);
            }
        }
예제 #3
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result)
        {
            if (asset.Source == null)
            {
                result.Error("Source cannot be null for Texture Asset [{0}]", asset);
                return;
            }

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

            result.BuildSteps = new ListBuildStep {
                new TextureConvertCommand(urlInStorage,
                                          new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), false))
            };
        }
예제 #4
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TextureAsset asset, AssetCompilerResult result)
        {
            if (!EnsureSourceExists(result, asset, assetAbsolutePath))
            {
                return;
            }

            // Get absolute path of asset source on disk
            var assetSource = GetAbsolutePath(assetAbsolutePath, asset.Source);

            var parameter = new TextureConvertParameters(assetSource, asset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality());

            result.BuildSteps = new AssetBuildStep(AssetItem)
            {
                new TextureConvertCommand(urlInStorage, parameter)
            };
        }
예제 #5
0
        protected Dictionary <TImageInfo, int> CompileGroup(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result)
        {
            result.BuildSteps = new AssetBuildStep(AssetItem);

            // Evaluate if we need to use a separate the alpha texture
            SeparateAlphaTexture = TextureCommandHelper.ShouldSeparateAlpha(asset.Alpha, asset.Format, context.Platform, context.GetGraphicsProfile());

            // create the registry containing the sprite assets texture index association
            var imageToTextureIndex = new Dictionary <TImageInfo, int>();

            // create and add import texture commands
            if (asset.Images != null)
            {
                // sort sprites by referenced texture.
                var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray();
                for (int i = 0; i < spriteByTextures.Length; i++)
                {
                    // skip the texture if the file is not valid.
                    var textureFile = spriteByTextures[i].Key;
                    if (!TextureFileIsValid(textureFile))
                    {
                        continue;
                    }

                    var spriteAssetArray = spriteByTextures[i].ToArray();
                    foreach (var spriteAsset in spriteAssetArray)
                    {
                        imageToTextureIndex[spriteAsset] = i;
                    }

                    // create an texture asset.
                    var textureAsset = new TextureAsset
                    {
                        Id               = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid)
                        Alpha            = asset.Alpha,
                        Format           = asset.Format,
                        GenerateMipmaps  = asset.GenerateMipmaps,
                        PremultiplyAlpha = asset.PremultiplyAlpha,
                        ColorKeyColor    = asset.ColorKeyColor,
                        ColorKeyEnabled  = asset.ColorKeyEnabled,
                    };

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

                    // add the texture build command.
                    result.BuildSteps.Add(
                        new TextureAssetCompiler.TextureConvertCommand(
                            ImageGroupAsset.BuildTextureUrl(urlInStorage, i),
                            new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture)));
                }

                result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported
            }
            return(imageToTextureIndex);
        }
예제 #6
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, ModelAsset asset, AssetCompilerResult result)
        {
            if (asset.Source == null)
            {
                result.Error("Source cannot be null for Texture Asset [{0}]", asset);
                return;
            }

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

            var allow32BitIndex           = context.GetGraphicsProfile() >= GraphicsProfile.Level_9_2;
            var allowUnsignedBlendIndices = context.GetGraphicsPlatform() != GraphicsPlatform.OpenGLES;
            var extension = asset.Source.GetFileExtension();

            // compute material and lighting configuration dictionaries here because some null reference can occur
            var materials = new Dictionary <string, Tuple <Guid, string> >();
            var lightings = new Dictionary <string, Tuple <Guid, string> >();

            foreach (var meshParam in asset.MeshParameters)
            {
                if (meshParam.Value.Material != null)
                {
                    materials.Add(meshParam.Key, new Tuple <Guid, string>(meshParam.Value.Material.Id, meshParam.Value.Material.Location));
                }

                // Transform AssetReference to Tuple<Guid,UFile> as AssetReference or ContentReference is not serializable (to generate the command hash)
                // TODO: temporary while the LightingParameters is a Member of MeshMaterialParameter class
                // TODO: should be passed directly in the Parameters of the mesh - no extra case is required
                if (meshParam.Value.LightingParameters != null)
                {
                    lightings.Add(meshParam.Key, new Tuple <Guid, string>(meshParam.Value.LightingParameters.Id, meshParam.Value.LightingParameters.Location));
                }
            }

            if (ImportFbxCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new ListBuildStep
                {
                    new ImportFbxCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = materials,
                        Lightings      = lightings,    // TODO: remove when lighting parameters will be behind a key
                        Parameters     = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters),
                        ViewDirectionForTransparentZSort = asset.ViewDirectionForTransparentZSort.HasValue ? asset.ViewDirectionForTransparentZSort.Value : -Vector3.UnitZ,
                    },
                    new WaitBuildStep(),
                };
            }
            else if (ImportAssimpCommand.IsSupportingExtensions(extension))
            {
                result.BuildSteps = new ListBuildStep
                {
                    new ImportAssimpCommand
                    {
                        SourcePath                = assetSource,
                        Location                  = urlInStorage,
                        Allow32BitIndex           = allow32BitIndex,
                        AllowUnsignedBlendIndices = allowUnsignedBlendIndices,
                        Compact        = asset.Compact,
                        PreservedNodes = asset.PreservedNodes,
                        Materials      = materials,
                        Lightings      = lightings,    // TODO: remove when lighting parameters will be behind a key
                        Parameters     = asset.MeshParameters.ToDictionary(pair => pair.Key, pair => pair.Value.Parameters),
                    },
                    new WaitBuildStep(),
                };
            }
            else
            {
                result.Error("No importer found for model extension '{0}. The model '{1}' can't be imported.", extension, assetSource);
            }
        }
예제 #7
0
        protected override void Compile(AssetCompilerContext context, string urlInStorage, UFile assetAbsolutePath, TGroupAsset asset, AssetCompilerResult result)
        {
            result.BuildSteps = new ListBuildStep();

            // Evaluate if we need to use a separate the alpha texture
            SeparateAlphaTexture = context.Platform == PlatformType.Android && asset.Alpha != AlphaFormat.None && asset.Format == TextureFormat.Compressed;

            // create the registry containing the sprite assets texture index association
            SpriteToTextureIndex = new Dictionary <TImageInfo, int>();

            // create and add import texture commands
            if (asset.Images != null)
            {
                // return compilation error if one or more of the sprite does not have a valid texture
                var noSourceAsset = asset.Images.FirstOrDefault(x => !TextureFileIsValid(x.Source));
                if (noSourceAsset != null)
                {
                    result.Error("The texture of image '{0}' either does not exist or is invalid", noSourceAsset.Name);
                    return;
                }

                // sort sprites by referenced texture.
                var spriteByTextures = asset.Images.GroupBy(x => x.Source).ToArray();
                for (int i = 0; i < spriteByTextures.Length; i++)
                {
                    var spriteAssetArray = spriteByTextures[i].ToArray();
                    foreach (var spriteAsset in spriteAssetArray)
                    {
                        SpriteToTextureIndex[spriteAsset] = i;
                    }

                    // create an texture asset.
                    var textureAsset = new TextureAsset
                    {
                        Id               = Guid.Empty, // CAUTION: It is important to use an empty GUID here, as we don't want the command to be rebuilt (by default, a new asset is creating a new guid)
                        Alpha            = asset.Alpha,
                        Format           = asset.Format,
                        GenerateMipmaps  = asset.GenerateMipmaps,
                        PremultiplyAlpha = asset.PremultiplyAlpha,
                        ColorKeyColor    = asset.ColorKeyColor,
                        ColorKeyEnabled  = asset.ColorKeyEnabled,
                    };

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

                    // add the texture build command.
                    result.BuildSteps.Add(
                        new TextureAssetCompiler.TextureConvertCommand(
                            ImageGroupAsset.BuildTextureUrl(urlInStorage, i),
                            new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.GetGraphicsPlatform(), context.GetGraphicsProfile(), context.GetTextureQuality(), SeparateAlphaTexture)));
                }

                result.BuildSteps.Add(new WaitBuildStep()); // wait the textures to be imported
            }
        }