Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_visual(self):
mesh = g.get_mesh('featuretype.STL')
# stl shouldn't have any visual properties defined
assert not mesh.visual.defined
for facet in mesh.facets:
mesh.visual.face_colors[facet] = g.trimesh.visual.random_color()
assert mesh.visual.defined
assert not mesh.visual.transparency
mesh.visual.face_colors[0] = [10, 10, 10, 130]
assert mesh.visual.transparency
assert len(scene.geometry) == 1
m = next(iter(scene.geometry.values()))
check_fuze(m)
# the PLY should have textures defined
m = g.get_mesh('fuze.ply', process=False)
check_fuze(m)
# ASCII PLY should have textures defined
m = g.get_mesh('fuze_ascii.ply', process=False)
check_fuze(m)
# load without doing the vertex separation
# will look like garbage but represents original
# and skips "disconnect vertices with different UV"
b = g.get_mesh('fuze.ply',
process=False,
fix_texture=False)
assert len(b.vertices) == 502
assert len(b.visual.uv) == 502
def test_single_vn(self):
"""
Make sure files with a single VN load.
"""
m = g.get_mesh('singlevn.obj')
assert len(m.vertices) > 0
assert len(m.faces) > 0
def test_concatenate(self):
a = g.get_mesh('ballA.off')
b = g.get_mesh('ballB.off')
a.visual.face_colors = [255, 0, 0]
r = a + b
assert any(r.visual.face_colors.ptp(axis=0) > 1)
def test_subdivide(self):
meshes = [
g.get_mesh('soup.stl'), # a soup of random triangles
g.get_mesh('cycloidal.ply'), # a mesh with multiple bodies
g.get_mesh('featuretype.STL')] # a mesh with a single body
for m in meshes:
sub = m.subdivide()
assert g.np.allclose(m.area, sub.area)
assert len(sub.faces) > len(m.faces)
v, f = g.trimesh.remesh.subdivide(
vertices=m.vertices,
faces=m.faces)
max_edge = m.scale / 50
v, f = g.trimesh.remesh.subdivide_to_size(
vertices=m.vertices,
faces=m.faces,
max_edge=max_edge)
ms = g.trimesh.Trimesh(vertices=v, faces=f)
def test_gltf_pole(self):
scene = g.get_mesh('simple_pole.glb')
# should have multiple primitives
assert len(scene.geometry) == 11
export = scene.export(file_type='glb')
assert len(export) > 0
# check a roundtrip
reloaded = g.trimesh.load(
g.trimesh.util.wrap_as_stream(export),
file_type='glb')
# make basic assertions
g.scene_equal(scene, reloaded)
def test_vertex(self):
m = g.get_mesh('torus.STL')
m.visual.vertex_colors = [100, 100, 100, 255]
assert len(m.visual.vertex_colors) == len(m.vertices)
def test_dupe(self):
m = g.get_mesh('tube.obj')
assert m.body_count == 1
s = g.trimesh.scene.split_scene(m)
assert len(s.graph.nodes) == 2
assert len(s.graph.nodes_geometry) == 1
assert len(s.duplicate_nodes) == 1
assert len(s.duplicate_nodes[0]) == 1
c = s.copy()
assert len(c.graph.nodes) == 2
assert len(c.graph.nodes_geometry) == 1
assert len(c.duplicate_nodes) == 1
assert len(c.duplicate_nodes[0]) == 1
u = s.convert_units('in', guess=True)
def test_distance(self):
# Ensure that FCL is importable
try:
g.trimesh.collision.CollisionManager()
except ValueError:
g.log.warning('skipping collision tests, no FCL installed')
return
cube = g.get_mesh('unit_cube.STL')
tf1 = g.np.eye(4)
tf1[:3, 3] = g.np.array([5, 0, 0])
tf2 = g.np.eye(4)
tf2[:3, 3] = g.np.array([-5, 0, 0])
tf3 = g.np.eye(4)
tf3[:3, 3] = g.np.array([2, 0, 0])
tf4 = g.np.eye(4)
tf4[:3, 3] = g.np.array([-2, 0, 0])
# Test one-to-many distance checking
m = g.trimesh.collision.CollisionManager()
m.add_object('cube1', cube, tf1)
def test_concatenate(self):
a = g.get_mesh('ballA.off')
b = g.get_mesh('ballB.off')
a.visual.face_colors = [255, 0, 0]
r = a + b
assert any(r.visual.face_colors.ptp(axis=0) > 1)