Issue
My goal is to create a numpy
array and convert its bytes data to QBuffer
. I am wondering how to set properly DataSize
, ByteStride
, and Count
. See my code below:
self.mesh = Qt3DRender.QGeometryRenderer()
self.mesh.setPrimitiveType(Qt3DRender.QGeometryRenderer.Points)
self.geometry = Qt3DRender.QGeometry(self.mesh)
vertex_data_buffer = Qt3DRender.QBuffer(Qt3DRender.QBuffer.VertexBuffer, self.geometry)
data = np.random.rand(1000, 3)
vertex_data_buffer.setData(QByteArray(data.tobytes()))
self.position_attribute = Qt3DRender.QAttribute()
self.position_attribute.setAttributeType(
Qt3DRender.QAttribute.VertexAttribute)
self.position_attribute.setBuffer(vertex_data_buffer)
self.position_attribute.setDataType(Qt3DRender.QAttribute.Float)
self.position_attribute.setDataSize(3) # ??
self.position_attribute.setByteOffset(0)
self.position_attribute.setByteStride(6) # ??
self.position_attribute.setCount(1000) # ??
self.position_attribute.setName(
Qt3DRender.QAttribute.defaultPositionAttributeName())
self.geometry.addAttribute(self.position_attribute)
Solution
We managed to fix this.
First of all these two copied below lines are deprecated. They can be removed.
self.position_attribute.setDataType(Qt3DRender.QAttribute.Float)
self.position_attribute.setDataSize(3)
One line is added:
self.position_attribute.setVertexSize(3)
ByteStride
should be set to 12
. 3
is the number of coordinates and 4
is length of float32
in bytes. Be aware to set numpy
's array
: data = np.random.rand(1000, 3).astype(np.float32)
.
self.position_attribute.setByteOffset(0)
self.position_attribute.setByteStride(3*4)
self.position_attribute.setCount(1000)
Answered By - Matphy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.