15 #include <Qt3DRender/QParameter> 16 #include <Qt3DRender/QShaderProgram> 17 #include <Qt3DRender/QRenderPass> 18 #include <Qt3DRender/QTechnique> 19 #include <Qt3DRender/QGraphicsApiFilter> 20 #include <Qt3DRender/QEffect> 21 #include <Qt3DRender/QBlendEquationArguments> 22 #include <Qt3DRender/QBlendEquation> 23 #include <Qt3DRender/QNoDepthMask> 34 : mSize( new
Qt3DRender::QParameter(
"BB_SIZE", QSizeF( 100, 100 ), this ) )
35 , mViewportSize( new
Qt3DRender::QParameter(
"WIN_SCALE", QSizeF( 800, 600 ), this ) )
37 addParameter( mSize );
38 addParameter( mViewportSize );
41 mTexture2D =
new Qt3DRender::QParameter(
"tex0", QVariant(),
this );
42 addParameter( mTexture2D );
45 Qt3DRender::QBlendEquationArguments *blendState =
new Qt3DRender::QBlendEquationArguments;
46 blendState->setSourceRgb( Qt3DRender::QBlendEquationArguments::SourceAlpha );
47 blendState->setDestinationRgb( Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha );
49 Qt3DRender::QBlendEquation *blendEquation =
new Qt3DRender::QBlendEquation;
50 blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
53 Qt3DRender::QShaderProgram *shaderProgram =
new Qt3DRender::QShaderProgram(
this );
54 shaderProgram->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/billboards.vert" ) ) ) );
55 shaderProgram->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/billboards.frag" ) ) ) );
56 shaderProgram->setGeometryShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/billboards.geom" ) ) ) );
59 Qt3DRender::QRenderPass *renderPass =
new Qt3DRender::QRenderPass(
this );
60 renderPass->setShaderProgram( shaderProgram );
61 renderPass->addRenderState( blendState );
62 renderPass->addRenderState( blendEquation );
65 Qt3DRender::QFilterKey *filterKey =
new Qt3DRender::QFilterKey;
66 filterKey->setName( QStringLiteral(
"renderingStyle" ) );
67 filterKey->setValue(
"forward" );
70 Qt3DRender::QTechnique *technique =
new Qt3DRender::QTechnique;
71 technique->addRenderPass( renderPass );
72 technique->addFilterKey( filterKey );
73 technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
74 technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
75 technique->graphicsApiFilter()->setMajorVersion( 3 );
76 technique->graphicsApiFilter()->setMinorVersion( 1 );
79 Qt3DRender::QEffect *effect =
new Qt3DRender::QEffect(
this );
80 effect->addTechnique( technique );
87 mSize->setValue( size );
92 return mSize->value().value<QSizeF>();
97 mViewportSize->setValue( size );
102 return mViewportSize->value().value<QSizeF>();
105 void QgsPoint3DBillboardMaterial::setTexture2DFromImage( QImage image,
double size )
109 QgsTerrainTextureImage *billboardTextureImage =
new QgsTerrainTextureImage( image, randomExtent, QStringLiteral(
"billboard material." ) );
111 setTexture2DFromTextureImage( billboardTextureImage );
112 setSize( QSizeF( size + size, size + size ) );
130 double strokeRatio = 0.5;
134 double minimumExtraSize = 40;
135 double extraPixel = minimumExtraSize > pixelSize * strokeRatio ? minimumExtraSize : pixelSize * strokeRatio;
136 int pixelWithExtra = std::ceil( pixelSize + extraPixel );
138 QImage symbolImage = symbolPixmap.toImage();
139 QImage flippedSymbolImage = symbolImage.mirrored();
140 setTexture2DFromImage( flippedSymbolImage, pixelWithExtra );
143 void QgsPoint3DBillboardMaterial::setTexture2DFromTextureImage( Qt3DRender::QAbstractTextureImage *textureImage )
146 Qt3DRender::QTexture2D *texture2D =
new Qt3DRender::QTexture2D(
this );
147 texture2D->setGenerateMipMaps(
false );
148 texture2D->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
149 texture2D->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
152 texture2D->addTextureImage( textureImage );
154 mTexture2D->setValue( QVariant::fromValue( texture2D ) );
void setSize(const QSizeF size)
Set the billboard size.
A rectangle specified with double values.
void useDefaultSymbol(const Qgs3DMapSettings &map, bool selected=false)
Set default symbol for the texture with map and selected parameter for rendering. ...
QColor selectionColor() const
Returns color used for selected features.
3 Definition of the world
void setViewportSize(const QSizeF size)
Set the size of the view port.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setTexture2DFromSymbol(QgsMarkerSymbol *markerSymbol, const Qgs3DMapSettings &map, bool selected=false)
Set markerSymbol for the texture with map and selected parameter for rendering.
void setSelectionColor(const QColor &color)
Sets the color to use when rendering selected features.
static QgsSymbol * defaultSymbol(QgsWkbTypes::GeometryType geomType)
Returns a new default symbol for the specified geometry type.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QgsPoint3DBillboardMaterial()
QgsUnitTypes::RenderUnit sizeUnit() const
Returns the size units for the whole symbol (including all symbol layers).
Contains information about the context of a rendering operation.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
double size() const
Returns the estimated size for the whole symbol, which is the maximum size of all marker symbol layer...
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr)
Returns a pixmap preview for a color ramp.
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
QSizeF windowSize() const
Returns the size of the view port.
QSizeF size() const
Returns the billboard size.