Skip to content

Commit 848ca0e

Browse files
authored
Merge branch 'fixing-nft' into api-doc-improvements
2 parents 900fdb6 + 53fb34a commit 848ca0e

33 files changed

+1371
-1990
lines changed

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
doc/reference
22
node_modules
33
build/*.bc
4-
emscripten/libjpeg/*.h
5-
emscripten/libjpeg/*.c
6-
emscripten/libjpeg/*.txt
7-
emscripten/libjpeg/README
8-
emscripten/libjpeg/*.log

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,19 @@ When writing JavaScript and making changes be aware that the emscripten uglifier
2727
- `tools/` (build scripts for building ARToolKit.js)
2828

2929
## WebAssembly
30-
JSARToolKit5 supports WebAssembly. The libary builds two WebAssembly artefacts during the build process. These are ```build/artoolkit_wasm.js``` and ```build/artoolkit_wasm.wasm```. To use those include the artoolkit_wasm.js into your html page and define ```var artoolkit_wasm_url = '<<PATH TO>>/artoolkit_wasm.wasm';``` prior to loading the artoolkit_wasm.js file, like so:
30+
31+
JSARToolKit5 supports WebAssembly. The libary builds two WebAssembly artifacts during the build process. These are ```build/artoolkit_wasm.js``` and ```build/artoolkit_wasm.wasm```. To use those, include the artoolkit_wasm.js into your html page and define ```var artoolkit_wasm_url = '<<PATH TO>>/artoolkit_wasm.wasm';``` before loading the artoolkit_wasm.js file, like this:
3132

3233
```js
3334
<script type='text/javascript'>
3435
var artoolkit_wasm_url = '../build/artoolkit_wasm.wasm';
3536
</script>
3637
<script src="../build/artoolkit_wasm.js"></script>
3738
```
38-
As loading the WebAssembly artefact is done asynchronous there is a callback that is called once everything is ready.
39+
As loading the WebAssembly artifact is done asynchronously, there is a callback that is called when everything is ready.
3940

4041
```js
41-
window.addEventListener('artoolkit-loaded', () => {
42+
window.addEventListener('artoolkit-loaded', () => {
4243
//do artoolkit stuff here
4344
});
4445
```
@@ -52,20 +53,22 @@ See examples/simple_image_wasm.html for details.
5253
- or, set the `ARTOOLKIT5_ROOT` environment variable to point to your ARToolKit5 clone
5354
- or, change the `tools/makem.js` file to point to your artoolkit5 clone (line 20)
5455

55-
## Build Instructions
56+
## Build the project
5657

5758
### Recommended: Build using Docker
58-
1. Install Docker (if you havn't already) [Docker](https://www.docker.com/) -> Get Docker
59+
60+
1. Install Docker (if you havn't already): [get Docker](https://www.docker.com/)
5961
2. Clone artoolkit5 repository on your machine: `git submodule update --init`
6062
3. `npm install`
61-
4. From inside jsartoolkit5 directory run `docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten-slim:latest bash` - download and start the container, in preparation for the build
62-
5. `docker exec emscripten npm run build-local` - build JS version of artoolkit5
63-
6. `docker stop emscripten` - stop the container after the build if needed
64-
7. `docker rm emscripten` - remove the container
65-
8. `docker rmi trzeci/emscripten-slim:latest` - remove the image if you don't need it anymore
66-
9. The build artefacts are in `/build`. There's a build with debug symbols in `artoolkit.debug.js` and the optimized build with bundled JS API in `artoolkit.min.js` and a WebAssembly build artoolkit_wasm.js and artoolkit_wasm.wasm
63+
4. From inside jsartoolkit5 directory run `docker run -dit --name emscripten -v $(pwd):/src trzeci/emscripten-slim:latest bash` to download and start the container, in preparation for the build
64+
5. `docker exec emscripten npm run build-local` to build JS version of artoolkit5
65+
6. `docker stop emscripten` to stop the container after the build, if needed
66+
7. `docker rm emscripten` to remove the container
67+
8. `docker rmi trzeci/emscripten-slim:latest` to remove the Docker image, if you don't need it anymore
68+
9. The build artifacts will appear in `/build`. There's a build with debug symbols in `artoolkit.debug.js` file and the optimized build with bundled JS API in `artoolkit.min.js`; also, a WebAssembly build artoolkit_wasm.js and artoolkit_wasm.wasm
6769

6870
### ⚠️ Not recommended ⚠️ : Build local with manual emscripten setup
71+
6972
To prevent issues with Emscripten setup and to not have to maintain several build environments (macOS, Windows, Linux) we only maintain the **Build using Docker**. Following are the instructions of the last know build on Linux which we verified are working. **Use at own risk.**
7073
** Not working on macOS!**
7174

build/artoolkit.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/artoolkit_wasm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/css/index.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
body {
2+
margin: 1em;
3+
padding: 0;
4+
height: 100%;
5+
width: 100%;
6+
font-family: sans-serif;
7+
font-size: 1.5em;
8+
background-color: #eee;
9+
color: #023962;
10+
}
11+
12+
ul, ol {
13+
list-style: none;
14+
}
15+
16+
li {
17+
margin-top: 1em;
18+
}
19+
20+
a {
21+
color: inherit;
22+
}
23+
24+
a:hover {
25+
background-color: #023962;
26+
color: white;
27+
}

examples/css/video-style.css

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
@keyframes rotate {
2-
0% {
3-
transform: rotate( 0deg);
4-
}
5-
100% {
6-
transform: rotate( 360deg);
7-
}
8-
}
9-
101
html,
112
body {
123
margin: 0;
@@ -17,44 +8,17 @@ html {
178
font-family: sans-serif;
189
}
1910

20-
body {}
21-
22-
body.loading::after {
23-
content: ' ';
24-
25-
position: fixed;
26-
left: 0;
27-
right: 0;
28-
top: 0;
29-
bottom: 0;
30-
31-
display: block;
32-
width: 4rem;
33-
height: 4rem;
34-
margin: auto auto;
35-
36-
border-style: solid;
37-
border-width: 2px;
38-
border-color: rgba(0,0,0,0.25) rgba(0,0,0,0.25) rgba(0,0,0,0.25) rgba(0,0,0,1.0);
39-
border-radius: 50%;
40-
41-
animation: rotate 800ms infinite linear;
42-
}
43-
44-
body.loading>* {
45-
opacity: 0.15;
46-
}
47-
4811
#loading {
4912
width: 100%;
5013
position: absolute;
51-
top: 10%;
5214
display: flex;
5315
flex-direction: column;
5416
justify-content: center;
5517
align-items: center;
5618
width: 100%;
57-
height: 40%;
19+
height: 100%;
20+
background-color: rgba(0, 0, 0, 0.45);
21+
z-index: 9999999;
5822
}
5923

6024
#loading img {

examples/nft_improved_worker/index.html

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,16 @@
55
</head>
66

77
<body>
8-
<h3>jsartoolkit5 demos with ar2Tracking</h3>
9-
<div>screen capture: <a href="https://imgur.com/WnaxILE">https://imgur.com/WnaxILE</a></div>
10-
<div>screen capture: <a href="https://imgur.com/BciDGxo">https://imgur.com/BciDGxo</a></div>
11-
<div>nft: <a href="https://imgur.com/HvcmRVl">https://imgur.com/HvcmRVl</a></div>
12-
<p>demo links:</p>
13-
<ul>
14-
<li><a href="main.html">camera input, single-threaded</a></li>
15-
<li><a href="main_worker.html">camera input, worker</a></li>
16-
<li><a href="main_threejs_worker.html">camera input, worker, threejs rendering</a></li>
17-
<li><a href="main_threejs_wasm_worker.html">camera input, worker with wasm, threejs rendering</a></li>
18-
<li><a href="threejs_worker_gltf.html">camera input, worker, threejs rendering and gltf model</a></li>
19-
<li><a href="video.html">video input, single-threaded</a></li>
20-
<li><a href="video_worker.html">video input, worker</a></li>
21-
<li><a href="video_threejs_worker.html">video input, worker, threejs rendering</a></li>
22-
<li><a href="nft_armchair_image.html">camera input, worker, threejs rendering and the armchair image to display</a></li>
23-
<li><a href="nft_pinball_video.html">camera input, worker, threejs rendering and a video to display</a></li>
24-
</ul>
25-
8+
<link rel="stylesheet" href="../css/index.css">
9+
<h3>jsartoolkit5 demos with ar2Tracking</h3>
10+
<div>Image to recognize for the following examples <a href="https://imgur.com/HvcmRVl">https://imgur.com/HvcmRVl</a></div>
11+
<p>Examples:</p>
12+
<ul>
13+
<li><a href="threejs_worker_gltf.html">Show a 3D, animated model. Uses web worker. Has loader. Has interpolation.</a></li>
14+
<li><a href="main_threejs_worker.html">Show a 3D sphere. Uses web worker. Has loader. Has interpolation. Asm version. (high framerate)</a></li>
15+
<li><a href="main_threejs_wasm_worker.html">Show a 3D sphere. Uses web worker. Has loader. Has interpolation. Uses web assembly</a></li>
16+
<li><a href="main.html">Draw a red rectangle around the image. Single-threaded. No loader</a></li>
17+
<li><a href="main_worker.html">Draw a red rectangle around the image. Uses web worker. No loader</a></li>
18+
</ul>
2619
</body>
2720
</html>

examples/nft_improved_worker/main.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,35 @@
2121
<script src="main.js"></script>
2222

2323
<script>
24-
let statsMain = new Stats();
24+
var statsMain = new Stats();
2525
statsMain.showPanel(1); // 0: fps, 1: ms, 2: mb, 3+: custom
2626
statsMain.domElement.style.position = 'relative';
2727
statsMain.domElement.style.left = '0px';
2828
statsMain.domElement.style.top = '0px';
2929
document.getElementById("stats1").appendChild(statsMain.dom);
3030

31-
let container = document.getElementById('container');
32-
let video = document.getElementById('video');
33-
let canvas_draw = document.getElementById('canvas_draw');
31+
var container = document.getElementById('container');
32+
var video = document.getElementById('video');
33+
var canvas_draw = document.getElementById('canvas_draw');
3434

3535
if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
36-
let hint = {};
36+
var hint = {};
3737
if (isMobile()) {
3838
hint = {
3939
facingMode: {"ideal": "environment"},
4040
audio: false,
4141
video: {
42-
width: {min: 240, max: 240},
43-
height: {min: 360, max: 360},
42+
width: { ideal: 480 },
43+
height: { ideal: 640 },
4444
},
4545
};
4646
}
4747

4848
navigator.mediaDevices.getUserMedia({video: hint}).then(function (stream) {
4949
video.srcObject = stream;
5050
video.play();
51-
video.addEventListener("loadedmetadata", () => {
52-
start(container, markers["pinball"], video, video.videoWidth, video.videoHeight, canvas_draw, () => statsMain.update());
51+
video.addEventListener("loadedmetadata", function() {
52+
start(container, markers["pinball"], video, video.videoWidth, video.videoHeight, canvas_draw, function() {statsMain.update()});
5353
});
5454
});
5555
}

examples/nft_improved_worker/main.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ function isMobile() {
5353
return /Android|mobile|iPad|iPhone/i.test(navigator.userAgent);
5454
}
5555

56-
let ar = null;
57-
let markerResult = null;
56+
var ar = null;
57+
var markerResult = null;
5858

59-
let markers = {
59+
var markers = {
6060
"pinball": {
6161
width: 1637,
6262
height: 2048,
@@ -66,18 +66,18 @@ let markers = {
6666
};
6767

6868
function start(container, marker, video, input_width, input_height, canvas_draw, render_update) {
69-
let vw, vh;
70-
let sw, sh;
71-
let pscale, sscale;
72-
let w, h;
73-
let pw, ph;
74-
let ox, oy;
75-
76-
let canvas_process = document.createElement('canvas');
77-
let context_draw = canvas_draw.getContext('2d');
78-
let context_process = canvas_process.getContext('2d');
79-
80-
let load = () => {
69+
var vw, vh;
70+
var sw, sh;
71+
var pscale, sscale;
72+
var w, h;
73+
var pw, ph;
74+
var ox, oy;
75+
76+
var canvas_process = document.createElement('canvas');
77+
var context_draw = canvas_draw.getContext('2d');
78+
var context_process = canvas_process.getContext('2d');
79+
80+
var load = function() {
8181
vw = input_width;
8282
vh = input_height;
8383

@@ -105,10 +105,10 @@ function start(container, marker, video, input_width, input_height, canvas_draw,
105105
canvas_process.width = pw;
106106
canvas_process.height = ph;
107107

108-
let param = new ARCameraParam('../Data/camera_para-iPhone 5 rear 640x480 1.0m.dat');
108+
var param = new ARCameraParam('../Data/camera_para-iPhone 5 rear 640x480 1.0m.dat');
109109
param.onload = function () {
110110
ar = new ARController(pw, ph, param);
111-
let cameraMatrix = ar.getCameraMatrix();
111+
var cameraMatrix = ar.getCameraMatrix();
112112

113113
ar.addEventListener('getNFTMarker', function (ev) {
114114
markerResult = {type: "found", matrixGL_RH: JSON.stringify(ev.data.matrixGL_RH), proj: JSON.stringify(cameraMatrix)};
@@ -123,15 +123,15 @@ function start(container, marker, video, input_width, input_height, canvas_draw,
123123
};
124124
};
125125

126-
let lasttime = Date.now();
127-
let time = 0;
126+
var lasttime = Date.now();
127+
var time = 0;
128128

129-
let x = 0;
130-
let draw = () => {
129+
var x = 0;
130+
var draw = function() {
131131
context_draw.clearRect(0, 0, vw, vh);
132132
render_update();
133-
let now = Date.now();
134-
let dt = now - lasttime;
133+
var now = Date.now();
134+
var dt = now - lasttime;
135135
time += dt;
136136
lasttime = now;
137137

@@ -142,10 +142,10 @@ function start(container, marker, video, input_width, input_height, canvas_draw,
142142

143143

144144
if (!markerResult) return;
145-
let proj = JSON.parse(markerResult.proj);
146-
let world = JSON.parse(markerResult.matrixGL_RH);
145+
var proj = JSON.parse(markerResult.proj);
146+
var world = JSON.parse(markerResult.matrixGL_RH);
147147

148-
let mat = multiplyMatrices(proj, world);
148+
var mat = multiplyMatrices(proj, world);
149149

150150
function glpointToCanvas(xyz) {
151151
return {
@@ -154,29 +154,29 @@ function start(container, marker, video, input_width, input_height, canvas_draw,
154154
}
155155
}
156156
function drawpoint(x, y, z) {
157-
let r = transformPoint(mat, {x: x, y: y, z: z});
158-
let c = glpointToCanvas(r);
157+
var r = transformPoint(mat, {x: x, y: y, z: z});
158+
var c = glpointToCanvas(r);
159159
return c;
160160
}
161161

162-
let width = marker.width;
163-
let height = marker.height;
164-
let dpi = marker.dpi;
162+
var width = marker.width;
163+
var height = marker.height;
164+
var dpi = marker.dpi;
165165

166-
let w = width / dpi * 2.54 * 10;
167-
let h = height / dpi * 2.54 * 10;
166+
var w = width / dpi * 2.54 * 10;
167+
var h = height / dpi * 2.54 * 10;
168168

169-
let p1 = drawpoint(0, 0, 0);
170-
let p2 = drawpoint(w, 0, 0);
171-
let p3 = drawpoint(w, h, 0);
172-
let p4 = drawpoint(0, h, 0);
169+
var p1 = drawpoint(0, 0, 0);
170+
var p2 = drawpoint(w, 0, 0);
171+
var p3 = drawpoint(w, h, 0);
172+
var p4 = drawpoint(0, h, 0);
173173
context_draw.beginPath();
174174
context_draw.moveTo(p1.x, p1.y);
175175
context_draw.lineTo(p2.x, p2.y);
176176
context_draw.lineTo(p3.x, p3.y);
177177
context_draw.lineTo(p4.x, p4.y);
178178
context_draw.closePath();
179-
context_draw.strokeStyle = "#FFF";
179+
context_draw.strokeStyle = "red";
180180
context_draw.stroke();
181181
};
182182

@@ -186,11 +186,11 @@ function start(container, marker, video, input_width, input_height, canvas_draw,
186186
context_process.drawImage(video, 0, 0, vw, vh, ox, oy, w, h);
187187
markerResult = null;
188188
if (ar) {
189-
let imageData = context_process.getImageData(0, 0, pw, ph);
189+
var imageData = context_process.getImageData(0, 0, pw, ph);
190190
ar.process(imageData);
191191
}
192192
}
193-
let tick = () => {
193+
var tick = function() {
194194
process();
195195
draw();
196196
requestAnimationFrame(tick);

0 commit comments

Comments
 (0)