[x3d-public] TriangleStripSet and ccw

Roy Walmsley roy.walmsley at ntlworld.com
Thu Oct 29 04:16:46 PDT 2015


Hi all,

I have reviewed the implementation of triangle strip sets with OpenGL. They are programmed as shown in the following example (from https://en.wikibooks.org/wiki/OpenGL_Programming/Basics/2DObjects):

glBegin(GL_TRIANGLE_STRIP); // draw in triangle strips
               glVertex2f(0.0f, 0.75f); // top of the roof
               glVertex2f(-0.5f, 0.25f); // left corner of the roof
               glVertex2f(0.5f, 0.25f); // right corner of the roof
               glVertex2f(-0.5f, -0.5f); // bottom left corner of the house
               glVertex2f(0.5f, -0.5f); //bottom right corner of the house
glEnd();

A triangle strip set, when discussed from the perspective of a user looking at a 2D image, does indeed have vertex ordering alternating. The ccw flag specifies the ordering for the first, and subsequent odd numbered, triangles. The even numbered triangles have the opposite ordering.

Within OpenGL, if normal are automatically calculated, then this will be taken care of internally. If normal are provided by the user, would they have to incorporate the alternating ordering? I don't know the answer to that.

If an implementation does not pass the triangle strip directly to OpenGL as above, but uses, say GL_TRIANGLES, then it must internally correct for the alternating ordering before sending each set of three vertices to OpenGL.

In my opinion the specification 19775-1 needs a sentence or two to clarify the meaning of the ccw field for both TriangleStripSet and IndexedTriangleStripSet.

As noted during our meeting yesterday, the issue does not arise with triangle fan sets, as all triangles are oriented the same way.

Regards,

Roy

-----Original Message-----
From: x3d-public [mailto:x3d-public-bounces at web3d.org] On Behalf Of simon place
Sent: 27 August 2015 16:23
To: x3d-public at web3d.org
Subject: Re: [x3d-public] TriangleStripSet and ccw

my thinking is that you could think of list-order and drawing-order, as not necessarily the same thing, then;

the definition of a Triangle Strip (see wikipedia) is telling you the drawing-order of even numbered triangles is reversed from their list-order, in which case the CCW is correct for the drawing-order.

of course this should be explicit, or refer to an external definition of triangle strip.



On 27 August 2015 at 15:08, Alekseyev, Vsevolod (NIH/NIAID) [E] <VAlekseyev at niaid.nih.gov> wrote:
> Any trivial one with 3 triangles will do.
>
>
>
>        <Scene>
>
>               <Transform>
>
>                      <Shape>
>
>                            <Appearance><Material diffuseColor="0 0.5 
> 0.5"/></Appearance>
>
>                            <IndexedTriangleStripSet index="0 1 2 3 4">
>
>                                   <Coordinate point="0 0 0 1 0 1 1 0 0 
> 2 0 1
> 2 0 0"/>
>
>                            </IndexedTriangleStripSet>
>
>                      </Shape>
>
>               </Transform>
>
>        </Scene>
>
>
>
>
>
> From: Roy Walmsley [mailto:roy.walmsley at ntlworld.com]
> Sent: Wednesday, August 26, 2015 6:49 PM
> To: Alekseyev, Vsevolod (NIH/NIAID) [E] <VAlekseyev at niaid.nih.gov>; 
> x3d-public at web3d.org
> Cc: x3d at web3d.org
> Subject: RE: [x3d-public] TriangleStripSet and ccw
>
>
>
> Vsevolod,
>
>
>
> Great catch!
>
>
>
> Tomorrow I’ll raise a Mantis issue covering this and let you know the 
> details.
>
>
>
> Do you have a reference to an X3D example file that can be used to 
> test implementations?
>
>
>
> Roy
>
>
>
> From: x3d-public [mailto:x3d-public-bounces at web3d.org] On Behalf Of 
> Alekseyev, Vsevolod (NIH/NIAID) [E]
> Sent: 24 August 2015 20:58
> To: x3d-public at web3d.org
> Subject: [x3d-public] TriangleStripSet and ccw
>
>
>
> While we’re on the topic of standard ambiguities, here’s another issue.
>
>
>
> Imagine a TriangleStripSet. It has a sequence of points with a sliding 
> window logic to them – the first triangle is points 0, 1, 2, the 
> second is 1,2,3, then 2, 3, 4, etc. It’s illustrated perfectly at 
> http://www.web3d.org/documents/specifications/19775-1/V3.3/Images/Tria
> ngleStripSet.png
>
>
>
> The element also has a ccw flag that tells us which side of the 
> triangle is the outer side.
>
>
>
> Now, the issue. If the ccw logic is to be followed *for every 
> triangle*, every second triangle would look the other way from the previous one.
>
>
>
> Look at the image. For the first triangle, the logic for determining 
> the outer side is – if you look at the triangle from the outside, 
> vertices 0, 1,
> 2 should go counterclockwise. But if you look from the same vantage 
> point at the second triangle, vertices 1, 2, 3 would go *clockwise* 
> instead. Were the algorithm to go by the strict letter of the ccw 
> rule, one would have to conclude that odd numbered triangles in the 
> strip look one way, even numbered ones look the other way.
>
>
>
> Fortunately, few implementors think so. Neither X3DOM nor X3D-Edit 
> read the standard that way. My Blender X3D importer flips the vertex 
> order for every odd triangle, too. The only implementation that does 
> not is meshlab. Upon rendering, it gives a very characteristic 
> “checkerboard” pattern – triangles that are seen from the inside are dark.
>
>
>
> The same issue would obviously plague IndexedTriangleStripSet, but not 
> [Indexed]TriangleFanSet.
>
>
>
> Maybe a clarification in the standard would be in order, that ccw only 
> applies to the *first* triangle in the strip, for the subsequent ones 
> one should go by consistent orientation of adjacent triangles.
>
>
>
> Vsevolod "Seva" Alekseyev
>
>
>
>
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org
>

_______________________________________________
x3d-public mailing list
x3d-public at web3d.org
http://web3d.org/mailman/listinfo/x3d-public_web3d.org




More information about the x3d-public mailing list