View: Shaded with Hard Edges

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: View: Shaded with Hard Edges

Post by saso »

grd wrote: Thu May 18, 2023 10:10 am @saso I can be wrong but you are sure that it isn't a Coin3D issue? How is it possible that cqparts (that also rely on occt) has it working?
Of course it is possible that there is existing support for this somewhere in the different layers of the geometry-rendering pipeline, but only someone with deep enough knowledge of all this can give you the right answer...

https://github.com/coin3d/coin
https://github.com/coin3d/coin/blob/529 ... r.cpp#L183 :?:
https://www.coin3d.org/Coin/html/classS ... rator.html :?:
https://www.coin3d.org/Coin/html/classSoDrawStyle.html

https://github.com/aumuell/open-inventor
https://github.com/aumuell/open-invento ... ator.h#L86 :?:
https://github.com/aumuell/open-invento ... 2B%2B#L383 :?:
User avatar
adrianinsaval
Veteran
Posts: 5541
Joined: Thu Apr 05, 2018 5:15 pm

Re: View: Shaded with Hard Edges

Post by adrianinsaval »

grd wrote: Thu May 18, 2023 10:10 am @saso I can be wrong but you are sure that it isn't a Coin3D issue? How is it possible that cqparts (that also rely on occt) has it working?
I don't see how coin would know which edge is smooth and which isn't, coin only receives a mesh. I would think this info has to come from the geometric kernel, it's most likely possible to do the question is just how and who will do it...
grd
Posts: 328
Joined: Wed Apr 13, 2022 5:13 am
Location: Eindhoven, The Netherlands

Re: View: Shaded with Hard Edges

Post by grd »

adrianinsaval wrote: Thu May 18, 2023 3:11 pm
grd wrote: Thu May 18, 2023 10:10 am @saso I can be wrong but you are sure that it isn't a Coin3D issue? How is it possible that cqparts (that also rely on occt) has it working?
I don't see how coin would know which edge is smooth and which isn't, coin only receives a mesh. I would think this info has to come from the geometric kernel, it's most likely possible to do the question is just how and who will do it...
I don't have the knowhow. The only thing that I can do is implement the buttons and the logic behind that, but the real code that I can't do.
About Nim. Latest Release 2.0.2. Here is Nim in 100 seconds and a Nim package. There are Qt and OCCT packages.
jeno
Veteran
Posts: 1820
Joined: Sun Jun 29, 2014 10:41 am

Re: View: Shaded with Hard Edges

Post by jeno »

adrianinsaval wrote: Thu May 18, 2023 3:11 pm I don't see how coin would know which edge is smooth and which isn't, coin only receives a mesh...
According to the difference between the normals of neighbouring faces.
Let's have a look over the fence
Screenshot_20230519_072200.png
Screenshot_20230519_072200.png (65.68 KiB) Viewed 1242 times
By default Blender shades hard over an value of 30°. Neighbouring faces beyond 30° are shaded smooth.
But I guess it isn't that easy. As far as I understood (more guessing than knowing) the edge lines are painted as different layer and are generated in OCC (IMeshTools_CurveTessellator?). So you need to have some kind of sorting algo in Coin3D.

cheers
User avatar
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: View: Shaded with Hard Edges

Post by saso »

Did someone check the links in my previous post to the SoNormalGenerator class in coin/open-inventor and read some of the comments in the code?
Triggers the normal generation. Normals are generated using
\a creaseAngle to find which edges should be flat-shaded
and which should be smooth-shaded.
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: View: Shaded with Hard Edges

Post by mfro »

jeno wrote: Fri May 19, 2023 5:47 am Let's have a look over the fenceScreenshot_20230519_072200.png
Can you give an example of an object where two Faces contact with varying angle along the edge? Would that then displayed as an edge ending in the middle of nowhere?
Cheers,
Markus
jeno
Veteran
Posts: 1820
Joined: Sun Jun 29, 2014 10:41 am

Re: View: Shaded with Hard Edges

Post by jeno »

mfro wrote: Fri May 19, 2023 11:01 am
jeno wrote: Fri May 19, 2023 5:47 am Let's have a look over the fenceScreenshot_20230519_072200.png
Can you give an example of an object where two Faces contact with varying angle along the edge? Would that then displayed as an edge ending in the middle of nowhere?
I did not write that or at least I did not meant that. I was talking about the angle between two connected (flat) faces of a mesh. Depending on that angle (or the angle between the face normals) they would be painted smooth or flat.

cheers
User avatar
mfro
Posts: 663
Joined: Sat Sep 23, 2017 8:15 am

Re: View: Shaded with Hard Edges

Post by mfro »

jeno wrote: Fri May 19, 2023 12:01 pm ...
I did not write that or at least I did not meant that. I was talking about the angle between two connected (flat) faces of a mesh. Depending on that angle (or the angle between the face normals) they would be painted smooth or flat.
...
Which would lead to the same visible result (as the mesh had to follow the faces)? I just cannot imagine how that is supposed to look like.
Cheers,
Markus
jeno
Veteran
Posts: 1820
Joined: Sun Jun 29, 2014 10:41 am

Re: View: Shaded with Hard Edges

Post by jeno »

mfro wrote: Fri May 19, 2023 12:15 pm ...Which would lead to the same visible result (as the mesh had to follow the faces)? I just cannot imagine how that is supposed to look like.
Compare the angle to each other face or normal (the blueish lines)
Screenshot_20230519-1.png
Screenshot_20230519-1.png (72.41 KiB) Viewed 1044 times
cheers
User avatar
saso
Veteran
Posts: 1920
Joined: Fri May 16, 2014 1:14 pm
Contact:

Re: View: Shaded with Hard Edges

Post by saso »

The confusion here comes IMO from the different interpretation and so by users understanding of what an "edge" is in so to say mesh modelers as blender or solid/brep modelers as freecad and then on top of that the additional confusion that actually also in solid modelers the geometry is actually rendered as a mesh and on top of that the shader smoothing (so, brep geometry -> mesh geometry -> shader)...

Here is a video that IMO shows good the concept of "edge smoothing" in blender, understand the difference from the video between smoothing an edge by adding a bevel (adding more polygons) and applying a shader...

phpBB [video]


This of course is very different to when we talk about faces and their bounding edges in brep and is in general, when we talk about the geometry, also not something we are interested about, but on the coin level this type of shading is also going on in FC and can be seen when changing for example between the "no shading", "shaded" and "flat lines" draw style.

A cylinder in FC and its faces shaded as flat and smooth. This visually represents the brep geometry which is for this cylinder basically just 3 faces (top, bottom and side) and 3 edges (two circles and a seam)
flat_smooth.jpg
flat_smooth.jpg (14.1 KiB) Viewed 970 times

This same cylinder, represented by the coin mesh (polygons), visible in "hidden line" draw style (was renamed to "tessellated" in realthunders version). As we can see a "brep face" is actually represented (rendered to the screen) as many mesh faces (triangles, polygons) and the logic of the normals angles for smooth and flat shading is actually applied between this mesh faces
coin_mesh.jpg
coin_mesh.jpg (13.4 KiB) Viewed 967 times

But if we get back to the edges as represented by boundary lines in FC, if we would be able to use this coin functionality then the logic would be that boundary edges between two smooth shaded faces would be hidden and others (between two flat shaded or between a flat and smooth shaded faces) would be visible...
Post Reply