Skip to content

Commit fe3ae7f

Browse files
committed
examples page and 2d_tracking example
1 parent 84b4d91 commit fe3ae7f

14 files changed

+1542
-1
lines changed

SDK/lib/.gitignore

Whitespace-only changes.

SDK/lib/artoolkitX.api.js

+1,241
Large diffs are not rendered by default.

SDK/lib/artoolkitx.js

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SDK/lib/artoolkitx.wasm

4.79 MB
Binary file not shown.

_includes/header.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
</div>
77
<nav id="nav-bar">
88
<ul>
9-
<li><a class="nav-link" href="/blog" id="yellow-link">Blog</a></li>
9+
<li><a class="nav-link" href="/blog" id="red-link">Blog</a></li>
10+
<li><a class="nav-link" href="/examples" id="yellow-link">Examples</a></li>
1011
<li><a class="nav-link" href="/project" id="green-link">The project</a></li>
1112
<li><a class="nav-link" href="/about-us" id="red-link">About us</a></li>
1213
<li><a class="nav-link" href="/contact" id="green-link">Contact us</a></li>

_layouts/examples.html

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
layout: default
3+
---
4+
{% include header.html %}
5+
<main class="content" role="main" id="hero-examples">
6+
<section class="main-content">
7+
{{ content }}
8+
{% include footer.html %}
9+
</section>
10+
</main>

_sass/jekyll-theme-cayman.scss

+9
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ nav > ul > li > a:hover {
189189
margin-top: 90vh;
190190
}
191191

192+
#hero-examples {
193+
display: flex;
194+
flex-direction: column;
195+
align-items: center;
196+
justify-content: center;
197+
height: 400px;
198+
margin-top: 40vh;
199+
}
200+
192201
#hero-contact {
193202
display: flex;
194203
flex-direction: column;

examples/Data/Alterra_Postcard_2.jpg

712 KB
Loading

examples/Data/camera_para.dat

176 Bytes
Binary file not shown.

examples/Data/css/style.css

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
html,
2+
body {
3+
margin: 0;
4+
overflow: hidden;
5+
}
6+
7+
.stats {
8+
position: absolute;
9+
top: 0;
10+
left: 0;
11+
z-index: 200;
12+
margin: 0.5rem;
13+
padding: 0.5rem 0.5rem 0;
14+
}
15+
16+
.stats-item {
17+
margin: 0 0 0.5rem;
18+
19+
}
20+
21+
.stats-item-title {
22+
margin: 0 0 0.25rem;
23+
24+
font-size: 0.75rem;
25+
}
26+
27+
#stats div {
28+
position: relative !important;
29+
}
30+
31+
.ui {
32+
position: fixed;
33+
margin: 0.5rem;
34+
padding: 0.5rem;
35+
background-color: rgba( 255,255,255,0.6 );
36+
border-radius: 6px;
37+
}
38+
39+
.marker {
40+
right: 0;
41+
bottom: 0;
42+
z-index: 200;
43+
margin: 0.5rem;
44+
padding: 0.25rem 0.5rem;
45+
46+
font-size: 0.75rem;
47+
color: inherit;
48+
text-decoration: none;
49+
}

examples/Data/js/third_party/three.js/stats.min.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Data/js/third_party/three.js/three.min.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
layout: examples
3+
---
4+
<div>
5+
<a href="/examples/simple_2d_tracking.html"><h2>ArtoolkitX.js example with 2d tracking</h2></a>
6+
<p>A simple example that display a cube and a grid. You need the <a href="/examples/Data/Alterra_Postcard_2.jpg">Alterra image</a>
7+
</div>

examples/simple_2d_tracking.html

