forked from mikocml/jsartoolkit5
-
Notifications
You must be signed in to change notification settings - Fork 20
/
main_threejs_wasm_worker.html
140 lines (118 loc) · 3.25 KB
/
main_threejs_wasm_worker.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>NFT marker example with a WebWorker, WASM and with Three.js</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=1">
<link rel="stylesheet" href="../css/video-style.css">
</head>
<body class="loading">
<div id="loading" >
<img src="../Data/logo.gif"/>
<span class="loading-text">Loading, please wait</span>
</div>
<!--
==================
STATS
==================
-->
<div id="stats" class="ui stats">
<div id="stats1" class="stats-item">
<p class="stats-item-title">
Main
</p>
</div>
<div id="stats2" class="stats-item">
<p class="stats-item-title">
Worker
</p>
</div>
</div>
<!--
==================
CAMERA VIDEO & CANVAS
==================
-->
<div id="app">
<video
loop
autoplay
muted
playsinline
id="video">
</video>
<canvas id="canvas"></canvas>
</div>
<a
href="https://raw.githubusercontent.com/artoolkit/artoolkit5/master/doc/Marker%20images/pinball.jpg"
class="ui marker"
target="_blank">
🖼 Marker Image
</a>
<script src="../js/third_party/three.js/stats.min.js"></script>
<script src="../js/third_party/three.js/three.min.js"></script>
<script src="threejs_wasm_worker.js"></script>
<script>
/**
* STATS
*/
var statsMain = new Stats();
statsMain.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
document.getElementById( 'stats1' ).appendChild( statsMain.dom );
var statsWorker = new Stats();
statsWorker.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
document.getElementById( 'stats2' ).appendChild( statsWorker.dom );
/**
* APP / ELEMENTS
*/
var container = document.getElementById( 'app' );
var video = document.getElementById( 'video' );
var canvas = document.getElementById( 'canvas' );
/**
* APP / VIDEO STREAM
*/
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
var hint = {
audio: false,
video: true
};
if( window.innerWidth < 800 ) {
var width = ( window.innerWidth < window.innerHeight ) ? 240 : 360;
var height = ( window.innerWidth < window.innerHeight ) ? 360 : 240;
var aspectRatio = window.innerWidth / window.innerHeight;
console.log( width, height );
hint = {
audio: false,
video: {
facingMode: 'environment',
width: { min: width, max: width }
},
};
console.log( hint );
}
navigator.mediaDevices.getUserMedia( hint ).then( function( stream ) {
video.srcObject = stream;
video.addEventListener( 'loadedmetadata', function() {
video.play();
console.log( 'video', video, video.videoWidth, video.videoHeight );
start(
container,
markers['pinball'],
video,
video.videoWidth,
video.videoHeight,
canvas,
function() {
statsMain.update()
},
function() {
statsWorker.update();
},
null
);
} );
} );
}
</script>
</body>
</html>