Skip to content
Permalink
Browse files

request change

  • Loading branch information
vcloarec committed Jan 16, 2020
1 parent 23de310 commit 1b4de39e360c562364bd5f2d3ecb115b079e97ad
@@ -17,14 +17,7 @@

#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 <Qt3DRender/QGeometryRenderer>

#include "qgsmeshlayer.h"
#include "qgsmapsettings.h"
@@ -59,20 +52,10 @@ void QgsMesh3dEntity::buildGeometry()
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,
mesh->setGeometry( new QgsMesh3dGeometry( mTriangularMesh,
mExtent,
mSymbol.verticaleScale(),
mesh ) );
#endif

addComponent( mesh );

@@ -19,8 +19,6 @@
#define QGSMESHENTITY_H

#include <Qt3DCore/QEntity>
#include <Qt3DRender/QGeometryRenderer>
#include <Qt3DRender/QTexture>

#include "mesh/qgsmesh3dgeometry_p.h"
#include "qgs3dmapsettings.h"
@@ -322,100 +322,3 @@ void QgsMesh3dGeometry::init()
addAttribute( mIndexAttribute );
}

QgsMesh3dDatasetGeometry::QgsMesh3dDatasetGeometry( const QgsTriangularMesh &mesh,
const QVector<double> &verticaleMagnitude,
const QVector<double> &scalarMagnitude,
const QgsRectangle &extent,
float verticaleScale,
Qt3DCore::QNode *parent ):
QGeometry( parent ),
mTriangularMesh( mesh ),
mVerticaleMagnitude( verticaleMagnitude ),
mScalarMagnitude( scalarMagnitude ),
mExtent( extent ),
mVertScale( verticaleScale )
{
init();
}

void QgsMesh3dDatasetGeometry::init()
{
mPositionAttribute = new QAttribute( this );
mNormalAttribute = new QAttribute( this );
mVertexScalarMagnitudeAttribute = new QAttribute( this );
mTexCoordAttribute = new QAttribute( this );
mIndexAttribute = new QAttribute( this );
mVertexBuffer = new Qt3DRender::QBuffer( Qt3DRender::QBuffer::VertexBuffer, this );
mIndexBuffer = new Qt3DRender::QBuffer( Qt3DRender::QBuffer::IndexBuffer, this );

const int stride = ( 3 /*position*/ +
2 /*texture*/ +
1 /*scalar magnitude*/ +
3 /*normale*/ ) * sizeof( float );

const uint nVerts = uint( mTriangularMesh.vertices().count() );


//define position attribute
mPositionAttribute->setName( QAttribute::defaultPositionAttributeName() );
mPositionAttribute->setVertexBaseType( QAttribute::Float );
mPositionAttribute->setVertexSize( 3 );
mPositionAttribute->setAttributeType( QAttribute::VertexAttribute );
mPositionAttribute->setBuffer( mVertexBuffer );
mPositionAttribute->setByteStride( stride );
mPositionAttribute->setCount( nVerts );

//define texture coordinate attribute
mTexCoordAttribute->setName( QAttribute::defaultTextureCoordinateAttributeName() );
mTexCoordAttribute->setVertexBaseType( QAttribute::Float );
mTexCoordAttribute->setVertexSize( 2 );
mTexCoordAttribute->setAttributeType( QAttribute::VertexAttribute );
mTexCoordAttribute->setBuffer( mVertexBuffer );
mTexCoordAttribute->setByteStride( stride );
mTexCoordAttribute->setByteOffset( 3 * sizeof( float ) );
mTexCoordAttribute->setCount( nVerts );

//define normale attribute
mNormalAttribute->setName( QAttribute::defaultNormalAttributeName() );
mNormalAttribute->setVertexBaseType( QAttribute::Float );
mNormalAttribute->setVertexSize( 3 );
mNormalAttribute->setAttributeType( QAttribute::VertexAttribute );
mNormalAttribute->setBuffer( mVertexBuffer );
mNormalAttribute->setByteStride( stride );
mNormalAttribute->setByteOffset( 5 * sizeof( float ) );
mNormalAttribute->setCount( nVerts );

//define scalar attribute
mVertexScalarMagnitudeAttribute->setName( QStringLiteral( "scalarMagnitude" ) );
mVertexScalarMagnitudeAttribute->setVertexBaseType( QAttribute::Float );
mVertexScalarMagnitudeAttribute->setVertexSize( 1 );
mVertexScalarMagnitudeAttribute->setAttributeType( QAttribute::VertexAttribute );
mVertexScalarMagnitudeAttribute->setBuffer( mVertexBuffer );
mVertexScalarMagnitudeAttribute->setByteStride( stride );
mVertexScalarMagnitudeAttribute->setByteOffset( 8 * sizeof( float ) );
mVertexScalarMagnitudeAttribute->setCount( nVerts );

//define triangle vertex indexes
mIndexAttribute->setAttributeType( QAttribute::IndexAttribute );
mIndexAttribute->setVertexBaseType( QAttribute::UnsignedInt );
mIndexAttribute->setBuffer( mIndexBuffer );

// Each primitive has 3 vertives
mIndexAttribute->setCount( uint( mTriangularMesh.triangles().count() ) * 3 );

//Data generator
mVertexBuffer->setData( MeshPlaneVertexDatasetBufferFunctor( mTriangularMesh,
mVerticaleMagnitude,
mScalarMagnitude,
mExtent,
mVertScale )() );

mIndexBuffer->setData( MeshPlaneIndexBufferFunctor( mTriangularMesh )() );

addAttribute( mPositionAttribute );
addAttribute( mVertexScalarMagnitudeAttribute );
addAttribute( mTexCoordAttribute );
addAttribute( mNormalAttribute );
addAttribute( mIndexAttribute );

}
@@ -69,35 +69,6 @@ class QgsMesh3dGeometry: public Qt3DRender::QGeometry

};

