Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
7021f821
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,发现更多精彩内容 >>
提交
7021f821
编写于
7月 31, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Created MD2Loader. Forcing it to little-endian by now.
上级
1f27dafe
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
180 addition
and
0 deletion
+180
-0
examples/js/loaders/MD2Loader.js
examples/js/loaders/MD2Loader.js
+180
-0
未找到文件。
examples/js/loaders/MD2Loader.js
0 → 100644
浏览文件 @
7021f821
/**
* @author mrdoob / http://mrdoob.com/
*/
THREE
.
MD2Loader
=
function
(
manager
)
{
this
.
manager
=
(
manager
!==
undefined
)
?
manager
:
THREE
.
DefaultLoadingManager
;
};
THREE
.
MD2Loader
.
prototype
=
{
constructor
:
THREE
.
MD2Loader
,
load
:
function
(
url
,
onLoad
,
onProgress
,
onError
)
{
var
scope
=
this
;
var
loader
=
new
THREE
.
XHRLoader
(
scope
.
manager
);
loader
.
setCrossOrigin
(
this
.
crossOrigin
);
loader
.
setResponseType
(
'
arraybuffer
'
);
loader
.
load
(
url
,
function
(
buffer
)
{
onLoad
(
scope
.
parse
(
buffer
)
);
},
onProgress
,
onError
);
},
setCrossOrigin
:
function
(
value
)
{
this
.
crossOrigin
=
value
;
},
parse
:
function
(
buffer
)
{
var
data
=
new
DataView
(
buffer
);
// http://tfc.duke.free.fr/coding/md2-specs-en.html
var
header
=
{};
var
headerNames
=
[
'
ident
'
,
'
version
'
,
'
skinwidth
'
,
'
skinheight
'
,
'
framesize
'
,
'
num_skins
'
,
'
num_vertices
'
,
'
num_st
'
,
'
num_tris
'
,
'
num_glcmds
'
,
'
num_frames
'
,
'
offset_skins
'
,
'
offset_st
'
,
'
offset_tris
'
,
'
offset_frames
'
,
'
offset_glcmds
'
,
'
offset_end
'
];
for
(
var
i
=
0
;
i
<
headerNames
.
length
;
i
++
)
{
header
[
headerNames
[
i
]
]
=
data
.
getInt32
(
i
*
4
,
true
);
}
if
(
header
.
ident
!==
844121161
||
header
.
version
!==
8
)
{
console
.
error
(
'
Not a valid MD2 file
'
);
return
;
}
if
(
header
.
offset_end
!==
data
.
byteLength
)
{
console
.
error
(
'
Corrupted MD2 file
'
);
return
;
}
//
var
geometry
=
new
THREE
.
Geometry
();
// uvs
var
uvs
=
[];
var
offset
=
header
.
offset_st
;
for
(
var
i
=
0
;
i
<
header
.
num_st
;
i
++
,
offset
+=
4
)
{
var
u
=
data
.
getInt16
(
offset
+
0
,
true
);
var
v
=
data
.
getInt16
(
offset
+
2
,
true
);
var
uv
=
new
THREE
.
Vector2
(
u
/
header
.
skinwidth
,
1
-
(
v
/
header
.
skinheight
)
);
uvs
.
push
(
uv
);
}
// triangles
var
offset
=
header
.
offset_tris
;
for
(
var
i
=
0
;
i
<
header
.
num_tris
;
i
++
)
{
var
a
=
data
.
getUint16
(
offset
+
0
,
true
);
var
b
=
data
.
getUint16
(
offset
+
2
,
true
);
var
c
=
data
.
getUint16
(
offset
+
4
,
true
);
var
face
=
new
THREE
.
Face3
(
a
,
b
,
c
);
geometry
.
faces
.
push
(
face
);
geometry
.
faceVertexUvs
[
0
].
push
(
[
uvs
[
data
.
getUint16
(
offset
+
6
,
true
)
],
uvs
[
data
.
getUint16
(
offset
+
8
,
true
)
],
uvs
[
data
.
getUint16
(
offset
+
10
,
true
)
]
]
);
offset
+=
12
;
}
// frames
var
translation
=
new
THREE
.
Vector3
();
var
scale
=
new
THREE
.
Vector3
();
var
offset
=
header
.
offset_frames
;
for
(
var
i
=
0
;
i
<
header
.
num_frames
;
i
++
)
{
scale
.
set
(
data
.
getFloat32
(
offset
+
0
,
true
),
data
.
getFloat32
(
offset
+
4
,
true
),
data
.
getFloat32
(
offset
+
8
,
true
)
);
translation
.
set
(
data
.
getFloat32
(
offset
+
12
,
true
),
data
.
getFloat32
(
offset
+
16
,
true
),
data
.
getFloat32
(
offset
+
20
,
true
)
);
offset
+=
24
;
var
string
=
[];
for
(
var
j
=
0
;
j
<
16
;
j
++
)
{
string
[
j
]
=
data
.
getUint8
(
offset
+
j
,
true
);
}
var
frame
=
{
name
:
String
.
fromCharCode
.
apply
(
null
,
string
),
vertices
:
[]
};
offset
+=
16
;
for
(
var
j
=
0
;
j
<
header
.
num_vertices
;
j
++
)
{
var
x
=
data
.
getUint8
(
offset
++
,
true
);
var
y
=
data
.
getUint8
(
offset
++
,
true
);
var
z
=
data
.
getUint8
(
offset
++
,
true
);
var
n
=
data
.
getUint8
(
offset
++
,
true
);
var
vertex
=
new
THREE
.
Vector3
(
x
*
scale
.
x
+
translation
.
x
,
z
*
scale
.
z
+
translation
.
z
,
y
*
scale
.
y
+
translation
.
y
);
frame
.
vertices
.
push
(
vertex
);
}
geometry
.
morphTargets
.
push
(
frame
);
}
geometry
.
vertices
=
geometry
.
morphTargets
[
0
].
vertices
;
return
geometry
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录