-
Notifications
You must be signed in to change notification settings - Fork 2
/
_test-text_anim.html
455 lines (374 loc) · 18.8 KB
/
_test-text_anim.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<!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 src="js/bitFont.js" type="text/javascript" charset="utf-8">
</script>
<script src="js/bitFont3D.js" type="text/javascript" charset="utf-8">
</script>
<script src="js/AnimationKit.js" type="text/javascript" charset="utf-8">
</script>
<script>
var shaderList = [];
var fxChain;
var bfstr = [];
var bf3d;
var ml;
var scene;
var animkit;
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;
}
// expose the alphaDepth buffer
shaderDepth = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/alpha_depth.fs",
});
// simple color invert
shaderInvert = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/invert.fs"
});
shaderDOF6 = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/dof_6tap.fs",
init: function(shader) {
shader.addFloat("near_depth");
shader.addFloat("far_depth");
},
onupdate: function(shader) {
// linear depth
var d = CubicVR.vec3.length(scene.camera.position, scene.camera.target);
shader.setFloat("near_depth", (d - 0.5 - scene.camera.nearclip) / scene.camera.farclip);
shader.setFloat("far_depth", (d + 4 - scene.camera.nearclip) / scene.camera.farclip);
}
});
shaderSSAO = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/ssao.fs",
});
// Bloom + 1/2 divisor + blend
shaderHalfBloom = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/bloom_6tap.fs",
outputMode: CubicVR.enums.post.output.ADD,
outputDivisor: 2
});
// Bloom + 1/4 divisor + blend
shaderQuarterBloom = new CubicVR.PostProcessShader({
shader_vertex: "lib/cubicvr/post_shaders/fx_general.vs",
shader_fragment: "lib/cubicvr/post_shaders/bloom_6tap.fs",
outputMode: CubicVR.enums.post.output.ADD,
outputDivisor: 4
});
var i = 0;
var shaderActive = 0;
fxSelect = document.getElementById("shaderSelector");
fxSelect.options[i] = new Option("Depth Buffer View", i++);
fxSelect.options[i] = new Option("Invert Color", i++);
fxSelect.options[i] = new Option("Screen-Space Ambient Occlusion", i++);
fxSelect.options[shaderActive = i] = new Option("6-Tap Depth Of Field", i++);
fxSelect.options[i] = new Option("6-Tap Bloom, 1/2 blend", i++);
fxSelect.options[i] = new Option("6-Tap Bloom, 1/4 blend", i++);
// fxSelect.selectedIndex = fxSelect.options.length-1;
fxSelect.selectedIndex = shaderActive;
shaderList.push(shaderDepth);
shaderList.push(shaderInvert);
shaderList.push(shaderSSAO);
shaderList.push(shaderDOF6);
shaderList.push(shaderHalfBloom);
shaderList.push(shaderQuarterBloom);
fxChain = new CubicVR.PostProcessChain(canvas.width, canvas.height, true);
fxChain.setBlurOpacity(1);
fxChain.setBlurIntensity(0);
for (var i = 0; i < shaderList.length; i++) {
fxChain.addShader(shaderList[i]);
shaderList[i].enabled = false;
}
shaderList[fxSelect.selectedIndex].enabled = true;
var fft;
var audioBuffer;
var signal = new Float32Array(4096);
var audioEngine = new AudioEngine(null,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 tWidth = 200;
var tHalfWidth = tWidth / 2;
var tEdge = tHalfWidth - 10;
var TWO_PI = Math.PI * 2;
var skip = 4;
var floorTextureColor = new CubicVR.CanvasTexture({
update: function(canvas, ctx) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineWidth = 5;
ctx.fillStyle = "rgb(40, 40, 40)";
ctx.fillRect(0, 0, canvas.width, canvas.height);
if (audioBuffer) {
for (var i = 0, l = signal.length; i < l && i < tEdge; i += skip) {
var c = Math.min(255, Math.round(signal[i] * 1000) + 64);
ctx.strokeStyle = "rgb(" + c + ", " + c + ", " + c + ")";
ctx.beginPath();
ctx.arc(tHalfWidth, tHalfWidth, i, 0, TWO_PI, true);
ctx.stroke();
} //for
} //if
},
width: tWidth,
height: tWidth,
});
var floorTextureBump = new CubicVR.CanvasTexture({
update: function(canvas, ctx) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.lineWidth = 5;
if (audioBuffer) {
for (var i = 0, l = signal.length; i < l && i < tEdge; i += skip) {
var c = Math.min(255, Math.round(signal[i] * 1000) + 64);
ctx.strokeStyle = "rgb(" + c + ", " + c + ", " + c + ")";
ctx.beginPath();
ctx.arc(tHalfWidth, tHalfWidth, i, 0, TWO_PI, true);
ctx.stroke();
} //for
} //if
},
width: tWidth,
height: tWidth,
});
var floorTextureNormal = new CubicVR.NormalMapGen(floorTextureBump, 512, 512);
var floorMaterial = new CubicVR.Material({
textures: {
color: floorTextureColor,
bump: floorTextureBump,
normal: floorTextureNormal,
},
opacity: 1,
});
var floorMesh = CubicVR.primitives.plane({
size: 20.0,
material: floorMaterial,
uvmapper: {
projectionMode: CubicVR.enums.uv.projection.PLANAR,
projectionAxis: CubicVR.enums.uv.axis.Z,
scale: [20.5, 20.5, 1]
}
});
floorMesh.triangulateQuads().compile().clean();
scene = new CubicVR.Scene(canvas.width, canvas.height, 80, 0.01, 50);
var floorObject = new CubicVR.SceneObject(floorMesh);
var logoObject = new CubicVR.SceneObject(logoMesh);
floorObject.rotation[0] = 90;
floorObject.position[1] = -1;
// in this order because of depth buffer quirks
scene.bindSceneObject(floorObject);
// scene.bindSceneObject(logoObject);
scene.camera.position = [1, 0.5, -1];
scene.camera.target = [0, 0, 0];
CubicVR.setGlobalDepthAlpha(true, scene.camera.nearclip, scene.camera.farclip);
/*
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: [0.4, 0.4, 0.4],
direction: CubicVR.vec3.normalize([0.5, -1, 0.5])
});
scene.bindLight(dirLight);
var pLight = new CubicVR.Light({
type: CubicVR.enums.light.type.POINT,
specular: [0.4, 0.4, 0.4],
intensity: 1,
distance: 20,
position: [0, 1.5, 0],
});
scene.bindLight(pLight);
var bfMaterial = new CubicVR.Material({
color: [0.3,0.4,0.9],
specular: [1,1,1],
shininess: 0.9,
textures: {
envsphere: new CubicVR.Texture("img/fract_reflections.jpg")
}
});
var bfUV = new CubicVR.UVMapper({
projectionMode: CubicVR.enums.uv.projection.CUBIC,
scale: [1, 1, 1]
});
bf3d = new bitFont3D("box",bfMaterial,bfUV);
bf3d.loadFont();
animkit = new AnimationKit();
scene.bindSceneObject(bfstr[0] = bf3d.genString("this is a test"));
scene.bindSceneObject(bfstr[1] = bf3d.genString("of multiline text"));
scene.bindSceneObject(bfstr[2] = bf3d.genString("animation"));
bfstr[0].rotation = [0,-15,0];
bfstr[1].rotation = [0,0,0];
bfstr[2].rotation = [0,15,0];
bfstr[0].position[1] = 2;
bfstr[1].position[1] = 1;
bfstr[2].position[1] = 0;
animkit.transition(0, 5, 3, bfstr[0], "spiral");
animkit.transition(0, 5, 3, bfstr[1], "spiral");
animkit.transition(0, 5, 3, bfstr[2], "spiral");
// window.addEventListener("keypress",function (e) {
// var newfontObj = new CubicVR.SceneObject({mesh:bf3d.chars[e.charCode], position:[(Math.random()-0.5)*10.0,0,(Math.random()-0.5)*10.0], scale:[1,1,1]});
// scene.bindSceneObject(newfontObj);
// },true);
ml = new CubicVR.MainLoop(function(timer, gl) {
var seconds = timer.getSeconds();
fxChain.begin();
// Clear the FX buffer
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
scene.render();
fxChain.end();
fxChain.render();
scene.evaluate(timer.getSeconds());
logoObject.rotation[1] = Math.sin(seconds) * 180 + Math.sin(seconds / 2) * 540 + Math.sin(seconds / 8) * 1080;
floorTextureColor.update();
// floorTextureBump.update();
// floorTextureNormal.update();
pLight.position[0] = Math.sin(seconds / 10) * 10;
pLight.position[2] = Math.cos(seconds / 10) * 10;
scene.camera.position[0] = 5 * Math.sin(seconds / 5) + Math.cos(seconds / 2) * 3.5;
scene.camera.position[2] = 5 * Math.cos(seconds / 5) + Math.cos(seconds / 2) * 3.5;
});
document.body.appendChild(canvas);
//new CubicVR.MouseViewController(canvas, scene.camera);
}, false);
function selectShaderFX(elem) {
fxSelect = document.getElementById("shaderSelector");
for (var i = 0; i < fxSelect.length; i++) {
shaderList[i].enabled = (fxSelect.options[i].selected) ? true : false;
}
}
function newText(str,type_str) {
for (var i = 0; i < bfstr.length; i++) {
scene.removeSceneObject(bfstr[i]);
}
bfstr = [];
var lines = str.split("\n");
var numlines = lines.length;
for (var i = 0; i < lines.length; i++) {
lines[i] = lines[i].replace("\n","");
bfstr[i] = bf3d.genString(lines[i],scene);
bfstr[i].position[1] = numlines-1-i;
scene.bindSceneObject(bfstr[i]);
if (type_str === "random") {
animkit.transition(ml.getTimerSeconds(), 10, 2, bfstr[i], type_str);
} else if (type_str === "spiral") {
animkit.transition(ml.getTimerSeconds(), 5, 3, bfstr[i], type_str);
} else if (type_str === "explode") {
animkit.transition(ml.getTimerSeconds(), 20, 3, bfstr[i], type_str);
}
}
}
function transitionAway(type_str,trans_str) {
for (var i = 0; i < bfstr.length; i++) {
if (type_str === "random") {
animkit.transition(ml.getTimerSeconds(), 20, 2, bfstr[i], type_str, trans_str);
} else if (type_str === "spiral") {
animkit.transition(ml.getTimerSeconds(), 20, 3, bfstr[i], type_str, trans_str);
} else if (type_str === "explode") {
animkit.transition(ml.getTimerSeconds(), 20, 3, bfstr[i], type_str, trans_str);
}
}
}
</script>
</head>
<body>
<div style='position:absolute; top:10px; left:10px; color:white; font-family:Arial; font-size:14px;'>
Change FX (multi):
<a href="javascript:void(0)" onclick="document.getElementById('fxDiv').style.display=(document.getElementById('fxDiv').style.display=='none')?'':'none';"
style='text-decoration:none'>( toggle )</a>
<div style='' id='fxDiv'>
<br />
<select id="shaderSelector" onchange="selectShaderFX(this)" multiple size="15" style='vertical-align:top'>
</select>
<br/>
Blur opac:
<input type='text' onchange="fxChain.setBlurOpacity(parseFloat(this.value))" size='4'
value="1">
intens:
<input type='text' onchange="fxChain.setBlurIntensity(parseFloat(this.value))" size='4'
value="0">
<br/>
<textarea value='enter text' id='text'>enter
some
multiline
text</textarea><br />
<select id='text_anim_type'>
<option value="spiral">
Spiral
</option>
<option value="random">
Random
</option>
<option value="explode">
Explode
</option>
</select>
<select id='text_anim_trans'>
<option value="in">
In
</option>
<option value="out">
Out
</option>
</select>
<input type='button' value='go' onclick='if (document.getElementById("text_anim_trans").selectedIndex==0) { newText(document.getElementById("text").value,document.getElementById("text_anim_type").options[document.getElementById("text_anim_type").selectedIndex].value); } else { transitionAway(document.getElementById("text_anim_type").options[document.getElementById("text_anim_type").selectedIndex].value,document.getElementById("text_anim_trans").options[document.getElementById("text_anim_trans").selectedIndex].value); }'>
</div>
</div>
</body>
</html>