Problems with wavefront object as GLMeshItem in Pyqtgraph
See original GitHub issueHi there! I’m trying to use PyWavefront to read an wavefront object and visualise it using Pyqtgraph. Using the faces and vertices data for GLLinePlotItem and GLScatterPlotItem works fine, but there seems to be a compatibility issue with the vertices and faces data with GLMeshItem:
> |==============================>>
> | Traceback (most recent call last):
> | File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 197, in _run_module_as_main
> | return _run_code(code, main_globals, None,
> | File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
> | exec(code, run_globals)
> | File "/Users/X/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
> | cli.main()
> | File "/Users/X/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 444, in main
> | run()
> | File "/Users/X/.vscode/extensions/ms-python.python-2021.3.680753044/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 285, in run_file
> | runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
> | File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 268, in run_path
> | return _run_module_code(code, init_globals, run_name,
> | File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
> | _run_code(code, mod_globals, init_globals,
> | File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
> | exec(code, run_globals)
> | File "/Users/X/test_pywavefront.py", line 45, in <module>
> | QtGui.QApplication.instance().exec_()
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/GLViewWidget.py", line 257, in paintGL
> | self.drawItemTree(useItemNames=useItemNames)
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/GLViewWidget.py", line 297, in drawItemTree
> | self.drawItemTree(i, useItemNames=useItemNames)
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/GLViewWidget.py", line 278, in drawItemTree
> | debug.printExc()
> | --- exception caught here ---
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/GLViewWidget.py", line 275, in drawItemTree
> | i.paint()
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/items/GLMeshItem.py", line 167, in paint
> | self.parseMeshData()
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/items/GLMeshItem.py", line 146, in parseMeshData
> | self.normals = md.vertexNormals(indexed='faces')
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/MeshData.py", line 209, in vertexNormals
> | faceNorms = self.faceNormals()
> | File "/Users/X/.venv/lib/python3.9/site-packages/pyqtgraph/opengl/MeshData.py", line 188, in faceNormals
> | self._faceNormals = np.cross(v[:,1]-v[:,0], v[:,2]-v[:,0])
> | TypeError: list indices must be integers or slices, not tuple
> |==============================<<
> Error while drawing item <pyqtgraph.opengl.items.GLMeshItem.GLMeshItem object at 0x7f82a86dbdc0>.
Does anybody try to use PyWavefront in combination with Pyqtgraph already? Can any body help me to find the problem and a solution? Looking forward for some help, thanks a lot in advance!
The code:
import pywavefront
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
import pyqtgraph.opengl as gl
import numpy as np
scene = pywavefront.Wavefront(
"/BMW_simple.obj",
strict=False,
create_materials=True,
collect_faces=True
)
print("Faces:", scene.mesh_list[0].faces)
print("Vertices:", scene.vertices)
print("Format:", scene.mesh_list[0].materials[0].vertex_format)
print("Vertices:", scene.mesh_list[0].materials[0].vertices)
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.show()
w.setWindowTitle('pyqtgraph example: GLMeshItem')
w.setCameraPosition(distance=40)
g = gl.GLGridItem()
g.scale(2,2,1)
w.addItem(g)
m1 = gl.GLMeshItem(vertexes=scene.vertices, drawFaces=False, drawEdges=True, smooth=True)
m1.translate(5, 5, 0)
m1.setGLOptions('additive')
w.addItem(m1)
pts2 = np.array(scene.vertices)
sh2 = gl.GLLinePlotItem(pos=pts2, mode='line_strip')
sh3 = gl.GLScatterPlotItem(pos=pts2)
w.addItem(sh2)
w.addItem(sh3)
## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top Results From Across the Web
How to draw a .obj file in pyqtgraph? - python - Stack Overflow
Use pyqtgraph's GLMeshItem https://pyqtgraph.readthedocs.io/en/latest/ ... Wavefront(os.path.join(root_path, 'data/box/box-V3F.obj')) pts2 ...
Read more >GLMeshItem — pyqtgraph 0.13.2.dev0 documentation
Displays a 3D triangle mesh. MeshData object from which to determine geometry for this item. Default face color used if no vertex or...
Read more >More GLViewWidget don't work at the same time !!
i'm developing an application that includes pyqtgraph for data ... "C:\Program Files (x86)\Python33\lib\site-packages\pyqtgraph\opengl\items\GLMeshItem.py", ...
Read more >Qt 3d mesh example
9, Mesh supports the following formats: Wavefront OBJ. ... of We propose the following perturbation scheme for the 3D mesh intersection problem. obj...
Read more >Flying Mesh Terrain Animation using PyQtGraph and OpenGL
In this video, we make an animated mesh surface which simulates natural terrain using perlin noise. The effect is that you're flying over ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for your input! Just managed to transform the outputs in the suitable format for PyQtGraph (extracted all faces into a separate array).
(Print statements are just for debugging purposes… I have used one of the examples and exchanged the model and it works fine, so the problem is definitely due to format issues…)
Hi @nitieaj! Sorry for the late response, had a few days of vacation. This is the code I used to transform the pywavefront object to a plot in pyqtgraph:
However, I did not manage to add the textures/materials of the model. I’m not sure whether this is possible or not with PyQtGraph - if you find a way, please let me know!
Furthermore, the cache function in pywavefront has not been working for me. The created binary file cannot be processed after its creation - again, if you find a solution, happy to hear back from you!