Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
99ae5a15
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,发现更多精彩内容 >>
提交
99ae5a15
编写于
9月 29, 2016
作者:
M
Michael Herzog
提交者:
Mr.doob
9月 29, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PLYLoader: BufferGeometry and Blender style (#9796)
上级
cce25aa5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
76 addition
and
77 deletion
+76
-77
examples/js/loaders/PLYLoader.js
examples/js/loaders/PLYLoader.js
+74
-75
examples/webgl_loader_ply.html
examples/webgl_loader_ply.html
+2
-2
未找到文件。
examples/js/loaders/PLYLoader.js
浏览文件 @
99ae5a15
...
...
@@ -64,7 +64,7 @@ THREE.PLYLoader.prototype = {
function
isASCII
(
data
)
{
var
header
=
parseHeader
(
bin2str
(
data
)
);
return
header
.
format
===
"
ascii
"
;
return
header
.
format
===
'
ascii
'
;
}
...
...
@@ -86,7 +86,7 @@ THREE.PLYLoader.prototype = {
function
parseHeader
(
data
)
{
var
patternHeader
=
/ply
([\s\S]
*
)
end_header
\s
/
;
var
headerText
=
""
;
var
headerText
=
''
;
var
headerLength
=
0
;
var
result
=
patternHeader
.
exec
(
data
);
...
...
@@ -138,28 +138,28 @@ THREE.PLYLoader.prototype = {
var
line
=
lines
[
i
];
line
=
line
.
trim
();
if
(
line
===
""
)
continue
;
if
(
line
===
''
)
continue
;
lineValues
=
line
.
split
(
/
\s
+/
);
lineType
=
lineValues
.
shift
();
line
=
lineValues
.
join
(
"
"
);
line
=
lineValues
.
join
(
'
'
);
switch
(
lineType
)
{
case
"
format
"
:
case
'
format
'
:
header
.
format
=
lineValues
[
0
];
header
.
version
=
lineValues
[
1
];
break
;
case
"
comment
"
:
case
'
comment
'
:
header
.
comments
.
push
(
line
);
break
;
case
"
element
"
:
case
'
element
'
:
if
(
currentElement
!==
undefined
)
{
...
...
@@ -174,7 +174,7 @@ THREE.PLYLoader.prototype = {
break
;
case
"
property
"
:
case
'
property
'
:
currentElement
.
properties
.
push
(
make_ply_element_property
(
lineValues
,
scope
.
propertyNameMapping
)
);
...
...
@@ -183,7 +183,7 @@ THREE.PLYLoader.prototype = {
default
:
console
.
log
(
"
unhandled
"
,
lineType
,
lineValues
);
console
.
log
(
'
unhandled
'
,
lineType
,
lineValues
);
}
...
...
@@ -224,7 +224,7 @@ THREE.PLYLoader.prototype = {
for
(
var
i
=
0
;
i
<
properties
.
length
;
i
++
)
{
if
(
properties
[
i
].
type
===
"
list
"
)
{
if
(
properties
[
i
].
type
===
'
list
'
)
{
var
list
=
[];
var
n
=
parseASCIINumber
(
values
.
shift
(),
properties
[
i
].
countType
);
...
...
@@ -253,14 +253,20 @@ THREE.PLYLoader.prototype = {
// PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
var
geometry
=
new
THREE
.
Geometry
();
var
buffer
=
{
indices
:
[],
vertices
:
[],
normals
:
[],
uvs
:
[],
colors
:
[]
};
var
result
;
var
header
=
parseHeader
(
data
);
var
patternBody
=
/end_header
\s([\s\S]
*
)
$/
;
var
body
=
""
;
var
body
=
''
;
if
(
(
result
=
patternBody
.
exec
(
data
)
)
!==
null
)
{
body
=
result
[
1
];
...
...
@@ -270,13 +276,12 @@ THREE.PLYLoader.prototype = {
var
lines
=
body
.
split
(
'
\n
'
);
var
currentElement
=
0
;
var
currentElementCount
=
0
;
geometry
.
useColor
=
false
;
for
(
var
i
=
0
;
i
<
lines
.
length
;
i
++
)
{
var
line
=
lines
[
i
];
line
=
line
.
trim
();
if
(
line
===
""
)
{
if
(
line
===
''
)
{
continue
;
...
...
@@ -291,31 +296,42 @@ THREE.PLYLoader.prototype = {
var
element
=
parseASCIIElement
(
header
.
elements
[
currentElement
].
properties
,
line
);
handleElement
(
geometry
,
header
.
elements
[
currentElement
].
name
,
element
);
handleElement
(
buffer
,
header
.
elements
[
currentElement
].
name
,
element
);
currentElementCount
++
;
}
return
postProcess
(
geometry
);
return
postProcess
(
buffer
);
}
function
postProcess
(
geometry
)
{
function
postProcess
(
buffer
)
{
if
(
geometry
.
useColor
)
{
var
geometry
=
new
THREE
.
BufferGeometry
();
for
(
var
i
=
0
;
i
<
geometry
.
faces
.
length
;
i
++
)
{
// mandatory buffer data
geometry
.
faces
[
i
].
vertexColors
=
[
geometry
.
colors
[
geometry
.
faces
[
i
].
a
],
geometry
.
colors
[
geometry
.
faces
[
i
].
b
],
geometry
.
colors
[
geometry
.
faces
[
i
].
c
]
];
geometry
.
setIndex
(
(
buffer
.
indices
.
length
>
65535
?
THREE
.
Uint32Attribute
:
THREE
.
Uint16Attribute
)(
buffer
.
indices
,
1
)
);
geometry
.
addAttribute
(
'
position
'
,
THREE
.
Float32Attribute
(
buffer
.
vertices
,
3
)
);
}
// optional buffer data
if
(
buffer
.
normals
.
length
>
0
)
{
geometry
.
addAttribute
(
'
normal
'
,
THREE
.
Float32Attribute
(
buffer
.
normals
,
3
)
);
}
if
(
buffer
.
uvs
.
length
>
0
)
{
geometry
.
elementsNeedUpdate
=
true
;
geometry
.
addAttribute
(
'
uv
'
,
THREE
.
Float32Attribute
(
buffer
.
uvs
,
2
)
);
}
if
(
buffer
.
colors
.
length
>
0
)
{
geometry
.
addAttribute
(
'
color
'
,
THREE
.
Float32Attribute
(
buffer
.
colors
,
3
)
);
}
...
...
@@ -325,61 +341,42 @@ THREE.PLYLoader.prototype = {
}
function
handleElement
(
geometry
,
elementName
,
element
)
{
function
handleElement
(
buffer
,
elementName
,
element
)
{
if
(
elementName
===
"
vertex
"
)
{
if
(
elementName
===
'
vertex
'
)
{
geometry
.
vertices
.
push
(
new
THREE
.
Vector3
(
element
.
x
,
element
.
y
,
element
.
z
)
);
buffer
.
vertices
.
push
(
element
.
x
,
element
.
y
,
element
.
z
);
if
(
'
red
'
in
element
&&
'
green
'
in
element
&&
'
blue
'
in
element
)
{
if
(
'
nx
'
in
element
&&
'
ny
'
in
element
&&
'
nz
'
in
element
)
{
buffer
.
normals
.
push
(
element
.
nx
,
element
.
ny
,
element
.
nz
);
geometry
.
useColor
=
true
;
}
if
(
'
s
'
in
element
&&
'
t
'
in
element
)
{
var
color
=
new
THREE
.
Color
();
color
.
setRGB
(
element
.
red
/
255.0
,
element
.
green
/
255.0
,
element
.
blue
/
255.0
);
geometry
.
colors
.
push
(
color
);
buffer
.
uvs
.
push
(
element
.
s
,
element
.
t
);
}
}
else
if
(
elementName
===
"
face
"
)
{
if
(
'
red
'
in
element
&&
'
green
'
in
element
&&
'
blue
'
in
element
)
{
var
vertex_indices
=
element
.
vertex_indices
;
var
texcoord
=
element
.
texcoord
;
buffer
.
colors
.
push
(
element
.
red
/
255.0
,
element
.
green
/
255.0
,
element
.
blue
/
255.0
);
if
(
vertex_indices
.
length
===
3
)
{
}
geometry
.
faces
.
push
(
new
THREE
.
Face3
(
vertex_indices
[
0
],
vertex_indices
[
1
],
vertex_indices
[
2
]
)
);
}
else
if
(
elementName
===
'
face
'
)
{
if
(
texcoord
)
{
geometry
.
faceVertexUvs
[
0
].
push
(
[
new
THREE
.
Vector2
(
texcoord
[
0
],
texcoord
[
1
]),
new
THREE
.
Vector2
(
texcoord
[
2
],
texcoord
[
3
]),
new
THREE
.
Vector2
(
texcoord
[
4
],
texcoord
[
5
])
]
);
}
var
vertex_indices
=
element
.
vertex_indices
||
element
.
vertex_index
;
// issue #9338
if
(
vertex_indices
.
length
===
3
)
{
buffer
.
indices
.
push
(
vertex_indices
[
0
],
vertex_indices
[
1
],
vertex_indices
[
2
]
);
}
else
if
(
vertex_indices
.
length
===
4
)
{
geometry
.
faces
.
push
(
new
THREE
.
Face3
(
vertex_indices
[
0
],
vertex_indices
[
1
],
vertex_indices
[
3
]
),
new
THREE
.
Face3
(
vertex_indices
[
1
],
vertex_indices
[
2
],
vertex_indices
[
3
]
)
);
if
(
texcoord
)
{
geometry
.
faceVertexUvs
[
0
].
push
(
[
new
THREE
.
Vector2
(
texcoord
[
0
],
texcoord
[
1
]),
new
THREE
.
Vector2
(
texcoord
[
2
],
texcoord
[
3
]),
new
THREE
.
Vector2
(
texcoord
[
6
],
texcoord
[
7
])
],
[
new
THREE
.
Vector2
(
texcoord
[
2
],
texcoord
[
3
]),
new
THREE
.
Vector2
(
texcoord
[
4
],
texcoord
[
5
]),
new
THREE
.
Vector2
(
texcoord
[
6
],
texcoord
[
7
])
]
);
}
buffer
.
indices
.
push
(
vertex_indices
[
0
],
vertex_indices
[
1
],
vertex_indices
[
3
]
);
buffer
.
indices
.
push
(
vertex_indices
[
1
],
vertex_indices
[
2
],
vertex_indices
[
3
]
);
}
...
...
@@ -412,7 +409,7 @@ THREE.PLYLoader.prototype = {
for
(
var
i
=
0
;
i
<
properties
.
length
;
i
++
)
{
if
(
properties
[
i
].
type
===
"
list
"
)
{
if
(
properties
[
i
].
type
===
'
list
'
)
{
var
list
=
[];
...
...
@@ -446,10 +443,16 @@ THREE.PLYLoader.prototype = {
function
parseBinary
(
data
)
{
var
geometry
=
new
THREE
.
Geometry
();
var
buffer
=
{
indices
:
[],
vertices
:
[],
normals
:
[],
uvs
:
[],
colors
:
[]
};
var
header
=
parseHeader
(
bin2str
(
data
)
);
var
little_endian
=
(
header
.
format
===
"
binary_little_endian
"
);
var
little_endian
=
(
header
.
format
===
'
binary_little_endian
'
);
var
body
=
new
DataView
(
data
,
header
.
headerLength
);
var
result
,
loc
=
0
;
...
...
@@ -461,20 +464,18 @@ THREE.PLYLoader.prototype = {
loc
+=
result
[
1
];
var
element
=
result
[
0
];
handleElement
(
geometry
,
header
.
elements
[
currentElement
].
name
,
element
);
handleElement
(
buffer
,
header
.
elements
[
currentElement
].
name
,
element
);
}
}
return
postProcess
(
geometry
);
return
postProcess
(
buffer
);
}
//
console
.
time
(
'
PLYLoader
'
);
var
geometry
;
var
scope
=
this
;
...
...
@@ -488,8 +489,6 @@ THREE.PLYLoader.prototype = {
}
console
.
timeEnd
(
'
PLYLoader
'
);
return
geometry
;
}
...
...
examples/webgl_loader_ply.html
浏览文件 @
99ae5a15
...
...
@@ -92,9 +92,9 @@
var
loader
=
new
THREE
.
PLYLoader
();
loader
.
load
(
'
./models/ply/ascii/dolphins.ply
'
,
function
(
geometry
)
{
geometry
.
compute
Face
Normals
();
geometry
.
compute
Vertex
Normals
();
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x0055ff
}
);
var
material
=
new
THREE
.
MeshStandardMaterial
(
{
color
:
0x0055ff
,
shading
:
THREE
.
FlatShading
}
);
var
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
mesh
.
position
.
y
=
-
0.25
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录