简体   繁体   English

用three.js加载obj

[英]Load obj with three.js

i'm new with three.js and in 3d graphics in general. 我是Three.js的新手,而且一般来说都是3D图形的。 I have to load a file obj, which is "high defined", actually i've found the way to load it on the screen, but it isn't well defined as i want. 我必须加载文件obj,它是“高定义的”,实际上我已经找到了将其加载到屏幕上的方法,但是它并不是我想要的很好定义的。

The file is an OBJ file, a ring with some pearl, but in the ring i see some lines and the object is not weel defined. 该文件是OBJ文件,带有一些珍珠的环,但是在环中我看到了一些线条,并且该对象未定义。 Actually i use this script to load the object: 实际上,我使用此脚本来加载对象:

            app.loadObj( {
            path: 'obj/',
            fileObj: 'prova.obj',
            pivot: pivotA,
            overdraw: true,
            instanceNo: 0
        } );

In the first picture is the ring with the lines that i'm talking about, in the second image how the ring should be rendered. 第一张图片中的环是我正在谈论的线条,第二张图片中的环是如何呈现的。 带有“删除”线的戒指

戒指应该如何 (As always, sorry for my bad English) (一如既往,对不起我的英语不好)

Looking at the OBJ file that you are loading on the site linked: Ring OBJ , I don't think you have vertex normals defined. 查看链接到的站点上正在加载的OBJ文件: Ring OBJ ,我认为您没有定义顶点法线

Take a look at the Wikipedia article on the Wavefront .obj file format . 查看有关Wavefront .obj文件格式Wikipedia文章 You will see that the way vertex normals are defined are at the face level with an index to the normal being used. 您将看到定义顶点法线的方式是在面级别上,并使用要使用的法线的索引。

For example, here is the OBJ definition of a Triangle: 例如,以下是三角形的OBJ定义:

v 0.00 0.00 0.00
v 0.00 1.00 0.00
v 1.00 0.00 0.00

vt 0.00 0.00
vt 0.00 1.00
vt 1.00 0.00

vn 0.00 0.00 1.00

f 0/0/0 1/1/0 2/2/0
  • v 0.00 0.00 0.00 defines a vertices position v 0.00 0.00 0.00定义顶点位置
  • vt 0.00 0.00 defines a texture UV position vt 0.00 0.00定义纹理UV位置
  • vn 0.00 0.00 1.00 defines a normal vn 0.00 0.00 1.00定义法线
  • f 0/0/0 1/1/0 2/2/0 defines a face that uses the indexes of each component f vertexIndex/uvIndex/normalIndex ... f 0/0/0 1/1/0 2/2/0定义使用每个分量的索引的面f vertexIndex/uvIndex/normalIndex ...

In your file, if you look all the way at the bottom, you will see that your faces are defined without normals. 在文件中,如果从头向下看,您会发现您的脸部定义没有法线。 They include a vertex index and a UV index, but no normal: 它们包括顶点索引和UV索引,但不包含法线:

v 3.462315 8.68541 -0.125
v 3.462315 8.68541 -0.497999
v 3.49977 8.670371 -0.766575
...

vt 0.166677 0 0
vt 0.166677 0.029819 0
vt 0.166677 0.052183 0
vt 0.166677 0.067092 0
...

f 1/1 8/8 25/25 
f 8/8 9/9 25/25 
f 9/9 10/10 24/24 
f 10/10 2/2 51/51 
f 2/2 11/11 49/49 
...

Because you are not providing vertex normals, Three.js is likely calculating default normals for you. 由于您没有提供顶点法线,Three.js可能会为您计算默认法线。 The easiest way to do this is per face, with no smoothing. 最简单的方法是每张脸都没有平滑感。

The calculation amounts to: cross((v1 - v0), (v2 - v0)) and this single normal is probably used for all vertices of the face which is why you get the very sharp, hard edges that you are seeing in your image. 计算总计为: cross((v1 - v0), (v2 - v0))并且该单一法线可能用于面部的所有顶点,这就是为什么您会在图像中看到非常锐利,坚硬的边缘的原因。

This is probably an issue with the way you are exporting your mesh from your modelling software. 从建模软件导出网格的方式可能是一个问题。 Go through the configuration again and make sure that you tick whatever checkbox says that you want normals included. 再次进行配置,并确保勾选要包含法线的复选框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM