[x3d-public] Negative scale and winding order

Holger Seelig holger.seelig at yahoo.de
Tue Sep 19 11:51:22 PDT 2023


I have made a small example how negative scale is handled in X_ITE:

https://create3000.github.io/x_ite/playground/?url=https://rawgit.com/create3000/Library/main/Tests/Components/Grouping/NegativeScale.x3d

https://andreasplesch.github.io/Library/Viewer/index.html?url=https://rawgit.com/create3000/Library/main/Tests/Components/Grouping/NegativeScale.x3d

It shows two models a tree and a text with its mirrored counterpart. The only thing to do is to apply a negative scale (here 1 -1 1) to the mirrored one. The important thing is that both models have solid true, which save rendering time, because only the front face must be rendered. In addition, the Shape node can be cloned which makes the file smaller. In both cases inside stays inside, and outside stays outside. You can see the text has no back faces.

In your case with the different coordinate system, also only a negative scale has to be applied to convert between left and right handed, no need to change ccw.

If the simpler approach is used to handle negative scale (no special handling), a model which has negative scale appears to be turned inside out, when solid is true. The only ways that the model is still useful now is to set solid to false, or to dupplicate the whole geometry and flip ccw, but this will either render unnecessary back faces or increases file size.

X_ITE exchanges ccw with cw if there is a negative scale in the modelViewMatrix, which undoes the effect of turning the model inside out.

--
Holger Seelig
Leipzig, Germany

holger.seelig at yahoo.de
https://create3000.github.io/x_ite/

> Am 19.09.2023 um 20:08 schrieb Joe D Williams <joedwil at earthlink.net>:
> 
> 
> -----Original Message-----
> From: Andreas Plesch <andreasplesch at gmail.com>
> Sent: Sep 19, 2023 9:03 AM
> To: X3D Graphics public mailing list <x3d-public at web3d.org>
> Subject: [x3d-public] Negative scale and winding order
> 
>> 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.
> 
> OK, I thought I tried that with no effect. 
> 
>> While this approach is very practical, I am not sure what the spec.
> actually requires in this respect. 
> 
> I did not care, it worked and I will look more later. 
> The following is all good. I think the  players show it different because the user code is changed from what I sent.
> 
>> 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 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
> 
> 
> _______________________________________________
> x3d-public mailing list
> x3d-public at web3d.org
> http://web3d.org/mailman/listinfo/x3d-public_web3d.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20230919/d906774a/attachment-0001.html>


More information about the x3d-public mailing list