Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
341a5c94
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 搜索 >>
未验证
提交
341a5c94
编写于
12月 21, 2020
作者:
M
Mr.doob
提交者:
GitHub
12月 21, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #20855 from Mcgode/edge-split-upgrade
EdgeSplitModifier - Support other attributes
上级
606b7f0d
a78bfb1a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
143 addition
and
39 deletion
+143
-39
examples/js/modifiers/EdgeSplitModifier.js
examples/js/modifiers/EdgeSplitModifier.js
+46
-10
examples/jsm/modifiers/EdgeSplitModifier.js
examples/jsm/modifiers/EdgeSplitModifier.js
+47
-10
examples/webgl_modifier_edgesplit.html
examples/webgl_modifier_edgesplit.html
+50
-19
未找到文件。
examples/js/modifiers/EdgeSplitModifier.js
浏览文件 @
341a5c94
THREE
.
EdgeSplitModifier
=
function
()
{
var
A
=
new
THREE
.
Vector3
();
...
...
@@ -153,6 +152,7 @@ THREE.EdgeSplitModifier = function () {
this
.
modify
=
function
(
geometry
,
cutOffAngle
)
{
const
wasNotBufferGeometry
=
geometry
.
isBufferGeometry
===
undefined
;
if
(
!
geometry
.
isBufferGeometry
)
{
geometry
=
new
THREE
.
BufferGeometry
().
fromGeometry
(
geometry
);
...
...
@@ -160,6 +160,19 @@ THREE.EdgeSplitModifier = function () {
}
let
hadNormals
=
false
;
if
(
geometry
.
attributes
.
normal
)
{
hadNormals
=
true
;
if
(
wasNotBufferGeometry
===
false
)
geometry
=
geometry
.
clone
();
geometry
.
deleteAttribute
(
'
normal
'
);
}
if
(
geometry
.
index
==
null
)
{
if
(
THREE
.
BufferGeometryUtils
===
undefined
)
{
...
...
@@ -178,7 +191,6 @@ THREE.EdgeSplitModifier = function () {
computeNormals
();
mapPositionsToIndexes
();
splitIndexes
=
[];
for
(
var
vertexIndexes
of
pointToIndexMap
)
{
...
...
@@ -187,9 +199,15 @@ THREE.EdgeSplitModifier = function () {
}
var
newPositions
=
new
Float32Array
(
positions
.
length
+
3
*
splitIndexes
.
length
);
newPositions
.
set
(
positions
);
var
offset
=
positions
.
length
;
const
newAttributes
=
{};
for
(
const
name
of
Object
.
keys
(
geometry
.
attributes
)
)
{
const
oldAttribute
=
geometry
.
attributes
[
name
];
const
newArray
=
new
oldAttribute
.
array
.
constructor
(
(
indexes
.
length
+
splitIndexes
.
length
)
*
oldAttribute
.
itemSize
);
newArray
.
set
(
oldAttribute
.
array
);
newAttributes
[
name
]
=
new
THREE
.
BufferAttribute
(
newArray
,
oldAttribute
.
itemSize
,
oldAttribute
.
normalized
);
}
var
newIndexes
=
new
Uint32Array
(
indexes
.
length
);
newIndexes
.
set
(
indexes
);
...
...
@@ -199,22 +217,40 @@ THREE.EdgeSplitModifier = function () {
var
split
=
splitIndexes
[
i
];
var
index
=
indexes
[
split
.
original
];
newPositions
[
offset
+
3
*
i
]
=
positions
[
3
*
index
];
newPositions
[
offset
+
3
*
i
+
1
]
=
positions
[
3
*
index
+
1
];
newPositions
[
offset
+
3
*
i
+
2
]
=
positions
[
3
*
index
+
2
];
for
(
const
attribute
of
Object
.
values
(
newAttributes
)
)
{
for
(
let
j
=
0
;
j
<
attribute
.
itemSize
;
j
++
)
{
attribute
.
array
[
(
indexes
.
length
+
i
)
*
attribute
.
itemSize
+
j
]
=
attribute
.
array
[
index
*
attribute
.
itemSize
+
j
];
}
}
for
(
var
j
of
split
.
indexes
)
{
newIndexes
[
j
]
=
offset
/
3
+
i
;
newIndexes
[
j
]
=
indexes
.
length
+
i
;
}
}
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
setAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
newPositions
,
3
,
true
)
);
geometry
.
setIndex
(
new
THREE
.
BufferAttribute
(
newIndexes
,
1
)
);
for
(
const
name
of
Object
.
keys
(
newAttributes
)
)
{
geometry
.
setAttribute
(
name
,
newAttributes
[
name
]
);
}
if
(
hadNormals
)
{
geometry
.
computeVertexNormals
();
}
return
geometry
;
};
...
...
examples/jsm/modifiers/EdgeSplitModifier.js
浏览文件 @
341a5c94
...
...
@@ -160,6 +160,7 @@ var EdgeSplitModifier = function () {
this
.
modify
=
function
(
geometry
,
cutOffAngle
)
{
const
wasNotBufferGeometry
=
geometry
.
isBufferGeometry
===
undefined
;
if
(
!
geometry
.
isBufferGeometry
)
{
geometry
=
new
BufferGeometry
().
fromGeometry
(
geometry
);
...
...
@@ -167,7 +168,20 @@ var EdgeSplitModifier = function () {
}
if
(
geometry
.
index
==
null
)
{
let
hadNormals
=
false
;
if
(
geometry
.
attributes
.
normal
)
{
hadNormals
=
true
;
if
(
wasNotBufferGeometry
===
false
)
geometry
=
geometry
.
clone
();
geometry
.
deleteAttribute
(
'
normal
'
);
}
if
(
!
geometry
.
index
)
{
if
(
BufferGeometryUtils
===
undefined
)
{
...
...
@@ -185,7 +199,6 @@ var EdgeSplitModifier = function () {
computeNormals
();
mapPositionsToIndexes
();
splitIndexes
=
[];
for
(
var
vertexIndexes
of
pointToIndexMap
)
{
...
...
@@ -194,9 +207,15 @@ var EdgeSplitModifier = function () {
}
var
newPositions
=
new
Float32Array
(
positions
.
length
+
3
*
splitIndexes
.
length
);
newPositions
.
set
(
positions
);
var
offset
=
positions
.
length
;
const
newAttributes
=
{};
for
(
const
name
of
Object
.
keys
(
geometry
.
attributes
)
)
{
const
oldAttribute
=
geometry
.
attributes
[
name
];
const
newArray
=
new
oldAttribute
.
array
.
constructor
(
(
indexes
.
length
+
splitIndexes
.
length
)
*
oldAttribute
.
itemSize
);
newArray
.
set
(
oldAttribute
.
array
);
newAttributes
[
name
]
=
new
BufferAttribute
(
newArray
,
oldAttribute
.
itemSize
,
oldAttribute
.
normalized
);
}
var
newIndexes
=
new
Uint32Array
(
indexes
.
length
);
newIndexes
.
set
(
indexes
);
...
...
@@ -206,22 +225,40 @@ var EdgeSplitModifier = function () {
var
split
=
splitIndexes
[
i
];
var
index
=
indexes
[
split
.
original
];
newPositions
[
offset
+
3
*
i
]
=
positions
[
3
*
index
];
newPositions
[
offset
+
3
*
i
+
1
]
=
positions
[
3
*
index
+
1
];
newPositions
[
offset
+
3
*
i
+
2
]
=
positions
[
3
*
index
+
2
];
for
(
const
attribute
of
Object
.
values
(
newAttributes
)
)
{
for
(
let
j
=
0
;
j
<
attribute
.
itemSize
;
j
++
)
{
attribute
.
array
[
(
indexes
.
length
+
i
)
*
attribute
.
itemSize
+
j
]
=
attribute
.
array
[
index
*
attribute
.
itemSize
+
j
];
}
}
for
(
var
j
of
split
.
indexes
)
{
newIndexes
[
j
]
=
offset
/
3
+
i
;
newIndexes
[
j
]
=
indexes
.
length
+
i
;
}
}
geometry
=
new
BufferGeometry
();
geometry
.
setAttribute
(
'
position
'
,
new
BufferAttribute
(
newPositions
,
3
,
true
)
);
geometry
.
setIndex
(
new
BufferAttribute
(
newIndexes
,
1
)
);
for
(
const
name
of
Object
.
keys
(
newAttributes
)
)
{
geometry
.
setAttribute
(
name
,
newAttributes
[
name
]
);
}
if
(
hadNormals
)
{
geometry
.
computeVertexNormals
();
}
return
geometry
;
};
...
...
examples/webgl_modifier_edgesplit.html
浏览文件 @
341a5c94
...
...
@@ -13,19 +13,20 @@
import
*
as
THREE
from
'
../build/three.module.js
'
;
import
{
OrbitControls
}
from
'
./jsm/controls/OrbitControls.js
'
;
import
{
OBJLoader
}
from
"
./jsm/loaders/OBJLoader.js
"
;
import
{
BufferGeometryUtils
}
from
"
./jsm/utils/BufferGeometryUtils.js
"
;
import
{
EdgeSplitModifier
}
from
"
./jsm/modifiers/EdgeSplitModifier.js
"
;
import
{
OBJLoader
}
from
'
./jsm/loaders/OBJLoader.js
'
;
import
{
EdgeSplitModifier
}
from
'
./jsm/modifiers/EdgeSplitModifier.js
'
;
import
{
GUI
}
from
"
./jsm/libs/dat.gui.module.js
"
;
import
{
GUI
}
from
'
./jsm/libs/dat.gui.module.js
'
;
let
renderer
,
scene
,
camera
;
let
modifier
,
mesh
,
baseGeometry
;
let
map
;
const
params
=
{
smoothShading
:
true
,
edgeSplit
:
true
,
cutOffAngle
:
20
,
showMap
:
false
,
};
init
();
...
...
@@ -63,10 +64,8 @@
'
./models/obj/cerberus/Cerberus.obj
'
,
function
(
group
)
{
// Retrieve Cerberus vertex positions only
const
modelGeometry
=
group
.
children
[
0
].
geometry
;
modelGeometry
.
deleteAttribute
(
'
normal
'
);
modelGeometry
.
deleteAttribute
(
'
uv
'
);
const
cerberus
=
group
.
children
[
0
];
const
modelGeometry
=
cerberus
.
geometry
;
modifier
=
new
EdgeSplitModifier
();
baseGeometry
=
modelGeometry
;
...
...
@@ -78,6 +77,13 @@
mesh
.
translateZ
(
1.5
);
scene
.
add
(
mesh
);
if
(
map
!==
undefined
&&
params
.
showMap
)
{
mesh
.
material
.
map
=
map
;
mesh
.
material
.
needsUpdate
=
true
;
}
render
();
}
...
...
@@ -85,12 +91,26 @@
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
new
THREE
.
TextureLoader
().
load
(
'
./models/obj/cerberus/Cerberus_A.jpg
'
,
function
(
texture
)
{
map
=
texture
;
if
(
mesh
!==
undefined
&&
params
.
showMap
)
{
mesh
.
material
.
map
=
map
;
mesh
.
material
.
needsUpdate
=
true
;
}
}
);
const
gui
=
new
GUI
(
{
name
:
"
Edge split modifier parameters
"
}
);
const
gui
=
new
GUI
(
{
name
:
'
Edge split modifier parameters
'
}
);
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
,
'
showMap
'
).
onFinishChange
(
updateMesh
);
gui
.
add
(
params
,
'
smoothShading
'
).
onFinishChange
(
updateMesh
);
gui
.
add
(
params
,
'
edgeSplit
'
).
onFinishChange
(
updateMesh
);
gui
.
add
(
params
,
'
cutOffAngle
'
).
min
(
0
).
max
(
180
).
onFinishChange
(
updateMesh
);
}
...
...
@@ -116,12 +136,10 @@
}
else
{
geometry
=
BufferGeometryUtils
.
mergeVertices
(
baseGeometry
)
;
geometry
=
baseGeometry
;
}
geometry
.
computeVertexNormals
();
return
geometry
;
}
...
...
@@ -129,12 +147,25 @@
function
updateMesh
()
{
mesh
.
geometry
=
getGeometry
();
if
(
mesh
!==
undefined
)
{
mesh
.
material
.
flatShading
=
params
.
smoothShading
===
false
;
mesh
.
material
.
needsUpdate
=
true
;
mesh
.
geometry
=
getGeometry
();
render
();
let
needsUpdate
=
mesh
.
material
.
flatShading
===
params
.
smoothShading
;
mesh
.
material
.
flatShading
=
params
.
smoothShading
===
false
;
if
(
map
!==
undefined
)
{
needsUpdate
=
needsUpdate
||
mesh
.
material
.
map
!==
(
params
.
showMap
?
map
:
null
);
mesh
.
material
.
map
=
params
.
showMap
?
map
:
null
;
}
mesh
.
material
.
needsUpdate
=
needsUpdate
;
render
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录