Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
70cc5f70
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,发现更多精彩内容 >>
未验证
提交
70cc5f70
编写于
9月 05, 2018
作者:
M
Mr.doob
提交者:
GitHub
9月 05, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14862 from Glinkis/patch-3
Update VRMLLoader to use or create an indexed geometry.
上级
9ff1e253
3c37371c
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
102 addition
and
47 deletion
+102
-47
examples/js/loaders/VRMLLoader.js
examples/js/loaders/VRMLLoader.js
+102
-47
未找到文件。
examples/js/loaders/VRMLLoader.js
浏览文件 @
70cc5f70
...
@@ -912,91 +912,144 @@ THREE.VRMLLoader.prototype = {
...
@@ -912,91 +912,144 @@ THREE.VRMLLoader.prototype = {
}
}
var
skip
=
0
;
// some shapes only have vertices for use in other shapes
// some shapes only have vertices for use in other shapes
if
(
data
.
coordIndex
)
{
if
(
data
.
coordIndex
)
{
function
triangulateIndexArray
(
indexArray
)
{
var
triangulatedIndexArray
=
[];
var
ccw
=
data
.
ccw
===
undefined
?
true
:
data
.
ccw
;
// ccw is true by default
var
skip
=
0
;
for
(
i
=
0
,
il
=
indexArray
.
length
;
i
<
il
;
i
++
)
{
var
indexedFace
=
data
.
coordIndex
[
i
];
// VRML support multipoint indexed face sets (more then 3 vertices). You must calculate the composing triangles here
skip
=
0
;
while
(
indexedFace
.
length
>=
3
&&
skip
<
(
indexedFace
.
length
-
2
)
)
{
var
i1
=
indexedFace
[
0
];
var
i2
=
indexedFace
[
skip
+
(
ccw
?
1
:
2
)
];
var
i3
=
indexedFace
[
skip
+
(
ccw
?
2
:
1
)
];
triangulatedIndexArray
.
push
(
i1
,
i2
,
i3
);
skip
++
;
}
}
return
triangulatedIndexArray
;
}
var
positionIndexes
=
data
.
coordIndex
?
triangulateIndexArray
(
data
.
coordIndex
)
:
[];
var
normalIndexes
=
data
.
normalIndex
?
triangulateIndexArray
(
data
.
normalIndex
)
:
positionIndexes
;
var
colorIndexes
=
data
.
colorIndex
?
triangulateIndexArray
(
data
.
colorIndex
)
:
positionIndexes
;
var
uvIndexes
=
data
.
texCoordIndex
?
triangulateIndexArray
(
data
.
texCoordIndex
)
:
positionIndexes
;
var
newIndexes
=
[];
var
newPositions
=
[];
var
newPositions
=
[];
var
newColors
=
[];
var
newNormals
=
[];
var
newNormals
=
[];
var
newColors
=
[];
var
newUvs
=
[];
var
newUvs
=
[];
position
=
new
THREE
.
Vector3
();
// if any other index array does not match the coordinate indexes, split any points that differ
color
=
new
THREE
.
Color
();
normal
=
new
THREE
.
Vector3
();
uv
=
new
THREE
.
Vector2
();
for
(
i
=
0
,
il
=
data
.
coordIndex
.
length
;
i
<
il
;
i
++
)
{
var
pointMap
=
Object
.
create
(
null
);
var
indexes
=
data
.
coordIndex
[
i
];
for
(
i
=
0
;
i
<
positionIndexes
.
length
;
i
++
)
{
// VRML support multipoint indexed face sets (more then 3 vertices). You must calculate the composing triangles here
var
pointAttributes
=
[];
skip
=
0
;
var
positionIndex
=
positionIndexes
[
i
];
var
normalIndex
=
normalIndexes
[
i
];
var
colorIndex
=
colorIndexes
[
i
];
var
uvIndex
=
uvIndexes
[
i
];
while
(
indexes
.
length
>=
3
&&
skip
<
(
indexes
.
length
-
2
)
)
{
var
base
=
10
;
// which base to use to represent each value
if
(
data
.
ccw
===
undefined
)
data
.
ccw
=
true
;
// ccw is true by default
pointAttributes
.
push
(
positionIndex
.
toString
(
base
)
);
var
i1
=
indexes
[
0
];
if
(
normalIndex
!==
undefined
)
{
var
i2
=
indexes
[
skip
+
(
data
.
ccw
?
1
:
2
)
];
var
i3
=
indexes
[
skip
+
(
data
.
ccw
?
2
:
1
)
];
// create non indexed geometry, necessary for face normal generation
pointAttributes
.
push
(
normalIndex
.
toString
(
base
)
);
position
.
fromArray
(
positions
,
i1
*
3
);
}
newPositions
.
push
(
position
.
x
,
position
.
y
,
position
.
z
);
position
.
fromArray
(
positions
,
i2
*
3
);
newPositions
.
push
(
position
.
x
,
position
.
y
,
position
.
z
);
position
.
fromArray
(
positions
,
i3
*
3
);
newPositions
.
push
(
position
.
x
,
position
.
y
,
position
.
z
);
if
(
colors
.
length
>
0
)
{
if
(
colorIndex
!==
undefined
)
{
color
.
fromArray
(
colors
,
i1
*
3
);
pointAttributes
.
push
(
colorIndex
.
toString
(
base
)
);
newColors
.
push
(
color
.
r
,
color
.
g
,
color
.
b
);
color
.
fromArray
(
colors
,
i2
*
3
);
newColors
.
push
(
color
.
r
,
color
.
g
,
color
.
b
);
color
.
fromArray
(
colors
,
i3
*
3
);
newColors
.
push
(
color
.
r
,
color
.
g
,
color
.
b
);
}
}
if
(
uvs
.
length
>
0
)
{
if
(
uvIndex
!==
undefined
)
{
uv
.
fromArray
(
uvs
,
i1
*
2
);
pointAttributes
.
push
(
uvIndex
.
toString
(
base
)
);
newUvs
.
push
(
uv
.
x
,
uv
.
y
);
uv
.
fromArray
(
uvs
,
i2
*
2
);
newUvs
.
push
(
uv
.
x
,
uv
.
y
);
uv
.
fromArray
(
uvs
,
i3
*
2
);
newUvs
.
push
(
uv
.
x
,
uv
.
y
);
}
}
if
(
normals
.
length
>
0
)
{
var
pointId
=
pointAttributes
.
join
(
'
,
'
);
var
newIndex
=
pointMap
[
pointId
];
if
(
newIndex
===
undefined
)
{
newIndex
=
newPositions
.
length
/
3
;
pointMap
[
pointId
]
=
newIndex
;
newPositions
.
push
(
positions
[
positionIndex
*
3
],
positions
[
positionIndex
*
3
+
1
],
positions
[
positionIndex
*
3
+
2
]
);
normal
.
fromArray
(
normals
,
i1
*
3
);
if
(
normalIndex
!==
undefined
&&
normals
.
length
>
0
)
{
newNormals
.
push
(
normal
.
x
,
normal
.
y
,
normal
.
z
);
normal
.
fromArray
(
normals
,
i2
*
3
);
newNormals
.
push
(
newNormals
.
push
(
normal
.
x
,
normal
.
y
,
normal
.
z
);
normals
[
normalIndex
*
3
],
normal
.
fromArray
(
normals
,
i3
*
3
);
normals
[
normalIndex
*
3
+
1
],
newNormals
.
push
(
normal
.
x
,
normal
.
y
,
normal
.
z
);
normals
[
normalIndex
*
3
+
2
]
);
}
}
skip
++
;
if
(
colorIndex
!==
undefined
&&
colors
.
length
>
0
)
{
newColors
.
push
(
colors
[
colorIndex
*
3
],
colors
[
colorIndex
*
3
+
1
],
colors
[
colorIndex
*
3
+
2
]
);
}
}
if
(
uvIndex
!==
undefined
&&
uvs
.
length
>
0
)
{
newUvs
.
push
(
uvs
[
uvIndex
*
2
],
uvs
[
uvIndex
*
2
+
1
]
);
}
}
newIndexes
.
push
(
newIndex
);
}
}
positions
=
newPositions
;
positions
=
newPositions
;
colors
=
newColors
;
normals
=
newNormals
;
normals
=
newNormals
;
color
=
newColors
;
uvs
=
newUvs
;
uvs
=
newUvs
;
geometry
.
setIndex
(
newIndexes
);
}
else
{
}
else
{
// do not add dummy mesh to the scene
// do not add dummy mesh to the scene
...
@@ -1034,6 +1087,8 @@ THREE.VRMLLoader.prototype = {
...
@@ -1034,6 +1087,8 @@ THREE.VRMLLoader.prototype = {
}
else
{
}
else
{
// convert geometry to non-indexed to get sharp normals
geometry
=
geometry
.
toNonIndexed
();
geometry
.
computeVertexNormals
();
geometry
.
computeVertexNormals
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录