我正在開發一個使用Qt3D的應用程序,需要通過C++訪問原始頂點數據。我正在使用QObjectPicker
進行射線定位,但由於數據是專用的(我開發了一個導入程序,它爲包含溫度讀數的每個頂點添加了一個額外的屬性),所以我不能使用QObjectPicker
來方便地從這個點讀取數據。Qt3D從QGeometry讀取原始頂點數據
3D對象正在通過QMesh
加載,所以我相信訪問原始數據的最佳方式是通過QMesh
的QGeometry
成員。如我錯了請糾正我。 QGeometry
具有保存頂點屬性的向量QAttribute
。 (再次,糾正我,如果我錯了。)從這一點上,我不知道如何從特定的頂點索引讀取數據。我的猜測是,我需要從某個位置讀取QAttribute::buffer
的數據,方法是知道每個頂點數據有多大,然後從偏移量讀取,但我該怎麼做?
這是我想出迄今:
void ES3DScene::handlePickerClicked(QPickEvent *pick)
{
QPickTriangleEvent *trianglePick = qobject_cast<QPickTriangleEvent*>(pick);
// I'd like to get the vertex data from vertex1Index's position.
qDebug() << "Clicked " << trianglePick->vertex1Index();
QGeometry *geometry = m_mesh->geometry();
auto attributes = geometry->attributes();
for (auto i = 0; i < attributes.count(); ++i)
{
if (attributes.at(i)->name() == QAttribute::defaultPositionAttributeName())
{
QAttribute *attribute = attributes.at(i);
qDebug() << "Attrib " << attribute;
//This is where I'm stuck. I need to read the vertex attributes for the
//vertex at trianglePick->vertex1Index();
break;
}
}
}
非常好。看起來像這樣做。在你回答之前不久,我發現了另一種非常相似的方式。 –