Export of .mpd to single 'stand-alone' .ldr file ?


Re: Export of .mpd to single 'stand-alone' .ldr file ?
#5
If you're willing to try to get the LDLoader portion of LDView to compile on your system, it could be fairly easily written:
  1. Use LDLoader to load the MPD file into an LDLMainModel object.
  2. Create a (recursive) function called flatten() that takes an already opened FILE*, an LDLModel* object, and a const float * matrix as its inputs.
  3. Pass the LDLMainModel object from step one, along with TCVector::getIdentityMatrix() into flatten(). (LDLMainModel is a subclass of LDLModel.)
  4. Inside flatten(), iterate through the first model->getActiveLineCount() file lines in the model using model->getFileLines() to get the array of lines.
  5. For each file line, check to see if it's a model line (type 1) (fileLine->getLineType() == LDLLineTypeModel)
  6. If it is a model line, create a local variable by typecasting from LDLFileLine* to LDLModelLine*.
  7. Call modelLine->getMatrix() to get the model line's matrix, then use TCVector::multMatrix(matrix, modelLineMatrix, newMatrix) to get the modified matrix (newMatrix is a local variable of type float[16]).
  8. Check to see if it's a part: modelLine->getModel()->isPart()
  9. If it's a part, write out a line to the output file as "1 modelLine->getColorNumber() newMatrix[0] newMatrix[1] newMatrix[2] newMatrix[4] newMatrix[5] newMatrix[6] newMatrix[8] newMatrix[9] newMatrix[10] modelLine->getModel()->getFilename()"
  10. If it's not a part, call flatten() with file, modelLine->getModel() and newMatrix.
  11. If the file line isn't a model line, ignore it.

The above could be improved. For example, you could support all line types, instead of just line type 1, but you'd have to very carefully avoid writing out the MPD-specific comments, and you'd have to have separate logic for each line type. Since I assume you want to just flatten an MPD that is made up of parts, the above algorithm should do the trick.

Note also that you don't have to use LDLoader from LDView to do this, but doing so would remove all the LDraw parsing requirements, since it would do all that. LDLoader is C++. If you're interested, send me an email that includes what OS (Windows, Mac, or Linux), and I'll try to get you up and running with LDLoader.
Reply
« Next Oldest | Next Newest »



Messages In This Thread
Re: Export of .mpd to single 'stand-alone' .ldr file ? - by Travis Cobbs - 2012-12-20, 3:04

Forum Jump:


Users browsing this thread: 1 Guest(s)