37
37
QgsPoint3DSymbolEntity::QgsPoint3DSymbolEntity ( const Qgs3DMapSettings &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol, Qt3DCore::QNode *parent )
38
38
: Qt3DCore::QEntity( parent )
39
39
{
40
- if ( symbol.shapeProperties ()[ " shape" ]. toString () == " model " )
40
+ if ( symbol.shape () == QgsPoint3DSymbol::Model )
41
41
{
42
42
QgsPoint3DSymbolModelEntityFactory::addEntitiesForSelectedPoints ( map, layer, symbol, this );
43
43
QgsPoint3DSymbolModelEntityFactory::addEntitiesForNotSelectedPoints ( map, layer, symbol, this );
@@ -199,78 +199,7 @@ Qt3DRender::QGeometryRenderer *QgsPoint3DSymbolInstancedEntityNode::renderer( co
199
199
instanceDataAttribute->setCount ( count );
200
200
instanceDataAttribute->setByteStride ( 3 * sizeof ( float ) );
201
201
202
- Qt3DRender::QGeometry *geometry = nullptr ;
203
- QVariantMap shapeProperties = symbol.shapeProperties ();
204
- QString shape = shapeProperties[" shape" ].toString ();
205
- if ( shape == " sphere" )
206
- {
207
- float radius = shapeProperties[" radius" ].toFloat ();
208
- Qt3DExtras::QSphereGeometry *g = new Qt3DExtras::QSphereGeometry;
209
- g->setRadius ( radius ? radius : 10 );
210
- geometry = g;
211
- }
212
- else if ( shape == " cone" )
213
- {
214
- float length = shapeProperties[" length" ].toFloat ();
215
- float bottomRadius = shapeProperties[" bottomRadius" ].toFloat ();
216
- float topRadius = shapeProperties[" topRadius" ].toFloat ();
217
- Qt3DExtras::QConeGeometry *g = new Qt3DExtras::QConeGeometry;
218
- g->setLength ( length ? length : 10 );
219
- g->setBottomRadius ( bottomRadius );
220
- g->setTopRadius ( topRadius );
221
- // g->setHasBottomEndcap(hasBottomEndcap);
222
- // g->setHasTopEndcap(hasTopEndcap);
223
- geometry = g;
224
- }
225
- else if ( shape == " cube" )
226
- {
227
- float size = shapeProperties[" size" ].toFloat ();
228
- Qt3DExtras::QCuboidGeometry *g = new Qt3DExtras::QCuboidGeometry;
229
- g->setXExtent ( size ? size : 10 );
230
- g->setYExtent ( size ? size : 10 );
231
- g->setZExtent ( size ? size : 10 );
232
- geometry = g;
233
- }
234
- else if ( shape == " torus" )
235
- {
236
- float radius = shapeProperties[" radius" ].toFloat ();
237
- float minorRadius = shapeProperties[" minorRadius" ].toFloat ();
238
- Qt3DExtras::QTorusGeometry *g = new Qt3DExtras::QTorusGeometry;
239
- g->setRadius ( radius ? radius : 10 );
240
- g->setMinorRadius ( minorRadius ? minorRadius : 5 );
241
- geometry = g;
242
- }
243
- else if ( shape == " plane" )
244
- {
245
- float size = shapeProperties[" size" ].toFloat ();
246
- Qt3DExtras::QPlaneGeometry *g = new Qt3DExtras::QPlaneGeometry;
247
- g->setWidth ( size ? size : 10 );
248
- g->setHeight ( size ? size : 10 );
249
- geometry = g;
250
- }
251
- #if QT_VERSION >= 0x050900
252
- else if ( shape == " extrudedText" )
253
- {
254
- float depth = shapeProperties[" depth" ].toFloat ();
255
- QString text = shapeProperties[" text" ].toString ();
256
- Qt3DExtras::QExtrudedTextGeometry *g = new Qt3DExtras::QExtrudedTextGeometry;
257
- g->setDepth ( depth ? depth : 1 );
258
- g->setText ( text );
259
- geometry = g;
260
- }
261
- #endif
262
- else // shape == "cylinder" or anything else
263
- {
264
- float radius = shapeProperties[" radius" ].toFloat ();
265
- float length = shapeProperties[" length" ].toFloat ();
266
- Qt3DExtras::QCylinderGeometry *g = new Qt3DExtras::QCylinderGeometry;
267
- // g->setRings(2); // how many vertices vertically
268
- // g->setSlices(8); // how many vertices on circumference
269
- g->setRadius ( radius ? radius : 10 );
270
- g->setLength ( length ? length : 10 );
271
- geometry = g;
272
- }
273
-
202
+ Qt3DRender::QGeometry *geometry = symbolGeometry ( symbol.shape (), symbol.shapeProperties () );
274
203
geometry->addAttribute ( instanceDataAttribute );
275
204
geometry->setBoundingVolumePositionAttribute ( instanceDataAttribute );
276
205
@@ -281,6 +210,91 @@ Qt3DRender::QGeometryRenderer *QgsPoint3DSymbolInstancedEntityNode::renderer( co
281
210
return renderer;
282
211
}
283
212
213
+ Qt3DRender::QGeometry *QgsPoint3DSymbolInstancedEntityNode::symbolGeometry ( QgsPoint3DSymbol::Shape shape, const QVariantMap &shapeProperties ) const
214
+ {
215
+ switch ( shape )
216
+ {
217
+ case QgsPoint3DSymbol::Cylinder:
218
+ {
219
+ float radius = shapeProperties[" radius" ].toFloat ();
220
+ float length = shapeProperties[" length" ].toFloat ();
221
+ Qt3DExtras::QCylinderGeometry *g = new Qt3DExtras::QCylinderGeometry;
222
+ // g->setRings(2); // how many vertices vertically
223
+ // g->setSlices(8); // how many vertices on circumference
224
+ g->setRadius ( radius ? radius : 10 );
225
+ g->setLength ( length ? length : 10 );
226
+ return g;
227
+ }
228
+
229
+ case QgsPoint3DSymbol::Sphere:
230
+ {
231
+ float radius = shapeProperties[" radius" ].toFloat ();
232
+ Qt3DExtras::QSphereGeometry *g = new Qt3DExtras::QSphereGeometry;
233
+ g->setRadius ( radius ? radius : 10 );
234
+ return g;
235
+ }
236
+
237
+ case QgsPoint3DSymbol::Cone:
238
+ {
239
+ float length = shapeProperties[" length" ].toFloat ();
240
+ float bottomRadius = shapeProperties[" bottomRadius" ].toFloat ();
241
+ float topRadius = shapeProperties[" topRadius" ].toFloat ();
242
+ Qt3DExtras::QConeGeometry *g = new Qt3DExtras::QConeGeometry;
243
+ g->setLength ( length ? length : 10 );
244
+ g->setBottomRadius ( bottomRadius );
245
+ g->setTopRadius ( topRadius );
246
+ // g->setHasBottomEndcap(hasBottomEndcap);
247
+ // g->setHasTopEndcap(hasTopEndcap);
248
+ return g;
249
+ }
250
+
251
+ case QgsPoint3DSymbol::Cube:
252
+ {
253
+ float size = shapeProperties[" size" ].toFloat ();
254
+ Qt3DExtras::QCuboidGeometry *g = new Qt3DExtras::QCuboidGeometry;
255
+ g->setXExtent ( size ? size : 10 );
256
+ g->setYExtent ( size ? size : 10 );
257
+ g->setZExtent ( size ? size : 10 );
258
+ return g;
259
+ }
260
+
261
+ case QgsPoint3DSymbol::Torus:
262
+ {
263
+ float radius = shapeProperties[" radius" ].toFloat ();
264
+ float minorRadius = shapeProperties[" minorRadius" ].toFloat ();
265
+ Qt3DExtras::QTorusGeometry *g = new Qt3DExtras::QTorusGeometry;
266
+ g->setRadius ( radius ? radius : 10 );
267
+ g->setMinorRadius ( minorRadius ? minorRadius : 5 );
268
+ return g;
269
+ }
270
+
271
+ case QgsPoint3DSymbol::Plane:
272
+ {
273
+ float size = shapeProperties[" size" ].toFloat ();
274
+ Qt3DExtras::QPlaneGeometry *g = new Qt3DExtras::QPlaneGeometry;
275
+ g->setWidth ( size ? size : 10 );
276
+ g->setHeight ( size ? size : 10 );
277
+ return g;
278
+ }
279
+
280
+ #if QT_VERSION >= 0x050900
281
+ case QgsPoint3DSymbol::ExtrudedText:
282
+ {
283
+ float depth = shapeProperties[" depth" ].toFloat ();
284
+ QString text = shapeProperties[" text" ].toString ();
285
+ Qt3DExtras::QExtrudedTextGeometry *g = new Qt3DExtras::QExtrudedTextGeometry;
286
+ g->setDepth ( depth ? depth : 1 );
287
+ g->setText ( text );
288
+ return g;
289
+ }
290
+ #endif
291
+
292
+ default :
293
+ Q_ASSERT ( false );
294
+ return nullptr ;
295
+ }
296
+ }
297
+
284
298
// * 3D MODEL RENDERING *//
285
299
286
300
static Qt3DExtras::QPhongMaterial *phongMaterial ( const QgsPoint3DSymbol &symbol )
0 commit comments