Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
c5e9eefc
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,发现更多精彩内容 >>
提交
c5e9eefc
编写于
11月 10, 2015
作者:
V
vincent courtalon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adding support for connecting any AudioNode to THREE.Audio as a source
上级
5d363fdd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
109 addition
and
6 deletion
+109
-6
examples/misc_sound.html
examples/misc_sound.html
+49
-6
src/audio/Audio.js
src/audio/Audio.js
+60
-0
未找到文件。
examples/misc_sound.html
浏览文件 @
c5e9eefc
...
...
@@ -88,6 +88,7 @@
material_sphere1
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0xffaa00
,
shading
:
THREE
.
FlatShading
}
);
material_sphere2
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0xff2200
,
shading
:
THREE
.
FlatShading
}
);
material_sphere3
=
new
THREE
.
MeshLambertMaterial
(
{
color
:
0x6622aa
,
shading
:
THREE
.
FlatShading
}
);
// sound spheres
...
...
@@ -116,15 +117,37 @@
sound2
.
setRefDistance
(
20
);
sound2
.
autoplay
=
true
;
mesh2
.
add
(
sound2
);
var
mesh3
=
new
THREE
.
Mesh
(
sphere
,
material_sphere3
);
mesh3
.
position
.
set
(
0
,
30
,
-
250
);
scene
.
add
(
mesh3
);
var
sound3
=
new
THREE
.
PositionalAudio
(
listener
);
var
oscillator
=
listener
.
context
.
createOscillator
();
oscillator
.
type
=
'
sine
'
;
oscillator
.
frequency
.
value
=
144
;
oscillator
.
start
(
0
);
sound3
.
setNodeSource
(
oscillator
);
sound3
.
setRefDistance
(
20
);
sound3
.
setVolume
(
0.5
);
mesh3
.
add
(
sound3
);
/* buffer2.load( 'sounds/376737_Skullbeatz___Bad_Cat_Maste.ogg' );
sound2.setBuffer(buffer2);
sound2.setRefDistance( 20 );
sound2.autoplay = true;
mesh2.add( sound2 );
*/
// global ambient audio
var
sound
3
=
new
THREE
.
Audio
(
listener
);
var
sound
4
=
new
THREE
.
Audio
(
listener
);
var
buffer3
=
new
THREE
.
AudioBuffer
(
listener
);
buffer3
.
load
(
'
sounds/Project_Utopia.ogg
'
);
sound
3
.
setBuffer
(
buffer3
);
sound
3
.
autoplay
=
true
;
sound
3
.
setLoop
(
true
);
sound
4
.
setBuffer
(
buffer3
);
sound
4
.
autoplay
=
true
;
sound
4
.
setLoop
(
true
);
sound3
.
setVolume
(
0.5
);
// ground
...
...
@@ -140,11 +163,18 @@
this
.
master
=
listener
.
getMasterVolume
();
this
.
firstSphere
=
sound1
.
getVolume
();
this
.
secondSphere
=
sound2
.
getVolume
();
this
.
Ambient
=
sound3
.
getVolume
();
this
.
thirdSphere
=
sound3
.
getVolume
();
this
.
Ambient
=
sound4
.
getVolume
();
};
var
GeneratorControls
=
function
()
{
this
.
frequency
=
oscillator
.
frequency
.
value
;
this
.
wavetype
=
oscillator
.
type
;
}
var
gui
=
new
dat
.
GUI
();
var
soundControls
=
new
SoundControls
();
var
generatorControls
=
new
GeneratorControls
();
var
volumeFolder
=
gui
.
addFolder
(
'
sound volume
'
);
var
generatorFolder
=
gui
.
addFolder
(
'
sound generator
'
);
volumeFolder
.
add
(
soundControls
,
'
master
'
).
min
(
0.0
).
max
(
1.0
).
step
(
0.01
).
onChange
(
function
()
{
listener
.
setMasterVolume
(
soundControls
.
master
);
});
...
...
@@ -154,10 +184,22 @@
volumeFolder
.
add
(
soundControls
,
'
secondSphere
'
).
min
(
0.0
).
max
(
1.0
).
step
(
0.01
).
onChange
(
function
()
{
sound2
.
setVolume
(
soundControls
.
secondSphere
);
});
volumeFolder
.
add
(
soundControls
,
'
thirdSphere
'
).
min
(
0.0
).
max
(
1.0
).
step
(
0.01
).
onChange
(
function
()
{
sound3
.
setVolume
(
soundControls
.
thirdSphere
);
});
volumeFolder
.
add
(
soundControls
,
'
Ambient
'
).
min
(
0.0
).
max
(
1.0
).
step
(
0.01
).
onChange
(
function
()
{
sound
3
.
setVolume
(
soundControls
.
Ambient
);
sound
4
.
setVolume
(
soundControls
.
Ambient
);
});
volumeFolder
.
open
();
generatorFolder
.
add
(
generatorControls
,
'
frequency
'
).
min
(
50.0
).
max
(
5000.0
).
step
(
1.0
).
onChange
(
function
()
{
oscillator
.
frequency
.
value
=
generatorControls
.
frequency
;
});
generatorFolder
.
add
(
generatorControls
,
'
wavetype
'
,
[
'
sine
'
,
'
square
'
,
'
sawtooth
'
,
'
triangle
'
]).
onChange
(
function
()
{
oscillator
.
type
=
generatorControls
.
wavetype
;
});
generatorFolder
.
open
();
...
...
@@ -210,6 +252,7 @@
material_sphere1
.
color
.
setHSL
(
0.0
,
0.3
+
0.7
*
(
1
+
Math
.
cos
(
time
)
)
/
2
,
0.5
);
material_sphere2
.
color
.
setHSL
(
0.1
,
0.3
+
0.7
*
(
1
+
Math
.
sin
(
time
)
)
/
2
,
0.5
);
material_sphere3
.
color
.
setHSL
(
0.1
,
0.3
+
0.7
*
(
1
+
Math
.
sin
(
time
)
)
/
2
,
0.5
);
renderer
.
render
(
scene
,
camera
);
...
...
src/audio/Audio.js
浏览文件 @
c5e9eefc
...
...
@@ -20,18 +20,35 @@ THREE.Audio = function ( listener ) {
this
.
startTime
=
0
;
this
.
playbackRate
=
1
;
this
.
isPlaying
=
false
;
this
.
hasPlaybackControl
=
true
;
this
.
sourceType
=
'
empty
'
;
};
THREE
.
Audio
.
prototype
=
Object
.
create
(
THREE
.
Object3D
.
prototype
);
THREE
.
Audio
.
prototype
.
constructor
=
THREE
.
Audio
;
THREE
.
Audio
.
prototype
.
setNodeSource
=
function
(
audioNode
)
{
this
.
hasPlaybackControl
=
false
;
this
.
sourceType
=
'
audioNode
'
;
this
.
source
=
audioNode
;
this
.
connect
();
return
this
;
};
THREE
.
Audio
.
prototype
.
setBuffer
=
function
(
audioBuffer
)
{
var
scope
=
this
;
audioBuffer
.
onReady
(
function
(
buffer
)
{
scope
.
source
.
buffer
=
buffer
;
scope
.
sourceType
=
'
buffer
'
;
if
(
scope
.
autoplay
)
scope
.
play
();
});
...
...
@@ -49,6 +66,14 @@ THREE.Audio.prototype.play = function () {
return
;
}
if
(
this
.
hasPlaybackControl
===
false
)
{
console
.
warn
(
'
THREE.Audio: this Audio has no playback control.
'
);
return
;
}
var
source
=
this
.
context
.
createBufferSource
();
...
...
@@ -68,6 +93,13 @@ THREE.Audio.prototype.play = function () {
THREE
.
Audio
.
prototype
.
pause
=
function
()
{
if
(
this
.
hasPlaybackControl
===
false
)
{
console
.
warn
(
'
THREE.Audio: this Audio has no playback control.
'
);
return
;
}
this
.
source
.
stop
();
this
.
startTime
=
this
.
context
.
currentTime
;
...
...
@@ -75,6 +107,13 @@ THREE.Audio.prototype.pause = function () {
THREE
.
Audio
.
prototype
.
stop
=
function
()
{
if
(
this
.
hasPlaybackControl
===
false
)
{
console
.
warn
(
'
THREE.Audio: this Audio has no playback control.
'
);
return
;
}
this
.
source
.
stop
();
this
.
startTime
=
0
;
...
...
@@ -134,6 +173,13 @@ THREE.Audio.prototype.getFilter = function () {
THREE
.
Audio
.
prototype
.
setPlaybackRate
=
function
(
value
)
{
if
(
this
.
hasPlaybackControl
===
false
)
{
console
.
warn
(
'
THREE.Audio: this Audio has no playback control.
'
);
return
;
}
this
.
playbackRate
=
value
;
if
(
this
.
isPlaying
===
true
)
{
...
...
@@ -158,11 +204,25 @@ THREE.Audio.prototype.onEnded = function() {
THREE
.
Audio
.
prototype
.
setLoop
=
function
(
value
)
{
if
(
this
.
hasPlaybackControl
===
false
)
{
console
.
warn
(
'
THREE.Audio: this Audio has no playback control.
'
);
return
;
}
this
.
source
.
loop
=
value
;
};
THREE
.
Audio
.
prototype
.
getLoop
=
function
()
{
if
(
this
.
hasPlaybackControl
===
false
)
{
console
.
warn
(
'
THREE.Audio: this Audio has no playback control.
'
);
return
false
;
}
return
this
.
source
.
loop
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录