相关网页
为什么 unity 中正方体网格的顶点数量为 24?_unity quad顶点数_Beetxm_的博客-CSDN博客
你知道Unity3D中一个cube有几个顶点吗?_unity顶点数_Marco&GalaxyDragon的博客-CSDN博客
为什么Unity中的顶点数比Max中的多?_blender unity 顶点数量不一致-CSDN博客
为什么是24个顶点?因为盒子的尖角处不是1个顶点,是3个重合的顶点,从法线图里就看的很明显:
这个图就很形象:
Splitting Up Verticies - Questions & Answers - Unity Discussions
实验
obj文件,是个cube,里面有8个顶点12个面。
# 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware
# 创建的文件:11.04.2023 13:05:22
#
# object Box001
#
v -15.0000 -15.0000 15.0000
v -15.0000 -15.0000 -15.0000
v 15.0000 -15.0000 -15.0000
v 15.0000 -15.0000 15.0000
v -15.0000 15.0000 15.0000
v 15.0000 15.0000 15.0000
v 15.0000 15.0000 -15.0000
v -15.0000 15.0000 -15.0000
# 8 vertices
g Box001
f 1 2 3
f 3 4 1
f 5 6 7
f 7 8 5
f 1 4 6
f 6 5 1
f 4 3 7
f 7 6 4
f 3 2 8
f 8 7 3
f 2 1 5
f 5 8 2
# 12 faces
导入unity:
8个顶点变24个顶点
12个面还是12个面
解决方法1
直接把法线设置成无就行了:
顶点依旧是8个:
就是没有法线,也就没有光照了。
解决方法2
如果既不想改变顶点数量,又想要光照的话,可以这么搞:
操作方法
关于模型导入面板的介绍:
Unity模型导入相关知识_unity导入fbx_虫虫!的博客-CSDN博客
设置方法:
Imported model vertex count doesn't match .obj file - Unity Forum

结果:
关于光滑
大概是这种感觉:
How to get a smooth mesh for Unity? - Questions & Answers - Unity Discussions
聊聊图形学中的Flat shading、Gouraud shading、Phong shading - 知乎 (zhihu.com)
拉到180,180是最大的角度了,所以,所有的edge都需要光滑。光滑,类似高斯模糊的那种感觉。你中有我,我中有你。
拉到0,所有的edge都没有光滑,就挺硬,硬边界,泾渭分明。
相关代码
完了的话,可以打印一下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShowNormals : MonoBehaviour
{
MeshFilter meshFilter = null;
int vertexNum = 0;
Vector3[] vertices = null;
Vector3[] normals = null;
// Start is called before the first frame update
void Start()
{
meshFilter = GetComponent<MeshFilter>();
vertexNum = meshFilter.mesh.vertexCount;
vertices = meshFilter.mesh.vertices;
GetComponent<MeshFilter>().mesh.RecalculateNormals();
normals = meshFilter.mesh.normals;
int[] triangles = meshFilter.mesh.triangles;
Debug.Log("顶点数"+vertexNum+"三角形数"+triangles.Length/3);
for(int i = 0;i<triangles.Length/3;i++){
Debug.Log(triangles[i*3+0]+" "+triangles[i*3+1]+" "+triangles[i*3+2]);
}
}
// Update is called once per frame
void Update()
{
// 可视化法线
for(int i=0;i<vertexNum;i++){
Debug.DrawLine(vertices[i] , vertices[i] + 15 * normals[i],Color.green,1000,true);
}
}
}
把内容都打印出来,和obj里的稍微有点不一样……
因为obj里顶点索引是从1开始算的,unity里是从0开始算的
比如第一个面,obj里是1,2,3;unity里打印的是0,2,1。unity里都加1就是1,3,2。
为什么顺序不一样呢,可能是因为3dmax和unity坐标系不同,顶点排列顺序就是反的,它顺时针,它逆时针什么的。
总体是对的上的。
百度:
OBJ import changes vertex order with Optimize Mesh set to "Nothing" - Unity Forum