Skip to content

Commit fed5b74

Browse files
committed
Implement addNFTMarker
1 parent 18c50eb commit fed5b74

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/ARToolkit.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,23 @@ export default class ARToolkit {
145145
return [markerId, markerNum];
146146
}
147147

148-
addNFTMarker() {
148+
async addNFTMarker(arId, url) {
149+
// url doesn't need to be a valid url. Extensions to make it valid will be added here
150+
const targetPrefix = '/markerNFT_' + this.markerCount++;
151+
const extensions = ['fset', 'iset', 'fset3'];
152+
153+
const storeMarker = async function (ext) {
154+
const fullUrl = url + '.' + ext;
155+
const target = targetPrefix + '.' + ext;
156+
const data = await Utils.fetchRemoteData(fullUrl);
157+
this._storeDataFile(data, target);
158+
};
159+
160+
const promises = extensions.map(storeMarker);
161+
await Promise.all(promises);
149162

163+
// return the internal marker ID
164+
return this.instance._addNFTMarker(arId, targetPrefix);
150165
}
151166
//----------------------------------------------------------------------------
152167

src/Utils.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,46 @@ export default class Utils {
1919
}
2020
return data;
2121
}
22+
23+
static uint8Data2String(uint8Data) {
24+
return String.fromCharCode.apply(String, uint8Data);
25+
}
26+
27+
static parseMultiFile(bytes) {
28+
// Parse a multi-marker file to an array of file-paths
29+
const str = Utils.uint8Data2String(bytes);
30+
31+
const lines = str.split('\n');
32+
33+
const files = [];
34+
35+
let state = 0; // 0 - read,
36+
let markers = 0;
37+
38+
lines.forEach(function (line) {
39+
line = line.trim();
40+
if (!line || line.startsWith('#')) return; // FIXME: Should probably be `if (line.indexOf('#') === 0) { return; }`
41+
42+
switch (state) {
43+
case 0:
44+
markers = +line;
45+
state = 1;
46+
return;
47+
case 1: // filename or barcode
48+
if (!line.match(/^\d+$/)) {
49+
files.push(line);
50+
}
51+
case 2: // width
52+
case 3: // matrices
53+
case 4:
54+
state++;
55+
return;
56+
case 5:
57+
state = 1;
58+
return;
59+
}
60+
});
61+
62+
return files;
63+
}
2264
}

0 commit comments

Comments
 (0)