Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
e5ece925
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,体验更适合开发者的 AI 搜索 >>
提交
e5ece925
编写于
1月 18, 2017
作者:
M
Mr.doob
提交者:
GitHub
1月 18, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10598 from Mugen87/dev
Geometries: Simplification and Refactoring
上级
3ee05d49
42480f3a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
85 addition
and
92 deletion
+85
-92
src/geometries/EdgesGeometry.js
src/geometries/EdgesGeometry.js
+10
-10
src/geometries/WireframeGeometry.js
src/geometries/WireframeGeometry.js
+75
-82
未找到文件。
src/geometries/EdgesGeometry.js
浏览文件 @
e5ece925
...
...
@@ -27,7 +27,7 @@ function EdgesGeometry( geometry, thresholdAngle ) {
// helper variables
var
thresholdDot
=
Math
.
cos
(
_Math
.
DEG2RAD
*
thresholdAngle
);
var
edge
=
[
0
,
0
],
hash
=
{};
var
edge
=
[
0
,
0
],
edges
=
{};
var
key
,
keys
=
[
'
a
'
,
'
b
'
,
'
c
'
];
// prepare source geometry
...
...
@@ -51,7 +51,7 @@ function EdgesGeometry( geometry, thresholdAngle ) {
var
sourceVertices
=
geometry2
.
vertices
;
var
faces
=
geometry2
.
faces
;
// now create a data structure
(hash)
where each entry represents an edge with its adjoining faces
// now create a data structure where each entry represents an edge with its adjoining faces
for
(
var
i
=
0
,
l
=
faces
.
length
;
i
<
l
;
i
++
)
{
...
...
@@ -65,13 +65,13 @@ function EdgesGeometry( geometry, thresholdAngle ) {
key
=
edge
.
toString
();
if
(
hash
[
key
]
===
undefined
)
{
if
(
edges
[
key
]
===
undefined
)
{
hash
[
key
]
=
{
vert1
:
edge
[
0
],
vert
2
:
edge
[
1
],
face1
:
i
,
face2
:
undefined
};
edges
[
key
]
=
{
index1
:
edge
[
0
],
index
2
:
edge
[
1
],
face1
:
i
,
face2
:
undefined
};
}
else
{
hash
[
key
].
face2
=
i
;
edges
[
key
].
face2
=
i
;
}
...
...
@@ -81,18 +81,18 @@ function EdgesGeometry( geometry, thresholdAngle ) {
// generate vertices
for
(
key
in
hash
)
{
for
(
key
in
edges
)
{
var
h
=
hash
[
key
];
var
e
=
edges
[
key
];
// an edge is only rendered if the angle (in degrees) between the face normals of the adjoining faces exceeds this value. default = 1 degree.
if
(
h
.
face2
===
undefined
||
faces
[
h
.
face1
].
normal
.
dot
(
faces
[
h
.
face2
].
normal
)
<=
thresholdDot
)
{
if
(
e
.
face2
===
undefined
||
faces
[
e
.
face1
].
normal
.
dot
(
faces
[
e
.
face2
].
normal
)
<=
thresholdDot
)
{
var
vertex
=
sourceVertices
[
h
.
vert
1
];
var
vertex
=
sourceVertices
[
e
.
index
1
];
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
vertex
=
sourceVertices
[
h
.
vert
2
];
vertex
=
sourceVertices
[
e
.
index
2
];
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
}
...
...
src/geometries/WireframeGeometry.js
浏览文件 @
e5ece925
import
{
BufferGeometry
}
from
'
../core/BufferGeometry
'
;
import
{
BufferAttribute
}
from
'
../core/BufferAttribute
'
;
import
{
Float32BufferAttribute
}
from
'
../core/BufferAttribute
'
;
import
{
Vector3
}
from
'
../math/Vector3
'
;
/**
* @author mrdoob / http://mrdoob.com/
* @author Mugen87 / https://github.com/Mugen87
*/
function
WireframeGeometry
(
geometry
)
{
...
...
@@ -11,37 +13,40 @@ function WireframeGeometry( geometry ) {
this
.
type
=
'
WireframeGeometry
'
;
var
edge
=
[
0
,
0
],
hash
=
{};
// buffer
var
keys
=
[
'
a
'
,
'
b
'
,
'
c
'
];
var
vertices
=
[];
// helper variables
var
i
,
j
,
l
,
o
,
ol
;
var
edge
=
[
0
,
0
],
edges
=
{},
e
;
var
key
,
keys
=
[
'
a
'
,
'
b
'
,
'
c
'
];
var
vertex
;
// different logic for Geometry and BufferGeometry
if
(
geometry
&&
geometry
.
isGeometry
)
{
var
vertices
=
geometry
.
vertices
;
var
faces
=
geometry
.
faces
;
var
numEdges
=
0
;
// create a data structure that contains all edges without duplicates
// allocate maximal size
var
edges
=
new
Uint32Array
(
6
*
faces
.
length
);
var
faces
=
geometry
.
faces
;
for
(
var
i
=
0
,
l
=
faces
.
length
;
i
<
l
;
i
++
)
{
for
(
i
=
0
,
l
=
faces
.
length
;
i
<
l
;
i
++
)
{
var
face
=
faces
[
i
];
for
(
var
j
=
0
;
j
<
3
;
j
++
)
{
for
(
j
=
0
;
j
<
3
;
j
++
)
{
edge
[
0
]
=
face
[
keys
[
j
]
];
edge
[
1
]
=
face
[
keys
[
(
j
+
1
)
%
3
]
];
edge
.
sort
(
sortFunction
);
edge
.
sort
(
sortFunction
);
// sorting prevents duplicates
var
key
=
edge
.
toString
();
key
=
edge
.
toString
();
if
(
hash
[
key
]
===
undefined
)
{
if
(
edges
[
key
]
===
undefined
)
{
edges
[
2
*
numEdges
]
=
edge
[
0
];
edges
[
2
*
numEdges
+
1
]
=
edge
[
1
];
hash
[
key
]
=
true
;
numEdges
++
;
edges
[
key
]
=
{
index1
:
edge
[
0
],
index2
:
edge
[
1
]
};
}
...
...
@@ -49,68 +54,64 @@ function WireframeGeometry( geometry ) {
}
var
coords
=
new
Float32Array
(
numEdges
*
2
*
3
);
// generate vertices
for
(
var
i
=
0
,
l
=
numEdges
;
i
<
l
;
i
++
)
{
for
(
key
in
edges
)
{
for
(
var
j
=
0
;
j
<
2
;
j
++
)
{
e
=
edges
[
key
];
var
vertex
=
vertices
[
edges
[
2
*
i
+
j
]
];
vertex
=
geometry
.
vertices
[
e
.
index1
];
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
var
index
=
6
*
i
+
3
*
j
;
coords
[
index
+
0
]
=
vertex
.
x
;
coords
[
index
+
1
]
=
vertex
.
y
;
coords
[
index
+
2
]
=
vertex
.
z
;
}
vertex
=
geometry
.
vertices
[
e
.
index2
];
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
}
this
.
addAttribute
(
'
position
'
,
new
BufferAttribute
(
coords
,
3
)
);
}
else
if
(
geometry
&&
geometry
.
isBufferGeometry
)
{
var
position
,
indices
,
groups
;
var
group
,
start
,
count
;
var
index1
,
index2
;
vertex
=
new
Vector3
();
if
(
geometry
.
index
!==
null
)
{
//
I
ndexed BufferGeometry
//
i
ndexed BufferGeometry
var
indices
=
geometry
.
index
.
array
;
var
vertices
=
geometry
.
attributes
.
position
;
var
groups
=
geometry
.
groups
;
var
numEdges
=
0
;
position
=
geometry
.
attributes
.
position
;
indices
=
geometry
.
index
;
groups
=
geometry
.
groups
;
if
(
groups
.
length
===
0
)
{
geometry
.
addGroup
(
0
,
indices
.
length
);
geometry
.
addGroup
(
0
,
indices
.
count
);
}
// allocate maximal size
var
edges
=
new
Uint32Array
(
2
*
indices
.
length
);
// create a data structure that contains all eges without duplicates
for
(
var
o
=
0
,
ol
=
groups
.
length
;
o
<
ol
;
++
o
)
{
for
(
o
=
0
,
ol
=
groups
.
length
;
o
<
ol
;
++
o
)
{
var
group
=
groups
[
o
];
group
=
groups
[
o
];
var
start
=
group
.
start
;
var
count
=
group
.
count
;
start
=
group
.
start
;
count
=
group
.
count
;
for
(
var
i
=
start
,
il
=
start
+
count
;
i
<
i
l
;
i
+=
3
)
{
for
(
i
=
start
,
l
=
(
start
+
count
);
i
<
l
;
i
+=
3
)
{
for
(
var
j
=
0
;
j
<
3
;
j
++
)
{
for
(
j
=
0
;
j
<
3
;
j
++
)
{
edge
[
0
]
=
indices
[
i
+
j
]
;
edge
[
1
]
=
indices
[
i
+
(
j
+
1
)
%
3
]
;
edge
.
sort
(
sortFunction
);
edge
[
0
]
=
indices
.
getX
(
i
+
j
)
;
edge
[
1
]
=
indices
.
getX
(
i
+
(
j
+
1
)
%
3
)
;
edge
.
sort
(
sortFunction
);
// sorting prevents duplicates
var
key
=
edge
.
toString
();
key
=
edge
.
toString
();
if
(
hash
[
key
]
===
undefined
)
{
if
(
edges
[
key
]
===
undefined
)
{
edges
[
2
*
numEdges
]
=
edge
[
0
];
edges
[
2
*
numEdges
+
1
]
=
edge
[
1
];
hash
[
key
]
=
true
;
numEdges
++
;
edges
[
key
]
=
{
index1
:
edge
[
0
],
index2
:
edge
[
1
]
};
}
...
...
@@ -120,61 +121,53 @@ function WireframeGeometry( geometry ) {
}
var
coords
=
new
Float32Array
(
numEdges
*
2
*
3
);
for
(
var
i
=
0
,
l
=
numEdges
;
i
<
l
;
i
++
)
{
// generate vertices
for
(
var
j
=
0
;
j
<
2
;
j
++
)
{
for
(
key
in
edges
)
{
var
index
=
6
*
i
+
3
*
j
;
var
index2
=
edges
[
2
*
i
+
j
];
e
=
edges
[
key
];
coords
[
index
+
0
]
=
vertices
.
getX
(
index2
);
coords
[
index
+
1
]
=
vertices
.
getY
(
index2
);
coords
[
index
+
2
]
=
vertices
.
getZ
(
index2
);
vertex
.
fromBufferAttribute
(
position
,
e
.
index1
);
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
}
vertex
.
fromBufferAttribute
(
position
,
e
.
index2
);
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
}
this
.
addAttribute
(
'
position
'
,
new
BufferAttribute
(
coords
,
3
)
);
}
else
{
// non-indexed BufferGeometry
var
vertices
=
geometry
.
attributes
.
position
.
array
;
var
numEdges
=
vertices
.
length
/
3
;
var
numTris
=
numEdges
/
3
;
position
=
geometry
.
attributes
.
position
;
var
coords
=
new
Float32Array
(
numEdges
*
2
*
3
);
for
(
i
=
0
,
l
=
(
position
.
count
/
3
);
i
<
l
;
i
++
)
{
for
(
var
i
=
0
,
l
=
numTris
;
i
<
l
;
i
++
)
{
for
(
j
=
0
;
j
<
3
;
j
++
)
{
for
(
var
j
=
0
;
j
<
3
;
j
++
)
{
// three edges per triangle, an edge is represented as (index1, index2)
// e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
var
index
=
18
*
i
+
6
*
j
;
index1
=
3
*
i
+
j
;
vertex
.
fromBufferAttribute
(
position
,
index1
);
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
var
index1
=
9
*
i
+
3
*
j
;
coords
[
index
+
0
]
=
vertices
[
index1
];
coords
[
index
+
1
]
=
vertices
[
index1
+
1
];
coords
[
index
+
2
]
=
vertices
[
index1
+
2
];
var
index2
=
9
*
i
+
3
*
(
(
j
+
1
)
%
3
);
coords
[
index
+
3
]
=
vertices
[
index2
];
coords
[
index
+
4
]
=
vertices
[
index2
+
1
];
coords
[
index
+
5
]
=
vertices
[
index2
+
2
];
index2
=
3
*
i
+
(
(
j
+
1
)
%
3
);
vertex
.
fromBufferAttribute
(
position
,
index2
);
vertices
.
push
(
vertex
.
x
,
vertex
.
y
,
vertex
.
z
);
}
}
this
.
addAttribute
(
'
position
'
,
new
BufferAttribute
(
coords
,
3
)
);
}
}
// build geometry
this
.
addAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
vertices
,
3
)
);
// custom array sort function
function
sortFunction
(
a
,
b
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录