Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
3532dd14
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,发现更多精彩内容 >>
提交
3532dd14
编写于
10月 13, 2017
作者:
M
Mugen87
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples: Added WebAudio timing example
上级
e8ddb44f
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
222 addition
and
0 deletion
+222
-0
examples/sounds/ping_pong.mp3
examples/sounds/ping_pong.mp3
+0
-0
examples/webaudio_timing.html
examples/webaudio_timing.html
+222
-0
未找到文件。
examples/sounds/ping_pong.mp3
0 → 100644
浏览文件 @
3532dd14
文件已添加
examples/webaudio_timing.html
0 → 100644
浏览文件 @
3532dd14
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webaudio - timing
</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
{
background
:
#777
;
padding
:
0
;
margin
:
0
;
font-weight
:
bold
;
overflow
:
hidden
;
}
#info
{
position
:
absolute
;
top
:
0px
;
width
:
100%
;
color
:
#ffffff
;
padding
:
5px
;
font-family
:
Monospace
;
font-size
:
13px
;
text-align
:
center
;
}
a
{
color
:
#ffffff
;
}
</style>
<script
src=
"../build/three.js"
></script>
<script
src=
"js/Detector.js"
></script>
<script
src=
"js/controls/OrbitControls.js"
></script>
</head>
<body>
<div
id=
"container"
></div>
<div
id=
"info"
>
<a
href=
"https://threejs.org"
target=
"_blank"
rel=
"noopener noreferrer"
>
three.js
</a>
webaudio timing | sound effect by
<a
href=
"https://freesound.org/people/michorvath/sounds/269718/"
target=
"_blank"
rel=
"noopener noreferrer"
>
michorvath
</a>
</div>
<script>
if
(
!
Detector
.
webgl
)
Detector
.
addGetWebGLMessage
();
var
scene
,
camera
,
renderer
,
audio
;
var
objects
=
[];
init
();
function
init
()
{
var
container
=
document
.
getElementById
(
'
container
'
);
scene
=
new
THREE
.
Scene
();
//
camera
=
new
THREE
.
PerspectiveCamera
(
45
,
window
.
innerWidth
/
window
.
innerHeight
,
0.1
,
100
);
camera
.
position
.
set
(
7
,
3
,
7
);
// lights
var
ambientLight
=
new
THREE
.
AmbientLight
(
0xcccccc
,
0.4
);
scene
.
add
(
ambientLight
);
var
directionalLight
=
new
THREE
.
DirectionalLight
(
0xffffff
,
0.7
);
directionalLight
.
position
.
set
(
0
,
5
,
5
);
scene
.
add
(
directionalLight
);
var
d
=
5
;
directionalLight
.
castShadow
=
true
;
directionalLight
.
shadow
.
camera
.
left
=
-
d
;
directionalLight
.
shadow
.
camera
.
right
=
d
;
directionalLight
.
shadow
.
camera
.
top
=
d
;
directionalLight
.
shadow
.
camera
.
bottom
=
-
d
;
directionalLight
.
shadow
.
camera
.
near
=
1
;
directionalLight
.
shadow
.
camera
.
far
=
20
;
directionalLight
.
shadow
.
mapSize
.
x
=
1024
;
directionalLight
.
shadow
.
mapSize
.
y
=
1024
;
// audio
var
audioLoader
=
new
THREE
.
AudioLoader
();
var
listener
=
new
THREE
.
AudioListener
();
camera
.
add
(
listener
);
// floor
var
floorGeometry
=
new
THREE
.
PlaneBufferGeometry
(
10
,
10
);
var
floorMaterial
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x4676b6
}
);
var
floor
=
new
THREE
.
Mesh
(
floorGeometry
,
floorMaterial
);
floor
.
rotation
.
x
=
Math
.
PI
*
-
0.5
;
floor
.
receiveShadow
=
true
;
scene
.
add
(
floor
);
// objects
var
count
=
5
;
var
radius
=
3
;
var
ballGeometry
=
new
THREE
.
SphereBufferGeometry
(
0.3
,
32
,
16
);
ballGeometry
.
translate
(
0
,
0.3
,
0
);
var
ballMaterial
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0xcccccc
}
);
// create objects when audio buffer is loaded
audioLoader
.
load
(
'
sounds/ping_pong.mp3
'
,
function
(
buffer
)
{
for
(
var
i
=
0
;
i
<
count
;
i
++
)
{
var
s
=
i
/
count
*
Math
.
PI
*
2
;
var
ball
=
new
THREE
.
Mesh
(
ballGeometry
,
ballMaterial
);
ball
.
castShadow
=
true
;
ball
.
userData
.
down
=
false
;
ball
.
position
.
x
=
radius
*
Math
.
cos
(
s
);
ball
.
position
.
z
=
radius
*
Math
.
sin
(
s
);
var
audio
=
new
THREE
.
PositionalAudio
(
listener
);
audio
.
setBuffer
(
buffer
);
ball
.
add
(
audio
);
scene
.
add
(
ball
);
objects
.
push
(
ball
);
}
animate
();
}
);
//
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
shadowMap
.
enabled
=
true
;
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
setClearColor
(
0x000000
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
container
.
appendChild
(
renderer
.
domElement
);
//
var
controls
=
new
THREE
.
OrbitControls
(
camera
,
renderer
.
domElement
);
controls
.
minDistance
=
1
;
controls
.
maxDistance
=
25
;
//
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
onWindowResize
(
event
)
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
function
animate
()
{
requestAnimationFrame
(
animate
);
render
();
}
var
speed
=
1.7
;
var
height
=
3
;
var
offset
=
0.5
;
var
time
=
0
;
function
render
()
{
time
+=
0.02
;
for
(
var
i
=
0
;
i
<
objects
.
length
;
i
++
)
{
var
ball
=
objects
[
i
];
var
previousHeight
=
ball
.
position
.
y
;
ball
.
position
.
y
=
Math
.
abs
(
Math
.
sin
(
i
*
offset
+
(
time
*
speed
)
)
*
height
);
if
(
ball
.
position
.
y
<
previousHeight
)
{
ball
.
userData
.
down
=
true
;
}
else
{
if
(
ball
.
userData
.
down
===
true
)
{
// ball changed direction from down to up
var
audio
=
ball
.
children
[
0
];
audio
.
play
();
// play audio with perfect timing when ball hits the surface
ball
.
userData
.
down
=
false
;
}
}
}
renderer
.
render
(
scene
,
camera
);
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录