Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
5db1eb3a
T
three.js
项目概览
Ablesons
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5db1eb3a
编写于
5月 11, 2020
作者:
M
Mr.doob
提交者:
GitHub
5月 11, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19338 from Mugen87/dev49
OBJLoader: Better handle inconsistent face definitions.
上级
4e6dbb7d
397c6b19
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
144 addition
and
33 deletion
+144
-33
examples/js/loaders/OBJLoader.js
examples/js/loaders/OBJLoader.js
+71
-16
examples/jsm/loaders/OBJLoader.js
examples/jsm/loaders/OBJLoader.js
+73
-17
未找到文件。
examples/js/loaders/OBJLoader.js
浏览文件 @
5db1eb3a
...
@@ -13,6 +13,13 @@ THREE.OBJLoader = ( function () {
...
@@ -13,6 +13,13 @@ THREE.OBJLoader = ( function () {
// usemap map_name
// usemap map_name
var
map_use_pattern
=
/^usemap /
;
var
map_use_pattern
=
/^usemap /
;
var
vA
=
new
THREE
.
Vector3
();
var
vB
=
new
THREE
.
Vector3
();
var
vC
=
new
THREE
.
Vector3
();
var
ab
=
new
THREE
.
Vector3
();
var
cb
=
new
THREE
.
Vector3
();
function
ParserState
()
{
function
ParserState
()
{
var
state
=
{
var
state
=
{
...
@@ -55,7 +62,9 @@ THREE.OBJLoader = ( function () {
...
@@ -55,7 +62,9 @@ THREE.OBJLoader = ( function () {
vertices
:
[],
vertices
:
[],
normals
:
[],
normals
:
[],
colors
:
[],
colors
:
[],
uvs
:
[]
uvs
:
[],
hasNormalIndices
:
false
,
hasUVIndices
:
false
},
},
materials
:
[],
materials
:
[],
smooth
:
true
,
smooth
:
true
,
...
@@ -248,6 +257,27 @@ THREE.OBJLoader = ( function () {
...
@@ -248,6 +257,27 @@ THREE.OBJLoader = ( function () {
},
},
addFaceNormal
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
vertices
;
var
dst
=
this
.
object
.
geometry
.
normals
;
vA
.
fromArray
(
src
,
a
);
vB
.
fromArray
(
src
,
b
);
vC
.
fromArray
(
src
,
c
);
cb
.
subVectors
(
vC
,
vB
);
ab
.
subVectors
(
vA
,
vB
);
cb
.
cross
(
ab
);
cb
.
normalize
();
dst
.
push
(
cb
.
x
,
cb
.
y
,
cb
.
z
);
dst
.
push
(
cb
.
x
,
cb
.
y
,
cb
.
z
);
dst
.
push
(
cb
.
x
,
cb
.
y
,
cb
.
z
);
},
addColor
:
function
(
a
,
b
,
c
)
{
addColor
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
colors
;
var
src
=
this
.
colors
;
...
@@ -270,6 +300,16 @@ THREE.OBJLoader = ( function () {
...
@@ -270,6 +300,16 @@ THREE.OBJLoader = ( function () {
},
},
addDefaultUV
:
function
()
{
var
dst
=
this
.
object
.
geometry
.
uvs
;
dst
.
push
(
0
,
0
);
dst
.
push
(
0
,
0
);
dst
.
push
(
0
,
0
);
},
addUVLine
:
function
(
a
)
{
addUVLine
:
function
(
a
)
{
var
src
=
this
.
uvs
;
var
src
=
this
.
uvs
;
...
@@ -290,26 +330,45 @@ THREE.OBJLoader = ( function () {
...
@@ -290,26 +330,45 @@ THREE.OBJLoader = ( function () {
this
.
addVertex
(
ia
,
ib
,
ic
);
this
.
addVertex
(
ia
,
ib
,
ic
);
this
.
addColor
(
ia
,
ib
,
ic
);
this
.
addColor
(
ia
,
ib
,
ic
);
// normals
if
(
na
!==
undefined
&&
na
!==
''
)
{
var
nLen
=
this
.
normals
.
length
;
ia
=
this
.
parseNormalIndex
(
na
,
nLen
);
ib
=
this
.
parseNormalIndex
(
nb
,
nLen
);
ic
=
this
.
parseNormalIndex
(
nc
,
nLen
);
this
.
addNormal
(
ia
,
ib
,
ic
);
this
.
object
.
geometry
.
hasNormalIndices
=
true
;
}
else
{
this
.
addFaceNormal
(
ia
,
ib
,
ic
);
}
// uvs
if
(
ua
!==
undefined
&&
ua
!==
''
)
{
if
(
ua
!==
undefined
&&
ua
!==
''
)
{
var
uvLen
=
this
.
uvs
.
length
;
var
uvLen
=
this
.
uvs
.
length
;
ia
=
this
.
parseUVIndex
(
ua
,
uvLen
);
ia
=
this
.
parseUVIndex
(
ua
,
uvLen
);
ib
=
this
.
parseUVIndex
(
ub
,
uvLen
);
ib
=
this
.
parseUVIndex
(
ub
,
uvLen
);
ic
=
this
.
parseUVIndex
(
uc
,
uvLen
);
ic
=
this
.
parseUVIndex
(
uc
,
uvLen
);
this
.
addUV
(
ia
,
ib
,
ic
);
}
this
.
addUV
(
ia
,
ib
,
ic
);
if
(
na
!==
undefined
&&
na
!==
''
)
{
this
.
object
.
geometry
.
hasUVIndices
=
true
;
// Normals are many times the same. If so, skip function call and parseInt.
}
else
{
var
nLen
=
this
.
normals
.
length
;
ia
=
this
.
parseNormalIndex
(
na
,
nLen
);
ib
=
na
===
nb
?
ia
:
this
.
parseNormalIndex
(
nb
,
nLen
);
// add placeholder values (for inconsistent face definitions)
ic
=
na
===
nc
?
ia
:
this
.
parseNormalIndex
(
nc
,
nLen
);
this
.
add
Normal
(
ia
,
ib
,
ic
);
this
.
add
DefaultUV
(
);
}
}
...
@@ -652,14 +711,10 @@ THREE.OBJLoader = ( function () {
...
@@ -652,14 +711,10 @@ THREE.OBJLoader = ( function () {
buffergeometry
.
setAttribute
(
'
position
'
,
new
THREE
.
Float32BufferAttribute
(
geometry
.
vertices
,
3
)
);
buffergeometry
.
setAttribute
(
'
position
'
,
new
THREE
.
Float32BufferAttribute
(
geometry
.
vertices
,
3
)
);
if
(
geometry
.
normals
.
length
>
0
)
{
if
(
geometry
.
hasNormalIndices
===
true
)
{
buffergeometry
.
setAttribute
(
'
normal
'
,
new
THREE
.
Float32BufferAttribute
(
geometry
.
normals
,
3
)
);
buffergeometry
.
setAttribute
(
'
normal
'
,
new
THREE
.
Float32BufferAttribute
(
geometry
.
normals
,
3
)
);
}
else
{
buffergeometry
.
computeVertexNormals
();
}
}
if
(
geometry
.
colors
.
length
>
0
)
{
if
(
geometry
.
colors
.
length
>
0
)
{
...
@@ -669,7 +724,7 @@ THREE.OBJLoader = ( function () {
...
@@ -669,7 +724,7 @@ THREE.OBJLoader = ( function () {
}
}
if
(
geometry
.
uvs
.
length
>
0
)
{
if
(
geometry
.
hasUVIndices
===
true
)
{
buffergeometry
.
setAttribute
(
'
uv
'
,
new
THREE
.
Float32BufferAttribute
(
geometry
.
uvs
,
2
)
);
buffergeometry
.
setAttribute
(
'
uv
'
,
new
THREE
.
Float32BufferAttribute
(
geometry
.
uvs
,
2
)
);
...
...
examples/jsm/loaders/OBJLoader.js
浏览文件 @
5db1eb3a
...
@@ -14,7 +14,8 @@ import {
...
@@ -14,7 +14,8 @@ import {
Mesh
,
Mesh
,
MeshPhongMaterial
,
MeshPhongMaterial
,
Points
,
Points
,
PointsMaterial
PointsMaterial
,
Vector3
}
from
"
../../../build/three.module.js
"
;
}
from
"
../../../build/three.module.js
"
;
var
OBJLoader
=
(
function
()
{
var
OBJLoader
=
(
function
()
{
...
@@ -28,6 +29,13 @@ var OBJLoader = ( function () {
...
@@ -28,6 +29,13 @@ var OBJLoader = ( function () {
// usemap map_name
// usemap map_name
var
map_use_pattern
=
/^usemap /
;
var
map_use_pattern
=
/^usemap /
;
var
vA
=
new
Vector3
();
var
vB
=
new
Vector3
();
var
vC
=
new
Vector3
();
var
ab
=
new
Vector3
();
var
cb
=
new
Vector3
();
function
ParserState
()
{
function
ParserState
()
{
var
state
=
{
var
state
=
{
...
@@ -70,7 +78,9 @@ var OBJLoader = ( function () {
...
@@ -70,7 +78,9 @@ var OBJLoader = ( function () {
vertices
:
[],
vertices
:
[],
normals
:
[],
normals
:
[],
colors
:
[],
colors
:
[],
uvs
:
[]
uvs
:
[],
hasNormalIndices
:
false
,
hasUVIndices
:
false
},
},
materials
:
[],
materials
:
[],
smooth
:
true
,
smooth
:
true
,
...
@@ -263,6 +273,27 @@ var OBJLoader = ( function () {
...
@@ -263,6 +273,27 @@ var OBJLoader = ( function () {
},
},
addFaceNormal
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
vertices
;
var
dst
=
this
.
object
.
geometry
.
normals
;
vA
.
fromArray
(
src
,
a
);
vB
.
fromArray
(
src
,
b
);
vC
.
fromArray
(
src
,
c
);
cb
.
subVectors
(
vC
,
vB
);
ab
.
subVectors
(
vA
,
vB
);
cb
.
cross
(
ab
);
cb
.
normalize
();
dst
.
push
(
cb
.
x
,
cb
.
y
,
cb
.
z
);
dst
.
push
(
cb
.
x
,
cb
.
y
,
cb
.
z
);
dst
.
push
(
cb
.
x
,
cb
.
y
,
cb
.
z
);
},
addColor
:
function
(
a
,
b
,
c
)
{
addColor
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
colors
;
var
src
=
this
.
colors
;
...
@@ -285,6 +316,16 @@ var OBJLoader = ( function () {
...
@@ -285,6 +316,16 @@ var OBJLoader = ( function () {
},
},
addDefaultUV
:
function
()
{
var
dst
=
this
.
object
.
geometry
.
uvs
;
dst
.
push
(
0
,
0
);
dst
.
push
(
0
,
0
);
dst
.
push
(
0
,
0
);
},
addUVLine
:
function
(
a
)
{
addUVLine
:
function
(
a
)
{
var
src
=
this
.
uvs
;
var
src
=
this
.
uvs
;
...
@@ -305,26 +346,45 @@ var OBJLoader = ( function () {
...
@@ -305,26 +346,45 @@ var OBJLoader = ( function () {
this
.
addVertex
(
ia
,
ib
,
ic
);
this
.
addVertex
(
ia
,
ib
,
ic
);
this
.
addColor
(
ia
,
ib
,
ic
);
this
.
addColor
(
ia
,
ib
,
ic
);
// normals
if
(
na
!==
undefined
&&
na
!==
''
)
{
var
nLen
=
this
.
normals
.
length
;
ia
=
this
.
parseNormalIndex
(
na
,
nLen
);
ib
=
this
.
parseNormalIndex
(
nb
,
nLen
);
ic
=
this
.
parseNormalIndex
(
nc
,
nLen
);
this
.
addNormal
(
ia
,
ib
,
ic
);
this
.
object
.
geometry
.
hasNormalIndices
=
true
;
}
else
{
this
.
addFaceNormal
(
ia
,
ib
,
ic
);
}
// uvs
if
(
ua
!==
undefined
&&
ua
!==
''
)
{
if
(
ua
!==
undefined
&&
ua
!==
''
)
{
var
uvLen
=
this
.
uvs
.
length
;
var
uvLen
=
this
.
uvs
.
length
;
ia
=
this
.
parseUVIndex
(
ua
,
uvLen
);
ia
=
this
.
parseUVIndex
(
ua
,
uvLen
);
ib
=
this
.
parseUVIndex
(
ub
,
uvLen
);
ib
=
this
.
parseUVIndex
(
ub
,
uvLen
);
ic
=
this
.
parseUVIndex
(
uc
,
uvLen
);
ic
=
this
.
parseUVIndex
(
uc
,
uvLen
);
this
.
addUV
(
ia
,
ib
,
ic
);
}
this
.
addUV
(
ia
,
ib
,
ic
);
if
(
na
!==
undefined
&&
na
!==
''
)
{
this
.
object
.
geometry
.
hasUVIndices
=
true
;
// Normals are many times the same. If so, skip function call and parseInt.
}
else
{
var
nLen
=
this
.
normals
.
length
;
ia
=
this
.
parseNormalIndex
(
na
,
nLen
);
ib
=
na
===
nb
?
ia
:
this
.
parseNormalIndex
(
nb
,
nLen
);
// add placeholder values (for inconsistent face definitions)
ic
=
na
===
nc
?
ia
:
this
.
parseNormalIndex
(
nc
,
nLen
);
this
.
add
Normal
(
ia
,
ib
,
ic
);
this
.
add
DefaultUV
(
);
}
}
...
@@ -667,14 +727,10 @@ var OBJLoader = ( function () {
...
@@ -667,14 +727,10 @@ var OBJLoader = ( function () {
buffergeometry
.
setAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
geometry
.
vertices
,
3
)
);
buffergeometry
.
setAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
geometry
.
vertices
,
3
)
);
if
(
geometry
.
normals
.
length
>
0
)
{
if
(
geometry
.
hasNormalIndices
===
true
)
{
buffergeometry
.
setAttribute
(
'
normal
'
,
new
Float32BufferAttribute
(
geometry
.
normals
,
3
)
);
buffergeometry
.
setAttribute
(
'
normal
'
,
new
Float32BufferAttribute
(
geometry
.
normals
,
3
)
);
}
else
{
buffergeometry
.
computeVertexNormals
();
}
}
if
(
geometry
.
colors
.
length
>
0
)
{
if
(
geometry
.
colors
.
length
>
0
)
{
...
@@ -684,7 +740,7 @@ var OBJLoader = ( function () {
...
@@ -684,7 +740,7 @@ var OBJLoader = ( function () {
}
}
if
(
geometry
.
uvs
.
length
>
0
)
{
if
(
geometry
.
hasUVIndices
===
true
)
{
buffergeometry
.
setAttribute
(
'
uv
'
,
new
Float32BufferAttribute
(
geometry
.
uvs
,
2
)
);
buffergeometry
.
setAttribute
(
'
uv
'
,
new
Float32BufferAttribute
(
geometry
.
uvs
,
2
)
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录