Skip to content

Dimensions of the NFT marker in the NFTMarkerInfo to fix marker position #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
735b091
display in the log console the number of ImageSet, width, height and …
kalwalt Feb 3, 2020
0013322
added new width, height and dpi data members to arController struct
kalwalt Feb 3, 2020
d32573f
passing data to the Event listener (NFTMarkerInfo)
kalwalt Feb 3, 2020
50719ce
prettify inside getNFTMarker
kalwalt Feb 5, 2020
032c26a
trying to set the position of the model with the BoundingBox size
kalwalt Feb 6, 2020
a695e97
added calculation of position for flamingo, need more tests
nicolocarpignoli Feb 10, 2020
13b810e
trying calculation of position with the sphere, not works as expected
kalwalt Feb 10, 2020
1d2e4fb
new Duck and CesiumMan examples, in the scene but can not be viewed
kalwalt Feb 10, 2020
181d21f
Duck now is displayed, but without the re-positioning stuff
kalwalt Feb 10, 2020
7a2abb3
console log for 3d model size
nicolocarpignoli Feb 10, 2020
cf3bddb
Duck is displayed now!
kalwalt Feb 10, 2020
6162b55
Merge branch 'dimensions-NFT-feature' of https://github.com/kalwalt/j…
kalwalt Feb 10, 2020
052954d
CesiumMan visible now
kalwalt Feb 10, 2020
4566f63
sphere is not needed
kalwalt Feb 10, 2020
0c05e43
Alterra NFT marker
kalwalt Feb 10, 2020
0834fc4
re adding the console.log for 3d model size
kalwalt Feb 10, 2020
2046641
added new example for Alterra image
kalwalt Feb 17, 2020
e848235
an example with a cone and transform Matrix
kalwalt Feb 17, 2020
f80d1d3
Duck and CesiumMan examples for Alterra image
kalwalt Feb 17, 2020
c140785
added example main_center_worker.html
kalwalt Mar 10, 2020
41bbed1
using another algorithm for Flamingo model
kalwalt Mar 20, 2020
b44a407
adding matrixUtils.js and example
kalwalt Mar 20, 2020
ac9881d
some improvements in the algorithm
kalwalt Mar 23, 2020
348a8c7
added z value ( not sure that is correct)
kalwalt Mar 23, 2020
86a1980
positioning works: algo with size and dpi calculation
kalwalt Mar 25, 2020
8616afe
removing matrixUtils.js
kalwalt Mar 26, 2020
c5e89ea
cone is displayed in the center, to be improved
kalwalt Mar 26, 2020
eabcef5
removing findPosition example from the index
kalwalt Mar 26, 2020
6fcd90a
enabling animations in CesiumMan examples
kalwalt Mar 26, 2020
09101d1
better handling for animations, and better display for Mobile
kalwalt Mar 26, 2020
295b82c
fix for wasm_worker
kalwalt Mar 26, 2020
cabe736
updateWorldMatrix inside orientationchange Event listener
kalwalt Apr 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,981 changes: 2,502 additions & 2,479 deletions build/artoolkit.debug.js

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions build/artoolkit.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkit_wasm.js

Large diffs are not rendered by default.

Binary file modified build/artoolkit_wasm.wasm
Binary file not shown.
31 changes: 30 additions & 1 deletion emscripten/ARToolKitJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ struct arController {
int surfaceSetCount = 0; // Running NFT marker id
AR2SurfaceSetT *surfaceSet[PAGES_MAX];
std::unordered_map<int, AR2SurfaceSetT*> surfaceSets;
int width_NFT;
int height_NFT;
int dpi_NFT;

ARdouble nearPlane = 0.0001;
ARdouble farPlane = 1000.0;
Expand Down Expand Up @@ -156,13 +159,19 @@ extern "C" {
id: 0,
error: -1,
found: 0,
width: 0,
height: 0,
dpi: 0,
pose: [0,0,0,0, 0,0,0,0, 0,0,0,0]
});
}
var markerInfo = artoolkit["NFTMarkerInfo"];
markerInfo["id"] = $a[i++];
markerInfo["error"] = $a[i++];
markerInfo["found"] = 1;
markerInfo["width"] = $a[i++];
markerInfo["height"] = $a[i++];
markerInfo["dpi"] = $a[i++];
markerInfo["pose"][0] = $a[i++];
markerInfo["pose"][1] = $a[i++];
markerInfo["pose"][2] = $a[i++];
Expand All @@ -178,6 +187,9 @@ extern "C" {
},
markerIndex,
err,
arc->width_NFT,
arc->height_NFT,
arc->dpi_NFT,

