Jean-Yves Didier

merge between master and branch modules

1 module.exports = function (grunt) { 1 module.exports = function (grunt) {
2 "use strict"; 2 "use strict";
3 3
4 + let shim = function(obj) { return `\nexport default ${obj};\n`; };
5 +
4 // Project configuration. 6 // Project configuration.
5 grunt.initConfig({ 7 grunt.initConfig({
6 pkg: grunt.file.readJSON('package.json'), 8 pkg: grunt.file.readJSON('package.json'),
9 + copy: {
10 + dist: {
11 + files:[
12 + {src: 'src/arcs_browser.js', dest: 'build/arcs_browser.js'},
13 + {src: 'src/arcs_node.mjs', dest: 'build/arcs_node.mjs'}
14 + ]
15 +
16 + }
17 + },
7 jsdoc: { 18 jsdoc: {
8 dist: { 19 dist: {
9 src: ['src/*.js', 'docs/Readme.md'], //, 'components/*.js'], 20 src: ['src/*.js', 'docs/Readme.md'], //, 'components/*.js'],
...@@ -43,16 +54,13 @@ module.exports = function (grunt) { ...@@ -43,16 +54,13 @@ module.exports = function (grunt) {
43 } 54 }
44 } 55 }
45 }, 56 },
46 - uglify: { 57 + terser: {
47 build: { 58 build: {
48 - options: {
49 - banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
50 - },
51 files: { 59 files: {
52 'build/arcs.min.js': [ 60 'build/arcs.min.js': [
53 'build/arcs.js' 61 'build/arcs.js'
54 ], 62 ],
55 - 'build/arcs_browser.js': [ 63 + 'build/arcs_browser.min.js': [
56 'src/arcs_browser.js' 64 'src/arcs_browser.js'
57 ], 65 ],
58 'build/arcseditor.min.js': [ 66 'build/arcseditor.min.js': [
...@@ -74,6 +82,37 @@ module.exports = function (grunt) { ...@@ -74,6 +82,37 @@ module.exports = function (grunt) {
74 } 82 }
75 83
76 }, 84 },
85 + file_append: {
86 + default_options: {
87 + files: [
88 + {
89 + append: shim('AR'),
90 + prepend: `import CV from '../cv/index.js';\n`,
91 + input: './deps/aruco/index.js'
92 + },
93 + {
94 + append: shim('CV'),
95 + input: './deps/cv/index.js'
96 + }
97 + ]
98 + }
99 + },
100 + 'string-replace': {
101 + dist: {
102 + files: {
103 + 'deps/objloader/objloader.js': 'deps/objloader/index.js',
104 + 'deps/mtlloader/mtlloader.js': 'deps/mtlloader/index.js',
105 + 'deps/ddsloader/ddsloader.js': 'deps/ddsloader/index.js'
106 + },
107 + options: {
108 + replacements:[{
109 + pattern: '../../../build/three.module.js',
110 + replacement: '../three.js/index.js'
111 + }]
112 + }
113 +
114 + }
115 + },
77 concat: { 116 concat: {
78 dist: { 117 dist: {
79 src: [ 118 src: [
...@@ -88,7 +127,6 @@ module.exports = function (grunt) { ...@@ -88,7 +127,6 @@ module.exports = function (grunt) {
88 'src/transitionnetwork.js', 127 'src/transitionnetwork.js',
89 'src/statemachine.js', 128 'src/statemachine.js',
90 'src/application.js', 129 'src/application.js',
91 - 'src/arcs_module.js',
92 'src/exports.js' 130 'src/exports.js'
93 ], 131 ],
94 dest: 'build/arcs.js' 132 dest: 'build/arcs.js'
...@@ -108,19 +146,22 @@ module.exports = function (grunt) { ...@@ -108,19 +146,22 @@ module.exports = function (grunt) {
108 146
109 } 147 }
110 148
111 -
112 }); 149 });
113 150
114 -// Load the plugin that provides the "uglify" task. 151 + // Load the plugin that provides the "uglify" task.
115 - grunt.loadNpmTasks('grunt-contrib-uglify');
116 grunt.loadNpmTasks('grunt-contrib-concat'); 152 grunt.loadNpmTasks('grunt-contrib-concat');
153 + grunt.loadNpmTasks('grunt-contrib-copy');
117 grunt.loadNpmTasks('grunt-jsdoc'); 154 grunt.loadNpmTasks('grunt-jsdoc');
118 grunt.loadNpmTasks('grunt-jslint'); 155 grunt.loadNpmTasks('grunt-jslint');
156 + grunt.loadNpmTasks('grunt-terser');
119 grunt.loadNpmTasks('grunt-bower-task'); 157 grunt.loadNpmTasks('grunt-bower-task');
158 + grunt.loadNpmTasks('grunt-file-append');
159 + grunt.loadNpmTasks('grunt-string-replace');
120 160
121 - 161 + // Default task(s).
122 -// Default task(s). 162 + grunt.registerTask('default', ['concat','copy','terser']);
123 - grunt.registerTask('default', ['concat','uglify']);
124 grunt.registerTask('lint', ['jslint']); 163 grunt.registerTask('lint', ['jslint']);
125 grunt.registerTask('doc', ['jsdoc']); 164 grunt.registerTask('doc', ['jsdoc']);
165 + grunt.registerTask('install-deps', ['bower', 'file_append', 'string-replace']);
166 +
126 }; 167 };
......
1 { 1 {
2 "name": "ARCS", 2 "name": "ARCS",
3 - "version": "0.1.0", 3 + "version": "0.2.0",
4 "description": "Augmented Reality Component System in web browser and node environment", 4 "description": "Augmented Reality Component System in web browser and node environment",
5 "main": "build/arcs.js", 5 "main": "build/arcs.js",
6 "keywords": [ 6 "keywords": [
...@@ -10,12 +10,11 @@ ...@@ -10,12 +10,11 @@
10 "author": "Jean-Yves Didier", 10 "author": "Jean-Yves Didier",
11 "license": "GPL", 11 "license": "GPL",
12 "dependencies": { 12 "dependencies": {
13 - "requirejs": "*",
14 "tracking.js": "*", 13 "tracking.js": "*",
15 - "three.js": "https://raw.githubusercontent.com/mrdoob/three.js/r68/build/three.min.js", 14 + "three.js": "https://raw.githubusercontent.com/mrdoob/three.js/r116/build/three.module.js",
16 - "objloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r68/examples/js/loaders/OBJLoader.js", 15 + "objloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r116/examples/jsm/loaders/OBJLoader.js",
17 - "mtlloader": "https://raw.githubusercontent.com/mrdoob/three.js/r68/examples/js/loaders/MTLLoader.js", 16 + "mtlloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r116/examples/jsm/loaders/MTLLoader.js",
18 - "objmtlloader": "https://raw.githubusercontent.com/mrdoob/three.js/r68/examples/js/loaders/OBJMTLLoader.js", 17 + "ddsloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r116/examples/jsm/loaders/DDSLoader.js",
19 "aruco": "https://raw.githubusercontent.com/jcmellado/js-aruco/master/src/aruco.js", 18 "aruco": "https://raw.githubusercontent.com/jcmellado/js-aruco/master/src/aruco.js",
20 "cv": "https://raw.githubusercontent.com/jcmellado/js-aruco/master/src/cv.js", 19 "cv": "https://raw.githubusercontent.com/jcmellado/js-aruco/master/src/cv.js",
21 "codemirror" : "*", 20 "codemirror" : "*",
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +{ "type": "module"}
1 -arcs_module(
2 - function (ARCS) {
3 - var Animator;
4 1
5 - /** 2 +import ARCS from '../build/arcs.js';
3 +
4 +var Animator;
5 +
6 +/**
6 * @class Animator 7 * @class Animator
7 * @classdesc A component that request new frames for animation. 8 * @classdesc A component that request new frames for animation.
8 * This component is useful when you want to create animations in the 9 * This component is useful when you want to create animations in the
9 * context of a web browser. 10 * context of a web browser.
10 */ 11 */
11 - Animator = ARCS.Component.create( 12 +Animator = ARCS.Component.create(
12 function() { 13 function() {
13 var paused = false; 14 var paused = false;
14 var self=this; 15 var self=this;
...@@ -49,8 +50,6 @@ arcs_module( ...@@ -49,8 +50,6 @@ arcs_module(
49 }, 50 },
50 ['start','stop'], 51 ['start','stop'],
51 'onAnimationFrame' 52 'onAnimationFrame'
52 - );
53 -
54 - return {Animator: Animator};
55 - }
56 ); 53 );
54 +
55 +export default {Animator: Animator};
......
1 -arcs_module( 1 +import ARCS from '../build/arcs.js';
2 - function (ARCS, CV, AR) { 2 +import CV from '../deps/cv/index.js';
3 - var ARUCODetector; 3 +import AR from '../deps/aruco/index.js';
4 4
5 - /** 5 +var ARUCODetector;
6 +
7 +/**
6 * @class ARUCODetector 8 * @class ARUCODetector
7 * @classdesc Component that detects ARUCO markers in images 9 * @classdesc Component that detects ARUCO markers in images
8 * This component encapsulate the {@link https://github.com/jcmellado/js-aruco|js-aruco} library. 10 * This component encapsulate the {@link https://github.com/jcmellado/js-aruco|js-aruco} library.
9 */ 11 */
10 - ARUCODetector = ARCS.Component.create( 12 +ARUCODetector = ARCS.Component.create(
11 function() { 13 function() {
12 var detector ; 14 var detector ;
13 15
...@@ -48,12 +50,6 @@ arcs_module( ...@@ -48,12 +50,6 @@ arcs_module(
48 }, 50 },
49 'detect', 51 'detect',
50 ['onMarkers'] 52 ['onMarkers']
51 - );
52 -
53 - return {ARUCODetector: ARUCODetector};
54 - },
55 - [
56 - {name:"deps/cv/index", exports:"CV"},
57 - {name:"deps/aruco/index",exports:"AR"}
58 - ]
59 ); 53 );
54 +
55 +export default {ARUCODetector: ARUCODetector};
......
1 -arcs_module(
2 - function(ARCS, three) {
3 - var ARViewer;
4 1
5 - /** 2 +import ARCS from '../build/arcs.js';
3 +import * as THREE from '../deps/three.js/index.js';
4 +import FrustumCamera from '../deps/three.js/frustumcamera.js';
5 +
6 +var ARViewer;
7 +
8 +/**
6 * @class ARViewer 9 * @class ARViewer
7 * @classdesc Simple compositing viewer for augmented reality 10 * @classdesc Simple compositing viewer for augmented reality
8 */ 11 */
9 - ARViewer = ARCS.Component.create( 12 +ARViewer = ARCS.Component.create(
10 /** @lends ARViewer.prototype */ 13 /** @lends ARViewer.prototype */
11 function () { 14 function () {
12 var container, sourceAspectRatio, sourceHeight; 15 var container, sourceAspectRatio, sourceHeight;
...@@ -131,6 +134,7 @@ arcs_module( ...@@ -131,6 +134,7 @@ arcs_module(
131 // put here the code to set orientation and position of object camera3d 134 // put here the code to set orientation and position of object camera3d
132 // see also documentation of Object3D (API Three.js) 135 // see also documentation of Object3D (API Three.js)
133 // since a camera is an Object3D 136 // since a camera is an Object3D
137 + console.log("viewing");
134 138
135 var rotation = markers[i].pose.rotation; 139 var rotation = markers[i].pose.rotation;
136 var translation = markers[i].pose.position; 140 var translation = markers[i].pose.position;
...@@ -281,7 +285,9 @@ arcs_module( ...@@ -281,7 +285,9 @@ arcs_module(
281 var box = new THREE.Box3(); 285 var box = new THREE.Box3();
282 box.setFromObject(scene3d); 286 box.setFromObject(scene3d);
283 var center = box.center(); 287 var center = box.center();
284 - var radius = box.getBoundingSphere().radius; 288 + var sphere = new THREE.Sphere();
289 + box.getBoundingSphere(sphere);
290 + var radius = sphere.radius;
285 291
286 camera3d.position.x = center.x ; 292 camera3d.position.x = center.x ;
287 camera3d.position.y = center.y ; 293 camera3d.position.y = center.y ;
...@@ -302,6 +308,10 @@ arcs_module( ...@@ -302,6 +308,10 @@ arcs_module(
302 } 308 }
303 309
304 }, 310 },
311 +<<<<<<< HEAD
312 + [ 'deps/three.js/index','deps/three.js/frustumcamera']
313 +);
314 +=======
305 /** @lends ARViewer.slots */ 315 /** @lends ARViewer.slots */
306 [ 316 [
307 'setWidgets','setFocal','viewAll','setSize','addScene', 317 'setWidgets','setFocal','viewAll','setSize','addScene',
...@@ -310,8 +320,8 @@ arcs_module( ...@@ -310,8 +320,8 @@ arcs_module(
310 320
311 ], 321 ],
312 [] 322 []
313 - );
314 - return {ARViewer: ARViewer};
315 - },
316 - [ 'deps/three.js/index','deps/three.js/frustumcamera']
317 ); 323 );
324 +
325 +export default {ARViewer: ARViewer};
326 +
327 +>>>>>>> modules
......
1 /* ugly hack in order to display data in web page instead of console */ 1 /* ugly hack in order to display data in web page instead of console */
2 +import ARCS from '../build/arcs.js';
2 3
3 - 4 +var Console;
4 -arcs_module( 5 +/**
5 - function(ARCS) {
6 - var Console;
7 - /**
8 * @class Console 6 * @class Console
9 * @classdesc Redirects console messages to a given HTML element in the page. 7 * @classdesc Redirects console messages to a given HTML element in the page.
10 * @param id {string} id of the HTML element in which console messages will be added. 8 * @param id {string} id of the HTML element in which console messages will be added.
11 */ 9 */
12 - Console = ARCS.Component.create( 10 +Console = ARCS.Component.create(
13 function (id) { 11 function (id) {
14 if (id === undefined) { 12 if (id === undefined) {
15 return ; 13 return ;
...@@ -26,7 +24,7 @@ arcs_module( ...@@ -26,7 +24,7 @@ arcs_module(
26 s.style.color=color; 24 s.style.color=color;
27 var elapsed = (new Date().getTime() - this.timeRef); 25 var elapsed = (new Date().getTime() - this.timeRef);
28 26
29 - s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span>' + Array.prototype.join.call(args, ' '); 27 + s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span> ' + Array.prototype.join.call(args, ' ');
30 output.appendChild(s); 28 output.appendChild(s);
31 output.appendChild(document.createElement("br")); 29 output.appendChild(document.createElement("br"));
32 }, 30 },
...@@ -42,8 +40,7 @@ arcs_module( ...@@ -42,8 +40,7 @@ arcs_module(
42 }; 40 };
43 } 41 }
44 } 42 }
45 - );
46 - return { Console: Console};
47 - }
48 -
49 ); 43 );
44 +
45 +
46 +export default { Console: Console};
......
...@@ -5,16 +5,14 @@ ...@@ -5,16 +5,14 @@
5 * @file 5 * @file
6 */ 6 */
7 7
8 -arcs_module(function (ARCS) { 8 +import ARCS from '../build/arcs.js';
9 - var Loop, DisplayInt, Sum; 9 +
10 - /** @exports loop */ 10 +/**
11 - //console.log("loop: ", ARCS);
12 - /**
13 * @class Loop 11 * @class Loop
14 * @classdesc loop component creation using a compact style. 12 * @classdesc loop component creation using a compact style.
15 * This component iterates for a given number of times 13 * This component iterates for a given number of times
16 */ 14 */
17 - Loop = ARCS.Component.create( 15 +var Loop = ARCS.Component.create(
18 function () { 16 function () {
19 /** 17 /**
20 * Sets the number of times the component should iterate. 18 * Sets the number of times the component should iterate.
...@@ -49,17 +47,17 @@ arcs_module(function (ARCS) { ...@@ -49,17 +47,17 @@ arcs_module(function (ARCS) {
49 }, 47 },
50 "setIterations", //slotList 48 "setIterations", //slotList
51 ["endLoop", "newIteration"] // signalList 49 ["endLoop", "newIteration"] // signalList
52 - ); 50 +);
53 51
54 52
55 - /** 53 +/**
56 * @class DisplayInt 54 * @class DisplayInt
57 * @classdesc displayInt component creation using a variation with defined slots 55 * @classdesc displayInt component creation using a variation with defined slots
58 * in the constructor (a slot is a function). DisplayInt will display an integer 56 * in the constructor (a slot is a function). DisplayInt will display an integer
59 * received on its display slot. 57 * received on its display slot.
60 */ 58 */
61 - DisplayInt = function () { 59 +var DisplayInt = function () {
62 - /** 60 +/**
63 * @param n {numeric} number to display 61 * @param n {numeric} number to display
64 * @function DisplayInt#display 62 * @function DisplayInt#display
65 * @slot 63 * @slot
...@@ -67,40 +65,39 @@ arcs_module(function (ARCS) { ...@@ -67,40 +65,39 @@ arcs_module(function (ARCS) {
67 this.display = function (n) { 65 this.display = function (n) {
68 console.log(" DisplayInt : " + n); 66 console.log(" DisplayInt : " + n);
69 }; 67 };
70 - }; 68 +};
71 69
72 - ARCS.Component.create(DisplayInt); 70 +ARCS.Component.create(DisplayInt);
73 - DisplayInt.slot("display"); 71 +DisplayInt.slot("display");
74 72
75 73
76 - /** 74 +/**
77 * @class Sum 75 * @class Sum
78 * @classdec Sum is a component summing integers passed to its slot "add" 76 * @classdec Sum is a component summing integers passed to its slot "add"
79 * and the result is sent back by signal "sum". 77 * and the result is sent back by signal "sum".
80 * This component is declared in two different phases: declaration of the 78 * This component is declared in two different phases: declaration of the
81 * constructor and declaration of the slot "add". 79 * constructor and declaration of the slot "add".
82 */ 80 */
83 - Sum = function () { 81 +var Sum = function () {
84 this.total = 0; 82 this.total = 0;
85 - }; 83 +};
86 84
87 - ARCS.Component.create(Sum); 85 +ARCS.Component.create(Sum);
88 - /** 86 +/**
89 * This slot adds its parameter to its internal sum and send it back by using 87 * This slot adds its parameter to its internal sum and send it back by using
90 * the signal "sum". 88 * the signal "sum".
91 * @param n {integer} add n to the internal sum of the component. 89 * @param n {integer} add n to the internal sum of the component.
92 * @function Sum#add 90 * @function Sum#add
93 * @slot 91 * @slot
94 */ 92 */
95 - Sum.slot("add", function (n) { 93 +Sum.slot("add", function (n) {
96 this.total = this.total + n; 94 this.total = this.total + n;
97 this.emit("sum", this.total); //console.log(" Total : " + this.total); 95 this.emit("sum", this.total); //console.log(" Total : " + this.total);
98 - }); 96 +});
99 - Sum.signal("sum"); 97 +Sum.signal("sum");
100 98
101 - // the anonymous function must return the components in one object: 99 +// the anonymous function must return the components in one object:
102 - // keys are factory names, value are actual constructors modified by 100 +// keys are factory names, value are actual constructors modified by
103 - // ARCS.Component.create 101 +// ARCS.Component.create
104 102
105 - return {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum}; 103 +export default {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum};
106 -});
......
1 +import ARCS from '../build/arcs.js';
2 +import POS from '../deps/pose/square_pose.js';
1 3
4 +var MarkerLocator;
2 5
3 -arcs_module(
4 - function (ARCS, POS) {
5 - var MarkerLocator;
6 6
7 - 7 +MarkerLocator = ARCS.Component.create(
8 - MarkerLocator = ARCS.Component.create(
9 function () { 8 function () {
10 var square_pose = new POS.SquareFiducial(); 9 var square_pose = new POS.SquareFiducial();
11 10
...@@ -44,10 +43,7 @@ arcs_module( ...@@ -44,10 +43,7 @@ arcs_module(
44 }, 43 },
45 ['locateMarkers','setFocalLength','setModelSize','setImageSource'], 44 ['locateMarkers','setFocalLength','setModelSize','setImageSource'],
46 ['onLocatedMarkers'] 45 ['onLocatedMarkers']
47 - ); 46 +);
48 47
49 48
50 - return { MarkerLocator: MarkerLocator };
51 - },
52 - [ {name: "deps/pose/square_pose", exports: "POS"} ]
53 -);
...\ No newline at end of file ...\ No newline at end of file
49 +export default { MarkerLocator: MarkerLocator };
......
1 -arcs_module( 1 +import ARCS from '../build/arcs.js';
2 - function(ARCS,_three) { 2 +import * as THREE from '../deps/three.js/index.js';
3 - var ObjectTransform ;
4 3
5 - /** 4 +var ObjectTransform ;
5 +
6 +/**
6 * @class ObjectTransform 7 * @class ObjectTransform
7 * @classdesc Apply transformations to objects 8 * @classdesc Apply transformations to objects
8 */ 9 */
9 - ObjectTransform = ARCS.Component.create( 10 +ObjectTransform = ARCS.Component.create(
10 function() { 11 function() {
11 var objRoot; 12 var objRoot;
12 var refMat; 13 var refMat;
...@@ -115,11 +116,6 @@ arcs_module( ...@@ -115,11 +116,6 @@ arcs_module(
115 }, 116 },
116 ['setObject', 'setTransform', 'setId'], 117 ['setObject', 'setTransform', 'setId'],
117 [] 118 []
118 - );
119 -
120 -
121 -
122 - return { ObjectTransform : ObjectTransform };
123 - },
124 - [ "deps/three.js/index" ]
125 ); 119 );
120 +
121 +export default { ObjectTransform : ObjectTransform };
......
1 -arcs_module( 1 +import ARCS from '../build/arcs.js';
2 - function(ARCS, three, _objloader, _mtlloader, _objmtlloader) { 2 +import * as THREE from '../deps/three.js/index.js';
3 - var OBJLoader; 3 +import { OBJLoader } from '../deps/objloader/objloader.js';
4 +import { MTLLoader } from '../deps/mtlloader/mtlloader.js';
5 +//import { DDSLoader } from '../deps/ddsloader/ddsloader.js';
4 6
5 7
6 - OBJLoader = ARCS.Component.create( 8 +var internalOBJLoader;
9 +
10 +
11 +internalOBJLoader = ARCS.Component.create(
7 function() { 12 function() {
8 var self = this; 13 var self = this;
9 var innerObject; 14 var innerObject;
...@@ -34,23 +39,31 @@ arcs_module( ...@@ -34,23 +39,31 @@ arcs_module(
34 // we may use a string tokenizer to determine file types 39 // we may use a string tokenizer to determine file types
35 // then all would be in the same loading slot. 40 // then all would be in the same loading slot.
36 41
42 + //console.log("loading objects", objURL, mtlURL);
43 + var manager = new THREE.LoadingManager();
44 + //manager.addHandler( /\.dds$/i, new DDSLoader() );
37 45
38 - console.log("loading objects", objURL, mtlURL);
39 if (mtlURL === undefined) { 46 if (mtlURL === undefined) {
40 //console.log("using loader"); 47 //console.log("using loader");
41 - loader = new THREE.OBJLoader(); 48 + loader = new OBJLoader(manager);
42 loader.load(objURL, onLoadWrapper, progress, error); 49 loader.load(objURL, onLoadWrapper, progress, error);
43 } else { 50 } else {
44 //console.log("using mtl loader"); 51 //console.log("using mtl loader");
45 - loader = new THREE.OBJMTLLoader(); 52 + loader = new MTLLoader(manager);
46 - loader.load(objURL, mtlURL, onLoadWrapper, progress, error); 53 + loader.load(mtlURL, function(materials) {
54 + materials.preload();
55 + console.log(materials);
56 + new OBJLoader(manager)
57 + .setMaterials(materials)
58 + .load(objURL, onLoadWrapper, progress, error);
59 + }, progress, error);
47 } 60 }
48 }; 61 };
49 62
50 this.loadJSON = function(jsonURL) { 63 this.loadJSON = function(jsonURL) {
51 var loader; 64 var loader;
52 //console.log("loading objects", jsonURL); 65 //console.log("loading objects", jsonURL);
53 - loader = new THREE.JSONLoader(); 66 + loader = new THREE.ObjectLoader();
54 loader.load(jsonURL, onLoadJSON); //, progress, error); 67 loader.load(jsonURL, onLoadJSON); //, progress, error);
55 68
56 69
...@@ -93,9 +106,6 @@ arcs_module( ...@@ -93,9 +106,6 @@ arcs_module(
93 }, 106 },
94 ["load","unitize", "resize"], 107 ["load","unitize", "resize"],
95 ["onLoad"] 108 ["onLoad"]
96 - );
97 -
98 - return { OBJLoader: OBJLoader};
99 - },
100 - [ 'deps/three.js/index', 'deps/objloader/index', 'deps/mtlloader/index','deps/objmtlloader/index' ]
101 ); 109 );
110 +
111 +export default { OBJLoader: internalOBJLoader};
......
1 +{ "type": "module"}
1 -arcs_module(function(ARCS) { 1 +import ARCS from '../build/arcs.js';
2 - var TokenSender;
3 2
4 - TokenSender = ARCS.Component.create( 3 +var TokenSender;
4 +
5 +TokenSender = ARCS.Component.create(
5 function( arr ) { 6 function( arr ) {
6 var i; 7 var i;
7 var self = this; 8 var self = this;
...@@ -20,7 +21,6 @@ arcs_module(function(ARCS) { ...@@ -20,7 +21,6 @@ arcs_module(function(ARCS) {
20 }, 21 },
21 [], 22 [],
22 ['sendToken'] 23 ['sendToken']
23 - ); 24 +);
24 25
25 - return { TokenSender : TokenSender };
26 -});
...\ No newline at end of file ...\ No newline at end of file
26 +export default { TokenSender : TokenSender };
......
1 -arcs_module(function(ARCS) { 1 +import ARCS from '../build/arcs.js';
2 - var LiveSource, VideoSource; 2 +
3 - LiveSource = ARCS.Component.create( 3 +var LiveSource, VideoSource;
4 +LiveSource = ARCS.Component.create(
4 function () { 5 function () {
5 var context, canvas, video, imageData; 6 var context, canvas, video, imageData;
6 var defaultWidth = 320; 7 var defaultWidth = 320;
...@@ -8,6 +9,7 @@ arcs_module(function(ARCS) { ...@@ -8,6 +9,7 @@ arcs_module(function(ARCS) {
8 var self = this; 9 var self = this;
9 10
10 var handleMediaStream = function(stream) { 11 var handleMediaStream = function(stream) {
12 + console.log(video,stream);
11 if (window.webkitURL) { 13 if (window.webkitURL) {
12 video.src = window.webkitURL.createObjectURL(stream); 14 video.src = window.webkitURL.createObjectURL(stream);
13 } else if (video.mozSrcObject !== undefined) { 15 } else if (video.mozSrcObject !== undefined) {
...@@ -17,8 +19,8 @@ arcs_module(function(ARCS) { ...@@ -17,8 +19,8 @@ arcs_module(function(ARCS) {
17 } else { 19 } else {
18 video.src = stream; 20 video.src = stream;
19 } 21 }
20 - video.videoWidth=defaultWidth; 22 + /*video.videoWidth=defaultWidth;
21 - video.videoHeight=defaultHeight; 23 + video.videoHeight=defaultHeight;*/
22 self.emit("onReady"); 24 self.emit("onReady");
23 }; 25 };
24 26
...@@ -27,18 +29,13 @@ arcs_module(function(ARCS) { ...@@ -27,18 +29,13 @@ arcs_module(function(ARCS) {
27 }; 29 };
28 30
29 var setUserMedia = function() { 31 var setUserMedia = function() {
30 - console.log("video test");
31 if (navigator.mediaDevices !== undefined) { 32 if (navigator.mediaDevices !== undefined) {
32 - navigator.mediaDevices.getUserMedia({video:{facingMode : "environment"}}) 33 + navigator.mediaDevices.getUserMedia({video: {facingMode: "environment", width: defaultWidth, height: defaultHeight}})
33 .then(handleMediaStream) 34 .then(handleMediaStream)
34 .catch(errorMediaStream); 35 .catch(errorMediaStream);
35 } else { 36 } else {
36 var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; 37 var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
37 if (getUserMedia !== undefined) { 38 if (getUserMedia !== undefined) {
38 - console.log(getUserMedia(), handleMediaStream, errorMediaStream);
39 - /*getUserMedia({video:true}, handleMediaStream,
40 - errorMediaStream
41 - );*/
42 getUserMedia({video:true}).then(handleMediaStream); 39 getUserMedia({video:true}).then(handleMediaStream);
43 } 40 }
44 } 41 }
...@@ -75,10 +72,10 @@ arcs_module(function(ARCS) { ...@@ -75,10 +72,10 @@ arcs_module(function(ARCS) {
75 }, 72 },
76 ['grabFrame','setWidgets'], 73 ['grabFrame','setWidgets'],
77 ['onReady','onImage'] 74 ['onReady','onImage']
78 - ); 75 +);
79 76
80 77
81 - VideoSource = ARCS.Component.create( 78 +VideoSource = ARCS.Component.create(
82 function() { 79 function() {
83 var context, canvas, video, imageData; 80 var context, canvas, video, imageData;
84 var defaultWidth=320; 81 var defaultWidth=320;
...@@ -124,8 +121,6 @@ arcs_module(function(ARCS) { ...@@ -124,8 +121,6 @@ arcs_module(function(ARCS) {
124 }, 121 },
125 ['grabFrame', 'setWidgets'], 122 ['grabFrame', 'setWidgets'],
126 ['onReady', 'onImage'] 123 ['onReady', 'onImage']
127 - ); 124 +);
128 -
129 125
130 - return {LiveSource: LiveSource, VideoSource: VideoSource}; 126 +export default {LiveSource: LiveSource, VideoSource: VideoSource};
131 -});
......
1 -arcs_module( 1 +import ARCS from '../build/arcs.js';
2 - function (ARCS) {
3 - var WindowEvent;
4 2
5 - WindowEvent = ARCS.Component.create( 3 +let WindowEvent;
4 +
5 +WindowEvent = ARCS.Component.create(
6 function () { 6 function () {
7 - var self= this; 7 + let self= this;
8 8
9 window.onresize = function() { 9 window.onresize = function() {
10 self.emit("onResize",window.innerWidth, window.innerHeight); 10 self.emit("onResize",window.innerWidth, window.innerHeight);
...@@ -12,8 +12,7 @@ arcs_module( ...@@ -12,8 +12,7 @@ arcs_module(
12 }, 12 },
13 [], 13 [],
14 ["onResize"] 14 ["onResize"]
15 - );
16 -
17 - return { WindowEvent: WindowEvent};
18 - }
19 ); 15 );
16 +
17 +
18 +export default { WindowEvent: WindowEvent};
......
...@@ -493,3 +493,5 @@ Mat3.prototype.row = function(index){ ...@@ -493,3 +493,5 @@ Mat3.prototype.row = function(index){
493 493
494 return new Vec3( m[index][0], m[index][1], m[index][2] ); 494 return new Vec3( m[index][0], m[index][1], m[index][2] );
495 }; 495 };
496 +
497 +export default POS;
......
...@@ -529,3 +529,5 @@ POS.Pose = function(error1, rotation1, translation1, error2, rotation2, translat ...@@ -529,3 +529,5 @@ POS.Pose = function(error1, rotation1, translation1, error2, rotation2, translat
529 this.alternativeRotation = rotation2; 529 this.alternativeRotation = rotation2;
530 this.alternativeTranslation = translation2; 530 this.alternativeTranslation = translation2;
531 }; 531 };
532 +
533 +export default POS;
......
...@@ -130,3 +130,5 @@ POS.SimplePose = function(pos, rot) { ...@@ -130,3 +130,5 @@ POS.SimplePose = function(pos, rot) {
130 this.position = pos; 130 this.position = pos;
131 this.rotation = rot; 131 this.rotation = rot;
132 }; 132 };
133 +
134 +export default POS;
......
...@@ -281,3 +281,5 @@ SVD.pythag = function(a, b){ ...@@ -281,3 +281,5 @@ SVD.pythag = function(a, b){
281 SVD.sign = function(a, b){ 281 SVD.sign = function(a, b){
282 return b >= 0.0? Math.abs(a): -Math.abs(a); 282 return b >= 0.0? Math.abs(a): -Math.abs(a);
283 }; 283 };
284 +
285 +export default SVD;
......
1 -arcs_module(function(ARCS) { 1 +import * as THREE from './index.js';
2 -THREE.FrustumCamera = function ( left, right, bottom, top, near, far ) { 2 +
3 +let FrustumCamera = function ( left, right, bottom, top, near, far ) {
3 4
4 THREE.Camera.call( this ); 5 THREE.Camera.call( this );
5 6
...@@ -17,22 +18,22 @@ THREE.FrustumCamera = function ( left, right, bottom, top, near, far ) { ...@@ -17,22 +18,22 @@ THREE.FrustumCamera = function ( left, right, bottom, top, near, far ) {
17 18
18 }; 19 };
19 20
20 -THREE.FrustumCamera.prototype = Object.create( THREE.Camera.prototype ); 21 +FrustumCamera.prototype = Object.create( THREE.Camera.prototype );
21 -THREE.FrustumCamera.prototype.constructor = THREE.FrustumCamera; 22 +FrustumCamera.prototype.constructor = FrustumCamera;
22 23
23 24
24 25
25 26
26 -THREE.FrustumCamera.prototype.updateProjectionMatrix = function () { 27 +FrustumCamera.prototype.updateProjectionMatrix = function () {
27 28
28 this.projectionMatrix.makeFrustum( 29 this.projectionMatrix.makeFrustum(
29 this.left, this.right, this.bottom, this.top, this.near, this.far 30 this.left, this.right, this.bottom, this.top, this.near, this.far
30 ); 31 );
31 }; 32 };
32 33
33 -THREE.FrustumCamera.prototype.clone = function () { 34 +FrustumCamera.prototype.clone = function () {
34 35
35 - var camera = new THREE.FrustumCamera(); 36 + var camera = new FrustumCamera();
36 37
37 THREE.Camera.prototype.clone.call( this, camera ); 38 THREE.Camera.prototype.clone.call( this, camera );
38 39
...@@ -51,6 +52,4 @@ THREE.FrustumCamera.prototype.clone = function () { ...@@ -51,6 +52,4 @@ THREE.FrustumCamera.prototype.clone = function () {
51 52
52 }; 53 };
53 54
54 -return {}; 55 +export default FrustumCamera;
55 -}, ['deps/three.js/index']
56 -);
......
...@@ -11,14 +11,17 @@ ...@@ -11,14 +11,17 @@
11 "Reality" 11 "Reality"
12 ], 12 ],
13 "author": "Jean-Yves Didier", 13 "author": "Jean-Yves Didier",
14 - "license": "GPL", 14 + "license": "GPL-3.0-or-later",
15 "devDependencies": { 15 "devDependencies": {
16 "bower": ">=1.3.9", 16 "bower": ">=1.3.9",
17 "grunt": ">=0.4.5", 17 "grunt": ">=0.4.5",
18 "grunt-jslint": ">=1.1.12", 18 "grunt-jslint": ">=1.1.12",
19 - "grunt-contrib-uglify": ">=0.5.1", 19 + "grunt-terser": "*",
20 "grunt-jsdoc": ">=0.5.6", 20 "grunt-jsdoc": ">=0.5.6",
21 "grunt-bower-task": ">=0.4.0", 21 "grunt-bower-task": ">=0.4.0",
22 - "grunt-contrib-concat": ">=0.5.0" 22 + "grunt-contrib-concat": ">=0.5.0",
23 + "grunt-contrib-copy": ">=1.0.0",
24 + "grunt-file-append": ">=0.0.7",
25 + "grunt-string-replace": ">=1.3.1"
23 } 26 }
24 } 27 }
......
...@@ -199,7 +199,7 @@ ARCS.Application = function () { ...@@ -199,7 +199,7 @@ ARCS.Application = function () {
199 * Starts the application 199 * Starts the application
200 */ 200 */
201 this.start = function () { 201 this.start = function () {
202 - console.log("[ARCS] Starting application"); 202 + console.log("[ARCS] Starting application...");
203 context.instanciate().then(preProcess); 203 context.instanciate().then(preProcess);
204 }; 204 };
205 }; 205 };
......
...@@ -22,7 +22,6 @@ var ARCS = ARCS || {}; ...@@ -22,7 +22,6 @@ var ARCS = ARCS || {};
22 * Helper functions to determine environment 22 * Helper functions to determine environment
23 * ***************************************************************************/ 23 * ***************************************************************************/
24 24
25 -
26 /** 25 /**
27 * @return {boolean} true if ARCS is run in a node.js environment 26 * @return {boolean} true if ARCS is run in a node.js environment
28 */ 27 */
...@@ -31,10 +30,3 @@ ARCS.isInNode = function () { ...@@ -31,10 +30,3 @@ ARCS.isInNode = function () {
31 }; 30 };
32 31
33 32
34 -/**
35 - * @return {boolean} true if ARCS is run with require.js
36 - */
37 -ARCS.isInRequire = function () {
38 - return (typeof define === 'function' && define.amd);
39 -};
40 -
......
...@@ -6,43 +6,31 @@ import ARCS from './arcs.js'; ...@@ -6,43 +6,31 @@ import ARCS from './arcs.js';
6 * It relies on require.js to get the job done. 6 * It relies on require.js to get the job done.
7 * @file 7 * @file
8 */ 8 */
9 +"use strict";
10 +
11 +// basically, here we start by importing the module ARCS
12 +import ARCS from './arcs.js';
9 13
10 -console.log("Bootstrapping ARCS..."); 14 +
15 +console.log("[ARCS] Bootstrapping...");
11 16
12 var baseUrl, appDescription, requireMarkup, xhr; 17 var baseUrl, appDescription, requireMarkup, xhr;
13 18
14 -requireMarkup = document.querySelector('[data-main]'); 19 +requireMarkup = document.querySelector('[data-arcsapp]');
15 if (requireMarkup !== undefined) { 20 if (requireMarkup !== undefined) {
16 baseUrl = requireMarkup.dataset.baseUrl ; 21 baseUrl = requireMarkup.dataset.baseUrl ;
17 appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json"; 22 appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json";
18 } 23 }
19 24
20 -// do not move these lines: xhr.open must be performed before require 25 +
21 -// changes paths. 26 +(async function toto() {
22 -xhr = new XMLHttpRequest(); 27 +var description = await(fetch(appDescription));
23 -xhr.open('GET',appDescription,true); 28 +var applicationObject = await(description.json());
24 -xhr.overrideMimeType("application/json"); 29 +
25 -xhr.onerror = function (e) { 30 +
26 - console.error("[ARCS] Failed to get app description (",appDescription,"):",e.target.status,e.message); 31 +console.log("[ARCS] Application description loaded");
27 -}; 32 +
28 - 33 +var aap = new ARCS.Application();
29 -xhr.onreadystatechange = function() { 34 +aap.import(applicationObject);
30 - if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { 35 +aap.start();
31 - try { 36 +})();
32 - console.log("ARCS application description loaded");
33 - var applicationObject = JSON.parse(xhr.responseText);
34 - if (baseUrl) {
35 - // TODO change this line below
36 - require.config( { baseUrl: baseUrl });
37 - }
38 - var aap = new ARCS.Application();
39 - aap.import(applicationObject);
40 - console.log("Starting application...");
41 - aap.start();
42 - } catch (e) {
43 - console.error("[ARCS] Error while parsing JSON:",e);
44 - }
45 - }
46 -};
47 -
48 -xhr.send();
......
1 -/**
2 - * definition of the main module function:
3 - * it takes an anonymous function as a parameter
4 - * the anonymous function has one parameter: the object encompassing
5 - * ARCS definitions (in order to able to use ARCS.Component.create, ...)
6 - * @param moduleDefinition {function} main function of the module.
7 - * It should return a list of components
8 - * @param deps {mixed[]} dependencies
9 - */
10 -
11 -// TODO remove dependency handling
12 -
13 -
14 -// reimplementation using native promises
15 -arcs_module = function(moduleDefinition) {
16 - var storeComponents, i;
17 -
18 - // TODO verify if this is still needed
19 - if (typeof module !== 'undefined') {
20 - if (module.parent.exports) {
21 - ARCS = module.exports;
22 - }
23 - }
24 -
25 -
26 - storeComponents = function () {
27 - var mdef, p;
28 - // we should insert ARCS at the beginning of deps !
29 -
30 - mdef = (typeof moduleDefinition === 'function') ?
31 - moduleDefinition.apply(this) : moduleDefinition;
32 -
33 - if (mdef === undefined) {
34 - throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition);
35 - }
36 -
37 - for (p in mdef) {
38 - if (mdef.hasOwnProperty(p) && ARCS.Context.currentContext != null) {
39 - ARCS.Context.currentContext.setFactory(p,mdef[p]); //.setFactory(ARCS.Application.currentApplication, p, mdef[p]);
40 - }
41 - }
42 -
43 - return Promise.resolve();
44 - };
45 - // until now, it is the very same code.
46 -
47 -
48 - ARCS.Context.currentContext.addLibraryPromise(
49 - storeComponents,
50 - function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); })
51 -
52 - );
53 -
54 -}
1 -#!/usr/bin/env node
2 -
3 -var ARCS = require('./arcs.js');
4 -var application = require('./appli.json');
5 -var aap = new ARCS.Application();
6 -aap.import(application);
7 -aap.start();
1 +#!/usr/bin/env -S node --experimental-modules --experimental-json-modules
2 +
3 +import ARCS from './arcs.js';
4 +import process from 'process';
5 +import path from 'path';
6 +import fs from 'fs';
7 +//import application from './appli.json';
8 +
9 +function usage() {
10 + let sp = process.argv[1].lastIndexOf(path.delimiter);
11 + console.log("usage:");
12 + console.log("\t",
13 + process.argv[1],
14 + "description.json"
15 + );
16 +}
17 +
18 +if (process.argv.length < 3) {
19 + usage();
20 + process.exit(1);
21 +}
22 +
23 +
24 +var appDescription = fs.readFileSync(process.argv[2]);
25 +if (appDescription === '') {
26 + console.error("File '"+process.argv[2]+"' is empty.");
27 + process.exit(2);
28 +}
29 +
30 +var application = JSON.parse(appDescription);
31 +
32 +var aap = new ARCS.Application();
33 +aap.import(application);
34 +aap.start();
...@@ -9,7 +9,7 @@ ARCS.Context = function( ctx ) { ...@@ -9,7 +9,7 @@ ARCS.Context = function( ctx ) {
9 var constants = {}; 9 var constants = {};
10 var factories = {}; 10 var factories = {};
11 var libraries = []; 11 var libraries = [];
12 - var depLibPromises=[]; 12 + //var depLibPromises=[];
13 var self = this; 13 var self = this;
14 var loadLibraries; 14 var loadLibraries;
15 var loadDataFile; 15 var loadDataFile;
...@@ -23,6 +23,7 @@ ARCS.Context = function( ctx ) { ...@@ -23,6 +23,7 @@ ARCS.Context = function( ctx ) {
23 if (ctx !== undefined) { 23 if (ctx !== undefined) {
24 libraries = ctx.libraries; 24 libraries = ctx.libraries;
25 25
26 + var p;
26 for (p in ctx.components) { 27 for (p in ctx.components) {
27 if (ctx.components.hasOwnProperty(p)) { 28 if (ctx.components.hasOwnProperty(p)) {
28 components[p] = ctx.components[p]; 29 components[p] = ctx.components[p];
...@@ -39,8 +40,7 @@ ARCS.Context = function( ctx ) { ...@@ -39,8 +40,7 @@ ARCS.Context = function( ctx ) {
39 40
40 } 41 }
41 42
42 - 43 + var loadDataFile =async function(fileName) {
43 - loadDataFile = function(fileName) {
44 var dataPromise ; 44 var dataPromise ;
45 45
46 if (ARCS.isInNode()) { 46 if (ARCS.isInNode()) {
...@@ -53,59 +53,12 @@ ARCS.Context = function( ctx ) { ...@@ -53,59 +53,12 @@ ARCS.Context = function( ctx ) {
53 } 53 }
54 }); 54 });
55 } else { 55 } else {
56 - return new Promise(function(resolve, reject) { 56 + var client = await fetch(fileName);
57 - var client = new XMLHttpRequest(); 57 + return client.json();
58 - client.open('GET',fileName,true);
59 - client.overrideMimeType("application/json");
60 - client.send();
61 -
62 - client.onload = function() {
63 - if (this.status >= 200 && this.status < 300) {
64 - resolve(JSON.parse(this.responseText));
65 - } else {
66 - console.error(this.statusText);
67 - reject(this.statusText);
68 } 58 }
69 }; 59 };
70 - client.onerror = function() {
71 - console.error(this.statusText);
72 - reject(this.statusText);
73 - };
74 - });
75 - }
76 - };
77 -
78 - this.addLibraryPromise = function(p) {
79 - depLibPromises.push(p);
80 - };
81 -
82 - promiseLibrary = function(libName) {
83 - return new Promise(function(resolve, reject) {
84 - if (libName.substr(-3) === '.js') {
85 - reject(libName);
86 - }
87 60
88 - if (ARCS.isInNode()) { 61 + var loadLibraries = function () {
89 - if (require("./" + libraries[i] + ".js") === undefined) {
90 - reject(libName);
91 - } else {
92 - resolve();
93 - }
94 - } else {
95 - require([libName],
96 - function() {
97 - resolve();
98 - },
99 - function(err) {
100 - reject(libName,err);
101 -
102 - }
103 - );
104 - }
105 - });
106 - };
107 -
108 - loadLibraries = function () {
109 var i; 62 var i;
110 // we will use different instances of require either the one of node 63 // we will use different instances of require either the one of node
111 // or the one from require.js 64 // or the one from require.js
...@@ -113,14 +66,13 @@ ARCS.Context = function( ctx ) { ...@@ -113,14 +66,13 @@ ARCS.Context = function( ctx ) {
113 66
114 var res=[]; 67 var res=[];
115 for(i=0; i < libraries.length; i++) { 68 for(i=0; i < libraries.length; i++) {
116 - res.push(promiseLibrary(libraries[i])); 69 + res.push(self.loadLibrary(libraries[i]));
117 } 70 }
118 return Promise.all(res); 71 return Promise.all(res);
119 }; 72 };
120 73
121 - instanciateComponents = function() { 74 + var instanciateComponents = function() {
122 var p, promises=[]; 75 var p, promises=[];
123 - console.log(components);
124 76
125 for (p in components) { 77 for (p in components) {
126 if (components.hasOwnProperty(p)) { 78 if (components.hasOwnProperty(p)) {
...@@ -129,7 +81,7 @@ ARCS.Context = function( ctx ) { ...@@ -129,7 +81,7 @@ ARCS.Context = function( ctx ) {
129 console.error("[ARCS] Context dump follows: ", libraries, components, constants); 81 console.error("[ARCS] Context dump follows: ", libraries, components, constants);
130 return ; 82 return ;
131 } 83 }
132 - factory = factories[components[p].type]; 84 + var factory = factories[components[p].type];
133 //console.log("instanciating ", p); 85 //console.log("instanciating ", p);
134 try { 86 try {
135 if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { 87 if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) {
...@@ -140,11 +92,12 @@ ARCS.Context = function( ctx ) { ...@@ -140,11 +92,12 @@ ARCS.Context = function( ctx ) {
140 // we need currying here ! 92 // we need currying here !
141 var delayInstanciation = function(p,factory) { 93 var delayInstanciation = function(p,factory) {
142 return function(obj) { 94 return function(obj) {
95 + console.log("instanciating from data file");
143 components[p].instance = new factory(obj); 96 components[p].instance = new factory(obj);
144 return Promise.resolve(); 97 return Promise.resolve();
145 } 98 }
146 }; 99 };
147 - 100 + console.log("loading data file", components[p].url);
148 promises.push( 101 promises.push(
149 loadDataFile(components[p].url).then(delayInstanciation(p,factory)) 102 loadDataFile(components[p].url).then(delayInstanciation(p,factory))
150 ); 103 );
...@@ -178,12 +131,22 @@ ARCS.Context = function( ctx ) { ...@@ -178,12 +131,22 @@ ARCS.Context = function( ctx ) {
178 libUrl = libName.url; 131 libUrl = libName.url;
179 } 132 }
180 133
134 + if (libraries.indexOf(libActualName) < 0) {
181 libraries.push(libActualName); 135 libraries.push(libActualName);
182 - promiseLibrary(libUrl).then( function() { 136 + }
137 + // TODO promisify call to cbFunction
138 + return import(libUrl).then( function(module) {
139 + // TODO insert here component factories
140 + for (p in module.default) {
141 + if (module.default.hasOwnProperty(p)) {
142 + ARCS.Context.currentContext.setFactory(p,module.default[p]);
143 + }
144 + }
145 +
183 if (cbFunction !== undefined) { 146 if (cbFunction !== undefined) {
184 cbFunction(); 147 cbFunction();
185 } 148 }
186 - }); 149 + }).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) });
187 }; 150 };
188 151
189 /** 152 /**
...@@ -300,9 +263,9 @@ ARCS.Context = function( ctx ) { ...@@ -300,9 +263,9 @@ ARCS.Context = function( ctx ) {
300 263
301 // this should return a promise ! 264 // this should return a promise !
302 this.instanciate = function () { 265 this.instanciate = function () {
303 - return loadLibraries().then(function() { return Promise.all(depLibPromises); }) 266 + //! TODO
304 - .then(instanciateComponents) 267 + return loadLibraries().then(instanciateComponents)
305 - .catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); }); 268 + .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); });
306 269
307 }; 270 };
308 271
......
1 +// no longer needed with the use of imports
1 2
2 -// ARCS is then defined as a node.js module 3 +export { ARCS as default};
3 -if (!ARCS.isInNode()) {
4 - var exports = {};
5 -}
6 -
7 -exports.Component = ARCS.Component;
8 -exports.Connection = ARCS.Connection;
9 -exports.Invocation = ARCS.Invocation;
10 -exports.Statemachine = ARCS.Statemachine;
11 -exports.Sheet = ARCS.Sheet;
12 -exports.Application = ARCS.Application;
13 -exports.EventLogicParser = ARCS.EventLogicParser;
14 -exports.TransitionSystem = ARCS.TransitionSystem;
15 -exports.isInNode = ARCS.isInNode;
16 -exports.isInRequire = ARCS.isInRequire;
17 -
18 -// hack for require.js
19 -// ARCS is then defined as a require.js module.
20 -if (ARCS.isInRequire()) {
21 - //console.log("module ARCS in require.js");
22 - define(exports);
23 -}
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -35,7 +35,7 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) { ...@@ -35,7 +35,7 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
35 } 35 }
36 36
37 res = ARCS.TransitionNetwork.build(tree[0],tokenEvents); 37 res = ARCS.TransitionNetwork.build(tree[0],tokenEvents);
38 - 38 + var i;
39 for (i=1; i < tree.length; i++) { 39 for (i=1; i < tree.length; i++) {
40 if (tree[i].hasOwnProperty('and')) { 40 if (tree[i].hasOwnProperty('and')) {
41 rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents); 41 rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents);
......
1 { 1 {
2 "context": { 2 "context": {
3 "libraries": [ 3 "libraries": [
4 - "components/arviewer","components/animator", 4 + "../components/arviewer.js","../components/animator.js",
5 - "components/objloader","components/video", 5 + "../components/objloader.js","../components/video.js",
6 - "components/arucodetector", "components/markerlocator", 6 + "../components/arucodetector.js", "../components/markerlocator.js",
7 - "components/windowevent", "components/tokensender", "components/objecttransform" 7 + "../components/windowevent.js", "../components/tokensender.js", "../components/objecttransform.js"
8 ], 8 ],
9 "components": { 9 "components": {
10 "viewer": { "type": "ARViewer"}, 10 "viewer": { "type": "ARViewer"},
......
...@@ -2,15 +2,15 @@ ...@@ -2,15 +2,15 @@
2 <head> 2 <head>
3 <title>ARCS: marker experiment</title> 3 <title>ARCS: marker experiment</title>
4 <link type="text/css" rel="stylesheet" href="arcs.css"> 4 <link type="text/css" rel="stylesheet" href="arcs.css">
5 - <script data-main="../../build/arcs_browser" 5 + <script src="../../build/arcs_browser.js"
6 data-base-url="../.." 6 data-base-url="../.."
7 data-arcsapp="arcsapp.json" 7 data-arcsapp="arcsapp.json"
8 - src="../../deps/requirejs/require.js"> 8 + type="module">
9 </script> 9 </script>
10 <meta charset="UTF-8"> 10 <meta charset="UTF-8">
11 </head> 11 </head>
12 <body> 12 <body>
13 - <video id="video" width=320 height=240 autoplay="true" style="display: none;"></video> 13 + <video id="video" width=640 height=480 autoplay="true" style="display: none;"></video>
14 <canvas id="canvas"></canvas> 14 <canvas id="canvas"></canvas>
15 <div id="container" ></div> 15 <div id="container" ></div>
16 <div id="contents"> 16 <div id="contents">
......
1 { 1 {
2 "context" : { 2 "context" : {
3 - "libraries" : [ "components/loop","components/console"], 3 + "libraries" : [ "../components/loop.js","../components/console.js"],
4 "components" : { 4 "components" : {
5 "loop": { "type": "Loop" }, 5 "loop": { "type": "Loop" },
6 "dint": { "type": "DisplayInt" }, 6 "dint": { "type": "DisplayInt" },
......
1 <html> 1 <html>
2 <head> 2 <head>
3 <title>ARCS engine</title> 3 <title>ARCS engine</title>
4 - <script data-main="../../build/arcs_browser" 4 + <script data-base-url="../.."
5 - data-base-url="../.."
6 data-arcsapp="arcsapp.json" 5 data-arcsapp="arcsapp.json"
7 - src="../../deps/requirejs/require.js"> 6 + type="module"
7 + src="../../build/arcs_browser.js">
8 </script> 8 </script>
9 + <style>
10 + body {
11 + font-family: sans-serif;
12 + }
13 + </style>
9 </head> 14 </head>
10 <body> 15 <body>
11 <h1>ARCS in Web Browser</h1> 16 <h1>ARCS in Web Browser</h1>
12 - <div style="height:100px; overflow: auto; border: solid 1px navy;"> 17 + <div style="height:80vh; overflow: auto; border: solid 1px navy;">
13 - <p id="output" style="margin: 5px; padding: 5px;"></p> 18 + <p id="output" style="margin: 5px; padding: 5px; font-family: monospace;"></p>
14 <div> 19 <div>
15 </body> 20 </body>
16 </html> 21 </html>
......