Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
54ada559
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
提交
54ada559
编写于
3月 29, 2016
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OBJLoader: Clean up.
上级
7c0b2462
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
113 addition
and
102 deletion
+113
-102
examples/js/loaders/OBJLoader.js
examples/js/loaders/OBJLoader.js
+113
-102
未找到文件。
examples/js/loaders/OBJLoader.js
浏览文件 @
54ada559
...
...
@@ -65,8 +65,8 @@ THREE.OBJLoader.prototype = {
},
_createParserState
:
function
()
{
_createParserState
:
function
()
{
var
state
=
{
objects
:
[],
object
:
{},
...
...
@@ -77,14 +77,16 @@ THREE.OBJLoader.prototype = {
materialLibraries
:
[],
startObject
:
function
(
name
,
fromDeclaration
)
{
startObject
:
function
(
name
,
fromDeclaration
)
{
// If the current object (initial from reset) is not from a g/o declaration in the parsed
// file. We need to use it for the first parsed g/o to keep things in sync.
if
(
this
.
object
&&
this
.
object
.
fromDeclaration
===
false
)
{
this
.
object
.
name
=
name
;
this
.
object
.
fromDeclaration
=
(
fromDeclaration
!==
false
);
this
.
object
.
fromDeclaration
=
(
fromDeclaration
!==
false
);
return
;
}
this
.
object
=
{
...
...
@@ -98,93 +100,104 @@ THREE.OBJLoader.prototype = {
name
:
''
,
smooth
:
true
},
fromDeclaration
:
(
fromDeclaration
!==
false
)
fromDeclaration
:
(
fromDeclaration
!==
false
)
};
this
.
objects
.
push
(
this
.
object
);
this
.
objects
.
push
(
this
.
object
);
},
parseVertexIndex
:
function
(
value
,
len
)
{
parseVertexIndex
:
function
(
value
,
len
)
{
var
index
=
parseInt
(
value
,
10
);
return
(
index
>=
0
?
index
-
1
:
index
+
len
/
3
)
*
3
;
},
parseNormalIndex
:
function
(
value
,
len
)
{
parseNormalIndex
:
function
(
value
,
len
)
{
var
index
=
parseInt
(
value
,
10
);
return
(
index
>=
0
?
index
-
1
:
index
+
len
/
3
)
*
3
;
},
parseUVIndex
:
function
(
value
,
len
)
{
parseUVIndex
:
function
(
value
,
len
)
{
var
index
=
parseInt
(
value
,
10
);
return
(
index
>=
0
?
index
-
1
:
index
+
len
/
2
)
*
2
;
},
addVertex
:
function
(
a
,
b
,
c
)
{
addVertex
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
vertices
;
this
.
object
.
geometry
.
vertices
.
push
(
src
[
a
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
a
+
1
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
a
+
2
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
b
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
b
+
1
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
b
+
2
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
c
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
c
+
1
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
c
+
2
]);
var
dst
=
this
.
object
.
geometry
.
vertices
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
dst
.
push
(
src
[
a
+
2
]
);
dst
.
push
(
src
[
b
+
0
]
);
dst
.
push
(
src
[
b
+
1
]
);
dst
.
push
(
src
[
b
+
2
]
);
dst
.
push
(
src
[
c
+
0
]
);
dst
.
push
(
src
[
c
+
1
]
);
dst
.
push
(
src
[
c
+
2
]
);
},
addVertexLine
:
function
(
a
)
{
addVertexLine
:
function
(
a
)
{
var
src
=
this
.
vertices
;
this
.
object
.
geometry
.
vertices
.
push
(
src
[
a
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
a
+
1
]);
this
.
object
.
geometry
.
vertices
.
push
(
src
[
a
+
2
]);
var
dst
=
this
.
object
.
geometry
.
vertices
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
dst
.
push
(
src
[
a
+
2
]
);
},
addNormal
:
function
(
a
,
b
,
c
)
{
addNormal
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
normals
;
this
.
object
.
geometry
.
normals
.
push
(
src
[
a
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
a
+
1
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
a
+
2
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
b
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
b
+
1
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
b
+
2
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
c
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
c
+
1
]);
this
.
object
.
geometry
.
normals
.
push
(
src
[
c
+
2
]);
var
dst
=
this
.
object
.
geometry
.
normals
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
dst
.
push
(
src
[
a
+
2
]
);
dst
.
push
(
src
[
b
+
0
]
);
dst
.
push
(
src
[
b
+
1
]
);
dst
.
push
(
src
[
b
+
2
]
);
dst
.
push
(
src
[
c
+
0
]
);
dst
.
push
(
src
[
c
+
1
]
);
dst
.
push
(
src
[
c
+
2
]
);
},
addUV
:
function
(
a
,
b
,
c
)
{
addUV
:
function
(
a
,
b
,
c
)
{
var
src
=
this
.
uvs
;
this
.
object
.
geometry
.
uvs
.
push
(
src
[
a
]);
this
.
object
.
geometry
.
uvs
.
push
(
src
[
a
+
1
]);
this
.
object
.
geometry
.
uvs
.
push
(
src
[
b
]);
this
.
object
.
geometry
.
uvs
.
push
(
src
[
b
+
1
]);
this
.
object
.
geometry
.
uvs
.
push
(
src
[
c
]);
this
.
object
.
geometry
.
uvs
.
push
(
src
[
c
+
1
]);
var
dst
=
this
.
object
.
geometry
.
uvs
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
dst
.
push
(
src
[
b
+
0
]
);
dst
.
push
(
src
[
b
+
1
]
);
dst
.
push
(
src
[
c
+
0
]
);
dst
.
push
(
src
[
c
+
1
]
);
},
addUVLine
:
function
(
a
)
{
addUVLine
:
function
(
a
)
{
var
src
=
this
.
uvs
;
this
.
object
.
geometry
.
uvs
.
push
(
src
[
a
]);
this
.
object
.
geometry
.
uvs
.
push
(
src
[
a
+
1
]);
var
dst
=
this
.
object
.
geometry
.
uvs
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
},
addFace
:
function
(
a
,
b
,
c
,
d
,
ua
,
ub
,
uc
,
ud
,
na
,
nb
,
nc
,
nd
)
{
addFace
:
function
(
a
,
b
,
c
,
d
,
ua
,
ub
,
uc
,
ud
,
na
,
nb
,
nc
,
nd
)
{
var
vLen
=
this
.
vertices
.
length
;
...
...
@@ -235,15 +248,8 @@ THREE.OBJLoader.prototype = {
var
nLen
=
this
.
normals
.
length
;
ia
=
this
.
parseNormalIndex
(
na
,
nLen
);
if
(
na
===
nb
)
ib
=
ia
;
else
ib
=
this
.
parseNormalIndex
(
nb
,
nLen
);
if
(
na
===
nc
)
ic
=
ia
;
else
ic
=
this
.
parseNormalIndex
(
nc
,
nLen
);
ib
=
na
===
nb
?
ia
:
this
.
parseNormalIndex
(
nb
,
nLen
);
ic
=
na
===
nc
?
ia
:
this
.
parseNormalIndex
(
nc
,
nLen
);
if
(
d
===
undefined
)
{
...
...
@@ -262,25 +268,33 @@ THREE.OBJLoader.prototype = {
},
addLineGeometry
:
function
(
vertexes
,
uvs
)
{
addLineGeometry
:
function
(
vertices
,
uvs
)
{
this
.
object
.
geometry
.
type
=
'
Line
'
;
var
vLen
=
this
.
vertices
.
length
;
var
uvLen
=
this
.
uvs
.
length
;
for
(
var
vi
=
0
,
l
=
vertexes
.
length
;
vi
<
l
;
vi
++
)
{
this
.
addVertexLine
(
this
.
parseVertexIndex
(
vertexes
[
vi
],
vLen
)
);
for
(
var
vi
=
0
,
l
=
vertices
.
length
;
vi
<
l
;
vi
++
)
{
this
.
addVertexLine
(
this
.
parseVertexIndex
(
vertices
[
vi
],
vLen
)
);
}
for
(
var
uvi
=
0
,
l
=
uvs
.
length
;
uvi
<
l
;
uvi
++
)
{
this
.
addUVLine
(
this
.
parseUVIndex
(
uvs
[
uvi
],
uvLen
)
);
for
(
var
uvi
=
0
,
l
=
uvs
.
length
;
uvi
<
l
;
uvi
++
)
{
this
.
addUVLine
(
this
.
parseUVIndex
(
uvs
[
uvi
],
uvLen
)
);
}
}
};
state
.
startObject
(
''
,
false
);
state
.
startObject
(
''
,
false
);
return
state
;
},
parse
:
function
(
text
)
{
...
...
@@ -289,9 +303,11 @@ THREE.OBJLoader.prototype = {
var
state
=
this
.
_createParserState
();
if
(
text
.
indexOf
(
'
\r\n
'
)
!==
-
1
)
{
if
(
text
.
indexOf
(
'
\r\n
'
)
!==
-
1
)
{
// This is faster than String.split with regex that splits on both
text
=
text
.
replace
(
'
\r\n
'
,
'
\n
'
);
text
=
text
.
replace
(
'
\r\n
'
,
'
\n
'
);
}
var
lines
=
text
.
split
(
'
\n
'
);
...
...
@@ -300,26 +316,22 @@ THREE.OBJLoader.prototype = {
var
result
=
[];
// Faster to just trim left side of the line. Use if available.
var
trimLeft
=
(
typeof
''
.
trimLeft
===
'
function
'
);
var
trimLeft
=
(
typeof
''
.
trimLeft
===
'
function
'
);
for
(
var
i
=
0
,
l
=
lines
.
length
;
i
<
l
;
i
++
)
{
line
=
lines
[
i
];
if
(
trimLeft
)
line
=
line
.
trimLeft
();
else
line
=
line
.
trim
();
line
=
trimLeft
?
line
.
trimLeft
()
:
line
.
trim
();
lineLength
=
line
.
length
;
if
(
lineLength
===
0
)
{
continue
;
}
if
(
lineLength
===
0
)
continue
;
lineFirstChar
=
line
.
charAt
(
0
);
if
(
lineFirstChar
===
'
#
'
)
{
// @todo invoke passed in handler if any
continue
;
}
// @todo invoke passed in handler if any
if
(
lineFirstChar
===
'
#
'
)
continue
;
if
(
lineFirstChar
===
'
v
'
)
{
...
...
@@ -359,7 +371,7 @@ THREE.OBJLoader.prototype = {
}
else
{
throw
new
Error
(
"
Unexpected vertex/normal/uv line: '
"
+
line
+
"
'
"
);
throw
new
Error
(
"
Unexpected vertex/normal/uv line: '
"
+
line
+
"
'
"
);
}
...
...
@@ -412,31 +424,32 @@ THREE.OBJLoader.prototype = {
}
else
{
throw
new
Error
(
"
Unexpected face line: '
"
+
line
+
"
'
"
);
throw
new
Error
(
"
Unexpected face line: '
"
+
line
+
"
'
"
);
}
}
else
if
(
lineFirstChar
===
"
l
"
)
{
var
lineParts
=
line
.
substring
(
1
).
trim
().
split
(
"
"
);
var
lineVert
ex
es
=
[],
lineUVs
=
[];
var
lineParts
=
line
.
substring
(
1
).
trim
().
split
(
"
"
);
var
lineVert
ic
es
=
[],
lineUVs
=
[];
if
(
line
.
indexOf
(
"
/
"
)
===
-
1
)
{
if
(
line
.
indexOf
(
"
/
"
)
===
-
1
)
{
lineVert
ex
es
=
lineParts
;
lineVert
ic
es
=
lineParts
;
}
else
{
for
(
var
li
=
0
,
llen
=
lineParts
.
length
;
li
<
llen
;
li
++
)
{
var
parts
=
lineParts
[
li
].
split
(
"
/
"
);
if
(
parts
[
0
]
!==
""
)
lineVertexes
.
push
(
parts
[
0
]);
if
(
parts
[
1
]
!==
""
)
lineUVs
.
push
(
parts
[
1
])
for
(
var
li
=
0
,
llen
=
lineParts
.
length
;
li
<
llen
;
li
++
)
{
var
parts
=
lineParts
[
li
].
split
(
"
/
"
);
if
(
parts
[
0
]
!==
""
)
lineVertices
.
push
(
parts
[
0
]
);
if
(
parts
[
1
]
!==
""
)
lineUVs
.
push
(
parts
[
1
]
);
}
}
state
.
addLineGeometry
(
lineVertexes
,
lineUVs
);
state
.
addLineGeometry
(
lineVertices
,
lineUVs
);
}
else
if
(
(
result
=
this
.
regexp
.
object_pattern
.
exec
(
line
)
)
!==
null
)
{
...
...
@@ -445,7 +458,7 @@ THREE.OBJLoader.prototype = {
// g group_name
var
name
=
result
[
0
].
substr
(
1
).
trim
();
state
.
startObject
(
name
);
state
.
startObject
(
name
);
}
else
if
(
this
.
regexp
.
material_use_pattern
.
test
(
line
)
)
{
...
...
@@ -469,27 +482,25 @@ THREE.OBJLoader.prototype = {
}
else
{
// Handle null terminated files without exception
if
(
line
===
'
\
0
'
)
continue
;
if
(
line
===
'
\
0
'
)
continue
;
throw
new
Error
(
"
Unexpected line: '
"
+
line
+
"
'
"
);
throw
new
Error
(
"
Unexpected line: '
"
+
line
+
"
'
"
);
}
}
var
container
=
new
THREE
.
Group
();
container
.
materialLibraries
=
[].
concat
(
state
.
materialLibraries
);
container
.
materialLibraries
=
[].
concat
(
state
.
materialLibraries
);
for
(
var
i
=
0
,
l
=
state
.
objects
.
length
;
i
<
l
;
i
++
)
{
var
object
=
state
.
objects
[
i
];
var
geometry
=
object
.
geometry
;
var
isLine
=
(
geometry
.
type
===
'
Line
'
);
var
isLine
=
(
geometry
.
type
===
'
Line
'
);
// Skip o/g line declarations that did not follow with any faces
if
(
geometry
.
vertices
.
length
===
0
)
continue
;
if
(
geometry
.
vertices
.
length
===
0
)
continue
;
var
buffergeometry
=
new
THREE
.
BufferGeometry
();
...
...
@@ -518,26 +529,26 @@ THREE.OBJLoader.prototype = {
material
=
this
.
materials
.
create
(
object
.
material
.
name
);
// mtl etc. loaders probably can't create line materials correctly, copy properties to a line material.
if
(
isLine
&&
material
&&
!
(
material
instanceof
THREE
.
LineBasicMaterial
)
)
{
if
(
isLine
&&
material
&&
!
(
material
instanceof
THREE
.
LineBasicMaterial
)
)
{
var
materialLine
=
new
THREE
.
LineBasicMaterial
();
materialLine
.
copy
(
material
);
materialLine
.
copy
(
material
);
material
=
materialLine
;
}
}
if
(
!
material
)
{
if
(
!
material
)
{
material
=
(
!
isLine
?
new
THREE
.
MeshPhongMaterial
()
:
new
THREE
.
LineBasicMaterial
()
);
material
=
(
!
isLine
?
new
THREE
.
MeshPhongMaterial
()
:
new
THREE
.
LineBasicMaterial
()
);
material
.
name
=
object
.
material
.
name
;
}
material
.
shading
=
object
.
material
.
smooth
?
THREE
.
SmoothShading
:
THREE
.
FlatShading
;
var
mesh
=
(
!
isLine
?
new
THREE
.
Mesh
(
buffergeometry
,
material
)
:
new
THREE
.
Line
(
buffergeometry
,
material
)
);
var
mesh
=
(
!
isLine
?
new
THREE
.
Mesh
(
buffergeometry
,
material
)
:
new
THREE
.
Line
(
buffergeometry
,
material
)
);
mesh
.
name
=
object
.
name
;
container
.
add
(
mesh
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录