您现在的位置是:首页 >学无止境 >obj导入unity顶点数量改变网站首页学无止境

obj导入unity顶点数量改变

averagePerson 2024-06-17 10:14:33
简介obj导入unity顶点数量改变

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个面

直接把法线设置成无就行了:

顶点依旧是8个:

就是没有法线,也就没有光照了。

如果既不想改变顶点数量,又想要光照的话,可以这么搞:

Imported model vertex count doesn't match .obj file - Unity Forum

关于unity的模型导入面板的介绍:

(86条消息) Unity模型导入相关知识_unity 模型导入设置_canon_卡农的博客-CSDN博客

完了的话,可以打印一下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Print : MonoBehaviour
{
    MeshFilter meshFilter;
    // 用来存放顶点数据
    int vertexNum;
    private Vector3[] points;
    int indexNum;
    int[] index;

    // Start is called before the first frame update
    void Start()
    {
        meshFilter = GetComponent<MeshFilter>();
        vertexNum = meshFilter.mesh.vertexCount;
        points = meshFilter.mesh.vertices;
        indexNum = meshFilter.mesh.triangles.Length;
        index = meshFilter.mesh.triangles;

        print("顶点数:" + vertexNum + "三角形数:" + indexNum/3);

        for(int i = 0; i < vertexNum; i++)
        {
            print(points[i]);
        }

        for(int i = 0; i < indexNum/3; i++)
        {
            print(index[i * 3 + 0] + " " + index[i * 3 + 1] + " " + index[i * 3 + 2]);
        }
    }
    // Update is called once per frame
    void Update()
    {
        
    }
}

把内容都打印出来,和obj里的稍微有点不一样…… 

百度:

When 3d models (OBJ) are imported into Unity, the Unity editor apparently adds more vertices to it. I found a workaround to get the number of vertices back to the original, but it messes up the original indices of vertices. Any idea how to fix this? : r/Unity3D (reddit.com)

OBJ import changes vertex order with Optimize Mesh set to "Nothing" - Unity Forum

3DS Max -> Unity Morphing Vertex problem? - Unity Forum 

 不知道咋弄,顶点顺序就先乱着吧……数量符合就行。

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。