public ProcessException(ErrorCode errorCode, string message, int width, int height)
                : base(message)
            {
                this.errorCode = errorCode;
                var errors = new List <string>();

                DelightingHelpers.GetErrorMessagesFrom(errorCode, errors, width, height);
                m_Errors = string.Join(", ", errors.ToArray());
            }
示例#2
0
            static void Execute(Command command)
            {
                if (string.IsNullOrEmpty(command.delightedTexturePath))
                {
                    throw new Exception("-output must be defined");
                }

                var service = Delighting.NewService();

                var input = new Input()
                            .SetSwitchYZ(command.switchYZ)
                            .SetForceLocalDelighting(command.forceLocalDelighting)
                            .SetSeparateDarkAreas(command.separateDarkAreas)
                            .SetRemoveHighlights(command.removeHighlights)
                            .SetRemoveDarkNoise(command.removeDarkNoise);

                if (!string.IsNullOrEmpty(command.inputFolderPath))
                {
                    var loadOp = service.LoadInputFolderAsync(command.inputFolderPath);
                    loadOp.Execute();
                    if (loadOp.error != null)
                    {
                        var width  = 0;
                        var height = 0;
                        if (loadOp.data != null && loadOp.data.baseTexture != null)
                        {
                            width  = loadOp.data.baseTexture.width;
                            height = loadOp.data.baseTexture.height;
                        }
                        var errors = new List <string>();
                        DelightingHelpers.GetErrorMessagesFrom(((ProcessException)loadOp.error).errorCode, errors, width, height);
                        for (int i = 0; i < errors.Count; i++)
                        {
                            UnityDebug.LogError(errors[i]);
                        }

                        return;
                    }

                    input
                    .SetBaseTexture(loadOp.data.baseTexture)
                    .SetNormalsTexture(loadOp.data.normalsTexture)
                    .SetBentNormalsTexture(loadOp.data.bentNormalsTexture)
                    .SetAmbientOcclusionTexture(loadOp.data.ambientOcclusionTexture)
                    .SetPositionTexture(loadOp.data.positionTexture)
                    .SetMaskTexture(loadOp.data.maskTexture);

                    service.SetInput(loadOp.data);
                }
                else
                {
                    input
                    .SetBaseTexture(command.baseTexturePath)
                    .SetNormalsTexture(command.normalsTexturePath)
                    .SetBentNormalsTexture(command.bentNormalsTexturePath)
                    .SetAmbientOcclusionTexture(command.ambientOcclusionTexturePath)
                    .SetPositionTexture(command.positionTexturePath)
                    .SetMaskTexture(command.maskTexturePath);
                    service.SetInput(input);
                }

                var processOp = service.ProcessAsync(new ProcessArgs {
                    fromStep = ProcessStep.Gather, calculateResult = true
                });

                processOp.Execute();

                if (processOp.error != null)
                {
                    UnityDebug.LogException(processOp.error);
                    return;
                }

                var bytes = processOp.data.result.EncodeToPNG();

                File.WriteAllBytes(command.delightedTexturePath, bytes);
            }