Beispiel #1
0
def draw_it(ldr, OCC):
    parts_path = "/home/kanzure/local/ldraw/ldraw/even_more/LDRAW/parts.lst"
    ldraw_path = ldr  #might not be a path though (in this case, it's definitely *not* a path)

    parts = Parts(parts_path, filename=False
                  )  #might not be a path though (ok, it handles this case now)

    try:
        model = Part(ldraw_path, filename=False)
    except PartError:
        sys.stderr.write("Failed to read LDraw file: %s\n" % ldraw_path)
        sys.exit(1)

    #pov_file.write('#include "colors.inc"\n\n')
    writer = OCC_Writer(parts, OCC)
    writer.write(model)
    main_shape = OCC.TopoDS.TopoDS_Shape()
    for shape in writer.all_shapes:

        main_shape = OCC.BRepAlgoAPI.BRepAlgoAPI_Fuse(copy.copy(main_shape),
                                                      shape)
        main_shape = copy.copy(main_shape).Shape()
        #self.OCC.Display.wxSamplesGui.display.DisplayShape(face.Shape())
    while main_shape.IsDone() == 0:
        print "blah2"
    OCC.Display.wxSamplesGui.display.DisplayShape(main_shape.Shape())
Beispiel #2
0
def generate(parts_lst, output_dir, force=False):
    """ main function for the library generation """
    library_path = os.path.join(output_dir, 'library')
    ensure_exists(library_path)
    hash_path = os.path.join(library_path, '__hash__')

    md5_parts_lst = hashlib.md5(open(parts_lst, 'rb').read()).hexdigest()

    if os.path.exists(hash_path):
        md5 = open(hash_path, 'r').read()
        if md5 == md5_parts_lst and not force:
            return

    parts = Parts(parts_lst)

    library__init__ = os.path.join(library_path, '__init__.py')

    with open(library__init__, 'w') as library__init__:
        library__init__.write(LIBRARY_INIT)
    #shutil.copy('ldraw-license.txt', os.path.join(library_path, 'license.txt'))

    gen_colours(parts, output_dir)
    gen_parts(parts, output_dir)

    open(hash_path, 'w').write(md5_parts_lst)
Beispiel #3
0
def get_model(ldraw_path):
    """" get model from ldraw path """
    config = get_config()
    parts = Parts(config['parts.lst'])
    try:
        model = Part(ldraw_path)
    except PartError:
        sys.stderr.write("Failed to read LDraw file: %s\n" % ldraw_path)
        sys.exit(1)
    return model, parts
Beispiel #4
0
from ldraw.geometry import Vector
from ldraw.lines import MetaCommand
from ldraw.parts import Parts
from ldraw.config import get_config
from ldraw.pieces import Piece

from constants import *

config = get_config()

parts = Parts(config['parts.lst'])


class Connections:
    def __init__(self,
                 top=None,
                 bottom=None,
                 left=None,
                 right=None,
                 front=None,
                 back=None):
        self.top = top
        self.bottom = bottom
        self.left = left
        self.right = right
        self.front = front
        self.back = back


class BoudingBox(object):
    def __init__(self, min, max):
Beispiel #5
0
            match["image size"])
        sys.exit(1)
    try:
        image_size = map(int, image_dimensions)
    except ValueError:
        sys.stderr.write(
            "Non-integer value specified for the image size: %s\n" %
            match["image size"])
        sys.exit(1)

    camera_position = Vector(*map(float, match["camera position"].split(",")))
    look_at_position = Vector(
        *map(float,
             match.get("look-at position", "0.0,0.0,0.0").split(",")))

    parts = Parts(parts_path)

    try:
        model = Part(ldraw_path)
    except PartError:
        sys.stderr.write("Failed to read LDraw file: %s\n" % ldraw_path)
        sys.exit(1)

    if match.has_key("sky"):
        background_colour = match["background colour"]
    else:
        background_colour = "#000000"

    try:
        stroke_colour = match["stroke colour"]
    except KeyError:
