README.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. PyAssimp: Python bindings for libassimp
  2. =======================================
  3. A simple Python wrapper for Assimp using ``ctypes`` to access the
  4. library. Requires Python >= 2.6.
  5. Python 3 support is mostly here, but not well tested.
  6. Note that pyassimp is not complete. Many ASSIMP features are missing.
  7. USAGE
  8. -----
  9. Complete example: 3D viewer
  10. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11. ``pyassimp`` comes with a simple 3D viewer that shows how to load and
  12. display a 3D model using a shader-based OpenGL pipeline.
  13. .. figure:: 3d_viewer_screenshot.png
  14. :alt: Screenshot
  15. Screenshot
  16. To use it, from within ``/port/PyAssimp``:
  17. ::
  18. $ cd scripts
  19. $ python ./3D-viewer <path to your model>
  20. You can use this code as starting point in your applications.
  21. Writing your own code
  22. ~~~~~~~~~~~~~~~~~~~~~
  23. To get started with ``pyassimp``, examine the simpler ``sample.py``
  24. script in ``scripts/``, which illustrates the basic usage. All Assimp
  25. data structures are wrapped using ``ctypes``. All the data+length fields
  26. in Assimp's data structures (such as ``aiMesh::mNumVertices``,
  27. ``aiMesh::mVertices``) are replaced by simple python lists, so you can
  28. call ``len()`` on them to get their respective size and access members
  29. using ``[]``.
  30. For example, to load a file named ``hello.3ds`` and print the first
  31. vertex of the first mesh, you would do (proper error handling
  32. substituted by assertions ...):
  33. .. code:: python
  34. from pyassimp import load
  35. with load('hello.3ds') as scene:
  36. assert len(scene.meshes)
  37. mesh = scene.meshes[0]
  38. assert len(mesh.vertices)
  39. print(mesh.vertices[0])
  40. Another example to list the 'top nodes' in a scene:
  41. .. code:: python
  42. from pyassimp import load
  43. with load('hello.3ds') as scene:
  44. for c in scene.rootnode.children:
  45. print(str(c))
  46. INSTALL
  47. -------
  48. Install ``pyassimp`` by running:
  49. ::
  50. $ python setup.py install
  51. PyAssimp requires a assimp dynamic library (``DLL`` on windows, ``.so``
  52. on linux, ``.dylib`` on macOS) in order to work. The default search
  53. directories are:
  54. - the current directory
  55. - on linux additionally: ``/usr/lib``, ``/usr/local/lib``,
  56. ``/usr/lib/x86_64-linux-gnu``
  57. To build that library, refer to the Assimp master ``INSTALL``
  58. instructions. To look in more places, edit ``./pyassimp/helper.py``.
  59. There's an ``additional_dirs`` list waiting for your entries.