Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
ecf862c4
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 搜索 >>
未验证
提交
ecf862c4
编写于
12月 21, 2020
作者:
M
Mr.doob
提交者:
GitHub
12月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20903 from Mcgode/edge-split-keep-normals
EdgeSplitModifier - Keep normals
上级
341a5c94
a003059a
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
80 addition
and
6 deletion
+80
-6
examples/js/modifiers/EdgeSplitModifier.js
examples/js/modifiers/EdgeSplitModifier.js
+27
-1
examples/jsm/modifiers/EdgeSplitModifier.d.ts
examples/jsm/modifiers/EdgeSplitModifier.d.ts
+15
-1
examples/jsm/modifiers/EdgeSplitModifier.js
examples/jsm/modifiers/EdgeSplitModifier.js
+28
-1
examples/webgl_modifier_edgesplit.html
examples/webgl_modifier_edgesplit.html
+9
-2
package-lock.json
package-lock.json
+1
-1
未找到文件。
examples/js/modifiers/EdgeSplitModifier.js
浏览文件 @
ecf862c4
...
...
@@ -7,6 +7,7 @@ THREE.EdgeSplitModifier = function () {
var
positions
,
normals
;
var
indexes
;
var
pointToIndexMap
,
splitIndexes
;
let
oldNormals
;
function
computeNormals
()
{
...
...
@@ -150,7 +151,7 @@ THREE.EdgeSplitModifier = function () {
}
this
.
modify
=
function
(
geometry
,
cutOffAngle
)
{
this
.
modify
=
function
(
geometry
,
cutOffAngle
,
tryKeepNormals
=
true
)
{
const
wasNotBufferGeometry
=
geometry
.
isBufferGeometry
===
undefined
;
if
(
!
geometry
.
isBufferGeometry
)
{
...
...
@@ -161,6 +162,7 @@ THREE.EdgeSplitModifier = function () {
let
hadNormals
=
false
;
oldNormals
=
null
;
if
(
geometry
.
attributes
.
normal
)
{
hadNormals
=
true
;
...
...
@@ -168,6 +170,9 @@ THREE.EdgeSplitModifier = function () {
if
(
wasNotBufferGeometry
===
false
)
geometry
=
geometry
.
clone
();
if
(
tryKeepNormals
&&
geometry
.
index
)
oldNormals
=
geometry
.
attributes
.
normal
.
array
;
geometry
.
deleteAttribute
(
'
normal
'
);
}
...
...
@@ -249,6 +254,27 @@ THREE.EdgeSplitModifier = function () {
geometry
.
computeVertexNormals
();
if
(
oldNormals
!==
null
)
{
const
changedNormals
=
new
Array
(
oldNormals
.
length
/
3
).
fill
(
false
);
for
(
const
splitData
of
splitIndexes
)
changedNormals
[
splitData
.
original
]
=
true
;
for
(
let
i
=
0
;
i
<
changedNormals
.
length
;
i
++
)
{
if
(
changedNormals
[
i
]
===
false
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
geometry
.
attributes
.
normal
.
array
[
3
*
i
+
j
]
=
oldNormals
[
3
*
i
+
j
];
}
}
}
}
return
geometry
;
...
...
examples/jsm/modifiers/EdgeSplitModifier.d.ts
浏览文件 @
ecf862c4
...
...
@@ -3,6 +3,20 @@ import { BufferGeometry, Geometry } from '../../../src/Three';
export
class
EdgeSplitModifier
{
constructor
();
modify
(
geometry
:
Geometry
,
cutOffPoint
:
number
):
BufferGeometry
;
/**
* @param geometry The geometry to modify by splitting edges.
* This geometry can be any of any type: Geometry or BufferGeometry, indexed or
* not...
*
* @param cutOffPoint The cutoff angle in radians. If the angle between two face normals is higher
* than this value, a split will be made.
*
* @param [tryKeepNormals = true] Set to true to keep the normal values for vertices that won't be split.
* To use this feature, you also need to pass an indexed geometry with a 'normal'
* BufferAttribute.
*/
modify
(
geometry
:
Geometry
,
cutOffPoint
:
number
,
tryKeepNormals
:
boolean
):
BufferGeometry
;
}
examples/jsm/modifiers/EdgeSplitModifier.js
浏览文件 @
ecf862c4
...
...
@@ -16,6 +16,8 @@ var EdgeSplitModifier = function () {
var
indexes
;
var
pointToIndexMap
,
splitIndexes
;
let
oldNormals
;
function
computeNormals
()
{
...
...
@@ -158,7 +160,7 @@ var EdgeSplitModifier = function () {
}
this
.
modify
=
function
(
geometry
,
cutOffAngle
)
{
this
.
modify
=
function
(
geometry
,
cutOffAngle
,
tryKeepNormals
=
true
)
{
const
wasNotBufferGeometry
=
geometry
.
isBufferGeometry
===
undefined
;
if
(
!
geometry
.
isBufferGeometry
)
{
...
...
@@ -169,6 +171,7 @@ var EdgeSplitModifier = function () {
let
hadNormals
=
false
;
oldNormals
=
null
;
if
(
geometry
.
attributes
.
normal
)
{
hadNormals
=
true
;
...
...
@@ -176,6 +179,9 @@ var EdgeSplitModifier = function () {
if
(
wasNotBufferGeometry
===
false
)
geometry
=
geometry
.
clone
();
if
(
tryKeepNormals
&&
geometry
.
index
)
oldNormals
=
geometry
.
attributes
.
normal
.
array
;
geometry
.
deleteAttribute
(
'
normal
'
);
}
...
...
@@ -257,6 +263,27 @@ var EdgeSplitModifier = function () {
geometry
.
computeVertexNormals
();
if
(
oldNormals
!==
null
)
{
const
changedNormals
=
new
Array
(
oldNormals
.
length
/
3
).
fill
(
false
);
for
(
const
splitData
of
splitIndexes
)
changedNormals
[
splitData
.
original
]
=
true
;
for
(
let
i
=
0
;
i
<
changedNormals
.
length
;
i
++
)
{
if
(
changedNormals
[
i
]
===
false
)
{
for
(
let
j
=
0
;
j
<
3
;
j
++
)
geometry
.
attributes
.
normal
.
array
[
3
*
i
+
j
]
=
oldNormals
[
3
*
i
+
j
];
}
}
}
}
return
geometry
;
...
...
examples/webgl_modifier_edgesplit.html
浏览文件 @
ecf862c4
...
...
@@ -15,6 +15,7 @@
import
{
OrbitControls
}
from
'
./jsm/controls/OrbitControls.js
'
;
import
{
OBJLoader
}
from
'
./jsm/loaders/OBJLoader.js
'
;
import
{
EdgeSplitModifier
}
from
'
./jsm/modifiers/EdgeSplitModifier.js
'
;
import
{
BufferGeometryUtils
}
from
'
./jsm/utils/BufferGeometryUtils.js
'
;
import
{
GUI
}
from
'
./jsm/libs/dat.gui.module.js
'
;
...
...
@@ -27,6 +28,7 @@
edgeSplit
:
true
,
cutOffAngle
:
20
,
showMap
:
false
,
tryKeepNormals
:
true
,
};
init
();
...
...
@@ -68,7 +70,7 @@
const
modelGeometry
=
cerberus
.
geometry
;
modifier
=
new
EdgeSplitModifier
();
baseGeometry
=
modelGeometry
;
baseGeometry
=
BufferGeometryUtils
.
mergeVertices
(
modelGeometry
)
;
mesh
=
new
THREE
.
Mesh
(
getGeometry
(),
new
THREE
.
MeshStandardMaterial
()
);
mesh
.
material
.
flatShading
=
!
params
.
smoothShading
;
...
...
@@ -111,6 +113,7 @@
gui
.
add
(
params
,
'
smoothShading
'
).
onFinishChange
(
updateMesh
);
gui
.
add
(
params
,
'
edgeSplit
'
).
onFinishChange
(
updateMesh
);
gui
.
add
(
params
,
'
cutOffAngle
'
).
min
(
0
).
max
(
180
).
onFinishChange
(
updateMesh
);
gui
.
add
(
params
,
'
tryKeepNormals
'
).
onFinishChange
(
updateMesh
);
}
...
...
@@ -132,7 +135,11 @@
if
(
params
.
edgeSplit
)
{
geometry
=
modifier
.
modify
(
baseGeometry
,
params
.
cutOffAngle
*
Math
.
PI
/
180
);
geometry
=
modifier
.
modify
(
baseGeometry
,
params
.
cutOffAngle
*
Math
.
PI
/
180
,
params
.
tryKeepNormals
);
}
else
{
...
...
package-lock.json
浏览文件 @
ecf862c4
...
...
@@ -3105,7 +3105,7 @@
},
"path-is-absolute"
:
{
"version"
:
"1.0.1"
,
"resolved"
:
"http://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz"
,
"resolved"
:
"http
s
://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz"
,
"integrity"
:
"sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
,
"dev"
:
true
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录