class QgsMesh3dDatasetGeometry : public Qt3DRender::QGeometry
{
public:
//! Constructs a mesh layer geometry from triangular mesh.
explicit QgsMesh3dDatasetGeometry( const QgsTriangularMesh &mesh,
const QVector<double> &verticaleMagnitude,
const QVector<double> &scalarMagnitude,
const QgsRectangle &extent,
float verticaleScale, QNode *parent );
private:
void init();

QgsTriangularMesh mTriangularMesh;
QVector<double> mVerticaleMagnitude;
QVector<double> mScalarMagnitude;
QgsRectangle mExtent;
float mVertScale;

Qt3DRender::QAttribute *mPositionAttribute = nullptr;
Qt3DRender::QAttribute *mNormalAttribute = nullptr;

//! attribute used to store the scalarMagnitude used to render color
Qt3DRender::QAttribute *mVertexScalarMagnitudeAttribute = nullptr;

Qt3DRender::QAttribute *mTexCoordAttribute = nullptr;
Qt3DRender::QAttribute *mIndexAttribute = nullptr;
Qt3DRender::QBuffer *mVertexBuffer = nullptr;
Qt3DRender::QBuffer *mIndexBuffer = nullptr;
};

///@endcond

@@ -189,7 +189,7 @@ void QgsMesh3dMaterial::configure()
mTechnique->addParameter( new Qt3DRender::QParameter( "colorRampCount", mSymbol.colorRampShader().colorRampItemList().count() ) );
int colorRampType = mSymbol.colorRampShader().colorRampType();
mTechnique->addParameter( new Qt3DRender::QParameter( "colorRampType", colorRampType ) );
QColor meshColor = mSymbol.uniqueMeshColor();
QColor meshColor = mSymbol.singleMeshColor();
mTechnique->addParameter( new Qt3DRender::QParameter( "meshColor", QVector4D( meshColor.redF(), meshColor.greenF(), meshColor.blueF(), 1.0f ) ) );
mTechnique->addParameter( new Qt3DRender::QParameter( "verticaleScale", float( mSymbol.verticaleScale() ) ) );
}
@@ -97,7 +97,6 @@ void QgsMeshTerrainGenerator::rootChunkHeightRange( float &hMin, float &hMax ) c
void QgsMeshTerrainGenerator::resolveReferences( const QgsProject &project )
{
mLayer = QgsMapLayerRef( project.mapLayer( mLayer.layerId ) );
mLayer = QgsMapLayerRef( project.mapLayer( mLayer.layerId ) );
}

