Skip to content

Commit

Permalink
Implemented URL processing option in castle-model-convertor
Browse files Browse the repository at this point in the history
  • Loading branch information
janadamec1 committed Sep 20, 2024
1 parent 674e97b commit f7ce757
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions castle_model_converter.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ var
StdInUrl: String = 'stdin.x3dv';
StdOutUrl: String = 'stdout.x3dv';
OutputX3dEncoding: String = '';
OutputUrlProcessing: TUrlProcessing = suNone;

const
Options: array [0..9] of TOption =
Options: array [0..10] of TOption =
(
(Short: 'h'; Long: 'help'; Argument: oaNone),
(Short: 'v'; Long: 'version'; Argument: oaNone),
Expand All @@ -67,7 +68,8 @@ const
(Short: #0; Long: 'validate'; Argument: oaNone),
(Short: #0; Long: 'stdin-url'; Argument: oaRequired),
(Short: #0; Long: 'stdout-url'; Argument: oaRequired),
(Short: #0; Long: 'float-precision'; Argument: oaRequired)
(Short: #0; Long: 'float-precision'; Argument: oaRequired),
(Short: #0; Long: 'url-processing'; Argument: oaRequired)
);

procedure OptionProc(OptionNum: Integer; HasArgument: boolean;
Expand Down Expand Up @@ -99,6 +101,7 @@ begin
OptionDescription('--stdin-url', 'If input URL is "-", then we read file contents from the standard input. In this case, you can use this option to provide a "pretend" URL for the input. We will use it to resolve relative URLs inside the input (e.g. to glTF binary blobs) and to guess the input file type. Default is "stdin.x3dv" in current directory, so we assume it is X3D (classic encoded), and resolve with respect to the current directory.') +NL+
OptionDescription('--stdout-url', 'If output URL is "-", then we write file contents to the standard output. In this case, you can use this option to provide a "pretend" URL for the output. We will use it to determine the output file type, e.g. "out.x3d" to output X3D XML encoding or "out.x3dv" to output X3D classic encoding.') +NL+
OptionDescription('--float-precision DIGITS', 'Number of digits after the decimal point when writing floating-point numbers. Default is to write all possibly relevant digits. Specify any value >= 0 to use this number of digits.') +NL+
OptionDescription('--url-processing none|convert-to-relative|embed-resources|copy-resources-to-subdirectory', 'How URLs in scene are treated when saving. None (default) means no processing, convert-to-relative changes URLs to relative paths, embed-resources stores the resouraces directly into output file if possible for the format, copy-resources-to-subdirectory copies resources next to output file and changes URLs to relative paths.') + NL +
OptionDescription('--encoding classic|xml', 'DEPRECATED. Choose X3D encoding. Do not use -- the 2nd parameter should determine the output type, ".x3d" extension says to make X3D XML, ".x3dv" says to make X3D classic. Or use --stdout-url to provide fake URL in case output is to stdout.') + NL +
NL+
ApplicationProperties.Description);
Expand Down Expand Up @@ -127,6 +130,15 @@ begin
else
FloatOutputFormat := '%.' + IntToStr(FloatPrecision) + 'f';
end;
10:begin
case Argument of
'none': OutputUrlProcessing := suNone;
'convert-to-relative': OutputUrlProcessing := suChangeCastleDataToRelative;
'embed-resources': OutputUrlProcessing := suEmbedResources;
'copy-resources-to-subdirectory': OutputUrlProcessing := suCopyResourcesToSubdirectory;
else Writeln(ErrOutput, 'Unknown argument value for url-processing');
end;
end;
else raise EInternalError.Create('OptionProc');
end;
end;
Expand Down Expand Up @@ -164,11 +176,9 @@ var
Node: TX3DRootNode;
EventsHandler: TEventsHandler;
OutputStream: TStream;
UrlProcessing: TUrlProcessing;
begin
ApplicationProperties.ApplicationName := 'castle-model-converter';
ApplicationProperties.Version := Version;
UrlProcessing := suNone; // TODO: get the value from parameters

{ parse command-line, calculating InputUrl and OutputUrl }
Parameters.Parse(Options, @OptionProc, nil);
Expand Down Expand Up @@ -228,8 +238,8 @@ begin
else
OutputStream := StdOutStream;

if UrlProcessing <> suNone then
ProcessUrls(Node, OutputUrl, UrlProcessing);
if OutputUrlProcessing <> suNone then
ProcessUrls(Node, OutputUrl, OutputUrlProcessing);

SaveNode(Node, OutputStream, OutputMimeType,
{ generator (metadata) } 'castle-model-converter, https://castle-engine.io/castle-model-converter',
Expand Down

0 comments on commit f7ce757

Please sign in to comment.