Skip to content
Permalink
Browse files

Added scale parameter

  • Loading branch information
NEDJIMAbelgacem committed Jul 8, 2020
1 parent 00cbe5d commit 82786932b92f3a98410cb9e2b18b3920bcecbc63
@@ -49,6 +49,8 @@ class _3D_EXPORT Qgs3DMapExportSettings : public QObject
bool exportTextures() const { return mExportTextures; }
//! Returns the terrain texture resolution
int terrainTextureResolution() const { return mTerrainTextureResolution; }
//! Returns the scale of the exported model
float scale() const { return mScale; }

//! Sets the scene name
void setSceneName( const QString &sceneName ) { mSceneName = sceneName; }
@@ -64,6 +66,8 @@ class _3D_EXPORT Qgs3DMapExportSettings : public QObject
void setExportTextures( bool exportTextures ) { mExportTextures = exportTextures; }
//! Sets the terrain texture resolution
void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
//! Sets the scale of exported model
void setScale( float scale ) { mScale = scale; }

private:
QString mSceneName = QString( "Scene" );
@@ -73,6 +77,7 @@ class _3D_EXPORT Qgs3DMapExportSettings : public QObject
bool mExportNormals = true;
bool mExportTextures = false;
int mTerrainTextureResolution = 512;
float mScale = 1.0f;
};

#endif // QGS3DMAPEXPORTSETTINGS_H
@@ -776,6 +776,7 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
exporter.setExportNormals( exportSettings.exportNormals() );
exporter.setExportTextures( exportSettings.exportTextures() );
exporter.setTerrainTextureResolution( exportSettings.terrainTextureResolution() );
exporter.setScale( exportSettings.scale() );

for ( QgsMapLayer *layer : mLayerEntities.keys() )
{
@@ -211,6 +211,7 @@ Qgs3DSceneExporter::Qgs3DSceneExporter( Qt3DCore::QNode *parent )
, mExportNormals( true )
, mExportTextures( false )
, mTerrainTextureResolution( 512 )
, mScale( 1.0f )
{

}
@@ -505,7 +506,7 @@ void Qgs3DSceneExporter::save( const QString &sceneName, const QString &sceneFol
out << "o " << obj->name() << "\n";
if ( material != QString() )
out << "usemtl " << material << "\n";
obj->saveTo( out, scale, QVector3D( centerX, centerY, centerZ ) );
obj->saveTo( out, scale / mScale, QVector3D( centerX, centerY, centerZ ) );
}
}

@@ -70,15 +70,19 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
//! Returns whether the textures will be exported
bool exportTextures() const { return mExportTextures; }

//! Sets the terrian resolution
//! Sets the terrain resolution
void setTerrainResolution( int resolution ) { mTerrainResolution = resolution; }
//! Returns the terrain resolution
int terrainResolution() const { return mTerrainResolution; }

//! Sets the terrian texture resolution
//! Sets the terrain texture resolution
void setTerrainTextureResolution( int resolution ) { mTerrainTextureResolution = resolution; }
//! Returns the terrain resolution
int terrainTextureResolution() const { return mTerrainTextureResolution; }
//! Sets the scale of the exported 3D model
void setScale( float scale ) { mScale = scale; }
//! Returns the scale of the exported 3D model
float scale() const { return mScale; }

private:
//! Processes the attribute directly by taking a position buffer and converting it to Qgs3DExportObject
@@ -106,6 +110,7 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
bool mExportNormals;
bool mExportTextures;
int mTerrainTextureResolution;
float mScale;
};

#endif // QGS3DSCENEEXPORTER_H
@@ -50,6 +50,7 @@ QgsMap3DExportWidget::QgsMap3DExportWidget( Qgs3DMapScene *scene, Qgs3DMapExport
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(); } );
connect( ui->scaleSpinBox, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), [ = ]( int ) { settingsChanged(); } );

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

void QgsMap3DExportWidget::exportScene()
@@ -13,7 +13,20 @@
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0" colspan="3">
<item row="3" column="1" colspan="2">
<widget class="QSpinBox" name="terrainTextureResolutionSpinBox">
<property name="minimum">
<number>16</number>
</property>
<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="smoothEdgesCheckBox">
<property name="text">
<string>Smooth Edges</string>
@@ -27,6 +40,13 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Terrain texture resolution</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="sceneNameLabel">
<property name="text">
@@ -37,7 +57,7 @@
<item row="1" column="1" colspan="2">
<widget class="QgsFileWidget" name="selectFolderWidget" native="true"/>
</item>
<item row="7" column="1">
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -50,7 +70,7 @@
</property>
</spacer>
</item>
<item row="6" column="0" colspan="3">
<item row="7" column="0" colspan="3">
<widget class="QCheckBox" name="exportTexturesCheckBox">
<property name="text">
<string>Export textures</string>
@@ -70,7 +90,7 @@
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<item row="6" column="0" colspan="3">
<widget class="QCheckBox" name="exportNormalsCheckBox">
<property name="text">
<string>Export Normals</string>
@@ -93,23 +113,23 @@
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="sceneNameLineEdit"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QSpinBox" name="terrainTextureResolutionSpinBox">
<item row="4" column="1" colspan="2">
<widget class="QDoubleSpinBox" name="scaleSpinBox">
<property name="minimum">
<number>16</number>
<double>0.100000000000000</double>
</property>
<property name="maximum">
<number>4096</number>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
<property name="value">
<number>512</number>
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Terrain texture resolution</string>
<string>Model scale</string>
</property>
</widget>
</item>

0 comments on commit 8278693

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