void QgsMeshTerrainGenerator::setLayer( QgsMeshLayer *layer )
@@ -115,6 +114,9 @@ QgsTerrainGenerator *QgsMeshTerrainGenerator::clone() const
QgsMeshTerrainGenerator *cloned = new QgsMeshTerrainGenerator();
cloned->mLayer = mLayer;
cloned->mTerrainTilingScheme = QgsTilingScheme();
cloned->mCrs = mCrs;
cloned->mSymbol = mSymbol;
cloned->mTransformContext = mTransformContext;
return cloned;
}

@@ -532,12 +532,3 @@ void Qgs3DMapSettings::setFieldOfView( const float fieldOfView )
emit fieldOfViewChanged();
}

QgsMesh3DSymbol Qgs3DMapSettings::meshterrainSymbol() const
{
return mMeshterrainSymbol;
}

void Qgs3DMapSettings::setMeshterrainSymbol( const QgsMesh3DSymbol &meshterrainSymbol )
{
mMeshterrainSymbol = meshterrainSymbol;
}
@@ -356,18 +356,6 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
*/
double outputDpi() const { return mDpi; }

/**
* Returns the mesh symbol used to render mesh terrain
* \since QGIS 3.12
*/
QgsMesh3DSymbol meshterrainSymbol() const;

/**
* Sets the mesh symbol used to render mesh terrain
* \since QGIS 3.12
*/
void setMeshterrainSymbol( const QgsMesh3DSymbol &meshterrainSymbol );

signals:
//! Emitted when the background color has changed
void backgroundColorChanged();
@@ -459,7 +447,6 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
QgsPathResolver mPathResolver;
QgsMapThemeCollection *mMapThemes = nullptr; //!< Pointer to map themes (e.g. from the current project) to resolve map theme content from the name
double mDpi = 96; //!< Dot per inch value for the screen / painter
QgsMesh3DSymbol mMeshterrainSymbol;
};


@@ -50,7 +50,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co
elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() );
elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() );
elemAdvancedSettings.setAttribute( QStringLiteral( "texture-unique-color" ), QgsSymbolLayerUtils::encodeColor( mUniqueColor ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) );
elem.appendChild( elemAdvancedSettings );

QDomElement elemDDP = doc.createElement( QStringLiteral( "data-defined-properties" ) );
@@ -82,7 +82,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ) );
mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() );
mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() );
mUniqueColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-unique-color" ) ) );
mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) );

QDomElement elemDDP = elem.firstChildElement( QStringLiteral( "data-defined-properties" ) );
if ( !elemDDP.isNull() )
@@ -149,14 +149,14 @@ void QgsMesh3DSymbol::setColorRampShader( const QgsColorRampShader &colorRampSha
mColorRampShader = colorRampShader;
}

QColor QgsMesh3DSymbol::uniqueMeshColor() const
QColor QgsMesh3DSymbol::singleMeshColor() const
{
return mUniqueColor;
return mSingleColor;
}

void QgsMesh3DSymbol::setUniqueMeshColor( const QColor &color )
void QgsMesh3DSymbol::setSingleMeshColor( const QColor &color )
{
mUniqueColor = color;
mSingleColor = color;
}

QgsMesh3DSymbol::RenderingStyle QgsMesh3DSymbol::renderingStyle() const

0 comments on commit 1b4de39

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