LDraw.org Discussion Forums
How to determine whether a file is a part or a subpart - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw File Processing and Conversion (https://forums.ldraw.org/forum-22.html)
+--- Thread: How to determine whether a file is a part or a subpart (/thread-16769.html)



How to determine whether a file is a part or a subpart - Nathan Friend - 2015-06-28

Is there a way to definitively know whether a particular .ldr or .dat file is a full part as opposed to a subpart or primitive? I'm writing an online LDraw visualizer using three.js, and one feature I'd like to add is an animation of the model "blowing up" - all of the pieces coming apart and falling to the floor. In order to do this, I'll need to know which definitions are linked and which aren't (i.e., I don't want the studs coming off the bricks).

My first thought is to assume that all subfile references in the root .ldr file are their own parts. However, I'm not sure if this is a reasonable assumption to make (this would do strange things if one was viewing a part directly, like a 2x4 brick (3001.dat) ).

Being able to identify individual parts will also help with seam width calculations.


Re: How to determine whether a file is a part or a subpart - Michael Heidemann - 2015-06-28

As far as I know the best is to look for an official header, where you can read if it is a subpart or a primitive.
There are some more ideas where you can look for, but this one is the most efficient I think.


Re: How to determine whether a file is a part or a subpart - Travis Cobbs - 2015-06-29

Official parts will have a 0 !LDRAW_ORG Part meta-statement. To the best of my knowledge all official parts will contain this meta-statement, and furthermore, all official files that contain this statement will be parts (not sub-parts or primitives). Having said that, many official parts are simply references to another file, which is also a part. In the context of a model that uses the first file, that instance of the second file isn't a part; it's a sub-part. So you have to have a run-time rule that state that in order to be a part, none of the file's ancestors can be a part. Or, probably easier, once you find a part, you know all its children aren't parts.

Unofficial parts are harder to recognize. LDView looks for quite a few different things when deciding if something is an unofficial part. I don't remember all of them off the top of my head, but it definitely looks for common meta-statements, as well as paying attention to the directory the file came from. I believe that it is set up so that if a file is loaded from a parts directory, it is considered to be a part if none of its ancestors was a part.