diff --git a/README.md b/README.md index 07b68468..41cf5ad5 100644 --- a/README.md +++ b/README.md @@ -2,20 +2,22 @@ Emscripten port of [ARToolKit](https://github.com/artoolkitx/artoolkit5) to JavaScript. -## MArkers Types +## Markers Types JSARToolKit5 support these types of markers: + - Square pictorial markers - Square barcode markers - Multi square markers set - NFT (natural feature tracking) markers ---- +-------------------------------------------------------------------------------- + **NOTE:** When writing JavaScript and making changes be aware that the emscripten uglifier does not support the ES6 syntax. ---- +-------------------------------------------------------------------------------- ## Project Structure @@ -24,31 +26,35 @@ When writing JavaScript and making changes be aware that the emscripten uglifier - `emscripten/` (source code for ARToolKit.js) - `examples/` (demos and examples using ARToolKit.js) - `js/` (compiled versions of ARToolKit.js with Three.js helper api) +- `tests/` (tests for compiled versions of ARToolKit.js) - `tools/` (build scripts for building ARToolKit.js) ## WebAssembly -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 = '<>/artoolkit_wasm.wasm';``` before loading the artoolkit_wasm.js file, like this: +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 = '<>/artoolkit_wasm.wasm';` before loading the artoolkit_wasm.js file, like this: -```js +```javascript ``` + As loading the WebAssembly artifact is done asynchronously, there is a callback that is called when everything is ready. -```js +```javascript window.addEventListener('artoolkit-loaded', () => { //do artoolkit stuff here }); ``` + See examples/simple_image_wasm.html for details. ## Clone the repository 1. Clone this repository 2. Clone ARToolKit5 project to get the latest source files. From within jsartoolkit5 directory do `git submodule update --init`. If you already cloned ARToolKit5 to a different directory you can: + - create a link in the `jsartoolkit5/emscripten/` directory that points to ARToolKit5 (`jsartoolkit5/emscripten/artoolkit5`) (Linux and macOS only) - or, set the `ARTOOLKIT5_ROOT` environment variable to point to your ARToolKit5 clone - or, change the `tools/makem.js` file to point to your artoolkit5 clone (line 20) @@ -62,40 +68,43 @@ See examples/simple_image_wasm.html for details. 3. `npm install` 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 5. `docker exec emscripten npm run build-local` to build JS version of artoolkit5 -6. `docker stop emscripten` to stop the container after the build, if needed -7. `docker rm emscripten` to remove the container -8. `docker rmi trzeci/emscripten-slim:latest` to remove the Docker image, if you don't need it anymore -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 +6. `docker exec emscripten npm run build-local-no-libar` to build JS version of artoolkit5 without rebuilding libar.bc +7. `docker stop emscripten` to stop the container after the build, if needed +8. `docker rm emscripten` to remove the container +9. `docker rmi trzeci/emscripten-slim:latest` to remove the Docker image, if you don't need it anymore +10. 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 ### ⚠️ Not recommended ⚠️ : Build local with manual emscripten setup -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.** -** Not working on macOS!** +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.** **Not working on macOS!** 1. Install build tools - 1. Install node.js (https://nodejs.org/en/) - 2. Install python2 (https://www.python.org/downloads/) - 3. Install emscripten (https://emscripten.org/docs/getting_started/downloads.html#download-and-install) - We used emscripten version **1.39.5-fastcomp** ~~1.38.44-fastcomp~~ -jsartoolkit5 aim is to create a Javascript version of artoolkit5. First, you need the artoolkit5 repository on your machine: + 1. Install node.js () + 2. Install python2 () + 3. Install emscripten () We used emscripten version **1.39.5-fastcomp** ~~1.38.44-fastcomp~~ + +jsartoolkit5 aim is to create a Javascript version of artoolkit5\. First, you need the artoolkit5 repository on your machine: + 2. Clone ARToolKit5 project to get the latest source files. From within jsartoolkit5 directory do `git submodule update --init`. If you already cloned ARToolKit5 to a different directory you can: + - create a link in the `jsartoolkit5/emscripten/` directory that points to ARToolKit5 (`jsartoolkit5/emscripten/artoolkit5`) - or, set the `ARTOOLKIT5_ROOT` environment variable to point to your ARToolKit5 clone - or, change the `tools/makem.js` file to point to your artoolkit5 clone (line 20) 3. Building + 1. Make sure `EMSCRIPTEN` env variable is set (e.g. `EMSCRIPTEN=/usr/lib/emsdk_portable/emscripten/master/ node tools/makem.js` - 3. Run `npm install` - 4. Run `npm run build-local` + 2. Run `npm install` + 3. Run `npm run build-local` -During development, you can run ```npm run watch```, it will rebuild the library everytime you change ```./js/``` directory. +During development, you can run `npm run watch`, it will rebuild the library everytime you change `./js/` directory. You can also run the script with the option `npm run build-local-no-libar` if you have already build libar.bc and you don't want to rebuild. 4. The built ASM.js files 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`. ## ARToolKit JS API -```js +```javascript @@ -103,7 +112,7 @@ During development, you can run ```npm run watch```, it will rebuild the library ## ARToolKit JS debug build -```js +```javascript @@ -114,7 +123,7 @@ During development, you can run ```npm run watch```, it will rebuild the library ## ARToolKit Three.js helper API -```js +```javascript @@ -149,7 +158,7 @@ The basic operation goes like this: ### Basic example with an image source and a pattern marker ( hiro ) -```js +```javascript diff --git a/package.json b/package.json index 7ea9824b..bbe5ab9f 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,17 @@ { "name": "jsartoolkit", - "version": "0.0.0", + "version": "5.5.139", "main": "js/index", "typings": "js/index", "description": "Emscripten port of ARToolKit to JavaScript", "keywords": [ "ARToolKit", "AR", - "Augmented Reality" + "Augmented Reality", + "WebAR", + "JavaScript" ], - "author": "ARToolKit (https://github.com/artoolkit)", + "author": "ARToolKit (https://github.com/artoolkitx/artoolkit5)", "repository": "git://https://github.com/artoolkitx/jsartoolkit5.git", "homepage": "https://github.com/artoolkitx/jsartoolkit5", "contributors": [ @@ -32,6 +34,7 @@ }, "scripts": { "build-local": "node tools/makem.js; echo Built at `date`", + "build-local-no-libar": "node tools/makem.js --no-libar; echo Built at `date`", "watch": "./node_modules/.bin/watch 'npm run build' ./js/", "create-doc": "grunt jsdoc", "test": "http-server -p 8085", diff --git a/tools/makem.js b/tools/makem.js index d8c72f34..674d3e38 100644 --- a/tools/makem.js +++ b/tools/makem.js @@ -8,12 +8,23 @@ var exec = require('child_process').exec, path = require('path'), - fs = require('fs'), - os = require('os'), + fs = require('fs'), + os = require('os'), child; const platform = os.platform(); +var NO_LIBAR = false; + +var arguments = process.argv; + +for (var j = 2; j < arguments.length; j++) { + if (arguments[j] == '--no-libar') { + NO_LIBAR = true; + console.log('Building jsartoolkit5 with --no-libar option, libar will be preserved.'); + }; +} + var HAVE_NFT = 1; var EMSCRIPTEN_ROOT = process.env.EMSCRIPTEN; @@ -74,7 +85,7 @@ function matchAll(patterns, prefix="") { return r; } - ar_sources = matchAll([ + ar_sources = matchAll([ 'AR/arLabelingSub/*.c', 'AR/*.c', 'ARICP/*.c', @@ -157,6 +168,7 @@ FLAGS += ' -s TOTAL_MEMORY=' + MEM + ' '; FLAGS += ' -s USE_ZLIB=1'; FLAGS += ' -s USE_LIBJPEG'; FLAGS += ' --memory-init-file 0 '; // for memless file +FLAGS += ' -s ALLOW_MEMORY_GROWTH=1'; var WASM_FLAGS = ' -s BINARYEN_TRAP_MODE=clamp' @@ -166,10 +178,8 @@ FLAGS += ' --bind '; /* DEBUG FLAGS */ var DEBUG_FLAGS = ' -g '; -// DEBUG_FLAGS += ' -s ASSERTIONS=2 ' DEBUG_FLAGS += ' -s ASSERTIONS=1 ' DEBUG_FLAGS += ' --profiling ' -// DEBUG_FLAGS += ' -s EMTERPRETIFY_ADVISE=1 ' DEBUG_FLAGS += ' -s ALLOW_MEMORY_GROWTH=1'; DEBUG_FLAGS += ' -s DEMANGLE_SUPPORT=1 '; @@ -196,8 +206,12 @@ function clean_builds() { try { var files = fs.readdirSync(OUTPUT_PATH); - if (files.length > 0) - for (var i = 0; i < files.length; i++) { + var filesLength = files.length; + if (filesLength > 0) + if (NO_LIBAR == true){ + filesLength -= 1; + } + for (var i = 0; i < filesLength; i++) { var filePath = OUTPUT_PATH + '/' + files[i]; if (fs.statSync(filePath).isFile()) fs.unlinkSync(filePath); @@ -233,11 +247,6 @@ var compile_wasm = format(EMCC + ' ' + INCLUDES + ' ' + FLAGS + WASM_FLAGS + DEFINES + PRE_FLAGS + ' -o {OUTPUT_PATH}{BUILD_FILE} ', OUTPUT_PATH, OUTPUT_PATH, BUILD_WASM_FILE); -var compile_all = format(EMCC + ' ' + INCLUDES + ' ' - + ar_sources.join(' ') - + FLAGS + ' ' + DEFINES + ' -o {OUTPUT_PATH}{BUILD_FILE} ', - OUTPUT_PATH, BUILD_DEBUG_FILE); - /* * Run commands */ @@ -278,11 +287,12 @@ function addJob(job) { addJob(clean_builds); addJob(compile_arlib); -//addJob(compile_kpm); -// compile_kpm addJob(compile_combine); addJob(compile_wasm); addJob(compile_combine_min); -// addJob(compile_all); + +if (NO_LIBAR == true){ + jobs.splice(1,1); +} runJob();