计算法线时纹理模糊

发布于 2025-01-19 08:11:39 字数 705 浏览 2 评论 0原文

我正在计算使用行进立方体算法生成的网格的法线,但是当我运行它时,对象看起来像图片中一样模糊。 使用代码生成的网格图像

变量: CurrentTri 是一个 Vector3int,包含每个顶点的索引 CurrentNorm 是具有当前法线的 Vector3 Verts 是顶点位置的 Vector3 数组 VertNorm 是顶点法线的 Vector3 数组

我计算法线的 C# 代码:

// Repeated for each triangle
CurrentNorm = Vector3.Cross(Verts[CurrentTri.y] - Verts[CurrentTri.x], Verts[CurrentTri.z] - Verts[CurrentTri.x]);

VertNorm[CurrentTri.x] += CurrentNorm;
VertNorm[CurrentTri.y] += CurrentNorm;
VertNorm[CurrentTri.z] += CurrentNorm;

标准化法线:

for(int i = 0; i < VertNorm.Length; i++)
{
    VertNorm[i] = VertNorm[i].normalized;
}
mesh.normals = VertNorm;

I'm calculating the normals of a mesh that I've generated using the marching cubes algorithm but when I run it the object looks blurry like in the picture.
Image of a mesh generated using the code

Variables:
CurrentTri is a Vector3int with the indexes of each vertex
CurrentNorm is a Vector3 with the current normal
Verts is a Vector3 array of the positions of the vertices
VertNorm is a Vector3 array of the normals of the vertices

The c# code where I calculate the normals:

// Repeated for each triangle
CurrentNorm = Vector3.Cross(Verts[CurrentTri.y] - Verts[CurrentTri.x], Verts[CurrentTri.z] - Verts[CurrentTri.x]);

VertNorm[CurrentTri.x] += CurrentNorm;
VertNorm[CurrentTri.y] += CurrentNorm;
VertNorm[CurrentTri.z] += CurrentNorm;

Normalising the normals:

for(int i = 0; i < VertNorm.Length; i++)
{
    VertNorm[i] = VertNorm[i].normalized;
}
mesh.normals = VertNorm;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路弥 2025-01-26 08:11:39

应该这样(我认为)。我是个白痴。

It's supposed to be like that (I think). I was a complete idiot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文