19 #include <Qt3DCore/QEntity>
20 #include <Qt3DCore/QComponent>
21 #include <Qt3DCore/QNode>
22 #include <Qt3DRender/QGeometry>
23 #include <Qt3DRender/QAttribute>
24 #include <Qt3DRender/QBuffer>
25 #include <Qt3DRender/QGeometryRenderer>
26 #include <Qt3DExtras/QPlaneGeometry>
27 #include <Qt3DCore/QTransform>
28 #include <Qt3DRender/QMaterial>
29 #include <Qt3DExtras/QDiffuseSpecularMaterial>
30 #include <Qt3DExtras/QTextureMaterial>
31 #include <Qt3DRender/QTextureImage>
32 #include <Qt3DRender/QTexture>
33 #include <Qt3DRender/QBufferDataGenerator>
34 #include <Qt3DRender/QBufferDataGeneratorPtr>
35 #include <Qt3DRender/QMesh>
36 #include <Qt3DRender/QSceneLoader>
37 #include <Qt3DRender/QAbstractTexture>
38 #include <Qt3DExtras/QCylinderGeometry>
39 #include <Qt3DExtras/QConeGeometry>
40 #include <Qt3DExtras/QSphereGeometry>
41 #include <Qt3DExtras/QCuboidGeometry>
42 #include <Qt3DExtras/QTorusGeometry>
43 #include <Qt3DExtras/QExtrudedTextMesh>
44 #include <Qt3DExtras/QPhongMaterial>
45 #include <Qt3DRender/QAbstractTextureImage>
49 #include <QTextStream>
64 #include "qgsmesh3dgeometry_p.h"
66 #include "qgsmesh3dentity_p.h"
67 #include "qgsmeshterraingenerator.h"
83 QVector<T>
getAttributeData( Qt3DRender::QAttribute *attribute,
const QByteArray &data )
85 const uint bytesOffset = attribute->byteOffset();
86 const uint bytesStride = attribute->byteStride();
87 const uint vertexSize = attribute->vertexSize();
90 if ( bytesStride == 0 )
92 QgsDebugMsg(
"bytesStride==0, the attribute probably was not set properly" );
96 const char *pData = data.constData();
97 for (
int i = bytesOffset; i < data.size(); i += bytesStride )
99 for (
unsigned int j = 0; j < vertexSize *
sizeof( T ); j +=
sizeof( T ) )
102 memcpy( &v, pData + i + j,
sizeof( T ) );
103 result.push_back( v );
112 QVector<uint> result;
113 const char *pData = data.constData();
114 for (
int i = 0; i < data.size(); i +=
sizeof( T ) )
117 memcpy( &v, pData + i,
sizeof( T ) );
118 result.push_back( ( uint ) v );
123 QVector<uint>
getIndexData( Qt3DRender::QAttribute *indexAttribute,
const QByteArray &data )
125 switch ( indexAttribute->vertexBaseType() )
127 case Qt3DRender::QAttribute::VertexBaseType::Int:
128 return _getIndexDataImplementation<int>( data );
129 case Qt3DRender::QAttribute::VertexBaseType::UnsignedInt:
130 return _getIndexDataImplementation<uint>( data );
131 case Qt3DRender::QAttribute::VertexBaseType::Short:
132 return _getIndexDataImplementation<short>( data );
133 case Qt3DRender::QAttribute::VertexBaseType::UnsignedShort:
134 return _getIndexDataImplementation<ushort>( data );
135 case Qt3DRender::QAttribute::VertexBaseType::Byte:
136 return _getIndexDataImplementation<char>( data );
137 case Qt3DRender::QAttribute::VertexBaseType::UnsignedByte:
138 return _getIndexDataImplementation<uchar>( data );
140 QgsDebugMsg(
"Probably trying to get index data using an attribute that has vertex data" );
143 return QVector<uint>();
146 QByteArray
getData( Qt3DRender::QBuffer *buffer )
148 QByteArray bytes = buffer->data();
149 if ( bytes.isNull() )
156 Qt3DRender::QAttribute *
findAttribute( Qt3DRender::QGeometry *geometry,
const QString &name, Qt3DRender::QAttribute::AttributeType type )
158 for ( Qt3DRender::QAttribute *attribute : geometry->attributes() )
160 if ( attribute->attributeType() != type )
continue;
161 if ( attribute->name() == name )
return attribute;
166 template<
typename Component>
169 if ( entity ==
nullptr )
return nullptr;
170 for ( Qt3DCore::QComponent *component : entity->components() )
172 Component *typedComponent = qobject_cast<Component *>( component );
173 if ( typedComponent !=
nullptr )
174 return typedComponent;
182 const QString rendererType = abstractRenderer->
type();
184 if ( rendererType ==
"mesh" )
191 if ( rendererType ==
"rulebased" )
194 const QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
195 for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
197 Qt3DCore::QEntity *parentEntity = qobject_cast<Qt3DCore::QEntity *>( renderer->parent() );
200 Qgs3DExportObject *
object = processGeometryRenderer( renderer, layer->
name() + QStringLiteral(
"_" ) );
201 if (
object ==
nullptr )
continue;
202 if ( mExportTextures )
203 processEntityMaterial( parentEntity,
object );
204 mObjects.push_back(
object );
211 if ( vectorLayerRenderer )
214 const bool exported = symbol->
exportGeometries(
this, entity, layer->
name() + QStringLiteral(
"_" ) );
224 void Qgs3DSceneExporter::processEntityMaterial( Qt3DCore::QEntity *entity,
Qgs3DExportObject *
object )
226 Qt3DExtras::QPhongMaterial *phongMaterial = findTypedComponent<Qt3DExtras::QPhongMaterial>( entity );
227 if ( phongMaterial !=
nullptr )
230 object->setupMaterial( &material );
232 Qt3DExtras::QDiffuseSpecularMaterial *diffuseMapMaterial = findTypedComponent<Qt3DExtras::QDiffuseSpecularMaterial>( entity );
234 if ( diffuseMapMaterial !=
nullptr )
236 const QVector<Qt3DRender::QAbstractTextureImage *> textureImages = diffuseMapMaterial->diffuse().value< Qt3DRender::QTexture2D * >()->textureImages();
238 for ( Qt3DRender::QAbstractTextureImage *tex : textureImages )
241 if ( imageTexture !=
nullptr )
break;
243 if ( imageTexture !=
nullptr )
245 const QImage image = imageTexture->
getImage();
246 object->setTextureImage( image );
257 QgsChunkNode *node = terrain->rootNode();
262 QgsTerrainTileEntity *terrainTile =
nullptr;
263 QgsTerrainTextureGenerator *textureGenerator = terrain->textureGenerator();
264 textureGenerator->waitForFinished();
265 const QSize oldResolution = textureGenerator->textureSize();
266 textureGenerator->setTextureSize( QSize( mTerrainTextureResolution, mTerrainTextureResolution ) );
267 switch ( generator->
type() )
270 terrainTile = getDemTerrainEntity( terrain, node );
271 parseDemTile( terrainTile, layerName + QStringLiteral(
"_" ) );
274 terrainTile = getFlatTerrainEntity( terrain, node );
275 parseFlatTile( terrainTile, layerName + QStringLiteral(
"_" ) );
279 terrainTile = getMeshTerrainEntity( terrain, node );
280 parseMeshTile( terrainTile, layerName + QStringLiteral(
"_" ) );
285 textureGenerator->setTextureSize( oldResolution );
288 QgsTerrainTileEntity *Qgs3DSceneExporter::getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node )
291 FlatTerrainChunkLoader *flatTerrainLoader = qobject_cast<FlatTerrainChunkLoader *>( generator->
createChunkLoader( node ) );
292 if ( mExportTextures )
293 terrain->textureGenerator()->waitForFinished();
295 Qt3DCore::QEntity *entity = flatTerrainLoader->createEntity(
this );
296 QgsTerrainTileEntity *tileEntity = qobject_cast<QgsTerrainTileEntity *>( entity );
300 QgsTerrainTileEntity *Qgs3DSceneExporter::getDemTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node )
306 QgsDemTerrainTileLoader *loader = qobject_cast<QgsDemTerrainTileLoader *>( generator->
createChunkLoader( node ) );
308 if ( mExportTextures )
309 terrain->textureGenerator()->waitForFinished();
310 QgsTerrainTileEntity *tileEntity = qobject_cast<QgsTerrainTileEntity *>( loader->createEntity(
this ) );
315 QgsTerrainTileEntity *Qgs3DSceneExporter::getMeshTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node )
317 QgsMeshTerrainGenerator *generator =
dynamic_cast<QgsMeshTerrainGenerator *
>( terrain->map3D().terrainGenerator() );
318 QgsMeshTerrainTileLoader *loader = qobject_cast<QgsMeshTerrainTileLoader *>( generator->createChunkLoader( node ) );
320 QgsTerrainTileEntity *tileEntity = qobject_cast<QgsTerrainTileEntity *>( loader->createEntity(
this ) );
324 void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity,
const QString &layerName )
326 Qt3DRender::QGeometryRenderer *mesh = findTypedComponent<Qt3DRender::QGeometryRenderer>( tileEntity );
327 Qt3DCore::QTransform *transform = findTypedComponent<Qt3DCore::QTransform>( tileEntity );
329 Qt3DRender::QGeometry *geometry = mesh->geometry();
330 Qt3DExtras::QPlaneGeometry *tileGeometry = qobject_cast<Qt3DExtras::QPlaneGeometry *>( geometry );
331 if ( tileGeometry ==
nullptr )
333 QgsDebugMsg(
"Qt3DExtras::QPlaneGeometry* is expected but something else was given" );
337 const float scale = transform->scale();
338 const QVector3D translation = transform->translation();
341 Qt3DRender::QAttribute *positionAttribute = tileGeometry->positionAttribute();
342 const QByteArray verticesBytes =
getData( positionAttribute->buffer() );
343 const QVector<float> positionBuffer = getAttributeData<float>( positionAttribute, verticesBytes );
346 Qt3DRender::QAttribute *indexAttribute = tileGeometry->indexAttribute();
347 const QByteArray indexBytes =
getData( indexAttribute->buffer() );
348 const QVector<uint> indexesBuffer =
getIndexData( indexAttribute, indexBytes );
350 QString objectNamePrefix = layerName;
351 if ( objectNamePrefix != QString() ) objectNamePrefix += QString();
354 mObjects.push_back(
object );
356 object->setSmoothEdges( mSmoothEdges );
357 object->setupPositionCoordinates( positionBuffer,
scale, translation );
358 object->setupFaces( indexesBuffer );
360 if ( mExportNormals )
363 QVector<float> normalsBuffer;
364 for (
int i = 0; i < positionBuffer.size(); i += 3 ) normalsBuffer << 0.0f << 1.0f << 0.0f;
365 object->setupNormalCoordinates( normalsBuffer );
368 Qt3DRender::QAttribute *texCoordsAttribute = tileGeometry->texCoordAttribute();
369 if ( mExportTextures && texCoordsAttribute !=
nullptr )
372 const QVector<float> texCoords = getAttributeData<float>( texCoordsAttribute, verticesBytes );
373 object->setupTextureCoordinates( texCoords );
375 QgsTerrainTextureImage *textureImage = tileEntity->textureImage();
376 const QImage img = textureImage->getImage();
377 object->setTextureImage( img );
381 void Qgs3DSceneExporter::parseDemTile( QgsTerrainTileEntity *tileEntity,
const QString &layerName )
383 Qt3DRender::QGeometryRenderer *mesh = findTypedComponent<Qt3DRender::QGeometryRenderer>( tileEntity );
384 Qt3DCore::QTransform *transform = findTypedComponent<Qt3DCore::QTransform>( tileEntity );
386 Qt3DRender::QGeometry *geometry = mesh->geometry();
387 DemTerrainTileGeometry *tileGeometry = qobject_cast<DemTerrainTileGeometry *>( geometry );
388 if ( tileGeometry ==
nullptr )
390 QgsDebugMsg(
"DemTerrainTileGeometry* is expected but something else was given" );
394 const float scale = transform->scale();
395 const QVector3D translation = transform->translation();
397 Qt3DRender::QAttribute *positionAttribute = tileGeometry->positionAttribute();
398 const QByteArray positionBytes = positionAttribute->buffer()->data();
399 const QVector<float> positionBuffer = getAttributeData<float>( positionAttribute, positionBytes );
401 Qt3DRender::QAttribute *indexAttribute = tileGeometry->indexAttribute();
402 const QByteArray indexBytes = indexAttribute->buffer()->data();
403 const QVector<unsigned int> indexBuffer =
getIndexData( indexAttribute, indexBytes );
406 mObjects.push_back(
object );
408 object->setSmoothEdges( mSmoothEdges );
409 object->setupPositionCoordinates( positionBuffer,
scale, translation );
410 object->setupFaces( indexBuffer );
412 Qt3DRender::QAttribute *normalsAttributes = tileGeometry->normalAttribute();
413 if ( mExportNormals && normalsAttributes !=
nullptr )
415 const QByteArray normalsBytes = normalsAttributes->buffer()->data();
416 const QVector<float> normalsBuffer = getAttributeData<float>( normalsAttributes, normalsBytes );
417 object->setupNormalCoordinates( normalsBuffer );
420 Qt3DRender::QAttribute *texCoordsAttribute = tileGeometry->texCoordsAttribute();
421 if ( mExportTextures && texCoordsAttribute !=
nullptr )
423 const QByteArray texCoordsBytes = texCoordsAttribute->buffer()->data();
424 const QVector<float> texCoordsBuffer = getAttributeData<float>( texCoordsAttribute, texCoordsBytes );
425 object->setupTextureCoordinates( texCoordsBuffer );
427 QgsTerrainTextureImage *textureImage = tileEntity->textureImage();
428 const QImage img = textureImage->getImage();
429 object->setTextureImage( img );
433 void Qgs3DSceneExporter::parseMeshTile( QgsTerrainTileEntity *tileEntity,
const QString &layerName )
435 QString objectNamePrefix = layerName;
436 if ( objectNamePrefix != QString() ) objectNamePrefix += QStringLiteral(
"_" );
438 const QList<Qt3DRender::QGeometryRenderer *> renderers = tileEntity->findChildren<Qt3DRender::QGeometryRenderer *>();
439 for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
442 if ( obj ==
nullptr )
continue;
447 QVector<Qgs3DExportObject *> Qgs3DSceneExporter::processInstancedPointGeometry( Qt3DCore::QEntity *entity,
const QString &objectNamePrefix )
449 QVector<Qgs3DExportObject *> objects;
450 const QList<Qt3DRender::QGeometry *> geometriesList = entity->findChildren<Qt3DRender::QGeometry *>();
451 for ( Qt3DRender::QGeometry *geometry : geometriesList )
453 Qt3DRender::QAttribute *positionAttribute =
findAttribute( geometry, Qt3DRender::QAttribute::defaultPositionAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
454 Qt3DRender::QAttribute *indexAttribute =
nullptr;
455 for ( Qt3DRender::QAttribute *attribute : geometry->attributes() )
457 if ( attribute->attributeType() == Qt3DRender::QAttribute::IndexAttribute )
458 indexAttribute = attribute;
460 if ( positionAttribute ==
nullptr || indexAttribute ==
nullptr )
462 const QByteArray vertexBytes =
getData( positionAttribute->buffer() );
463 const QByteArray indexBytes =
getData( indexAttribute->buffer() );
464 const QVector<float> positionData = getAttributeData<float>( positionAttribute, vertexBytes );
465 const QVector<uint> indexData =
getIndexData( indexAttribute, indexBytes );
467 Qt3DRender::QAttribute *instanceDataAttribute =
findAttribute( geometry, QStringLiteral(
"pos" ), Qt3DRender::QAttribute::VertexAttribute );
468 const QByteArray instancePositionBytes =
getData( instanceDataAttribute->buffer() );
469 QVector<float> instancePosition = getAttributeData<float>( instanceDataAttribute, instancePositionBytes );
470 for (
int i = 0; i < instancePosition.size(); i += 3 )
473 objects.push_back(
object );
474 object->setupPositionCoordinates( positionData, 1.0f, QVector3D( instancePosition[i], instancePosition[i + 1], instancePosition[i + 2] ) );
475 object->setupFaces( indexData );
477 object->setSmoothEdges( mSmoothEdges );
479 Qt3DRender::QAttribute *normalsAttribute =
findAttribute( geometry, Qt3DRender::QAttribute::defaultNormalAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
480 if ( mExportNormals && normalsAttribute !=
nullptr )
483 const QVector<float> normalsData = getAttributeData<float>( normalsAttribute, vertexBytes );
484 object->setupNormalCoordinates( normalsData );
491 QVector<Qgs3DExportObject *> Qgs3DSceneExporter::processSceneLoaderGeometries( Qt3DRender::QSceneLoader *sceneLoader,
const QString &objectNamePrefix )
493 QVector<Qgs3DExportObject *> objects;
494 Qt3DCore::QEntity *sceneLoaderParent = qobject_cast<Qt3DCore::QEntity *>( sceneLoader->parent() );
495 Qt3DCore::QTransform *entityTransform = findTypedComponent<Qt3DCore::QTransform>( sceneLoaderParent );
496 float sceneScale = 1.0f;
497 QVector3D sceneTranslation( 0.0f, 0.0f, 0.0f );
498 if ( entityTransform !=
nullptr )
500 sceneScale = entityTransform->scale();
501 sceneTranslation = entityTransform->translation();
503 for (
const QString &entityName : sceneLoader->entityNames() )
505 Qt3DRender::QGeometryRenderer *mesh = qobject_cast<Qt3DRender::QGeometryRenderer *>( sceneLoader->component( entityName, Qt3DRender::QSceneLoader::GeometryRendererComponent ) );
506 Qgs3DExportObject *
object = processGeometryRenderer( mesh, objectNamePrefix, sceneScale, sceneTranslation );
507 if (
object ==
nullptr )
continue;
508 objects.push_back(
object );
513 Qgs3DExportObject *Qgs3DSceneExporter::processGeometryRenderer( Qt3DRender::QGeometryRenderer *mesh,
const QString &objectNamePrefix,
float sceneScale, QVector3D sceneTranslation )
516 if ( mesh->primitiveType() != Qt3DRender::QGeometryRenderer::Triangles )
return nullptr;
519 QVector3D translation( 0.0f, 0.0f, 0.0f );
520 QObject *parent = mesh->parent();
521 while ( parent !=
nullptr )
523 Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( parent );
524 Qt3DCore::QTransform *transform = findTypedComponent<Qt3DCore::QTransform>( entity );
525 if ( transform !=
nullptr )
527 scale *= transform->scale();
528 translation += transform->translation();
530 parent = parent->parent();
533 Qt3DRender::QGeometry *geometry = mesh->geometry();
535 Qt3DRender::QAttribute *positionAttribute =
findAttribute( geometry, Qt3DRender::QAttribute::defaultPositionAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
536 Qt3DRender::QAttribute *indexAttribute =
nullptr;
537 QByteArray indexBytes, vertexBytes;
538 QVector<uint> indexData;
539 QVector<float> positionData;
540 for ( Qt3DRender::QAttribute *attribute : geometry->attributes() )
542 if ( attribute->attributeType() == Qt3DRender::QAttribute::IndexAttribute )
543 indexAttribute = attribute;
546 if ( indexAttribute !=
nullptr )
548 indexBytes =
getData( indexAttribute->buffer() );
552 if ( positionAttribute !=
nullptr )
554 vertexBytes =
getData( positionAttribute->buffer() );
555 positionData = getAttributeData<float>( positionAttribute, vertexBytes );
559 if ( positionAttribute !=
nullptr && indexAttribute ==
nullptr )
561 for (
int i = 0; i < positionData.size() / 3; ++i )
562 indexData.push_back( i );
565 if ( positionAttribute ==
nullptr )
567 QgsDebugMsg(
"Geometry renderer with null data was being processed" );
572 object->setupPositionCoordinates( positionData,
scale * sceneScale, translation + sceneTranslation );
573 object->setupFaces( indexData );
575 Qt3DRender::QAttribute *normalsAttribute =
findAttribute( geometry, Qt3DRender::QAttribute::defaultNormalAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
576 if ( mExportNormals && normalsAttribute !=
nullptr )
579 const QVector<float> normalsData = getAttributeData<float>( normalsAttribute, vertexBytes );
580 object->setupNormalCoordinates( normalsData );
583 Qt3DRender::QAttribute *texCoordsAttribute =
findAttribute( geometry, Qt3DRender::QAttribute::defaultTextureCoordinateAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
584 if ( mExportTextures && texCoordsAttribute !=
nullptr )
587 const QVector<float> texCoordsData = getAttributeData<float>( texCoordsAttribute, vertexBytes );
588 object->setupTextureCoordinates( texCoordsData );
594 QVector<Qgs3DExportObject *> Qgs3DSceneExporter::processLines( Qt3DCore::QEntity *entity,
const QString &objectNamePrefix )
596 QVector<Qgs3DExportObject *> objs;
597 const QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
598 for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
600 if ( renderer->primitiveType() != Qt3DRender::QGeometryRenderer::LineStripAdjacency )
continue;
601 Qt3DRender::QGeometry *geom = renderer->geometry();
602 Qt3DRender::QAttribute *positionAttribute =
findAttribute( geom, Qt3DRender::QAttribute::defaultPositionAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
603 Qt3DRender::QAttribute *indexAttribute =
nullptr;
604 for ( Qt3DRender::QAttribute *attribute : geom->attributes() )
606 if ( attribute->attributeType() == Qt3DRender::QAttribute::IndexAttribute )
608 indexAttribute = attribute;
612 if ( positionAttribute ==
nullptr || indexAttribute ==
nullptr )
614 QgsDebugMsg(
"Position or index attribute was not found" );
618 const QByteArray vertexBytes =
getData( positionAttribute->buffer() );
619 const QByteArray indexBytes =
getData( indexAttribute->buffer() );
620 const QVector<float> positionData = getAttributeData<float>( positionAttribute, vertexBytes );
621 const QVector<uint> indexData =
getIndexData( indexAttribute, indexBytes );
628 objs.push_back( exportObject );
633 Qgs3DExportObject *Qgs3DSceneExporter::processPoints( Qt3DCore::QEntity *entity,
const QString &objectNamePrefix )
635 QVector<float> points;
636 const QList<Qt3DRender::QGeometryRenderer *> renderers = entity->findChildren<Qt3DRender::QGeometryRenderer *>();
637 for ( Qt3DRender::QGeometryRenderer *renderer : renderers )
639 Qt3DRender::QGeometry *geometry = qobject_cast<QgsBillboardGeometry *>( renderer->geometry() );
640 if ( geometry ==
nullptr )
642 Qt3DRender::QAttribute *positionAttribute =
findAttribute( geometry, Qt3DRender::QAttribute::defaultPositionAttributeName(), Qt3DRender::QAttribute::VertexAttribute );
643 const QByteArray positionBytes =
getData( positionAttribute->buffer() );
644 if ( positionBytes.size() == 0 )
646 const QVector<float> positions = getAttributeData<float>( positionAttribute, positionBytes );
657 const QString objFilePath = QDir( sceneFolderPath ).filePath( sceneName + QStringLiteral(
".obj" ) );
658 const QString mtlFilePath = QDir( sceneFolderPath ).filePath( sceneName + QStringLiteral(
".mtl" ) );
660 QFile file( objFilePath );
661 if ( !file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
663 QFile mtlFile( mtlFilePath );
664 if ( !mtlFile.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
667 float maxfloat = std::numeric_limits<float>::max(), minFloat = std::numeric_limits<float>::lowest();
668 float minX = maxfloat, minY = maxfloat, minZ = maxfloat, maxX = minFloat, maxY = minFloat, maxZ = minFloat;
671 float diffX = 1.0f, diffY = 1.0f, diffZ = 1.0f;
676 const float centerX = ( minX + maxX ) / 2.0f;
677 const float centerY = ( minY + maxY ) / 2.0f;
678 const float centerZ = ( minZ + maxZ ) / 2.0f;
680 const float scale = std::max( diffX, std::max( diffY, diffZ ) );
682 QTextStream out( &file );
684 const QString mtlLibName = sceneName +
".mtl";
685 out <<
"mtllib " << mtlLibName <<
"\n";
687 QTextStream mtlOut( &mtlFile );
690 if ( obj ==
nullptr )
continue;
692 const QString material = obj->
saveMaterial( mtlOut, sceneFolderPath );
693 out <<
"o " << obj->
name() <<
"\n";
694 if ( material != QString() )
695 out <<
"usemtl " << material <<
"\n";
696 obj->
saveTo( out,
scale / mScale, QVector3D( centerX, centerY, centerZ ) );
700 QString Qgs3DSceneExporter::getObjectName(
const QString &name )
703 if ( usedObjectNamesCounter.contains( name ) )
705 ret = QStringLiteral(
"%1%2" ).arg( name ).arg( usedObjectNamesCounter[name] );
706 usedObjectNamesCounter[name]++;
709 usedObjectNamesCounter[name] = 2;