Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
8919ca32
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,发现更多精彩内容 >>
提交
8919ca32
编写于
7月 06, 2017
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OBJLoader: Clean up.
上级
2e08e1f4
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
284 addition
and
296 deletion
+284
-296
examples/js/loaders/OBJLoader.js
examples/js/loaders/OBJLoader.js
+284
-296
未找到文件。
examples/js/loaders/OBJLoader.js
浏览文件 @
8919ca32
...
...
@@ -2,70 +2,32 @@
* @author mrdoob / http://mrdoob.com/
*/
THREE
.
OBJLoader
=
function
(
manager
)
{
THREE
.
OBJLoader
=
(
function
(
)
{
this
.
manager
=
(
manager
!==
undefined
)
?
manager
:
THREE
.
DefaultLoadingManager
;
this
.
materials
=
null
;
this
.
regexp
=
{
// v float float float
vertex_pattern
:
/^v
\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)
/
,
var
vertex_pattern
=
/^v
\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)
/
;
// vn float float float
normal_pattern
:
/^vn
\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)
/
,
var
normal_pattern
=
/^vn
\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)
/
;
// vt float float
uv_pattern
:
/^vt
\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)
/
,
var
uv_pattern
=
/^vt
\s
+
([\d\.\+\-
eE
]
+
)\s
+
([\d\.\+\-
eE
]
+
)
/
;
// f vertex vertex vertex
face_vertex
:
/^f
\s
+
(
-
?\d
+
)\s
+
(
-
?\d
+
)\s
+
(
-
?\d
+
)(?:\s
+
(
-
?\d
+
))?
/
,
var
face_vertex
=
/^f
\s
+
(
-
?\d
+
)\s
+
(
-
?\d
+
)\s
+
(
-
?\d
+
)(?:\s
+
(
-
?\d
+
))?
/
;
// f vertex/uv vertex/uv vertex/uv
face_vertex_uv
:
/^f
\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)(?:\s
+
(
-
?\d
+
)\/(
-
?\d
+
))?
/
,
var
face_vertex_uv
=
/^f
\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)(?:\s
+
(
-
?\d
+
)\/(
-
?\d
+
))?
/
;
// f vertex/uv/normal vertex/uv/normal vertex/uv/normal
face_vertex_uv_normal
:
/^f
\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
)(?:\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
))?
/
,
var
face_vertex_uv_normal
=
/^f
\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
)(?:\s
+
(
-
?\d
+
)\/(
-
?\d
+
)\/(
-
?\d
+
))?
/
;
// f vertex//normal vertex//normal vertex//normal
face_vertex_normal
:
/^f
\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
)(?:\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
))?
/
,
var
face_vertex_normal
=
/^f
\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
)\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
)(?:\s
+
(
-
?\d
+
)\/\/(
-
?\d
+
))?
/
;
// o object_name | g group_name
object_pattern
:
/^
[
og
]\s
*
(
.+
)?
/
,
var
object_pattern
=
/^
[
og
]\s
*
(
.+
)?
/
;
// s boolean
smoothing_pattern
:
/^s
\s
+
(\d
+|on|off
)
/
,
var
smoothing_pattern
=
/^s
\s
+
(\d
+|on|off
)
/
;
// mtllib file_reference
material_library_pattern
:
/^mtllib /
,
var
material_library_pattern
=
/^mtllib /
;
// usemtl material_name
material_use_pattern
:
/^usemtl /
};
};
THREE
.
OBJLoader
.
prototype
=
{
constructor
:
THREE
.
OBJLoader
,
load
:
function
(
url
,
onLoad
,
onProgress
,
onError
)
{
var
material_use_pattern
=
/^usemtl /
;
var
scope
=
this
;
var
loader
=
new
THREE
.
FileLoader
(
scope
.
manager
);
loader
.
setPath
(
this
.
path
);
loader
.
load
(
url
,
function
(
text
)
{
onLoad
(
scope
.
parse
(
text
)
);
},
onProgress
,
onError
);
},
setPath
:
function
(
value
)
{
this
.
path
=
value
;
},
setMaterials
:
function
(
materials
)
{
this
.
materials
=
materials
;
},
_createParserState
:
function
()
{
function
ParserState
()
{
var
state
=
{
objects
:
[],
...
...
@@ -178,7 +140,7 @@ THREE.OBJLoader.prototype = {
if
(
end
&&
this
.
materials
.
length
>
1
)
{
for
(
var
mi
=
this
.
materials
.
length
-
1
;
mi
>=
0
;
mi
--
)
{
if
(
this
.
materials
[
mi
].
groupCount
<=
0
)
{
if
(
this
.
materials
[
mi
].
groupCount
<=
0
)
{
this
.
materials
.
splice
(
mi
,
1
);
}
}
...
...
@@ -254,15 +216,9 @@ THREE.OBJLoader.prototype = {
var
src
=
this
.
vertices
;
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
]
);
dst
.
push
(
src
[
a
+
0
],
src
[
a
+
1
],
src
[
a
+
2
]
);
dst
.
push
(
src
[
b
+
0
],
src
[
b
+
1
],
src
[
b
+
2
]
);
dst
.
push
(
src
[
c
+
0
],
src
[
c
+
1
],
src
[
c
+
2
]
);
},
...
...
@@ -271,9 +227,7 @@ THREE.OBJLoader.prototype = {
var
src
=
this
.
vertices
;
var
dst
=
this
.
object
.
geometry
.
vertices
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
dst
.
push
(
src
[
a
+
2
]
);
dst
.
push
(
src
[
a
+
0
],
src
[
a
+
1
],
src
[
a
+
2
]
);
},
...
...
@@ -282,15 +236,9 @@ THREE.OBJLoader.prototype = {
var
src
=
this
.
normals
;
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
]
);
dst
.
push
(
src
[
a
+
0
],
src
[
a
+
1
],
src
[
a
+
2
]
);
dst
.
push
(
src
[
b
+
0
],
src
[
b
+
1
],
src
[
b
+
2
]
);
dst
.
push
(
src
[
c
+
0
],
src
[
c
+
1
],
src
[
c
+
2
]
);
},
...
...
@@ -299,12 +247,9 @@ THREE.OBJLoader.prototype = {
var
src
=
this
.
uvs
;
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
]
);
dst
.
push
(
src
[
a
+
0
],
src
[
a
+
1
]
);
dst
.
push
(
src
[
b
+
0
],
src
[
b
+
1
]
);
dst
.
push
(
src
[
c
+
0
],
src
[
c
+
1
]
);
},
...
...
@@ -313,8 +258,7 @@ THREE.OBJLoader.prototype = {
var
src
=
this
.
uvs
;
var
dst
=
this
.
object
.
geometry
.
uvs
;
dst
.
push
(
src
[
a
+
0
]
);
dst
.
push
(
src
[
a
+
1
]
);
dst
.
push
(
src
[
a
+
0
],
src
[
a
+
1
]
);
},
...
...
@@ -416,13 +360,53 @@ THREE.OBJLoader.prototype = {
return
state
;
}
//
function
OBJLoader
(
manager
)
{
this
.
manager
=
(
manager
!==
undefined
)
?
manager
:
THREE
.
DefaultLoadingManager
;
this
.
materials
=
null
;
};
OBJLoader
.
prototype
=
{
constructor
:
OBJLoader
,
load
:
function
(
url
,
onLoad
,
onProgress
,
onError
)
{
var
scope
=
this
;
var
loader
=
new
THREE
.
FileLoader
(
scope
.
manager
);
loader
.
setPath
(
this
.
path
);
loader
.
load
(
url
,
function
(
text
)
{
onLoad
(
scope
.
parse
(
text
)
);
},
onProgress
,
onError
);
},
setPath
:
function
(
value
)
{
this
.
path
=
value
;
},
setMaterials
:
function
(
materials
)
{
this
.
materials
=
materials
;
},
parse
:
function
(
text
)
{
console
.
time
(
'
OBJLoader
'
);
var
state
=
this
.
_create
ParserState
();
var
state
=
new
ParserState
();
if
(
text
.
indexOf
(
'
\r\n
'
)
!==
-
1
)
{
...
...
@@ -465,7 +449,7 @@ THREE.OBJLoader.prototype = {
lineSecondChar
=
line
.
charAt
(
1
);
if
(
lineSecondChar
===
'
'
&&
(
result
=
this
.
regexp
.
vertex_pattern
.
exec
(
line
)
)
!==
null
)
{
if
(
lineSecondChar
===
'
'
&&
(
result
=
vertex_pattern
.
exec
(
line
)
)
!==
null
)
{
// 0 1 2 3
// ["v 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
...
...
@@ -476,7 +460,7 @@ THREE.OBJLoader.prototype = {
parseFloat
(
result
[
3
]
)
);
}
else
if
(
lineSecondChar
===
'
n
'
&&
(
result
=
this
.
regexp
.
normal_pattern
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
lineSecondChar
===
'
n
'
&&
(
result
=
normal_pattern
.
exec
(
line
)
)
!==
null
)
{
// 0 1 2 3
// ["vn 1.0 2.0 3.0", "1.0", "2.0", "3.0"]
...
...
@@ -487,7 +471,7 @@ THREE.OBJLoader.prototype = {
parseFloat
(
result
[
3
]
)
);
}
else
if
(
lineSecondChar
===
'
t
'
&&
(
result
=
this
.
regexp
.
uv_pattern
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
lineSecondChar
===
'
t
'
&&
(
result
=
uv_pattern
.
exec
(
line
)
)
!==
null
)
{
// 0 1 2
// ["vt 0.1 0.2", "0.1", "0.2"]
...
...
@@ -505,7 +489,7 @@ THREE.OBJLoader.prototype = {
}
else
if
(
lineFirstChar
===
"
f
"
)
{
if
(
(
result
=
this
.
regexp
.
face_vertex_uv_normal
.
exec
(
line
)
)
!==
null
)
{
if
(
(
result
=
face_vertex_uv_normal
.
exec
(
line
)
)
!==
null
)
{
// f vertex/uv/normal vertex/uv/normal vertex/uv/normal
// 0 1 2 3 4 5 6 7 8 9 10 11 12
...
...
@@ -517,7 +501,7 @@ THREE.OBJLoader.prototype = {
result
[
3
],
result
[
6
],
result
[
9
],
result
[
12
]
);
}
else
if
(
(
result
=
this
.
regexp
.
face_vertex_uv
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
(
result
=
face_vertex_uv
.
exec
(
line
)
)
!==
null
)
{
// f vertex/uv vertex/uv vertex/uv
// 0 1 2 3 4 5 6 7 8
...
...
@@ -528,7 +512,7 @@ THREE.OBJLoader.prototype = {
result
[
2
],
result
[
4
],
result
[
6
],
result
[
8
]
);
}
else
if
(
(
result
=
this
.
regexp
.
face_vertex_normal
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
(
result
=
face_vertex_normal
.
exec
(
line
)
)
!==
null
)
{
// f vertex//normal vertex//normal vertex//normal
// 0 1 2 3 4 5 6 7 8
...
...
@@ -540,7 +524,7 @@ THREE.OBJLoader.prototype = {
result
[
2
],
result
[
4
],
result
[
6
],
result
[
8
]
);
}
else
if
(
(
result
=
this
.
regexp
.
face_vertex
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
(
result
=
face_vertex
.
exec
(
line
)
)
!==
null
)
{
// f vertex vertex vertex
// 0 1 2 3 4
...
...
@@ -579,7 +563,7 @@ THREE.OBJLoader.prototype = {
}
state
.
addLineGeometry
(
lineVertices
,
lineUVs
);
}
else
if
(
(
result
=
this
.
regexp
.
object_pattern
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
(
result
=
object_pattern
.
exec
(
line
)
)
!==
null
)
{
// o object_name
// or
...
...
@@ -591,19 +575,19 @@ THREE.OBJLoader.prototype = {
state
.
startObject
(
name
);
}
else
if
(
this
.
regexp
.
material_use_pattern
.
test
(
line
)
)
{
}
else
if
(
material_use_pattern
.
test
(
line
)
)
{
// material
state
.
object
.
startMaterial
(
line
.
substring
(
7
).
trim
(),
state
.
materialLibraries
);
}
else
if
(
this
.
regexp
.
material_library_pattern
.
test
(
line
)
)
{
}
else
if
(
material_library_pattern
.
test
(
line
)
)
{
// mtl file
state
.
materialLibraries
.
push
(
line
.
substring
(
7
).
trim
()
);
}
else
if
(
(
result
=
this
.
regexp
.
smoothing_pattern
.
exec
(
line
)
)
!==
null
)
{
}
else
if
(
(
result
=
smoothing_pattern
.
exec
(
line
)
)
!==
null
)
{
// smooth shading
...
...
@@ -687,7 +671,7 @@ THREE.OBJLoader.prototype = {
for
(
var
mi
=
0
,
miLen
=
materials
.
length
;
mi
<
miLen
;
mi
++
)
{
var
sourceMaterial
=
materials
[
mi
];
var
sourceMaterial
=
materials
[
mi
];
var
material
=
undefined
;
if
(
this
.
materials
!==
null
)
{
...
...
@@ -726,7 +710,7 @@ THREE.OBJLoader.prototype = {
for
(
var
mi
=
0
,
miLen
=
materials
.
length
;
mi
<
miLen
;
mi
++
)
{
var
sourceMaterial
=
materials
[
mi
];
var
sourceMaterial
=
materials
[
mi
];
buffergeometry
.
addGroup
(
sourceMaterial
.
groupStart
,
sourceMaterial
.
groupCount
,
mi
);
}
...
...
@@ -750,4 +734,8 @@ THREE.OBJLoader.prototype = {
}
};
};
return
OBJLoader
;
}
)();
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录