コード例 #1
0
def add_elset_from_bmeshes(structure, name, bmeshes=None, layer=None):
    """ Adds the Blender meshes' edges and faces as an element set.

    Parameters
    ----------
    structure : obj
        Structure object to update.
    name : str
        Name of the new element set.
    bmeshes : list
        Blender mesh objects to extract edges and faces.
    layer : int
        Layer to get bmeshes from if bmeshes are not given.

    Returns
    -------
    None

    Notes
    -----
    - Either bmeshes or layer should be given, not both.

    """

    if layer is not None:
        bmeshes = [
            object for object in get_objects(layer=layer)
            if object.type == 'MESH'
        ]

    elements = []

    for bmesh in bmeshes:

        blendermesh = BlenderMesh(bmesh)
        vertices = blendermesh.get_vertex_coordinates()
        edges = blendermesh.get_edge_vertex_indices()
        faces = blendermesh.get_face_vertex_indices()

        for u, v in edges:
            sp = structure.check_node_exists(vertices[u])
            ep = structure.check_node_exists(vertices[v])
            element = structure.check_element_exists([sp, ep])
            if element is not None:
                elements.append(element)

        for face in faces:
            nodes = [structure.check_node_exists(vertices[i]) for i in face]
            element = structure.check_element_exists(nodes)
            if element is not None:
                elements.append(element)

    structure.add_set(name=name, type='element', selection=elements)
コード例 #2
0
__author__ = ['Andrew Liew <*****@*****.**>']
__copyright__ = 'Copyright 2018, BLOCK Research Group - ETH Zurich'
__license__ = 'MIT License'
__email__ = '*****@*****.**'

clear_layer(layer=1)

# Structure

mdl = Structure(name='mesh_tris', path='/home/al/temp/')

# Discretise

blendermesh = BlenderMesh(get_objects(layer=0)[0])
pts = blendermesh.get_vertex_coordinates()
fcs = blendermesh.get_face_vertex_indices()

vertices, faces = functions.discretise_faces(vertices=pts,
                                             faces=fcs,
                                             target=0.1,
                                             min_angle=15,
                                             factor=1,
                                             iterations=50)
for pts, fc in zip(vertices, faces):
    bmesh = xdraw_mesh(name='face', vertices=pts, faces=fc, layer=1, wire=True)
    blender.add_nodes_elements_from_bmesh(mdl,
                                          bmesh=bmesh,
                                          mesh_type='ShellElement')

# Summary
コード例 #3
0
def add_nodes_elements_from_bmesh(structure,
                                  bmesh,
                                  line_type=None,
                                  mesh_type=None,
                                  acoustic=False,
                                  thermal=False):
    """ Adds the Blender mesh's nodes, edges and faces to the Structure object.

    Parameters
    ----------
    structure : obj
        Structure object to update.
    bmesh : obj
        Blender mesh object.
    line_type : str
        Element type for lines (bmesh edges).
    mesh_type : str
        Element type for meshes.
    acoustic : bool
        Acoustic properties on or off.
    thermal : bool
        Thermal properties on or off.

    Returns
    -------
    list
        Node keys that were added to the Structure.
    list
        Element keys that were added to the Structure.

    """

    blendermesh = BlenderMesh(bmesh)
    vertices = blendermesh.get_vertex_coordinates()
    edges = blendermesh.get_edge_vertex_indices()
    faces = blendermesh.get_face_vertex_indices()

    try:
        name = blendermesh.guid
        if name[-5:-3] == '}.':
            name = name[:-4]
    except:
        pass

    created_nodes = set()
    created_elements = set()

    for vertex in vertices:
        node = structure.add_node(vertex)
        created_nodes.add(node)

    if line_type and edges:

        try:
            dic = json.loads(name.replace("'", '"'))
            ex = dic.get('ex', None)
            ey = dic.get('ey', None)
        except:
            ex = None
            ey = None
        axes = {'ex': ex, 'ey': ey}

        for u, v in edges:
            sp_xyz = vertices[u]
            ep_xyz = vertices[v]
            sp = structure.check_node_exists(sp_xyz)
            ep = structure.check_node_exists(ep_xyz)
            ez = subtract_vectors(ep_xyz, sp_xyz)
            if ex and not ey:
                ey = cross_vectors(ex, ez)
            axes['ey'] = ey
            axes['ez'] = ez
            e = structure.add_element(nodes=[sp, ep],
                                      type=line_type,
                                      acoustic=acoustic,
                                      thermal=thermal,
                                      axes=axes)
            if e is not None:
                created_elements.add(e)

    if mesh_type:

        if mesh_type in [
                'HexahedronElement', 'TetrahedronElement', 'SolidElement',
                'PentahedronElement'
        ]:
            nodes = [structure.check_node_exists(i) for i in vertices]
            e = structure.add_element(nodes=nodes,
                                      type=mesh_type,
                                      acoustic=acoustic,
                                      thermal=thermal)
            if e is not None:
                created_elements.add(e)

        else:
            try:
                dic = json.loads(name.replace("'", '"'))
                ex = dic.get('ex', None)
                ey = dic.get('ey', None)
                if ex and ey:
                    ez = cross_vectors(ex, ey)
                else:
                    ez = None
            except:
                ex = None
                ey = None
                ez = None
            axes = {'ex': ex, 'ey': ey, 'ez': ez}

            for face in faces:
                nodes = [
                    structure.check_node_exists(vertices[i]) for i in face
                ]
                e = structure.add_element(nodes=nodes,
                                          type=mesh_type,
                                          acoustic=acoustic,
                                          thermal=thermal,
                                          axes=axes)
                if e is not None:
                    created_elements.add(e)

    return list(created_nodes), list(created_elements)
コード例 #4
0
def add_tets_from_bmesh(structure,
                        name,
                        bmesh,
                        draw_tets=False,
                        volume=None,
                        layer=19,
                        acoustic=False,
                        thermal=False):
    """ Adds tetrahedron elements from a Blender mesh to the Structure object.

    Parameters
    ----------
    structure : obj
        Structure object to update.
    name : str
        Name for the element set of tetrahedrons.
    bmesh : obj
        The Blender mesh representing the outer surface.
    draw_tets : bool
        Draw the generated tetrahedrons.
    volume : float
        Maximum volume for tets.
    layer : int
        Layer to draw tetrahedrons if draw_tets=True.
    acoustic : bool
        Acoustic properties on or off.
    thermal : bool
        Thermal properties on or off.

    Returns
    -------
    None

    """

    blendermesh = BlenderMesh(bmesh)
    vertices = blendermesh.get_vertex_coordinates()
    faces = blendermesh.get_face_vertex_indices()

    tets_points, tets_elements = tets_from_vertices_faces(vertices=vertices,
                                                          faces=faces,
                                                          volume=volume)

    for point in tets_points:
        structure.add_node(point)

    ekeys = []
    for element in tets_elements:
        nodes = [structure.check_node_exists(tets_points[i]) for i in element]
        ekey = structure.add_element(nodes=nodes,
                                     type='TetrahedronElement',
                                     acoustic=acoustic,
                                     thermal=thermal)
        ekeys.append(ekey)
    structure.add_set(name=name, type='element', selection=ekeys)

    if draw_tets:
        tet_faces = [[0, 1, 2], [1, 3, 2], [1, 3, 0], [0, 2, 3]]
        for i, points in enumerate(tets_elements):
            xyz = [tets_points[j] for j in points]
            xdraw_mesh(name=str(i), vertices=xyz, faces=tet_faces, layer=layer)