Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
27ba8e1c
T
three.js
项目概览
车家大少爷
/
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,发现更多精彩内容 >>
未验证
提交
27ba8e1c
编写于
10月 29, 2018
作者:
M
Mr.doob
提交者:
GitHub
10月 29, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15145 from WestLangley/dev-waves_example
Particles waves example: convert to THREE.Points
上级
0c360b76
3809b1fa
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
81 addition
and
18 deletion
+81
-18
examples/webgl_points_waves.html
examples/webgl_points_waves.html
+81
-18
未找到文件。
examples/webgl_points_waves.html
浏览文件 @
27ba8e1c
...
...
@@ -40,6 +40,36 @@
<script
src=
"js/WebGL.js"
></script>
<script
src=
"js/libs/stats.min.js"
></script>
<script
type=
"x-shader/x-vertex"
id=
"vertexshader"
>
attribute
float
scale
;
void
main
()
{
vec4
mvPosition
=
modelViewMatrix
*
vec4
(
position
,
1.0
);
gl_PointSize
=
scale
*
(
300.0
/
-
mvPosition
.
z
);
gl_Position
=
projectionMatrix
*
mvPosition
;
}
</script>
<script
type=
"x-shader/x-fragment"
id=
"fragmentshader"
>
uniform
vec3
color
;
void
main
()
{
if
(
length
(
gl_PointCoord
-
vec2
(
0.5
,
0.5
)
)
>
0.475
)
discard
;
gl_FragColor
=
vec4
(
color
,
1.0
);
}
</script>
<script>
if
(
WEBGL
.
isWebGLAvailable
()
===
false
)
{
...
...
@@ -53,7 +83,7 @@
var
container
,
stats
;
var
camera
,
scene
,
renderer
;
var
particles
,
particle
,
count
=
0
;
var
particles
,
count
=
0
;
var
mouseX
=
0
,
mouseY
=
0
;
...
...
@@ -73,30 +103,54 @@
scene
=
new
THREE
.
Scene
();
particles
=
new
Array
();
var
material
=
new
THREE
.
SpriteMaterial
(
{
//
map
:
new
THREE
.
TextureLoader
().
load
(
'
textures/sprites/circle.png
'
),
var
numParticles
=
AMOUNTX
*
AMOUNTY
;
}
);
var
positions
=
new
Float32Array
(
numParticles
*
3
);
var
scales
=
new
Float32Array
(
numParticles
);
var
i
=
0
;
var
i
=
0
,
j
=
0
;
for
(
var
ix
=
0
;
ix
<
AMOUNTX
;
ix
++
)
{
for
(
var
iy
=
0
;
iy
<
AMOUNTY
;
iy
++
)
{
particle
=
particles
[
i
++
]
=
new
THREE
.
Sprite
(
material
);
particle
.
position
.
x
=
ix
*
SEPARATION
-
(
(
AMOUNTX
*
SEPARATION
)
/
2
);
particle
.
position
.
z
=
iy
*
SEPARATION
-
(
(
AMOUNTY
*
SEPARATION
)
/
2
);
scene
.
add
(
particle
);
positions
[
i
]
=
ix
*
SEPARATION
-
(
(
AMOUNTX
*
SEPARATION
)
/
2
);
// x
positions
[
i
+
1
]
=
0
;
// y
positions
[
i
+
2
]
=
iy
*
SEPARATION
-
(
(
AMOUNTY
*
SEPARATION
)
/
2
);
// z
scales
[
j
]
=
1
;
i
+=
3
;
j
++
;
}
}
renderer
=
new
THREE
.
WebGLRenderer
();
var
geometry
=
new
THREE
.
BufferGeometry
();
geometry
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
positions
,
3
)
);
geometry
.
addAttribute
(
'
scale
'
,
new
THREE
.
BufferAttribute
(
scales
,
1
)
);
var
material
=
new
THREE
.
ShaderMaterial
(
{
uniforms
:
{
color
:
{
value
:
new
THREE
.
Color
(
0xffffff
)
},
},
vertexShader
:
document
.
getElementById
(
'
vertexshader
'
).
textContent
,
fragmentShader
:
document
.
getElementById
(
'
fragmentshader
'
).
textContent
}
);
//
particles
=
new
THREE
.
Points
(
geometry
,
material
);
scene
.
add
(
particles
);
//
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
container
.
appendChild
(
renderer
.
domElement
);
...
...
@@ -178,22 +232,31 @@
camera
.
position
.
y
+=
(
-
mouseY
-
camera
.
position
.
y
)
*
.
05
;
camera
.
lookAt
(
scene
.
position
);
var
i
=
0
;
var
positions
=
particles
.
geometry
.
attributes
.
position
.
array
;
var
scales
=
particles
.
geometry
.
attributes
.
scale
.
array
;
var
i
=
0
,
j
=
0
;
for
(
var
ix
=
0
;
ix
<
AMOUNTX
;
ix
++
)
{
for
(
var
iy
=
0
;
iy
<
AMOUNTY
;
iy
++
)
{
particle
=
particles
[
i
++
];
particle
.
position
.
y
=
(
Math
.
sin
(
(
ix
+
count
)
*
0.3
)
*
50
)
+
(
Math
.
sin
(
(
iy
+
count
)
*
0.5
)
*
50
);
particle
.
scale
.
x
=
particle
.
scale
.
y
=
(
Math
.
sin
(
(
ix
+
count
)
*
0.3
)
+
1
)
*
4
+
(
Math
.
sin
(
(
iy
+
count
)
*
0.5
)
+
1
)
*
4
;
positions
[
i
+
1
]
=
(
Math
.
sin
(
(
ix
+
count
)
*
0.3
)
*
50
)
+
(
Math
.
sin
(
(
iy
+
count
)
*
0.5
)
*
50
);
scales
[
j
]
=
(
Math
.
sin
(
(
ix
+
count
)
*
0.3
)
+
1
)
*
8
+
(
Math
.
sin
(
(
iy
+
count
)
*
0.5
)
+
1
)
*
8
;
i
+=
3
;
j
++
;
}
}
particles
.
geometry
.
attributes
.
position
.
needsUpdate
=
true
;
particles
.
geometry
.
attributes
.
scale
.
needsUpdate
=
true
;
renderer
.
render
(
scene
,
camera
);
count
+=
0.1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录