如何在 pyqtgraph 中绘制 .obj 文件?
How to draw a .obj file in pyqtgraph?
这行代码渲染了一行。
import pywavefront
import pyqtgraph.opengl as gl
from pyqtgraph.Qt import QtWidgets
import numpy as np
import sys
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = gl.GLViewWidget()
xx = 0
yx = 0
zx = 0
xy = 1
yy = 0
zy = 0
Xdot = (xx, yx, zx)
Ydot = (xy, yy, zy)
pts = np.array([Xdot, Ydot])
sh1 = gl.GLLinePlotItem(pos=pts, width=1, antialias=False)
w.addItem(sh1)
w.show()
app.exec()
如何让 pyqtgraph 渲染 .obj 文件?添加下面的行
scene = pywavefront.Wavefront('./mogaze/meshfiles/cup.obj',create_materials=True)
w.addItem(scene)
return 错误
QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)"
Unimplemented OBJ format statement 's' on line 's 1'
Traceback (most recent call last):
File "draw-human-objects-pred.py", line 137, in <module>
w.addItem(scene)
File "C:\Users\ha_ha\anaconda3\envs\pywavefront\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 64, in addItem
item._setView(self)
AttributeError: 'Wavefront' object has no attribute '_setView'
我认为它不是添加到小部件的合适对象。
此示例我如何加载和显示多维数据集:
root_path = os.path.dirname(__file__)
scene = pywavefront.Wavefront(os.path.join(root_path, 'data/box/box-V3F.obj'))
pts2 = np.array(scene.vertices)
sh2 = gl.GLLinePlotItem(pos=pts2, mode='line_strip')
sh3 = gl.GLScatterPlotItem(pos=pts2)
w.addItem(sh2)
w.addItem(sh3)
这是 box-V3F.obj
文件的内容,我在其中注释掉了行 s off
:
# Blender v2.78 (sub 0) OBJ File: 'box.blend'
# www.blender.org
mtllib box.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
usemtl Material
#s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8
我对这个库没有太多经验,但我希望这对你有帮助。
使用 pyqtgraph's
GLMeshItem
https://pyqtgraph.readthedocs.io/en/latest/3dgraphics/glmeshitem.html 但是你需要有 3 个点的顶点。
您可以使用 pywavefront
加载您的 .obj 文件以获得每个面有 3 个顶点的 .obj 文件。
https://github.com/pywavefront/PyWavefront/issues/87然后用pyqtgraph加载它。
这行代码渲染了一行。
import pywavefront
import pyqtgraph.opengl as gl
from pyqtgraph.Qt import QtWidgets
import numpy as np
import sys
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = gl.GLViewWidget()
xx = 0
yx = 0
zx = 0
xy = 1
yy = 0
zy = 0
Xdot = (xx, yx, zx)
Ydot = (xy, yy, zy)
pts = np.array([Xdot, Ydot])
sh1 = gl.GLLinePlotItem(pos=pts, width=1, antialias=False)
w.addItem(sh1)
w.show()
app.exec()
如何让 pyqtgraph 渲染 .obj 文件?添加下面的行
scene = pywavefront.Wavefront('./mogaze/meshfiles/cup.obj',create_materials=True)
w.addItem(scene)
return 错误
QWindowsContext: OleInitialize() failed: "COM error 0xffffffff80010106 RPC_E_CHANGED_MODE (Unknown error 0x080010106)"
Unimplemented OBJ format statement 's' on line 's 1'
Traceback (most recent call last):
File "draw-human-objects-pred.py", line 137, in <module>
w.addItem(scene)
File "C:\Users\ha_ha\anaconda3\envs\pywavefront\lib\site-packages\pyqtgraph\opengl\GLViewWidget.py", line 64, in addItem
item._setView(self)
AttributeError: 'Wavefront' object has no attribute '_setView'
我认为它不是添加到小部件的合适对象。
此示例我如何加载和显示多维数据集:
root_path = os.path.dirname(__file__)
scene = pywavefront.Wavefront(os.path.join(root_path, 'data/box/box-V3F.obj'))
pts2 = np.array(scene.vertices)
sh2 = gl.GLLinePlotItem(pos=pts2, mode='line_strip')
sh3 = gl.GLScatterPlotItem(pos=pts2)
w.addItem(sh2)
w.addItem(sh3)
这是 box-V3F.obj
文件的内容,我在其中注释掉了行 s off
:
# Blender v2.78 (sub 0) OBJ File: 'box.blend'
# www.blender.org
mtllib box.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
usemtl Material
#s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8
我对这个库没有太多经验,但我希望这对你有帮助。
使用 pyqtgraph's
GLMeshItem
https://pyqtgraph.readthedocs.io/en/latest/3dgraphics/glmeshitem.html 但是你需要有 3 个点的顶点。
您可以使用 pywavefront
加载您的 .obj 文件以获得每个面有 3 个顶点的 .obj 文件。
https://github.com/pywavefront/PyWavefront/issues/87然后用pyqtgraph加载它。