classdef unrealDatasmithExportOptions < matlabshared.roadrunner.FormatOptions
    %UNREALDATASMITHEXPORTOPTIONS  Options for exporting RoadRunner scene to UnrealDatasmith
    %   unrealDatasmithExportOptions(Name=Value) creates an export options
    %   configuration object for the UnrealDatasmith format with properties
    %   specified as one or more name-value arguments.
    %
    %   If a default property value is "auto", the RoadRunner application
    %   determines what value to use and sets the property to that value.
    %
    %   Properties:
    %
    %   SplitMeshes             Split meshes by their segmentation type,
    %                           specified as true or false. 
    %                           Default: "auto".
    %
    %   ResizeTextureDimensions Resize the dimensions of exported textures
    %                           by rounding them up to the next highest
    %                           power of two, specified as true or false.
    %                           Default: "auto".
    %
    %   ExportOnlyHighestLOD    Export only highest level of details,
    %                           specified as true or false.
    %                           Default: "auto".
    %
    %   TilesExportOptions      Options to split meshes per tile,
    %                           specified as a tilesExportOptions object.
    %                           Default: "auto".
    %
    %   Example
    %   -------
    %   % Create UnrealDatasmith export options that set ResizeTextureDimensions
    %   options = unrealDatasmithExportOptions(ResizeTextureDimensions=true);
    %
    %   See also roadrunner/exportScene, tilesExportOptions.

    %   Copyright 2021-2023 The MathWorks, Inc.

    properties
        SplitMeshes
        ResizeTextureDimensions
        ExportOnlyHighestLOD
        TilesExportOptions
    end
    
    methods
        function obj = unrealDatasmithExportOptions(varargin)
            %UNREALDATASMITHEXPORTOPTIONS Construct an instance of this class
            p = inputParser;
            p.addParameter('SplitMeshes', []);
            p.addParameter('ResizeTextureDimensions', []);
            p.addParameter('ExportOnlyHighestLOD', []);
            p.addParameter('TilesExportOptions', tilesExportOptions.empty);
            p.parse(varargin{:});
            results = p.Results;
            obj.SplitMeshes = results.SplitMeshes;
            obj.ResizeTextureDimensions = results.ResizeTextureDimensions;
            obj.ExportOnlyHighestLOD = results.ExportOnlyHighestLOD;
            obj.TilesExportOptions = results.TilesExportOptions;
        end

        function set.SplitMeshes(obj,value)
            if obj.IsAuto(value)
                obj.SplitMeshes = [];
            else
                mustBeScalarOrEmpty(value),mustBeNumericOrLogical(value);
                obj.SplitMeshes = logical(value);
            end
        end

        function value = get.SplitMeshes(obj)
            if isempty(obj.SplitMeshes)
                value = "auto";
            else
                value = obj.SplitMeshes;
            end
        end

        function set.ResizeTextureDimensions(obj,value)
            if obj.IsAuto(value)
                obj.ResizeTextureDimensions = [];
            else
                mustBeScalarOrEmpty(value),mustBeNumericOrLogical(value);
                obj.ResizeTextureDimensions = logical(value);
            end
        end

        function value = get.ResizeTextureDimensions(obj)
            if isempty(obj.ResizeTextureDimensions)
                value = "auto";
            else
                value = obj.ResizeTextureDimensions;
            end
        end

        function set.ExportOnlyHighestLOD(obj,value)
            if obj.IsAuto(value)
                obj.ExportOnlyHighestLOD = [];
            else
                mustBeScalarOrEmpty(value),mustBeNumericOrLogical(value);
                obj.ExportOnlyHighestLOD = logical(value);
            end
        end

        function value = get.ExportOnlyHighestLOD(obj)
            if isempty(obj.ExportOnlyHighestLOD)
                value = "auto";
            else
                value = obj.ExportOnlyHighestLOD;
            end
        end

        function set.TilesExportOptions(obj,value)
            if obj.IsAuto(value)
                obj.TilesExportOptions = tilesExportOptions.empty;
            else
                mustBeA(value,'tilesExportOptions');
                obj.TilesExportOptions = value;
            end
        end

        function value = get.TilesExportOptions(obj)
            if isempty(obj.TilesExportOptions)
                value = "auto";
            else
                value = obj.TilesExportOptions;
            end
        end

    end

    methods(Hidden)
        function s = getUnderlying(obj)
            % Get the underlying options representation.
            s = mathworks.roadrunner.UnrealDatasmithExportSettings;
            if ~isequal(obj.SplitMeshes,"auto")
                s.split_by_segmentation = matlabshared.roadrunner.Utilities.toBoolValue(obj.SplitMeshes);
            end
            if ~isequal(obj.ResizeTextureDimensions,"auto")
                s.power_of_two_textures = matlabshared.roadrunner.Utilities.toBoolValue(obj.ResizeTextureDimensions);
            end
            if ~isequal(obj.ExportOnlyHighestLOD,"auto")
                s.export_only_highest_lods = matlabshared.roadrunner.Utilities.toBoolValue(obj.ExportOnlyHighestLOD);
            end
            if ~isequal(obj.TilesExportOptions,"auto")
                s.export_to_tiles = obj.TilesExportOptions.getUnderlying();
            end
        end
    end
end

