Skip to content
Permalink
Browse files
Address reviews
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed May 13, 2022
1 parent e24f5cb commit 84eac84230dfb626c9f20bbcc1bd62b4ccfc67ee
@@ -18,9 +18,7 @@
#include "qgssymbollayerutils.h"
#include "qgsapplication.h"
#include "qgsimagecache.h"
#include <Qt3DExtras/QDiffuseMapMaterial>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DExtras/QPhongAlphaMaterial>
#include <Qt3DExtras/QDiffuseSpecularMaterial>
#include <Qt3DRender/QAttribute>
#include <Qt3DRender/QBuffer>
#include <Qt3DRender/QGeometry>
@@ -101,30 +99,17 @@ Qt3DRender::QMaterial *QgsPhongMaterialSettings::toMaterial( QgsMaterialSettings
if ( dataDefinedProperties().hasActiveProperties() )
return dataDefinedMaterial();

int opacity = mOpacity * 255;
Qt3DExtras::QDiffuseSpecularMaterial *material = new Qt3DExtras::QDiffuseSpecularMaterial;
material->setDiffuse( QColor( mDiffuse.red(), mDiffuse.green(), mDiffuse.blue(), opacity ) );
material->setAmbient( QColor( mAmbient.red(), mAmbient.green(), mAmbient.blue(), opacity ) );
material->setSpecular( QColor( mSpecular.red(), mSpecular.green(), mSpecular.blue(), opacity ) );
material->setShininess( mShininess );
if ( mOpacity != 1 )
{
Qt3DExtras::QPhongAlphaMaterial *material = new Qt3DExtras::QPhongAlphaMaterial;
material->setDiffuse( mDiffuse );
material->setAmbient( mAmbient );
material->setSpecular( mSpecular );
material->setShininess( mShininess );
material->setAlpha( mOpacity );

if ( context.isSelected() )
{
// update the material with selection colors
material->setDiffuse( context.selectionColor() );
material->setAmbient( context.selectionColor().darker() );
}
return material;
material->setAlphaBlendingEnabled( true );
}

Qt3DExtras::QPhongMaterial *material = new Qt3DExtras::QPhongMaterial;
material->setDiffuse( mDiffuse );
material->setAmbient( mAmbient );
material->setSpecular( mSpecular );
material->setShininess( mShininess );

if ( context.isSelected() )
{
// update the material with selection colors
@@ -26,6 +26,7 @@
#include <Qt3DExtras/QForwardRenderer>
#include <Qt3DExtras/QPhongMaterial>
#include <Qt3DExtras/QPhongAlphaMaterial>
#include <Qt3DExtras/QDiffuseSpecularMaterial>
#include <Qt3DExtras/QSphereMesh>
#include <Qt3DLogic/QFrameAction>
#include <Qt3DRender/QEffect>
@@ -913,14 +914,17 @@ void Qgs3DMapScene::finalizeNewEntity( Qt3DCore::QEntity *newEntity )
bm->setViewportSize( mCameraController->viewport().size() );
}


// Finalize adding the 3D transparent objects by adding the layer components to the entities
for ( Qt3DExtras::QPhongAlphaMaterial *ph : newEntity->findChildren<Qt3DExtras::QPhongAlphaMaterial *>() )
QgsShadowRenderingFrameGraph *frameGraph = mEngine->frameGraph();
Qt3DRender::QLayer *layer = frameGraph->transparentObjectLayer();
for ( Qt3DExtras::QDiffuseSpecularMaterial *ph : newEntity->findChildren<Qt3DExtras::QDiffuseSpecularMaterial *>() )
{
if ( ph->diffuse().value<QColor>().alphaF() == 1.0f )
continue;
Qt3DCore::QEntity *entity = qobject_cast<Qt3DCore::QEntity *>( ph->parent() );
if ( !entity )
continue;
QgsShadowRenderingFrameGraph *frameGraph = mEngine->frameGraph();
Qt3DRender::QLayer *layer = frameGraph->transparentObjectLayer();
if ( entity->components().contains( layer ) )
continue;
entity->addComponent( layer );
@@ -28,6 +28,8 @@
#include <Qt3DRender/QGraphicsApiFilter>
#include <Qt3DRender/QBlendEquation>
#include <Qt3DRender/QSortPolicy>
#include <Qt3DRender/QNoDepthMask>
#include <Qt3DRender/QBlendEquationArguments>

Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructTexturesPreviewPass()
{
@@ -122,9 +124,6 @@ Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructForwardRende
Qt3DRender::QSortPolicy *sortPolicy = new Qt3DRender::QSortPolicy( transparentObjectsLayerFilter );
QVector<Qt3DRender::QSortPolicy::SortType> sortTypes;
sortTypes.push_back( Qt3DRender::QSortPolicy::BackToFront );
sortTypes.push_back( Qt3DRender::QSortPolicy::Material );
sortTypes.push_back( Qt3DRender::QSortPolicy::StateChangeCost );
sortTypes.push_back( Qt3DRender::QSortPolicy::FrontToBack );
sortPolicy->setSortTypes( sortTypes );

Qt3DRender::QRenderStateSet *transparentObjectsRenderStateSet = new Qt3DRender::QRenderStateSet( sortPolicy );
@@ -133,13 +132,23 @@ Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructForwardRende
depthTest->setDepthFunction( Qt3DRender::QDepthTest::Less );
transparentObjectsRenderStateSet->addRenderState( depthTest );

Qt3DRender::QNoDepthMask *noDepthMask = new Qt3DRender::QNoDepthMask;
transparentObjectsRenderStateSet->addRenderState( noDepthMask );

Qt3DRender::QCullFace *cullFace = new Qt3DRender::QCullFace;
cullFace->setMode( Qt3DRender::QCullFace::CullingMode::NoCulling );
transparentObjectsRenderStateSet->addRenderState( cullFace );

Qt3DRender::QBlendEquation *blendEquation = new Qt3DRender::QBlendEquation;
blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Subtract );
blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
transparentObjectsRenderStateSet->addRenderState( blendEquation );

Qt3DRender::QBlendEquationArguments *blenEquationArgs = new Qt3DRender::QBlendEquationArguments;
blenEquationArgs->setSourceRgb( Qt3DRender::QBlendEquationArguments::Blending::One );
blenEquationArgs->setDestinationRgb( Qt3DRender::QBlendEquationArguments::Blending::OneMinusSource1Alpha );
blenEquationArgs->setSourceAlpha( Qt3DRender::QBlendEquationArguments::Blending::One );
blenEquationArgs->setDestinationAlpha( Qt3DRender::QBlendEquationArguments::Blending::OneMinusSource1Alpha );
transparentObjectsRenderStateSet->addRenderState( blenEquationArgs );
}

return mMainCameraSelector;
@@ -33,11 +33,7 @@ QgsPhongMaterialWidget::QgsPhongMaterialWidget( QWidget *parent )
connect( mAmbientDataDefinedButton, &QgsPropertyOverrideButton::changed, this, &QgsPhongMaterialWidget::changed );
connect( mDiffuseDataDefinedButton, &QgsPropertyOverrideButton::changed, this, &QgsPhongMaterialWidget::changed );
connect( mSpecularDataDefinedButton, &QgsPropertyOverrideButton::changed, this, &QgsPhongMaterialWidget::changed );
connect( mOpacitySlider, &QSlider::valueChanged, this, &QgsPhongMaterialWidget::changed );
connect( mOpacitySlider, &QSlider::valueChanged, this, [&]( int value )
{
mOpacityPercentageLabel->setText( QStringLiteral( "%1%" ).arg( value ) );
} );
connect( mOpacityWidget, &QgsOpacityWidget::opacityChanged, this, &QgsPhongMaterialWidget::changed );
}

