-
Notifications
You must be signed in to change notification settings - Fork 2
/
jsmodplayer.html
186 lines (160 loc) · 6.49 KB
/
jsmodplayer.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
overflow: hidden;
}
</style>
<script src="lib/jsmodplayer/src/modfile.js"></script>
<script src="lib/jsmodplayer/src/xmfile.js"></script>
<script src="lib/jsmodplayer/src/modplayer.js"></script>
<script src="lib/jsmodplayer/src/support.js"></script>
<script src="lib/cubicvr/CubicVR.js"></script>
<script src="lib/dsp.js"></script>
<script src="js/audio.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function (e) {
var canvas = document.createElement('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
var gl = CubicVR.GLCore.init(canvas, 'lib/cubicvr/CubicVR_Core.vs', 'lib/cubicvr/CubicVR_Core.fs');
if (!gl) {
return;
}
var fft;
var audioBuffer;
var signal = new Float32Array(4096);
var audioEngine = new AudioEngine(function (data) {
fft.forward(data);
audioBuffer = data;
for (var i=0, l=4096; i<l; ++i) {
if (fft.spectrum[i] > signal[i]) {
signal[i] = fft.spectrum[i];
}
else {
signal[i]*=0.45;
} //if
} //for
});
audioEngine.playMod('mod.mod');
audioEngine.audioObject.volume = 1;
fft = new FFT(4096, 44100);
var logoMaterial = new CubicVR.Material({
textures: {
color: new CubicVR.Texture("img/logo.jpg"),
alpha: new CubicVR.Texture("img/logo-alpha.jpg"),
},
opacity: 0.99,
});
var logoMesh = CubicVR.primitives.plane({
size: 1.0,
material: logoMaterial,
uvmapper: {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Z,
scale: [1, 1, 1]
}
});
logoMesh.triangulateQuads().compile().clean();
var floorMaterial = new CubicVR.Material({
color: [.4, .4, .4],
opacity: 1,
});
var uvplanar = {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Y,
scale: [0.5, 0.5, 0.5]
};
function makeCylinderLathe(mesh, height, inner_radius, outer_radius, res, material, uvmapper) {
var pointList = new Array();
var thick = outer_radius-inner_radius;
var radius = inner_radius+(thick)/2.0;
var transform;
pointList.push([inner_radius, 0, 0]);
pointList.push([inner_radius+thick, 0, 0]);
pointList.push([inner_radius+thick, height, 0]);
pointList.push([inner_radius, height, 0]);
pointList.push([inner_radius, 0, 0]);
CubicVR.genLatheObject(mesh, pointList, res, material, transform, uvmapper);
}
var scene = new CubicVR.Scene(canvas.width, canvas.height, 80);
var SOUND_FLOOR_RINGS = 25,
SOUND_FLOOR_Y = -3,
SOUND_FLOOR_H = 2.0,
SOUND_FLOOR_SPACING = 0.35,
MAX_WIDTH = 15;
var soundFloorRings = [];
for (var i=0; i<SOUND_FLOOR_RINGS; ++i) {
var soundFloorMesh = new CubicVR.Mesh();
makeCylinderLathe(soundFloorMesh, SOUND_FLOOR_H, i*MAX_WIDTH/SOUND_FLOOR_RINGS, (i+1)*MAX_WIDTH/SOUND_FLOOR_RINGS-SOUND_FLOOR_SPACING, 3, floorMaterial, uvplanar);
soundFloorMesh.triangulateQuads().compile().clean();
var soundFloorObject = new CubicVR.SceneObject(soundFloorMesh);
scene.bindSceneObject(soundFloorObject);
soundFloorRings.push(soundFloorObject);
soundFloorObject.targetY = SOUND_FLOOR_Y;
soundFloorObject.rotation[1] = 3*i;
} //for
function updateSoundFloor(seconds) {
for (var i=0; i<SOUND_FLOOR_RINGS; ++i) {
var newY = SOUND_FLOOR_Y + fft.spectrum[2*(i)] * 10;
var ring = soundFloorRings[i];
if (ring.targetY < newY) {
ring.targetY = newY;
} //if
ring.position[1] -= (ring.position[1] - ring.targetY)*.25;
ring.targetY = Math.max(ring.targetY - 0.01, SOUND_FLOOR_Y);
//ring.rotation[1] -= (SOUND_FLOOR_RINGS - i) * 0.05;
ring.rotation[1] = Math.sin(seconds + (SOUND_FLOOR_RINGS-i)*0.1)*120;
} //for
}; //updateSoundFloor
var logoObject = new CubicVR.SceneObject(logoMesh);
// bind this last because of depth buffer quirks
scene.bindSceneObject(logoObject);
scene.camera.position = [1, 0.5, -1];
scene.camera.target = [0, 0, 0];
/*
planeObject.motion = new CubicVR.Motion();
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 0, 0);
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 2.5, -180).tension = 1;
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 5, 360).tension = 1;
planeObject.motion.setKey(CubicVR.enums.motion.ROT, 1, 6, 360);
planeObject.motion.setBehavior(CubicVR.enums.motion.ROT, 1, CubicVR.enums.envelope.behavior.CONSTANT, CubicVR.enums.envelope.behavior.OFFSET);
*/
var dirLight = new CubicVR.Light({
type: CubicVR.enums.light.type.DIRECTIONAL,
specular: [1,1,1],
direction: CubicVR.vec3.normalize([0.5,-1,0.5])
});
scene.bindLight(dirLight);
var pLight = new CubicVR.Light({
type: CubicVR.enums.light.type.POINT,
specular: [1, 1, 1],
intensity: 2,
distance: 20,
position: [0, 1.5, 0],
});
scene.bindLight(pLight);
CubicVR.MainLoop(function(timer, gl) {
var seconds = timer.getSeconds();
scene.render();
scene.evaluate(timer.getSeconds());
logoObject.rotation[1] = Math.sin(seconds)*180 + Math.sin(seconds/2)*540 + Math.sin(seconds/8)*1080;
pLight.position[0] = Math.sin(seconds/10)*10;
pLight.position[2] = Math.cos(seconds/10)*10;
scene.camera.position[0] = 2 * Math.sin(seconds/5) + Math.cos(seconds/2) * 1.5;
scene.camera.position[2] = 2 * Math.cos(seconds/5) + Math.cos(seconds/2) * 1.5;
updateSoundFloor(seconds);
});
document.body.appendChild(canvas);
//new CubicVR.MouseViewController(canvas, scene.camera);
}, false);
</script>
</head>
<body>
</body>
</html>