Three.js:负比例后如何翻转法线 [英] Three.js: How to flip normals after negative scale

查看:41
本文介绍了Three.js:负比例后如何翻转法线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经克隆并使用负比例翻转了一个对象,这导致我的单面反转.我的问题是,我怎样才能翻转法线?

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?

我不想使用 material.side = THREE.DoubleSide,原因如下:1) 无法正常工作(一些阴影是从内部绘制的)和 2) 想要保持尽可能多的性能.所以 DoubleSide 不适合我.

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;

提前致谢!

推荐答案

出于多种原因,我建议不要使用负比例,如以下链接所述:在three.js中转换顶点法线

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.

您可以手动遍历几何图形并翻转每个面的缠绕顺序.这可能对您有用——如果您没有应用纹理并且没有使用 UV.如果要对几何体进行纹理处理,则还需要更正 UV.

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.

实际上,几何反演实用程序是对three.js 的一个很好的补充.目前,库不支持您要执行的操作.

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

three.js r.72

这篇关于Three.js:负比例后如何翻转法线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