[Interest] Initialization of Buffer entity property in QML
Jérôme Godbout
godboutj at amotus.ca
Wed Apr 10 15:57:46 CEST 2019
The new is not something you should do into binding for sure. If I look at the Qml Buffer doc:
https://doc.qt.io/qt-5/qml-qt3d-render-buffer.html
Not much seem to be expose to Qml, syncData, usage
https://doc.qt.io/qt-5/qt3drender-qbuffer.html
and the sub class QBuffer offer the following properties accessType.
Seem like you will need to fill the data into C++ from what the doc is saying. Maybe make your own QmlBuffer inherited class where you can expose QByteArray to expose the data, the dataChanged signal is already present. Just need a property exposure, wonder why this was not already exposed. You can make static Q_INVOKABLE to create QByteArray from JS array type into that class:
Q_INVOKABLE QByteArray MakeVector3F(const QVariantList& data);
Q_INVOKABLE QByteArray MakeVector2D(const QVariantList& data);
...
Maybe add the data type, so you could have a call that push/pop data into your buffer QByteArray
Q_INVOKABLE void pushData(const QVariant& data);
with the proper C++ call to convert the QVariant into the Buffer data type.
Those buffer class seem a bit anemic into functionality, wonder how they should be normally be used?!? The Qml exposure seem incomplete to me. Maybe someone with deeper knowledge can pitch in, but the only way I see it, they are fully managed into C++ only to be plug in Qml at best, no containing data manipulation into Qml from what I see. You use case seem legit to me, you have some property you need to assign to a Buffer, you probably don't want to do this with huge data set, but for simple and debugging buffer this will come in handy to do so. In the real world, making C++ producer to generate you data Buffer would be better performance wise.
I haven't play much with Qt3D, but we did a lot of rendering to texture at my previous place, and we did have a Qml Buffer implementation way before Qt3D and we did needed those data type and everything was named attribs to the rendering actor and we could set the shader programs (vertex, geometry, fragment...) from the Qml, we could attachs as many attribs Buffer and a draw call to the actors for the rendering. I would expect something similar for a real 3D rendering engine.
-----Original Message-----
From: Interest <interest-bounces at qt-project.org> On Behalf Of Volker Enderlein
Sent: April 10, 2019 3:48 AM
To: Qt Project <interest at qt-project.org>
Subject: [Interest] Initialization of Buffer entity property in QML
Hi,
in a QML file I try to initialize a property of type Buffer, but unfortunately it does not work.
There's no error but in the MyMesh Entity the vertices Buffer always has zero length.
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import QtQuick 2.0
import Qt3D.Extras 2.10
Entity {
id: root
property Buffer vertices: Buffer { type: Buffer.VertexBuffer; data:
new Float32Array([ -1., 1., 0., 1., 1., 0., -1., -1., 0., 1., -1., 0. ]) }
MyMesh {
id: mesh
vertices: root.vertices
}
}
How is the correct way?
Cheers, Volker
_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
More information about the Interest
mailing list