Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] texturing support for vector layer #36981

Merged
merged 30 commits into from Jul 9, 2020

Conversation

NEDJIMAbelgacem
Copy link
Contributor

Added texturing support for QGIS 3D

  • Now from the symbol properties you can select an image to be displayed on the surfaces of buildings as diffuse map.
  • The user can also change the scale of textures from the symbol properties as you can see in these screenshots:

Screenshot_20200604_182756
Screenshot_20200604_182723

  • Some visual issue may appear when using textures. these issues relates to the normals of surfaces that you may be able to fix by checking "add back faces" and playing around with the invert normals and culling mode in the symbol properties.
  • I modified a bit of the QgsTessellatedPolygonGeometry constructor so that every Qt3DRender::QAttribute of the geometry will be constructed properly because setting them after constructing the object can be confusing and we don't want it to construct objects that we won't need later on. I also provided default parameters for the constructor so we don't have problems with existing code.

@github-actions github-actions bot added this to the 3.14.0 milestone Jun 4, 2020
@m-kuhn
Copy link
Member

m-kuhn commented Jun 4, 2020

Nice start!

Welcome Belgacem.

@nyalldawson nyalldawson added Feature Frozen Feature freeze - Do not merge! 3D Relates to QGIS' 3D engine or rendering labels Jun 4, 2020
@nyalldawson nyalldawson modified the milestones: 3.14.0, 3.16 (Feature) Jun 4, 2020
}
}
Qt3DRender::QTextureImage *textureImage = new Qt3DRender::QTextureImage;
textureImage->setSource( QUrl::fromLocalFile( textureFilePath ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at https://stackoverflow.com/questions/50944249/create-qtextureimage-from-qimage , it seems there's a means to directly construct textures from a QImage object. If this is the case, then you could use QgsImageCache::pathAsImage() (via QgsApplication::imageCache()->pathAsImage(...)) here instead of directly loading from a local file.

There's two benefits to this approach

  1. If the image has been previously loaded then it'll save a bunch of work
  2. QgsImageCache supports base64 encoded image paths. This allows for embedding images directly inside a QgsProject, so that the project becomes portable and there's no path issues when you share the project (or QML style) with others. To enable this you'd also need to chance the textureFile widget in the ui file to a QgsImageSourceLineEdit widget (which adds the UI for users to embed pictures).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about that. I will change the textureFile widget to QgsImageSourceLineEdit and use QgsImageCache and make another commit.
Thanks for the suggestion!

@nyalldawson
Copy link
Collaborator

Wow, you've really "hit the ground running"!! Great start to GSOC @NEDJIMAbelgacem !

@ismailsunni
Copy link
Contributor

Awesome @NEDJIMAbelgacem
You can also add some gifs to show the 3D or how the setting works (nice to have/see but not mandatory for sure)

@timlinux
Copy link
Member

timlinux commented Jun 7, 2020

Looking awesome @NEDJIMAbelgacem !

Copy link
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking great - nice work!

I have left a couple of suggestions below on how to further improve the code...

src/3d/qgsphongmaterialsettings.cpp Outdated Show resolved Hide resolved
src/3d/qgsphongmaterialsettings.h Outdated Show resolved Hide resolved
src/3d/qgsphongmaterialsettings.h Outdated Show resolved Hide resolved
src/3d/qgsphongmaterialsettings.h Outdated Show resolved Hide resolved
src/3d/symbols/qgspolygon3dsymbol_p.cpp Show resolved Hide resolved
src/3d/symbols/qgspolygon3dsymbol_p.cpp Show resolved Hide resolved
src/3d/symbols/qgspolygon3dsymbol_p.cpp Outdated Show resolved Hide resolved
src/core/qgstessellator.cpp Outdated Show resolved Hide resolved
src/core/qgstessellator.cpp Outdated Show resolved Hide resolved
@NEDJIMAbelgacem NEDJIMAbelgacem force-pushed the vector-layer-texturing branch 6 times, most recently from 976ea24 to 3e17459 Compare June 16, 2020 00:43
@nyalldawson nyalldawson removed the Frozen Feature freeze - Do not merge! label Jun 19, 2020
@NEDJIMAbelgacem
Copy link
Contributor Author

Hi,
The separation between roofs and walls in now complete although it's not very good now due to technical limitations of how we classify a vector layer feature's geometry as part of wall or roof.
I made a new combo box that selects which facade we want to render (wall, roofs or walls and roofs). To know if a triangle is a wall or a roof I calculate the degrees between the triangle's normal and the horizontal plane, if the angle is less than 10 degrees the triangle is a part of a roof, otherwise it's part of a wall.
To take advantage of the walls and roofs separation, the user needs to create 2 rules in the rule based rendering each one having it's own symbol.
The user can also change the scale and rotation of textures.
I noticed that the Phong material gets reused in parts where there is no need to use textures. I hide the texture UI widgets every time except when it is needed for the vector layer.
Screenshot_2020-06-27_14-19-47

Copy link
Member

@wonder-sk wonder-sk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! We will probably still need to do some further work on texturing, but this one is good to go...

@wonder-sk wonder-sk merged commit cc96e9e into qgis:master Jul 9, 2020
@timlinux timlinux added Changelog Items that are queued to appear in the visual changelog - remove after harvesting ChangelogHarvested This PR description has been harvested in the Changelog already. and removed Changelog Items that are queued to appear in the visual changelog - remove after harvesting labels Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3D Relates to QGIS' 3D engine or rendering ChangelogHarvested This PR description has been harvested in the Changelog already. Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants