| 
4 | 4 |     import generic as g  | 
5 | 5 | 
 
  | 
6 | 6 | 
 
  | 
7 |  | -class MFTest(g.unittest.TestCase):  | 
8 |  | -    def test_3MF(self):  | 
9 |  | -        # an assembly with instancing  | 
10 |  | -        s = g.get_mesh("counterXP.3MF")  | 
11 |  | - | 
12 |  | -        # should be 2 unique meshes  | 
13 |  | -        assert len(s.geometry) == 2  | 
14 |  | -        # should be 6 instances around the scene  | 
15 |  | -        assert len(s.graph.nodes_geometry) == 6  | 
16 |  | -        assert all(m.is_volume for m in s.geometry.values())  | 
17 |  | - | 
18 |  | -        # a single body 3MF assembly  | 
19 |  | -        s = g.get_mesh("featuretype.3MF")  | 
20 |  | -        # should be 2 unique meshes  | 
21 |  | -        assert len(s.geometry) == 1  | 
22 |  | -        # should be 6 instances around the scene  | 
23 |  | -        assert len(s.graph.nodes_geometry) == 1  | 
24 |  | - | 
25 |  | -    def test_units(self):  | 
26 |  | -        # test our unit conversion function  | 
27 |  | -        converter = g.trimesh.units.unit_conversion  | 
28 |  | -        # these are the units listed in the 3MF spec as valid  | 
29 |  | -        units = ["micron", "millimeter", "centimeter", "inch", "foot", "meter"]  | 
30 |  | -        # check conversion factor for all valid 3MF units  | 
31 |  | -        assert all(converter(u, "inches") > 1e-12 for u in units)  | 
32 |  | - | 
33 |  | -    def test_more_units(self):  | 
34 |  | -        # make sure that units survive down to the mesh  | 
35 |  | -        s = g.trimesh.load_scene(g.os.path.join(g.dir_models, "featuretype.3MF"))  | 
36 |  | -        m = next(iter(s.geometry.values()))  | 
37 |  | -        assert m.units is not None, m.metadata  | 
38 |  | - | 
39 |  | -    def test_kwargs(self):  | 
40 |  | -        # check if kwargs are properly passed to geometries  | 
41 |  | -        s = g.get_mesh("P_XPM_0331_01.3mf")  | 
42 |  | -        assert all(len(v.vertices) == 4 for v in s.geometry.values())  | 
43 |  | - | 
44 |  | -        s = g.get_mesh("P_XPM_0331_01.3mf", process=False)  | 
45 |  | -        assert all(len(v.vertices) == 5 for v in s.geometry.values())  | 
46 |  | - | 
47 |  | -    def test_names(self):  | 
48 |  | -        # check if two different objects with the same name are correctly  | 
49 |  | -        # processed  | 
50 |  | -        s = g.get_mesh("cube_and_sphere_same_name.3mf")  | 
51 |  | -        assert len(s.geometry) == 2  | 
52 |  | - | 
53 |  | -    def test_roundtrip(self):  | 
54 |  | -        if g.sys.version_info < (3, 6):  | 
55 |  | -            g.log.warning("relies on > Python 3.5")  | 
56 |  | -            return  | 
57 |  | - | 
58 |  | -        # test a scene round-tripped through the  | 
59 |  | -        # 3MF exporter and importer  | 
60 |  | -        s = g.get_mesh("cycloidal.3DXML")  | 
61 |  | -        assert len(s.geometry) == 13  | 
 | 7 | +def test_3MF():  | 
 | 8 | +    # an assembly with instancing  | 
 | 9 | +    s = g.get_mesh("counterXP.3MF")  | 
 | 10 | + | 
 | 11 | +    # should be 2 unique meshes  | 
 | 12 | +    assert len(s.geometry) == 2  | 
 | 13 | +    # should be 6 instances around the scene  | 
 | 14 | +    assert len(s.graph.nodes_geometry) == 6  | 
 | 15 | +    assert all(m.is_volume for m in s.geometry.values())  | 
 | 16 | + | 
 | 17 | +    # a single body 3MF assembly  | 
 | 18 | +    s = g.get_mesh("featuretype.3MF")  | 
 | 19 | +    # should be 2 unique meshes  | 
 | 20 | +    assert len(s.geometry) == 1  | 
 | 21 | +    # should be 6 instances around the scene  | 
 | 22 | +    assert len(s.graph.nodes_geometry) == 1  | 
 | 23 | + | 
 | 24 | + | 
 | 25 | +def test_units():  | 
 | 26 | +    # test our unit conversion function  | 
 | 27 | +    converter = g.trimesh.units.unit_conversion  | 
 | 28 | +    # these are the units listed in the 3MF spec as valid  | 
 | 29 | +    units = ["micron", "millimeter", "centimeter", "inch", "foot", "meter"]  | 
 | 30 | +    # check conversion factor for all valid 3MF units  | 
 | 31 | +    assert all(converter(u, "inches") > 1e-12 for u in units)  | 
 | 32 | + | 
 | 33 | + | 
 | 34 | +def test_more_units():  | 
 | 35 | +    # make sure that units survive down to the mesh  | 
 | 36 | +    s = g.trimesh.load_scene(g.os.path.join(g.dir_models, "featuretype.3MF"))  | 
 | 37 | +    m = next(iter(s.geometry.values()))  | 
 | 38 | +    assert m.units is not None, m.metadata  | 
 | 39 | + | 
 | 40 | + | 
 | 41 | +def test_kwargs():  | 
 | 42 | +    # check if kwargs are properly passed to geometries  | 
 | 43 | +    s = g.get_mesh("P_XPM_0331_01.3mf")  | 
 | 44 | +    assert all(len(v.vertices) == 4 for v in s.geometry.values())  | 
 | 45 | + | 
 | 46 | +    s = g.get_mesh("P_XPM_0331_01.3mf", process=False)  | 
 | 47 | +    assert all(len(v.vertices) == 5 for v in s.geometry.values())  | 
 | 48 | + | 
 | 49 | + | 
 | 50 | +def test_names():  | 
 | 51 | +    # check if two different objects with the same name are correctly  | 
 | 52 | +    # processed  | 
 | 53 | +    s = g.get_mesh("cube_and_sphere_same_name.3mf")  | 
 | 54 | +    assert len(s.geometry) == 2  | 
 | 55 | + | 
 | 56 | + | 
 | 57 | +def test_roundtrip():  | 
 | 58 | +    if g.sys.version_info < (3, 6):  | 
 | 59 | +        g.log.warning("relies on > Python 3.5")  | 
 | 60 | +        return  | 
 | 61 | + | 
 | 62 | +    # test a scene round-tripped through the  | 
 | 63 | +    # 3MF exporter and importer  | 
 | 64 | + | 
 | 65 | +    for name, count in [("cycloidal.3DXML", 13), ("pyramids.3mf", 6)]:  | 
 | 66 | +        s = g.get_mesh(name)  | 
 | 67 | +        assert len(s.geometry) == count  | 
62 | 68 | 
 
  | 
63 | 69 |         # export and reload  | 
64 | 70 |         r = g.trimesh.load(  | 
 | 
0 commit comments