e.g.
Qt3DCore::QEntity *sphereEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh;
sphereMesh->setRadius(3);
Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform;
sphereTransform->setScale(3);
sphereEntity->addComponent(sphereMesh);
sphereEntity->addComponent(sphereTransform);
Can I get all sphereMesh's vertexes ?
And are it's vertexes tranformed by sphereTransform ?
or How can I get the tranformed vertexes ?
I think I can use QAttribute, but I need some examples.
update:
I have tried:
// plane
Qt3DCore::QEntity *planeEntity = new Qt3DCore::QEntity(rootEntity);
Qt3DExtras::QPlaneMesh *planeMesh = new Qt3DExtras::QPlaneMesh;
planeMesh->setWidth(1);
planeMesh->setHeight(1);
Qt3DCore::QTransform *planeform = new Qt3DCore::QTransform;
planeform->setRotation(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), 90.0f));
planeform->setScale(10);
planeEntity->addComponent(planeMesh);
planeEntity->addComponent(material);
planeEntity->addComponent(planeform);
// ----------------
QList<QVector4D> list;
for ( auto attribute : planeMesh->geometry()->attributes() ) {
if (attribute->name() == Qt3DRender::QAttribute::defaultPositionAttributeName()) {
Qt3DRender::QBuffer *buffer = attribute->buffer();
const QByteArray &data = buffer->data();
for ( int i = 0 ; i < attribute->count() ; i++ ) {
int vertexOffset = i * attribute->byteStride();
int offset = vertexOffset + attribute->byteOffset();
const char *vertexData = attribute->buffer()->data().constData() + (i * attribute->byteStride() + attribute->byteOffset());
qDebug() << (int)vertexData;
const float *typedVertexData = reinterpret_cast<const float*>(vertexData);
list << QVector4D(typedVertexData[0], typedVertexData[1], typedVertexData[2], 1.0) ;
qDebug() << list.last();
} // for
} // if
} // for
and it's output:
QVector4D(0, 0, 0, 1)
QVector4D(1.57402e-38, 1.34525e-43, 0, 1)
QVector4D(0, 7.00649e-45, 1.52015e-23, 1)
QVector4D(1.52015e-23, 0, 0, 1)
and I transform it :
qDebug() << (list[0] * planeform->matrix());
qDebug() << (list[1] * planeform->matrix());
qDebug() << (list[2] * planeform->matrix());
qDebug() << (list[3] * planeform->matrix());
// ---- output --------
QVector4D(0, 0, 0, 1)
QVector4D(1.57402e-37, 0, -1.34525e-42, 1)
QVector4D(0, 1.52015e-22, 9.06081e-30, 1)
QVector4D(1.52015e-22, 0, 0, 1)
I think it is too small. How do I fix it?
question from:
https://stackoverflow.com/questions/65886488/qt3d-can-i-list-all-vertexes-from-qt3drenderqgeometryrenderer