Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
394d9bfb
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,发现更多精彩内容 >>
提交
394d9bfb
编写于
7月 04, 2017
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
STLLoader: Refactoring
上级
a33b5b65
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
133 addition
and
127 deletion
+133
-127
examples/js/loaders/STLLoader.js
examples/js/loaders/STLLoader.js
+133
-127
未找到文件。
examples/js/loaders/STLLoader.js
浏览文件 @
394d9bfb
...
...
@@ -56,10 +56,10 @@ THREE.STLLoader.prototype = {
parse
:
function
(
data
)
{
var
isBinary
=
function
(
)
{
function
isBinary
(
data
)
{
var
expect
,
face_size
,
n_faces
,
reader
;
reader
=
new
DataView
(
binD
ata
);
reader
=
new
DataView
(
d
ata
);
face_size
=
(
32
/
8
*
3
)
+
(
(
32
/
8
*
3
)
*
3
)
+
(
16
/
8
);
n_faces
=
reader
.
getUint32
(
80
,
true
);
expect
=
80
+
(
32
/
8
)
+
(
n_faces
*
face_size
);
...
...
@@ -75,6 +75,7 @@ THREE.STLLoader.prototype = {
// plentiful. So, check the first 5 bytes for 'solid'.
// US-ASCII ordinal values for 's', 'o', 'l', 'i', 'd'
var
solid
=
[
115
,
111
,
108
,
105
,
100
];
for
(
var
i
=
0
;
i
<
5
;
i
++
)
{
...
...
@@ -87,17 +88,12 @@ THREE.STLLoader.prototype = {
}
// First 5 bytes read "solid"; declare it to be an ASCII STL
return
false
;
};
var
binData
=
this
.
ensureBinary
(
data
);
return
isBinary
()
?
this
.
parseBinary
(
binData
)
:
this
.
parseASCII
(
this
.
ensureString
(
data
)
);
return
false
;
},
}
parseBinary
:
function
(
data
)
{
function
parseBinary
(
data
)
{
var
reader
=
new
DataView
(
data
);
var
faces
=
reader
.
getUint32
(
80
,
true
);
...
...
@@ -196,9 +192,9 @@ THREE.STLLoader.prototype = {
return
geometry
;
},
}
parseASCII
:
function
(
data
)
{
function
parseASCII
(
data
)
{
var
geometry
=
new
THREE
.
BufferGeometry
();
var
patternFace
=
/facet
([\s\S]
*
?)
endfacet/g
;
...
...
@@ -239,17 +235,19 @@ THREE.STLLoader.prototype = {
}
// Every face have to own ONE valid normal
// every face have to own ONE valid normal
if
(
normalCountPerFace
!==
1
)
{
throw
new
Error
(
'
Something isn
\'
t right with the normal of face number
'
+
faceCounter
);
console
.
error
(
'
THREE.STLLoader:
Something isn
\'
t right with the normal of face number
'
+
faceCounter
);
}
// Each face have to own THREE valid vertices
// each face have to own THREE valid vertices
if
(
vertexCountPerFace
!==
3
)
{
throw
new
Error
(
'
Something isn
\'
t right with the vertices of face number
'
+
faceCounter
);
console
.
error
(
'
THREE.STLLoader:
Something isn
\'
t right with the vertices of face number
'
+
faceCounter
);
}
...
...
@@ -257,18 +255,18 @@ THREE.STLLoader.prototype = {
}
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
vertices
)
,
3
)
);
geometry
.
addAttribute
(
'
normal
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
normals
)
,
3
)
);
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
Float32BufferAttribute
(
vertices
,
3
)
);
geometry
.
addAttribute
(
'
normal
'
,
new
THREE
.
Float32BufferAttribute
(
normals
,
3
)
);
return
geometry
;
},
}
ensureString
:
function
(
buf
)
{
function
ensureString
(
buffer
)
{
if
(
typeof
buf
!==
"
string
"
)
{
if
(
typeof
buffer
!==
'
string
'
)
{
var
array_buffer
=
new
Uint8Array
(
buf
);
var
array_buffer
=
new
Uint8Array
(
buffer
);
if
(
window
.
TextDecoder
!==
undefined
)
{
...
...
@@ -278,7 +276,7 @@ THREE.STLLoader.prototype = {
var
str
=
''
;
for
(
var
i
=
0
,
il
=
buf
.
byteLength
;
i
<
il
;
i
++
)
{
for
(
var
i
=
0
,
il
=
buffer
.
byteLength
;
i
<
il
;
i
++
)
{
str
+=
String
.
fromCharCode
(
array_buffer
[
i
]
);
// implicitly assumes little-endian
...
...
@@ -288,30 +286,38 @@ THREE.STLLoader.prototype = {
}
else
{
return
buf
;
return
buffer
;
}
},
}
ensureBinary
:
function
(
buf
)
{
function
ensureBinary
(
buffer
)
{
if
(
typeof
buf
===
"
string
"
)
{
if
(
typeof
buffer
===
'
string
'
)
{
var
array_buffer
=
new
Uint8Array
(
buf
.
length
);
for
(
var
i
=
0
;
i
<
buf
.
length
;
i
++
)
{
var
array_buffer
=
new
Uint8Array
(
buffer
.
length
);
for
(
var
i
=
0
;
i
<
buffer
.
length
;
i
++
)
{
array_buffer
[
i
]
=
buf
.
charCodeAt
(
i
)
&
0xff
;
// implicitly assumes little-endian
array_buffer
[
i
]
=
buffer
.
charCodeAt
(
i
)
&
0xff
;
// implicitly assumes little-endian
}
return
array_buffer
.
buffer
||
array_buffer
;
}
else
{
return
buf
;
return
buffer
;
}
}
// start
var
binData
=
ensureBinary
(
data
);
return
isBinary
(
binData
)
?
parseBinary
(
binData
)
:
parseASCII
(
ensureString
(
data
)
);
}
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录