three.jsflipnormalsscaletransform

Three.js: How to flip normals after negative scale


I have cloned and than flipped an object using negative scale, which causes my single sided faces to inverse. My question is, how can i flip the normals too?

I don't want to use material.side = THREE.DoubleSide, for reasons: 1) didn't work properly (some shades are drawn from inside) and 2) wanna keep as much performance as possible. So DoubleSide isn't an option for me.

Thats how my object if flipped.

mesh.scale.x = - scale_width;

Thanks in advance!


Solution

  • I would advise against negative scale for a whole host of reasons, as explained in this link: Transforming vertex normals in three.js

    You can instead apply an inversion matrix to your geometry like so

    geometry.scale( - 1, 1, 1 );
    

    As explained in the link, a consequence to doing this, however, is the geometry faces will no longer have counterclockwise winding order, but clockwise.

    You can manually traverse your geometry and flip the winding order of each face. This may work for you -- if you do not have a texture applied and are not using UVs. If your geometry is to be textured, the UVs will need to be corrected, too.

    Actually, a geometry inversion utility would be a nice addition to three.js. Currently, what you want to do is not supported by the library.

    three.js r.72