Skip to content
Permalink
Browse files

Export lines phong material

  • Loading branch information
NEDJIMAbelgacem committed Jul 12, 2020
1 parent 9fe793a commit 9db1e3fb6c513306aca45306a0406a993205e7fd
Showing with 46 additions and 12 deletions.
  1. +18 −9 src/3d/qgs3dexportobject.cpp
  2. +5 −0 src/3d/qgs3dexportobject.h
  3. +23 −3 src/3d/qgs3dsceneexporter.cpp
@@ -173,13 +173,22 @@ void Qgs3DExportObject::saveTo( QTextStream &out, float scale, const QVector3D &

QString Qgs3DExportObject::saveMaterial( QTextStream &mtlOut, const QString &folderPath )
{
QString textureName = mName + "_material";
if ( mTexturesUV.size() == 0 )
return QString();
QString filePath = QDir( folderPath ).filePath( textureName + ".jpg" );
mTextureImage.save( filePath, "JPG" );

mtlOut << "newmtl " << textureName << "\n";
mtlOut << "\tmap_Kd " << textureName << ".jpg" << "\n";
return textureName;
QString materialName = mName + "_material";
if ( mMaterialParameters.size() == 0 && ( mTexturesUV.size() == 0 || mTextureImage.isNull() ) ) return QString();
mtlOut << "newmtl " << materialName << "\n";
if ( mTexturesUV.size() != 0 && !mTextureImage.isNull() )
{
QString filePath = QDir( folderPath ).filePath( materialName + ".jpg" );
mTextureImage.save( filePath, "JPG" );
mtlOut << "\tmap_Kd " << materialName << ".jpg" << "\n";
}
else
{
for ( QString parameter : mMaterialParameters.keys() )
{
mtlOut << "\t" << parameter << " " << mMaterialParameters[parameter] << "\n";
}
mtlOut << "\tillum 2\n";
}
return materialName;
}
@@ -83,17 +83,22 @@ class Qgs3DExportObject : public QObject
*/
void objectBounds( float &minX, float &minY, float &minZ, float &maxX, float &maxY, float &maxZ );

//! Sets a material parameter to be exported in the .mtl file
void setMaterialParameter( const QString &parameter, const QString &value ) { mMaterialParameters[parameter] = value; }

//! Saves the current object to the output stream while scaling the object and centering it to be visible in exported scene
void saveTo( QTextStream &out, float scale, const QVector3D &center );
//! saves the texture of the object and material informations
QString saveMaterial( QTextStream &mtlOut, const QString &folder );

private:
QString mName;
QString mParentName;
QVector<float> mVertexPosition;
QVector<float> mNormals;
QVector<float> mTexturesUV;
QVector<unsigned int> mIndexes;
QMap<QString, QString> mMaterialParameters;

QImage mTextureImage;

@@ -61,6 +61,7 @@
#include "qgsvectorlayer3drenderer.h"
#include "qgspolygon3dsymbol.h"
#include "qgsline3dsymbol.h"
#include "qgspoint3dsymbol.h"

#include <numeric>

@@ -155,7 +156,7 @@ bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsV
const QgsLine3DSymbol *lineSymbol = dynamic_cast<const QgsLine3DSymbol *>( symbol );
if ( lineSymbol->renderAsSimpleLines() )
{

//TODO: handle simple line geometries in some way
}
else
{
@@ -167,7 +168,17 @@ bool Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity, QgsV
}
else if ( symbolType == "point" )
{

const QgsPoint3DSymbol *pointSymbol = dynamic_cast<const QgsPoint3DSymbol *>( symbol );
// TODO: handle point geometries somehow
if ( pointSymbol->shape() == QgsPoint3DSymbol::Model )
{
}
else if ( pointSymbol->shape() == QgsPoint3DSymbol::Billboard )
{
}
else
{
}
}
}
}
@@ -385,7 +396,16 @@ void Qgs3DSceneExporter::processBufferedLineGeometry( QgsTessellatedPolygonGeome
QVector<float> normalsData = getAttributeData<float>( normalsAttribute, normalsBytes );
object->setupNormalCoordinates( normalsData );
}
// TODO: handle material

QgsPhongMaterialSettings material = lineSymbol->material();
QColor diffuse = material.diffuse();
QColor specular = material.specular();
QColor ambient = material.ambient();
float shininess = material.shininess();
object->setMaterialParameter( QString( "Kd" ), QString( "%1 %2 %3" ).arg( diffuse.redF() ).arg( diffuse.greenF() ).arg( diffuse.blueF() ) );
object->setMaterialParameter( QString( "Ka" ), QString( "%1 %2 %3" ).arg( ambient.redF() ).arg( ambient.greenF() ).arg( ambient.blueF() ) );
object->setMaterialParameter( QString( "Ks" ), QString( "%1 %2 %3" ).arg( specular.redF() ).arg( specular.greenF() ).arg( specular.blueF() ) );
object->setMaterialParameter( QString( "Ns" ), QString( "%1" ).arg( shininess ) );
}

void Qgs3DSceneExporter::save( const QString &sceneName, const QString &sceneFolderPath )

0 comments on commit 9db1e3f

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