Skip to content
Permalink
Browse files

3D symbols: private members + public getters/setters ... just like bi…

…g kids
  • Loading branch information
wonder-sk committed Aug 15, 2017
1 parent 870d96e commit fc28a97ee5b013d6e45577266b7d572445d2873b
@@ -22,10 +22,10 @@ Qt3DExtras::QPhongMaterial *LineEntity::material( const QgsLine3DSymbol &symbol
{
Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial;

material->setAmbient( symbol.material.ambient() );
material->setDiffuse( symbol.material.diffuse() );
material->setSpecular( symbol.material.specular() );
material->setShininess( symbol.material.shininess() );
material->setAmbient( symbol.material().ambient() );
material->setDiffuse( symbol.material().diffuse() );
material->setSpecular( symbol.material().specular() );
material->setShininess( symbol.material().shininess() );

return material;
}
@@ -102,12 +102,12 @@ Qt3DRender::QGeometryRenderer *LineEntityNode::renderer( const Map3D &map, const
QgsAbstractGeometry *g = geom.geometry();

QgsGeos engine( g );
QgsAbstractGeometry *buffered = engine.buffer( symbol.width / 2., nSegments, endCapStyle, joinStyle, mitreLimit ); // factory
QgsAbstractGeometry *buffered = engine.buffer( symbol.width() / 2., nSegments, endCapStyle, joinStyle, mitreLimit ); // factory

if ( QgsWkbTypes::flatType( buffered->wkbType() ) == QgsWkbTypes::Polygon )
{
QgsPolygonV2 *polyBuffered = static_cast<QgsPolygonV2 *>( buffered );
Utils::clampAltitudes( polyBuffered, symbol.altClamping, symbol.altBinding, symbol.height, map );
Utils::clampAltitudes( polyBuffered, symbol.altitudeClamping(), symbol.altitudeBinding(), symbol.height(), map );
polygons.append( polyBuffered );
}
else if ( QgsWkbTypes::flatType( buffered->wkbType() ) == QgsWkbTypes::MultiPolygon )
@@ -118,15 +118,15 @@ Qt3DRender::QGeometryRenderer *LineEntityNode::renderer( const Map3D &map, const
QgsAbstractGeometry *partBuffered = mpolyBuffered->geometryN( i );
Q_ASSERT( QgsWkbTypes::flatType( partBuffered->wkbType() ) == QgsWkbTypes::Polygon );
QgsPolygonV2 *polyBuffered = static_cast<QgsPolygonV2 *>( partBuffered )->clone(); // need to clone individual geometry parts
Utils::clampAltitudes( polyBuffered, symbol.altClamping, symbol.altBinding, symbol.height, map );
Utils::clampAltitudes( polyBuffered, symbol.altitudeClamping(), symbol.altitudeBinding(), symbol.height(), map );
polygons.append( polyBuffered );
}
delete buffered;
}
}

