GeometryCreator/Info & smooth group

With the new utility.geometry package I would like to use a GeometryCreator (let’s call it gec) to create a model, which I then feed to XithGeometryInfo (let’s call it xgi).

Two questions…

a) How does xgi.recalculateSmoothGroupNormals() work in english (*) ?
Does it take all the faces with the same smooth group number (which has been set per setFaceSmoothingGroup) and avarage the normal vector of adjacent faces?
Or does it avarage just all the face’s vectors in the same smooth group?

For example:
http://mitglied.lycos.de/nautis/Publik/Cone.png

Face0 is in an own smooth group, whereas Face1…FaceN are in a second smooth group. This would work fine, then? Does adjacent mean: Face0 is adjacent to Face1 but not to Face2, even when the top most vertex (the Cone’s top) is being shared?
(Edit: of course Face0 would have to consist of many triangles, but in the end it’s the same question.)

b) Instead of using smooth groups I’d like to define a maximum angle between adjacent polygons that will be smooth shaded. Shading across edges at higher angles shouldn’t be interpolated (the polygons will appear to meet at a sharp seam).
I think there’s no such possibility in Xith3d currently, so I would have to use smooth groups anway? So… find out “somehow” all adjacent faces with an angle between them being below the crease value. Then set all these faces to the same smoothgroup. Then use the recalculateSmoothGroupNormals() method.
Would this work-around do the trick?

(*) I know there’s the source code but … I’m very bad in understanding other people’s source…

I made a normal generator once that used an angle to define the hard edges. I could try explaining the algorithm and/or give you the source if you are interested.

[quote]I made a normal generator once that used an angle to define the hard edges. I could try explaining the algorithm and/or give you the source if you are interested.
[/quote]
Thanks, explaining would be nice. Because somewhat like it could be used to find the faces which belong to the same smooth group (and then use GeometryInfo). Which means all Xith users would benefit. :slight_smile:

I second that. Any info on that would be very nice ;D

Yes, it works this way. For each vertex, it’s normal is set to average of normals of all faces attached to it, from given smooth group. This means that if vertex belongs to faces from more than one smooth group, it will be duplicated - one copy for each smooth group it belongs to.

Please remember that smoothing works on vertices, not on faces. It doesn’t matter which face is adjacent to which - it is only important which faces contain given vertex. Top of cone vertex is adjacent to all faces 1-n, so it’s normal will be average of normals of all faces - which probably will be a vector pointing upwards. Vertices at edge of bottom of cone will be duplicated - once with normals for sides and once with normals for bottom cap.

To get the perfect cone, you need to have many vertices at top point - one for each face. To achieve that (if you really want to use GeometryInfo for that, as you can as well calculate normals yourself), you will need to create a cylinder, just with one cap very, very small (0.00001 diameter for example for 1 unit size cone) - big enough so the difference will not be lost in floating arithmetics.

Yes, such functionality would be nice - but currently it is not available. It can be written at top of current package, but there is no one-line trick that can do this - it just needs to be implemented the hard way.

[quote]Thanks, explaining would be nice. Because somewhat like it could be used to find the faces which belong to the same smooth group (and then use GeometryInfo). Which means all Xith users would benefit. :slight_smile:
[/quote]
Ok. I’ll try to explain the basic idee.
To find the vertex normal for a face you must (take a deep breath): Take the average of the face normals of the faces that share the vertex and that can be reached recursivly from the initial face threw a soft edge. A soft edge is an edge that angle between the two connected faces normals is below the crease angle.

I’ll try to visualise it with an example. Lets say you want to find the vertex normal of the top vertex in face 1 in your cone example.

Start by adding face 1 normal to normal sum. Face 2 and n share the top vertex with 1, and is connected to face 1 threw an edge. The edges are not hard so both faces normals will be added to the normal sum. Face 2 and n is treated the same way recursevly. Face 2 will not go to face 1 because it’s already been there. Face 3 will be added because it share the top vertex and is connected to nr 2 threw a soft edge. This recursion will go on until it reaces the other side. Then faces 1 to n have been added and the resulting normal will point up.

The top vertex normal must be calculated for each face it is apart of. In this example they will all be the same.

Thanks Abies & Tom. Very helpful articles.