trans[0][0],
trans[0][1],
Expand All @@ -203,13 +215,19 @@ extern "C" {
id: 0,
error: -1,
found: 0,
width: 0,
height: 0,
dpi: 0,
pose: [0,0,0,0, 0,0,0,0, 0,0,0,0]
});
}
var markerInfo = artoolkit["NFTMarkerInfo"];
markerInfo["id"] = $a[i++];
markerInfo["error"] = -1;
markerInfo["found"] = 0;
markerInfo["width"] = 0;
markerInfo["height"] = 0;
markerInfo["dpi"] = 0;
markerInfo["pose"][0] = 0;
markerInfo["pose"][1] = 0;
markerInfo["pose"][2] = 0;
Expand Down Expand Up @@ -280,7 +298,7 @@ extern "C" {
}

int loadNFTMarker(arController *arc, int surfaceSetCount, const char* datasetPathname) {
int i, pageNo;
int i, pageNo, numIset, width, height, dpi;
KpmRefDataSet *refDataSet;

KpmHandle *kpmHandle = arc->kpmHandle;
Expand Down Expand Up @@ -313,6 +331,17 @@ extern "C" {
if ((arc->surfaceSet[surfaceSetCount] = ar2ReadSurfaceSet(datasetPathname, "fset", NULL)) == NULL ) {
ARLOGe("Error reading data from %s.fset\n", datasetPathname);
}

numIset = arc->surfaceSet[surfaceSetCount]->surface[0].imageSet->num;
arc->width_NFT = arc->surfaceSet[surfaceSetCount]->surface[0].imageSet->scale[0]->xsize;
arc->height_NFT = arc->surfaceSet[surfaceSetCount]->surface[0].imageSet->scale[0]->ysize;
arc->dpi_NFT = arc->surfaceSet[surfaceSetCount]->surface[0].imageSet->scale[0]->dpi;

ARLOGi("NFT num. of ImageSet: %i\n", numIset);
ARLOGi("NFT marker width: %i\n", arc->width_NFT);
ARLOGi("NFT marker width: %i\n", arc->height_NFT);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be 'NFT marker height' ;)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i will fix it. Thank you!

ARLOGi("NFT marker dpi: %i\n", arc->dpi_NFT);

ARLOGi(" Done.\n");

if (surfaceSetCount == PAGES_MAX) exit(-1);
Expand Down
Binary file added examples/Data/models/CesiumMan.glb
Binary file not shown.
Binary file added examples/Data/models/Duck.glb
Binary file not shown.
Binary file added examples/DataNFT/Alterra_Postcard_2100.fset
Binary file not shown.
Binary file added examples/DataNFT/Alterra_Postcard_2100.fset3
Binary file not shown.
Binary file added examples/DataNFT/Alterra_Postcard_2100.iset
Binary file not shown.
15 changes: 13 additions & 2 deletions examples/nft_improved_worker/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,24 @@
<link rel="stylesheet" href="../css/index.css">
<h3>jsartoolkit5 demos with ar2Tracking</h3>
<div>Image to recognize for the following examples <a href="https://imgur.com/HvcmRVl">https://imgur.com/HvcmRVl</a></div>
<p>Examples:</p>
<p>Examples based on the pinball image:</p>
<ul>
<li><a href="threejs_worker_gltf.html">Show a 3D, animated model. Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="threejs_worker_CesiumMan_gltf.html">Show a 3D, animated model (CesiumMan). Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="threejs_worker_Duck_gltf.html">Show a 3D, animated model (Duck). Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="threejs_worker_Flamingo_gltf.html">Show a 3D, animated model (Flamingo). Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="main_threejs_worker.html">Show a 3D sphere. Uses web worker. Has loader. Has interpolation. Asm version. (high framerate)</a></li>
<li><a href="main_threejs_worker_cone.html">Show a 3D cone. Uses web worker. Has loader. Has interpolation. Asm version. (high framerate)</a></li>
<li><a href="main_threejs_wasm_worker.html">Show a 3D sphere. Uses web worker. Has loader. Has interpolation. Uses web assembly</a></li>
<li><a href="main.html">Draw a red rectangle around the image. Single-threaded. No loader</a></li>
<li><a href="main_worker.html">Draw a red rectangle around the image. Uses web worker. No loader</a></li>
<li><a href="main_center_worker.html">Draw a red rectangle around the image and the center with a green dot. Uses web worker. No loader</a></li>
</ul>
<p>Examples based on the Alterra image:</p>
<ul>
<li><a href="threejs_worker_A_CesiumMan_gltf.html">Show a 3D, animated model (CesiumMan). Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="threejs_worker_A_Duck_gltf.html">Show a 3D, animated model (Duck). Uses web worker. Has loader. Has interpolation.</a></li>
<li><a href="threejs_worker_A_Flamingo_gltf.html">Show a 3D, animated modell (Flamingo). Uses web worker. Has loader. Has interpolation.</a></li>
</ul>

</body>
</html>
65 changes: 65 additions & 0 deletions examples/nft_improved_worker/main_center_worker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<html>
<head>
<title>NFT_test</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=0.5, maximum-scale=1">
<style>
html, body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div style="position:absolute; color:white; top:0;left:0" id="stats1"><div>Main</div></div>
<div style="position:absolute; color:white; top:80px;left:0" id="stats2"><div>Worker</div></div>
<div id="container">
<video id="video"></video>
<canvas style="position: absolute; left:0; top:0" id="canvas_draw"></canvas>
</div>

<script src="../js/third_party/three.js/stats.min.js"></script>
<script src="main_center_worker.js"></script>

<script>
var statsMain = new Stats();
statsMain.showPanel(1); // 0: fps, 1: ms, 2: mb, 3+: custom
statsMain.domElement.style.position = 'relative';
statsMain.domElement.style.left = '0px';
statsMain.domElement.style.top = '0px';
document.getElementById("stats1").appendChild(statsMain.dom);

var statsWorker = new Stats();
statsWorker.showPanel(1); // 0: fps, 1: ms, 2: mb, 3+: custom
statsWorker.domElement.style.position = 'relative';
statsWorker.domElement.style.left = '0px';
statsWorker.domElement.style.top = '0px';
document.getElementById("stats2").appendChild(statsWorker.dom);

var container = document.getElementById('container');
var video = document.getElementById('video');
var canvas_draw = document.getElementById('canvas_draw');

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
var hint = {};
if (isMobile()) {
hint = {
facingMode: {"ideal": "environment"},
audio: false,
video: {
width: { ideal: 480 },
height: { ideal: 640 },
},
};
}

navigator.mediaDevices.getUserMedia({video: hint}).then(function (stream) {
video.srcObject = stream;
video.play();
video.addEventListener("loadedmetadata", function() {
start(container, markers["pinball"], video, video.videoWidth, video.videoHeight, canvas_draw, function() {statsMain.update()}, function() {statsWorker.update()});
});
});
}
</script>
</body>
</html>
212 changes: 212 additions & 0 deletions examples/nft_improved_worker/main_center_worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
function multiplyMatrices(a, b) {
var ae = a;
var be = b;
var te = new Float64Array(16);

var a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12];
var a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13];
var a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14];
var a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15];

