[x3d-public] Negative scale and winding order

Andreas Plesch andreasplesch at gmail.com
Thu Sep 21 18:25:39 PDT 2023


Hi Joe,

On Thu, Sep 21, 2023 at 7:25 PM Joe D Williams <joedwil at earthlink.net> wrote:
>
> >This includes the script used for the conversion of the original.
> It took a bit of trial and error but all it does is:
>
> > negate all Z in the IFS points,
>
> OK,that is the equivalent of scale z -1.
> Equivalent in the fact that each polygon is translated from back to front so that for this skin, it was facing -Z but now it is facing +z. Since the polygons are flipped in z, from the outside the normals are still pointing inside; from the outside the windings are flipped from ccw to cw. For the skin, the only remedy to render the skin viewed from the outside (assuming the skin was drawn ccw) is to change ccw true to ccw false. Now the skin is visible.
> (Note that all browsers may not agree that these two changes are equivalent because the scale z=-1 may define that operation as including changing the normal instead of changing the winding.
>
> A key point may be asking: Is this a mirror image of the original? Specifically, is the original character's left, still its left after this operation?

That is an interesting perspective. I think a mirrored figure turns an
originally left arm into a right arm. If that is not as desired, a
rotation by 180 would keep a left arm a left arm. A rotation is
simpler since it also does not change insides to outsides.

> > negate all Z in the center field of the joints (had forgotten about this) and
>
> OK, this negation of the joint center z-axis may actually help in more than one way. Of course this is necessary to maintain relative alignment with the skin. Effectively, that makes the skeleton also face +z. Ithinkthisisalsoequivalent to scale z=-1.

Yes, this is of course required.

> > then also negate all Z in the OrientationInterpolators keyValues.
>
> That would be one way to do it. The other would be to negate just the scalar. From what I have seen, both are equivalent.

It turns out, as mentioned below, that negating the Z component of the
rotation axis and negating the angle of rotation are not equivalent.
In fact, it is necessary to negate both to achieve the correct
rotations on the changed geometry. Just negating the rotation axis
would keep a clockwise rotation clockwise. But due to the mirroring we
need it now counterclockwise, hence it is also necessary to negate the
angle.

> However, now we are in realm of whether we are aiming to reuse an animation developed with the original character, or aiming to use an animation developed for a 'standard' x3d character. So far I don't have learning experience of importing animationdevelopedl for+Zin but same sort ofoperationshouldapply because the handedness is changed.

I see that Leif is probably an example where a standard x3d character
animation is used for a non-standard (+Z into the plane) model. That
does seem like a recipe for trouble.

> > It is also necessary to negate all angles in the OrientationInterpolator which is not obvious but makes some sense since we are changing handedness.
>
> Right, as above, negating the scalar should work. However, the need to do this proves that just negating the joint center z does not change the handedness of the joint.

Right, the center is just a translation. It does not affect the sense
of rotation.

> This model has skin index and weights defined in +Zin and the target animations are defined in +Zout. When the skin points and joint centers are translated by negation of z, and the animations are changed from left to right-handedness by changing signs of each axis do the target animations correctly address right and left joints of the model?

I think so because all animations look correct but Leif is pretty
symmetrical. But I think what was designed as left (the left hand) is
now right (the right hand). Eg. if it is important it is the right
hand which moves (to write something), negative scaling (either by
transform or directly in the geometry) would not work.

> > Not sure if this works for all models but it is worth a try.
>
> It seems easy to deal with the skin geometry and skeleton dimensions, just handedness of animations and left-right of imported model.

-Andreas

> -----Original Message-----
> From: Andreas Plesch <andreasplesch at gmail.com>
> Sent: Sep 21, 2023 1:52 PM
> To: Joe D Williams <joedwil at earthlink.net>
> Cc: X3D Graphics public mailing list <x3d-public at web3d.org>, <holger.seelig at googlemail.com>
> Subject: Re: [x3d-public] Negative scale and winding order
>
> solid='false' works quite well:
>
> https://create3000.github.io/x_ite/playground/?url=https://gist.githubusercontent.com/andreasplesch/10ac4252e769fb7970e5eacab71fc6be/raw/eb5518d478bcf76eb6269a5873c583db540067be/Leif_solid_false.x3d
> https://andreasplesch.github.io/Library/Viewer/index.html?url=https://gist.githubusercontent.com/andreasplesch/10ac4252e769fb7970e5eacab71fc6be/raw/eb5518d478bcf76eb6269a5873c583db540067be/Leif_solid_false.x3d
>
> An attempt to convert to +Z in, eg. not using a negative scale for Z
> also seems to work:
>
> https://create3000.github.io/x_ite/playground/?url=https://gist.githubusercontent.com/andreasplesch/10ac4252e769fb7970e5eacab71fc6be/raw/958e87beef033edeed0b963cc2180b3ed2c916f9/Leif_no_negScale.x3d
> https://andreasplesch.github.io/Library/Viewer/index.html?url=https://gist.githubusercontent.com/andreasplesch/10ac4252e769fb7970e5eacab71fc6be/raw/958e87beef033edeed0b963cc2180b3ed2c916f9/Leif_no_negScale.x3d
>
> This includes the script used for the conversion of the original. It
> took a bit of trial and error but all it does is: negate all Z in the
> IFS points, negate all Z in the center field of the joints (had
> forgotten about this) and then also negate all Z in the
> OrientationInterpolators keyValues. It is also necessary to negate all
> angles in the OrientationInterpolator which is not obvious but makes
> some sense since we are changing handedness. Not sure if this works
> for all models but it is worth a try.
>
> Best, Andreas
>
>
> On Thu, Sep 21, 2023 at 1:42 PM Andreas Plesch wrote:
> >
> > In any case, it will take time to come to a solution which works
> > across browsers. So the quick fix is to use solid='false'. The real
> > solution for best compatibility would be to fix the geometry so it
> > does not need a negative scale.
> >
> > Cheers, Andreas
> >
> > On Thu, Sep 21, 2023 at 1:24 PM Joe D Williams wrote:
> > >
> > > > So perhaps the question is how to apply negative scale transforms tonormals as intended by the spec.The Leif example has ccw=false and a negative scale (for z). Itappears as outside in on x_ite and outside out on view3dscene andx3dom.
> > >
> > > Of course I am interested in this because to me the X_ITE rendering is wrong, unless that is, the player is required to reverse the normals for scale z = -1.
> > > X_ITE is 'automagically' reversing the normals, so when I do the ccw=FALSE the thing is transparent from the front of the polygon. Of course if I use ccw=TRUE then the other tools look like X_ITE, transparent from the front.
> > >
> > > Holger, can you please either convince the other players they are wrong, or fix yours to work like the rest. If the spec is not certain what to do about this, then please either fix the spec or X_ITE.
> > >
> > > I just want the model to show as intended and be correct, even if sort of a practical hack, so please l figure it out because I really need everyone to do the right thing on this, whatever that might be.
> > >
> > > . Thanks and Best Regards,
> > > Joe
> > >
> > >
> > > -----Original Message-----
> > > From: Joe D Williams
> > > Sent: Sep 19, 2023 1:26 PM
> > > To: Andreas Plesch , X3D Graphics public mailing list ,
> > > Subject: Re: [x3d-public] Negative scale and winding order
> > >
> > > >> 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.
> > >
> > > Sorry I sort of wrote this off, to both you and Holger.
> > > A good, reliable solution to this problem is needed, as learned or not from recent experience.
> > >
> > > One thing I think happened to me was seeing that common graphics authoring programs use as a 'Native' default or pre-selected +Zin with left-hand rule for axis rotations.
> > > For the Humanoid animation, we want to align ourselves in +Zout character space, so the character Front is looking out of the screen with +y up, +x to character left. In the case of x3d +Zout, the character is gaze is toward +z. In the case of +Zin, the character Front gaze is toward -z. Or, we may find the situation where the character is drawn in +Zin with gaze toward +z.
> > >
> > > For HAnim there are three main issues: skeleton and skin and animations. Well, actually these boil down into just one problem: They all have to work together. So to even consider importing stuffs drawn or animated in a different space a plan is needed. I used standard features to force display of skin because it was drawn in a different space. This almost worked everywhere.
> > >
> > > I think it should work everywhere, because the -1 for z scaling is going to operate just the same as if I had actually negated the coord points(?). Since the +Zin model with scale 1 1 1 will be seen as facing -z the character's back is toward the x3d default camera. Using scale 1 1-1 operates so that the character is now facing the x3d default camera.
> > > However, just guessing, since the polygon that was drawn ccw true is now being drawn ccw false and is now transparent from its front. Changing ccw to false seemed to get the normal aimed in the right direction.
> > >
> > > Thanks for the help,
> > > Joe
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > > -----Original Message-----
> > > From: Joe D Williams
> > > Sent: Sep 19, 2023 11:09 AM
> > > To: Andreas Plesch , X3D Graphics public mailing list
> > > Subject: Re: [x3d-public] Negative scale and winding order
> > >
> > >
> > > -----Original Message-----
> > > From: Andreas Plesch
> > > Sent: Sep 19, 2023 9:03 AM
> > > To: X3D Graphics public mailing list
> > > 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
> > >
> > >
> > >
> > > _______________________________________________
> > > x3d-public mailing list
> > > x3d-public at web3d.org
> > > http://web3d.org/mailman/listinfo/x3d-public_web3d.org
> > >
> > >
> >
> >
> > --
> > Andreas Plesch
> > Waltham, MA 02453
>
>
>
> --
> Andreas Plesch
> Waltham, MA 02453
>
>


-- 
Andreas Plesch
Waltham, MA 02453



More information about the x3d-public mailing list