Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
c94cb5fe
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,发现更多精彩内容 >>
提交
c94cb5fe
编写于
4月 29, 2015
作者:
R
Ricardo Cabello
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6475 from benaadams/circle-buffer-geo
CircleBufferGeometry
上级
caeb33fc
cb5545a5
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
357 addition
and
0 deletion
+357
-0
examples/webgl_instanced_particles_billboards.html
examples/webgl_instanced_particles_billboards.html
+284
-0
src/extras/geometries/CircleBufferGeometry.js
src/extras/geometries/CircleBufferGeometry.js
+72
-0
utils/build/includes/extras.json
utils/build/includes/extras.json
+1
-0
未找到文件。
examples/webgl_instanced_particles_billboards.html
0 → 100644
浏览文件 @
c94cb5fe
<!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>
src/extras/geometries/CircleBufferGeometry.js
0 → 100644
浏览文件 @
c94cb5fe
/**
* @author benaadams / https://twitter.com/ben_a_adams
*/
THREE
.
CircleBufferGeometry
=
function
(
radius
,
segments
,
thetaStart
,
thetaLength
)
{
THREE
.
BufferGeometry
.
call
(
this
);
this
.
type
=
'
CircleBufferGeometry
'
;
this
.
parameters
=
{
radius
:
radius
,
segments
:
segments
,
thetaStart
:
thetaStart
,
thetaLength
:
thetaLength
};
radius
=
radius
||
50
;
segments
=
segments
!==
undefined
?
Math
.
max
(
3
,
segments
)
:
8
;
thetaStart
=
thetaStart
!==
undefined
?
thetaStart
:
0
;
thetaLength
=
thetaLength
!==
undefined
?
thetaLength
:
Math
.
PI
*
2
;
var
i
;
var
vertices
=
segments
+
2
;
var
positions
=
new
Float32Array
(
3
*
vertices
);
this
.
addAttribute
(
'
position
'
,
new
THREE
.
BufferAttribute
(
positions
,
3
)
);
var
normals
=
new
Float32Array
(
3
*
vertices
);
this
.
addAttribute
(
'
normal
'
,
new
THREE
.
BufferAttribute
(
normals
,
3
)
);
var
uvs
=
new
Float32Array
(
2
*
vertices
);
this
.
addAttribute
(
'
uv
'
,
new
THREE
.
BufferAttribute
(
uvs
,
2
)
);
// center data is already zero, but need to set a few extras
normals
[
3
]
=
1.0
;
uvs
[
0
]
=
0.5
;
uvs
[
1
]
=
0.5
;
for
(
s
=
0
,
i
=
3
,
ii
=
2
;
s
<
vertices
;
s
++
,
i
+=
3
,
ii
+=
2
)
{
var
segment
=
thetaStart
+
s
/
segments
*
thetaLength
;
positions
[
i
]
=
radius
*
Math
.
cos
(
segment
);
positions
[
i
+
1
]
=
radius
*
Math
.
sin
(
segment
);
normals
[
i
+
2
]
=
1
;
// normal z
uvs
[
ii
]
=
(
positions
[
i
]
/
radius
+
1
)
/
2
;
uvs
[
ii
+
1
]
=
(
positions
[
i
+
1
]
/
radius
+
1
)
/
2
;
}
var
indices
=
[];
for
(
i
=
1
;
i
<=
segments
;
i
++
)
{
indices
.
push
(
i
);
indices
.
push
(
i
+
1
);
indices
.
push
(
0
);
}
this
.
addAttribute
(
'
index
'
,
new
THREE
.
BufferAttribute
(
new
Uint16Array
(
indices
),
1
)
);
this
.
computeFaceNormals
();
this
.
boundingSphere
=
new
THREE
.
Sphere
(
new
THREE
.
Vector3
(),
radius
);
};
THREE
.
CircleBufferGeometry
.
prototype
=
Object
.
create
(
THREE
.
BufferGeometry
.
prototype
);
THREE
.
CircleBufferGeometry
.
prototype
.
constructor
=
THREE
.
CircleBufferGeometry
;
utils/build/includes/extras.json
浏览文件 @
c94cb5fe
...
...
@@ -28,6 +28,7 @@
"src/extras/animation/MorphAnimation.js"
,
"src/extras/geometries/BoxGeometry.js"
,
"src/extras/geometries/CircleGeometry.js"
,
"src/extras/geometries/CircleBufferGeometry.js"
,
"src/extras/geometries/CylinderGeometry.js"
,
"src/extras/geometries/EdgesGeometry.js"
,
"src/extras/geometries/ExtrudeGeometry.js"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录