Skip to content
Permalink
Browse files

Merge pull request #33837 from vcloarec/3D_back_simple

[Feature][Mesh][3D] new 3D mesh layer renderer
  • Loading branch information
wonder-sk committed Jan 16, 2020
2 parents a5c9b39 + 1b4de39 commit 5cb8997dc2ea01882ad3dee5b1570401f2e1b7f7
Showing with 2,632 additions and 334 deletions.
  1. +11 −0 src/3d/CMakeLists.txt
  2. +3 −0 src/3d/chunks/qgschunkedentity_p.cpp
  3. +108 −0 src/3d/mesh/qgsmesh3dentity_p.cpp
  4. +102 −0 src/3d/mesh/qgsmesh3dentity_p.h
  5. +324 −0 src/3d/mesh/qgsmesh3dgeometry_p.cpp
  6. +75 −0 src/3d/mesh/qgsmesh3dgeometry_p.h
  7. +196 −0 src/3d/mesh/qgsmesh3dmaterial_p.cpp
  8. +78 −0 src/3d/mesh/qgsmesh3dmaterial_p.h
  9. +180 −0 src/3d/mesh/qgsmeshterraingenerator.cpp
  10. +97 −0 src/3d/mesh/qgsmeshterraingenerator.h
  11. +8 −0 src/3d/qgs3dmapsettings.cpp
  12. +1 −0 src/3d/qgs3dmapsettings.h
  13. +22 −4 src/3d/qgsmeshlayer3drenderer.cpp
  14. +1 −1 src/3d/qgsmeshlayer3drenderer.h
  15. +3 −0 src/3d/shaders.qrc
  16. +204 −0 src/3d/shaders/mesh/mesh.frag
  17. +161 −0 src/3d/shaders/mesh/mesh.geom
  18. +26 −0 src/3d/shaders/mesh/mesh.vert
  19. +110 −1 src/3d/symbols/qgsmesh3dsymbol.cpp
  20. +138 −1 src/3d/symbols/qgsmesh3dsymbol.h
  21. +1 −0 src/3d/terrain/qgsdemterraintileloader_p.cpp
  22. +2 −0 src/3d/terrain/qgsterraingenerator.cpp
  23. +1 −0 src/3d/terrain/qgsterraingenerator.h
  24. +14 −6 src/3d/terrain/qgsterraintileloader_p.cpp
  25. +11 −0 src/3d/terrain/qgsterraintileloader_p.h
  26. +5 −1 src/app/3d/qgs3dmapcanvasdockwidget.h
  27. +131 −53 src/app/3d/qgs3dmapconfigwidget.cpp
  28. +2 −1 src/app/3d/qgs3dmapconfigwidget.h
  29. +1 −0 src/app/3d/qgsline3dsymbolwidget.cpp
  30. +131 −24 src/app/3d/qgsmesh3dsymbolwidget.cpp
  31. +22 −6 src/app/3d/qgsmesh3dsymbolwidget.h
  32. +7 −15 src/app/3d/qgsmeshlayer3drendererwidget.cpp
  33. +2 −2 src/app/3d/qgsmeshlayer3drendererwidget.h
  34. +1 −0 src/app/CMakeLists.txt
  35. +2 −0 src/app/qgisapp.cpp
  36. +53 −0 src/core/mesh/qgstriangularmesh.cpp
  37. +14 −0 src/core/mesh/qgstriangularmesh.h
  38. +128 −107 src/ui/3d/map3dconfigwidget.ui
  39. +0 −112 src/ui/3d/mesh3dsymbolwidget.ui
  40. +256 −0 src/ui/3d/qgsmesh3dpropswidget.ui
  41. BIN tests/testdata/control_images/3d/expected_mesh3d/default/expected_mesh3d.png
  42. BIN tests/testdata/control_images/3d/expected_mesh3d/fedora/expected_mesh3d.png
