Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
fktz008
three.js
提交
8ea885cd
T
three.js
项目概览
fktz008
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
未验证
提交
8ea885cd
编写于
9月 22, 2021
作者:
M
Michael Herzog
提交者:
GitHub
9月 22, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure geometry helpers can use new clone() method. (#22571)
上级
271dc86e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
126 addition
and
130 deletion
+126
-130
src/geometries/EdgesGeometry.js
src/geometries/EdgesGeometry.js
+74
-79
src/geometries/WireframeGeometry.js
src/geometries/WireframeGeometry.js
+52
-51
未找到文件。
src/geometries/EdgesGeometry.js
浏览文件 @
8ea885cd
...
...
@@ -11,133 +11,128 @@ const _triangle = new Triangle();
class
EdgesGeometry
extends
BufferGeometry
{
constructor
(
geometry
,
thresholdAngle
)
{
constructor
(
geometry
=
null
,
thresholdAngle
=
1
)
{
super
();
this
.
type
=
'
EdgesGeometry
'
;
this
.
parameters
=
{
geometry
:
geometry
,
thresholdAngle
:
thresholdAngle
};
thresholdAngle
=
(
thresholdAngle
!==
undefined
)
?
thresholdAngle
:
1
;
if
(
geometry
.
isGeometry
===
true
)
{
if
(
geometry
!==
null
)
{
console
.
error
(
'
THREE.EdgesGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.
'
);
return
;
}
const
precisionPoints
=
4
;
const
precision
=
Math
.
pow
(
10
,
precisionPoints
);
const
thresholdDot
=
Math
.
cos
(
MathUtils
.
DEG2RAD
*
thresholdAngle
);
const
precisionPoints
=
4
;
const
precision
=
Math
.
pow
(
10
,
precisionPoints
);
const
thresholdDot
=
Math
.
cos
(
MathUtils
.
DEG2RAD
*
thresholdAngle
)
;
const
indexAttr
=
geometry
.
getIndex
()
;
const
positionAttr
=
geometry
.
getAttribute
(
'
position
'
);
const
indexCount
=
indexAttr
?
indexAttr
.
count
:
positionAttr
.
count
;
const
indexAttr
=
geometry
.
getIndex
()
;
const
positionAttr
=
geometry
.
getAttribute
(
'
position
'
)
;
const
indexCount
=
indexAttr
?
indexAttr
.
count
:
positionAttr
.
count
;
const
indexArr
=
[
0
,
0
,
0
]
;
const
vertKeys
=
[
'
a
'
,
'
b
'
,
'
c
'
]
;
const
hashes
=
new
Array
(
3
)
;
const
indexArr
=
[
0
,
0
,
0
]
;
const
vertKeys
=
[
'
a
'
,
'
b
'
,
'
c
'
];
const
hashes
=
new
Array
(
3
);
const
edgeData
=
{}
;
const
vertices
=
[
];
for
(
let
i
=
0
;
i
<
indexCount
;
i
+=
3
)
{
const
edgeData
=
{};
const
vertices
=
[];
for
(
let
i
=
0
;
i
<
indexCount
;
i
+=
3
)
{
if
(
indexAttr
)
{
if
(
indexAttr
)
{
indexArr
[
0
]
=
indexAttr
.
getX
(
i
);
indexArr
[
1
]
=
indexAttr
.
getX
(
i
+
1
);
indexArr
[
2
]
=
indexAttr
.
getX
(
i
+
2
);
indexArr
[
0
]
=
indexAttr
.
getX
(
i
);
indexArr
[
1
]
=
indexAttr
.
getX
(
i
+
1
);
indexArr
[
2
]
=
indexAttr
.
getX
(
i
+
2
);
}
else
{
}
else
{
indexArr
[
0
]
=
i
;
indexArr
[
1
]
=
i
+
1
;
indexArr
[
2
]
=
i
+
2
;
indexArr
[
0
]
=
i
;
indexArr
[
1
]
=
i
+
1
;
indexArr
[
2
]
=
i
+
2
;
}
}
const
{
a
,
b
,
c
}
=
_triangle
;
a
.
fromBufferAttribute
(
positionAttr
,
indexArr
[
0
]
);
b
.
fromBufferAttribute
(
positionAttr
,
indexArr
[
1
]
);
c
.
fromBufferAttribute
(
positionAttr
,
indexArr
[
2
]
);
_triangle
.
getNormal
(
_normal
);
const
{
a
,
b
,
c
}
=
_triangle
;
a
.
fromBufferAttribute
(
positionAttr
,
indexArr
[
0
]
);
b
.
fromBufferAttribute
(
positionAttr
,
indexArr
[
1
]
);
c
.
fromBufferAttribute
(
positionAttr
,
indexArr
[
2
]
);
_triangle
.
getNormal
(
_normal
);
// create hashes for the edge from the vertices
hashes
[
0
]
=
`
${
Math
.
round
(
a
.
x
*
precision
)
}
,
${
Math
.
round
(
a
.
y
*
precision
)
}
,
${
Math
.
round
(
a
.
z
*
precision
)
}
`
;
hashes
[
1
]
=
`
${
Math
.
round
(
b
.
x
*
precision
)
}
,
${
Math
.
round
(
b
.
y
*
precision
)
}
,
${
Math
.
round
(
b
.
z
*
precision
)
}
`
;
hashes
[
2
]
=
`
${
Math
.
round
(
c
.
x
*
precision
)
}
,
${
Math
.
round
(
c
.
y
*
precision
)
}
,
${
Math
.
round
(
c
.
z
*
precision
)
}
`
;
// create hashes for the edge from the vertices
hashes
[
0
]
=
`
${
Math
.
round
(
a
.
x
*
precision
)
}
,
${
Math
.
round
(
a
.
y
*
precision
)
}
,
${
Math
.
round
(
a
.
z
*
precision
)
}
`
;
hashes
[
1
]
=
`
${
Math
.
round
(
b
.
x
*
precision
)
}
,
${
Math
.
round
(
b
.
y
*
precision
)
}
,
${
Math
.
round
(
b
.
z
*
precision
)
}
`
;
hashes
[
2
]
=
`
${
Math
.
round
(
c
.
x
*
precision
)
}
,
${
Math
.
round
(
c
.
y
*
precision
)
}
,
${
Math
.
round
(
c
.
z
*
precision
)
}
`
;
// skip degenerate triangles
if
(
hashes
[
0
]
===
hashes
[
1
]
||
hashes
[
1
]
===
hashes
[
2
]
||
hashes
[
2
]
===
hashes
[
0
]
)
{
// skip degenerate triangles
if
(
hashes
[
0
]
===
hashes
[
1
]
||
hashes
[
1
]
===
hashes
[
2
]
||
hashes
[
2
]
===
hashes
[
0
]
)
{
continue
;
continue
;
}
}
// iterate over every edge
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
// iterate over every edge
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
// get the first and next vertex making up the edge
const
jNext
=
(
j
+
1
)
%
3
;
const
vecHash0
=
hashes
[
j
];
const
vecHash1
=
hashes
[
jNext
];
const
v0
=
_triangle
[
vertKeys
[
j
]
];
const
v1
=
_triangle
[
vertKeys
[
jNext
]
];
// get the first and next vertex making up the edge
const
jNext
=
(
j
+
1
)
%
3
;
const
vecHash0
=
hashes
[
j
];
const
vecHash1
=
hashes
[
jNext
];
const
v0
=
_triangle
[
vertKeys
[
j
]
];
const
v1
=
_triangle
[
vertKeys
[
jNext
]
];
const
hash
=
`
${
vecHash0
}
_
${
vecHash1
}
`
;
const
reverseHash
=
`
${
vecHash1
}
_
${
vecHash0
}
`
;
const
hash
=
`
${
vecHash0
}
_
${
vecHash1
}
`
;
const
reverseHash
=
`
${
vecHash1
}
_
${
vecHash0
}
`
;
if
(
reverseHash
in
edgeData
&&
edgeData
[
reverseHash
]
)
{
if
(
reverseHash
in
edgeData
&&
edgeData
[
reverseHash
]
)
{
// if we found a sibling edge add it into the vertex array if
// it meets the angle threshold and delete the edge from the map.
if
(
_normal
.
dot
(
edgeData
[
reverseHash
].
normal
)
<=
thresholdDot
)
{
// if we found a sibling edge add it into the vertex array if
// it meets the angle threshold and delete the edge from the map.
if
(
_normal
.
dot
(
edgeData
[
reverseHash
].
normal
)
<=
thresholdDot
)
{
vertices
.
push
(
v0
.
x
,
v0
.
y
,
v0
.
z
);
vertices
.
push
(
v1
.
x
,
v1
.
y
,
v1
.
z
);
vertices
.
push
(
v0
.
x
,
v0
.
y
,
v0
.
z
);
vertices
.
push
(
v1
.
x
,
v1
.
y
,
v1
.
z
);
}
}
edgeData
[
reverseHash
]
=
null
;
edgeData
[
reverseHash
]
=
null
;
}
else
if
(
!
(
hash
in
edgeData
)
)
{
}
else
if
(
!
(
hash
in
edgeData
)
)
{
// if we've already got an edge here then skip adding a new one
edgeData
[
hash
]
=
{
// if we've already got an edge here then skip adding a new one
edgeData
[
hash
]
=
{
index0
:
indexArr
[
j
],
index1
:
indexArr
[
jNext
],
normal
:
_normal
.
clone
(),
index0
:
indexArr
[
j
],
index1
:
indexArr
[
jNext
],
normal
:
_normal
.
clone
(),
};
}
;
}
}
}
}
// iterate over all remaining, unmatched edges and add them to the vertex array
for
(
const
key
in
edgeData
)
{
// iterate over all remaining, unmatched edges and add them to the vertex array
for
(
const
key
in
edgeData
)
{
if
(
edgeData
[
key
]
)
{
if
(
edgeData
[
key
]
)
{
const
{
index0
,
index1
}
=
edgeData
[
key
];
_v0
.
fromBufferAttribute
(
positionAttr
,
index0
);
_v1
.
fromBufferAttribute
(
positionAttr
,
index1
);
const
{
index0
,
index1
}
=
edgeData
[
key
];
_v0
.
fromBufferAttribute
(
positionAttr
,
index0
);
_v1
.
fromBufferAttribute
(
positionAttr
,
index1
);
vertices
.
push
(
_v0
.
x
,
_v0
.
y
,
_v0
.
z
);
vertices
.
push
(
_v1
.
x
,
_v1
.
y
,
_v1
.
z
);
vertices
.
push
(
_v0
.
x
,
_v0
.
y
,
_v0
.
z
);
vertices
.
push
(
_v1
.
x
,
_v1
.
y
,
_v1
.
z
);
}
}
}
this
.
setAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
vertices
,
3
)
);
this
.
setAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
vertices
,
3
)
);
}
}
...
...
src/geometries/WireframeGeometry.js
浏览文件 @
8ea885cd
...
...
@@ -4,65 +4,66 @@ import { Vector3 } from '../math/Vector3.js';
class
WireframeGeometry
extends
BufferGeometry
{
constructor
(
geometry
)
{
constructor
(
geometry
=
null
)
{
super
();
this
.
type
=
'
WireframeGeometry
'
;
if
(
geometry
.
isGeometry
===
true
)
{
this
.
parameters
=
{
geometry
:
geometry
};
console
.
error
(
'
THREE.WireframeGeometry no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.
'
);
return
;
if
(
geometry
!==
null
)
{
}
// buffer
// buffer
const
vertices
=
[];
const
edges
=
new
Set
();
const
vertices
=
[];
const
edges
=
new
Set
();
// helper variables
// helper variables
const
start
=
new
Vector3
();
const
end
=
new
Vector3
();
const
start
=
new
Vector3
();
const
end
=
new
Vector3
();
if
(
geometry
.
index
!==
null
)
{
if
(
geometry
.
index
!==
null
)
{
// indexed BufferGeometry
// indexed BufferGeometry
const
position
=
geometry
.
attributes
.
position
;
const
indices
=
geometry
.
index
;
let
groups
=
geometry
.
groups
;
const
position
=
geometry
.
attributes
.
position
;
const
indices
=
geometry
.
index
;
let
groups
=
geometry
.
groups
;
if
(
groups
.
length
===
0
)
{
if
(
groups
.
length
===
0
)
{
groups
=
[
{
start
:
0
,
count
:
indices
.
count
,
materialIndex
:
0
}
];
groups
=
[
{
start
:
0
,
count
:
indices
.
count
,
materialIndex
:
0
}
];
}
}
// create a data structure that contains all eges without duplicates
// create a data structure that contains all eges without duplicates
for
(
let
o
=
0
,
ol
=
groups
.
length
;
o
<
ol
;
++
o
)
{
for
(
let
o
=
0
,
ol
=
groups
.
length
;
o
<
ol
;
++
o
)
{
const
group
=
groups
[
o
];
const
group
=
groups
[
o
];
const
groupStart
=
group
.
start
;
const
groupCount
=
group
.
count
;
const
groupStart
=
group
.
start
;
const
groupCount
=
group
.
count
;
for
(
let
i
=
groupStart
,
l
=
(
groupStart
+
groupCount
);
i
<
l
;
i
+=
3
)
{
for
(
let
i
=
groupStart
,
l
=
(
groupStart
+
groupCount
);
i
<
l
;
i
+=
3
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
const
index1
=
indices
.
getX
(
i
+
j
);
const
index2
=
indices
.
getX
(
i
+
(
j
+
1
)
%
3
);
const
index1
=
indices
.
getX
(
i
+
j
);
const
index2
=
indices
.
getX
(
i
+
(
j
+
1
)
%
3
);
start
.
fromBufferAttribute
(
position
,
index1
);
end
.
fromBufferAttribute
(
position
,
index2
);
start
.
fromBufferAttribute
(
position
,
index1
);
end
.
fromBufferAttribute
(
position
,
index2
);
if
(
isUniqueEdge
(
start
,
end
,
edges
)
===
true
)
{
if
(
isUniqueEdge
(
start
,
end
,
edges
)
===
true
)
{
vertices
.
push
(
start
.
x
,
start
.
y
,
start
.
z
);
vertices
.
push
(
end
.
x
,
end
.
y
,
end
.
z
);
vertices
.
push
(
start
.
x
,
start
.
y
,
start
.
z
);
vertices
.
push
(
end
.
x
,
end
.
y
,
end
.
z
);
}
}
...
...
@@ -70,31 +71,31 @@ class WireframeGeometry extends BufferGeometry {
}
}
}
else
{
}
else
{
// non-indexed BufferGeometry
// non-indexed BufferGeometry
const
position
=
geometry
.
attributes
.
position
;
const
position
=
geometry
.
attributes
.
position
;
for
(
let
i
=
0
,
l
=
(
position
.
count
/
3
);
i
<
l
;
i
++
)
{
for
(
let
i
=
0
,
l
=
(
position
.
count
/
3
);
i
<
l
;
i
++
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
{
for
(
let
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)
// 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)
const
index1
=
3
*
i
+
j
;
const
index2
=
3
*
i
+
(
(
j
+
1
)
%
3
);
const
index1
=
3
*
i
+
j
;
const
index2
=
3
*
i
+
(
(
j
+
1
)
%
3
);
start
.
fromBufferAttribute
(
position
,
index1
)
;
end
.
fromBufferAttribute
(
position
,
index2
);
start
.
fromBufferAttribute
(
position
,
index1
);
end
.
fromBufferAttribute
(
position
,
index2
);
if
(
isUniqueEdge
(
start
,
end
,
edges
)
===
true
)
{
if
(
isUniqueEdge
(
start
,
end
,
edges
)
===
true
)
{
vertices
.
push
(
start
.
x
,
start
.
y
,
start
.
z
);
vertices
.
push
(
end
.
x
,
end
.
y
,
end
.
z
);
vertices
.
push
(
start
.
x
,
start
.
y
,
start
.
z
);
vertices
.
push
(
end
.
x
,
end
.
y
,
end
.
z
);
}
}
...
...
@@ -102,11 +103,11 @@ class WireframeGeometry extends BufferGeometry {
}
}
// build geometry
// build geometry
this
.
setAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
vertices
,
3
)
);
this
.
setAttribute
(
'
position
'
,
new
Float32BufferAttribute
(
vertices
,
3
)
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录