尽管我一直坚持画一个简单的立方体,但我在运行时正在生成网格。为什么屏幕上什么都没出现?
如何将浮点数组(三角形顶点)转换为3D网格?
为满足所需的描述长度,我有第二个相关问题。当多维数据集已经被渲染时,如何在其上放置纹理?
class Master : public QObject
{
Q_OBJECT
public:
explicit Master(QObject *parent = nullptr) : QObject(parent)
{
float vertexArray[] = {
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
1.0f,-1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
-1.0f,-1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f,-1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f,-1.0f,
1.0f,-1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f,-1.0f,
-1.0f, 1.0f,-1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f,-1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f,-1.0f, 1.0f
};
m_buffer.append(reinterpret_cast<const char*>(vertexArray), sizeof(vertexArray));
}
Q_PROPERTY(QByteArray buffer READ buffer CONSTANT)
QByteArray buffer() const { return m_buffer; }
private:
QByteArray m_buffer;
};
和Scene3D中的GeometryRenderer:
Entity{
Material{
id: material
parameters: [
Parameter { name: "color"; value: "green" }
]
}
GeometryRenderer{
id: geometryRenderer
instanceCount: 0
primitiveType: GeometryRenderer.Triangles
geometry: Geometry{
Attribute{
attributeType: Attribute.VertexAttribute
vertexBaseType: Attribute.Float
vertexSize: 3
byteOffset: 0
byteStride: 3 * 4
count: 12
buffer : Buffer{
type: Buffer.VertexBuffer
data: Master.buffer
}
}
}
}
components: [material, geometryRenderer]
}