Code cleanup

This commit is contained in:
NEDJIMAbelgacem 2020-07-28 00:14:22 +01:00
parent daa532794b
commit 64f004bd3b
8 changed files with 29 additions and 38 deletions

View File

@ -42,7 +42,7 @@ void insertIndexData( QVector<uint> &vertexIndex, const QVector<T> &faceIndex )
}
}
void Qgs3DExportObject::setupPositionCoordinates( const QVector<float> &positionsBuffer, float scale, const QVector3D translation )
void Qgs3DExportObject::setupPositionCoordinates( const QVector<float> &positionsBuffer, float scale, const QVector3D &translation )
{
for ( int i = 0; i < positionsBuffer.size(); i += 3 )
{
@ -77,7 +77,10 @@ void Qgs3DExportObject::setupTextureCoordinates( const QVector<float> &texturesB
void Qgs3DExportObject::setupMaterial( QgsAbstractMaterialSettings *material )
{
QMap<QString, QString> parameters = material->toExportParameters();
for ( QString &key : parameters.keys() ) setMaterialParameter( key, parameters[key] );
for ( auto it = parameters.begin(); it != parameters.end(); ++it )
{
setMaterialParameter( it.key(), it.value() );
}
}
void Qgs3DExportObject::objectBounds( float &minX, float &minY, float &minZ, float &maxX, float &maxY, float &maxZ )
@ -190,7 +193,6 @@ QString Qgs3DExportObject::saveMaterial( QTextStream &mtlOut, const QString &fol
for ( QString key : mMaterialParameters.keys() )
{
mtlOut << "\t" << key << " " << mMaterialParameters[key] << "\n";
qDebug() << "\t" << key << " " << mMaterialParameters[key] << "\n";
}
mtlOut << "\tillum 2\n";
return materialName;

View File

@ -69,8 +69,8 @@ class Qgs3DExportObject : public QObject
//! Sets whether triangles edges will look smooth
void setSmoothEdges( bool smoothEdges ) { mSmoothEdges = smoothEdges; }
//! Sets positions coordinates from just one positions buffer (generates faces automatically) and does the translation and scaling
void setupPositionCoordinates( const QVector<float> &positionsBuffer, float scale = 1.0f, const QVector3D translation = QVector3D( 0, 0, 0 ) );
//! Sets positions coordinates and does the translation and scaling
void setupPositionCoordinates( const QVector<float> &positionsBuffer, float scale = 1.0f, const QVector3D &translation = QVector3D( 0, 0, 0 ) );
//! Sets the faces in facesIndexes to the faces in the object
void setupFaces( const QVector<uint> &facesIndexes );
//! sets line vertex indexes

View File

@ -24,7 +24,7 @@
/**
* \brief The Qgs3DMapExportSettings class
* Manages the various settings the user can choose from when exorting a 3D scene
* Manages the various settings the user can choose from when exporting a 3D scene
* \ingroup 3d
* \since QGIS 3.16
*/

View File

@ -873,10 +873,11 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
exporter.setTerrainTextureResolution( exportSettings.terrainTextureResolution() );
exporter.setScale( exportSettings.scale() );
for ( QgsMapLayer *layer : mLayerEntities.keys() )
for ( auto it = mLayerEntities.constBegin(); it != mLayerEntities.constEnd(); ++it )
{
QgsMapLayer *layer = it.key();
Qt3DCore::QEntity *rootEntity = it.value();
QgsMapLayerType layerType = layer->type();
Qt3DCore::QEntity *rootEntity = mLayerEntities[layer];
switch ( layerType )
{
case QgsMapLayerType::VectorLayer:
@ -889,10 +890,10 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
case QgsMapLayerType::PluginLayer:
notParsedLayers.push_back( layer->name() );
break;
case QgsMapLayerType::MeshLayer: //!< Added in 3.2
case QgsMapLayerType::MeshLayer:
notParsedLayers.push_back( layer->name() );
break;
case QgsMapLayerType::VectorTileLayer: //!< Added in 3.14
case QgsMapLayerType::VectorTileLayer:
notParsedLayers.push_back( layer->name() );
break;
}
@ -903,11 +904,11 @@ void Qgs3DMapScene::exportScene( const Qgs3DMapExportSettings &exportSettings )
exporter.save( exportSettings.sceneName(), exportSettings.sceneFolderPath() );
if ( notParsedLayers.size() != 0 )
if ( !notParsedLayers.empty() )
{
QString message = "The following layers were not exported: \n";
for ( QString layerName : notParsedLayers )
for ( const QString &layerName : notParsedLayers )
message += layerName + "\n";
QgsMessageOutput::showMessage( "3D exporter warning", message, QgsMessageOutput::MessageText );
QgsMessageOutput::showMessage( tr( "3D exporter warning" ), message, QgsMessageOutput::MessageText );
}
}

View File

@ -97,7 +97,7 @@ QVector<T> getAttributeData( Qt3DRender::QAttribute *attribute, QByteArray data
{
for ( unsigned int j = 0; j < vertexSize * sizeof( T ); j += sizeof( T ) )
{
// maybe a problem with indienness can happen?
// maybe a problem with endienness can happen?
T v;
char *vArr = ( char * )&v;
for ( unsigned int k = 0; k < sizeof( T ); ++k )
@ -163,18 +163,6 @@ QByteArray getData( Qt3DRender::QBuffer *buffer )
return bytes;
}
Qgs3DSceneExporter::Qgs3DSceneExporter( Qt3DCore::QNode *parent )
: Qt3DCore::QEntity( parent )
, mSmoothEdges( false )
, mTerrainResolution( 128 )
, mExportNormals( true )
, mExportTextures( false )
, mTerrainTextureResolution( 512 )
, mScale( 1.0f )
{
}
Qt3DRender::QAttribute *findAttribute( Qt3DRender::QGeometry *geometry, const QString &name, Qt3DRender::QAttribute::AttributeType type )
{
for ( Qt3DRender::QAttribute *attribute : geometry->attributes() )

View File

@ -51,7 +51,7 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
Q_OBJECT
public:
//! Constructor
Qgs3DSceneExporter( Qt3DCore::QNode *parent = nullptr );
Qgs3DSceneExporter( Qt3DCore::QNode *parent = nullptr ) : Qt3DCore::QEntity( parent ) { }
/**
* Creates necessary export objects from entity if it represents valid vector layer entity
@ -127,12 +127,12 @@ class Qgs3DSceneExporter : public Qt3DCore::QEntity
QMap<QString, int> usedObjectNamesCounter;
QVector<Qgs3DExportObject *> mObjects;
bool mSmoothEdges;
int mTerrainResolution;
bool mExportNormals;
bool mExportTextures;
int mTerrainTextureResolution;
float mScale;
bool mSmoothEdges = false;
int mTerrainResolution = 128;
bool mExportNormals = true;
bool mExportTextures = false;
int mTerrainTextureResolution = 512;
float mScale = 1.0f;
};
#endif // QGS3DSCENEEXPORTER_H

View File

@ -118,7 +118,7 @@ class _3D_EXPORT QgsAbstractMaterialSettings SIP_ABSTRACT
/**
* Returns the parameters to be exported to .mtl file
*/
virtual QMap<QString, QString> toExportParameters() const = 0 SIP_FACTORY;
virtual QMap<QString, QString> toExportParameters() const = 0;
/**
* Adds parameters from the material to a destination \a effect.

View File

@ -146,10 +146,10 @@ QgsLineMaterial *QgsPhongMaterialSettings::toLineMaterial( const QgsMaterialCont
QMap<QString, QString> QgsPhongMaterialSettings::toExportParameters() const
{
QMap<QString, QString> parameters;
parameters[ QString( "Kd" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mDiffuse.redF() ).arg( mDiffuse.greenF() ).arg( mDiffuse.blueF() );
parameters[ QString( "Ka" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
parameters[ QString( "Ks" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mSpecular.redF() ).arg( mSpecular.greenF() ).arg( mSpecular.blueF() );
parameters[ QString( "Ns" ) ] = QStringLiteral( "%1" ).arg( mShininess );
parameters[ QStringLiteral( "Kd" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mDiffuse.redF() ).arg( mDiffuse.greenF() ).arg( mDiffuse.blueF() );
parameters[ QStringLiteral( "Ka" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mAmbient.redF() ).arg( mAmbient.greenF() ).arg( mAmbient.blueF() );
parameters[ QStringLiteral( "Ks" ) ] = QStringLiteral( "%1 %2 %3" ).arg( mSpecular.redF() ).arg( mSpecular.greenF() ).arg( mSpecular.blueF() );
parameters[ QStringLiteral( "Ns" ) ] = QStringLiteral( "%1" ).arg( mShininess );
return parameters;
}