예제 #1
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_spheres(spheres, div=20):
    """ Draw a set of spheres.

    Parameters:
        spheres (dic): {'radius':, 'pos':, 'color':, 'name':, 'layer':}.
        div (int): Divisions for spheres.

    Returns:
        list: Created sphere objects.
    """
    bpy.ops.mesh.primitive_uv_sphere_add(ring_count=div, segments=div)
    object = bpy.context.object
    objects = []
    for sphere in spheres:
        copy = object.copy()
        copy.scale *= sphere.get('radius', 1)
        copy.location = Vector(sphere.get('pos', [0, 0, 0]))
        copy.name = sphere.get('name', 'sphere')
        copy.data = copy.data.copy()
        material = create_material(color=sphere.get('color', [1, 1, 1]))
        copy.data.materials.append(material)
        set_object_layer(object=copy, layer=sphere.get('layer', 0))
        objects.append(copy)
    delete_object(object=object)
    return _link_objects(objects)
예제 #2
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_texts(texts):
    """ Draw a set of text objects.

    Parameters:
        texts (list): {'radius':, 'pos':, 'color':, 'name':, 'text':, 'layer':}.

    Returns:
        list: Created text objects.
    """
    bpy.ops.object.text_add(view_align=True)
    object = bpy.context.object
    objects = []
    for text in texts:
        copy = object.copy()
        copy.scale *= text.get('radius', 1)
        copy.location = Vector(text.get('pos', [0, 0, 0]))
        copy.name = text.get('name', 'text')
        copy.data.body = text.get('text', 'text')
        copy.data = copy.data.copy()
        material = create_material(color=text.get('color', [1, 1, 1]))
        copy.data.materials.append(material)
        set_object_layer(object=copy, layer=text.get('layer', 0))
        objects.append(copy)
    delete_object(object=object)
    return _link_objects(objects)
예제 #3
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_mesh(name,
               vertices=[],
               edges=[],
               faces=[],
               layer=0,
               color=[1, 1, 1],
               alpha=1,
               wire=True):
    """ Draws a Blender mesh.

    Parameters:
        name (str): Blender mesh name.
        vertices (list): Vertices co-ordinates.
        edges (list): Edge vertex indices.
        faces (list): Face vertex indices.
        layer (int): Layer number.
        color (list): Material color.
        alpha (float): Alpha [0, 1].
        wire (bool): Show wires for faces.

    Returns:
        obj: Created Blender mesh object.
    """
    mesh = bpy.data.meshes.new(name)
    mesh.from_pydata(vertices, edges, faces)
    mesh.update(calc_edges=True)
    bmesh = bpy.data.objects.new(name, mesh)
    bpy.context.scene.objects.link(bmesh)
    bmesh.show_wire = wire
    material = create_material(color=color, alpha=alpha)
    bmesh.data.materials.append(material)
    set_object_layer(object=bmesh, layer=layer)
    bmesh.select = False
    return bmesh
예제 #4
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_lines(lines):
    """ Draw a set of lines.

    Parameters:
        lines (list): {'color':, 'start':, 'end':, 'name':, 'width':, 'layer': }.

    Returns:
        list: Created line objects.
    """
    objects = []
    for line in lines:
        curve = bpy.data.curves.new(line.get('name', 'line'), type='CURVE')
        curve.dimensions = '3D'
        object = bpy.data.objects.new(line.get('name', 'line'), curve)
        object.location = [0, 0, 0]
        line_ = curve.splines.new('NURBS')
        line_.points.add(2)
        line_.points[0].co = list(line.get('start')) + [1]
        line_.points[1].co = list(line.get('end')) + [1]
        line_.order_u = 1
        material = create_material(color=line.get('color', [1, 1, 1]))
        object.data.fill_mode = 'FULL'
        object.data.bevel_depth = line.get('width', 0.05)
        object.data.bevel_resolution = 0
        object.data.materials.append(material)
        set_object_layer(object=object, layer=line.get('layer', 0))
        objects.append(object)
    deselect_all_objects()
    return _link_objects(objects)