@@ -62,6 +62,12 @@ SET(QGIS_3D_SRCS
terrain/qgsterraintileloader_p.cpp
#terrain/quantizedmeshgeometry.cpp
#terrain/quantizedmeshterraingenerator.cpp

mesh/qgsmesh3dgeometry_p.cpp
mesh/qgsmesh3dentity_p.cpp
mesh/qgsmesh3dmaterial_p.cpp
mesh/qgsmeshterraingenerator.cpp

)

SET(QGIS_3D_HDRS
@@ -101,6 +107,7 @@ SET(QGIS_3D_HDRS
terrain/qgsterraintileloader_p.h
chunks/qgschunkloader_p.h
chunks/qgschunkqueuejob_p.h
mesh/qgsmeshterraingenerator.h
)

SET(QGIS_3D_PRIVATE_HDRS
@@ -122,6 +129,9 @@ SET(QGIS_3D_PRIVATE_HDRS
terrain/qgsterraintexturegenerator_p.h
terrain/qgsterraintextureimage_p.h
terrain/qgsterraintileentity_p.h
mesh/qgsmesh3dentity_p.h
mesh/qgsmesh3dgeometry_p.h
mesh/qgsmesh3dmaterial_p.h
)

QT5_ADD_RESOURCES(QGIS_3D_RCC_SRCS shaders.qrc)
@@ -131,6 +141,7 @@ QT5_ADD_RESOURCES(QGIS_3D_RCC_SRCS shaders.qrc)
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/chunks
${CMAKE_CURRENT_SOURCE_DIR}/mesh
${CMAKE_CURRENT_SOURCE_DIR}/symbols
${CMAKE_CURRENT_SOURCE_DIR}/terrain
${CMAKE_SOURCE_DIR}/src/core/
@@ -59,6 +59,9 @@ static float screenSpaceError( float epsilon, float distance, float screenSize,

static float screenSpaceError( QgsChunkNode *node, const QgsChunkedEntity::SceneState &state )
{
if ( node->error() <= 0 ) //it happens for meshes
return 0;

float dist = node->bbox().distanceFromPoint( state.cameraPos );

// TODO: what to do when distance == 0 ?
@@ -0,0 +1,108 @@
/***************************************************************************
qgsmesh3dentity.cpp
-------------------------
begin : january 2020
copyright : (C) 2020 by Vincent Cloarec
email : vcloarec at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmesh3dentity_p.h"

#include <Qt3DRender/QGeometryRenderer>

#include "qgsmeshlayer.h"
#include "qgsmapsettings.h"
#include "qgs3dmapsettings.h"
#include "qgsmeshlayerrenderer.h"
#include "qgsterraintextureimage_p.h"
#include "qgsmesh3dmaterial_p.h"


QgsMesh3dEntity::QgsMesh3dEntity( const Qgs3DMapSettings &map,
const QgsTriangularMesh triangularMesh,
const QgsRectangle &extent,
const QgsMesh3DSymbol &symbol ):
mExtent( extent ),
mSymbol( symbol ),
mMapSettings( map ),
mTriangularMesh( triangularMesh )
{}

void QgsMesh3dEntity::build()
{
buildGeometry();
applyMaterial();
}

void QgsMesh3dEntity::buildGeometry()
{
Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;
QVector<double> fakeScalarMag( mTriangularMesh.vertices().count() );
for ( int i = 0; i < mTriangularMesh.vertices().count(); ++i )
{
fakeScalarMag[i] = mTriangularMesh.vertices().at( i ).z();
}

mesh->setGeometry( new QgsMesh3dGeometry( mTriangularMesh,
mExtent,
mSymbol.verticaleScale(),
mesh ) );

addComponent( mesh );

Qt3DCore::QTransform *tform = new Qt3DCore::QTransform;
tform->setTranslation( QVector3D( float( -mMapSettings.origin().x() ), 0, float( mMapSettings.origin().y() ) ) );
addComponent( tform );
}

void QgsMesh3dEntity::applyMaterial()
{
mMaterial = new QgsMesh3dMaterial( mSymbol );
addComponent( mMaterial );
}

QgsMesh3dTerrainTileEntity::QgsMesh3dTerrainTileEntity( const Qgs3DMapSettings &map,
const QgsTriangularMesh triangularMesh,
const QgsRectangle &extent,
const QgsMesh3DSymbol &symbol,
QgsChunkNodeId nodeId,
Qt3DCore::QNode *parent ):
QgsTerrainTileEntity( nodeId, parent ),
mExtent( extent ),
mSymbol( symbol ),
mMapSettings( map ),
mTriangularMesh( triangularMesh )
{}

void QgsMesh3dTerrainTileEntity::build()
{
buildGeometry();
applyMaterial();
}

void QgsMesh3dTerrainTileEntity::buildGeometry()
{
Qt3DRender::QGeometryRenderer *mesh = new Qt3DRender::QGeometryRenderer;

mesh->setGeometry( new QgsMesh3dGeometry( mTriangularMesh, mExtent, mSymbol.verticaleScale(), mesh ) );
addComponent( mesh );

Qt3DCore::QTransform *tform = new Qt3DCore::QTransform;
tform->setTranslation( QVector3D( float( -mMapSettings.origin().x() ), 0, float( mMapSettings.origin().y() ) ) );
addComponent( tform );
}

void QgsMesh3dTerrainTileEntity::applyMaterial()
{
mMaterial = new QgsMesh3dMaterial( mSymbol );
addComponent( mMaterial );
}
@@ -0,0 +1,102 @@
/***************************************************************************
qgsmesh3dentity.h
-------------------------
begin : january 2020
copyright : (C) 2020 by Vincent Cloarec
email : vcloarec at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMESHENTITY_H
#define QGSMESHENTITY_H

#include <Qt3DCore/QEntity>

#include "mesh/qgsmesh3dgeometry_p.h"
#include "qgs3dmapsettings.h"
#include "qgsmesh3dsymbol.h"
#include "qgsterraintileentity_p.h"

///@cond PRIVATE

//
// W A R N I N G
// -------------
//
// This file is not part of the QGIS API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//

class Qgs3DMapSettings;
class QgsTessellatedPolygonGeometry;
class QgsMesh3DSymbol;

class QgsMeshLayer;
class QgsMesh3dMaterial;

//! Entity that handles rendering of mesh
class QgsMesh3dEntity: public Qt3DCore::QEntity
{
public:
//! Constructor
QgsMesh3dEntity( const Qgs3DMapSettings &map,
const QgsTriangularMesh triangularMesh,
const QgsRectangle &extent,
const QgsMesh3DSymbol &symbol );

//! Builds the geometry and the material
void build();

private:
virtual void buildGeometry();
virtual void applyMaterial();

QgsRectangle mExtent;
QgsMesh3DSymbol mSymbol;
Qgs3DMapSettings mMapSettings;
QgsTriangularMesh mTriangularMesh;
QgsMesh3dMaterial *mMaterial = nullptr;

static int mMesh3DEntityCount;
QString name;
};

//! Entity that handles rendering of terrain mesh
class QgsMesh3dTerrainTileEntity: public QgsTerrainTileEntity
{
public:
QgsMesh3dTerrainTileEntity( const Qgs3DMapSettings &map,
const QgsTriangularMesh triangularMesh,
const QgsRectangle &extent,
const QgsMesh3DSymbol &symbol,
QgsChunkNodeId nodeId,
Qt3DCore::QNode *parent = nullptr );

void build();

private:
virtual void buildGeometry();
virtual void applyMaterial();

QgsRectangle mExtent;
QgsMesh3DSymbol mSymbol;
Qgs3DMapSettings mMapSettings;
QgsTriangularMesh mTriangularMesh;
QgsMesh3dMaterial *mMaterial = nullptr;

static int mMesh3DEntityCount;
QString name;
};

///@endcond

#endif // QGSMESHENTITY_H

0 comments on commit 5cb8997

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