Showing
36 changed files
with
1179 additions
and
1386 deletions
1 | module.exports = function (grunt) { | 1 | module.exports = function (grunt) { |
2 | "use strict"; | 2 | "use strict"; |
3 | + | ||
4 | + let shim = function(obj) { return `\nexport default ${obj};\n`; }; | ||
3 | 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,7 +82,38 @@ module.exports = function (grunt) { | ... | @@ -74,7 +82,38 @@ module.exports = function (grunt) { |
74 | } | 82 | } |
75 | 83 | ||
76 | }, | 84 | }, |
77 | - concat: { | 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 | + }, | ||
116 | + concat: { | ||
78 | dist: { | 117 | dist: { |
79 | src: [ | 118 | src: [ |
80 | 'src/arcs.js', | 119 | 'src/arcs.js', |
... | @@ -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' |
... | @@ -106,21 +144,24 @@ module.exports = function (grunt) { | ... | @@ -106,21 +144,24 @@ module.exports = function (grunt) { |
106 | dest: 'build/arcseditor.js' | 144 | dest: 'build/arcseditor.js' |
107 | } | 145 | } |
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" : "*", | ... | ... |
... | @@ -22,22 +22,14 @@ var ARCS = ARCS || {}; | ... | @@ -22,22 +22,14 @@ 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 | */ |
29 | ARCS.isInNode = function () { | 28 | ARCS.isInNode = function () { |
30 | - return (typeof require === 'function' && require.resolve); | 29 | + return (typeof require === 'function' && require.resolve); |
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 | - | ||
41 | 33 | ||
42 | /****************************************************************************** | 34 | /****************************************************************************** |
43 | * Component implementation | 35 | * Component implementation |
... | @@ -241,7 +233,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -241,7 +233,7 @@ ARCS.Context = function( ctx ) { |
241 | var constants = {}; | 233 | var constants = {}; |
242 | var factories = {}; | 234 | var factories = {}; |
243 | var libraries = []; | 235 | var libraries = []; |
244 | - var depLibPromises=[]; | 236 | + //var depLibPromises=[]; |
245 | var self = this; | 237 | var self = this; |
246 | var loadLibraries; | 238 | var loadLibraries; |
247 | var loadDataFile; | 239 | var loadDataFile; |
... | @@ -255,6 +247,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -255,6 +247,7 @@ ARCS.Context = function( ctx ) { |
255 | if (ctx !== undefined) { | 247 | if (ctx !== undefined) { |
256 | libraries = ctx.libraries; | 248 | libraries = ctx.libraries; |
257 | 249 | ||
250 | + var p; | ||
258 | for (p in ctx.components) { | 251 | for (p in ctx.components) { |
259 | if (ctx.components.hasOwnProperty(p)) { | 252 | if (ctx.components.hasOwnProperty(p)) { |
260 | components[p] = ctx.components[p]; | 253 | components[p] = ctx.components[p]; |
... | @@ -271,8 +264,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -271,8 +264,7 @@ ARCS.Context = function( ctx ) { |
271 | 264 | ||
272 | } | 265 | } |
273 | 266 | ||
274 | - | 267 | + var loadDataFile =async function(fileName) { |
275 | - loadDataFile = function(fileName) { | ||
276 | var dataPromise ; | 268 | var dataPromise ; |
277 | 269 | ||
278 | if (ARCS.isInNode()) { | 270 | if (ARCS.isInNode()) { |
... | @@ -285,59 +277,12 @@ ARCS.Context = function( ctx ) { | ... | @@ -285,59 +277,12 @@ ARCS.Context = function( ctx ) { |
285 | } | 277 | } |
286 | }); | 278 | }); |
287 | } else { | 279 | } else { |
288 | - return new Promise(function(resolve, reject) { | 280 | + var client = await fetch(fileName); |
289 | - var client = new XMLHttpRequest(); | 281 | + return client.json(); |
290 | - client.open('GET',fileName,true); | ||
291 | - client.overrideMimeType("application/json"); | ||
292 | - client.send(); | ||
293 | - | ||
294 | - client.onload = function() { | ||
295 | - if (this.status >= 200 && this.status < 300) { | ||
296 | - resolve(JSON.parse(this.responseText)); | ||
297 | - } else { | ||
298 | - console.error(this.statusText); | ||
299 | - reject(this.statusText); | ||
300 | - } | ||
301 | - }; | ||
302 | - client.onerror = function() { | ||
303 | - console.error(this.statusText); | ||
304 | - reject(this.statusText); | ||
305 | - }; | ||
306 | - }); | ||
307 | } | 282 | } |
308 | }; | 283 | }; |
309 | - | 284 | + |
310 | - this.addLibraryPromise = function(p) { | 285 | + var loadLibraries = function () { |
311 | - depLibPromises.push(p); | ||
312 | - }; | ||
313 | - | ||
314 | - promiseLibrary = function(libName) { | ||
315 | - return new Promise(function(resolve, reject) { | ||
316 | - if (libName.substr(-3) === '.js') { | ||
317 | - reject(libName); | ||
318 | - } | ||
319 | - | ||
320 | - if (ARCS.isInNode()) { | ||
321 | - if (require("./" + libraries[i] + ".js") === undefined) { | ||
322 | - reject(libName); | ||
323 | - } else { | ||
324 | - resolve(); | ||
325 | - } | ||
326 | - } else { | ||
327 | - require([libName], | ||
328 | - function() { | ||
329 | - resolve(); | ||
330 | - }, | ||
331 | - function(err) { | ||
332 | - reject(libName,err); | ||
333 | - | ||
334 | - } | ||
335 | - ); | ||
336 | - } | ||
337 | - }); | ||
338 | - }; | ||
339 | - | ||
340 | - loadLibraries = function () { | ||
341 | var i; | 286 | var i; |
342 | // we will use different instances of require either the one of node | 287 | // we will use different instances of require either the one of node |
343 | // or the one from require.js | 288 | // or the one from require.js |
... | @@ -345,14 +290,13 @@ ARCS.Context = function( ctx ) { | ... | @@ -345,14 +290,13 @@ ARCS.Context = function( ctx ) { |
345 | 290 | ||
346 | var res=[]; | 291 | var res=[]; |
347 | for(i=0; i < libraries.length; i++) { | 292 | for(i=0; i < libraries.length; i++) { |
348 | - res.push(promiseLibrary(libraries[i])); | 293 | + res.push(self.loadLibrary(libraries[i])); |
349 | } | 294 | } |
350 | return Promise.all(res); | 295 | return Promise.all(res); |
351 | }; | 296 | }; |
352 | 297 | ||
353 | - instanciateComponents = function() { | 298 | + var instanciateComponents = function() { |
354 | var p, promises=[]; | 299 | var p, promises=[]; |
355 | - console.log(components); | ||
356 | 300 | ||
357 | for (p in components) { | 301 | for (p in components) { |
358 | if (components.hasOwnProperty(p)) { | 302 | if (components.hasOwnProperty(p)) { |
... | @@ -361,7 +305,7 @@ ARCS.Context = function( ctx ) { | ... | @@ -361,7 +305,7 @@ ARCS.Context = function( ctx ) { |
361 | console.error("[ARCS] Context dump follows: ", libraries, components, constants); | 305 | console.error("[ARCS] Context dump follows: ", libraries, components, constants); |
362 | return ; | 306 | return ; |
363 | } | 307 | } |
364 | - factory = factories[components[p].type]; | 308 | + var factory = factories[components[p].type]; |
365 | //console.log("instanciating ", p); | 309 | //console.log("instanciating ", p); |
366 | try { | 310 | try { |
367 | if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { | 311 | if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) { |
... | @@ -410,13 +354,23 @@ ARCS.Context = function( ctx ) { | ... | @@ -410,13 +354,23 @@ ARCS.Context = function( ctx ) { |
410 | libActualName = libName.name; | 354 | libActualName = libName.name; |
411 | libUrl = libName.url; | 355 | libUrl = libName.url; |
412 | } | 356 | } |
413 | - | 357 | + |
414 | - libraries.push(libActualName); | 358 | + if (libraries.indexOf(libActualName) < 0) { |
415 | - promiseLibrary(libUrl).then( function() { | 359 | + libraries.push(libActualName); |
360 | + } | ||
361 | + // TODO promisify call to cbFunction | ||
362 | + return import(libUrl).then( function(module) { | ||
363 | + // TODO insert here component factories | ||
364 | + for (p in module.default) { | ||
365 | + if (module.default.hasOwnProperty(p)) { | ||
366 | + ARCS.Context.currentContext.setFactory(p,module.default[p]); | ||
367 | + } | ||
368 | + } | ||
369 | + | ||
416 | if (cbFunction !== undefined) { | 370 | if (cbFunction !== undefined) { |
417 | cbFunction(); | 371 | cbFunction(); |
418 | } | 372 | } |
419 | - }); | 373 | + }).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) }); |
420 | }; | 374 | }; |
421 | 375 | ||
422 | /** | 376 | /** |
... | @@ -533,9 +487,9 @@ ARCS.Context = function( ctx ) { | ... | @@ -533,9 +487,9 @@ ARCS.Context = function( ctx ) { |
533 | 487 | ||
534 | // this should return a promise ! | 488 | // this should return a promise ! |
535 | this.instanciate = function () { | 489 | this.instanciate = function () { |
536 | - return loadLibraries().then(function() { return Promise.all(depLibPromises); }) | 490 | + //! TODO |
537 | - .then(instanciateComponents) | 491 | + return loadLibraries().then(instanciateComponents) |
538 | - .catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); }); | 492 | + .catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); }); |
539 | 493 | ||
540 | }; | 494 | }; |
541 | 495 | ||
... | @@ -1697,7 +1651,7 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) { | ... | @@ -1697,7 +1651,7 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) { |
1697 | } | 1651 | } |
1698 | 1652 | ||
1699 | res = ARCS.TransitionNetwork.build(tree[0],tokenEvents); | 1653 | res = ARCS.TransitionNetwork.build(tree[0],tokenEvents); |
1700 | - | 1654 | + var i; |
1701 | for (i=1; i < tree.length; i++) { | 1655 | for (i=1; i < tree.length; i++) { |
1702 | if (tree[i].hasOwnProperty('and')) { | 1656 | if (tree[i].hasOwnProperty('and')) { |
1703 | rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents); | 1657 | rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents); |
... | @@ -2083,7 +2037,7 @@ ARCS.Application = function () { | ... | @@ -2083,7 +2037,7 @@ ARCS.Application = function () { |
2083 | * Starts the application | 2037 | * Starts the application |
2084 | */ | 2038 | */ |
2085 | this.start = function () { | 2039 | this.start = function () { |
2086 | - console.log("[ARCS] Starting application"); | 2040 | + console.log("[ARCS] Starting application..."); |
2087 | context.instanciate().then(preProcess); | 2041 | context.instanciate().then(preProcess); |
2088 | }; | 2042 | }; |
2089 | }; | 2043 | }; |
... | @@ -2099,116 +2053,6 @@ ARCS.Application.slot("setSheet"); | ... | @@ -2099,116 +2053,6 @@ ARCS.Application.slot("setSheet"); |
2099 | ARCS.Application.slot("finish"); | 2053 | ARCS.Application.slot("finish"); |
2100 | 2054 | ||
2101 | 2055 | ||
2102 | -/** | 2056 | +// no longer needed with the use of imports |
2103 | - * definition of the main module function: | ||
2104 | - * it takes an anonymous function as a parameter | ||
2105 | - * the anonymous function has one parameter: the object encompassing | ||
2106 | - * ARCS definitions (in order to able to use ARCS.Component.create, ...) | ||
2107 | - * @param moduleDefinition {function} main function of the module. | ||
2108 | - * It should return a list of components | ||
2109 | - * @param deps {mixed[]} dependencies | ||
2110 | - */ | ||
2111 | - | ||
2112 | -// reimplementation using native promises | ||
2113 | -arcs_module = function(moduleDefinition, deps) { | ||
2114 | - var storeComponents, i; | ||
2115 | - | ||
2116 | - if (typeof module !== 'undefined') { | ||
2117 | - if (module.parent.exports) { | ||
2118 | - ARCS = module.exports; | ||
2119 | - } | ||
2120 | - } | ||
2121 | - | ||
2122 | - if (deps === undefined) { deps = []; } | ||
2123 | - | ||
2124 | - storeComponents = function (deps) { | ||
2125 | - var mdef, p; | ||
2126 | - // we should insert ARCS at the beginning of deps ! | ||
2127 | - deps.unshift(ARCS); | ||
2128 | - | ||
2129 | - mdef = (typeof moduleDefinition === 'function') ? | ||
2130 | - moduleDefinition.apply(this, deps) : moduleDefinition; | ||
2131 | - | ||
2132 | - if (mdef === undefined) { | ||
2133 | - throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition); | ||
2134 | - } | ||
2135 | 2057 | ||
2136 | - for (p in mdef) { | 2058 | +export { ARCS as default}; |
2137 | - if (mdef.hasOwnProperty(p) && ARCS.Context.currentContext != null) { | ||
2138 | - ARCS.Context.currentContext.setFactory(p,mdef[p]); //.setFactory(ARCS.Application.currentApplication, p, mdef[p]); | ||
2139 | - } | ||
2140 | - } | ||
2141 | - | ||
2142 | - return Promise.resolve(); | ||
2143 | - }; | ||
2144 | - // until now, it is the very same code. | ||
2145 | - | ||
2146 | - // here we create a promise to solve dependency | ||
2147 | - // reject has the dependency name, while resolve has the object | ||
2148 | - var depResolve = function(dep) { | ||
2149 | - return new Promise(function(resolve, reject) { | ||
2150 | - var d,shimConfig; | ||
2151 | - if (ARCS.isInNode()) { | ||
2152 | - d = require(dep); | ||
2153 | - if (d === undefined) { | ||
2154 | - reject(dep); | ||
2155 | - } else { | ||
2156 | - resolve(d); | ||
2157 | - } | ||
2158 | - } else { | ||
2159 | - // this one a little bit trickier since we have to shim. | ||
2160 | - if (dep.name !== undefined) { | ||
2161 | - shimConfig = { shim: {} }; | ||
2162 | - shimConfig.shim[dep.name] = { exports: dep.exports }; | ||
2163 | - if (dep.deps !== undefined) { | ||
2164 | - shimConfig.shim[dep.name].deps = dep.deps; | ||
2165 | - } | ||
2166 | - require.config(shimConfig); | ||
2167 | - dep = dep.name; | ||
2168 | - } | ||
2169 | - // shim performed | ||
2170 | - require([dep], | ||
2171 | - function(d) { resolve(d); }, | ||
2172 | - function(err) { console.log("[ARCS] Trouble with module ", dep); reject(dep, err); } | ||
2173 | - ); | ||
2174 | - } | ||
2175 | - }); | ||
2176 | - }; | ||
2177 | - | ||
2178 | - var depResolves = []; | ||
2179 | - for (i=0; i<deps.length; i++) { | ||
2180 | - depResolves[i] = depResolve(deps[i]); | ||
2181 | - } | ||
2182 | - | ||
2183 | - | ||
2184 | - | ||
2185 | - ARCS.Context.currentContext.addLibraryPromise( | ||
2186 | - Promise.all(depResolves).then(storeComponents, | ||
2187 | - function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); }) | ||
2188 | - | ||
2189 | - ); | ||
2190 | - | ||
2191 | -} | ||
2192 | - | ||
2193 | -// ARCS is then defined as a node.js module | ||
2194 | -if (!ARCS.isInNode()) { | ||
2195 | - var exports = {}; | ||
2196 | -} | ||
2197 | - | ||
2198 | -exports.Component = ARCS.Component; | ||
2199 | -exports.Connection = ARCS.Connection; | ||
2200 | -exports.Invocation = ARCS.Invocation; | ||
2201 | -exports.Statemachine = ARCS.Statemachine; | ||
2202 | -exports.Sheet = ARCS.Sheet; | ||
2203 | -exports.Application = ARCS.Application; | ||
2204 | -exports.EventLogicParser = ARCS.EventLogicParser; | ||
2205 | -exports.TransitionSystem = ARCS.TransitionSystem; | ||
2206 | -exports.isInNode = ARCS.isInNode; | ||
2207 | -exports.isInRequire = ARCS.isInRequire; | ||
2208 | - | ||
2209 | -// hack for require.js | ||
2210 | -// ARCS is then defined as a require.js module. | ||
2211 | -if (ARCS.isInRequire()) { | ||
2212 | - //console.log("module ARCS in require.js"); | ||
2213 | - define(exports); | ||
2214 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -/*! ARCS 2017-07-17 */ | ||
2 | -var ARCS=ARCS||{};if(ARCS.isInNode=function(){return"function"==typeof require&&require.resolve},ARCS.isInRequire=function(){return"function"==typeof define&&define.amd},ARCS.Component={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(a,b,c){return void 0===a.prototype?(console.error("Cannot create such a component"),0):(a.prototype.slots=[],a.prototype.signals={},a.slotList=function(){return a.prototype.slots},a.prototype.slotList=function(){return a.prototype.slots},a.prototype.signalList=function(){var b,c=[];for(b in a.prototype.signals)c.push(b);return c},a.signalList=function(){return a.prototype.signalList()},a.prototype.emit=function(a){var b,c,d,e=Array.prototype.slice.call(arguments,1);for(b in this.signals[a])c=this.signals[a][b].func,d=this.signals[a][b].obj,c.apply(d,e)},a.slot=function(b,c){var d;if(b instanceof Array)for(d=0;d<b.length;d++)a.prototype.slots.push(b[d]);else a.prototype.slots.push(b),void 0!==c&&(a.prototype[b]=c)},a.signal=function(b){var c;if(b instanceof Array)for(c=0;c<b.length;c++)a.prototype.signals[b[c]]=1;else a.prototype.signals[b]=1},void 0!==b&&a.slot(b),void 0!==c&&a.signal(c),a)},check:function(a){return void 0!==a.prototype&&(void 0!==a.prototype.signals&&void 0!==a.prototype.slots)},connect:function(a,b,c,d){var e,f;if(void 0===a.signals)throw ARCS.Component.SourceIsNotComponent;if(void 0===a.signals[b])throw ARCS.Component.UndefinedSignal;if(void 0===c[d])throw ARCS.Component.UndefinedSlot;if(!a.hasOwnProperty("signals")){e=a.signals,a.signals={};for(f in e)a.signals[f]=[]}a.signals[b].push({obj:c,func:c[d]})},disconnect:function(a,b,c,d){var e;for(e=0;e<a.signals[b].length;e++)a.signals[b][e].obj===c&&a.signals[b][e].func===c[d]&&(a.signals[b].splice(e,1),e--)},invoke:function(a,b,c){if(void 0===a[b])throw ARCS.Component.UndefinedSlot;var d=a[b];d.apply(a,c)},config:function(a,b){"function"==typeof a.config&&a.config(b)}},ARCS.Context=function(a){var b,c,d,e,f={},g={},h={},j=[],k=[],l=this;if(h.StateMachine=ARCS.Statemachine,void 0!==a){j=a.libraries;for(p in a.components)a.components.hasOwnProperty(p)&&(f[p]=a.components[p]);if(void 0!==a.constants)for(p in a.constants)a.constants.hasOwnProperty(p)&&(g[p]=a.constants[p])}c=function(a){return ARCS.isInNode()?new Promise(function(b,c){var d=require(a);void 0!==d?b(d):c("[ARCS] File not found")}):new Promise(function(b,c){var d=new XMLHttpRequest;d.open("GET",a,!0),d.overrideMimeType("application/json"),d.send(),d.onload=function(){this.status>=200&&this.status<300?b(JSON.parse(this.responseText)):(console.error(this.statusText),c(this.statusText))},d.onerror=function(){console.error(this.statusText),c(this.statusText)}})},this.addLibraryPromise=function(a){k.push(a)},d=function(a){return new Promise(function(b,c){".js"===a.substr(-3)&&c(a),ARCS.isInNode()?void 0===require("./"+j[i]+".js")?c(a):b():require([a],function(){b()},function(b){c(a,b)})})},b=function(){var a;ARCS.Context.currentContext=l;var b=[];for(a=0;a<j.length;a++)b.push(d(j[a]));return Promise.all(b)},e=function(){var a,b=[];console.log(f);for(a in f)if(f.hasOwnProperty(a)){if(void 0===h[f[a].type])return console.error("[ARCS] Factory "+f[a].type+" not found."),void console.error("[ARCS] Context dump follows: ",j,f,g);factory=h[f[a].type];try{if(void 0!==f[a].value||void 0!==f[a].url||void 0!==f[a].ref){if(void 0!==f[a].value&&(f[a].instance=new factory(f[a].value)),void 0!==f[a].url){var d=function(a,b){return function(c){return f[a].instance=new b(c),Promise.resolve()}};b.push(c(f[a].url).then(d(a,factory)))}void 0!==f[a].ref&&void 0!==g[f[a].ref]&&(f[a].instance=new factory(g[f[a].ref]))}else f[a].instance=new factory}catch(b){console.error("[ARCS] Component of type ",a," not instanciated.",b)}}return Promise.all(b)},this.loadLibrary=function(a,b){var c=a,e=a;ARCS.Context.currentContext=l,"string"!=typeof a&&(e=a.name,c=a.url),j.push(e),d(c).then(function(){void 0!==b&&b()})},this.getComponentList=function(){var a,b=Object.keys(f);for(a=0;a<b.length;a++)f.hasOwnProperty(b[a])||b.splice(a--,1);return b},this.getConstant=function(a){return g[a]},this.getComponentType=function(a){if(void 0!==f[a])return f[a].type},this.getComponentValue=function(a){if(void 0!==f[a])return f[a].value},this.getComponent=function(a){if(void 0!==f[a])return f[a].instance},this.getComponentName=function(a){var b,c;for(c=f.getComponentList(),b=0;b<c.length;b++)if(f[c[b]].instance===a)return c[b]},this.setFactory=function(a,b){h[a]=b},this.toJSON=function(){var a,b={};for(a in f)f.hasOwnProperty(a)&&(b[a]={type:f[a].type,value:f[a].value});return b},this.setComponentValue=function(a,b){f[a].value=b},this.addComponent=function(a,b,c){var d;f[a]={},f[a].type=b,f[a].value=c;var e=h[b];void 0!==e&&(d=new e(c)),f[a].instance=d},this.removeComponent=function(a){delete f[a]},this.getFactory=function(a){return h[a]},this.getFactoryList=function(){return Object.keys(h)},this.instanciate=function(){return b().then(function(){return Promise.all(k)}).then(e).catch(function(a){console.log("[ARCS] Trouble instanciating context",a)})};var m=function(a,b){var c,d=Object.create(b);for(c in a)a.hasOwnProperty(c)&&(d[c]=a[c]);return d};this.chain=function(a,b,c){return[m(a,f),m(b,g),m(c,h)]},this.setParent=function(a){if(void 0!==a){var b=a.chain(f,g,h);f=b[0],g=b[1],h=b[2]}}},ARCS.Context.currentContext=null,ARCS.Invocation=function(a,b,c){this.getDestination=function(){return a},this.getSlot=function(){return b},this.getValue=function(){return c},this.invoke=function(){var d=a[b];return void 0===d?void console.error("Undefined slot %s of component %s",b,a):void d.apply(a,c)}},ARCS.Invocation.cast=function(a,b){if(void 0!==a.value){var c=b.getComponent(a.destination);return void 0===c&&console.error("[ARCS] Destination ",a.destination," is undefined"),new ARCS.Invocation(c,a.slot,a.value)}if(void 0!==a.ref)return new ARCS.Invocation(b.getComponent(a.destination),a.slot,b.getConstant(a.ref))},ARCS.Invocation.PRE_CONNECTION=0,ARCS.Invocation.POST_CONNECTION=1,ARCS.Invocation.CLEAN_UP=2,ARCS.Connection=function(a,b,c,d){this.connect=function(){try{ARCS.Component.connect(a,b,c,d)}catch(e){console.log(e,a,b,c,d)}},this.disconnect=function(){ARCS.Component.disconnect(a,b,c,d)},this.getSource=function(){return a},this.getDestination=function(){return c},this.getSlot=function(){return d},this.getSignal=function(){return b}},ARCS.Connection.cast=function(a,b){return new ARCS.Connection(b.getComponent(a.source),a.signal,b.getComponent(a.destination),a.slot)},ARCS.Sheet=function(a){var b,c,d,e,f,g=new ARCS.Context,h=[],i=[],j=[],k=[],l=0,m=0,n=0,o=0;b=function(){var a;for(a=0;a<h.length;a++)h[a].invoke()},c=function(){var a;for(a=0;a<i.length;a++)i[a].invoke()},d=function(){var a;for(a=0;a<j.length;a++)j[a].invoke()},e=function(){var a;for(a=0;a<k.length;a++)k[a].connect()},f=function(){var a;for(a=0;a<k.length;a++)k[a].disconnect()},this.setContext=function(a){g=a},this.activate=function(){g.instanciate().then(function(){b(),e(),c()})},this.deactivate=function(){f(),d()},this.addPreConnection=function(a){var b=ARCS.Invocation.cast(a,g);return b.id=l++,h.push(b),b.id},this.addPostConnection=function(a){var b=ARCS.Invocation.cast(a,g);return b.id=m++,i.push(b),b.id},this.addCleanup=function(a){var b=ARCS.Invocation.cast(a,g);return b.id=n++,j.push(b),b.id},this.addConnection=function(a){var b=ARCS.Connection.cast(a,g);return b.id=o++,k.push(b),b.id};var p=function(a,b){for(var c=b.length;c--&&b[c].id!==a;);c>=0?b.splice(c,1):console.warn("Could not remove data with id",a)};this.removePreConnection=function(a){p(a,h)},this.removePostConnection=function(a){p(a,i)},this.removeCleanup=function(a){p(a,j)};var q=function(a,b,c){for(var d=c.length;d--&&c[d].id!==a;);d>=0&&(c[d].value=b)};this.changePreConnection=function(a,b){q(a,b,h)},this.changePostConnection=function(a,b){q(a,b,i)},this.changeCleanup=function(a,b){q(a,b,j)},this.removeConnection=function(a){p(a,k)};var r=function(a,b,c){for(var d,e=c.length,f=c.length;e--&&c[e].id!==a;);for(;f--&&c[f].id!==b;);e>=0&&f>=0&&(d=c[e],c[e]=c[f],c[f]=d,c[e].id=a,c[f].id=b)};this.swapConnections=function(a,b){r(a,b,k)},this.swapCleanups=function(a,b){r(a,b,j)},this.swapPreConnections=function(a,b){r(a,b,h)},this.swapPostConnections=function(a,b){r(a,b,i)};var s=function(a){var b=0,c=ARCS.Invocation.cast,d=ARCS.Connection.cast;for(b=0;b<a.preconnections.length;b++)h.push(c(a.preconnections[b],g));for(b=0;b<a.postconnections.length;b++)i.push(c(a.postconnections[b],g));for(b=0;b<a.cleanups.length;b++)j.push(c(a.cleanups[b],g));for(b=0;b<a.connections.length;b++)k.push(d(a.connections[b],g))};this.import=function(b){b.hasOwnProperty("context")&&(g=new ARCS.Context(b.context),g.setParent(a)),g.instanciate().then(function(){s(b)})};var t=function(a){return{destination:g.getComponentName(a.getDestination()),slot:a.getSlot(),value:a.getValue()}},u=function(a){return{source:g.getComponentName(a.getSource()),signal:a.getSignal(),destination:g.getComponentName(a.getDestination()),slot:a.getSlot()}};this.toJSON=function(){var a,b=[],c=[],d=[],e=[];for(a=0;a<k.length;a++)d.push(u(k[a]));for(a=0;a<h.length;a++)b.push(t(h[a]));for(a=0;a<i.length;a++)c.push(t(i[a]));for(a=0;a<j.length;a++)e.push(t(j[a]));return{preconnections:b,postconnections:c,connections:d,cleanups:e}},g.setParent(a)},ARCS.EventLogicParser=function(){function a(a,b){function c(){this.constructor=a}c.prototype=b.prototype,a.prototype=new c}function b(a,b,c,d,e,f){this.message=a,this.expected=b,this.found=c,this.offset=d,this.line=e,this.column=f,this.name="SyntaxError"}function c(a){function c(b){function c(b,c,d){var e,f;for(e=c;e<d;e++)f=a.charAt(e),"\n"===f?(b.seenCR||b.line++,b.column=1,b.seenCR=!1):"\r"===f||"\u2028"===f||"\u2029"===f?(b.line++,b.column=1,b.seenCR=!0):(b.column++,b.seenCR=!1)}return R!==b&&(R>b&&(R=0,S={line:1,column:1,seenCR:!1}),c(S,R,b),R=b),S}function d(a){P<T||(P>T&&(T=P,U=[]),U.push(a))}function e(d,e,f){function g(a){var b=1;for(a.sort(function(a,b){return a.description<b.description?-1:a.description>b.description?1:0});b<a.length;)a[b-1]===a[b]?a.splice(b,1):b++}function h(a,b){function c(a){function b(a){return a.charCodeAt(0).toString(16).toUpperCase()}return a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,function(a){return"\\x0"+b(a)}).replace(/[\x10-\x1F\x80-\xFF]/g,function(a){return"\\x"+b(a)}).replace(/[\u0180-\u0FFF]/g,function(a){return"\\u0"+b(a)}).replace(/[\u1080-\uFFFF]/g,function(a){return"\\u"+b(a)})}var d,e,f,g=new Array(a.length);for(f=0;f<a.length;f++)g[f]=a[f].description;return d=a.length>1?g.slice(0,-1).join(", ")+" or "+g[a.length-1]:g[0],e=b?'"'+c(b)+'"':"end of input","Expected "+d+" but "+e+" found."}var i=c(f),j=f<a.length?a.charAt(f):null;return null!==e&&g(e),new b(null!==d?d:h(e,j),e,j,f,i.line,i.column)}function f(){var a;return a=g()}function g(){var a,b,c,d;if(a=P,b=i(),b!==q){if(c=[],d=h(),d!==q)for(;d!==q;)c.push(d),d=h();else c=t;c!==q?(Q=a,b=u(b,c),a=b):(P=a,a=t)}else P=a,a=t;return a===q&&(a=i()),a}function h(){var a,b,c;return a=P,b=l(),b!==q?(c=i(),c!==q?(Q=a,b=v(c),a=b):(P=a,a=t)):(P=a,a=t),a===q&&(a=P,b=m(),b!==q?(c=i(),c!==q?(Q=a,b=w(c),a=b):(P=a,a=t)):(P=a,a=t)),a}function i(){var b,c,e,f;return b=P,c=j(),c!==q&&(Q=b,c=x(c)),b=c,b===q&&(b=P,40===a.charCodeAt(P)?(c=y,P++):(c=q,0===V&&d(z)),c!==q?(e=g(),e!==q?(41===a.charCodeAt(P)?(f=A,P++):(f=q,0===V&&d(B)),f!==q?(Q=b,c=C(e),b=c):(P=b,b=t)):(P=b,b=t)):(P=b,b=t)),b}function j(){var b,c,e;return V++,b=P,c=P,e=k(),e!==q&&(e=a.substring(c,P)),c=e,c!==q&&(Q=b,c=E(c)),b=c,V--,b===q&&(c=q,0===V&&d(D)),b}function k(){var b,c,e,f,g;if(b=P,c=n(),c!==q)if(F.test(a.charAt(P))?(e=a.charAt(P),P++):(e=q,0===V&&d(G)),e!==q){for(f=[],H.test(a.charAt(P))?(g=a.charAt(P),P++):(g=q,0===V&&d(I));g!==q;)f.push(g),H.test(a.charAt(P))?(g=a.charAt(P),P++):(g=q,0===V&&d(I));f!==q?(g=n(),g!==q?(c=[c,e,f,g],b=c):(P=b,b=t)):(P=b,b=t)}else P=b,b=t;else P=b,b=t;return b}function l(){var b,c,e,f;return b=P,c=n(),c!==q?(38===a.charCodeAt(P)?(e=J,P++):(e=q,0===V&&d(K)),e!==q?(f=n(),f!==q?(c=[c,e,f],b=c):(P=b,b=t)):(P=b,b=t)):(P=b,b=t),b}function m(){var b,c,e,f;return b=P,c=n(),c!==q?(124===a.charCodeAt(P)?(e=L,P++):(e=q,0===V&&d(M)),e!==q?(f=n(),f!==q?(c=[c,e,f],b=c):(P=b,b=t)):(P=b,b=t)):(P=b,b=t),b}function n(){var b,c;for(b=[],N.test(a.charAt(P))?(c=a.charAt(P),P++):(c=q,0===V&&d(O));c!==q;)b.push(c),N.test(a.charAt(P))?(c=a.charAt(P),P++):(c=q,0===V&&d(O));return b}var o,p=arguments.length>1?arguments[1]:{},q={},r={start:f},s=f,t=q,u=function(a,b){return[a].concat(b)},v=function(a){return{and:a}},w=function(a){return{or:a}},x=function(a){return a},y="(",z={type:"literal",value:"(",description:'"("'},A=")",B={type:"literal",value:")",description:'")"'},C=function(a){return[a]},D={type:"other",description:"id"},E=function(a){return a.trim()},F=/^[_a-zA-Z]/,G={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},H=/^[_a-zA-Z0-9]/,I={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},J="&",K={type:"literal",value:"&",description:'"&"'},L="|",M={type:"literal",value:"|",description:'"|"'},N=/^[ \r\n\t]/,O={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},P=0,Q=0,R=0,S={line:1,column:1,seenCR:!1},T=0,U=[],V=0;if("startRule"in p){if(!(p.startRule in r))throw new Error("Can't start parsing from rule \""+p.startRule+'".');s=r[p.startRule]}if(o=s(),o!==q&&P===a.length)return o;throw o!==q&&P<a.length&&d({type:"end",description:"end of input"}),e(null,U,T)}return a(b,Error),{SyntaxError:b,parse:c}}(),ARCS.TokenEvent=function(){var a,b;this.promise=new Promise(function(c,d){a=c,b=d}),this.accept=function(){a()},this.abort=function(){b()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(a){return this.promise=Promise.all([this.promise,a.promise]),this},this.or=function(a){return this.promise=Promise.race([this.promise,a.promise]),this}},ARCS.TransitionNetwork.build=function(a,b){var c,d,e;if("string"==typeof a){var f;b.hasOwnProperty(a)?f=b[a]:b[a]=f=new ARCS.TokenEvent;var g=new ARCS.TransitionNetwork;return g.promise=f.promise,g}for(c=ARCS.TransitionNetwork.build(a[0],b),i=1;i<a.length;i++)a[i].hasOwnProperty("and")?(e=ARCS.TransitionNetwork.build(a[i].and,b),d=c.and(e)):a[i].hasOwnProperty("or")?(e=ARCS.TransitionNetwork.build(a[i].or,b),d=c.or(e)):console.warn("[ARCS] Illegal tree"),c=d;return c},ARCS.Statemachine=new ARCS.Component.create(function(a){var b="",c="",d={},e="",f=this,g={},h={},i={},j=function(a){f.slots.indexOf(a)<0&&(f.slots.push(a),f[a]=function(a){return function(){f.setToken(a)}}(a))},k=function(a){var b;if(d.hasOwnProperty(a)){h={};for(b in d[a])d[a].hasOwnProperty(b)&&(i=ARCS.TransitionNetwork.build(g[b],h).promise,i.then(function(){var c;for(c in h)h.hasOwnProperty(c)&&h[c].abort();k(d[a][b])}))}e=a,f.emit("requestSheet",e),e===c&&f.emit("requestTermination")};this.setInitialState=function(a){b=a,e=b},this.setFinalState=function(a){c=a},this.addTransition=function(a,b,c){var e,f,h=/([A-Za-z_]\w*)/g;try{var f=ARCS.EventLogicParser.parse(b);if("string"==typeof f)j(f);else for(;null!==(e=h.exec(b));)j(e[0]);g[b]=f,void 0===d[a]&&(d[a]={}),d[a][b]=c}catch(a){}},this.setToken=function(a){h.hasOwnProperty(a)&&h[a].accept()},this.setTransitions=function(a){var b,c;for(b in a)if(a.hasOwnProperty(b))for(c in a[b])a[b].hasOwnProperty(c)&&this.addTransition(b,c,a[b][c])},this.start=function(){console.log("statemachine",this,b,a),k(b)},void 0!==a&&(b=a.initial,c=a.final,this.setTransitions(a.transitions),e="")},["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){var a,b=new ARCS.Context,c={},d={},e=[],f=this,g="";this.export=function(){var a={context:b,controller:b.getComponentName(d),sheets:c};return a},this.getContext=function(){return b},this.getSheetList=function(){return Object.keys(c)},this.getSheet=function(a){return c[a]},this.addSheet=function(a,d){c[a]=d,d.setContext(b)},this.removeSheet=function(a){delete c[a]},a=function(){var a,e,g;for(e=b.getComponent(d),d=e,g=Object.keys(c),a=0;a<g.length;a++)e=new ARCS.Sheet(b),e.import(c[g[a]],b),c[g[a]]=e;ARCS.Component.connect(d,"requestSheet",f,"setSheet"),ARCS.Component.connect(d,"requestTermination",f,"finish"),d.start()},this.setController=function(a){d=b.getComponent(a)},this.setSheet=function(a){c.hasOwnProperty(a)?(g&&c[g].deactivate(),g=a,c[g].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+a)},this.finish=function(){g&&c[g].deactivate()},this.import=function(a){b=new ARCS.Context(a.context),c=a.sheets,d=a.controller,void 0===d&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(a,b){factories[a]=b},this.setDependency=function(a){e[a]={}},this.start=function(){console.log("[ARCS] Starting application"),b.instanciate().then(a)}},ARCS.Application.setDependency=function(a,b){a.setDependency(b)},ARCS.Component.create(ARCS.Application),ARCS.Application.slot("setSheet"),ARCS.Application.slot("finish"),arcs_module=function(a,b){var c,d;"undefined"!=typeof module&&module.parent.exports&&(ARCS=module.exports),void 0===b&&(b=[]),c=function(b){var c,d;if(b.unshift(ARCS),c="function"==typeof a?a.apply(this,b):a,void 0===c)throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n"+a);for(d in c)c.hasOwnProperty(d)&&null!=ARCS.Context.currentContext&&ARCS.Context.currentContext.setFactory(d,c[d]);return Promise.resolve()};var e=function(a){return new Promise(function(b,c){var d,e;ARCS.isInNode()?(d=require(a),void 0===d?c(a):b(d)):(void 0!==a.name&&(e={shim:{}},e.shim[a.name]={exports:a.exports},void 0!==a.deps&&(e.shim[a.name].deps=a.deps),require.config(e),a=a.name),require([a],function(a){b(a)},function(b){console.log("[ARCS] Trouble with module ",a),c(a,b)}))})},f=[];for(d=0;d<b.length;d++)f[d]=e(b[d]);ARCS.Context.currentContext.addLibraryPromise(Promise.all(f).then(c,function(a){console.error("[ARCS] Failed to load dependency ",a)}))},!ARCS.isInNode())var exports={};exports.Component=ARCS.Component,exports.Connection=ARCS.Connection,exports.Invocation=ARCS.Invocation,exports.Statemachine=ARCS.Statemachine,exports.Sheet=ARCS.Sheet,exports.Application=ARCS.Application,exports.EventLogicParser=ARCS.EventLogicParser,exports.TransitionSystem=ARCS.TransitionSystem,exports.isInNode=ARCS.isInNode,exports.isInRequire=ARCS.isInRequire,ARCS.isInRequire()&&define(exports); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +var ARCS=ARCS||{};ARCS.isInNode=function(){return"function"==typeof require&&require.resolve},ARCS.Component={SourceIsNotComponent:{message:"Source is not a component"},UndefinedSignal:{message:"Signal is not defined"},UndefinedSlot:{message:"Slot is not defined"},create:function(n,t,e){return void 0===n.prototype?(console.error("Cannot create such a component"),0):(n.prototype.slots=[],n.prototype.signals={},n.slotList=function(){return n.prototype.slots},n.prototype.slotList=function(){return n.prototype.slots},n.prototype.signalList=function(){var t,e=[];for(t in n.prototype.signals)e.push(t);return e},n.signalList=function(){return n.prototype.signalList()},n.prototype.emit=function(n){var t,e,o,i=Array.prototype.slice.call(arguments,1);for(t in this.signals[n])e=this.signals[n][t].func,o=this.signals[n][t].obj,e.apply(o,i)},n.slot=function(t,e){var o;if(t instanceof Array)for(o=0;o<t.length;o++)n.prototype.slots.push(t[o]);else n.prototype.slots.push(t),void 0!==e&&(n.prototype[t]=e)},n.signal=function(t){var e;if(t instanceof Array)for(e=0;e<t.length;e++)n.prototype.signals[t[e]]=1;else n.prototype.signals[t]=1},void 0!==t&&n.slot(t),void 0!==e&&n.signal(e),n)},check:function(n){return void 0!==n.prototype&&(void 0!==n.prototype.signals&&void 0!==n.prototype.slots)},connect:function(n,t,e,o){var i,r;if(void 0===n.signals)throw ARCS.Component.SourceIsNotComponent;if(void 0===n.signals[t])throw ARCS.Component.UndefinedSignal;if(void 0===e[o])throw ARCS.Component.UndefinedSlot;if(!n.hasOwnProperty("signals"))for(r in i=n.signals,n.signals={},i)n.signals[r]=[];n.signals[t].push({obj:e,func:e[o]})},disconnect:function(n,t,e,o){var i;for(i=0;i<n.signals[t].length;i++)n.signals[t][i].obj===e&&n.signals[t][i].func===e[o]&&(n.signals[t].splice(i,1),i--)},invoke:function(n,t,e){if(void 0===n[t])throw ARCS.Component.UndefinedSlot;n[t].apply(n,e)},config:function(n,t){"function"==typeof n.config&&n.config(t)}},ARCS.Context=function(n){var t={},e={},o={},i=[],r=this;if(o.StateMachine=ARCS.Statemachine,void 0!==n){var s;for(s in i=n.libraries,n.components)n.components.hasOwnProperty(s)&&(t[s]=n.components[s]);if(void 0!==n.constants)for(s in n.constants)n.constants.hasOwnProperty(s)&&(e[s]=n.constants[s])}var c=async function(n){return ARCS.isInNode()?new Promise((function(t,e){var o=require(n);void 0!==o?t(o):e("[ARCS] File not found")})):(await fetch(n)).json()},a=function(){var n,r=[];for(n in t)if(t.hasOwnProperty(n)){if(void 0===o[t[n].type])return console.error("[ARCS] Factory "+t[n].type+" not found."),void console.error("[ARCS] Context dump follows: ",i,t,e);var s=o[t[n].type];try{if(void 0!==t[n].value||void 0!==t[n].url||void 0!==t[n].ref){if(void 0!==t[n].value&&(t[n].instance=new s(t[n].value)),void 0!==t[n].url){console.log("loading data file",t[n].url),r.push(c(t[n].url).then(function(n,e){return function(o){return console.log("instanciating from data file"),t[n].instance=new e(o),Promise.resolve()}}(n,s)))}void 0!==t[n].ref&&void 0!==e[t[n].ref]&&(t[n].instance=new s(e[t[n].ref]))}else t[n].instance=new s}catch(t){console.error("[ARCS] Component of type ",n," not instanciated.",t)}}return Promise.all(r)};this.loadLibrary=function(n,t){var e=n,o=n;return ARCS.Context.currentContext=r,"string"!=typeof n&&(o=n.name,e=n.url),i.indexOf(o)<0&&i.push(o),import(e).then((function(n){for(s in n.default)n.default.hasOwnProperty(s)&&ARCS.Context.currentContext.setFactory(s,n.default[s]);void 0!==t&&t()})).catch((function(n){console.error("[ARCS] Trouble loading '",e,"' with reason -",n)}))},this.getComponentList=function(){var n,e=Object.keys(t);for(n=0;n<e.length;n++)t.hasOwnProperty(e[n])||e.splice(n--,1);return e},this.getConstant=function(n){return e[n]},this.getComponentType=function(n){if(void 0!==t[n])return t[n].type},this.getComponentValue=function(n){if(void 0!==t[n])return t[n].value},this.getComponent=function(n){if(void 0!==t[n])return t[n].instance},this.getComponentName=function(n){var e,o;for(o=t.getComponentList(),e=0;e<o.length;e++)if(t[o[e]].instance===n)return o[e]},this.setFactory=function(n,t){o[n]=t},this.toJSON=function(){var n,e={};for(n in t)t.hasOwnProperty(n)&&(e[n]={type:t[n].type,value:t[n].value});return e},this.setComponentValue=function(n,e){t[n].value=e},this.addComponent=function(n,e,i){var r;t[n]={},t[n].type=e,t[n].value=i;var s=o[e];void 0!==s&&(r=new s(i)),t[n].instance=r},this.removeComponent=function(n){delete t[n]},this.getFactory=function(n){return o[n]},this.getFactoryList=function(){return Object.keys(o)},this.instanciate=function(){ | ||
2 | +//! TODO | ||
3 | +return function(){var n;ARCS.Context.currentContext=r;var t=[];for(n=0;n<i.length;n++)t.push(r.loadLibrary(i[n]));return Promise.all(t)}().then(a).catch((function(n){console.error("[ARCS] Trouble instanciating context",n)}))};var u=function(n,t){var e,o=Object.create(t);for(e in n)n.hasOwnProperty(e)&&(o[e]=n[e]);return o};this.chain=function(n,i,r){return[u(n,t),u(i,e),u(r,o)]},this.setParent=function(n){if(void 0!==n){var i=n.chain(t,e,o);t=i[0],e=i[1],o=i[2]}}},ARCS.Context.currentContext=null,ARCS.Invocation=function(n,t,e){this.getDestination=function(){return n},this.getSlot=function(){return t},this.getValue=function(){return e},this.invoke=function(){var o=n[t];void 0!==o?o.apply(n,e):console.error("Undefined slot %s of component %s",t,n)}},ARCS.Invocation.cast=function(n,t){if(void 0!==n.value){var e=t.getComponent(n.destination);return void 0===e&&console.error("[ARCS] Destination ",n.destination," is undefined"),new ARCS.Invocation(e,n.slot,n.value)}if(void 0!==n.ref)return new ARCS.Invocation(t.getComponent(n.destination),n.slot,t.getConstant(n.ref))},ARCS.Invocation.PRE_CONNECTION=0,ARCS.Invocation.POST_CONNECTION=1,ARCS.Invocation.CLEAN_UP=2,ARCS.Connection=function(n,t,e,o){this.connect=function(){try{ARCS.Component.connect(n,t,e,o)}catch(i){console.log(i,n,t,e,o)}},this.disconnect=function(){ARCS.Component.disconnect(n,t,e,o)},this.getSource=function(){return n},this.getDestination=function(){return e},this.getSlot=function(){return o},this.getSignal=function(){return t}},ARCS.Connection.cast=function(n,t){return new ARCS.Connection(t.getComponent(n.source),n.signal,t.getComponent(n.destination),n.slot)},ARCS.Sheet=function(n){var t,e,o,i,r,s=new ARCS.Context,c=[],a=[],u=[],f=[],l=0,p=0,h=0,C=0;t=function(){var n;for(n=0;n<c.length;n++)c[n].invoke()},e=function(){var n;for(n=0;n<a.length;n++)a[n].invoke()},o=function(){var n;for(n=0;n<u.length;n++)u[n].invoke()},i=function(){var n;for(n=0;n<f.length;n++)f[n].connect()},r=function(){var n;for(n=0;n<f.length;n++)f[n].disconnect()},this.setContext=function(n){s=n},this.activate=function(){s.instanciate().then((function(){t(),i(),e()}))},this.deactivate=function(){r(),o()},this.addPreConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=l++,c.push(t),t.id},this.addPostConnection=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=p++,a.push(t),t.id},this.addCleanup=function(n){var t=ARCS.Invocation.cast(n,s);return t.id=h++,u.push(t),t.id},this.addConnection=function(n){var t=ARCS.Connection.cast(n,s);return t.id=C++,f.push(t),t.id};var d=function(n,t){for(var e=t.length;e--&&t[e].id!==n;);e>=0?t.splice(e,1):console.warn("Could not remove data with id",n)};this.removePreConnection=function(n){d(n,c)},this.removePostConnection=function(n){d(n,a)},this.removeCleanup=function(n){d(n,u)};var v=function(n,t,e){for(var o=e.length;o--&&e[o].id!==n;);o>=0&&(e[o].value=t)};this.changePreConnection=function(n,t){v(n,t,c)},this.changePostConnection=function(n,t){v(n,t,a)},this.changeCleanup=function(n,t){v(n,t,u)},this.removeConnection=function(n){d(n,f)};var g=function(n,t,e){for(var o,i=e.length,r=e.length;i--&&e[i].id!==n;);for(;r--&&e[r].id!==t;);i>=0&&r>=0&&(o=e[i],e[i]=e[r],e[r]=o,e[i].id=n,e[r].id=t)};this.swapConnections=function(n,t){g(n,t,f)},this.swapCleanups=function(n,t){g(n,t,u)},this.swapPreConnections=function(n,t){g(n,t,c)},this.swapPostConnections=function(n,t){g(n,t,a)};this.import=function(t){t.hasOwnProperty("context")&&(s=new ARCS.Context(t.context)).setParent(n),s.instanciate().then((function(){!function(n){var t=0,e=ARCS.Invocation.cast,o=ARCS.Connection.cast;for(t=0;t<n.preconnections.length;t++)c.push(e(n.preconnections[t],s));for(t=0;t<n.postconnections.length;t++)a.push(e(n.postconnections[t],s));for(t=0;t<n.cleanups.length;t++)u.push(e(n.cleanups[t],s));for(t=0;t<n.connections.length;t++)f.push(o(n.connections[t],s))}(t)}))};var S=function(n){return{destination:s.getComponentName(n.getDestination()),slot:n.getSlot(),value:n.getValue()}};this.toJSON=function(){var n,t,e=[],o=[],i=[],r=[];for(n=0;n<f.length;n++)i.push((t=f[n],{source:s.getComponentName(t.getSource()),signal:t.getSignal(),destination:s.getComponentName(t.getDestination()),slot:t.getSlot()}));for(n=0;n<c.length;n++)e.push(S(c[n]));for(n=0;n<a.length;n++)o.push(S(a[n]));for(n=0;n<u.length;n++)r.push(S(u[n]));return{preconnections:e,postconnections:o,connections:i,cleanups:r}},s.setParent(n)},ARCS.EventLogicParser=function(){function n(n,t,e,o,i,r){this.message=n,this.expected=t,this.found=e,this.offset=o,this.line=i,this.column=r,this.name="SyntaxError"}return function(n,t){function e(){this.constructor=n}e.prototype=t.prototype,n.prototype=new e}(n,Error),{SyntaxError:n,parse:function(t){var e,o=arguments.length>1?arguments[1]:{},i={},r={start:U},s=U,c=i,a=function(n,t){return[n].concat(t)},u=function(n){return{and:n}},f=function(n){return{or:n}},l=function(n){return n},p="(",h={type:"literal",value:"(",description:'"("'},C=")",d={type:"literal",value:")",description:'")"'},v=function(n){return[n]},g={type:"other",description:"id"},S=function(n){return n.trim()},A=/^[_a-zA-Z]/,m={type:"class",value:"[_a-zA-Z]",description:"[_a-zA-Z]"},y=/^[_a-zA-Z0-9]/,R={type:"class",value:"[_a-zA-Z0-9]",description:"[_a-zA-Z0-9]"},w="&",x={type:"literal",value:"&",description:'"&"'},P="|",O={type:"literal",value:"|",description:'"|"'},T=/^[ \r\n\t]/,N={type:"class",value:"[ \\r\\n\\t]",description:"[ \\r\\n\\t]"},b=0,k=0,F={line:1,column:1,seenCR:!1},I=0,E=[],L=0;if("startRule"in o){if(!(o.startRule in r))throw new Error("Can't start parsing from rule \""+o.startRule+'".');s=r[o.startRule]}function j(n){return k!==n&&(k>n&&(k=0,F={line:1,column:1,seenCR:!1}),function(n,e,o){var i,r;for(i=e;i<o;i++)"\n"===(r=t.charAt(i))?(n.seenCR||n.line++,n.column=1,n.seenCR=!1):"\r"===r||"\u2028"===r||"\u2029"===r?(n.line++,n.column=1,n.seenCR=!0):(n.column++,n.seenCR=!1)}(F,k,n),k=n),F}function _(n){b<I||(b>I&&(I=b,E=[]),E.push(n))}function q(e,o,i){var r=j(i),s=i<t.length?t.charAt(i):null;return null!==o&&function(n){var t=1;for(n.sort((function(n,t){return n.description<t.description?-1:n.description>t.description?1:0}));t<n.length;)n[t-1]===n[t]?n.splice(t,1):t++}(o),new n(null!==e?e:function(n,t){var e,o=new Array(n.length);for(e=0;e<n.length;e++)o[e]=n[e].description;return"Expected "+(n.length>1?o.slice(0,-1).join(", ")+" or "+o[n.length-1]:o[0])+" but "+(t?'"'+function(n){function t(n){return n.charCodeAt(0).toString(16).toUpperCase()}return n.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E\x0F]/g,(function(n){return"\\x0"+t(n)})).replace(/[\x10-\x1F\x80-\xFF]/g,(function(n){return"\\x"+t(n)})).replace(/[\u0180-\u0FFF]/g,(function(n){return"\\u0"+t(n)})).replace(/[\u1080-\uFFFF]/g,(function(n){return"\\u"+t(n)}))}(t)+'"':"end of input")+" found."}(o,s),o,s,i,r.line,r.column)}function U(){return D()}function D(){var n,t,e,o;if(n=b,(t=Z())!==i){if(e=[],(o=z())!==i)for(;o!==i;)e.push(o),o=z();else e=c;e!==i?(n,n=t=a(t,e)):(b=n,n=c)}else b=n,n=c;return n===i&&(n=Z()),n}function z(){var n,t;return n=b,B()!==i&&(t=Z())!==i?(n,n=u(t)):(b=n,n=c),n===i&&(n=b,M()!==i&&(t=Z())!==i?(n,n=f(t)):(b=n,n=c)),n}function Z(){var n,e,o,r;return n=b,(e=V())!==i&&(n,e=l(e)),(n=e)===i&&(n=b,40===t.charCodeAt(b)?(e=p,b++):(e=i,0===L&&_(h)),e!==i&&(o=D())!==i?(41===t.charCodeAt(b)?(r=C,b++):(r=i,0===L&&_(d)),r!==i?(n,n=e=v(o)):(b=n,n=c)):(b=n,n=c)),n}function V(){var n,e,o;return L++,n=b,e=b,(o=J())!==i&&(o=t.substring(e,b)),(e=o)!==i&&(n,e=S(e)),L--,(n=e)===i&&(e=i,0===L&&_(g)),n}function J(){var n,e,o,r,s;if(n=b,(e=G())!==i)if(A.test(t.charAt(b))?(o=t.charAt(b),b++):(o=i,0===L&&_(m)),o!==i){for(r=[],y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));s!==i;)r.push(s),y.test(t.charAt(b))?(s=t.charAt(b),b++):(s=i,0===L&&_(R));r!==i&&(s=G())!==i?n=e=[e,o,r,s]:(b=n,n=c)}else b=n,n=c;else b=n,n=c;return n}function B(){var n,e,o,r;return n=b,(e=G())!==i?(38===t.charCodeAt(b)?(o=w,b++):(o=i,0===L&&_(x)),o!==i&&(r=G())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c),n}function M(){var n,e,o,r;return n=b,(e=G())!==i?(124===t.charCodeAt(b)?(o=P,b++):(o=i,0===L&&_(O)),o!==i&&(r=G())!==i?n=e=[e,o,r]:(b=n,n=c)):(b=n,n=c),n}function G(){var n,e;for(n=[],T.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(N));e!==i;)n.push(e),T.test(t.charAt(b))?(e=t.charAt(b),b++):(e=i,0===L&&_(N));return n}if((e=s())!==i&&b===t.length)return e;throw e!==i&&b<t.length&&_({type:"end",description:"end of input"}),q(null,E,I)}}}(),ARCS.TokenEvent=function(){var n,t;this.promise=new Promise((function(e,o){n=e,t=o})),this.accept=function(){n()},this.abort=function(){t()}},ARCS.TransitionNetwork=function(){this.promise={},this.and=function(n){return this.promise=Promise.all([this.promise,n.promise]),this},this.or=function(n){return this.promise=Promise.race([this.promise,n.promise]),this}},ARCS.TransitionNetwork.build=function(n,t){var e,o,i,r;if("string"==typeof n){var s;t.hasOwnProperty(n)?s=t[n]:t[n]=s=new ARCS.TokenEvent;var c=new ARCS.TransitionNetwork;return c.promise=s.promise,c}for(e=ARCS.TransitionNetwork.build(n[0],t),r=1;r<n.length;r++)n[r].hasOwnProperty("and")?(i=ARCS.TransitionNetwork.build(n[r].and,t),o=e.and(i)):n[r].hasOwnProperty("or")?(i=ARCS.TransitionNetwork.build(n[r].or,t),o=e.or(i)):console.warn("[ARCS] Illegal tree"),e=o;return e},ARCS.Statemachine=new ARCS.Component.create((function(n){var t="",e="",o={},i="",r=this,s={},c={},a=function(n){var t;r.slots.indexOf(n)<0&&(r.slots.push(n),r[n]=(t=n,function(){r.setToken(t)}))},u=function(n){var t;if(o.hasOwnProperty(n))for(t in c={},o[n])o[n].hasOwnProperty(t)&&ARCS.TransitionNetwork.build(s[t],c).promise.then((function(){var e;for(e in c)c.hasOwnProperty(e)&&c[e].abort();u(o[n][t])}));i=n,r.emit("requestSheet",i),i===e&&r.emit("requestTermination")};this.setInitialState=function(n){i=t=n},this.setFinalState=function(n){e=n},this.addTransition=function(n,t,e){var i,r=/([A-Za-z_]\w*)/g;try{var c;if("string"==typeof(c=ARCS.EventLogicParser.parse(t)))a(c);else for(;null!==(i=r.exec(t));)a(i[0]);s[t]=c,void 0===o[n]&&(o[n]={}),o[n][t]=e}catch(n){}},this.setToken=function(n){c.hasOwnProperty(n)&&c[n].accept()},this.setTransitions=function(n){var t,e;for(t in n)if(n.hasOwnProperty(t))for(e in n[t])n[t].hasOwnProperty(e)&&this.addTransition(t,e,n[t][e])},this.start=function(){console.log("statemachine",this,t,n),u(t)},void 0!==n&&(t=n.initial,e=n.final,this.setTransitions(n.transitions),i="")}),["setToken"],["requestSheet","requestTermination"]),ARCS.Application=function(){var n,t=new ARCS.Context,e={},o={},i=[],r=this,s="";this.export=function(){return{context:t,controller:t.getComponentName(o),sheets:e}},this.getContext=function(){return t},this.getSheetList=function(){return Object.keys(e)},this.getSheet=function(n){return e[n]},this.addSheet=function(n,o){e[n]=o,o.setContext(t)},this.removeSheet=function(n){delete e[n]},n=function(){var n,i,s;for(i=t.getComponent(o),o=i,s=Object.keys(e),n=0;n<s.length;n++)(i=new ARCS.Sheet(t)).import(e[s[n]],t),e[s[n]]=i;ARCS.Component.connect(o,"requestSheet",r,"setSheet"),ARCS.Component.connect(o,"requestTermination",r,"finish"),o.start()},this.setController=function(n){o=t.getComponent(n)},this.setSheet=function(n){e.hasOwnProperty(n)?(s&&e[s].deactivate(),e[s=n].activate()):console.warn("[ARCS] Tried to activate hollow sheet named: "+n)},this.finish=function(){s&&e[s].deactivate()},this.import=function(n){t=new ARCS.Context(n.context),e=n.sheets,void 0===(o=n.controller)&&console.error("[ARCS] Undefined controller. Cannot start application.")},this.setFactory=function(n,t){factories[n]=t},this.setDependency=function(n){i[n]={}},this.start=function(){console.log("[ARCS] Starting application..."),t.instanciate().then(n)}},ARCS.Application.setDependency=function(n,t){n.setDependency(t)},ARCS.Component.create(ARCS.Application),ARCS.Application.slot("setSheet"),ARCS.Application.slot("finish");export{ARCS as default}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
build/package.json
0 → 100644
1 | +{ "type": "module"} |
1 | -arcs_module( | 1 | + |
2 | - function (ARCS) { | 2 | +import ARCS from '../build/arcs.js'; |
3 | - var Animator; | 3 | + |
4 | +var Animator; | ||
4 | 5 | ||
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; |
15 | - | 16 | + |
16 | - var tick = function () { | 17 | + var tick = function () { |
17 | - if (paused === false) { | 18 | + if (paused === false) { |
18 | - requestAnimationFrame(tick); | 19 | + requestAnimationFrame(tick); |
19 | - self.emit("onAnimationFrame"); | 20 | + self.emit("onAnimationFrame"); |
20 | - } | 21 | + } |
21 | - } | 22 | + } |
22 | - | 23 | + |
23 | - /** | 24 | + /** |
24 | - * Starts requesting frames for animation. As soon as it is started, | 25 | + * Starts requesting frames for animation. As soon as it is started, |
25 | - * the signal <b>onAnimationFrame</b> is periodically triggered. | 26 | + * the signal <b>onAnimationFrame</b> is periodically triggered. |
26 | - * @slot | 27 | + * @slot |
27 | - * @emits onAnimationFrame | 28 | + * @emits onAnimationFrame |
28 | - * @function Animator#start | 29 | + * @function Animator#start |
29 | - */ | 30 | + */ |
30 | - this.start = function () { | 31 | + this.start = function () { |
31 | - paused = false; | 32 | + paused = false; |
32 | - tick(); | 33 | + tick(); |
33 | - }; | 34 | + }; |
34 | - | 35 | + |
35 | - /** | 36 | + /** |
36 | - * Stops requesting frames for animation. | 37 | + * Stops requesting frames for animation. |
37 | - * @slot | 38 | + * @slot |
38 | - * @function Animator#stop | 39 | + * @function Animator#stop |
39 | - */ | 40 | + */ |
40 | - this.stop = function () { | 41 | + this.stop = function () { |
41 | - paused = true; | 42 | + paused = true; |
42 | - }; | 43 | + }; |
43 | - | 44 | + |
44 | - /** | 45 | + /** |
45 | - * Signals that an animation frame is ready. | 46 | + * Signals that an animation frame is ready. |
46 | - * @signal | 47 | + * @signal |
47 | - * @function Animator#onAnimationFrame | 48 | + * @function Animator#onAnimationFrame |
48 | - */ | 49 | + */ |
49 | - }, | 50 | + }, |
50 | - ['start','stop'], | 51 | + ['start','stop'], |
51 | - 'onAnimationFrame' | 52 | + 'onAnimationFrame' |
52 | - ); | 53 | +); |
53 | 54 | ||
54 | - return {Animator: Animator}; | ||
55 | - } | ||
56 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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 | + | ||
5 | +var ARUCODetector; | ||
4 | 6 | ||
5 | - /** | 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 | ||
14 | - /*1 Instanciate here the detector */ | 16 | + /*1 Instanciate here the detector */ |
15 | - detector = new AR.Detector(); | 17 | + detector = new AR.Detector(); |
16 | 18 | ||
17 | - /** | 19 | + /** |
18 | - * Detects ARUCO markers in the given image. | 20 | + * Detects ARUCO markers in the given image. |
19 | - * If markers are detected, this slot triggers the signal <b>onMarkers</b>. | 21 | + * If markers are detected, this slot triggers the signal <b>onMarkers</b>. |
20 | - * @param image {obj} the image in which markers should be detected | 22 | + * @param image {obj} the image in which markers should be detected |
21 | - * @emits onMarkers | 23 | + * @emits onMarkers |
22 | - * @function ARUCODetector#detect | 24 | + * @function ARUCODetector#detect |
23 | - * @slot | 25 | + * @slot |
24 | - */ | 26 | + */ |
25 | - this.detect = function (image) { | 27 | + this.detect = function (image) { |
26 | - /*1 recover markers from image | 28 | + /*1 recover markers from image |
27 | - * then send they will be sent through onMarkers event | 29 | + * then send they will be sent through onMarkers event |
28 | - */ | 30 | + */ |
29 | - var markers = detector.detect(image); | 31 | + var markers = detector.detect(image); |
30 | - this.emit("onMarkers",markers); | 32 | + this.emit("onMarkers",markers); |
31 | - }; | 33 | + }; |
32 | - | 34 | + |
33 | - /** | 35 | + /** |
34 | - * Signal that is emitted when markers are detected in an image. | 36 | + * Signal that is emitted when markers are detected in an image. |
35 | - * @function ARUCODetector#onMarkers | 37 | + * @function ARUCODetector#onMarkers |
36 | - * @param markers {Marker[]} Array of detected markers. | 38 | + * @param markers {Marker[]} Array of detected markers. |
37 | - * @signal | 39 | + * @signal |
38 | - */ | 40 | + */ |
39 | - | 41 | + |
40 | - /** | 42 | + /** |
41 | - * @typedef {Object} Marker | 43 | + * @typedef {Object} Marker |
42 | - * @property {number} id - marker id | 44 | + * @property {number} id - marker id |
43 | - * @property {Object} pose - computed pose for the marker | 45 | + * @property {Object} pose - computed pose for the marker |
44 | - * @property {number[]} pose.rotation - rotation matrix (3x3) | 46 | + * @property {number[]} pose.rotation - rotation matrix (3x3) |
45 | - * @property {number[]} pose.position - translation (3 components) | 47 | + * @property {number[]} pose.position - translation (3 components) |
46 | - */ | 48 | + */ |
47 | - | ||
48 | - }, | ||
49 | - 'detect', | ||
50 | - ['onMarkers'] | ||
51 | - ); | ||
52 | 49 | ||
53 | - return {ARUCODetector: ARUCODetector}; | ||
54 | }, | 50 | }, |
55 | - [ | ||
56 | - {name:"deps/cv/index", exports:"CV"}, | ||
57 | - {name:"deps/aruco/index",exports:"AR"} | ||
58 | - ] | ||
59 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
51 | + 'detect', | ||
52 | + ['onMarkers'] | ||
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'; |
6 | - * @class ARViewer | 3 | +import * as THREE from '../deps/three.js/index.js'; |
7 | - * @classdesc Simple compositing viewer for augmented reality | 4 | +import FrustumCamera from '../deps/three.js/frustumcamera.js'; |
8 | - */ | 5 | + |
9 | - ARViewer = ARCS.Component.create( | 6 | +var ARViewer; |
10 | - /** @lends ARViewer.prototype */ | 7 | + |
11 | - function () { | 8 | +/** |
12 | - var container, sourceAspectRatio, sourceHeight; | 9 | + * @class ARViewer |
10 | + * @classdesc Simple compositing viewer for augmented reality | ||
11 | + */ | ||
12 | +ARViewer = ARCS.Component.create( | ||
13 | + /** @lends ARViewer.prototype */ | ||
14 | + function () { | ||
15 | + var container, sourceAspectRatio, sourceHeight; | ||
16 | + | ||
17 | + var renderer, scene2d, scene3d, camera2d, camera3d, videoSource, videoTexture; | ||
18 | + | ||
19 | + var aspectRatioKept = true; | ||
20 | + | ||
21 | + var sceneId; | ||
22 | + | ||
23 | + | ||
24 | + // scenegraph initializations | ||
25 | + scene2d = new THREE.Scene(); | ||
26 | + camera2d = new THREE.OrthographicCamera(-0.5, 0.5, 0.5, -0.5); | ||
27 | + scene2d.add(camera2d); | ||
28 | + | ||
29 | + scene3d = new THREE.Scene(); | ||
30 | + | ||
31 | + /** | ||
32 | + * Initializes the widgets (HTML elements) needed as a basis | ||
33 | + * for the viewer. | ||
34 | + * @param cName {string} id of the container that will enclose the scene renderer | ||
35 | + * @param vName {string} id of the element at the source of the video stream | ||
36 | + * @slot | ||
37 | + * @function ARViewer#setWidgets | ||
38 | + */ | ||
39 | + this.setWidgets = function(cName,vName) { | ||
40 | + container = document.getElementById(cName); | ||
41 | + videoSource = document.getElementById(vName); | ||
42 | + var containerStyle = window.getComputedStyle(container); | ||
43 | + var videoStyle = window.getComputedStyle(videoSource); | ||
44 | + sourceAspectRatio = parseInt(videoStyle.width) / parseInt(videoStyle.height); | ||
45 | + sourceHeight = parseInt(videoStyle.height); | ||
13 | 46 | ||
14 | - var renderer, scene2d, scene3d, camera2d, camera3d, videoSource, videoTexture; | 47 | + container.width = parseInt(containerStyle.width); |
15 | - | 48 | + container.height = parseInt(containerStyle.height); |
16 | - var aspectRatioKept = true; | ||
17 | - | ||
18 | - var sceneId; | ||
19 | - | ||
20 | - | ||
21 | - // scenegraph initializations | ||
22 | - scene2d = new THREE.Scene(); | ||
23 | - camera2d = new THREE.OrthographicCamera(-0.5, 0.5, 0.5, -0.5); | ||
24 | - scene2d.add(camera2d); | ||
25 | - | ||
26 | - scene3d = new THREE.Scene(); | ||
27 | 49 | ||
28 | - /** | 50 | + renderer = new THREE.WebGLRenderer(); |
29 | - * Initializes the widgets (HTML elements) needed as a basis | 51 | + renderer.setClearColor(0x000000, 1); |
30 | - * for the viewer. | 52 | + renderer.setSize(container.width, container.height); |
31 | - * @param cName {string} id of the container that will enclose the scene renderer | 53 | + container.appendChild(renderer.domElement); |
32 | - * @param vName {string} id of the element at the source of the video stream | ||
33 | - * @slot | ||
34 | - * @function ARViewer#setWidgets | ||
35 | - */ | ||
36 | - this.setWidgets = function(cName,vName) { | ||
37 | - container = document.getElementById(cName); | ||
38 | - videoSource = document.getElementById(vName); | ||
39 | - var containerStyle = window.getComputedStyle(container); | ||
40 | - var videoStyle = window.getComputedStyle(videoSource); | ||
41 | - sourceAspectRatio = parseInt(videoStyle.width) / parseInt(videoStyle.height); | ||
42 | - sourceHeight = parseInt(videoStyle.height); | ||
43 | - | ||
44 | - container.width = parseInt(containerStyle.width); | ||
45 | - container.height = parseInt(containerStyle.height); | ||
46 | 54 | ||
47 | - renderer = new THREE.WebGLRenderer(); | 55 | + var theta = 45; //2*Math.atan2(container.height/2,focalLength)*180/3.14159265; |
48 | - renderer.setClearColor(0x000000, 1); | 56 | + camera3d = new THREE.PerspectiveCamera(theta, container.width / container.height, 0.01, 10000); |
49 | - renderer.setSize(container.width, container.height); | 57 | + scene3d.add(camera3d); |
50 | - container.appendChild(renderer.domElement); | 58 | + |
51 | - | 59 | + var _light = new THREE.DirectionalLight(0xffffff); |
52 | - var theta = 45; //2*Math.atan2(container.height/2,focalLength)*180/3.14159265; | 60 | + _light.position.set(0,5,5); |
53 | - camera3d = new THREE.PerspectiveCamera(theta, container.width / container.height, 0.01, 10000); | 61 | + |
54 | - scene3d.add(camera3d); | 62 | + scene3d.add(_light); |
55 | - | ||
56 | - var _light = new THREE.DirectionalLight(0xffffff); | ||
57 | - _light.position.set(0,5,5); | ||
58 | - | ||
59 | - scene3d.add(_light); | ||
60 | - | ||
61 | - if ( THREE.VideoTexture !== undefined) { | ||
62 | - console.log("Using video texture since it is available"); | ||
63 | - videoTexture = new THREE.VideoTexture(videoSource); | ||
64 | - } else { | ||
65 | - console.log("Falling back on simple texture"); | ||
66 | - videoTexture = new THREE.Texture(videoSource); | ||
67 | - } | ||
68 | - var geometry = new THREE.PlaneGeometry(1.0, 1.0); | ||
69 | - var material = new THREE.MeshBasicMaterial( {map: videoTexture, depthTest: false, depthWrite: false} ); | ||
70 | - var mesh = new THREE.Mesh(geometry, material); | ||
71 | - var textureObject = new THREE.Object3D(); | ||
72 | - textureObject.position.z = -1; | ||
73 | - textureObject.add(mesh); | ||
74 | - scene2d.add(textureObject); | ||
75 | - | ||
76 | - updateAspectRatio(); | ||
77 | - }; | ||
78 | - | ||
79 | - /** | ||
80 | - * Set the focal length of the virtual camera for very simple | ||
81 | - * camera models. | ||
82 | - * @param focal {numeric} focal length (in pixels) of the camera. | ||
83 | - * @slot | ||
84 | - * @function ARViewer#setFocal | ||
85 | - */ | ||
86 | - this.setFocal = function (focal) { | ||
87 | - var theta = 2*Math.atan(0.5*sourceHeight/focal)*180/Math.PI; | ||
88 | - camera3d.fov = theta; | ||
89 | - console.log(theta); | ||
90 | - //camera3d.updateProjectionMatrix(); | ||
91 | - updateAspectRatio(); | ||
92 | - }; | ||
93 | 63 | ||
94 | - | 64 | + if ( THREE.VideoTexture !== undefined) { |
95 | - /** | 65 | + console.log("Using video texture since it is available"); |
96 | - * Set intrinsic camera parameters for the virtual camera | 66 | + videoTexture = new THREE.VideoTexture(videoSource); |
97 | - * @param intrinsics {array} linearized array of camera parameters | 67 | + } else { |
98 | - * @slot | 68 | + console.log("Falling back on simple texture"); |
99 | - * @function ARViewer#setIntrinsics | 69 | + videoTexture = new THREE.Texture(videoSource); |
100 | - */ | 70 | + } |
101 | - this.setIntrinsics = function (parameters) { | 71 | + var geometry = new THREE.PlaneGeometry(1.0, 1.0); |
102 | - /*3 set here the intrinsic parameters of camera3d | 72 | + var material = new THREE.MeshBasicMaterial( {map: videoTexture, depthTest: false, depthWrite: false} ); |
103 | - * camera3d should be of type THREE.FrustumCamera | 73 | + var mesh = new THREE.Mesh(geometry, material); |
104 | - * you should frustum accordingly to intrinsic parameters | 74 | + var textureObject = new THREE.Object3D(); |
105 | - */ | 75 | + textureObject.position.z = -1; |
106 | - | 76 | + textureObject.add(mesh); |
107 | - // camera3d = new THREE.FrustumCamera( ... ) ; | 77 | + scene2d.add(textureObject); |
108 | - | 78 | + |
109 | - | 79 | + updateAspectRatio(); |
110 | - }; | 80 | + }; |
111 | - | ||
112 | - | ||
113 | - /** | ||
114 | - * Set extrinsic camera parameters for the virtual camera | ||
115 | - * @param markers {array} an array of markers | ||
116 | - * @slot | ||
117 | - * @function ARViewer#setExtrinsics | ||
118 | - */ | ||
119 | - this.setExtrinsics = function (markers) { | ||
120 | - /*2 set here the extrinsic parameters of camera3d | ||
121 | - * Each marker has 3 major properties : | ||
122 | - * - id is the marker id; | ||
123 | - * - pose.rotation gives its orientation using a rotation matrix | ||
124 | - * and is a 3x3 array | ||
125 | - * - pose.position gives its position with respect to the camera | ||
126 | - * and is a vector with 3 components. | ||
127 | - */ | ||
128 | - var i ; | ||
129 | - for ( i = 0; i < markers.length; i++) { | ||
130 | - if ( markers[i].id === sceneId ) { | ||
131 | - // put here the code to set orientation and position of object camera3d | ||
132 | - // see also documentation of Object3D (API Three.js) | ||
133 | - // since a camera is an Object3D | ||
134 | 81 | ||
135 | - var rotation = markers[i].pose.rotation; | 82 | + /** |
136 | - var translation = markers[i].pose.position; | 83 | + * Set the focal length of the virtual camera for very simple |
137 | - var matrix = new THREE.Matrix4( | 84 | + * camera models. |
138 | - rotation[0][0], rotation[0][1], rotation[0][2], translation[0], | 85 | + * @param focal {numeric} focal length (in pixels) of the camera. |
139 | - rotation[1][0], rotation[1][1], rotation[1][2], translation[1], | 86 | + * @slot |
140 | - rotation[2][0], rotation[2][1], rotation[2][2], translation[2], | 87 | + * @function ARViewer#setFocal |
141 | - 0 , 0, 0, 1); | 88 | + */ |
89 | + this.setFocal = function (focal) { | ||
90 | + var theta = 2*Math.atan(0.5*sourceHeight/focal)*180/Math.PI; | ||
91 | + camera3d.fov = theta; | ||
92 | + console.log(theta); | ||
93 | + //camera3d.updateProjectionMatrix(); | ||
94 | + updateAspectRatio(); | ||
95 | + }; | ||
96 | + | ||
97 | + | ||
98 | + /** | ||
99 | + * Set intrinsic camera parameters for the virtual camera | ||
100 | + * @param intrinsics {array} linearized array of camera parameters | ||
101 | + * @slot | ||
102 | + * @function ARViewer#setIntrinsics | ||
103 | + */ | ||
104 | + this.setIntrinsics = function (parameters) { | ||
105 | + /*3 set here the intrinsic parameters of camera3d | ||
106 | + * camera3d should be of type THREE.FrustumCamera | ||
107 | + * you should frustum accordingly to intrinsic parameters | ||
108 | + */ | ||
109 | + | ||
110 | + // camera3d = new THREE.FrustumCamera( ... ) ; | ||
111 | + | ||
112 | + | ||
113 | + }; | ||
114 | + | ||
142 | 115 | ||
143 | - /*var r = new THREE.Euler(); | 116 | + /** |
144 | - r.setFromRotationMatrix(matrix); | 117 | + * Set extrinsic camera parameters for the virtual camera |
145 | - camera3d.rotation.x = r.x; | 118 | + * @param markers {array} an array of markers |
146 | - camera3d.rotation.y = r.y; | 119 | + * @slot |
147 | - camera3d.rotation.z = r.z;*/ | 120 | + * @function ARViewer#setExtrinsics |
148 | - | 121 | + */ |
149 | - camera3d.position.x = translation[0]; | 122 | + this.setExtrinsics = function (markers) { |
150 | - camera3d.position.y = translation[1]; | 123 | + /*2 set here the extrinsic parameters of camera3d |
151 | - camera3d.position.z = translation[2]; | 124 | + * Each marker has 3 major properties : |
152 | - | 125 | + * - id is the marker id; |
153 | - /*objRoot.scale.x = 1; | 126 | + * - pose.rotation gives its orientation using a rotation matrix |
154 | - objRoot.scale.y = 1; | 127 | + * and is a 3x3 array |
155 | - objRoot.scale.z = 1;*/ | 128 | + * - pose.position gives its position with respect to the camera |
156 | - | 129 | + * and is a vector with 3 components. |
157 | - | 130 | + */ |
158 | - } | 131 | + var i ; |
159 | - } | 132 | + for ( i = 0; i < markers.length; i++) { |
133 | + if ( markers[i].id === sceneId ) { | ||
134 | + // put here the code to set orientation and position of object camera3d | ||
135 | + // see also documentation of Object3D (API Three.js) | ||
136 | + // since a camera is an Object3D | ||
137 | + console.log("viewing"); | ||
138 | + | ||
139 | + var rotation = markers[i].pose.rotation; | ||
140 | + var translation = markers[i].pose.position; | ||
141 | + var matrix = new THREE.Matrix4( | ||
142 | + rotation[0][0], rotation[0][1], rotation[0][2], translation[0], | ||
143 | + rotation[1][0], rotation[1][1], rotation[1][2], translation[1], | ||
144 | + rotation[2][0], rotation[2][1], rotation[2][2], translation[2], | ||
145 | + 0 , 0, 0, 1); | ||
146 | + | ||
147 | + /*var r = new THREE.Euler(); | ||
148 | + r.setFromRotationMatrix(matrix); | ||
149 | + camera3d.rotation.x = r.x; | ||
150 | + camera3d.rotation.y = r.y; | ||
151 | + camera3d.rotation.z = r.z;*/ | ||
160 | 152 | ||
153 | + camera3d.position.x = translation[0]; | ||
154 | + camera3d.position.y = translation[1]; | ||
155 | + camera3d.position.z = translation[2]; | ||
156 | + | ||
157 | + /*objRoot.scale.x = 1; | ||
158 | + objRoot.scale.y = 1; | ||
159 | + objRoot.scale.z = 1;*/ | ||
161 | 160 | ||
162 | - }; | ||
163 | - | ||
164 | - /** | ||
165 | - * Set the scene id in case we should set extrinsic parameters. | ||
166 | - * @param id {number} the id of the scene | ||
167 | - * @function ARViewer#setSceneId | ||
168 | - * @slot | ||
169 | - */ | ||
170 | - this.setSceneId = function (id) { | ||
171 | - sceneId = id; | ||
172 | - }; | ||
173 | - | ||
174 | - /** | ||
175 | - * Sets the size of the viewport in pixels to render the scene | ||
176 | - * @param width {number} width of the viewport | ||
177 | - * @param height {number} height of the viewport | ||
178 | - * @slot | ||
179 | - * @function ARViewer#setSize | ||
180 | - */ | ||
181 | - this.setSize = function(width, height) { | ||
182 | - var W = width|0; | ||
183 | - var H = height|0; | ||
184 | 161 | ||
185 | - container.width = width; | 162 | + } |
186 | - container.height = height; | 163 | + } |
187 | - renderer.setSize(W,H); | 164 | + |
165 | + | ||
166 | + }; | ||
167 | + | ||
168 | + /** | ||
169 | + * Set the scene id in case we should set extrinsic parameters. | ||
170 | + * @param id {number} the id of the scene | ||
171 | + * @function ARViewer#setSceneId | ||
172 | + * @slot | ||
173 | + */ | ||
174 | + this.setSceneId = function (id) { | ||
175 | + sceneId = id; | ||
176 | + }; | ||
177 | + | ||
178 | + /** | ||
179 | + * Sets the size of the viewport in pixels to render the scene | ||
180 | + * @param width {number} width of the viewport | ||
181 | + * @param height {number} height of the viewport | ||
182 | + * @slot | ||
183 | + * @function ARViewer#setSize | ||
184 | + */ | ||
185 | + this.setSize = function(width, height) { | ||
186 | + var W = width|0; | ||
187 | + var H = height|0; | ||
188 | + | ||
189 | + container.width = width; | ||
190 | + container.height = height; | ||
191 | + renderer.setSize(W,H); | ||
188 | 192 | ||
189 | - updateAspectRatio(); | 193 | + updateAspectRatio(); |
190 | - }; | 194 | + }; |
195 | + | ||
196 | + /** | ||
197 | + * Tells to keep the aspect ratio of the camera. | ||
198 | + * It avoids deformations of the augmented scene. | ||
199 | + * @param b {boolean} set it to <tt>true</tt> to keep aspect ratio, <tt>false</tt> otherwise | ||
200 | + * @slot | ||
201 | + * @function ARViewer#keepAspectRatio | ||
202 | + */ | ||
203 | + this.keepAspectRatio = function (b) { | ||
204 | + aspectRatioKept = b; | ||
205 | + }; | ||
206 | + | ||
207 | + var updateAspectRatio = function () { | ||
208 | + var cAspectRatio = container.width / container.height; | ||
209 | + var actualWidth, actualHeight; | ||
210 | + var xoff, yoff; | ||
191 | 211 | ||
192 | - /** | 212 | + if (aspectRatioKept == true) { |
193 | - * Tells to keep the aspect ratio of the camera. | 213 | + // cameras have the source aspect ratio |
194 | - * It avoids deformations of the augmented scene. | 214 | + camera2d.aspect = sourceAspectRatio; |
195 | - * @param b {boolean} set it to <tt>true</tt> to keep aspect ratio, <tt>false</tt> otherwise | 215 | + camera2d.updateProjectionMatrix(); |
196 | - * @slot | 216 | + camera3d.aspect = sourceAspectRatio; |
197 | - * @function ARViewer#keepAspectRatio | 217 | + camera3d.updateProjectionMatrix(); |
198 | - */ | 218 | + // then, we should adjust viewport accordingly. |
199 | - this.keepAspectRatio = function (b) { | 219 | + if (cAspectRatio > sourceAspectRatio) { |
200 | - aspectRatioKept = b; | 220 | + actualHeight = container.height; |
201 | - }; | 221 | + actualWidth = actualHeight * sourceAspectRatio; |
222 | + } else { | ||
223 | + actualWidth = container.width; | ||
224 | + actualHeight = actualWidth / sourceAspectRatio; | ||
225 | + } | ||
202 | 226 | ||
203 | - var updateAspectRatio = function () { | 227 | + xoff = (container.width - actualWidth) / 2 ; |
204 | - var cAspectRatio = container.width / container.height; | 228 | + yoff = (container.height - actualHeight) / 2; |
205 | - var actualWidth, actualHeight; | 229 | + renderer.setViewport(xoff, yoff, actualWidth, actualHeight); |
206 | - var xoff, yoff; | 230 | + } else { |
207 | - | 231 | + // for 3D camera, we will have to recompute the actual |
208 | - if (aspectRatioKept == true) { | 232 | + // aspect ratio. |
209 | - // cameras have the source aspect ratio | ||
210 | - camera2d.aspect = sourceAspectRatio; | ||
211 | - camera2d.updateProjectionMatrix(); | ||
212 | - camera3d.aspect = sourceAspectRatio; | ||
213 | - camera3d.updateProjectionMatrix(); | ||
214 | - // then, we should adjust viewport accordingly. | ||
215 | - if (cAspectRatio > sourceAspectRatio) { | ||
216 | - actualHeight = container.height; | ||
217 | - actualWidth = actualHeight * sourceAspectRatio; | ||
218 | - } else { | ||
219 | - actualWidth = container.width; | ||
220 | - actualHeight = actualWidth / sourceAspectRatio; | ||
221 | - } | ||
222 | - | ||
223 | - xoff = (container.width - actualWidth) / 2 ; | ||
224 | - yoff = (container.height - actualHeight) / 2; | ||
225 | - renderer.setViewport(xoff, yoff, actualWidth, actualHeight); | ||
226 | - } else { | ||
227 | - // for 3D camera, we will have to recompute the actual | ||
228 | - // aspect ratio. | ||
229 | - | ||
230 | - // but first reset viewport, just in case | ||
231 | - renderer.setViewport(0, 0, container.width, container.height); | ||
232 | - camera2d.aspect = cAspectRatio ; | ||
233 | - camera2d.updateProjectionMatrix(); | ||
234 | - camera3d.aspect = sourceAspectRatio; | ||
235 | - camera3d.updateProjectionMatrix(); | ||
236 | - console.log(camera3d.projectionMatrix); | ||
237 | - } | ||
238 | - | ||
239 | - }; | ||
240 | 233 | ||
241 | - /** | 234 | + // but first reset viewport, just in case |
242 | - * Adds new objects to the current 3D scene | 235 | + renderer.setViewport(0, 0, container.width, container.height); |
243 | - * @param scene {object} 3D object as defined by Three.js to add to the scene. | 236 | + camera2d.aspect = cAspectRatio ; |
244 | - * @slot | 237 | + camera2d.updateProjectionMatrix(); |
245 | - * @function ARViewer#addScene | 238 | + camera3d.aspect = sourceAspectRatio; |
246 | - */ | 239 | + camera3d.updateProjectionMatrix(); |
247 | - this.addScene = function (scene) { | 240 | + console.log(camera3d.projectionMatrix); |
248 | - scene3d.add(scene); | 241 | + } |
249 | - }; | ||
250 | 242 | ||
251 | - /** | 243 | + }; |
252 | - * Removes an object from the current 3D scene | 244 | + |
253 | - * @param scene {object} 3D object as defined by Three.js to remove from the scene. | 245 | + /** |
254 | - * @slot | 246 | + * Adds new objects to the current 3D scene |
255 | - * @function ARViewer#removeScene | 247 | + * @param scene {object} 3D object as defined by Three.js to add to the scene. |
256 | - */ | 248 | + * @slot |
257 | - this.removeScene = function (scene) { | 249 | + * @function ARViewer#addScene |
258 | - scene3d.remove(scene); | 250 | + */ |
259 | - }; | 251 | + this.addScene = function (scene) { |
260 | - | 252 | + scene3d.add(scene); |
261 | - /** | 253 | + }; |
262 | - * Triggers the rendering of the composite scene | 254 | + |
263 | - * @function ARViewer#render | 255 | + /** |
264 | - * @slot | 256 | + * Removes an object from the current 3D scene |
265 | - */ | 257 | + * @param scene {object} 3D object as defined by Three.js to remove from the scene. |
266 | - this.render = function () { | 258 | + * @slot |
267 | - videoTexture.needsUpdate = true; | 259 | + * @function ARViewer#removeScene |
268 | - renderer.autoClear = false; | 260 | + */ |
269 | - renderer.clear(); | 261 | + this.removeScene = function (scene) { |
270 | - renderer.render(scene2d, camera2d); | 262 | + scene3d.remove(scene); |
271 | - renderer.render(scene3d, camera3d); | 263 | + }; |
272 | - }; | 264 | + |
273 | - | 265 | + /** |
274 | - /** | 266 | + * Triggers the rendering of the composite scene |
275 | - * Computes the ideal camera position to see the whole 3D scene. | 267 | + * @function ARViewer#render |
276 | - * Mainly useful for debugging | 268 | + * @slot |
277 | - * @function ARViewer#viewAll | 269 | + */ |
278 | - * @slot | 270 | + this.render = function () { |
279 | - */ | 271 | + videoTexture.needsUpdate = true; |
280 | - this.viewAll = function () { | 272 | + renderer.autoClear = false; |
281 | - var box = new THREE.Box3(); | 273 | + renderer.clear(); |
282 | - box.setFromObject(scene3d); | 274 | + renderer.render(scene2d, camera2d); |
283 | - var center = box.center(); | 275 | + renderer.render(scene3d, camera3d); |
284 | - var radius = box.getBoundingSphere().radius; | 276 | + }; |
285 | - | 277 | + |
286 | - camera3d.position.x = center.x ; | 278 | + /** |
287 | - camera3d.position.y = center.y ; | 279 | + * Computes the ideal camera position to see the whole 3D scene. |
288 | - var c = Math.cos(camera3d.fov/2); | 280 | + * Mainly useful for debugging |
289 | - var s = Math.sin(camera3d.fov/2); | 281 | + * @function ARViewer#viewAll |
290 | - | 282 | + * @slot |
291 | - camera3d.position.z = center.z + 1.2 * radius*s*( 1 + s / c ) ; | 283 | + */ |
292 | - }; | 284 | + this.viewAll = function () { |
293 | - | 285 | + var box = new THREE.Box3(); |
294 | - /** | 286 | + box.setFromObject(scene3d); |
295 | - * Resets the position of the camera to the origin of the scene coordinate system | 287 | + var center = box.center(); |
296 | - * @slot | 288 | + var sphere = new THREE.Sphere(); |
297 | - * @function ARViewer#resetCamera | 289 | + box.getBoundingSphere(sphere); |
298 | - */ | 290 | + var radius = sphere.radius; |
299 | - this.resetCamera = function () { | ||
300 | - camera3d.position.x = camera3d.position.y = camera3d.position.z = 0; | ||
301 | - camera3d.up = THREE.Object3D.DefaultUp.clone(); | ||
302 | - } | ||
303 | 291 | ||
304 | - }, | 292 | + camera3d.position.x = center.x ; |
305 | - /** @lends ARViewer.slots */ | 293 | + camera3d.position.y = center.y ; |
306 | - [ | 294 | + var c = Math.cos(camera3d.fov/2); |
307 | - 'setWidgets','setFocal','viewAll','setSize','addScene', | 295 | + var s = Math.sin(camera3d.fov/2); |
308 | - 'resetCamera','removeScene','render','keepAspectRatio', | 296 | + |
309 | - 'setExtrinsics', 'setIntrinsics' | 297 | + camera3d.position.z = center.z + 1.2 * radius*s*( 1 + s / c ) ; |
310 | - | 298 | + }; |
311 | - ], | 299 | + |
312 | - [] | 300 | + /** |
313 | - ); | 301 | + * Resets the position of the camera to the origin of the scene coordinate system |
314 | - return {ARViewer: ARViewer}; | 302 | + * @slot |
303 | + * @function ARViewer#resetCamera | ||
304 | + */ | ||
305 | + this.resetCamera = function () { | ||
306 | + camera3d.position.x = camera3d.position.y = camera3d.position.z = 0; | ||
307 | + camera3d.up = THREE.Object3D.DefaultUp.clone(); | ||
308 | + } | ||
309 | + | ||
315 | }, | 310 | }, |
311 | +<<<<<<< HEAD | ||
316 | [ 'deps/three.js/index','deps/three.js/frustumcamera'] | 312 | [ 'deps/three.js/index','deps/three.js/frustumcamera'] |
317 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
313 | +); | ||
314 | +======= | ||
315 | + /** @lends ARViewer.slots */ | ||
316 | + [ | ||
317 | + 'setWidgets','setFocal','viewAll','setSize','addScene', | ||
318 | + 'resetCamera','removeScene','render','keepAspectRatio', | ||
319 | + 'setExtrinsics', 'setIntrinsics' | ||
320 | + | ||
321 | + ], | ||
322 | + [] | ||
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 | ||
4 | +var Console; | ||
5 | +/** | ||
6 | + * @class Console | ||
7 | + * @classdesc Redirects console messages to a given HTML element in the page. | ||
8 | + * @param id {string} id of the HTML element in which console messages will be added. | ||
9 | + */ | ||
10 | +Console = ARCS.Component.create( | ||
11 | + function (id) { | ||
12 | + if (id === undefined) { | ||
13 | + return ; | ||
14 | + } | ||
15 | + | ||
16 | + var output = document.getElementById(id); | ||
17 | + | ||
18 | + if (output) { | ||
19 | + window.console = { | ||
20 | + timeRef: new Date().getTime(), | ||
21 | + output : output, | ||
22 | + display: function(color,args) { | ||
23 | + var s = document.createElement("span"); | ||
24 | + s.style.color=color; | ||
25 | + var elapsed = (new Date().getTime() - this.timeRef); | ||
3 | 26 | ||
4 | -arcs_module( | 27 | + s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span> ' + Array.prototype.join.call(args, ' '); |
5 | - function(ARCS) { | 28 | + output.appendChild(s); |
6 | - var Console; | 29 | + output.appendChild(document.createElement("br")); |
7 | - /** | 30 | + }, |
8 | - * @class Console | 31 | + log: function () { |
9 | - * @classdesc Redirects console messages to a given HTML element in the page. | 32 | + this.display('green',arguments); |
10 | - * @param id {string} id of the HTML element in which console messages will be added. | 33 | + }, |
11 | - */ | 34 | + error: function () { |
12 | - Console = ARCS.Component.create( | 35 | + this.display('red',arguments); |
13 | - function (id) { | 36 | + }, |
14 | - if (id === undefined) { | 37 | + warn: function () { |
15 | - return ; | 38 | + this.display('orange',arguments); |
16 | } | 39 | } |
17 | - | 40 | + }; |
18 | - var output = document.getElementById(id); | 41 | + } |
19 | - | ||
20 | - if (output) { | ||
21 | - window.console = { | ||
22 | - timeRef: new Date().getTime(), | ||
23 | - output : output, | ||
24 | - display: function(color,args) { | ||
25 | - var s = document.createElement("span"); | ||
26 | - s.style.color=color; | ||
27 | - var elapsed = (new Date().getTime() - this.timeRef); | ||
28 | - | ||
29 | - s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span>' + Array.prototype.join.call(args, ' '); | ||
30 | - output.appendChild(s); | ||
31 | - output.appendChild(document.createElement("br")); | ||
32 | - }, | ||
33 | - log: function () { | ||
34 | - this.display('green',arguments); | ||
35 | - }, | ||
36 | - error: function () { | ||
37 | - this.display('red',arguments); | ||
38 | - }, | ||
39 | - warn: function () { | ||
40 | - this.display('orange',arguments); | ||
41 | - } | ||
42 | - }; | ||
43 | - } | ||
44 | - } | ||
45 | - ); | ||
46 | - return { Console: Console}; | ||
47 | } | 42 | } |
43 | +); | ||
44 | + | ||
48 | 45 | ||
49 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
46 | +export default { Console: Console}; | ... | ... |
... | @@ -5,102 +5,99 @@ | ... | @@ -5,102 +5,99 @@ |
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; | ||
10 | - /** @exports loop */ | ||
11 | - //console.log("loop: ", ARCS); | ||
12 | - /** | ||
13 | - * @class Loop | ||
14 | - * @classdesc loop component creation using a compact style. | ||
15 | - * This component iterates for a given number of times | ||
16 | - */ | ||
17 | - Loop = ARCS.Component.create( | ||
18 | - function () { | ||
19 | - /** | ||
20 | - * Sets the number of times the component should iterate. | ||
21 | - * It starts the iterations. At each iteration, a signal newIteration is | ||
22 | - * emitted, then, at the end of the iterations, a signal sendToken is | ||
23 | - * eventually triggered. | ||
24 | - * @param n {numeric} number of iterations | ||
25 | - * @function Loop#setIterations | ||
26 | - * @slot | ||
27 | - * @emits newIteration | ||
28 | - * @emits sendToken | ||
29 | - */ | ||
30 | - this.setIterations = function (n) { | ||
31 | - var i; | ||
32 | - for (i = 0; i < n; i++) { | ||
33 | - console.log("Loop : emitting ", i); | ||
34 | - this.emit("newIteration", i); | ||
35 | - } | ||
36 | - this.emit("endLoop"); | ||
37 | - }; | ||
38 | - | ||
39 | - /** @function Loop#newIteration | ||
40 | - * @signal | ||
41 | - * @param n {number} current iteration number. | ||
42 | - */ | ||
43 | - | ||
44 | - /** @function Loop#sendToken | ||
45 | - * @signal | ||
46 | - * @param s {string} token to emit. | ||
47 | - */ | ||
48 | - | ||
49 | - }, | ||
50 | - "setIterations", //slotList | ||
51 | - ["endLoop", "newIteration"] // signalList | ||
52 | - ); | ||
53 | - | ||
54 | 9 | ||
55 | - /** | 10 | +/** |
56 | - * @class DisplayInt | 11 | + * @class Loop |
57 | - * @classdesc displayInt component creation using a variation with defined slots | 12 | + * @classdesc loop component creation using a compact style. |
58 | - * in the constructor (a slot is a function). DisplayInt will display an integer | 13 | + * This component iterates for a given number of times |
59 | - * received on its display slot. | 14 | + */ |
60 | - */ | 15 | +var Loop = ARCS.Component.create( |
61 | - DisplayInt = function () { | 16 | + function () { |
62 | /** | 17 | /** |
63 | - * @param n {numeric} number to display | 18 | + * Sets the number of times the component should iterate. |
64 | - * @function DisplayInt#display | 19 | + * It starts the iterations. At each iteration, a signal newIteration is |
65 | - * @slot | 20 | + * emitted, then, at the end of the iterations, a signal sendToken is |
66 | - */ | 21 | + * eventually triggered. |
67 | - this.display = function (n) { | 22 | + * @param n {numeric} number of iterations |
68 | - console.log(" DisplayInt : " + n); | 23 | + * @function Loop#setIterations |
24 | + * @slot | ||
25 | + * @emits newIteration | ||
26 | + * @emits sendToken | ||
27 | + */ | ||
28 | + this.setIterations = function (n) { | ||
29 | + var i; | ||
30 | + for (i = 0; i < n; i++) { | ||
31 | + console.log("Loop : emitting ", i); | ||
32 | + this.emit("newIteration", i); | ||
33 | + } | ||
34 | + this.emit("endLoop"); | ||
69 | }; | 35 | }; |
70 | - }; | 36 | + |
37 | + /** @function Loop#newIteration | ||
38 | + * @signal | ||
39 | + * @param n {number} current iteration number. | ||
40 | + */ | ||
41 | + | ||
42 | + /** @function Loop#sendToken | ||
43 | + * @signal | ||
44 | + * @param s {string} token to emit. | ||
45 | + */ | ||
46 | + | ||
47 | + }, | ||
48 | + "setIterations", //slotList | ||
49 | + ["endLoop", "newIteration"] // signalList | ||
50 | +); | ||
71 | 51 | ||
72 | - ARCS.Component.create(DisplayInt); | ||
73 | - DisplayInt.slot("display"); | ||
74 | 52 | ||
75 | - | 53 | +/** |
76 | - /** | 54 | + * @class DisplayInt |
77 | - * @class Sum | 55 | + * @classdesc displayInt component creation using a variation with defined slots |
78 | - * @classdec Sum is a component summing integers passed to its slot "add" | 56 | + * in the constructor (a slot is a function). DisplayInt will display an integer |
79 | - * and the result is sent back by signal "sum". | 57 | + * received on its display slot. |
80 | - * This component is declared in two different phases: declaration of the | 58 | + */ |
81 | - * constructor and declaration of the slot "add". | 59 | +var DisplayInt = function () { |
82 | - */ | 60 | +/** |
83 | - Sum = function () { | 61 | + * @param n {numeric} number to display |
84 | - this.total = 0; | 62 | + * @function DisplayInt#display |
63 | + * @slot | ||
64 | + */ | ||
65 | + this.display = function (n) { | ||
66 | + console.log(" DisplayInt : " + n); | ||
85 | }; | 67 | }; |
68 | +}; | ||
69 | + | ||
70 | +ARCS.Component.create(DisplayInt); | ||
71 | +DisplayInt.slot("display"); | ||
86 | 72 | ||
87 | - ARCS.Component.create(Sum); | ||
88 | - /** | ||
89 | - * This slot adds its parameter to its internal sum and send it back by using | ||
90 | - * the signal "sum". | ||
91 | - * @param n {integer} add n to the internal sum of the component. | ||
92 | - * @function Sum#add | ||
93 | - * @slot | ||
94 | - */ | ||
95 | - Sum.slot("add", function (n) { | ||
96 | - this.total = this.total + n; | ||
97 | - this.emit("sum", this.total); //console.log(" Total : " + this.total); | ||
98 | - }); | ||
99 | - Sum.signal("sum"); | ||
100 | 73 | ||
101 | - // the anonymous function must return the components in one object: | 74 | +/** |
102 | - // keys are factory names, value are actual constructors modified by | 75 | + * @class Sum |
103 | - // ARCS.Component.create | 76 | + * @classdec Sum is a component summing integers passed to its slot "add" |
77 | + * and the result is sent back by signal "sum". | ||
78 | + * This component is declared in two different phases: declaration of the | ||
79 | + * constructor and declaration of the slot "add". | ||
80 | + */ | ||
81 | +var Sum = function () { | ||
82 | + this.total = 0; | ||
83 | +}; | ||
104 | 84 | ||
105 | - return {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum}; | 85 | +ARCS.Component.create(Sum); |
86 | +/** | ||
87 | + * This slot adds its parameter to its internal sum and send it back by using | ||
88 | + * the signal "sum". | ||
89 | + * @param n {integer} add n to the internal sum of the component. | ||
90 | + * @function Sum#add | ||
91 | + * @slot | ||
92 | + */ | ||
93 | +Sum.slot("add", function (n) { | ||
94 | + this.total = this.total + n; | ||
95 | + this.emit("sum", this.total); //console.log(" Total : " + this.total); | ||
106 | }); | 96 | }); |
97 | +Sum.signal("sum"); | ||
98 | + | ||
99 | +// the anonymous function must return the components in one object: | ||
100 | +// keys are factory names, value are actual constructors modified by | ||
101 | +// ARCS.Component.create | ||
102 | + | ||
103 | +export default {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum}; | ... | ... |
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( | 6 | + |
4 | - function (ARCS, POS) { | 7 | +MarkerLocator = ARCS.Component.create( |
5 | - var MarkerLocator; | 8 | + function () { |
9 | + var square_pose = new POS.SquareFiducial(); | ||
10 | + | ||
11 | + this.setFocalLength = function (focalLength) { | ||
12 | + square_pose.setFocalLength(focalLength); | ||
13 | + }; | ||
14 | + | ||
15 | + this.setModelSize = function (modelSize) { | ||
16 | + square_pose.setModelSize(modelSize); | ||
17 | + }; | ||
18 | + | ||
19 | + this.setIntrinsics = function (intrinsics) { | ||
20 | + square_pose.setMatrix(intrinsics); | ||
21 | + }; | ||
6 | 22 | ||
23 | + this.setImageSource = function (id) { | ||
24 | + var imageSource = document.getElementById(id); | ||
25 | + if (id === undefined) { | ||
26 | + return; | ||
27 | + } | ||
28 | + | ||
29 | + var imageSourceStyle = window.getComputedStyle(imageSource); | ||
30 | + square_pose.setImageSize(parseInt(imageSourceStyle.width),parseInt( imageSourceStyle.height)); | ||
31 | + | ||
32 | + }; | ||
7 | 33 | ||
8 | - MarkerLocator = ARCS.Component.create( | 34 | + this.locateMarkers = function (markers) { |
9 | - function () { | 35 | + var k, pose; |
10 | - var square_pose = new POS.SquareFiducial(); | 36 | + for (k=0; k < markers.length; k++) { |
11 | - | 37 | + corners = markers[k].corners; |
12 | - this.setFocalLength = function (focalLength) { | 38 | + markers[k].pose = square_pose.pose(corners); |
13 | - square_pose.setFocalLength(focalLength); | 39 | + } |
14 | - }; | 40 | + |
15 | - | 41 | + this.emit("onLocatedMarkers",markers); |
16 | - this.setModelSize = function (modelSize) { | 42 | + }; |
17 | - square_pose.setModelSize(modelSize); | 43 | + }, |
18 | - }; | 44 | + ['locateMarkers','setFocalLength','setModelSize','setImageSource'], |
19 | - | 45 | + ['onLocatedMarkers'] |
20 | - this.setIntrinsics = function (intrinsics) { | 46 | +); |
21 | - square_pose.setMatrix(intrinsics); | ||
22 | - }; | ||
23 | - | ||
24 | - this.setImageSource = function (id) { | ||
25 | - var imageSource = document.getElementById(id); | ||
26 | - if (id === undefined) { | ||
27 | - return; | ||
28 | - } | ||
29 | - | ||
30 | - var imageSourceStyle = window.getComputedStyle(imageSource); | ||
31 | - square_pose.setImageSize(parseInt(imageSourceStyle.width),parseInt( imageSourceStyle.height)); | ||
32 | - | ||
33 | - }; | ||
34 | - | ||
35 | - this.locateMarkers = function (markers) { | ||
36 | - var k, pose; | ||
37 | - for (k=0; k < markers.length; k++) { | ||
38 | - corners = markers[k].corners; | ||
39 | - markers[k].pose = square_pose.pose(corners); | ||
40 | - } | ||
41 | - | ||
42 | - this.emit("onLocatedMarkers",markers); | ||
43 | - }; | ||
44 | - }, | ||
45 | - ['locateMarkers','setFocalLength','setModelSize','setImageSource'], | ||
46 | - ['onLocatedMarkers'] | ||
47 | - ); | ||
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 ; |
6 | - * @class ObjectTransform | ||
7 | - * @classdesc Apply transformations to objects | ||
8 | - */ | ||
9 | - ObjectTransform = ARCS.Component.create( | ||
10 | - function() { | ||
11 | - var objRoot; | ||
12 | - var refMat; | ||
13 | - var id = -1; | ||
14 | 5 | ||
15 | - /** | 6 | +/** |
16 | - * Sets the object of interest on which we would like to apply transforms. | 7 | + * @class ObjectTransform |
17 | - * @param obj {object} a Three.js Object3D | 8 | + * @classdesc Apply transformations to objects |
18 | - * @function ObjectTransform#setObject | 9 | + */ |
19 | - */ | 10 | +ObjectTransform = ARCS.Component.create( |
20 | - this.setObject = function (obj) { | 11 | + function() { |
21 | - objRoot = new THREE.Object3D(); | 12 | + var objRoot; |
22 | - obj.parent.add(objRoot); | 13 | + var refMat; |
23 | - obj.parent.remove(obj); | 14 | + var id = -1; |
24 | - objRoot.add(obj); | ||
25 | - | ||
26 | - var box = new THREE.Box3; | ||
27 | - box.setFromObject(obj); | ||
28 | - var s = box.size(); | ||
29 | - var scale = MAX3(s.x, s.y, s.z); | ||
30 | - console.log(scale); | ||
31 | - obj.add(new THREE.AxisHelper(scale / 2)); | ||
32 | - }; | ||
33 | - | ||
34 | - var MAX3 = function (a,b,c) { | ||
35 | - if ( a >= b ) { | ||
36 | - if ( a >= c) { | ||
37 | - return a; | ||
38 | - } else { | ||
39 | - return c; | ||
40 | - } | ||
41 | - } else { | ||
42 | - if (b >= c) { | ||
43 | - return b; | ||
44 | - } else { | ||
45 | - return c; | ||
46 | - } | ||
47 | - } | ||
48 | - }; | ||
49 | 15 | ||
50 | - | 16 | + /** |
51 | - | 17 | + * Sets the object of interest on which we would like to apply transforms. |
52 | - // right now, we make something compatible with aruco markers | 18 | + * @param obj {object} a Three.js Object3D |
53 | - // it may evolve in the future | 19 | + * @function ObjectTransform#setObject |
54 | - | 20 | + */ |
55 | - /** | 21 | + this.setObject = function (obj) { |
56 | - * Takes an array of markers and then applies transformations | 22 | + objRoot = new THREE.Object3D(); |
57 | - * to the referenced object. | 23 | + obj.parent.add(objRoot); |
58 | - * @function ObjectTransform#setTransform | 24 | + obj.parent.remove(obj); |
59 | - * @param arr {Marker[]} an array of detected markers. | 25 | + objRoot.add(obj); |
60 | - */ | 26 | + |
61 | - this.setTransform = function ( arr ) { | 27 | + var box = new THREE.Box3; |
62 | - /*2 set here the transformation we should apply on objRoot | 28 | + box.setFromObject(obj); |
63 | - * Each marker has 3 major properties : | 29 | + var s = box.size(); |
64 | - * - id is the marker id; | 30 | + var scale = MAX3(s.x, s.y, s.z); |
65 | - * - pose.rotation gives its orientation using a rotation matrix | 31 | + console.log(scale); |
66 | - * and is a 3x3 array | 32 | + obj.add(new THREE.AxisHelper(scale / 2)); |
67 | - * - pose.position gives its position with respect to the camera | 33 | + }; |
68 | - * and is a vector with 3 components. | ||
69 | - */ | ||
70 | - if (objRoot === undefined) { return ; } | ||
71 | - var i ; | ||
72 | - for ( i = 0; i < arr.length; i++) { | ||
73 | - if ( arr[i].id === id ) { | ||
74 | - // insert your code here. | ||
75 | - | ||
76 | - //<-- | ||
77 | - var rotation = arr[i].pose.rotation; | ||
78 | - var translation = arr[i].pose.position; | ||
79 | - /*var matrix = new THREE.Matrix4( | ||
80 | - rotation[0][0], rotation[0][1], rotation[0][2], translation[0], | ||
81 | - rotation[1][0], rotation[1][1], rotation[1][2], translation[1], | ||
82 | - rotation[2][0], rotation[2][1], rotation[2][2], translation[2], | ||
83 | - 0 , 0, 0, 1); | ||
84 | 34 | ||
85 | - var r = new THREE.Euler(); | 35 | + var MAX3 = function (a,b,c) { |
86 | - r.setFromRotationMatrix(matrix); | 36 | + if ( a >= b ) { |
87 | - objRoot.rotation.x = r.x; | 37 | + if ( a >= c) { |
88 | - objRoot.rotation.y = r.y; | 38 | + return a; |
89 | - objRoot.rotation.z = r.z; | 39 | + } else { |
90 | - | 40 | + return c; |
91 | - objRoot.position.x = translation[0]; | 41 | + } |
92 | - objRoot.position.y = translation[1]; | 42 | + } else { |
93 | - objRoot.position.z = translation[2]; | 43 | + if (b >= c) { |
94 | - | 44 | + return b; |
95 | - objRoot.scale.x = 1; | 45 | + } else { |
96 | - objRoot.scale.y = 1; | 46 | + return c; |
97 | - objRoot.scale.z = 1;*/ | ||
98 | - | ||
99 | - objRoot.rotation.x = -Math.asin(-rotation[1][2]); | ||
100 | - objRoot.rotation.y = -Math.atan2(rotation[0][2], rotation[2][2]); | ||
101 | - objRoot.rotation.z = Math.atan2(rotation[1][0], rotation[1][1]); | ||
102 | - | ||
103 | - objRoot.position.x = translation[0]; | ||
104 | - objRoot.position.y = translation[1]; | ||
105 | - objRoot.position.z = -translation[2]; | ||
106 | - //--> | ||
107 | - | ||
108 | - } | ||
109 | } | 47 | } |
110 | - }; | 48 | + } |
111 | - | 49 | + }; |
112 | - this.setId = function (i) { | ||
113 | - id = i; | ||
114 | - }; | ||
115 | - }, | ||
116 | - ['setObject', 'setTransform', 'setId'], | ||
117 | - [] | ||
118 | - ); | ||
119 | 50 | ||
51 | + | ||
52 | + | ||
53 | + // right now, we make something compatible with aruco markers | ||
54 | + // it may evolve in the future | ||
55 | + | ||
56 | + /** | ||
57 | + * Takes an array of markers and then applies transformations | ||
58 | + * to the referenced object. | ||
59 | + * @function ObjectTransform#setTransform | ||
60 | + * @param arr {Marker[]} an array of detected markers. | ||
61 | + */ | ||
62 | + this.setTransform = function ( arr ) { | ||
63 | + /*2 set here the transformation we should apply on objRoot | ||
64 | + * Each marker has 3 major properties : | ||
65 | + * - id is the marker id; | ||
66 | + * - pose.rotation gives its orientation using a rotation matrix | ||
67 | + * and is a 3x3 array | ||
68 | + * - pose.position gives its position with respect to the camera | ||
69 | + * and is a vector with 3 components. | ||
70 | + */ | ||
71 | + if (objRoot === undefined) { return ; } | ||
72 | + var i ; | ||
73 | + for ( i = 0; i < arr.length; i++) { | ||
74 | + if ( arr[i].id === id ) { | ||
75 | + // insert your code here. | ||
76 | + | ||
77 | + //<-- | ||
78 | + var rotation = arr[i].pose.rotation; | ||
79 | + var translation = arr[i].pose.position; | ||
80 | + /*var matrix = new THREE.Matrix4( | ||
81 | + rotation[0][0], rotation[0][1], rotation[0][2], translation[0], | ||
82 | + rotation[1][0], rotation[1][1], rotation[1][2], translation[1], | ||
83 | + rotation[2][0], rotation[2][1], rotation[2][2], translation[2], | ||
84 | + 0 , 0, 0, 1); | ||
120 | 85 | ||
86 | + var r = new THREE.Euler(); | ||
87 | + r.setFromRotationMatrix(matrix); | ||
88 | + objRoot.rotation.x = r.x; | ||
89 | + objRoot.rotation.y = r.y; | ||
90 | + objRoot.rotation.z = r.z; | ||
91 | + | ||
92 | + objRoot.position.x = translation[0]; | ||
93 | + objRoot.position.y = translation[1]; | ||
94 | + objRoot.position.z = translation[2]; | ||
95 | + | ||
96 | + objRoot.scale.x = 1; | ||
97 | + objRoot.scale.y = 1; | ||
98 | + objRoot.scale.z = 1;*/ | ||
99 | + | ||
100 | + objRoot.rotation.x = -Math.asin(-rotation[1][2]); | ||
101 | + objRoot.rotation.y = -Math.atan2(rotation[0][2], rotation[2][2]); | ||
102 | + objRoot.rotation.z = Math.atan2(rotation[1][0], rotation[1][1]); | ||
121 | 103 | ||
122 | - return { ObjectTransform : ObjectTransform }; | 104 | + objRoot.position.x = translation[0]; |
105 | + objRoot.position.y = translation[1]; | ||
106 | + objRoot.position.z = -translation[2]; | ||
107 | + //--> | ||
108 | + | ||
109 | + } | ||
110 | + } | ||
111 | + }; | ||
112 | + | ||
113 | + this.setId = function (i) { | ||
114 | + id = i; | ||
115 | + }; | ||
123 | }, | 116 | }, |
124 | - [ "deps/three.js/index" ] | ||
125 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
117 | + ['setObject', 'setTransform', 'setId'], | ||
118 | + [] | ||
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 | ||
7 | + | ||
8 | +var internalOBJLoader; | ||
9 | + | ||
10 | + | ||
11 | +internalOBJLoader = ARCS.Component.create( | ||
12 | + function() { | ||
13 | + var self = this; | ||
14 | + var innerObject; | ||
5 | 15 | ||
6 | - OBJLoader = ARCS.Component.create( | 16 | + var onLoadWrapper = function(obj) { |
7 | - function() { | 17 | + innerObject = obj; |
8 | - var self = this; | 18 | + console.log("[OBJLoader] object has %d components", obj.children.length); |
9 | - var innerObject; | 19 | + //console.log(obj); |
10 | - | 20 | + self.emit("onLoad", obj); |
11 | - var onLoadWrapper = function(obj) { | 21 | + }; |
12 | - innerObject = obj; | ||
13 | - console.log("[OBJLoader] object has %d components", obj.children.length); | ||
14 | - //console.log(obj); | ||
15 | - self.emit("onLoad", obj); | ||
16 | - }; | ||
17 | 22 | ||
18 | - var onLoadJSON = function(geom, mat) { | 23 | + var onLoadJSON = function(geom, mat) { |
19 | - innerObject = new THREE.Mesh(geom, new THREE.MeshFaceMaterial(mat)); | 24 | + innerObject = new THREE.Mesh(geom, new THREE.MeshFaceMaterial(mat)); |
20 | - | 25 | + |
21 | - self.emit("onLoad", innerObject); | 26 | + self.emit("onLoad", innerObject); |
22 | - }; | 27 | + }; |
23 | - | 28 | + |
24 | - var progress = function ( xhr ) { | 29 | + var progress = function ( xhr ) { |
25 | - console.log( (xhr.loaded / xhr.total * 100) + '% loaded' ); | 30 | + console.log( (xhr.loaded / xhr.total * 100) + '% loaded' ); |
26 | - }; | 31 | + }; |
27 | - | 32 | + |
28 | - var error = function ( xhr ) { | 33 | + var error = function ( xhr ) { |
29 | - console.log( 'An error happened' ); | 34 | + console.log( 'An error happened' ); |
30 | - }; | 35 | + }; |
31 | - | 36 | + |
32 | - this.load = function(objURL, mtlURL) { | 37 | + this.load = function(objURL, mtlURL) { |
33 | - var loader; | 38 | + var loader; |
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 | + |
37 | - | 42 | + //console.log("loading objects", objURL, mtlURL); |
38 | - console.log("loading objects", objURL, mtlURL); | 43 | + var manager = new THREE.LoadingManager(); |
39 | - if (mtlURL === undefined) { | 44 | + //manager.addHandler( /\.dds$/i, new DDSLoader() ); |
40 | - //console.log("using loader"); | 45 | + |
41 | - loader = new THREE.OBJLoader(); | 46 | + if (mtlURL === undefined) { |
42 | - loader.load(objURL, onLoadWrapper, progress, error); | 47 | + //console.log("using loader"); |
48 | + loader = new OBJLoader(manager); | ||
49 | + loader.load(objURL, onLoadWrapper, progress, error); | ||
50 | + } else { | ||
51 | + //console.log("using mtl loader"); | ||
52 | + loader = new MTLLoader(manager); | ||
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); | ||
60 | + } | ||
61 | + }; | ||
62 | + | ||
63 | + this.loadJSON = function(jsonURL) { | ||
64 | + var loader; | ||
65 | + //console.log("loading objects", jsonURL); | ||
66 | + loader = new THREE.ObjectLoader(); | ||
67 | + loader.load(jsonURL, onLoadJSON); //, progress, error); | ||
68 | + | ||
69 | + | ||
70 | + }; | ||
71 | + | ||
72 | + var MAX3 = function (a,b,c) { | ||
73 | + if ( a >= b ) { | ||
74 | + if ( a >= c) { | ||
75 | + return a; | ||
43 | } else { | 76 | } else { |
44 | - //console.log("using mtl loader"); | 77 | + return c; |
45 | - loader = new THREE.OBJMTLLoader(); | ||
46 | - loader.load(objURL, mtlURL, onLoadWrapper, progress, error); | ||
47 | } | 78 | } |
48 | - }; | 79 | + } else { |
49 | - | 80 | + if (b >= c) { |
50 | - this.loadJSON = function(jsonURL) { | 81 | + return b; |
51 | - var loader; | ||
52 | - //console.log("loading objects", jsonURL); | ||
53 | - loader = new THREE.JSONLoader(); | ||
54 | - loader.load(jsonURL, onLoadJSON); //, progress, error); | ||
55 | - | ||
56 | - | ||
57 | - }; | ||
58 | - | ||
59 | - var MAX3 = function (a,b,c) { | ||
60 | - if ( a >= b ) { | ||
61 | - if ( a >= c) { | ||
62 | - return a; | ||
63 | - } else { | ||
64 | - return c; | ||
65 | - } | ||
66 | } else { | 82 | } else { |
67 | - if (b >= c) { | 83 | + return c; |
68 | - return b; | ||
69 | - } else { | ||
70 | - return c; | ||
71 | - } | ||
72 | } | 84 | } |
73 | - }; | 85 | + } |
74 | - | 86 | + }; |
75 | - this.unitize = function() { | 87 | + |
76 | - if (innerObject === undefined) { return ; } | 88 | + this.unitize = function() { |
77 | - var box = new THREE.Box3(); | 89 | + if (innerObject === undefined) { return ; } |
78 | - box.setFromObject(innerObject); | 90 | + var box = new THREE.Box3(); |
79 | - var s = box.size(); | 91 | + box.setFromObject(innerObject); |
80 | - var c = box.center(); | 92 | + var s = box.size(); |
81 | - var scale = 1 / MAX3(s.x, s.y, s.z); | 93 | + var c = box.center(); |
82 | - innerObject.scale.x = innerObject.scale.y = innerObject.scale.z = scale; | 94 | + var scale = 1 / MAX3(s.x, s.y, s.z); |
83 | - }; | 95 | + innerObject.scale.x = innerObject.scale.y = innerObject.scale.z = scale; |
84 | - | 96 | + }; |
85 | - this.resize = function(s) { | 97 | + |
86 | - this.unitize(); | 98 | + this.resize = function(s) { |
87 | - if (innerObject === undefined) { return ; } | 99 | + this.unitize(); |
88 | - innerObject.scale.x *= s; | 100 | + if (innerObject === undefined) { return ; } |
89 | - innerObject.scale.y *= s; | 101 | + innerObject.scale.x *= s; |
90 | - innerObject.scale.z *= s; | 102 | + innerObject.scale.y *= s; |
91 | - }; | 103 | + innerObject.scale.z *= s; |
92 | - | 104 | + }; |
93 | - }, | ||
94 | - ["load","unitize", "resize"], | ||
95 | - ["onLoad"] | ||
96 | - ); | ||
97 | 105 | ||
98 | - return { OBJLoader: OBJLoader}; | ||
99 | }, | 106 | }, |
100 | - [ 'deps/three.js/index', 'deps/objloader/index', 'deps/mtlloader/index','deps/objmtlloader/index' ] | ||
101 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
107 | + ["load","unitize", "resize"], | ||
108 | + ["onLoad"] | ||
109 | +); | ||
110 | + | ||
111 | +export default { OBJLoader: internalOBJLoader}; | ... | ... |
components/package.json
0 → 100644
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; |
5 | - function( arr ) { | ||
6 | - var i; | ||
7 | - var self = this; | ||
8 | - for (i=0; i< arr.length; i++) { | ||
9 | - if (typeof arr[i] === "string") { | ||
10 | - this.slots.push(arr[i]); | ||
11 | - //TokenSender.prototype.slots.push(arr[i]); | ||
12 | - this[arr[i]] = function( s ) { | ||
13 | - return function() { | ||
14 | - console.log("[TokenSender] emitting %s", s); | ||
15 | - this.emit("sendToken",s); | ||
16 | - }; | ||
17 | - } (arr[i]); | ||
18 | - } | ||
19 | - } | ||
20 | - }, | ||
21 | - [], | ||
22 | - ['sendToken'] | ||
23 | - ); | ||
24 | 4 | ||
25 | - return { TokenSender : TokenSender }; | ||
26 | -}); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
5 | +TokenSender = ARCS.Component.create( | ||
6 | + function( arr ) { | ||
7 | + var i; | ||
8 | + var self = this; | ||
9 | + for (i=0; i< arr.length; i++) { | ||
10 | + if (typeof arr[i] === "string") { | ||
11 | + this.slots.push(arr[i]); | ||
12 | + //TokenSender.prototype.slots.push(arr[i]); | ||
13 | + this[arr[i]] = function( s ) { | ||
14 | + return function() { | ||
15 | + console.log("[TokenSender] emitting %s", s); | ||
16 | + this.emit("sendToken",s); | ||
17 | + }; | ||
18 | + } (arr[i]); | ||
19 | + } | ||
20 | + } | ||
21 | + }, | ||
22 | + [], | ||
23 | + ['sendToken'] | ||
24 | +); | ||
25 | + | ||
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 | - function () { | 4 | +LiveSource = ARCS.Component.create( |
5 | - var context, canvas, video, imageData; | 5 | + function () { |
6 | - var defaultWidth = 320; | 6 | + var context, canvas, video, imageData; |
7 | - var defaultHeight = 240; | 7 | + var defaultWidth = 320; |
8 | - var self = this; | 8 | + var defaultHeight = 240; |
9 | - | 9 | + var self = this; |
10 | - var handleMediaStream = function(stream) { | 10 | + |
11 | - if (window.webkitURL) { | 11 | + var handleMediaStream = function(stream) { |
12 | - video.src = window.webkitURL.createObjectURL(stream); | 12 | + console.log(video,stream); |
13 | - } else if (video.mozSrcObject !== undefined) { | 13 | + if (window.webkitURL) { |
14 | - video.mozSrcObject = stream; | 14 | + video.src = window.webkitURL.createObjectURL(stream); |
15 | - } else if (video.srcObject !== undefined) { | 15 | + } else if (video.mozSrcObject !== undefined) { |
16 | - video.srcObject = stream; | 16 | + video.mozSrcObject = stream; |
17 | - } else { | 17 | + } else if (video.srcObject !== undefined) { |
18 | - video.src = stream; | 18 | + video.srcObject = stream; |
19 | - } | 19 | + } else { |
20 | - video.videoWidth=defaultWidth; | 20 | + video.src = stream; |
21 | - video.videoHeight=defaultHeight; | 21 | + } |
22 | - self.emit("onReady"); | 22 | + /*video.videoWidth=defaultWidth; |
23 | - }; | 23 | + video.videoHeight=defaultHeight;*/ |
24 | - | 24 | + self.emit("onReady"); |
25 | - var errorMediaStream = function(error) { | 25 | + }; |
26 | - console.error("Cannot initialize video component:", error.code); | 26 | + |
27 | - }; | 27 | + var errorMediaStream = function(error) { |
28 | - | 28 | + console.error("Cannot initialize video component:", error.code); |
29 | - var setUserMedia = function() { | 29 | + }; |
30 | - console.log("video test"); | 30 | + |
31 | - if (navigator.mediaDevices !== undefined) { | 31 | + var setUserMedia = function() { |
32 | - navigator.mediaDevices.getUserMedia({video:{facingMode : "environment"}}) | 32 | + if (navigator.mediaDevices !== undefined) { |
33 | - .then(handleMediaStream) | 33 | + navigator.mediaDevices.getUserMedia({video: {facingMode: "environment", width: defaultWidth, height: defaultHeight}}) |
34 | - .catch(errorMediaStream); | 34 | + .then(handleMediaStream) |
35 | - } else { | 35 | + .catch(errorMediaStream); |
36 | - var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; | 36 | + } else { |
37 | - if (getUserMedia !== undefined) { | 37 | + var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; |
38 | - console.log(getUserMedia(), handleMediaStream, errorMediaStream); | 38 | + if (getUserMedia !== undefined) { |
39 | - /*getUserMedia({video:true}, handleMediaStream, | 39 | + getUserMedia({video:true}).then(handleMediaStream); |
40 | - errorMediaStream | ||
41 | - );*/ | ||
42 | - getUserMedia({video:true}).then(handleMediaStream); | ||
43 | - } | ||
44 | - } | ||
45 | - }; | ||
46 | - | ||
47 | - this.grabFrame = function () { | ||
48 | - if ( context === undefined || canvas === undefined || video === undefined) | ||
49 | - return; | ||
50 | - if (video.readyState === video.HAVE_ENOUGH_DATA) { | ||
51 | - context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
52 | - imageData = context.getImageData(0, 0, canvas.width, canvas.height); | ||
53 | - this.emit("onImage",imageData); | ||
54 | } | 40 | } |
55 | - }; | 41 | + } |
42 | + }; | ||
43 | + | ||
44 | + this.grabFrame = function () { | ||
45 | + if ( context === undefined || canvas === undefined || video === undefined) | ||
46 | + return; | ||
47 | + if (video.readyState === video.HAVE_ENOUGH_DATA) { | ||
48 | + context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
49 | + imageData = context.getImageData(0, 0, canvas.width, canvas.height); | ||
50 | + this.emit("onImage",imageData); | ||
51 | + } | ||
52 | + }; | ||
53 | + | ||
54 | + this.setSize = function(x,y) { | ||
56 | 55 | ||
57 | - this.setSize = function(x,y) { | 56 | + }; |
58 | - | 57 | + |
59 | - }; | 58 | + this.setWidgets = function (videoId, canvasId) { |
59 | + video = document.getElementById(videoId); | ||
60 | + canvas = document.getElementById(canvasId); | ||
60 | 61 | ||
61 | - this.setWidgets = function (videoId, canvasId) { | 62 | + if (video === undefined || canvas === undefined) { |
62 | - video = document.getElementById(videoId); | 63 | + console.log("video elements not defined"); |
63 | - canvas = document.getElementById(canvasId); | 64 | + return; |
64 | - | 65 | + } |
65 | - if (video === undefined || canvas === undefined) { | 66 | + context = canvas.getContext("2d"); |
66 | - console.log("video elements not defined"); | 67 | + var canvasStyle= window.getComputedStyle(canvas); |
67 | - return; | 68 | + canvas.width=parseInt(canvasStyle.width); |
68 | - } | 69 | + canvas.height=parseInt(canvasStyle.height); |
69 | - context = canvas.getContext("2d"); | 70 | + setUserMedia(); |
70 | - var canvasStyle= window.getComputedStyle(canvas); | 71 | + }; |
71 | - canvas.width=parseInt(canvasStyle.width); | 72 | + }, |
72 | - canvas.height=parseInt(canvasStyle.height); | 73 | + ['grabFrame','setWidgets'], |
73 | - setUserMedia(); | 74 | + ['onReady','onImage'] |
74 | - }; | 75 | +); |
75 | - }, | 76 | + |
76 | - ['grabFrame','setWidgets'], | 77 | + |
77 | - ['onReady','onImage'] | 78 | +VideoSource = ARCS.Component.create( |
78 | - ); | 79 | + function() { |
79 | - | 80 | + var context, canvas, video, imageData; |
80 | - | 81 | + var defaultWidth=320; |
81 | - VideoSource = ARCS.Component.create( | 82 | + var defaultHeight=240; |
82 | - function() { | 83 | + var self=this; |
83 | - var context, canvas, video, imageData; | 84 | + |
84 | - var defaultWidth=320; | 85 | + this.setWidgets = function (videoId, canvasId) { |
85 | - var defaultHeight=240; | 86 | + video = document.getElementById(videoId); |
86 | - var self=this; | 87 | + canvas = document.getElementById(canvasId); |
87 | 88 | ||
88 | - this.setWidgets = function (videoId, canvasId) { | 89 | + if (video === undefined || canvas === undefined) { |
89 | - video = document.getElementById(videoId); | 90 | + return; |
90 | - canvas = document.getElementById(canvasId); | 91 | + } |
91 | - | 92 | + context = canvas.getContext("2d"); |
92 | - if (video === undefined || canvas === undefined) { | 93 | + var canvasStyle= window.getComputedStyle(canvas); |
93 | - return; | 94 | + canvas.width=parseInt(canvasStyle.width); |
94 | - } | 95 | + canvas.height=parseInt(canvasStyle.height); |
95 | - context = canvas.getContext("2d"); | ||
96 | - var canvasStyle= window.getComputedStyle(canvas); | ||
97 | - canvas.width=parseInt(canvasStyle.width); | ||
98 | - canvas.height=parseInt(canvasStyle.height); | ||
99 | 96 | ||
100 | - if (video.paused || video.ended) { | 97 | + if (video.paused || video.ended) { |
101 | - video.addEventListener('play', function() { | 98 | + video.addEventListener('play', function() { |
102 | - self.emit("onReady"); | ||
103 | - }); | ||
104 | - } else { | ||
105 | self.emit("onReady"); | 99 | self.emit("onReady"); |
106 | - } | 100 | + }); |
107 | - | 101 | + } else { |
108 | - | 102 | + self.emit("onReady"); |
109 | - }; | 103 | + } |
110 | 104 | ||
111 | - this.grabFrame = function () { | ||
112 | - if ( context === undefined || canvas === undefined || video === undefined) | ||
113 | - return; | ||
114 | - if (video.paused || video.ended) { | ||
115 | - return; | ||
116 | - } | ||
117 | - | ||
118 | - context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
119 | - imageData = context.getImageData(0, 0, canvas.width, canvas.height); | ||
120 | - this.emit("onImage",imageData); | ||
121 | - }; | ||
122 | 105 | ||
106 | + }; | ||
107 | + | ||
108 | + this.grabFrame = function () { | ||
109 | + if ( context === undefined || canvas === undefined || video === undefined) | ||
110 | + return; | ||
111 | + if (video.paused || video.ended) { | ||
112 | + return; | ||
113 | + } | ||
114 | + | ||
115 | + context.drawImage(video, 0, 0, canvas.width, canvas.height); | ||
116 | + imageData = context.getImageData(0, 0, canvas.width, canvas.height); | ||
117 | + this.emit("onImage",imageData); | ||
118 | + }; | ||
123 | 119 | ||
124 | - }, | ||
125 | - ['grabFrame', 'setWidgets'], | ||
126 | - ['onReady', 'onImage'] | ||
127 | - ); | ||
128 | - | ||
129 | 120 | ||
130 | - return {LiveSource: LiveSource, VideoSource: VideoSource}; | 121 | + }, |
131 | -}); | 122 | + ['grabFrame', 'setWidgets'], |
123 | + ['onReady', 'onImage'] | ||
124 | +); | ||
125 | + | ||
126 | +export default {LiveSource: LiveSource, VideoSource: VideoSource}; | ... | ... |
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; |
6 | - function () { | 4 | + |
7 | - var self= this; | 5 | +WindowEvent = ARCS.Component.create( |
8 | - | 6 | + function () { |
9 | - window.onresize = function() { | 7 | + let self= this; |
10 | - self.emit("onResize",window.innerWidth, window.innerHeight); | 8 | + |
11 | - }; | 9 | + window.onresize = function() { |
12 | - }, | 10 | + self.emit("onResize",window.innerWidth, window.innerHeight); |
13 | - [], | 11 | + }; |
14 | - ["onResize"] | 12 | + }, |
15 | - ); | 13 | + [], |
14 | + ["onResize"] | ||
15 | +); | ||
16 | 16 | ||
17 | - return { WindowEvent: WindowEvent}; | ||
18 | - } | ||
19 | -); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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; | ... | ... |
... | @@ -129,4 +129,6 @@ POS.SquareFiducial.prototype.crossProduct = function(a,b) { | ... | @@ -129,4 +129,6 @@ POS.SquareFiducial.prototype.crossProduct = function(a,b) { |
129 | POS.SimplePose = function(pos, rot) { | 129 | POS.SimplePose = function(pos, rot) { |
130 | this.position = pos; | 130 | this.position = pos; |
131 | this.rotation = rot; | 131 | this.rotation = rot; |
132 | -}; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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,19 +22,11 @@ var ARCS = ARCS || {}; | ... | @@ -22,19 +22,11 @@ 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 | */ |
29 | ARCS.isInNode = function () { | 28 | ARCS.isInNode = function () { |
30 | - return (typeof require === 'function' && require.resolve); | 29 | + return (typeof require === 'function' && require.resolve); |
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(); | ... | ... |
src/arcs_module.js
deleted
100644 → 0
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 | -} |
src/arcs_node.js
deleted
100644 → 0
src/arcs_node.mjs
0 → 100755
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 | - } | ||
69 | - }; | ||
70 | - client.onerror = function() { | ||
71 | - console.error(this.statusText); | ||
72 | - reject(this.statusText); | ||
73 | - }; | ||
74 | - }); | ||
75 | } | 58 | } |
76 | }; | 59 | }; |
77 | - | 60 | + |
78 | - this.addLibraryPromise = function(p) { | 61 | + var loadLibraries = function () { |
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 | - | ||
88 | - if (ARCS.isInNode()) { | ||
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 | ); |
... | @@ -177,13 +130,23 @@ ARCS.Context = function( ctx ) { | ... | @@ -177,13 +130,23 @@ ARCS.Context = function( ctx ) { |
177 | libActualName = libName.name; | 130 | libActualName = libName.name; |
178 | libUrl = libName.url; | 131 | libUrl = libName.url; |
179 | } | 132 | } |
180 | - | 133 | + |
181 | - libraries.push(libActualName); | 134 | + if (libraries.indexOf(libActualName) < 0) { |
182 | - promiseLibrary(libUrl).then( function() { | 135 | + libraries.push(libActualName); |
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="../.." | 5 | + data-arcsapp="arcsapp.json" |
6 | - data-arcsapp="arcsapp.json" | 6 | + type="module" |
7 | - src="../../deps/requirejs/require.js"> | 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> | ... | ... |
-
Please register or login to post a comment