LDraw.org Discussion Forums

Full Version: LDD questions
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
1. Is it possible to extract patterns out of LDD files, and if yes, how?
2. Is there a program like LDView for LDD files (so if 1 is answered with no, I could look at the patterned parts, make screenshots and use these as templates).
As far as I know, patterns in LDD are textures. There's a pretty good chance they could be extracted, but I don't know how to do so.

The only program I know of to view LDD files is LDD itself.
Someone somewhere (probably Lugnet) once pointed out that they are/were a standard 3d modelling format compressed into a zip with a little extra information. It might be worth sniffing around the parts library file with a zip file viewer.

Tim (who does not have LDD to check)
How do I open the .lif file (since it is the largest file in the folder, I assume it's the library)?
Hey Daniel,

the .lif files are kind of a container format.

http://news.lugnet.com/cad/ldd/?n=139 Wrote:I'd actually compare it more directly to EA's IFF (Interchange File Format)
format, first created (mostly) for the Amiga personal computer. It has chunks
and chunk headers that are very similiar to IFF. (LIF = LEGO Interchange Format,
would be my guess at the meaning, as well).

I agree with this quote. LEGO used chunks like 0001 and 0002 (...).

There was a discussion (among others) on eurobicks about the legality of extracting and sharing the content of the .lif-files. I am not a jurist nor is my english that good, that I got the result of this discussions.

http://www.eurobricks.com/forum/index.ph...&p=1180814' Wrote:BTW, documenting the file formats is one thing. Appropriating Lego’s data contained within such file formats is quite another – that data (the .lif contents) certainly is subject to plain old copyright. You would require written permission to reproduce it. Converting it to another format is merely a ‘derived work’ and permission is still required.

Once, Philo described a way to take a 3d screenshots of a ldd model. In the resulting .3dxml files the decorations are available too. But they are in a strange format. I did not had a closer look on them, yet...


inside the .3dxml files the decorations seems to be stored as Base64 encoded .tga files. I found a phyton script (referenced from here), that was written to import .3dxml files into Blender. Since I do not have Blender installed I could not give it a try, but the script gave me a feeling for how the images needs to be handled.

Maybe this is interesting for someone else.

BTW, this could give us access to the textures of the computer games, too...

Hey again,

yes, it works. I played around with the phyton script and I was able to extract .tga files from the .3dxml files. I successfully extracted images from the LDD and from Lego Star Wars II.

It looks like the images are upside down, but I think that is just a small issue. There is one .lxf file available on eurobricks that contains all decorations. The script could extract them all at once.

import zipfile, base64, struct, os
import xml.etree.ElementTree as etree

def load_images(filename):
    if zipfile.is_zipfile(filename):
        zf = zipfile.ZipFile(filename, 'r')
        member = zf.namelist()[1]
        filename = zf.open(member)
        print 'Unzipping', member
    tree = etree.parse(filename)
    images = tree.find('.//{http://www.3ds.com/xsd/3DXML}ImageSet')
    numimages = len(images)
    print 'Number of images:', numimages
    #imgs = []
    for i in tree.findall('.//{http://www.3ds.com/xsd/3DXML}Pixel'):
        write_tga(i, numimages)

def write_tga(image, numimages):
    h = int(image.attrib['height'])
    w = int(image.attrib['width'])
    fmt = image.attrib['format']
    pixels = image[0].text
    size = len(`numimages`)
    imgidx = image.attrib['id']
    imgidx = str('Map-%0'+`size`+'d') % int(imgidx)
    filename = imgidx + '.tga'
    bits = 32 if 'A' in fmt else 24
    alpha = 8 if 'A' in fmt else 0
    dirname = 'textures'
    if not os.path.exists(dirname): os.mkdir(dirname)
    pathname = os.path.join(dirname, filename)
    if not os.path.exists(pathname):
        print 'writing %s (%dx%d) %s' % (pathname, w, h, fmt.lower())
        with open(pathname, 'wb') as file:
            file.write(struct.pack('12B', 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0))
            file.write(struct.pack('HH', w, h))
            file.write(struct.pack('BB', bits, alpha))
            pixels = base64.b64decode(pixels) #$base64.b64decode(bytes(pixels, 'utf-8'))
            pixels = rgb_to_bgr(pixels, fmt)

def rgb_to_bgr(pixels, fmt):
    pixels = list(pixels)
    npixels = len(pixels)
    step = 4 if 'A' in fmt else 3
    for i in range(0, npixels, step):
        pixels[i],pixels[i+2] = pixels[i+2],pixels[i]
    #$pixels = map(chr, pixels)
    pixels = ''.join(pixels)
    #$pixels = bytes(pixels, 'latin-1')
    return pixels

I am not well versed with python! What I did:
  • Put the code in a file (e.g. extractimages.py)
  • Saved the script in the folder where the .3dxml files are
  • Opened a phyton console
  • Imported os (import os)
  • Changed directory in the python console to the path where the .3dxml files are (os.chdir('<path>'))
  • Imported the new script (import extractimages)
  • Extracted images (extractimages.load_images('<file>.3dxml'))

You will get a folder named 'textures'. I hope it works.

No it doesn't.

I get a syntax error, when import the script:

Traceback (most recent call last):
File "<stdin">, line 1, in <module>
File "extractimages.py", line 9
print 'Unzipping', member
SyntaxError: invalid syntax

If I continue anyway:

Traceback (most recent call last):
File "<stdin">, line 1, in <module>
NameError: name 'extractimages' is not defined.

BTW: I downloaded the lxf file. I don't have a 3dxml file (whatever this is), so does it work anyway if I fix the syntax (no idea how)?

When I asked, I thought more of a program like isobuster... ;-)

[EDIT]. I finally got the script imported by deleting all the lines with "print" in it. But when I start the script I get another error message:

Traceback (most recent call last):
File "<stdin">, line 1, in <module>
File "extractimages.py", line 11, in load_images
numimages = len(images)
TypeError: object of type 'NoneType' has no len()

[EDIT2] After installing another program to convert lxf to 3dxml, I get another Error.
TypeError: expected bytes, not str.

I think I'll stay with simple screenshots and rebuild it in photoshop. This seems to go a lot faster.

I am sorry that it did not work. I used Phyton 2.7.2...

You can get the 3dxml file through the way Philo described here. I thought I mentioned that. Sorry.
  • Start 3DVIA Screenprint
  • Start LDD
  • Open the file with all decorated parts
  • press F10 - 3DVIA Screenprint will generate the 3dxml file (at least on my pc)

Now you can use the Phyton script to get all the decorations.

I would like to make them available to you. But currently I have no webspace to share them...
Could you send me an eMail (rolf_osterthunATgmxPOINTde)?

Travis Cobbs Wrote:As far as I know, patterns in LDD are textures. There's a pretty good chance they could be extracted, but I don't know how to do so.

The only program I know of to view LDD files is LDD itself.

saving the LDD bitmaps out to files was a driver for getting TEXMAP developed (none of them have been used since TEXMAP was made operational, though). Smile