Parsing LDraw


RE: Parsing LDraw
#2
In due time you will likely get an answer from Niels Schmidt or Travis Cobbs, but here's my take:

The file format is modular, not recursive. Recursive would mean that the same file or callpath contained the same file twice. The file format implies branching and one may end up reading the same file hundreds of times if implemented naively. Is your target to minimize the number of times a file is read or the number of open file handles?

Before thinking about populating a data structure most efficiently, you need to define the data structure you will store the contents to. Here, I will assume you want to aggregate all quads, lines, and triangles into one big collection and kind of 'inline' all the type 1 objects. I also assume you have a single-threaded application.

In any case, I would create a temporary object structure that mimics the hierarchy of the files and file references so that each file has only one object, but possibly more than one reference path. This minimized the number of times you need to read one file. Such a data structure could also keep track of the reference path, i.e. the path from the root object to the current object. If the file being read contains a reference that is already in its callpath then you have detected an infinite loop.

Once you know the tree is loopless, you can read each file once and copy the lines, triangles, and quads into temporary arrays. Once the temporary structure has been fully populated, you can just collapse it to a single collection by applying the transforms as you mentioned. You may also wish to keep track of the winding, so keep a lookout for "BFC INVERTNEXT" and BFC CCW/CW/nocertify.
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Parsing LDraw - by Max Murtazin - 2025-08-20, 18:04
RE: Parsing LDraw - by Peter Blomberg - 2025-08-21, 14:35
RE: Parsing LDraw - by Travis Cobbs - Yesterday, 0:33

Forum Jump:


Users browsing this thread: 1 Guest(s)