Ejemplo n.º 1
0
def _parse_nodes(node, mesh_list):

    for child in node.children:

        if type(child) == Node:
            _parse_nodes(child, mesh_list)
        elif isinstance(child, Observer):
            return
        else:
            mesh_list.append((to_mesh(child), child.meta))
Ejemplo n.º 2
0
def parse_nodes(node, mesh_dict=None):
    """
    The method searches a Raysect scenegraph and creates a dictionary with primitive representations.
    :param node: A raysect.core.World or raysect.core.Node instance to be searched
    :param mesh_dict: A python dictionary to add primitive representations to
    
    :return A python dictionary with keys being raysect primitives and items being their representations.
    """

    if not isinstance(node, Node) and not isinstance(node, World):
        raise TypeError(
            "node has to be an instance of raysect.core.Node or raysect.core.World"
        )

    if mesh_dict is None:
        mesh_dict = {}

    for child in node.children:
        mesh_dict = parse_nodes(child, mesh_dict)

        if isinstance(child, Primitive) or isinstance(child, Observer):
            mesh_dict[child] = to_mesh(child)

    return mesh_dict
Ejemplo n.º 3
0
from raysect.primitive import Sphere, Mesh
from raysect_mayavi.primitives import to_mesh
from raysect_mayavi.primitives.triangle import triangle3d_intersects_triangle3d


# OPERATION = 'UNION'
# OPERATION = 'INTERSECTION'
OPERATION = 'DIFFERENCE'


world = World()
s1 = Sphere(0.5, transform=translate(-0.25, 0, 0), name='s1')
s2 = Sphere(0.5, transform=translate(0.25, 0, 0), name='s2')


s1_vertices, s1_triangles = to_mesh(s1)
n_s1_vertices = s1_vertices.shape[0]
n_s1_triangles = s1_triangles.shape[0]
s1_mesh = Mesh(vertices=s1_vertices, triangles=s1_triangles, smoothing=False)
print()
print('n_s1_triangles', n_s1_triangles)

s2_vertices, s2_triangles = to_mesh(s2)
n_s2_vertices = s2_vertices.shape[0]
n_s2_triangles = s2_triangles.shape[0]
s2_mesh = Mesh(vertices=s2_vertices, triangles=s2_triangles, smoothing=False)
print('n_s2_triangles', n_s2_triangles)


s1_intersects = np.zeros(n_s1_triangles)
s1s2_distance = np.empty(n_s1_triangles)