Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
cb5545a5
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,发现更多精彩内容 >>
提交
cb5545a5
编写于
4月 29, 2015
作者:
B
Ben Adams
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Example of moving to instancing using circle geo
上级
a8fbd8ca
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
284 addition
and
0 deletion
+284
-0
examples/webgl_instanced_particles_billboards.html
examples/webgl_instanced_particles_billboards.html
+284
-0
未找到文件。
examples/webgl_instanced_particles_billboards.html
0 → 100644
浏览文件 @
cb5545a5
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - instanced particles - billboards - colors
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
color
:
#ffffff
;
font-family
:
Monospace
;
font-size
:
13px
;
text-align
:
center
;
font-weight
:
bold
;
background-color
:
#000000
;
margin
:
0px
;
overflow
:
hidden
;
}
#info
{
position
:
absolute
;
top
:
0px
;
width
:
100%
;
padding
:
5px
;
}
a
{
color
:
#ffffff
;
}
#oldie
a
{
color
:
#da0
;
}
#notSupported
{
width
:
50%
;
margin
:
auto
;
border
:
2px
red
solid
;
margin-top
:
20px
;
padding
:
10px
;
}
</style>
</head>
<body>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
>
three.js
</a>
- instanced circle billboards - colors
<div
id=
"notSupported"
style=
"display:none"
>
Sorry your graphics card + browser does not support hardware instancing
</div>
</div>
<script
src=
"../build/three.min.js"
></script>
<script
src=
"js/Detector.js"
></script>
<script
src=
"js/libs/stats.min.js"
></script>
<script
id=
"vshader"
type=
"x-shader/x-vertex"
>
precision
highp
float
;
uniform
mat4
modelViewMatrix
;
uniform
mat4
projectionMatrix
;
attribute
vec3
position
;
attribute
vec2
uv
;
attribute
vec3
normal
;
attribute
vec4
translateScale
;
attribute
vec3
color
;
varying
vec2
vUv
;
varying
vec3
vColor
;
void
main
()
{
vec4
positionAdj
=
vec4
(
translateScale
.
xyz
,
1.0
);
vec4
mvPosition
=
modelViewMatrix
*
positionAdj
;
mvPosition
.
xyz
+=
position
*
translateScale
.
w
;
vUv
=
uv
;
vColor
=
color
;
gl_Position
=
projectionMatrix
*
mvPosition
;
}
</script>
<script
id=
"fshader"
type=
"x-shader/x-fragment"
>
precision
highp
float
;
uniform
sampler2D
map
;
varying
vec2
vUv
;
varying
vec3
vColor
;
void
main
()
{
vec4
diffuseColor
=
texture2D
(
map
,
vUv
);
gl_FragColor
=
vec4
(
diffuseColor
.
xyz
*
vColor
,
diffuseColor
.
w
);
if
(
diffuseColor
.
w
<
0.5
)
discard
;
}
</script>
<script>
var
container
,
stats
;
var
camera
,
scene
,
renderer
;
var
particles
,
geometry
,
material
,
sprite
;
var
mouseX
=
0
,
mouseY
=
0
;
var
windowHalfX
=
window
.
innerWidth
/
2
;
var
windowHalfY
=
window
.
innerHeight
/
2
;
function
init
()
{
if
(
!
Detector
.
webgl
)
{
Detector
.
addGetWebGLMessage
();
return
false
;
}
renderer
=
new
THREE
.
WebGLRenderer
();
if
(
!
renderer
.
supportsInstancedArrays
)
{
document
.
getElementById
(
"
notSupported
"
).
style
.
display
=
""
;
return
false
;
}
container
=
document
.
createElement
(
'
div
'
);
document
.
body
.
appendChild
(
container
);
camera
=
new
THREE
.
PerspectiveCamera
(
50
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
3000
);
camera
.
position
.
z
=
1400
;
scene
=
new
THREE
.
Scene
();
geometry
=
new
THREE
.
InstancedBufferGeometry
().
copy
(
new
THREE
.
CircleBufferGeometry
(
1
,
16
)
);
sprite
=
THREE
.
ImageUtils
.
loadTexture
(
"
textures/sprites/ball.png
"
);
var
particleCount
=
5000
;
var
translateScaleArray
=
new
Float32Array
(
4
*
particleCount
);
var
colorsArray
=
new
Float32Array
(
3
*
particleCount
);
var
color
=
new
THREE
.
Color
(
0xffffff
);
for
(
i
=
0
,
ii
=
0
,
ul
=
particleCount
*
4
;
i
<
ul
;
i
+=
4
,
ii
+=
3
)
{
translateScaleArray
[
i
]
=
2000
*
Math
.
random
()
-
1000
;
translateScaleArray
[
i
+
1
]
=
2000
*
Math
.
random
()
-
1000
;
translateScaleArray
[
i
+
2
]
=
2000
*
Math
.
random
()
-
1000
;
translateScaleArray
[
i
+
3
]
=
24
;
color
.
setHSL
((
translateScaleArray
[
i
]
+
1000
)
/
2000
,
1
,
0.5
);
colorsArray
[
ii
]
=
color
.
r
;
colorsArray
[
ii
+
1
]
=
color
.
g
;
colorsArray
[
ii
+
2
]
=
color
.
b
;
}
geometry
.
addAttribute
(
"
translateScale
"
,
new
THREE
.
InstancedBufferAttribute
(
translateScaleArray
,
4
,
1
)
);
geometry
.
addAttribute
(
"
color
"
,
new
THREE
.
InstancedBufferAttribute
(
colorsArray
,
3
,
1
)
);
material
=
new
THREE
.
RawShaderMaterial
(
{
uniforms
:
{
map
:
{
type
:
"
t
"
,
value
:
sprite
}
},
vertexShader
:
document
.
getElementById
(
'
vshader
'
).
textContent
,
fragmentShader
:
document
.
getElementById
(
'
fshader
'
).
textContent
,
depthTest
:
true
,
depthWrite
:
true
,
attributes
:
{
'
translateScale
'
:
1
,
'
color
'
:
2
}
}
);
scene
.
add
(
new
THREE
.
Mesh
(
geometry
,
material
)
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
container
.
appendChild
(
renderer
.
domElement
);
//
stats
=
new
Stats
();
stats
.
domElement
.
style
.
position
=
'
absolute
'
;
stats
.
domElement
.
style
.
top
=
'
0px
'
;
container
.
appendChild
(
stats
.
domElement
);
//
document
.
addEventListener
(
'
mousemove
'
,
onDocumentMouseMove
,
false
);
document
.
addEventListener
(
'
touchstart
'
,
onDocumentTouchStart
,
false
);
document
.
addEventListener
(
'
touchmove
'
,
onDocumentTouchMove
,
false
);
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
return
true
;
}
function
onDocumentMouseMove
(
event
)
{
mouseX
=
event
.
clientX
-
windowHalfX
;
mouseY
=
event
.
clientY
-
windowHalfY
;
}
function
onDocumentTouchStart
(
event
)
{
if
(
event
.
touches
.
length
===
1
)
{
event
.
preventDefault
();
mouseX
=
event
.
touches
[
0
].
pageX
-
windowHalfX
;
mouseY
=
event
.
touches
[
0
].
pageY
-
windowHalfY
;
}
}
function
onDocumentTouchMove
(
event
)
{
if
(
event
.
touches
.
length
===
1
)
{
event
.
preventDefault
();
mouseX
=
event
.
touches
[
0
].
pageX
-
windowHalfX
;
mouseY
=
event
.
touches
[
0
].
pageY
-
windowHalfY
;
}
}
function
onWindowResize
(
event
)
{
windowHalfX
=
window
.
innerWidth
/
2
;
windowHalfY
=
window
.
innerHeight
/
2
;
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
//
function
animate
()
{
requestAnimationFrame
(
animate
);
render
();
stats
.
update
();
}
var
lastTime
=
0
;
function
render
()
{
var
time
=
Date
.
now
()
*
0.00005
;
camera
.
position
.
x
+=
(
mouseX
-
camera
.
position
.
x
)
*
0.05
;
camera
.
position
.
y
+=
(
-
mouseY
-
camera
.
position
.
y
)
*
0.05
;
camera
.
lookAt
(
scene
.
position
);
renderer
.
render
(
scene
,
camera
);
}
if
(
init
()
)
{
animate
();
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录