Skip to content
Permalink
Browse files

new 3D mesh renderer

  • Loading branch information
vcloarec committed Jan 15, 2020
1 parent 56bb8e9 commit 1c4a20f73c9f19fc75805cd0365ea8eb9db245d0
Showing with 2,774 additions and 334 deletions.
  1. +11 −0 src/3d/CMakeLists.txt
  2. +3 −0 src/3d/chunks/qgschunkedentity_p.cpp
  3. +125 −0 src/3d/mesh/qgsmesh3dentity_p.cpp
  4. +104 −0 src/3d/mesh/qgsmesh3dentity_p.h
  5. +421 −0 src/3d/mesh/qgsmesh3dgeometry_p.cpp
  6. +104 −0 src/3d/mesh/qgsmesh3dgeometry_p.h
  7. +198 −0 src/3d/mesh/qgsmesh3dmaterial_p.cpp
  8. +78 −0 src/3d/mesh/qgsmesh3dmaterial_p.h
  9. +161 −0 src/3d/mesh/qgsmeshterraingenerator.cpp
  10. +80 −0 src/3d/mesh/qgsmeshterraingenerator.h
  11. +5 −0 src/3d/qgs3dmapscene.cpp
  12. +3 −0 src/3d/qgs3dmapscene.h
  13. +17 −0 src/3d/qgs3dmapsettings.cpp
  14. +14 −0 src/3d/qgs3dmapsettings.h
  15. +22 −4 src/3d/qgsmeshlayer3drenderer.cpp
  16. +1 −1 src/3d/qgsmeshlayer3drenderer.h
  17. +3 −0 src/3d/shaders.qrc
  18. +204 −0 src/3d/shaders/mesh/mesh.frag
  19. +161 −0 src/3d/shaders/mesh/mesh.geom
  20. +26 −0 src/3d/shaders/mesh/mesh.vert
  21. +110 −1 src/3d/symbols/qgsmesh3dsymbol.cpp
  22. +138 −1 src/3d/symbols/qgsmesh3dsymbol.h
  23. +1 −0 src/3d/terrain/qgsdemterraintileloader_p.cpp
  24. +2 −0 src/3d/terrain/qgsterraingenerator.cpp
  25. +1 −0 src/3d/terrain/qgsterraingenerator.h
  26. +14 −6 src/3d/terrain/qgsterraintileloader_p.cpp
  27. +11 −0 src/3d/terrain/qgsterraintileloader_p.h
  28. +5 −1 src/app/3d/qgs3dmapcanvasdockwidget.h
  29. +132 −53 src/app/3d/qgs3dmapconfigwidget.cpp
  30. +2 −1 src/app/3d/qgs3dmapconfigwidget.h
  31. +1 −0 src/app/3d/qgsline3dsymbolwidget.cpp
  32. +131 −24 src/app/3d/qgsmesh3dsymbolwidget.cpp
  33. +22 −6 src/app/3d/qgsmesh3dsymbolwidget.h
  34. +7 −15 src/app/3d/qgsmeshlayer3drendererwidget.cpp
  35. +2 −2 src/app/3d/qgsmeshlayer3drendererwidget.h
  36. +1 −0 src/app/CMakeLists.txt
  37. +2 −0 src/app/qgisapp.cpp
  38. +53 −0 src/core/mesh/qgstriangularmesh.cpp
  39. +14 −0 src/core/mesh/qgstriangularmesh.h
  40. +128 −107 src/ui/3d/map3dconfigwidget.ui
  41. +0 −112 src/ui/3d/mesh3dsymbolwidget.ui
  42. +256 −0 src/ui/3d/qgsmesh3dpropswidget.ui
  43. BIN tests/testdata/control_images/3d/expected_mesh3d/default/expected_mesh3d.png
  44. BIN tests/testdata/control_images/3d/expected_mesh3d/fedora/expected_mesh3d.png
@@ -59,6 +59,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
@@ -97,6 +103,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
@@ -116,6 +123,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)
@@ -125,6 +135,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/
@@ -56,6 +56,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,125 @@
/***************************************************************************
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 <QOpenGLContext>
#include <qopenglfunctions_3_2_core.h>

#include <Qt3DRender/QTexture>
#include <Qt3DRender/QParameter>
#include <Qt3DExtras/QTextureMaterial>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DExtras/QMetalRoughMaterial>

#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();
}

#if 0
mesh->setGeometry( new QgsMesh3dGeometry_p( mTriangularMesh,
mExtent,
mSymbol.verticaleScale(),
mesh ) );
#else

mesh->setGeometry( new QgsMesh3dDatasetGeometry( mTriangularMesh,
fakeScalarMag,
fakeScalarMag,
mExtent,
mSymbol.verticaleScale(),
mesh ) );
#endif

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( QgsMesh3dMaterial::ScalarDataSet, 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( QgsMesh3dMaterial::ZValue, mSymbol );
addComponent( mMaterial );
}
@@ -0,0 +1,104 @@
/***************************************************************************
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 <Qt3DRender/QGeometryRenderer>
#include <Qt3DRender/QTexture>

#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 1c4a20f

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