This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
349 lines (297 loc) · 12.6 KB
/
index.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
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<title>Hello, world!</title>
<!-- include three.js library -->
<script src='js/three.js'></script>
<!-- include jsartookit -->
<script src="jsartoolkit5/artoolkit.min.js"></script>
<script src="jsartoolkit5/artoolkit.api.js"></script>
<!-- include threex.artoolkit -->
<script src="threex/threex-artoolkitsource.js"></script>
<script src="threex/threex-artoolkitcontext.js"></script>
<script src="threex/threex-arbasecontrols.js"></script>
<script src="threex/threex-armarkercontrols.js"></script>
</head>
<body style='margin : 0px; overflow: hidden; font-family: Monospace;'>
<script>
/** cloned from https://codepen.io/rainner/details/LREdXd **/
/**
* Global utils
*/
/** cloned from https://codepen.io/rainner/details/LREdXd **/
var arToolkitSource, arToolkitContext;
var markerRoot;
(function() {
var _w = window,
_s = window.screen,
_b = document.body,
_d = document.documentElement;
window.Utils = {
// screen info
screen: function()
{
var width = Math.max( 0, _w.innerWidth || _d.clientWidth || _b.clientWidth || 0 );
var height = Math.max( 0, _w.innerHeight || _d.clientHeight || _b.clientHeight || 0 );
return {
width : width,
height : height,
centerx : width / 2,
centery : height / 2,
ratio : width / height,
};
},
};
})();
/**
* Firework object
*/
(function() {
// constructor
var Firework = function( scene )
{ //properties
this.scene = scene;
this.done = false;
this.dest = [];
this.colors = [];
this.geometry = null;
this.points = null;
this.material = new THREE.PointsMaterial({
size: .1,
color: 0xffffff,
//color: 'blue',
opacity: 1,
vertexColors: true,
transparent: true,
depthTest: true,
});
this.launch();
};
// prototype (constructor assigned to itself)
Firework.prototype = {
constructor: Firework,
// reset
reset: function()
{
//this.scene.remove( this.points );
markerRoot.remove( this.points );
this.dest = []; // `dest` for destination
this.colors = [];
this.geometry = null;
this.points = null;
},
// launch
launch: function()
{
var x = THREE.Math.randFloat( -1, 1 ); //x, y and z are random numbers, but x relies on width of screen
var y = THREE.Math.randFloat( .5, 1.0 );
var z = THREE.Math.randFloat( -1., 1. );
var from = new THREE.Vector3( x, -1, z ); //not visible, well below the screen
var to = new THREE.Vector3( x, y, z ); //will go in straight line from start to end (explosion)
var color = new THREE.Color();
color.setHSL( THREE.Math.randFloat( 0.1, 0.9 ), 1, 0.9 );
this.colors.push( color );
this.geometry = new THREE.Geometry(); //a very basic geometry that will be characterized later
this.points = new THREE.Points( this.geometry, this.material ); //a very specific kind of Mesh?
this.geometry.colors = this.colors; //an array
this.geometry.vertices.push( from ); //a vector with variables x and z
this.dest.push( to ); //a vector with variables x, y and z
this.colors.push( color ); //twice? see line 103
markerRoot.add( this.points );
////https://threejs.org/docs/#api/en/geometries/SphereGeometry
//var geometry = new THREE.SphereGeometry( 1, 32, 32 );
//var material = new THREE.MeshBasicMaterial( {color: 0xffff00} );
//var sphere = new THREE.Mesh( geometry, material );
//
//markerRoot.add( sphere )
},
// explode
explode_set: function( vector )
{
markerRoot.remove( this.points );
this.dest = [];
this.colors = [];
this.geometry = new THREE.Geometry();
this.points = new THREE.Points( this.geometry, this.material );
for( var i = 0; i < 80; i++ ) //80 new points
{
var color = new THREE.Color();
color.setHSL( THREE.Math.randFloat( 0.1, 0.9 ), 1, 0.5 );
this.colors.push( color );
var from = new THREE.Vector3( //previous vector position into a ranged random position
THREE.Math.randFloat( vector.x - .010, vector.x + .010 ),
THREE.Math.randFloat( vector.y - .010, vector.y + .010 ),
THREE.Math.randFloat( vector.z - .010, vector.z + .010 )
);
var to = new THREE.Vector3( //previous vector position into a ranged random position outside screen
THREE.Math.randFloat( vector.x - 1., vector.x + 1. ),
THREE.Math.randFloat( vector.y - 1., vector.y + 1. ),
THREE.Math.randFloat( vector.z - 1., vector.z + 1. )
);
this.geometry.vertices.push( from );
this.dest.push( to );
}
this.geometry.colors = this.colors;
markerRoot.add( this.points );
},
// update
explode_ani: function()
{
// only if objects exist
if( this.points && this.geometry )
{
var total = this.geometry.vertices.length;
// lerp (change) particle positions
for( var i = 0; i < total; i++ )
{
this.geometry.vertices[i].x += ( this.dest[i].x - this.geometry.vertices[i].x ) / 20; //make 20 steps before exploding
this.geometry.vertices[i].y += ( this.dest[i].y - this.geometry.vertices[i].y ) / 20;
this.geometry.vertices[i].z += ( this.dest[i].z - this.geometry.vertices[i].z ) / 20;
this.geometry.verticesNeedUpdate = true; //relevant!!
}
// watch first particle for explosion
if( total === 1 )
{
if( Math.ceil( this.geometry.vertices[0].y ) > ( this.dest[0].y - .020 ) ) //reached an altitude threshold
{
this.explode_set( this.geometry.vertices[0] );
return;
}
}
// fade out exploded particles
if( total > 1 )
{
this.material.opacity -= 0.015;
this.material.colorsNeedUpdate = true; //relevant!!!
}
// remove, reset and stop animating
if( this.material.opacity <= 0 )
{
this.reset();
this.done = true;
return;
}
}
},
};
// export
window.Firework = Firework;
})();
(function() {
var screen = Utils.screen(),
renderer = null,
camera = null,
scene = null,
to = { px: 0, py: 0, pz: 2 },
fireworks = [];
try {
renderer = new THREE.WebGLRenderer( { alpha: true, antialias: true } );
camera = new THREE.Camera();
scene = new THREE.Scene();
}
catch( e ) {
alert( "THREE.JS Error: " + e.toString() );
return;
}
function setup()
{
camera.position.set( 0, 0, 0 );
camera.rotation.set( 0, 0, 0 );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setClearColor( 0x000000, 0 );
renderer.sortObjects = true;
renderer.setSize( 640, 480 );
renderer.domElement.style["display"] = "block";
renderer.domElement.style["position"] = "fixed";
//renderer.domElement.style["position"] = "absolute";
renderer.domElement.style["width"] = "100%";
renderer.domElement.style["height"] = "100%";
renderer.domElement.style["z-index"] = "-1";
//
renderer.domElement.style["top"] = '0px';
renderer.domElement.style["left"] = '0px';
document.body.appendChild( renderer.domElement );
////////////////////////////////////////////////////////////
// setup arToolkitSource
////////////////////////////////////////////////////////////
arToolkitSource = new THREEx.ArToolkitSource({
sourceType : 'webcam',
});
function onResize()
{
console.log('onResize');
arToolkitSource.onResize()
arToolkitSource.copySizeTo(renderer.domElement)
if ( arToolkitContext.arController !== null )
{
arToolkitSource.copySizeTo(arToolkitContext.arController.canvas)
}
}
arToolkitSource.init(function onReady(){
onResize()
});
// handle resize event
window.addEventListener('resize', function(){
onResize()
});
////////////////////////////////////////////////////////////
// setup arToolkitContext
////////////////////////////////////////////////////////////
// create atToolkitContext
arToolkitContext = new THREEx.ArToolkitContext({
cameraParametersUrl: 'data/camera_para.dat',
detectionMode: 'mono'
});
// copy projection matrix to camera when initialization complete
arToolkitContext.init( function onCompleted(){
camera.projectionMatrix.copy( arToolkitContext.getProjectionMatrix() );
});
////////////////////////////////////////////////////////////
// setup markerRoots
////////////////////////////////////////////////////////////
// build markerControls
markerRoot = new THREE.Object3D();
scene.add(markerRoot);
let markerControls = new THREEx.ArMarkerControls(arToolkitContext, markerRoot, {
type: 'pattern', patternUrl: "data/HNY2019.patt",
})
};
// animation loop
function draw()
{
requestAnimationFrame(draw);
// add fireworks
if( THREE.Math.randInt( 1, 20 ) === 10 ) //random appearence of fireworks
{
//var __ = new Firework( scene );
console.log(markerRoot)
fireworks.push( new Firework( scene ) ); //a queue of fireworks
//markerRoot;
}
// update fireworks
for( var i = 0; i < fireworks.length; i++ )
{
if( fireworks[ i ].done ) // cleanup
{
fireworks.splice( i, 1 );
continue;
}
fireworks[ i ].explode_ani();
}
if ( arToolkitSource.ready !== false ){
console.log('ready');
arToolkitContext.update( arToolkitSource.domElement );
}
//// lerp camera position (change with element)
//camera.position.x += ( to.px - camera.position.x ) / .040;
//camera.position.y += ( to.py - camera.position.y ) / .040;
//camera.position.z += ( to.pz - camera.position.z ) / .040;
// render
renderer.render( scene, camera );
};
setup();
draw();
})();
</script>
</body>
</html5>