Lego io scripts, need help (dl @ 1st page 2004.04.18)


(Oyster) #1

Question 1: how to tell the similarity of 2 colors. Lego uses only a limited color set. I’ve to choose a similar color during write a dat file. I’ve tried
|FaceColor.R-LegoColor.R|+|FaceColor.G-LegoColor.G|+|FaceColor.B-LegoColor.B|
and
|FaceColor.R-LegoColor.R|^2+|FaceColor.G-LegoColor.G|^2+|FaceColor.B-LegoColor.B|^2
to get the lego color, which results in a min in the above formulas. But they often pick up a incorrect color.

Question 2: add face without adding dupliacted vetrex? I know a veterx list and a face list will work, but if there are many faces, the lists grow heavily. Can python script do ‘remove dup’?

Current state - very elementary :smiley:
write
mesh: done
color: wip
read
type 0, Comment or META Command: wip
type 1, Part file reference: wip, the most complex parts
type 2, Line: done
type 3, Triangle: done
type 4, Quadrilateral: done
type 5, Optional Line: wip


(tuinbels) #2

Hi,

The current API does not have a remove duplicate call, but it is possible to do it with python.
I’ve done this with the Knife Tool to get rid of the duplicated vertices.

But it is better not to create doubles at all. I do not know what the files look like you want to import, but normally, they consist of a list with vertex coordinates and a list with faces (with the indices of the vertices they consist of). First you add all vertices, and after that, the faces can be added without creating duplicated vertices.
In the above link, there are 2 import scripts that do just that.

I hope this is useful for you,

Wim


(KDR_11k) #3

You could make a dictionary with the vertex coordinates (as tuples) as keys and pointers to the vertices themselves as the content. That way you can check back with the dictionary whether a vertex at the given position exists and if so it will give you the vertex so you can include it into the face, if not you can create the vertex and add it to the dictionary.


(Oyster) #4

Ok. you may dl it from
http://www.newsmth.net/att.php?p.284.8754.952.zip

pic
http://proxy.smth.org:8000/bbscon.php?ftype=0&bid=284&id=8754&ap=458486

and

http://proxy.smth.org:8000/bbscon.php?ftype=0&bid=284&id=8754&ap=420712

Usage:

  1. copy *.py and lego.cfg to the Blender script directory
  2. dl Complete LDraw.org Parts Library from
    http://www.ldraw.org/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=2
    and decompress it with directory using winzip
    The car.dat and pyramid.dat is coming with
    http://www.ldraw.org/modules.php?op=modload&name=Downloads&file=index&req=getit&lid=60
  3. edit lego.cfg according to your installation in step 2
  4. update your blender scripts menu. The script can be found under Export and Import

bugs

  1. choice of simular colors (still). btw:The color is taken from http://isodomos.com/VPH/ColorLego
  2. type 1 during reading data file
    http://proxy.smth.org:8000/bbscon.php?ftype=0&bid=284&id=8754&ap=340755

and

http://proxy.smth.org:8000/bbscon.php?ftype=0&bid=284&id=8754&ap=373843

notice the length of 2 lines
3. write to data
http://proxy.smth.org:8000/bbscon.php?ftype=0&bid=284&id=8754&ap=530612

and

http://proxy.smth.org:8000/bbscon.php?ftype=0&bid=284&id=8754&ap=567509

notice the locations of cube and sphere. don’t know the reason

to do

  1. assign color to face. a mesh can have 16 materials at most, what if a Lego part has more than 16 colors?
  2. type 0, 5 when read data file
  3. speed up. The re-index on vertices and faces needs a very big memeory, and costs too much time. Maybe skip it and let the user “remove doubles”. Well, I prefer to a python interface to “remove doubles” very much.
  4. GUI

(mifune) #5

a result of the script:
http://gallery.mudpuddle.co.nz/albums/album01/lego.jpg


(mifune) #6

could it be possible to make from each lego piece one mesh and then parent it to one mesh? im having trouble seperating the legopieces because sometimes they share the same vertices.
or is it possible to assign multiple matirials to one mesh?


(Oyster) #7

If the vertices at the same location doesn’t join together, there will be so many vertices for a mesh. Then more PC memory is need.

Furthermore, the “lego piece” conception is obscure, the real elements of a gizmo is lines and faces difined by vertices. If the same vertices for different parts is not merged, you can’t still get the wanted mesh, e.g. for a box piece, you will get exactly 4 rectangle faces and maybe 12 lines seperately.

And there is another reason: a “lego piece” file A may link another file B, and the mesh in B file is treated as a block. A joined mesh is easy for programming.

My script will not be updated till I kill the bugs I’ve mentioned.

P.S. I notice that every Blender mesh can have at most 16 materials, but a lego mesh can have more materials. I have no idea in this case.


(mifune) #8

what my biggest concern is that i want a nice colored mesh. a single mesh can be very handy for a programmer but the customer (me :wink: ) wants a nice sollution.

i see that mlcad has 16 standard colors. i can stick to them if i can get a nice collored lego model.

but i cant do your job (yet) so ill have to wait for you.

and as the puppet repair man says in toy story 2: “you cant rush art”.
i can wait.


(homer_simpson) #9

Hi,

i have programed an exporter in Java which reads LDraw files an convert them into another format (f.e. Wavefront .OBJ which could imported by blender very good)

Look at http://ldrawconverter.sourceforge.net/


(3Dre) #10

you can also open LDraw files in Leocad, and then export them to OBJ. I’ve got great results this way.