Skip to content
Permalink
Browse files

Added terrain texture resolution spinbox

  • Loading branch information
NEDJIMAbelgacem committed Jul 8, 2020
1 parent 294c507 commit 2edd11c9528dcd26e2c54532865d33f288cf8637
@@ -47,6 +47,8 @@ class _3D_EXPORT Qgs3DMapExportSettings : public QObject
bool exportNormals() const { return mExportNormals; }
//! Returns whether textures will be exported
bool exportTextures() const { return mExportTextures; }
//! Returns the terrain texture resolution
int terrainTextureResolution() const { return mTerrainTextureResolution; }

//! Sets the scene name
void setSceneName( const QString &sceneName ) { mSceneName = sceneName; }
@@ -60,18 +62,17 @@ class _3D_EXPORT Qgs3DMapExportSettings : public QObject
void setExportNormals( bool exportNormals ) { mExportNormals = exportNormals; }
//! Sets whether textures will be exported
void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
//! Returns a path to a file that with the "name.extension" in the export folder
QString getFilePath( const QString &name, const QString &extension ) const
{
return QDir( mSceneFolderPath ).filePath( name + "." + extension );
}
//! Sets the terrain texture resolution
void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }

private:
QString mSceneName = QString( "Scene" );
QString mSceneFolderPath = QDir::homePath();
int mTerrainResolution = 128;
bool mSmoothEdges = false;
bool mExportNormals = true;
bool mExportTextures = false;
int mTerrainTextureResolution = 512;
};

#endif // QGS3DMAPEXPORTSETTINGS_H
@@ -775,13 +775,13 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
exporter.setSmoothEdges( exportSettings.smoothEdges() );
exporter.setExportNormals( exportSettings.exportNormals() );
exporter.setExportTextures( exportSettings.exportTextures() );
exporter.setTerrainTextureResolution( exportSettings.terrainTextureResolution() );

for ( QgsMapLayer *layer : mLayerEntities.keys() )
{
exporter.parseEntity( mLayerEntities[layer] );
}
exporter.parseEntity( mTerrain );

QString filePath = exportSettings.getFilePath( exportSettings.sceneName(), "obj" );
exporter.save( exportSettings.sceneName(), exportSettings.sceneFolderPath() );
}
@@ -59,11 +59,6 @@ QVector<T> getAttributeData( Qt3DRender::QAttribute *attribute )
uint bytesStride = attribute->byteStride();
uint vertexSize = attribute->vertexSize();

qDebug() << "bytesOffset: " << bytesOffset;
qDebug() << "bytesStride: " << bytesStride;
qDebug() << "VertexSize: " << vertexSize;
qDebug() << "Data size: " << data.size();

