test_mesh.py
Go to the documentation of this file.
1 import unittest
2 
3 import pyexotica as exo
4 
5 try:
6  import trimesh
7 except ImportError:
8  from nose.plugins.skip import SkipTest
9 
10  raise SkipTest("trimesh is not available, skipping related tests.")
11 
12 
13 def validate_mesh(mesh):
14  print(mesh, mesh.vertex_count, mesh.triangle_count)
15  assert mesh.vertex_count == 33
16  assert mesh.triangle_count == 62
17 
18 
19 class TestPythonMeshCreation(unittest.TestCase):
21  # Load mesh from resource path
22  print(">>> Loading STL directly from package-path")
23  mesh = exo.Mesh.createMeshFromResource(
24  "package://exotica_examples/resources/cone.stl"
25  )
26  validate_mesh(mesh)
27 
29  # Load STL mesh from Exotica resource path
30  print(">>> Loading STL from Exotica-resource-path")
31  mesh = exo.Mesh.createMeshFromResource("{exotica_examples}/resources/cone.stl")
32  validate_mesh(mesh)
33 
34  # Load OBJ from Exotica resource path
35  print(">>> Loading OBJ from Exotica-resource-path")
36  mesh = exo.Mesh.createMeshFromResource("{exotica_examples}/resources/cone.obj")
37  validate_mesh(mesh)
38 
40  # Load mesh from vertices and triangles
41  print(">>> Creating mesh from list of vertices")
42  # Note: exotica's load_obj is not compatible with all obj files, so don't use it.
43  m = trimesh.load(exo.Tools.parse_path("{exotica_examples}/resources/cone.obj"))
44  vertices = [m.vertices[i] for i in m.faces.flatten()]
45  mesh = exo.Mesh.createMeshFromVertices(vertices)
46  validate_mesh(mesh)
47 
49  # STL
50  print(">>> Creating mesh from list of vertices and list of triangles")
51  m = trimesh.load(exo.Tools.parse_path("{exotica_examples}/resources/cone.stl"))
52  mesh = exo.Mesh.createMeshFromVertices(m.vertices, m.faces.flatten())
53  validate_mesh(mesh)
54 
55 
56 if __name__ == "__main__":
57  unittest.main()
test_mesh.TestPythonMeshCreation
Definition: test_mesh.py:19
test_mesh.validate_mesh
def validate_mesh(mesh)
Definition: test_mesh.py:13
test_mesh.TestPythonMeshCreation.test_create_mesh_from_resource_package_path
def test_create_mesh_from_resource_package_path(self)
Definition: test_mesh.py:20
test_mesh.TestPythonMeshCreation.teset_create_mesh_from_vertices_and_triangles
def teset_create_mesh_from_vertices_and_triangles(self)
Definition: test_mesh.py:48
test_mesh.TestPythonMeshCreation.test_create_mesh_from_resource_exotica_resource_path
def test_create_mesh_from_resource_exotica_resource_path(self)
Definition: test_mesh.py:28
test_mesh.TestPythonMeshCreation.test_create_mesh_from_vertices
def test_create_mesh_from_vertices(self)
Definition: test_mesh.py:39


exotica_python
Author(s):
autogenerated on Fri Aug 2 2024 08:44:00