Skip to content
Permalink
Browse files

CMakeLists cleanup

Deleted .bom files
Qgs3DMapCanvasDockWidget::exportScene cleanup
Deleted unused functions and variables
Fixed typo
  • Loading branch information
NEDJIMAbelgacem committed Jul 10, 2020
1 parent ed035b9 commit fcdd64dc0ed8eba85d22ee2007b22284480e7bc2
@@ -70,6 +70,7 @@ SET(QGIS_3D_SRCS
mesh/qgsmeshterraingenerator.cpp
qgs3dsceneexporter.cpp
qgs3dexportobject.cpp
qgs3dmapexportsettings.cpp
)

SET(QGIS_3D_HDRS
@@ -112,8 +113,6 @@ SET(QGIS_3D_HDRS
chunks/qgschunkqueuejob_p.h
mesh/qgsmeshterraingenerator.h
qgs3dsceneexporter.h
qgs3dmapexportsettings.cpp

)

SET(QGIS_3D_PRIVATE_HDRS
@@ -34,7 +34,7 @@ void Qgs3DExportObject::setupPositionCoordinates( const QVector<float> &position
{
for ( int j = 0; j < 3; ++j )
{
mVertxPosition << positionsBuffer[i + j] * scale + translation[j];
mVertexPosition << positionsBuffer[i + j] * scale + translation[j];
}
}

@@ -51,15 +51,17 @@ void Qgs3DExportObject::setupPositionCoordinates( const QVector<float> &position
{
for ( int j = 0; j < 3; ++j )
{
mVertxPosition << positionsBuffer[i + j] * scale + translation[j];
mVertexPosition << positionsBuffer[i + j] * scale + translation[j];
}
}

for ( int i = 0; i < faceIndex.size(); i += 3 )
{
// skip invalid triangles
if ( faceIndex[i] == faceIndex[i + 1] && faceIndex[i + 1] == faceIndex[i + 2] ) continue;
for ( int j = 0; j < 3; ++j ) mIndexes << faceIndex[i + j] + 1;
if ( faceIndex[i] == faceIndex[i + 1] && faceIndex[i + 1] == faceIndex[i + 2] )
continue;
for ( int j = 0; j < 3; ++j )
mIndexes << faceIndex[i + j] + 1;
}
}

@@ -78,12 +80,12 @@ void Qgs3DExportObject::objectBounds( float &minX, float &minY, float &minZ, flo
for ( unsigned int vertice : mIndexes )
{
int heightIndex = ( vertice - 1 ) * 3 + 1;
minX = std::min( minX, mVertxPosition[heightIndex - 1] );
maxX = std::max( maxX, mVertxPosition[heightIndex - 1] );
minY = std::min( minY, mVertxPosition[heightIndex] );
maxY = std::max( maxY, mVertxPosition[heightIndex] );
minZ = std::min( minZ, mVertxPosition[heightIndex + 1] );
maxZ = std::max( maxZ, mVertxPosition[heightIndex + 1] );
minX = std::min( minX, mVertexPosition[heightIndex - 1] );
maxX = std::max( maxX, mVertexPosition[heightIndex - 1] );
minY = std::min( minY, mVertexPosition[heightIndex] );
maxY = std::max( maxY, mVertexPosition[heightIndex] );
minZ = std::min( minZ, mVertexPosition[heightIndex + 1] );
maxZ = std::max( maxZ, mVertexPosition[heightIndex + 1] );
}
}

@@ -93,17 +95,19 @@ void Qgs3DExportObject::saveTo( QTextStream &out, float scale, const QVector3D &
// turns out grouping doest work as expected in blender

// smoothen edges
if ( mSmoothEdges ) out << "s on\n";
else out << "s off\n";
if ( mSmoothEdges )
out << "s on\n";
else
out << "s off\n";

// Construct vertices
for ( int i = 0; i < mVertxPosition.size(); i += 3 )
for ( int i = 0; i < mVertexPosition.size(); i += 3 )
{
// for now just ignore wrong vertex positions
out << "v ";
out << ( mVertxPosition[i] - center.x() ) / scale << " ";
out << ( mVertxPosition[i + 1] - center.y() ) / scale << " ";
out << ( mVertxPosition[i + 2] - center.z() ) / scale << "\n";
out << ( mVertexPosition[i] - center.x() ) / scale << " ";
out << ( mVertexPosition[i + 1] - center.y() ) / scale << " ";
out << ( mVertexPosition[i + 2] - center.z() ) / scale << "\n";
if ( i + 3 <= mNormals.size() )
{
out << "vn " << mNormals[i] << " " << mNormals[i + 1] << " " << mNormals[i + 2] << "\n";
@@ -116,29 +120,33 @@ void Qgs3DExportObject::saveTo( QTextStream &out, float scale, const QVector3D &
}
}

bool hasTextures = mTexturesUV.size() == mVertxPosition.size() / 3 * 2;
bool hasTextures = mTexturesUV.size() == mVertexPosition.size() / 3 * 2;
// if the object has normals then the normals and positions buffers should be the same size
bool hasNormals = mNormals.size() == mVertxPosition.size();
bool hasNormals = mNormals.size() == mVertexPosition.size();

if ( !hasNormals && !mNormals.empty() )
{
qDebug() << "WARNING: vertex normals count and vertex positions count are different";
}
int verticesCount = mVertxPosition.size() / 3;
int verticesCount = mVertexPosition.size() / 3;

auto getVertexIndex = [&]( int i ) -> QString
{
int negativeIndex = -1 - ( verticesCount - i );
if ( hasNormals && !hasTextures ) return QString( "%1//%2" ).arg( negativeIndex ).arg( negativeIndex );
if ( !hasNormals && hasTextures ) return QString( "%1/%2" ).arg( negativeIndex ).arg( negativeIndex );
if ( hasNormals && hasTextures ) return QString( "%1/%2/%3" ).arg( negativeIndex ).arg( negativeIndex ).arg( negativeIndex );
if ( hasNormals && !hasTextures )
return QString( "%1//%2" ).arg( negativeIndex ).arg( negativeIndex );
if ( !hasNormals && hasTextures )
return QString( "%1/%2" ).arg( negativeIndex ).arg( negativeIndex );
if ( hasNormals && hasTextures )
return QString( "%1/%2/%3" ).arg( negativeIndex ).arg( negativeIndex ).arg( negativeIndex );
return QString( "%1" ).arg( negativeIndex );
};

// Construct faces
for ( int i = 0; i < mIndexes.size(); i += 3 )
{
if ( mIndexes[i] == mIndexes[i + 1] && mIndexes[i + 1] == mIndexes[i + 2] ) continue;
if ( mIndexes[i] == mIndexes[i + 1] && mIndexes[i + 1] == mIndexes[i + 2] )
continue;
out << "f " << getVertexIndex( mIndexes[i] );
out << " " << getVertexIndex( mIndexes[i + 1] );
out << " " << getVertexIndex( mIndexes[i + 2] );
@@ -149,7 +157,8 @@ 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();
if ( mTexturesUV.size() == 0 )
return QString();
QString filePath = QDir( folderPath ).filePath( textureName + ".jpg" );
mTextureImage.save( filePath, "JPG" );

@@ -83,7 +83,7 @@ class Qgs3DExportObject : public QObject
private:
QString mName;
QString mParentName;
QVector<float> mVertxPosition;
QVector<float> mVertexPosition;
QVector<float> mNormals;
QVector<float> mTexturesUV;
QVector<unsigned int> mIndexes;

This file was deleted.

@@ -82,8 +82,7 @@ QVector<T> getAttributeData( Qt3DRender::QAttribute *attribute, QByteArray data
return result;
}

template<>
QVector<unsigned int> getAttributeData<unsigned int>( Qt3DRender::QAttribute *attribute, QByteArray data )
QVector<unsigned int> getIndexData( QByteArray data )
{
QVector<unsigned int> result;
for ( int i = 0; i < data.size(); i += sizeof( unsigned int ) )
@@ -207,6 +206,8 @@ QVector<unsigned int> createPlaneIndexData( const QSize &resolution )
return indexes;
}



Qgs3DSceneExporter::Qgs3DSceneExporter( Qt3DCore::QNode *parent )
: Qt3DCore::QEntity( parent )
, mSmoothEdges( false )
@@ -221,12 +222,14 @@ Qgs3DSceneExporter::Qgs3DSceneExporter( Qt3DCore::QNode *parent )

void Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity )
{
if ( entity == nullptr ) return;
if ( entity == nullptr )
return;
// We iterate over every component and find components that represent a tessellated geometry
for ( Qt3DCore::QComponent *c : entity->components() )
{
Qt3DRender::QGeometryRenderer *comp = qobject_cast<Qt3DRender::QGeometryRenderer *>( c );
if ( comp == nullptr ) continue;
if ( comp == nullptr )
continue;
Qt3DRender::QGeometry *geom = comp->geometry();

QgsTessellatedPolygonGeometry *tessellated = qobject_cast<QgsTessellatedPolygonGeometry *>( geom );
@@ -242,7 +245,8 @@ void Qgs3DSceneExporter::parseVectorLayerEntity( Qt3DCore::QEntity *entity )
for ( QObject *child : entity->children() )
{
Qt3DCore::QEntity *childEntity = qobject_cast<Qt3DCore::QEntity *>( child );
if ( childEntity != nullptr ) parseVectorLayerEntity( childEntity );
if ( childEntity != nullptr )
parseVectorLayerEntity( childEntity );
}
}

@@ -308,7 +312,8 @@ QgsTerrainTileEntity *Qgs3DSceneExporter::getFlatTerrainEntity( QgsTerrainEntity
QgsFlatTerrainGenerator *generator = dynamic_cast<QgsFlatTerrainGenerator *>( terrain->map3D().terrainGenerator() );
QgsChunkLoader *loader = generator->createSynchronousChunkLoader( node );
FlatTerrainChunkLoader *flatTerrainLoader = qobject_cast<FlatTerrainChunkLoader *>( loader );
if ( flatTerrainLoader == nullptr ) return nullptr;
if ( flatTerrainLoader == nullptr )
return nullptr;
// the entity we created should be deallocated when we deallocate the scene exporter
Qt3DCore::QEntity *entity = flatTerrainLoader->createEntity( this );
QgsTerrainTileEntity *tileEntity = qobject_cast<QgsTerrainTileEntity *>( entity );
@@ -330,24 +335,22 @@ QgsTerrainTileEntity *Qgs3DSceneExporter::getDemTerrainEntity( QgsTerrainEntity
return tileEntity;
}

void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity, QgsTerrainTextureGenerator *textureGenerator )
template<typename Component>
Component *findTypedComponent( Qt3DCore::QEntity *entity )
{
Qt3DRender::QGeometryRenderer *mesh = nullptr;
Qt3DCore::QTransform *transform = nullptr;
for ( Qt3DCore::QComponent *component : tileEntity->components() )
for ( Qt3DCore::QComponent *component : entity->components() )
{
Qt3DRender::QGeometryRenderer *meshTyped = qobject_cast<Qt3DRender::QGeometryRenderer *>( component );
if ( meshTyped != nullptr )
{
mesh = meshTyped;
continue;
}
Qt3DCore::QTransform *transformTyped = qobject_cast<Qt3DCore::QTransform *>( component );
if ( transformTyped != nullptr )
{
transform = transformTyped;
}
Component *typedComponent = qobject_cast<Component *>( component );
if ( typedComponent != nullptr )
return typedComponent;
}
return nullptr;
}

void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity, QgsTerrainTextureGenerator *textureGenerator )
{
Qt3DRender::QGeometryRenderer *mesh = findTypedComponent<Qt3DRender::QGeometryRenderer>( tileEntity );
Qt3DCore::QTransform *transform = findTypedComponent<Qt3DCore::QTransform>( tileEntity );

Qt3DRender::QGeometry *geometry = mesh->geometry();
Qt3DExtras::QPlaneGeometry *tileGeometry = qobject_cast<Qt3DExtras::QPlaneGeometry *>( geometry );
@@ -357,6 +360,15 @@ void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity, QgsTer
return;
}

tileGeometry->updateVertices();
tileGeometry->updateIndices();

Qt3DRender::QAttribute *positionAttribute = tileGeometry->positionAttribute();
Qt3DRender::QAttribute *indexAttribute = tileGeometry->indexAttribute();

qDebug() << "Position attribute data size: " << positionAttribute->buffer()->data().size();
qDebug() << "Index attribute data size: " << indexAttribute->buffer()->data().size();

float scale = transform->scale();
QVector3D translation = transform->translation();

@@ -388,22 +400,8 @@ void Qgs3DSceneExporter::parseFlatTile( QgsTerrainTileEntity *tileEntity, QgsTer

void Qgs3DSceneExporter::parseDemTile( QgsTerrainTileEntity *tileEntity, QgsTerrainTextureGenerator *textureGenerator )
{
Qt3DRender::QGeometryRenderer *mesh = nullptr;
Qt3DCore::QTransform *transform = nullptr;
for ( Qt3DCore::QComponent *component : tileEntity->components() )
{
Qt3DRender::QGeometryRenderer *meshTyped = qobject_cast<Qt3DRender::QGeometryRenderer *>( component );
if ( meshTyped != nullptr )
{
mesh = meshTyped;
continue;
}
Qt3DCore::QTransform *transformTyped = qobject_cast<Qt3DCore::QTransform *>( component );
if ( transformTyped != nullptr )
{
transform = transformTyped;
}
}
Qt3DRender::QGeometryRenderer *mesh = findTypedComponent<Qt3DRender::QGeometryRenderer>( tileEntity );
Qt3DCore::QTransform *transform = findTypedComponent<Qt3DCore::QTransform>( tileEntity );

Qt3DRender::QGeometry *geometry = mesh->geometry();
DemTerrainTileGeometry *tileGeometry = qobject_cast<DemTerrainTileGeometry *>( geometry );
@@ -422,7 +420,7 @@ void Qgs3DSceneExporter::parseDemTile( QgsTerrainTileEntity *tileEntity, QgsTerr

Qt3DRender::QAttribute *indexAttribute = tileGeometry->indexAttribute();
QByteArray indexBytes = indexAttribute->buffer()->data();
QVector<unsigned int> indexBuffer = getAttributeData<unsigned int>( indexAttribute, indexBytes );
QVector<unsigned int> indexBuffer = getIndexData( indexBytes );

Qgs3DExportObject *object = new Qgs3DExportObject( getObjectName( "DEM_tile" ), "", this );
mObjects.push_back( object );

0 comments on commit fcdd64d

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