37 , mWithNormals( _withNormals )
38 , mInvertNormals( _invertNormals )
39 , mAddBackFaces( _addBackFaces )
40 , mAddTextureCoords( _addTextureCoords )
44 const QgsTessellator tmpTess( 0, 0, mWithNormals,
false,
false,
false, mAddTextureCoords );
45 const int stride = tmpTess.
stride();
48 mPositionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
49 mPositionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
50 mPositionAttribute->setVertexSize( 3 );
51 mPositionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
52 mPositionAttribute->setBuffer( mVertexBuffer );
53 mPositionAttribute->setByteStride( stride );
54 mPositionAttribute->setByteOffset( 0 );
55 addAttribute( mPositionAttribute );
60 mNormalAttribute->setName( Qt3DQAttribute::defaultNormalAttributeName() );
61 mNormalAttribute->setVertexBaseType( Qt3DQAttribute::Float );
62 mNormalAttribute->setVertexSize( 3 );
63 mNormalAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
64 mNormalAttribute->setBuffer( mVertexBuffer );
65 mNormalAttribute->setByteStride( stride );
66 mNormalAttribute->setByteOffset( 3 *
sizeof(
float ) );
67 addAttribute( mNormalAttribute );
69 if ( mAddTextureCoords )
72 mTextureCoordsAttribute->setName( Qt3DQAttribute::defaultTextureCoordinateAttributeName() );
73 mTextureCoordsAttribute->setVertexBaseType( Qt3DQAttribute::Float );
74 mTextureCoordsAttribute->setVertexSize( 2 );
75 mTextureCoordsAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
76 mTextureCoordsAttribute->setBuffer( mVertexBuffer );
77 mTextureCoordsAttribute->setByteStride( stride );
78 mTextureCoordsAttribute->setByteOffset( mWithNormals ? 6 *
sizeof(
float ) : 3 *
sizeof( float ) );
79 addAttribute( mTextureCoordsAttribute );
85 Q_ASSERT( polygons.count() ==
featureIds.count() );
86 mTriangleIndexStartingIndices.reserve( polygons.count() );
87 mTriangleIndexFids.reserve( polygons.count() );
89 QgsTessellator tessellator( origin.
x(), origin.
y(), mWithNormals, mInvertNormals, mAddBackFaces,
false, mAddTextureCoords );
90 for (
int i = 0; i < polygons.count(); ++i )
93 const uint startingTriangleIndex =
static_cast<uint
>( tessellator.
dataVerticesCount() / 3 );
94 mTriangleIndexStartingIndices.append( startingTriangleIndex );
98 const float extr = extrusionHeightPerPolygon.
isEmpty() ? extrusionHeight : extrusionHeightPerPolygon.at( i );
102 qDeleteAll( polygons );
104 const QByteArray data( (
const char * )tessellator.
data().constData(), tessellator.
data().count() *
sizeof(
float ) );
105 const int nVerts = data.count() / tessellator.
stride();
107 mVertexBuffer->setData( data );
108 mPositionAttribute->setCount( nVerts );
109 if ( mNormalAttribute )
110 mNormalAttribute->setCount( nVerts );
111 if ( mAddTextureCoords )
112 mTextureCoordsAttribute->setCount( nVerts );
118 mTriangleIndexFids = triangleIndexFids;
120 mVertexBuffer->setData( vertexBufferData );
121 mPositionAttribute->setCount( vertexCount );
122 if ( mNormalAttribute )
123 mNormalAttribute->setCount( vertexCount );
124 if ( mTextureCoordsAttribute )
125 mTextureCoordsAttribute->setCount( vertexCount );
void setPolygons(const QList< QgsPolygon * > &polygons, const QList< QgsFeatureId > &featureIds, const QgsPointXY &origin, float extrusionHeight, const QList< float > &extrusionHeightPerPolygon=QList< float >())
Initializes vertex buffer from given polygons. Takes ownership of passed polygon geometries.
void setData(const QByteArray &vertexBufferData, int vertexCount, const QVector< QgsFeatureId > &triangleIndexFids, const QVector< uint > &triangleIndexStartingIndices)
Initializes vertex buffer (and other members) from data that were already tessellated.