-
Notifications
You must be signed in to change notification settings - Fork 51
/
gamesounds.html
114 lines (98 loc) · 3.79 KB
/
gamesounds.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html>
<script src='vendor/three.js/build/three.min.js'></script>
<script src='helpers/webaudiox.gamesounds.js'></script>
<script src='../lib/webaudiox.lineout.js'></script>
<script src='../lib/webaudiox.loadbuffer.js'></script>
<script src='../lib/webaudiox.three.js'></script>
<script src='../lib/webaudiox.shim.js'></script>
<body style='margin: 0px; background-color: #bbbbbb; overflow: hidden;'><script>
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
var updateFcts = [];
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 100 );
camera.position.z = 0;
//////////////////////////////////////////////////////////////////////////////////
// add an object and make it move //
//////////////////////////////////////////////////////////////////////////////////
var geometry = new THREE.CubeGeometry( 1, 1, 1)
var material = new THREE.MeshBasicMaterial()
var mesh = new THREE.Mesh( geometry, material )
scene.add( mesh )
updateFcts.push(function(delta, now){
var angle = 0.1 * now * Math.PI*2
mesh.position.x = Math.cos(angle)*3
mesh.position.z = Math.sin(angle)*3
})
updateFcts.push(function(delta, now){
mesh.rotation.x += 3 * delta;
mesh.rotation.y += 2 * delta;
})
//////////////////////////////////////////////////////////////////////////////////
// to play immediatly //
//////////////////////////////////////////////////////////////////////////////////
var sounds = new WebAudiox.GameSounds()
sounds.lineOut.volume = 0.2
updateFcts.push(function(delta){
sounds.update(delta)
})
// handle a listener following the camera
var soundListener = new WebAudiox.GameSoundListener(sounds)
soundListener.startFollow(camera)
updateFcts.push(function(delta){
soundListener.update(delta)
})
var url = 'sounds/rezoner-7DFPS-2013-2.mp3'
var soundClip = sounds.createClip()
.register('soundTrack')
.load(url, function(soundClip){
var soundSource = soundClip.play({
loop : true,
volume : 1.0,
follow : mesh,
// position: new THREE.Vector3(-1,0,0),
// position: mesh
})
console.dir(soundSource)
setTimeout(function(){