Description
Ldraw has an MPD extension for embedding multiple files in the same file. The extension is documented here: https://www.ldraw.org/article/47.html.
While files using the MPD extension typically use the .mpd extension, it's also common to see .ldr files containing multiple embedded files. This seems to be the standard way to define submodels in a single ldraw file or embed custom parts.
The current parsing implementation assumes all subfile commands come from the resolver like DiskResolver
, which won't be the case for embedded files. This causes resolve errors. The spec doesn't make any requirements on how to handle embedded filenames "masking" the filenames of actual parts on disk. This could theoretically be handled by just parsing and adding all the embedded files to the source map before recursing into the subfiles themselves. This would ensure the embedded submodel
file gets loaded before we try and resolve the command 1 ... submodel
.
This may also require changes to the return type of the parse commands. Returning a single SourceFile
may not adequately capture that the file could have embedded files. This depends on whether a SourceFile
should represent the list of commands in a single ldraw file or the file "blocks" as represented in the MPD extension. It still makes sense for parse_raw
to return the SourceFile
. The recursive version parse
could return all commands in a single SourceFile
, return a collection of SourceFile
, or not return a SourceFile
at all.
I'm currently working on reworking the file loading to try and support this extension as described above. Let me know if you have any suggestions or concerns.