Example #1
0
def network_from_bmesh(bmesh):
    """ Create a Network datastructure from a Blender mesh.

    Parameters:
        bmesh (obj): Blender mesh object.

    Returns:
        obj: Network object.
    """
    blendermesh = BlenderMesh(bmesh)
    vertices = blendermesh.get_vertex_coordinates()
    edges = blendermesh.get_edge_vertex_indices()
    network = Network.from_vertices_and_edges(vertices=vertices, edges=edges)
    return network
from compas.datastructures import Network
from compas.numerical import drx_numpy
from compas_plotters import NetworkPlotter

L = 2.5
n = 100
EI = 0.2

vertices = [[i, 1 - abs(i), 0] for i in list(linspace(-1, 1, n))]
for i in range(n):
    if vertices[i][1] < 0.5:
        vertices[i][0] = sign(vertices[i][0]) * vertices[i][1]
edges = [[i, i + 1] for i in range(n - 1)]

structure = Network.from_vertices_and_edges(vertices=vertices, edges=edges)
structure.update_default_vertex_attributes({
    'is_fixed': False,
    'EIx': EI,
    'EIy': EI
})
structure.update_default_edge_attributes({'E': 50, 'A': 1, 'l0': L / n})
structure.get_vertices_attributes(['B', 'is_fixed'], [[0, 0, 0], True],
                                  structure.leaves())
structure.attributes['beams'] = {'beam': {'nodes': list(range(n))}}

lines = []
for u, v in structure.edges():
    lines.append({
        'start': structure.vertex_coordinates(u, 'xy'),
        'end': structure.vertex_coordinates(v, 'xy'),
Example #3
0
tol = 0.01
du = 0.02
deg = pi / 180
dr = 15 * deg

# Target

curve = get_objects(layer=1)[0]
blendercurve = BlenderCurve(object=curve)
Xt = array(blendercurve.divide(number_of_segments=mi))

# Network

vertices = [list(Xi) for Xi in list(Xt[:mi:div, :])]
edges = [[i, i + 1] for i in range(m)]
network = Network.from_vertices_and_edges(vertices=vertices, edges=edges)
network.update_default_vertex_attributes({'EIx': E*I, 'EIy': E*I})
network.update_default_edge_attributes({'E': E, 'A': A, 'l0': ds})
network.set_vertices_attributes([0, 1, m - 1, m], {'B': [0, 0, 0]})
network.beams = {'beam': {'nodes': list(range(network.number_of_vertices()))}}

# Manual

#dofs = 0, 0, 45 * deg, 0.6, 0, 155 * deg
#Xs = update(dofs=dofs, network=network, tol=tol, plot=True, Xt=Xt, ds=ds)

# Optimise

generations = 30

xa, za = Xt[+0, [0, 2]]
Example #4
0
    gltf = GLTF(filepath_glb)

    default_scene_index = gltf.parser.default_scene_index or 0
    vertex_data = gltf.parser.scenes[default_scene_index].nodes

    vertices = {
        name: gltf_node.position
        for name, gltf_node in vertex_data.items()
    }
    edges = [
        (node.node_key, child)
        for node in gltf.parser.scenes[default_scene_index].nodes.values()
        for child in node.children
    ]

    scene_tree = Network.from_vertices_and_edges(vertices, edges)
    scene_tree.plot()

    transformed_meshes = []

    for vertex_name, gltf_node in vertex_data.items():
        if gltf_node.mesh_data is None:
            continue
        t = gltf_node.transform
        m = Mesh.from_vertices_and_faces(gltf_node.mesh_data.vertices,
                                         gltf_node.mesh_data.faces)
        transformed_mesh = mesh_transformed(m, t)
        transformed_meshes.append(transformed_mesh)

    viewer = MultiMeshViewer()
    viewer.meshes = transformed_meshes