Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
65a55a5e
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,发现更多精彩内容 >>
提交
65a55a5e
编写于
4月 16, 2012
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Started OBJLoader.
上级
803f4577
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
186 addition
and
0 deletion
+186
-0
examples/js/loaders/OBJLoader.js
examples/js/loaders/OBJLoader.js
+72
-0
examples/webgl_loader_obj.html
examples/webgl_loader_obj.html
+114
-0
未找到文件。
examples/js/loaders/OBJLoader.js
0 → 100644
浏览文件 @
65a55a5e
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE
.
OBJLoader
=
function
()
{};
THREE
.
OBJLoader
.
prototype
.
load
=
function
(
url
,
callback
)
{
var
xhr
=
new
XMLHttpRequest
();
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
if
(
xhr
.
status
==
200
||
xhr
.
status
==
0
)
{
THREE
.
OBJLoader
.
prototype
.
parse
(
xhr
.
responseText
,
callback
);
}
else
{
console
.
error
(
'
THREE.OBJLoader: Couldn
\'
t load
'
+
url
+
'
(
'
+
xhr
.
status
+
'
)
'
);
}
}
};
xhr
.
open
(
"
GET
"
,
url
,
true
);
xhr
.
send
(
null
);
};
THREE
.
OBJLoader
.
prototype
.
parse
=
function
(
data
,
callback
)
{
var
geometry
=
new
THREE
.
Geometry
();
var
objects
=
data
.
split
(
'
\n
o
'
);
for
(
var
i
=
0
,
il
=
objects
.
length
;
i
<
il
;
i
++
)
{
var
object
=
objects
[
i
];
var
pattern
,
result
;
// vertices
pattern
=
/v
([\-
|
\d
|.
]
+
)
([\-
|
\d
|.
]
+
)
([\-
|
\d
|.
]
+
)
/g
;
while
(
(
result
=
pattern
.
exec
(
object
)
)
!=
null
)
{
var
vertex
=
new
THREE
.
Vector3
(
parseFloat
(
result
[
1
]
),
parseFloat
(
result
[
2
]
),
parseFloat
(
result
[
3
]
)
);
geometry
.
vertices
.
push
(
vertex
);
}
// faces
pattern
=
/f
([\d]
+
)\/([\d]
+
)\/([\d]
+
)
([\d]
+
)\/([\d]
+
)\/([\d]
+
)
([\d]
+
)\/([\d]
+
)\/([\d]
+
)
/g
;
while
(
(
result
=
pattern
.
exec
(
object
)
)
!=
null
)
{
var
face
=
new
THREE
.
Face3
(
parseInt
(
result
[
1
]
)
-
1
,
parseInt
(
result
[
4
]
)
-
1
,
parseInt
(
result
[
7
]
)
-
1
);
geometry
.
faces
.
push
(
face
);
}
}
geometry
.
computeCentroids
();
callback
(
geometry
);
}
examples/webgl_loader_obj.html
0 → 100644
浏览文件 @
65a55a5e
<!doctype html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - loaders - OBJ loader
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
font-family
:
Monospace
;
background-color
:
#000
;
color
:
#fff
;
margin
:
0px
;
overflow
:
hidden
;
}
#info
{
color
:
#fff
;
position
:
absolute
;
top
:
10px
;
width
:
100%
;
text-align
:
center
;
z-index
:
100
;
display
:
block
;
}
#info
a
,
.button
{
color
:
#f00
;
font-weight
:
bold
;
text-decoration
:
underline
;
cursor
:
pointer
}
</style>
</head>
<body>
<div
id=
"info"
>
<a
href=
"http://github.com/mrdoob/three.js"
target=
"_blank"
>
three.js
</a>
- OBJLoader test
</div>
<script
src=
"../build/Three.js"
></script>
<script
src=
"js/loaders/OBJLoader.js"
></script>
<script
src=
"js/Detector.js"
></script>
<script
src=
"js/Stats.js"
></script>
<script>
var
container
,
stats
;
var
camera
,
scene
,
renderer
;
var
mouseX
=
0
,
mouseY
=
0
;
var
windowHalfX
=
window
.
innerWidth
/
2
;
var
windowHalfY
=
window
.
innerHeight
/
2
;
init
();
animate
();
function
init
()
{
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
scene
=
new
THREE
.
Scene
();
camera
=
new
THREE
.
PerspectiveCamera
(
45
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
2000
);
camera
.
position
.
z
=
100
;
scene
.
add
(
camera
);
var
loader
=
new
THREE
.
OBJLoader
();
loader
.
load
(
"
obj/female02/female02.obj
"
,
function
(
geometry
)
{
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
new
THREE
.
MeshBasicMaterial
(
{
wireframe
:
true
}
)
);
scene
.
add
(
mesh
);
}
);
// RENDERER
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
container
.
appendChild
(
renderer
.
domElement
);
document
.
addEventListener
(
'
mousemove
'
,
onDocumentMouseMove
,
false
);
}
function
onDocumentMouseMove
(
event
)
{
mouseX
=
(
event
.
clientX
-
windowHalfX
);
mouseY
=
(
event
.
clientY
-
windowHalfY
);
}
//
function
animate
()
{
requestAnimationFrame
(
animate
);
render
();
}
function
render
()
{
camera
.
position
.
x
+=
(
mouseX
-
camera
.
position
.
x
)
*
.
05
;
camera
.
position
.
y
+=
(
-
mouseY
-
camera
.
position
.
y
)
*
.
05
;
camera
.
lookAt
(
scene
.
position
);
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录