QgsMaterialSettingsWidget *QgsPhongMaterialWidget::create()
@@ -105,7 +101,7 @@ void QgsPhongMaterialWidget::setSettings( const QgsAbstractMaterialSettings *set
btnAmbient->setColor( phongMaterial->ambient() );
btnSpecular->setColor( phongMaterial->specular() );
spinShininess->setValue( phongMaterial->shininess() );
mOpacitySlider->setValue( phongMaterial->opacity() * 100.0 );
mOpacityWidget->setOpacity( phongMaterial->opacity() );

mPropertyCollection = settings->dataDefinedProperties();

@@ -121,7 +117,7 @@ QgsAbstractMaterialSettings *QgsPhongMaterialWidget::settings()
m->setAmbient( btnAmbient->color() );
m->setSpecular( btnSpecular->color() );
m->setShininess( spinShininess->value() );
m->setOpacity( mOpacitySlider->value() / 100.0 );
m->setOpacity( mOpacityWidget->opacity() );

mPropertyCollection.setProperty( QgsAbstractMaterialSettings::Diffuse, mDiffuseDataDefinedButton->toProperty() );
mPropertyCollection.setProperty( QgsAbstractMaterialSettings::Ambient, mAmbientDataDefinedButton->toProperty() );
@@ -63,13 +63,6 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsDoubleSpinBox" name="spinShininess">
<property name="maximum">
<double>1000.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QgsPropertyOverrideButton" name="mDiffuseDataDefinedButton">
<property name="text">
@@ -130,30 +123,20 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSlider" name="mOpacitySlider">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lblOpacity">
<property name="text">
<string>Opacity</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="mOpacityPercentageLabel">
<property name="text">
<string>100%</string>
<item row="4" column="1" colspan="2">
<widget class="QgsOpacityWidget" name="mOpacityWidget" native="true"/>
</item>
<item row="3" column="1" colspan="2">
<widget class="QgsDoubleSpinBox" name="spinShininess">
<property name="maximum">
<double>1000.000000000000000</double>
</property>
</widget>
</item>
@@ -176,6 +159,12 @@
<header>qgscolorbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>QgsOpacityWidget</class>
<extends>QWidget</extends>
<header>qgsopacitywidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>btnDiffuse</tabstop>

0 comments on commit 84eac84

Please sign in to comment.