Beispiel #6
0
#!/usr/bin/env python
from ldraw.parts import Parts

parts = Parts()
part = parts.part(code='93055')
print(part.category)
print(part.description)
part = parts.part(code='u9156c02')
print(part.category)
print(part.description)
Beispiel #7
0
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import sys
from ldraw.colours import *
from ldraw.figure import *
from ldraw.geometry import Identity, XAxis
from ldraw.parts import Parts
from ldraw.pieces import Group, Piece

if len(sys.argv) != 2:

    sys.stderr.write("Usage: %s <parts file>\n" % sys.argv[0])
    sys.exit(1)

parts = Parts(sys.argv[1])

group = Group(Vector(0, 0, -40), Identity())

figure = Person(group = group)
figure.head(Yellow, part = parts.Heads["Head with Monocle, Scar, and Moustache Pattern"])
figure.hat(Black, parts.Hats["Top Hat"])
figure.torso(Black, parts.Torsos["Torso with Black Suit, Red Shirt, Gold Clasps Pattern"])
figure.left_arm(Black, 70)
figure.left_hand(White, 0)
figure.right_arm(Black, -30)
figure.right_hand(White, 0)
figure.right_hand_item(ChromeSilver, Vector(0, -58, -20), 0, parts.parts["Minifig Tool Magnifying Glass"])
figure.hips(Black)
figure.left_leg(Black, 50)
figure.right_leg(Black, -40)
Beispiel #8
0
                p3 = current_matrix * obj.p3 + current_position
                p4 = current_matrix * obj.p4 + current_position
                if abs((p3-p1).cross(p2-p1)) != 0:
                    self._write_triangle(p1,p2,p3)
                if abs((p3-p1).cross(p4-p1)) != 0:
                    self._write_triangle(p3, p4, p1) 
        #the moment of truth
        visual.faces(pos=self.positions, normal=self.normals)
    def _write_triangle(self, v1, v2, v3):
        vec1 = numpy.matrix([v1.x-v2.x,v1.y-v2.y,v1.z-v2.z])
        vec2 = numpy.matrix([v2.x-v3.x,v2.y-v3.y,v2.z-v3.z])
        normal_vector = numpy.cross(vec1, vec2)
        self.positions.append((v1.x,v1.y,v1.z))
        self.positions.append((v2.x,v2.y,v2.z))
        self.positions.append((v3.x,v3.y,v3.z))
    
        self.normals.append((normal_vector.item(0), normal_vector.item(1), normal_vector.item(2)))
        self.normals.append((normal_vector.item(0), normal_vector.item(1), normal_vector.item(2)))
        self.normals.append((normal_vector.item(0), normal_vector.item(1), normal_vector.item(2)))

parts = Parts(parts_path, filename=True)
try:
    model = Part(ldraw_path, filename=True)
except PartError:
    sys.stderr.write("Failed to read LDraw file: %s\n" % ldraw_path)
    sys.exit(1)

writer = Visualizer(parts)
writer.write(model)

Beispiel #9
0
if __name__ == "__main__":

    syntax = "<LDraw parts file> <LDraw file> <Output inventory file>"
    syntax_obj = cmdsyntax.Syntax(syntax)
    matches = syntax_obj.get_args(sys.argv[1:])

    if len(matches) != 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], syntax))
        sys.exit(1)

    match = matches[0]
    parts_path = match["LDraw parts file"]
    ldraw_path = match["LDraw file"]
    inventory_path = match["Output inventory file"]

    parts = Parts(parts_path)

    try:
        model = Part(ldraw_path)
    except PartError:
        sys.stderr.write("Failed to read LDraw file: %s\n" % ldraw_path)
        sys.exit(1)

    inventory = {}
    length = 0

    for obj in model.objects:

        if obj.part == "LIGHT":
            continue