mGeometry = new PolygonGeometry;
mGeometry->setPolygons( polygons, origin, /*symbol.height,*/ symbol.extrusionHeight );
mGeometry->setPolygons( polygons, origin, symbol.extrusionHeight() );

Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer;
renderer->setGeometry( mGeometry );
@@ -37,7 +37,7 @@
PointEntity::PointEntity( const Map3D &map, QgsVectorLayer *layer, const QgsPoint3DSymbol &symbol, Qt3DCore::QNode *parent )
: Qt3DCore::QEntity( parent )
{
if ( symbol.shapeProperties["shape"].toString() == "model" )
if ( symbol.shapeProperties()["shape"].toString() == "model" )
{
Model3DPointEntityFactory::addEntitiesForSelectedPoints( map, layer, symbol, this );
Model3DPointEntityFactory::addEntitiesForNotSelectedPoints( map, layer, symbol, this );
@@ -80,12 +80,12 @@ Qt3DRender::QMaterial *InstancedPointEntityFactory::material( const QgsPoint3DSy
Qt3DRender::QParameter *specularParameter = new Qt3DRender::QParameter( QStringLiteral( "ks" ), QColor::fromRgbF( 0.01f, 0.01f, 0.01f, 1.0f ) );
Qt3DRender::QParameter *shininessParameter = new Qt3DRender::QParameter( QStringLiteral( "shininess" ), 150.0f );

diffuseParameter->setValue( symbol.material.diffuse() );
ambientParameter->setValue( symbol.material.ambient() );
specularParameter->setValue( symbol.material.specular() );
shininessParameter->setValue( symbol.material.shininess() );
diffuseParameter->setValue( symbol.material().diffuse() );
ambientParameter->setValue( symbol.material().ambient() );
specularParameter->setValue( symbol.material().specular() );
shininessParameter->setValue( symbol.material().shininess() );

QMatrix4x4 transformMatrix = symbol.transform;
QMatrix4x4 transformMatrix = symbol.transform();
QMatrix3x3 normalMatrix = transformMatrix.normalMatrix(); // transponed inverse of 3x3 sub-matrix

// QMatrix3x3 is not supported for passing to shaders, so we pass QMatrix4x4
@@ -198,19 +198,20 @@ Qt3DRender::QGeometryRenderer *InstancedPointEntityNode::renderer( const QgsPoin
instanceDataAttribute->setByteStride( 3 * sizeof( float ) );

Qt3DRender::QGeometry *geometry = nullptr;
QString shape = symbol.shapeProperties["shape"].toString();
QVariantMap shapeProperties = symbol.shapeProperties();
QString shape = shapeProperties["shape"].toString();
if ( shape == "sphere" )
{
float radius = symbol.shapeProperties["radius"].toFloat();
float radius = shapeProperties["radius"].toFloat();
Qt3DExtras::QSphereGeometry *g = new Qt3DExtras::QSphereGeometry;
g->setRadius( radius ? radius : 10 );
geometry = g;
}
else if ( shape == "cone" )
{
float length = symbol.shapeProperties["length"].toFloat();
float bottomRadius = symbol.shapeProperties["bottomRadius"].toFloat();
float topRadius = symbol.shapeProperties["topRadius"].toFloat();
float length = shapeProperties["length"].toFloat();
float bottomRadius = shapeProperties["bottomRadius"].toFloat();
float topRadius = shapeProperties["topRadius"].toFloat();
Qt3DExtras::QConeGeometry *g = new Qt3DExtras::QConeGeometry;
g->setLength( length ? length : 10 );
g->setBottomRadius( bottomRadius );
@@ -221,7 +222,7 @@ Qt3DRender::QGeometryRenderer *InstancedPointEntityNode::renderer( const QgsPoin
}
else if ( shape == "cube" )
{
float size = symbol.shapeProperties["size"].toFloat();
float size = shapeProperties["size"].toFloat();
Qt3DExtras::QCuboidGeometry *g = new Qt3DExtras::QCuboidGeometry;
g->setXExtent( size ? size : 10 );
g->setYExtent( size ? size : 10 );
@@ -230,16 +231,16 @@ Qt3DRender::QGeometryRenderer *InstancedPointEntityNode::renderer( const QgsPoin
}
else if ( shape == "torus" )
{
float radius = symbol.shapeProperties["radius"].toFloat();
float minorRadius = symbol.shapeProperties["minorRadius"].toFloat();
float radius = shapeProperties["radius"].toFloat();
float minorRadius = shapeProperties["minorRadius"].toFloat();
Qt3DExtras::QTorusGeometry *g = new Qt3DExtras::QTorusGeometry;
g->setRadius( radius ? radius : 10 );
g->setMinorRadius( minorRadius ? minorRadius : 5 );
geometry = g;
}
else if ( shape == "plane" )
{
float size = symbol.shapeProperties["size"].toFloat();
float size = shapeProperties["size"].toFloat();
Qt3DExtras::QPlaneGeometry *g = new Qt3DExtras::QPlaneGeometry;
g->setWidth( size ? size : 10 );
g->setHeight( size ? size : 10 );
@@ -248,8 +249,8 @@ Qt3DRender::QGeometryRenderer *InstancedPointEntityNode::renderer( const QgsPoin
#if QT_VERSION >= 0x050900
else if ( shape == "extrudedText" )
{
float depth = symbol.shapeProperties["depth"].toFloat();
QString text = symbol.shapeProperties["text"].toString();
float depth = shapeProperties["depth"].toFloat();
QString text = shapeProperties["text"].toString();
Qt3DExtras::QExtrudedTextGeometry *g = new Qt3DExtras::QExtrudedTextGeometry;
g->setDepth( depth ? depth : 1 );
g->setText( text );
@@ -258,8 +259,8 @@ Qt3DRender::QGeometryRenderer *InstancedPointEntityNode::renderer( const QgsPoin
#endif
else // shape == "cylinder" or anything else
{
float radius = symbol.shapeProperties["radius"].toFloat();
float length = symbol.shapeProperties["length"].toFloat();
float radius = shapeProperties["radius"].toFloat();
float length = shapeProperties["length"].toFloat();
Qt3DExtras::QCylinderGeometry *g = new Qt3DExtras::QCylinderGeometry;
//g->setRings(2); // how many vertices vertically
//g->setSlices(8); // how many vertices on circumference
@@ -284,10 +285,10 @@ static Qt3DExtras::QPhongMaterial *phongMaterial( const QgsPoint3DSymbol &symbol
{
Qt3DExtras::QPhongMaterial *phong = new Qt3DExtras::QPhongMaterial;

phong->setAmbient( symbol.material.ambient() );
phong->setDiffuse( symbol.material.diffuse() );
phong->setSpecular( symbol.material.specular() );
phong->setShininess( symbol.material.shininess() );
phong->setAmbient( symbol.material().ambient() );
phong->setDiffuse( symbol.material().diffuse() );
phong->setSpecular( symbol.material().specular() );
phong->setShininess( symbol.material().shininess() );

return phong;
}
@@ -312,7 +313,7 @@ void Model3DPointEntityFactory::addEntitiesForNotSelectedPoints( const Map3D &ma
notSelected.subtract( layer->selectedFeatureIds() );
req.setFilterFids( notSelected );

if ( symbol.shapeProperties["overwriteMaterial"].toBool() )
if ( symbol.shapeProperties()["overwriteMaterial"].toBool() )
{
addMeshEntities( map, layer, req, symbol, parent, false );
}
@@ -330,7 +331,7 @@ void Model3DPointEntityFactory::addSceneEntities( const Map3D &map, QgsVectorLay
// build the entity
Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;

QUrl url = QUrl::fromLocalFile( symbol.shapeProperties["model"].toString() );
QUrl url = QUrl::fromLocalFile( symbol.shapeProperties()["model"].toString() );
Qt3DRender::QSceneLoader *modelLoader = new Qt3DRender::QSceneLoader;
modelLoader->setSource( url );

@@ -358,7 +359,7 @@ void Model3DPointEntityFactory::addMeshEntities( const Map3D &map, QgsVectorLaye
// build the entity
Qt3DCore::QEntity *entity = new Qt3DCore::QEntity;

QUrl url = QUrl::fromLocalFile( symbol.shapeProperties["model"].toString() );
QUrl url = QUrl::fromLocalFile( symbol.shapeProperties()["model"].toString() );
Qt3DRender::QMesh *mesh = new Qt3DRender::QMesh;
mesh->setSource( url );

@@ -372,7 +373,7 @@ void Model3DPointEntityFactory::addMeshEntities( const Map3D &map, QgsVectorLaye
Qt3DCore::QTransform *Model3DPointEntityFactory::transform( const QVector3D &position, const QgsPoint3DSymbol &symbol )
{
Qt3DCore::QTransform *tr = new Qt3DCore::QTransform;
tr->setMatrix( symbol.transform );
tr->setMatrix( symbol.transform() );
tr->setTranslation( position + tr->translation() );
return tr;
}
@@ -72,10 +72,10 @@ void PolygonEntity::addEntityForNotSelectedPolygons( const Map3D &map, QgsVector
Qt3DExtras::QPhongMaterial *PolygonEntity::material( const QgsPolygon3DSymbol &symbol ) const
{
Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial;
material->setAmbient( symbol.material.ambient() );
material->setDiffuse( symbol.material.diffuse() );
material->setSpecular( symbol.material.specular() );
material->setShininess( symbol.material.shininess() );
material->setAmbient( symbol.material().ambient() );
material->setDiffuse( symbol.material().diffuse() );
material->setSpecular( symbol.material().specular() );
material->setShininess( symbol.material().shininess() );
return material;
}

@@ -115,7 +115,7 @@ Qt3DRender::QGeometryRenderer *PolygonEntityNode::renderer( const Map3D &map, co
{
QgsPolygonV2 *poly = static_cast<QgsPolygonV2 *>( g );
QgsPolygonV2 *polyClone = poly->clone();
Utils::clampAltitudes( polyClone, symbol.altClamping, symbol.altBinding, symbol.height, map );
Utils::clampAltitudes( polyClone, symbol.altitudeClamping(), symbol.altitudeBinding(), symbol.height(), map );
polygons.append( polyClone );
}
else if ( QgsWkbTypes::flatType( g->wkbType() ) == QgsWkbTypes::MultiPolygon )
@@ -126,7 +126,7 @@ Qt3DRender::QGeometryRenderer *PolygonEntityNode::renderer( const Map3D &map, co
QgsAbstractGeometry *g2 = mpoly->geometryN( i );
Q_ASSERT( QgsWkbTypes::flatType( g2->wkbType() ) == QgsWkbTypes::Polygon );
QgsPolygonV2 *polyClone = static_cast<QgsPolygonV2 *>( g2 )->clone();
Utils::clampAltitudes( polyClone, symbol.altClamping, symbol.altBinding, symbol.height, map );
Utils::clampAltitudes( polyClone, symbol.altitudeClamping(), symbol.altitudeBinding(), symbol.height(), map );
polygons.append( polyClone );
}
}
@@ -135,7 +135,7 @@ Qt3DRender::QGeometryRenderer *PolygonEntityNode::renderer( const Map3D &map, co
}

mGeometry = new PolygonGeometry;
mGeometry->setPolygons( polygons, origin, symbol.extrusionHeight );
mGeometry->setPolygons( polygons, origin, symbol.extrusionHeight() );

Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer;
renderer->setGeometry( mGeometry );
@@ -1,11 +1,11 @@
#include "qgsline3dsymbol.h"

QgsLine3DSymbol::QgsLine3DSymbol()
: altClamping( AltClampRelative )
, altBinding( AltBindCentroid )
, height( 0 )
, extrusionHeight( 0 )
, width( 2 )
: mAltClamping( AltClampRelative )
, mAltBinding( AltBindCentroid )
, mWidth( 2 )
, mHeight( 0 )
, mExtrusionHeight( 0 )
{

}
@@ -22,15 +22,15 @@ void QgsLine3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co
QDomDocument doc = elem.ownerDocument();

QDomElement elemDataProperties = doc.createElement( "data" );
elemDataProperties.setAttribute( "alt-clamping", Utils::altClampingToString( altClamping ) );
elemDataProperties.setAttribute( "alt-binding", Utils::altBindingToString( altBinding ) );
elemDataProperties.setAttribute( "height", height );
elemDataProperties.setAttribute( "extrusion-height", extrusionHeight );
elemDataProperties.setAttribute( "width", width );
elemDataProperties.setAttribute( "alt-clamping", Utils::altClampingToString( mAltClamping ) );
elemDataProperties.setAttribute( "alt-binding", Utils::altBindingToString( mAltBinding ) );
elemDataProperties.setAttribute( "height", mHeight );
elemDataProperties.setAttribute( "extrusion-height", mExtrusionHeight );
elemDataProperties.setAttribute( "width", mWidth );
elem.appendChild( elemDataProperties );

QDomElement elemMaterial = doc.createElement( "material" );
material.writeXml( elemMaterial );
mMaterial.writeXml( elemMaterial );
elem.appendChild( elemMaterial );
}

@@ -39,12 +39,12 @@ void QgsLine3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
Q_UNUSED( context );

QDomElement elemDataProperties = elem.firstChildElement( "data" );
altClamping = Utils::altClampingFromString( elemDataProperties.attribute( "alt-clamping" ) );
altBinding = Utils::altBindingFromString( elemDataProperties.attribute( "alt-binding" ) );
height = elemDataProperties.attribute( "height" ).toFloat();
extrusionHeight = elemDataProperties.attribute( "extrusion-height" ).toFloat();
width = elemDataProperties.attribute( "width" ).toFloat();
mAltClamping = Utils::altClampingFromString( elemDataProperties.attribute( "alt-clamping" ) );
mAltBinding = Utils::altBindingFromString( elemDataProperties.attribute( "alt-binding" ) );
mHeight = elemDataProperties.attribute( "height" ).toFloat();
mExtrusionHeight = elemDataProperties.attribute( "extrusion-height" ).toFloat();
mWidth = elemDataProperties.attribute( "width" ).toFloat();

QDomElement elemMaterial = elem.firstChildElement( "material" );
material.readXml( elemMaterial );
mMaterial.readXml( elemMaterial );
}
@@ -20,14 +20,32 @@ class _3D_EXPORT QgsLine3DSymbol : public QgsAbstract3DSymbol
void writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const override;
void readXml( const QDomElement &elem, const QgsReadWriteContext &context ) override;

AltitudeClamping altClamping; //! how to handle altitude of vector features
AltitudeBinding altBinding; //! how to handle clamping of vertices of individual features
AltitudeClamping altitudeClamping() const { return mAltClamping; }
void setAltitudeClamping( AltitudeClamping altClamping ) { mAltClamping = altClamping; }

float height; //!< Base height of polygons
float extrusionHeight; //!< How much to extrude (0 means no walls)
PhongMaterialSettings material; //!< Defines appearance of objects
AltitudeBinding altitudeBinding() const { return mAltBinding; }
void setAltitudeBinding( AltitudeBinding altBinding ) { mAltBinding = altBinding; }

float width; //!< Line width (horizontally)
float width() const { return mWidth; }
void setWidth( float width ) { mWidth = width; }

float height() const { return mHeight; }
void setHeight( float height ) { mHeight = height; }

float extrusionHeight() const { return mExtrusionHeight; }
void setExtrusionHeight( float extrusionHeight ) { mExtrusionHeight = extrusionHeight; }

PhongMaterialSettings material() const { return mMaterial; }
void setMaterial( const PhongMaterialSettings &material ) { mMaterial = material; }

private:
AltitudeClamping mAltClamping; //! how to handle altitude of vector features
AltitudeBinding mAltBinding; //! how to handle clamping of vertices of individual features

float mWidth; //!< Line width (horizontally)
float mHeight; //!< Base height of polygons
float mExtrusionHeight; //!< How much to extrude (0 means no walls)
PhongMaterialSettings mMaterial; //!< Defines appearance of objects
};


@@ -18,30 +18,30 @@ void QgsPoint3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &c
QDomDocument doc = elem.ownerDocument();

QDomElement elemMaterial = doc.createElement( "material" );
material.writeXml( elemMaterial );
mMaterial.writeXml( elemMaterial );
elem.appendChild( elemMaterial );

QVariantMap shapePropertiesCopy( shapeProperties );
QVariantMap shapePropertiesCopy( mShapeProperties );
shapePropertiesCopy["model"] = QVariant( context.pathResolver().writePath( shapePropertiesCopy["model"].toString() ) );

QDomElement elemShapeProperties = doc.createElement( "shape-properties" );
elemShapeProperties.appendChild( QgsXmlUtils::writeVariant( shapePropertiesCopy, doc ) );
elem.appendChild( elemShapeProperties );

QDomElement elemTransform = doc.createElement( "transform" );
elemTransform.setAttribute( "matrix", Utils::matrix4x4toString( transform ) );
elemTransform.setAttribute( "matrix", Utils::matrix4x4toString( mTransform ) );
elem.appendChild( elemTransform );
}

void QgsPoint3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
QDomElement elemMaterial = elem.firstChildElement( "material" );
material.readXml( elemMaterial );
mMaterial.readXml( elemMaterial );

QDomElement elemShapeProperties = elem.firstChildElement( "shape-properties" );
shapeProperties = QgsXmlUtils::readVariant( elemShapeProperties.firstChildElement() ).toMap();
shapeProperties["model"] = QVariant( context.pathResolver().readPath( shapeProperties["model"].toString() ) );
mShapeProperties = QgsXmlUtils::readVariant( elemShapeProperties.firstChildElement() ).toMap();
mShapeProperties["model"] = QVariant( context.pathResolver().readPath( mShapeProperties["model"].toString() ) );

QDomElement elemTransform = elem.firstChildElement( "transform" );
transform = Utils::stringToMatrix4x4( elemTransform.attribute( "matrix" ) );
mTransform = Utils::stringToMatrix4x4( elemTransform.attribute( "matrix" ) );
}

0 comments on commit fc28a97

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