var b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12];
var b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13];
var b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14];
var b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15];

te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;

te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;

te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;

te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;

return te;
}

function transformPoint(m, xyz) {
var x = xyz.x, y = xyz.y, z = xyz.z;
var e = m;

var w = 1 / (e[3] * x + e[7] * y + e[11] * z + e[15]);

var r = {};
r.x = (e[0] * x + e[4] * y + e[8] * z + e[12]) * w;
r.y = (e[1] * x + e[5] * y + e[9] * z + e[13]) * w;
r.z = (e[2] * x + e[6] * y + e[10] * z + e[14]) * w;

return r;
}

function isMobile() {
return /Android|mobile|iPad|iPhone/i.test(navigator.userAgent);
}

var markers = {
"pinball": {
width: 1637,
height: 2048,
dpi: 215,
url: "./examples/DataNFT/pinball",
},
};

function start(container, marker, video, input_width, input_height, canvas_draw, render_update, track_update) {
var vw, vh;
var sw, sh;
var pscale, sscale;
var w, h;
var pw, ph;
var ox, oy;
var worker;
var camera_para = './../examples/Data/camera_para-iPhone 5 rear 640x480 1.0m.dat'

var canvas_process = document.createElement('canvas');
var context_draw = canvas_draw.getContext('2d');
var context_process = canvas_process.getContext('2d');

var load = function() {
vw = input_width;
vh = input_height;

pscale = 320 / Math.max(vw, vh / 3 * 4);
sscale = isMobile() ? window.outerWidth / input_width : 1;

sw = vw * sscale;
sh = vh * sscale;
video.style.width = sw + "px";
video.style.height = sh + "px";
container.style.width = sw + "px";
container.style.height = sh + "px";
canvas_draw.style.clientWidth = sw + "px";
canvas_draw.style.clientHeight = sh + "px";
canvas_draw.width = sw;
canvas_draw.height = sh;
w = vw * pscale;
h = vh * pscale;
pw = Math.max(w, h / 3 * 4);
ph = Math.max(h, w / 4 * 3);
ox = (pw - w) / 2;
oy = (ph - h) / 2;
canvas_process.style.clientWidth = pw + "px";
canvas_process.style.clientHeight = ph + "px";
canvas_process.width = pw;
canvas_process.height = ph;

worker = new Worker('../../js/artoolkit.worker.js');

worker.postMessage({type: "load", pw: pw, ph: ph, camera_para: camera_para, marker: '../' + marker.url});

worker.onmessage = function(ev) {
var msg = ev.data;
switch (msg.type) {
case "found": {
found(msg);
break;
}
case "not found": {
found(null);
break;
}
}
track_update();
process();
};
};

var lastmsg = null;
var found = function(msg) {
lastmsg = msg;
};

var lasttime = Date.now();
var time = 0;

var x = 0;

var draw = function() {
context_draw.clearRect(0, 0, vw, vh);
render_update();
var now = Date.now();
var dt = now - lasttime;
time += dt;
lasttime = now;

x += dt;
x %= sw;
context_draw.fillStyle = "#FFF";
context_draw.fillRect(x, 0, 5, 10);

if (!lastmsg) return;
var proj = JSON.parse(lastmsg.proj);
var world = JSON.parse(lastmsg.matrixGL_RH);

var mat = multiplyMatrices(proj, world);

function glpointToCanvas(xyz) {
return {
x: (xyz.x + 1) * 0.5 * pw / pscale * sscale - ox / pscale * sscale,
y: (1 - xyz.y) * 0.5 * ph / pscale * sscale - oy / pscale * sscale,
}
}
function drawpoint(x, y, z) {
var r = transformPoint(mat, {x: x, y: y, z: z});
var c = glpointToCanvas(r);
return c;
}

var width = marker.width;
var height = marker.height;
var dpi = marker.dpi;

var w = width / dpi * 2.54 * 10;
var h = height / dpi * 2.54 * 10;

var p1 = drawpoint(0, 0, 0);
var p2 = drawpoint(w, 0, 0);
var p3 = drawpoint(w, h, 0);
var p4 = drawpoint(0, h, 0);
var pos = drawpoint(w/2, h/2, 0);
context_draw.beginPath()
context_draw.arc(pos.x, pos.y, 8, 0, Math.PI * 2)
context_draw.fillStyle = 'green'
context_draw.fill()
context_draw.beginPath();
context_draw.moveTo(p1.x, p1.y);
context_draw.lineTo(p2.x, p2.y);
context_draw.lineTo(p3.x, p3.y);
context_draw.lineTo(p4.x, p4.y);
context_draw.closePath();
context_draw.strokeStyle = "red";
context_draw.stroke();
};

function process() {
context_process.fillStyle = "black";
context_process.fillRect(0, 0, pw, ph);
context_process.drawImage(video, 0, 0, vw, vh, ox, oy, w, h);

var imageData = context_process.getImageData(0, 0, pw, ph);
worker.postMessage({type: "process", imagedata: imageData}, [imageData.data.buffer]);
}
var tick = function() {
draw();
requestAnimationFrame(tick);
};

load();
tick();
process();
}
Loading