【发布时间】:2014-09-15 11:30:23
【问题描述】:
我大约 2 天尝试做的是在运行时导入网格: http://wiki.unity3d.com/index.php?title=ObjImporter
我一共找到了 3 个进口商,一个是我必须支付的,一个可能是上述进口商的修改版本,还有一个是我现在拥有的。
我要导入它:
ObjImporter objImporter = new ObjImporter();
Holder.ModelMesh = objImporter.ImportFile("./file.obj");
很遗憾,我收到了这个错误:
IndexOutOfRangeException: Array index is out of range.
ObjImporter.populateMeshStruct (.meshStruct& mesh) (at Assets/OBJReader/ObjImporter.cs:218)
ObjImporter.ImportFile (System.String filePath) (at Assets/OBJReader/ObjImporter.cs:33)
哪个指向:
temp.z = System.Convert.ToInt32(brokenBrokenString[2]);
而且我完全不知道它为什么会这样做......我不知道如何修复它,因为我没有编写那个脚本,所以我请求一些帮助,说明它为什么不能按预期工作。
其他信息: 可以找到我尝试加载的文件,因为我可以在脚本中将名称更改为“file.b”,它告诉我它无法加载,而当我放入 .obj 时,它告诉那一侧没有错误。 我还尝试了其他 2 个同样失败的文件。
编辑 我还尝试注释掉那条线,结果很奇怪:模型在那里,但我的相机无缘无故地出现了一些奇怪的形状......
【问题讨论】:
-
仅供以后阅读本文的人阅读,如果您对导入网格上的闪电有任何问题,只需在 importfile 方法中执行此操作即可:
Mesh mesh = new Mesh();mesh.vertices = newVerts;mesh.uv = newUVs;mesh.normals = newNormals;mesh.triangles = newMesh.triangles;// Auto-calculate vertex normals from the meshmesh.RecalculateNormals(); //added and it miraculously fixed the lightning issues on the mesh!mesh.RecalculateBounds();mesh.Optimize();return mesh;