LDraw.org Discussion Forums
Export of .mpd to single 'stand-alone' .ldr file ? - Printable Version

+- LDraw.org Discussion Forums (https://forums.ldraw.org)
+-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html)
+--- Forum: LDraw Editors and Viewers (https://forums.ldraw.org/forum-11.html)
+--- Thread: Export of .mpd to single 'stand-alone' .ldr file ? (/thread-7398.html)

Pages: 1 2 3


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Rob - 2012-12-20

Excellent ! That's looking good as far as I can see.

Could you try the attached model (which I originally downloaded from this forums MOC section).

Is how your doing this something you could put into a command line utility ?

e.g. MAKELDR.EXE input.mpd output.ldr

Many thanks.

Rob


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Rob - 2012-12-20

OK hold the front page - I think I have cracked it !!!

Attached is my 'flattened' version of the file I attached in my previous post (only line type 1's included)

(When I looked at this a couple of months back I literally spent a week solid trying to get this to work - amazing what coming back afresh can do - and Travis's step by step method list was also the catalyst which got it working - so thanks Travis).

The code (for those who are interested in these things) is as follows (the Ldrawpart is my own class - not included here).

Function Flatten(ByVal cModelFile As String, ByVal oParentMatrix As Windows.Media.Media3D.Matrix3D)

Dim cModelData As String = IO.File.ReadAllText(cModelFile)
Dim aLines As Array = Split(RemoveTrailingLineFeeds(cModelData), vbCrLf)
Dim oPart As LDrawPart

For Each cLine In aLines
oPart = New LDrawPart(cLine, ExtractPath(cModelFile) & "\")
If oPart.LineType = 1 Then
If LCase(RightStr(oPart.DatFile, 4)) = ".ldr" Then
Flatten(ExtractPath(cModelFile) & "\" & oPart.DatFile, oPart.Matrix3d)
Else
Dim oNewMatrix As Matrix3D = Matrix3D.Multiply(oPart.Matrix3d, oParentMatrix)
cCombinedData = cCombinedData & oPart.LineType & " " & _
oPart.Colour & " " & _
oNewMatrix.OffsetX & " " & _
oNewMatrix.OffsetY & " " & _
oNewMatrix.OffsetZ & " " & _
oNewMatrix.M11 & " " & _
oNewMatrix.M21 & " " & _
oNewMatrix.M31 & " " & _
oNewMatrix.M12 & " " & _
oNewMatrix.M22 & " " & _
oNewMatrix.M32 & " " & _
oNewMatrix.M13 & " " & _
oNewMatrix.M23 & " " & _
oNewMatrix.M33 & " " & _
oPart.DatFile & vbCrLf
End If
Else
cCombinedData = cCombinedData & cLine & vbCrLf
End If
Next

IO.File.WriteAllText(ExtractPath(cModelFile) & "\flattened.ldr", cCombinedData)

End Function


(This function assumes all 'in-line' ldr files in the MPD file have already been extracted as seperate files (in the same folder/directory) as the 'base' file - that's easy to do).

This is SO much simpler that what I was trying before !

HOORAY ITS CHRISTMAS !


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Rob - 2012-12-21

Update:

All working well except with models which feature a custom rotation point(s) such as

0 ROTATION CENTER -30 -2 0 1 "Custom"
0 ROTATION CONFIG -2 0

I assume the -30 -2 0 is the X,Y,Z point to rotate around - applying to any following parts... but what is the 4th numeric element ?
Also - what is the significance of the ROTATION CONFIG numbers ?

(I have googled for this but can't find any reference).

Rob.


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Michael Heidemann - 2012-12-21

What do you expect should happen with that line?

If you want to have that rotation point also in your flatterend version with the same functionality than in the structured version before, then you also need to apply the changes to that values. IMHO

Edit:
MLCad produces for every model in an mpd content file these two lines. By inlining these models into the main model you will get lots of 0 ROTATION lines. I have not yet checked how MLCad will work with more than one entry and which (first or last) will be used then. So to have those rotation point working also in the flatterened file will be difficult in my eyes. At present my export routine simply ingnores these 0 ROTATION line during inlining process.

By the way:
I saw in your code that you rely on the extension of the file. We just had an discussion here that this is not a good idea.
Official parts are forced to carry the extension '.dat'. But that is all we surely know. So it might be that a file with the extension '.ldr' has mpd content and should be processed like that.


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Rob - 2012-12-21

Hi Michael,

Thanks for the reply.

I'm trying to achive an LDR file which has only type 1 lines ideally. Any custom rotations should be 'incorporated' into the flatten function so that the pieces are at their absolution position and any translation/rotation values in the ldraw line entry are related to 0,0,0 not to any other 'custom' rotation point.

Thanks for the note that the 'submodel' might be an MPD file also - I'll bear that in mind.

FYI - I need the LDR files in this 'standalone' format for an animation function which I use for creating 'build' animations of Lego models - it works fine with 'straight' LDR files but not with MPD files - so I'm trying to create a routine that will take any MPD file and 'flatten' it into a 'simple as possible' LDR file ready for processing by my animation function.

(The custom rotation is not a huge problem as not that many models I've seen feature it - at anything other than the default values - but for completeness I would like to deal with it correctly).

Rob (TCBUK)


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Michael Heidemann - 2012-12-21

Code:
FYI - I need the LDR files in this 'standalone' format for an animation function which I use for creating 'build' animations of Lego models - it works fine with 'straight' LDR files but not with MPD files - so I'm trying to create a routine that will take any MPD file and 'flatten' it into a 'simple as possible' LDR file ready for processing by my animation function.
Do you have already something to show :-)

The next version of MPDCenter will have this 'flatten' function. Currently I am working on referenced mpd content files.
I am not sure to make a command line tool as derivation. Before you do the flattening you should have all the files needed in the mpd, and that is sometimes not the case. At this point MPDCenter can help if you have the required part somewhere on your disk.


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Travis Cobbs - 2012-12-21

I don't think I understand. If you just want to output an LDR file with all type 1 lines, you should be able to completely ignore the rotation points, shouldn't you? They may be used by editors like MLCAD to aid in rotating the sub-models inside an MPD, but that just changes the way the MLCAD re-calculates the matrix that refers to the file. They are completely ignored by renderers.


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Rob - 2012-12-22

For some samples of my work to date (using non-mpd files so far - or ones that I've have got to work with out 'flattening') please visit...

www.thecreativebrick.co.uk


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Rob - 2012-12-22

I've attached the model which my flatten function fails to work correctly on.

Original model found here: http://lego.bldesign.org/models/?m=cormorant

(I think it's a really fab design BTW).

Travis - I don't think the MLCAD custom rotation lines should affect anything either, it may be something else which is causing the problem with this particular model.

Michael - could you try this with your flatten function and see if it works ?

There maybe something odd about this particular model file (apart from the custom rotation lines) which is throwing something.

Rob (TCBUK)


Re: Export of .mpd to single 'stand-alone' .ldr file ? - Michael Heidemann - 2012-12-22

No problem on this side. Works like expected.

I remember that I also had lots of days spend in finding all necessary code to do it right Smile