QVector<T> result;
for ( int i = bytesOffset; i < data.size(); i += bytesStride )
{
@@ -103,7 +98,6 @@ QVector<unsigned int> getAttributeData<unsigned int>( Qt3DRender::QAttribute *at
return result;
}


QVector<float> createPlaneVertexData( float w, float h, const QSize &resolution )
{
// Taken from Qt3D source with some modifications
@@ -241,9 +235,7 @@ void Qgs3DSceneExporter::parseEntity( Qt3DCore::QEntity *entity )
QgsTessellatedPolygonGeometry *tessellated = qobject_cast<QgsTessellatedPolygonGeometry *>( geom );
if ( tessellated != nullptr )
{
qDebug() << "Processing QgsTessellatedPolygonGeometry started";
process( tessellated );
qDebug() << "Processing QgsTessellatedPolygonGeometry ended";
continue;
}

@@ -291,27 +283,23 @@ void Qgs3DSceneExporter::parseEntity( QgsTerrainEntity *terrain )

QgsTerrainGenerator *generator = settings.terrainGenerator();
QgsTerrainTileEntity *terrainTile = nullptr;
QgsTerrainTextureGenerator *textureGenerator = terrain->textureGenerator();
QSize oldResolution = textureGenerator->textureSize();
textureGenerator->setTextureSize( QSize( mTerrainTextureResolution, mTerrainTextureResolution ) );
switch ( generator->type() )
{
case QgsTerrainGenerator::Dem:
for ( QgsChunkNode *node : leafs )
{
terrainTile = getDemTerrainEntity( terrain, node );
QgsTerrainTextureGenerator *textureGenerator = terrain->textureGenerator();
QSize oldResolution = textureGenerator->textureSize();
textureGenerator->setTextureSize( QSize( mTerrainTextureResolution, mTerrainTextureResolution ) );
this->parseDemTile( terrainTile, textureGenerator );
textureGenerator->setTextureSize( oldResolution );
}
break;
case QgsTerrainGenerator::Flat:
for ( QgsChunkNode *node : leafs )
{
terrainTile = getFlatTerrainEntity( terrain, node );
QgsTerrainTextureGenerator *textureGenerator = terrain->textureGenerator();
QSize oldResolution = textureGenerator->textureSize();
this->parseFlatTile( terrainTile, textureGenerator );
textureGenerator->setTextureSize( oldResolution );
}
break;
// TODO: implement other terrain types
@@ -320,6 +308,7 @@ void Qgs3DSceneExporter::parseEntity( QgsTerrainEntity *terrain )
case QgsTerrainGenerator::Online:
break;
}
textureGenerator->setTextureSize( oldResolution );
}

QgsTerrainTileEntity *Qgs3DSceneExporter::getFlatTerrainEntity( QgsTerrainEntity *terrain, QgsChunkNode *node )
@@ -397,10 +386,8 @@ void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity, QgsTer

if ( mExportTextures )
{
qDebug() << "Generating texCoords";
QVector<float> texCoords = createPlaneTexCoordsData( 1.0f, 1.0f, tileGeometry->resolution(), false );
object->setupTextureCoordinates( texCoords );
qDebug() << "Generated texCoords";

QImage img = textureGenerator->renderSynchronously( tileEntity->textureImage()->imageExtent(), tileEntity->textureImage()->imageDebugText() );
object->setTextureImage( img );
@@ -491,10 +478,10 @@ void Qgs3DSceneExporter::save( const QString &sceneName, const QString &sceneFol
float minX = maxfloat, minY = maxfloat, minZ = maxfloat, maxX = minFloat, maxY = minFloat, maxZ = minFloat;
for ( Qgs3DExportObject *obj : mObjects ) obj->objectBounds( minX, minY, minZ, maxX, maxY, maxZ );

float diffX = 1.0f, diffY = 1.0f, diffZ = 1.0f;
diffX = maxX - minX;
diffY = maxY - minY;
diffZ = maxZ - minZ;
// float diffX = 1.0f, diffY = 1.0f, diffZ = 1.0f;
// diffX = maxX - minX;
// diffY = maxY - minY;
// diffZ = maxZ - minZ;

float centerX = ( minX + maxX ) / 2.0f;
float centerY = ( minY + maxY ) / 2.0f;
@@ -57,6 +57,8 @@ class _3D_EXPORT QgsFlatTerrainGenerator : public QgsTerrainGenerator
QgsFlatTerrainGenerator() = default;

QgsChunkLoader *createChunkLoader( QgsChunkNode *node ) const override SIP_FACTORY;

//! create a chunk loader that loads synchronously
QgsChunkLoader *createSynchronousChunkLoader( QgsChunkNode *node ) const;

QgsTerrainGenerator *clone() const override SIP_FACTORY;
@@ -88,7 +88,6 @@ class QgsTerrainTextureGenerator : public QObject
QgsMapSettings baseMapSettings();

const Qgs3DMapSettings &mMap;
QSize mTextureSize;

struct JobData
{
@@ -101,6 +100,7 @@ class QgsTerrainTextureGenerator : public QObject

QHash<QgsMapRendererSequentialJob *, JobData> mJobs;
int mLastJobId;
QSize mTextureSize;
};

/// @endcond
@@ -49,6 +49,7 @@ QgsMap3DExportWidget::QgsMap3DExportWidget( Qgs3DMapScene *scene, Qgs3DMapExport
connect( ui->terrainResolutionSpinBox, qgis::overload<int>::of( &QSpinBox::valueChanged ), [ = ]( int ) { settingsChanged(); } );
connect( ui->exportNormalsCheckBox, &QCheckBox::stateChanged, [ = ]( int ) { settingsChanged(); } );
connect( ui->exportTexturesCheckBox, &QCheckBox::stateChanged, [ = ]( int ) { settingsChanged(); } );
connect( ui->terrainTextureResolutionSpinBox, qgis::overload<int>::of( &QSpinBox::valueChanged ), [ = ]( int ) { settingsChanged(); } );

// sets the export settings to whatever is on the scene
settingsChanged();
@@ -67,6 +68,7 @@ void QgsMap3DExportWidget::settingsChanged()
mExportSettings->setSmoothEdges( ui->smoothEdgesCheckBox->isChecked() );
mExportSettings->setExportNormals( ui->exportNormalsCheckBox->isChecked() );
mExportSettings->setExportTextures( ui->exportTexturesCheckBox->isChecked() );
mExportSettings->setTerrainTextureResolution( ui->terrainTextureResolutionSpinBox->value() );
}

void QgsMap3DExportWidget::exportScene()
@@ -13,30 +13,31 @@
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="label">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="smoothEdgesCheckBox">
<property name="text">
<string>Terrain resolution</string>
<string>Smooth Edges</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QgsFileWidget" name="selectFolderWidget" native="true"/>
</item>
<item row="2" column="1" colspan="2">
<widget class="QSpinBox" name="terrainResolutionSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4096</number>
<item row="1" column="0">
<widget class="QLabel" name="folderLAbel">
<property name="text">
<string>Folder</string>
</property>
<property name="value">
<number>1</number>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="sceneNameLabel">
<property name="text">
<string>Scene name</string>
</property>
</widget>
</item>
<item row="6" column="1">
<item row="1" column="1" colspan="2">
<widget class="QgsFileWidget" name="selectFolderWidget" native="true"/>
</item>
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -49,7 +50,27 @@
</property>
</spacer>
</item>
<item row="4" column="0" colspan="3">
<item row="6" column="0" colspan="3">
<widget class="QCheckBox" name="exportTexturesCheckBox">
<property name="text">
<string>Export textures</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QSpinBox" name="terrainResolutionSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>4096</number>
</property>
<property name="value">
<number>1</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="exportNormalsCheckBox">
<property name="text">
<string>Export Normals</string>
@@ -62,34 +83,33 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QCheckBox" name="smoothEdgesCheckBox">
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Smooth Edges</string>
<string>Terrain resolution</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="sceneNameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="folderLAbel">
<property name="text">
<string>Folder</string>
<item row="3" column="1" colspan="2">
<widget class="QSpinBox" name="terrainTextureResolutionSpinBox">
<property name="minimum">
<number>16</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="sceneNameLabel">
<property name="text">
<string>Scene name</string>
<property name="maximum">
<number>4096</number>
</property>
<property name="value">
<number>512</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="exportTexturesCheckBox">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Export textures</string>
<string>Terrain texture resolution</string>
</property>
</widget>
</item>

0 comments on commit 2edd11c

Please sign in to comment.
You can’t perform that action at this time.