| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef GEOMETRYTESTHELPER_H |
| 5 |
#define GEOMETRYTESTHELPER_H |
| 6 |
|
| 7 |
#include <Qt3DCore/qattribute.h> |
| 8 |
#include <Qt3DCore/qbuffer.h> |
| 9 |
#include <Qt3DCore/qgeometry.h> |
| 10 |
|
| 11 |
template<typename IndexType> |
| 12 |
IndexType extractIndexData(Qt3DCore::QAttribute *attribute, int index) |
| 13 |
{ |
| 14 |
|
| 15 |
const IndexType *typedData = reinterpret_cast<const IndexType *>(attribute->buffer()->data().constData()); |
| 16 |
|
| 17 |
|
| 18 |
const IndexType indexValue = *(typedData + index); |
| 19 |
return indexValue; |
| 20 |
} |
| 21 |
|
| 22 |
template<typename VertexType, typename IndexType> |
| 23 |
VertexType extractVertexData(Qt3DCore::QAttribute *attribute, IndexType index) |
| 24 |
{ |
| 25 |
|
| 26 |
const char *rawData = attribute->buffer()->data().constData(); |
| 27 |
|
| 28 |
|
| 29 |
const char *vertexData = rawData + (index * attribute->byteStride() + attribute->byteOffset()); |
| 30 |
|
| 31 |
|
| 32 |
VertexType vertex; |
| 33 |
const Qt3DCore::QAttribute::VertexBaseType type = attribute->vertexBaseType(); |
| 34 |
switch (type) |
| 35 |
{ |
| 36 |
case Qt3DCore::QAttribute::Float: { |
| 37 |
const float *typedVertexData = reinterpret_cast<const float *>(vertexData); |
| 38 |
const int components = attribute->vertexSize(); |
| 39 |
for (int i = 0; i < components; ++i) |
| 40 |
vertex[i] = typedVertexData[i]; |
| 41 |
break; |
| 42 |
|
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
default: |
| 47 |
qWarning() << "Unhandled type"; |
| 48 |
Q_UNREACHABLE(); |
| 49 |
break; |
| 50 |
} |
| 51 |
|
| 52 |
return vertex; |
| 53 |
} |
| 54 |
|
| 55 |
#endif |