예제 #5
0
파일: drawing.py 프로젝트: tclim/compas
def draw_cuboid(Lx=1,
                Ly=1,
                Lz=1,
                pos=[0, 0, 0],
                layer=0,
                color=[1, 1, 1],
                wire=True):
    """ Draw a cuboid.

    Parameters:
        Lx (float): Length in x.
        Ly (float): Length in y.
        Lz (float): Length in z.
        pos (list): Centroid position [x, y, z].
        layer (int): Layer number.
        color (list): Material color.
        wire (bool): Show wires for faces.

    Returns:
        obj: Created cube object.
    """
    bpy.ops.mesh.primitive_cube_add(radius=1, location=pos)
    cube = bpy.context.object
    cube.dimensions = [Lx, Ly, Lz]
    cube.show_wire = wire
    material = create_material(color=color)
    cube.data.materials.append(material)
    set_object_layer(object=cube, layer=layer)
    cube.select = False
    return cube
예제 #6
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_pointcloud(points):
    """ Draw a set of points using Blender mesh vertices.

    Parameters:
        points (dic): {'pos':, 'name':, 'layer':}.

    Returns:
        list: Created point objects (bmeshes).
    """
    object = xdraw_mesh(name='pt', vertices=[[0, 0, 0]])
    objects = []
    for point in points:
        copy = object.copy()
        copy.location = Vector(point.get('pos', [0, 0, 0]))
        copy.name = point.get('name', 'point')
        copy.data = copy.data.copy()
        set_object_layer(object=copy, layer=point.get('layer', 0))
        objects.append(copy)
    delete_object(object=object)
    return _link_objects(objects)
예제 #7
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_points(points):
    """ Draw a set of points (empties).

    Parameters:
        points (list): {'radius':, 'pos':, 'name':, 'layer':}.

    Returns:
        list: Created empty objects.
    """
    bpy.ops.object.empty_add(type='SPHERE', radius=1, location=[0, 0, 0])
    object = bpy.context.object
    objects = []
    for point in points:
        copy = object.copy()
        copy.scale *= point.get('radius', 1)
        copy.location = Vector(point.get('pos', [0, 0, 0]))
        copy.name = point.get('name', 'point')
        set_object_layer(object=copy, layer=point.get('layer', 0))
        objects.append(copy)
    delete_object(object=object)
    return _link_objects(objects)
예제 #8
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_pipes(pipes, div=8):
    """ Draw a set of pipes.

    Parameters:
        pipes (list): {'radius':, 'start':, 'end':, 'color':, 'name':, 'layer':}.
        div (int): Divisions around cross-section.

    Returns:
        list: Created pipe objects.
    """
    bpy.ops.mesh.primitive_cylinder_add(radius=1,
                                        depth=1,
                                        vertices=div,
                                        location=[0, 0, 0])
    object = bpy.context.object
    objects = []
    for pipe in pipes:
        radius = pipe.get('radius', 1)
        start = pipe.get('start', [0, 0, 0])
        end = pipe.get('end', [0, 0, 1])
        L = distance_point_point(start, end)
        pos = centroid_points([start, end])
        copy = object.copy()
        copy.name = pipe.get('name', 'pipe')
        copy.rotation_euler[1] = acos((end[2] - start[2]) / L)
        copy.rotation_euler[2] = atan2(end[1] - start[1], end[0] - start[0])
        copy.location = Vector(pos)
        copy.data = copy.data.copy()
        copy.scale = ((radius, radius, L))
        copy.show_wire = True
        material = create_material(color=pipe.get('color', [1, 1, 1]))
        copy.data.materials.append(material)
        set_object_layer(object=copy, layer=pipe.get('layer', 0))
        objects.append(copy)
    delete_object(object=object)
    return _link_objects(objects)
예제 #9
0
파일: drawing.py 프로젝트: tclim/compas
def xdraw_cubes(cubes):
    """ Draw a set of cubes.

    Parameters:
        cubes (list): {'radius':, 'pos':, 'color':, 'name':, 'layer':}.

    Returns:
        list: Created cube objects.
    """
    bpy.ops.mesh.primitive_cube_add()
    object = bpy.context.object
    objects = []
    for cube in cubes:
        copy = object.copy()
        copy.scale *= cube.get('radius', 1)
        copy.location = Vector(cube.get('pos', [0, 0, 0]))
        material = create_material(color=cube.get('color', [1, 1, 1]))
        copy.data.materials.append(material)
        copy.name = cube.get('name', 'cube')
        copy.data = copy.data.copy()
        set_object_layer(object=copy, layer=cube.get('layer', 0))
        objects.append(copy)
    delete_object(object=object)
    return _link_objects(objects)