[x3d-public] Negative scale and winding order

Andreas Plesch andreasplesch at gmail.com
Tue Sep 19 14:30:03 PDT 2023


Thanks for finding the gltf specification:
https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#instantiation
is the section on winding order.

To be honest, I cannot really understand the sentence but since the
implementation note says that this enables mirroring via negative
scale it must mean x_ite's or view3dscene's robust behaviour.

Of note is that gltf does not have an equivalent of the ccw field, eg.
it is not possible to swap the facing outward direction, for example
for models imported from a left handed modeling system into the
righthanded gltf coordinate system. gltf expects that geometry is
prepared correctly in the first place.

It may be instructive to find existing x3d examples which use negative
scale. There are probably not many and I do not remember any in the
large example archive.

Also note that solid=false is usually not a performance bottleneck
even if it doubles the triangles since GPU rendering is so efficient.

-Andreas

On Tue, Sep 19, 2023 at 3:48 PM Michalis Kamburelis
<michalis.kambi at gmail.com> wrote:
>
> ( Note: I didn't follow the related thread so far, so I'm not saying
> what the X3D should do and which X3D browser is "right". By I thought
> I'll add some notes what does glTF say and what does CGE/view3dscene
> do :) )
>
> CGE/view3dscene have an optional setting "Robust Negative Scale" that
> allows to support lighting and backface culling on models with
> negative scale in more obvious manner.
>
> Turning it "on" makes CGE/view3dscene follow exactly the glTF spec
> that says ( https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html
> ):
>
> """
> When a mesh primitive uses any triangle-based topology (i.e.,
> triangles, triangle strip, or triangle fan), the determinant of the
> node’s global transform defines the winding order of that primitive.
> If the determinant is a positive value, the winding order triangle
> faces is counterclockwise; in the opposite case, the winding order is
> clockwise.
>
> Implementation Note
>
> Switching the winding order to clockwise enables mirroring geometry
> via negative scale transforms.
> """
>
> One can test it in view3dscene (toggle "View -> Robust Negative Scale"
> menu item) or in Castle Game Engine editor (toggle the
> "RenderOptions.RobustNegativeScale" property of the relevant
> TCastleScene). I generally found it a useful idea and some (rare) glTF
> models rely on it. It is not enabled by default (for now) only because
> it incurs a small performance cost and is often not necessary.
>
> Regards,
> Michalis
>
> wt., 19 wrz 2023 o 18:03 Andreas Plesch <andreasplesch at gmail.com> napisał(a):
> >
> > Holger made good points on why a negative scale in the parent
> > transform should not affect which side of a geomet is considered
> > facing outward and visible with solid=true.
> >
> > While this approach is very practical, I am not sure what the spec.
> > actually requires in this respect.
> >
> > First, it does not explicitly single out the case of a negative scale.
> > Should it ? If so, it would probably have to deal with the effective
> > world transform.
> >
> > https://www.web3d.org/specifications/X3Dv4Draft/ISO-IEC19775-1v4-IS.proof/Part01/components/rendering.html#CommonGeometryFields
> >
> > 'The ccw field defines the ordering of the vertex coordinates of the
> > geometry with respect to user-given or automatically generated normal
> > vectors used in the lighting model equations. If ccw is TRUE, the
> > normals shall follow the right hand rule; the orientation of each
> > normal with respect to the vertices (taken in order) shall be such
> > that the vertices appear to be oriented in a counterclockwise order
> > when the vertices are viewed (in the local coordinate system of the
> > Shape) from the opposite direction as the normal. If ccw is FALSE, the
> > normals shall be oriented in the opposite direction. If normals are
> > not generated but are supplied using a Normal node, and the
> > orientation of the normals does not match the setting of the ccw
> > field, results are undefined.'
> >
> > has the relevant ccw field language.
> >
> > I think the specified process is:
> >
> > - Compute the outward facing normal of a triangle using the ordering
> > of the vertices in such a way that the ordering appears
> > counterclockwise when viewed in the opposite direction of the computed
> > normal. This uses the local, untransformed (raw) coordinates.
> >
> > - invert the normal if ccw=false.
> >
> > - Apply the accumulated transforms to both the vertices and the
> > computed normal. The spec. has a strict definition on how to apply a
> > transform to vertices to transform from the child space to the parent
> > space. For normals transformations there is a computer graphics
> > standard approach and probably opengl based equations but the spec.
> > itself seems to be silent.
> >
> > So perhaps the question is how to apply negative scale transforms to
> > normals as intended by the spec.
> >
> > The Leif example has ccw=false and a negative scale (for z). It
> > appears as outside in on x_ite and outside out on view3dscene and
> > x3dom.
> >
> > A workaround is solid=false but that may not always be possible or desired.
> > Another workaround is to not use negative scales/mirroring, eg.
> > preprocess geometry accordingly which seems like a major limitation.
> >
> > -Andreas
> >
> > On Tue, Sep 19, 2023 at 10:37 AM <x3d-public-request at web3d.org> wrote:
> > >
> > > Send x3d-public mailing list submissions to
> > >         x3d-public at web3d.org
> > >
> > > To subscribe or unsubscribe via the World Wide Web, visit
> > >         http://web3d.org/mailman/listinfo/x3d-public_web3d.org
> > > or, via email, send a message with subject or body 'help' to
> > >         x3d-public-request at web3d.org
> > >
> > > You can reach the person managing the list at
> > >         x3d-public-owner at web3d.org
> > >
> > > When replying, please edit your Subject line so it is more specific
> > > than "Re: Contents of x3d-public digest..."
> > >
> >
> > > 2. Negative Scale
> > >
> > > A negative scale will not affect what is front face and what is back face. This means that a Text node with solid true, mirrored with negative scale (0 -1 0), also shows its front face to the camera. This makes it possible to create a text with solid true which has a mirrored counterpart which is a clone of the Text node.
> > >
> > > A negative scale will not turn the model inside out, it stays as it is. The main advantage is as described above: we can use solid true models in many situations where a negative scale is used without flipping inside out.
> > >
> > > This effect is achieved by detecting if there is any negative scale, which can be determined if the determinant of the scale-rotation matrix is less than zero. If this is the case, ccw must be exchanged with cw and vice versa.
> >
> > _______________________________________________
> > x3d-public mailing list
> > x3d-public at web3d.org
> > http://web3d.org/mailman/listinfo/x3d-public_web3d.org



-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list