Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
11c166dd
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,发现更多精彩内容 >>
提交
11c166dd
编写于
11月 17, 2015
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
VTKLoader clean up.
上级
70759607
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
91 addition
and
97 deletion
+91
-97
examples/js/loaders/VTKLoader.js
examples/js/loaders/VTKLoader.js
+91
-97
未找到文件。
examples/js/loaders/VTKLoader.js
浏览文件 @
11c166dd
/**
*
Origin: https://github.com/mrdoob/three.js/blob/af21991fc7c4e1d35d6a93031707273d937af0f9/examples/js/loaders/VTKLoader.js
* @author
mrdoob / http://mrdoob.com/ and
Alex Pletzer
*
@author mrdoob / http://mrdoob.com/
* @author Alex Pletzer
*/
THREE
.
VTKLoader
=
function
(
manager
)
{
...
...
@@ -14,30 +14,22 @@ THREE.VTKLoader.prototype = {
constructor
:
THREE
.
VTKLoader
,
load
:
function
(
url
,
onLoad
,
onProgress
,
onError
)
{
// Will we bump into trouble reading the whole file into memory?
var
scope
=
this
;
var
loader
=
new
THREE
.
XHRLoader
(
scope
.
manager
);
loader
.
setCrossOrigin
(
this
.
crossOrigin
);
loader
.
load
(
url
,
function
(
text
)
{
onLoad
(
scope
.
parse
(
text
)
);
},
},
onProgress
,
onError
);
},
setCrossOrigin
:
function
(
value
)
{
this
.
crossOrigin
=
value
;
},
parse
:
function
(
data
)
{
// connectivity of the triangles
var
indices
=
[];
...
...
@@ -65,7 +57,7 @@ THREE.VTKLoader.prototype = {
// indicates start of polygon connectivity section
var
patPOLYGONS
=
/^POLYGONS /
;
// POINT_DATA number_of_values
// POINT_DATA number_of_values
var
patPOINT_DATA
=
/^POINT_DATA
[
]
+
(\d
+
)
/
;
// CELL_DATA number_of_polys
...
...
@@ -84,153 +76,153 @@ THREE.VTKLoader.prototype = {
var
inColorSection
=
false
;
var
inNormalsSection
=
false
;
var
lines
=
data
.
split
(
'
\n
'
);
var
lines
=
data
.
split
(
'
\n
'
);
for
(
var
i
in
lines
)
{
var
line
=
lines
[
i
];
if
(
inPointsSection
)
{
// get the vertices
while
(
(
result
=
pat3Floats
.
exec
(
line
)
)
!==
null
)
{
var
x
=
parseFloat
(
result
[
1
]
);
var
y
=
parseFloat
(
result
[
2
]
);
var
z
=
parseFloat
(
result
[
3
]
);
positions
.
push
(
x
,
y
,
z
);
}
}
else
if
(
inPolygonsSection
)
{
if
(
(
result
=
patConnectivity
.
exec
(
line
)
)
!==
null
)
{
// numVertices i0 i1 i2 ...
var
numVertices
=
parseInt
(
result
[
1
]
);
var
inds
=
result
[
2
].
split
(
/
\s
+/
);
var
inds
=
result
[
2
].
split
(
/
\s
+/
);
if
(
numVertices
>=
3
)
{
var
i0
=
parseInt
(
inds
[
0
]
);
var
i1
,
i2
;
var
k
=
1
;
// split the polygon in numVertices - 2 triangles
for
(
var
j
=
0
;
j
<
numVertices
-
2
;
++
j
)
{
for
(
var
j
=
0
;
j
<
numVertices
-
2
;
++
j
)
{
i1
=
parseInt
(
inds
[
k
]
);
i2
=
parseInt
(
inds
[
k
+
1
]
);
indices
.
push
(
i0
,
i1
,
i2
);
k
++
;
indices
.
push
(
i0
,
i1
,
i2
);
k
++
;
}
}
}
}
else
if
(
inPointDataSection
||
inCellDataSection
)
{
if
(
inColorSection
)
{
// Get the colors
while
(
(
result
=
pat3Floats
.
exec
(
line
)
)
!==
null
)
{
var
r
=
parseFloat
(
result
[
1
]
);
var
g
=
parseFloat
(
result
[
2
]
);
var
b
=
parseFloat
(
result
[
3
]
);
colors
.
push
(
r
,
g
,
b
);
}
}
else
if
(
inNormalsSection
)
{
// Get the normal vectors
while
(
(
result
=
pat3Floats
.
exec
(
line
)
)
!==
null
)
{
var
nx
=
parseFloat
(
result
[
1
]
);
var
ny
=
parseFloat
(
result
[
2
]
);
var
nz
=
parseFloat
(
result
[
3
]
);
normals
.
push
(
nx
,
ny
,
nz
);
}
}
}
if
(
patPOLYGONS
.
exec
(
line
)
!==
null
)
{
inPolygonsSection
=
true
;
inPointsSection
=
false
;
}
else
if
(
patPOINTS
.
exec
(
line
)
!==
null
)
{
inPolygonsSection
=
false
;
inPointsSection
=
true
;
}
else
if
(
patPOINT_DATA
.
exec
(
line
)
!==
null
)
{
inPointDataSection
=
true
;
inPointsSection
=
false
;
inPolygonsSection
=
false
;
}
else
if
(
patCELL_DATA
.
exec
(
line
)
!==
null
)
{
inCellDataSection
=
true
;
inPointsSection
=
false
;
inPolygonsSection
=
false
;
}
else
if
(
patCOLOR_SCALARS
.
exec
(
line
)
!==
null
)
{
inColorSection
=
true
;
inNormalsSection
=
false
;
inPointsSection
=
false
;
inPolygonsSection
=
false
;
}
else
if
(
patNORMALS
.
exec
(
line
)
!==
null
)
{
inNormalsSection
=
true
;
inColorSection
=
false
;
inPointsSection
=
false
;
inPolygonsSection
=
false
;
}
}
var
geometry
;
var
stagger
=
'
point
'
;
if
(
colors
.
length
==
indices
.
length
)
{
stagger
=
'
cell
'
;
}
if
(
stagger
==
'
point
'
)
{
// Nodal. Use BufferGeometry
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
addAttribute
(
'
index
'
,
new
THREE
.
BufferAttribute
(
new
(
indices
.
length
>
65535
?
Uint32Array
:
Uint16Array
)(
indices
),
1
)
);
geometry
.
setIndex
(
new
THREE
.
BufferAttribute
(
new
(
indices
.
length
>
65535
?
Uint32Array
:
Uint16Array
)(
indices
),
1
)
);
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
positions
),
3
)
);
if
(
colors
.
length
==
positions
.
length
)
{
geometry
.
addAttribute
(
'
color
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
colors
),
3
)
);
}
if
(
normals
.
length
==
positions
.
length
)
{
geometry
.
addAttribute
(
'
normal
'
,
new
THREE
.
BufferAttribute
(
new
Float32Array
(
normals
),
3
)
);
}
}
else
{
// Cell centered colors. The only way to attach a solid color to each triangle
// is to use Geometry, which is less efficient than BufferGeometry
geometry
=
new
THREE
.
Geometry
();
...
...
@@ -243,42 +235,44 @@ THREE.VTKLoader.prototype = {
var
x
,
y
,
z
;
var
r
,
g
,
b
;
for
(
var
j
=
0
;
j
<
numPoints
;
++
j
)
{
x
=
positions
[
3
*
j
+
0
];
y
=
positions
[
3
*
j
+
1
];
z
=
positions
[
3
*
j
+
2
];
for
(
var
j
=
0
;
j
<
numPoints
;
++
j
)
{
x
=
positions
[
3
*
j
+
0
];
y
=
positions
[
3
*
j
+
1
];
z
=
positions
[
3
*
j
+
2
];
geometry
.
vertices
.
push
(
new
THREE
.
Vector3
(
x
,
y
,
z
)
);
}
for
(
var
i
=
0
;
i
<
numTriangles
;
++
i
)
{
ia
=
indices
[
3
*
i
+
0
];
ib
=
indices
[
3
*
i
+
1
];
ic
=
indices
[
3
*
i
+
2
];
for
(
var
i
=
0
;
i
<
numTriangles
;
++
i
)
{
ia
=
indices
[
3
*
i
+
0
];
ib
=
indices
[
3
*
i
+
1
];
ic
=
indices
[
3
*
i
+
2
];
geometry
.
faces
.
push
(
new
THREE
.
Face3
(
ia
,
ib
,
ic
)
);
}
if
(
colors
.
length
==
numTriangles
*
3
)
{
for
(
var
i
=
0
;
i
<
numTriangles
;
++
i
)
{
face
=
geometry
.
faces
[
i
];
r
=
colors
[
3
*
i
+
0
];
g
=
colors
[
3
*
i
+
1
];
b
=
colors
[
3
*
i
+
2
];
for
(
var
i
=
0
;
i
<
numTriangles
;
++
i
)
{
face
=
geometry
.
faces
[
i
];
r
=
colors
[
3
*
i
+
0
];
g
=
colors
[
3
*
i
+
1
];
b
=
colors
[
3
*
i
+
2
];
face
.
color
=
new
THREE
.
Color
().
setRGB
(
r
,
g
,
b
);
}
}
}
return
geometry
;
}
};
THREE
.
EventDispatcher
.
prototype
.
apply
(
THREE
.
VTKLoader
.
prototype
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录