我想使用pyqtgraph OpenGL绘制3D形状(矩形,立方体...) 但我想做到这一点而无需使用顶点和面孔。 我希望能够对每个点(基本上是折线)(线框)以及起点和终点设置为:
而不是顶点和面,使用常规的XYZ坐标linestart = [X0,Y0,Z0]
lineend = [X1,Y1,Z1]
这两个点将用一条线连接,以此类推,以防我想制作更复杂的形状。然后,关闭线条循环,将其定义为单个形状,并用一些透明的颜色填充它。
这是我现在可供参考的内容:
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph.opengl as gl
import pyqtgraph as pg
import numpy as np
from numpy import *
app = QtGui.QApplication([])
w = gl.GLViewWidget()
w.opts['distance'] = 40
w.show()
w.setWindowTitle('test plot')
w.setGeometry(300,300,2500,1500)
gx = gl.GLGridItem()
w.addItem(gx)
gy = gl.GLGridItem()
w.addItem(gy)
gz = gl.GLGridItem()
w.addItem(gz)
axis = gl.GLAxisItem()
w.addItem(axis)
def plot_shape():
verts = np.array([
[0, 0, 0],
[2, 0, 0],
[1, 2, 0],
[1, 1, 1],
])
faces = np.array([
[0, 1, 2],
[0, 1, 3],
[0, 2, 3],
[1, 2, 3]
])
colors = np.array([
[1, 0, 0, 0.3],
[0, 1, 0, 0.3],
[0, 0, 1, 0.3],
[1, 1, 0, 0.3]
])
m1 = gl.GLMeshItem(vertexes=verts, faces=faces, faceColors=colors, smooth=False)
m1.setGLOptions('additive') # transparency
w.addItem(m1)
plot_shape()
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()