Skip to content

Commit

Permalink
convert variables type var to let or const
Browse files Browse the repository at this point in the history
  • Loading branch information
kalwalt committed Oct 24, 2024
1 parent e6a1135 commit 0ac0413
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 216 deletions.
2 changes: 1 addition & 1 deletion build/artoolkitNFT.min.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/artoolkitNFT_wasm.simd.js

Large diffs are not rendered by default.

141 changes: 71 additions & 70 deletions js/artoolkitNFT.api.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; (function () {
'use strict'

var scope;
let scope;
if (typeof window !== 'undefined') {
scope = window;
} else if (typeof global !== 'undefined') {
Expand All @@ -11,31 +11,31 @@
}

/**
The ARControllerNFT is the main object for doing AR marker detection with JSARToolKit.
The ARControllerNFT is the main object for doing AR marker detection with JSARToolKit.
To use an ARControllerNFT, you need to tell it the dimensions to use for the AR processing canvas and
pass it an ARCameraParamNFT to define the camera parameters to use when processing images.
The ARCameraParamNFT defines the lens distortion and aspect ratio of the camera used.
See https://www.artoolworks.com/support/library/Calibrating_your_camera for more information about AR camera parameters and how to make and use them.
To use an ARControllerNFT, you need to tell it the dimensions to use for the AR processing canvas and
pass it an ARCameraParamNFT to define the camera parameters to use when processing images.
The ARCameraParamNFT defines the lens distortion and aspect ratio of the camera used.
See https://www.artoolworks.com/support/library/Calibrating_your_camera for more information about AR camera parameters and how to make and use them.
If you pass an image as the first argument, the ARControllerNFT uses that as the image to process,
using the dimensions of the image as AR processing canvas width and height. If the first argument
to ARControllerNFT is an image, the second argument is used as the camera param.
If you pass an image as the first argument, the ARControllerNFT uses that as the image to process,
using the dimensions of the image as AR processing canvas width and height. If the first argument
to ARControllerNFT is an image, the second argument is used as the camera param.
The camera parameters argument can be either an ARCameraParamNFT or an URL to a camera definition file.
If the camera argument is an URL, it is loaded into a new ARCameraParamNFT, and the ARControllerNFT dispatches
a 'load' event and calls the onload method if it is defined.
The camera parameters argument can be either an ARCameraParamNFT or an URL to a camera definition file.
If the camera argument is an URL, it is loaded into a new ARCameraParamNFT, and the ARControllerNFT dispatches
a 'load' event and calls the onload method if it is defined.
@exports ARControllerNFT
@constructor
@exports ARControllerNFT
@constructor
@param {number} width The width of the images to process.
@param {number} height The height of the images to process.
@param {ARCameraParamNFT | string} camera The ARCameraParamNFT to use for image processing. If this is a string, the ARControllerNFT treats it as an URL and tries to load it as a ARCameraParamNFT definition file, calling ARControllerNFT#onload on success.
*/
var ARControllerNFT = function (width, height, cameraPara) {
@param {number} width The width of the images to process.
@param {number} height The height of the images to process.
@param {ARCameraParamNFT | string} camera The ARCameraParamNFT to use for image processing. If this is a string, the ARControllerNFT treats it as an URL and tries to load it as a ARCameraParamNFT definition file, calling ARControllerNFT#onload on success.
*/
const ARControllerNFT = function (width, height, cameraPara) {
this.id = undefined;
var w = width, h = height;
const w = width, h = height;

this.listeners = {};

Expand Down Expand Up @@ -90,7 +90,7 @@
artoolkitNFT.teardown(this.id);
}

for (var t in this) {
for (const t in this) {
this[t] = null;
}
};
Expand Down Expand Up @@ -123,29 +123,29 @@
this._copyImageToHeap(image);

// get NFT markers
var k, o;
let k, o;
for (k in this.nftMarkers) {
o = this.nftMarkers[k];
o.inPrevious = o.inCurrent;
o.inCurrent = false;
}

// detect NFT markers
var nftMarkerCount = this.nftMarkerCount;
const nftMarkerCount = this.nftMarkerCount;
this.detectNFTMarker();

// in ms
var MARKER_LOST_TIME = 200;
const MARKER_LOST_TIME = 200;

for (var i = 0; i < nftMarkerCount; i++) {
var nftMarkerInfo = this.getNFTMarker(i);
var markerType = artoolkitNFT.NFT_MARKER;
for (let i = 0; i < nftMarkerCount; i++) {
const nftMarkerInfo = this.getNFTMarker(i);
const markerType = artoolkitNFT.NFT_MARKER;

if (nftMarkerInfo.found) {
self.markerFound = i;
self.markerFoundTime = Date.now();

var visible = this.trackNFTMarkerId(i);
const visible = this.trackNFTMarkerId(i);
visible.matrix.set(nftMarkerInfo.pose);
visible.inCurrent = true;
this.transMatToGLMat(visible.matrix, this.transform_mat);
Expand Down Expand Up @@ -205,7 +205,7 @@
@return {Object} The marker tracking object.
*/
ARControllerNFT.prototype.trackNFTMarkerId = function (id, markerWidth) {
var obj = this.nftMarkers[id];
let obj = this.nftMarkers[id];
if (!obj) {
this.nftMarkers[id] = obj = {
inPrevious: false,
Expand Down Expand Up @@ -260,9 +260,9 @@
@param {Object} event Event to dispatch.
*/
ARControllerNFT.prototype.dispatchEvent = function (event) {
var listeners = this.listeners[event.name];
const listeners = this.listeners[event.name];
if (listeners) {
for (var i = 0; i < listeners.length; i++) {
for (let i = 0; i < listeners.length; i++) {
listeners[i].call(this, event);
}
}
Expand All @@ -288,7 +288,7 @@
@param {function} onError - The error callback. Called with the encountered error if the load fails.
*/
ARControllerNFT.prototype.loadNFTMarkers = function (markerURLs, onSuccess, onError) {
var self = this;
const self = this;
artoolkitNFT.addNFTMarkers(this.id, markerURLs, function (ids) {
self.nftMarkerCount += ids.length;
onSuccess(ids);
Expand Down Expand Up @@ -359,7 +359,7 @@
@param {number} [scale] The scale for the transform.
*/
ARControllerNFT.prototype.arglCameraViewRHf = function (glMatrix, glRhMatrix, scale) {
var m_modelview;
let m_modelview;
if (glRhMatrix == undefined)
m_modelview = new Float64Array(16);
else
Expand Down Expand Up @@ -687,15 +687,15 @@
var imageData = image;

}
var data = imageData.data; // this is of type Uint8ClampedArray: The Uint8ClampedArray typed array represents an array of 8-bit unsigned integers clamped to 0-255 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray)
const data = imageData.data; // this is of type Uint8ClampedArray: The Uint8ClampedArray typed array represents an array of 8-bit unsigned integers clamped to 0-255 (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray)

//Here we have access to the unmodified video image. We now need to add the videoLuma chanel to be able to serve the underlying ARTK API
if (this.videoLuma) {
var q = 0;
let q = 0;
//Create luma from video data assuming Pixelformat AR_PIXEL_FORMAT_RGBA (ARToolKitJS.cpp L: 43)

for (var p = 0; p < this.videoSize; p++) {
var r = data[q + 0], g = data[q + 1], b = data[q + 2];
for (let p = 0; p < this.videoSize; p++) {
const r = data[q], g = data[q + 1], b = data[q + 2];
// videoLuma[p] = (r+r+b+g+g+g)/6; // https://stackoverflow.com/a/596241/5843642
this.videoLuma[p] = (r + r + r + b + g + g + g + g) >> 3;
q += 4;
Expand Down Expand Up @@ -729,7 +729,7 @@
@param {Function} onload Onload callback to be called on successful parameter loading.
@param {Function} onerror Error callback to called when things don't work out.
*/
var ARCameraParamNFT = function (src, onload, onerror) {
const ARCameraParamNFT = function (src, onload, onerror) {
this.id = -1;
this._src = '';
this.complete = false;
Expand Down Expand Up @@ -804,7 +804,7 @@

// ARToolKit exported JS API
//
var artoolkitNFT = {
const artoolkitNFT = {

UNKNOWN_MARKER: -1,
NFT_MARKER: 0, // 0,
Expand All @@ -815,7 +815,7 @@

};

var FUNCTIONS = [
const FUNCTIONS = [
'setup',
'teardown',

Expand Down Expand Up @@ -857,20 +857,20 @@
artoolkitNFT[n] = Module[n];
});

for (var m in Module) {
for (const m in Module) {
if (m.match(/^AR/))
artoolkitNFT[m] = Module[m];
}
}

var marker_count = 0;
let marker_count = 0;

function addNFTMarker(arId, url, callback, onError) {
var mId = marker_count++;
var prefix = '/markerNFT_' + mId;
var filename1 = prefix + '.fset';
var filename2 = prefix + '.iset';
var filename3 = prefix + '.fset3';
const mId = marker_count++;
const prefix = '/markerNFT_' + mId;
const filename1 = prefix + '.fset';
const filename2 = prefix + '.iset';
const filename3 = prefix + '.fset3';
ajax(url + '.fset', filename1, function () {
ajax(url + '.iset', filename2, function () {
ajax(url + '.fset3', filename3, function () {
Expand All @@ -881,18 +881,18 @@
}, function (errorNumber) { if (onError) onError(errorNumber); });
}

function addNFTMarkers(arId, urls, callback, onError) {
var prefixes = [];
var pending = urls.length * 3;
var onSuccess = (filename) => {
function addNFTMarkers(arId, urls, callback, onerror) {
const prefixes = [];
let pending = urls.length * 3;
const onSuccess = (filename) => {
pending -= 1;
if (pending === 0) {
const vec = new Module.StringList();
const markerIds = [];
for (let i = 0; i < prefixes.length; i++) {
vec.push_back(prefixes[i]);
}
var ret = Module._addNFTMarkers(arId, vec);
const ret = Module._addNFTMarkers(arId, vec);
for (let i = 0; i < ret.size(); i++) {
markerIds.push(ret.get(i));
}
Expand All @@ -901,18 +901,18 @@
if (callback) callback(markerIds);
}
}
var onError = (filename, errorNumber) => {
const onError = (filename, errorNumber) => {
console.log("failed to load: ", filename);
onError(errorNumber);
onerror(errorNumber);
}

for (var i = 0; i < urls.length; i++) {
var url = urls[i];
var prefix = '/markerNFT_' + marker_count;
for (let i = 0; i < urls.length; i++) {
const url = urls[i];
const prefix = '/markerNFT_' + marker_count;
prefixes.push(prefix);
var filename1 = prefix + '.fset';
var filename2 = prefix + '.iset';
var filename3 = prefix + '.fset3';
const filename1 = prefix + '.fset';
const filename2 = prefix + '.iset';
const filename3 = prefix + '.fset3';

ajax(url + '.fset', filename1, onSuccess.bind(filename1), onError.bind(filename1));
ajax(url + '.iset', filename2, onSuccess.bind(filename2), onError.bind(filename2));
Expand All @@ -925,14 +925,15 @@
return String.fromCharCode.apply(String, array);
}

var camera_count = 0;
let camera_count = 0;

function loadCamera(url, callback, errorCallback) {
var filename = '/camera_param_' + camera_count++;
var writeCallback = function (errorCode) {
const filename = '/camera_param_' + camera_count++;
const writeCallback = function (errorCode) {
const id = Module._loadCamera(filename);
if (!Module._loadCamera) {
if (callback) callback(id); setTimeout(writeCallback, 10);
} else {
var id = Module._loadCamera(filename);
if (callback) callback(id);
}
};
Expand All @@ -948,8 +949,8 @@
// transfer image

function writeStringToFS(target, string, callback) {
var byteArray = new Uint8Array(string.length);
for (var i = 0; i < byteArray.length; i++) {
const byteArray = new Uint8Array(string.length);
for (let i = 0; i < byteArray.length; i++) {
byteArray[i] = string.charCodeAt(i) & 0xff;
}
writeByteArrayToFS(target, byteArray, callback);
Expand All @@ -967,15 +968,15 @@
// ajax('../bin/Data/patt.hiro', '/patt.hiro', callback);

function ajax(url, target, callback, errorCallback) {
var oReq = new XMLHttpRequest();
const oReq = new XMLHttpRequest();
oReq.open('GET', url, true);
oReq.responseType = 'arraybuffer'; // blob arraybuffer

oReq.onload = function () {
if (this.status == 200) {
// console.log('ajax done for ', url);
var arrayBuffer = oReq.response;
var byteArray = new Uint8Array(arrayBuffer);
const arrayBuffer = oReq.response;
const byteArray = new Uint8Array(arrayBuffer);
writeByteArrayToFS(target, byteArray, callback);
}
else {
Expand All @@ -994,7 +995,7 @@
if (scope.Module) {
scope.Module.onRuntimeInitialized = function () {
runWhenLoaded();
var event = new Event('artoolkitNFT-loaded');
const event = new Event('artoolkitNFT-loaded');
scope.dispatchEvent(event);
};
} else {
Expand Down
Loading

0 comments on commit 0ac0413

Please sign in to comment.