+205
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" href="./Data/css/style.css">
4+
</head>
5+
<body>
6+
<div id="stats" class="ui stats">
7+
<div class="stats-item">
8+
<p class="stats-item-title">
9+
Stats
10+
</p>
11+
</div>
12+
</div>
13+
<script src="./Data/js/third_party/three.js/three.min.js"></script>
14+
<script src="./Data/js/third_party/three.js/stats.min.js"></script>
15+
<script type='text/javascript'>
16+
window.artoolkitX_wasm_url = '../SDK/lib/artoolkitx.wasm';
17+
</script>
18+
19+
20+
<script id="vert" type="glsl-vertex">
21+
precision highp float;
22+
precision lowp int;
23+
24+
uniform mat4 cameraMatrix;
25+
uniform mat4 transformationMatrix;
26+
27+
varying vec2 vUv;
28+
29+
void main(void)
30+
{
31+
vUv = uv;
32+
gl_Position = cameraMatrix * transformationMatrix * vec4(position, 1.0);
33+
}
34+
</script>
35+
36+
<script id="frag" type="glsl-fragment">
37+
precision highp float;
38+
precision lowp int;
39+
40+
varying vec2 vUv;
41+
42+
void main(void)
43+
{
44+
gl_FragColor = vec4(vUv, 1.0, 1.0);
45+
}
46+
</script>
47+
48+
<script type="module" src="../SDK/lib/artoolkitX.api.js"></script>
49+
<script type="module">
50+
import ARController from '../SDK/lib/artoolkitX.api.js';
51+
52+
var statsMain = new Stats();
53+
statsMain.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
54+
document.getElementById( 'stats' ).appendChild( statsMain.dom );
55+
56+
let ar1, interval;
57+
58+
const cameraParam = './Data/camera_para.dat';
59+
60+
const config = {
61+
cameraParam: cameraParam,
62+
width: 640,
63+
height: 480
64+
};
65+
66+
var trackable = {
67+
trackableType: "2d",
68+
url: './Data/Alterra_Postcard_2.jpg',
69+
width: 1.0
70+
}
71+
72+
window.addEventListener('artoolkitX-loaded', () => {
73+
74+
var cMat = new THREE.Matrix4();
75+
var tMat = new THREE.Matrix4();
76+
77+
var USE_SHADER = false;
78+
79+
var shaderMaterial = new THREE.ShaderMaterial({
80+
uniforms: {
81+
cameraMatrix: {type: 'm4', value: cMat },
82+
transformationMatrix: {type: 'm4', value: tMat }
83+
},
84+
vertexShader: vert.text,
85+
fragmentShader: frag.text
86+
});
87+
88+
var renderer = new THREE.WebGLRenderer();
89+
var scene = new THREE.Scene();
90+
91+
ARController.getUserMediaARController(config).then( arController => {
92+
93+
renderer.setSize(config.width, config.height);
94+
document.body.appendChild(renderer.domElement);
95+
renderer.domElement.style = 'position: absolute; width: 100%; height: 100%'
96+
97+
var videoTex = new THREE.Texture(arController.image);
98+
99+
videoTex.minFilter = THREE.LinearFilter;
100+
videoTex.flipY = false;
101+
102+
// Then create a plane textured with the video.
103+
var plane = new THREE.Mesh(
104+
new THREE.PlaneBufferGeometry(2, 2),
105+
new THREE.MeshBasicMaterial({map: videoTex, side: THREE.DoubleSide})
106+
);
107+
108+
// The video plane shouldn't care about the z-buffer.
109+
plane.material.depthTest = false;
110+
plane.material.depthWrite = false;
111+
112+
// Create a camera and a scene for the video plane and
113+
// add the camera and the video plane to the scene.
114+
var videoCamera = new THREE.OrthographicCamera(-1, 1, -1, 1, -1, 1);
115+
var videoScene = new THREE.Scene();
116+
videoScene.add(plane);
117+
videoScene.add(videoCamera);
118+
119+
// Create a camera and a marker root object for your Three.js scene.
120+
const camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.01, 1000 );
121+
scene.add(camera);
122+
123+
var light = new THREE.PointLight(0xffffff);
124+
light.position.set(400, 500, 100);
125+
scene.add(light);
126+
var light = new THREE.PointLight(0xffffff);
127+
light.position.set(-400, -500, -100);
128+
scene.add(light);
129+
130+
var markerRoot = new THREE.Object3D();
131+
132+
markerRoot.wasVisible = false;
133+
markerRoot.markerMatrix = new Float64Array(16);
134+
markerRoot.matrixAutoUpdate = false;
135+
136+
// Add the marker models and suchlike into your marker root object.
137+
138+
var cube = new THREE.Mesh(
139+
new THREE.BoxGeometry(0.5,0.5,0.5),
140+
USE_SHADER ?
141+
shaderMaterial :
142+
new THREE.MeshLambertMaterial({ color: 0x44ffff, wireframe: false })
143+
);
144+
markerRoot.add(cube);
145+
markerRoot.visible = true;
146+
// adding a grid xz and an axesHelper
147+
var axesHelper = new THREE.AxesHelper( 5 );
148+
markerRoot.add( axesHelper );
149+
150+
var gridXZ = new THREE.GridHelper(10, 10);
151+
markerRoot.add(gridXZ);
152+
153+
// Add the marker root to your scene.
154+
scene.add(markerRoot);
155+
156+
arController.addEventListener('getMarker', (trackableInfo) => {
157+
console.log("TrackableID: " + trackableInfo.data.trackableId);
158+
markerRoot.visible = true;
159+
markerRoot.matrix.elements = trackableInfo.data.transformation
160+
});
161+
162+
try {
163+
arController.start().then( () => {
164+
console.log("start done");
165+
const camMatrix = arController.getCameraMatrix(0.01, 1000);
166+
camera.projectionMatrix.fromArray(camMatrix);
167+
camera.updateProjectionMatrix();
168+
var trackableId = arController.addTrackable(trackable);
169+
interval = setInterval(function() {
170+
arController.process();
171+
videoTex.needsUpdate = true;
172+
const ac = renderer.autoClear;
173+
renderer.autoClear = false;
174+
renderer.clear();
175+
statsMain.update()
176+
renderer.render(videoScene, videoCamera);
177+
renderer.render(scene, camera);
178+
renderer.autoClear = ac;
179+
}, 13);
180+
ar1 = arController;
181+
});
182+
}
183+
catch (e) {
184+
console.log(e);
185+
}
186+
} );
187+
188+
});
189+
190+
window.closeVideo = function() {
191+
if(ar1) {
192+
ar1.dispose();
193+
clearInterval(interval);
194+
}
195+
else {
196+
console.error("Trying to close before opened");
197+
}
198+
}
199+
200+
201+
</script>
202+
203+
<button class="ui marker" onclick="window.closeVideo()">Close Video</button>
204+
</body>
205+
</html>

0 commit comments

Comments
 (0)