Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
6d1a600b
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,发现更多精彩内容 >>
提交
6d1a600b
编写于
12月 12, 2019
作者:
D
Don McCurdy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples: Improve performance of 'instancing / scatter' animation
上级
ff616175
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
13 deletion
+30
-13
examples/webgl_instancing_scatter.html
examples/webgl_instancing_scatter.html
+30
-13
未找到文件。
examples/webgl_instancing_scatter.html
浏览文件 @
6d1a600b
...
...
@@ -36,10 +36,12 @@
var
sampler
;
var
count
=
api
.
count
;
var
ages
=
new
Float32Array
(
count
);
var
scales
=
new
Float32Array
(
count
);
var
dummy
=
new
THREE
.
Object3D
();
var
_sPosition
=
new
THREE
.
Vector3
();
var
_sNormal
=
new
THREE
.
Vector3
();
var
_position
=
new
THREE
.
Vector3
();
var
_normal
=
new
THREE
.
Vector3
();
var
_scale
=
new
THREE
.
Vector3
();
// var surfaceGeometry = new THREE.BoxBufferGeometry( 10, 10, 10 ).toNonIndexed();
var
surfaceGeometry
=
new
THREE
.
TorusKnotBufferGeometry
(
10
,
3
,
100
,
16
).
toNonIndexed
();
...
...
@@ -49,6 +51,14 @@
// Source: https://gist.github.com/gre/1650294
var
easeOutCubic
=
function
(
t
)
{
return
(
--
t
)
*
t
*
t
+
1
;
};
// Scaling curve causes particles to grow quickly, ease gradually into full scale, then
// disappear quickly. More of the particle's lifetime is spent around full scale.
var
scaleCurve
=
function
(
t
)
{
return
Math
.
abs
(
easeOutCubic
(
(
t
>
0.5
?
1
-
t
:
t
)
*
2
)
);
};
var
loader
=
new
GLTFLoader
();
loader
.
load
(
'
./models/gltf/Flower/Flower.glb
'
,
function
(
gltf
)
{
...
...
@@ -184,6 +194,7 @@
for
(
var
i
=
0
;
i
<
count
;
i
++
)
{
ages
[
i
]
=
Math
.
random
();
scales
[
i
]
=
scaleCurve
(
ages
[
i
]
);
resampleParticle
(
i
);
...
...
@@ -198,12 +209,12 @@
function
resampleParticle
(
i
)
{
sampler
.
sample
(
_
sPosition
,
_sN
ormal
);
_
sNormal
.
add
(
_sP
osition
);
sampler
.
sample
(
_
position
,
_n
ormal
);
_
normal
.
add
(
_p
osition
);
dummy
.
position
.
copy
(
_
sP
osition
);
dummy
.
scale
.
set
(
ages
[
i
],
ages
[
i
],
ag
es
[
i
]
);
dummy
.
lookAt
(
_
sN
ormal
);
dummy
.
position
.
copy
(
_
p
osition
);
dummy
.
scale
.
set
(
scales
[
i
],
scales
[
i
],
scal
es
[
i
]
);
dummy
.
lookAt
(
_
n
ormal
);
dummy
.
updateMatrix
();
stemMesh
.
setMatrixAt
(
i
,
dummy
.
matrix
);
...
...
@@ -211,13 +222,16 @@
}
function
updateParticle
(
i
,
)
{
function
updateParticle
(
i
)
{
// Update lifecycle.
ages
[
i
]
+=
0.005
;
if
(
ages
[
i
]
>=
1
)
{
ages
[
i
]
=
0.001
;
scales
[
i
]
=
scaleCurve
(
ages
[
i
]
);
resampleParticle
(
i
);
...
...
@@ -225,13 +239,16 @@
}
var
scale
=
Math
.
abs
(
easeOutCubic
(
(
ages
[
i
]
>
0.5
?
1
-
ages
[
i
]
:
ages
[
i
]
)
*
2
)
);
// Update scale.
stemMesh
.
getMatrixAt
(
i
,
dummy
.
matrix
);
dummy
.
matrix
.
decompose
(
dummy
.
position
,
dummy
.
quaternion
,
dummy
.
scale
);
dummy
.
scale
.
set
(
scale
,
scale
,
scale
);
dummy
.
updateMatrix
();
var
prevScale
=
scales
[
i
];
scales
[
i
]
=
scaleCurve
(
ages
[
i
]
);
_scale
.
set
(
scales
[
i
]
/
prevScale
,
scales
[
i
]
/
prevScale
,
scales
[
i
]
/
prevScale
);
// Update transform.
stemMesh
.
getMatrixAt
(
i
,
dummy
.
matrix
);
dummy
.
matrix
.
scale
(
_scale
);
stemMesh
.
setMatrixAt
(
i
,
dummy
.
matrix
);
blossomMesh
.
setMatrixAt
(
i
,
dummy
.
matrix
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录