Jean-Yves Didier

merge between master and branch modules

module.exports = function (grunt) {
"use strict";
let shim = function(obj) { return `\nexport default ${obj};\n`; };
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
dist: {
files:[
{src: 'src/arcs_browser.js', dest: 'build/arcs_browser.js'},
{src: 'src/arcs_node.mjs', dest: 'build/arcs_node.mjs'}
]
}
},
jsdoc: {
dist: {
src: ['src/*.js', 'docs/Readme.md'], //, 'components/*.js'],
......@@ -43,16 +54,13 @@ module.exports = function (grunt) {
}
}
},
uglify: {
terser: {
build: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
files: {
'build/arcs.min.js': [
'build/arcs.js'
],
'build/arcs_browser.js': [
'build/arcs_browser.min.js': [
'src/arcs_browser.js'
],
'build/arcseditor.min.js': [
......@@ -74,7 +82,38 @@ module.exports = function (grunt) {
}
},
concat: {
file_append: {
default_options: {
files: [
{
append: shim('AR'),
prepend: `import CV from '../cv/index.js';\n`,
input: './deps/aruco/index.js'
},
{
append: shim('CV'),
input: './deps/cv/index.js'
}
]
}
},
'string-replace': {
dist: {
files: {
'deps/objloader/objloader.js': 'deps/objloader/index.js',
'deps/mtlloader/mtlloader.js': 'deps/mtlloader/index.js',
'deps/ddsloader/ddsloader.js': 'deps/ddsloader/index.js'
},
options: {
replacements:[{
pattern: '../../../build/three.module.js',
replacement: '../three.js/index.js'
}]
}
}
},
concat: {
dist: {
src: [
'src/arcs.js',
......@@ -88,7 +127,6 @@ module.exports = function (grunt) {
'src/transitionnetwork.js',
'src/statemachine.js',
'src/application.js',
'src/arcs_module.js',
'src/exports.js'
],
dest: 'build/arcs.js'
......@@ -106,21 +144,24 @@ module.exports = function (grunt) {
dest: 'build/arcseditor.js'
}
}
}
});
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-jslint');
grunt.loadNpmTasks('grunt-terser');
grunt.loadNpmTasks('grunt-bower-task');
grunt.loadNpmTasks('grunt-file-append');
grunt.loadNpmTasks('grunt-string-replace');
// Default task(s).
grunt.registerTask('default', ['concat','uglify']);
// Default task(s).
grunt.registerTask('default', ['concat','copy','terser']);
grunt.registerTask('lint', ['jslint']);
grunt.registerTask('doc', ['jsdoc']);
grunt.registerTask('install-deps', ['bower', 'file_append', 'string-replace']);
};
......
{
"name": "ARCS",
"version": "0.1.0",
"version": "0.2.0",
"description": "Augmented Reality Component System in web browser and node environment",
"main": "build/arcs.js",
"keywords": [
......@@ -10,12 +10,11 @@
"author": "Jean-Yves Didier",
"license": "GPL",
"dependencies": {
"requirejs": "*",
"tracking.js": "*",
"three.js": "https://raw.githubusercontent.com/mrdoob/three.js/r68/build/three.min.js",
"objloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r68/examples/js/loaders/OBJLoader.js",
"mtlloader": "https://raw.githubusercontent.com/mrdoob/three.js/r68/examples/js/loaders/MTLLoader.js",
"objmtlloader": "https://raw.githubusercontent.com/mrdoob/three.js/r68/examples/js/loaders/OBJMTLLoader.js",
"three.js": "https://raw.githubusercontent.com/mrdoob/three.js/r116/build/three.module.js",
"objloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r116/examples/jsm/loaders/OBJLoader.js",
"mtlloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r116/examples/jsm/loaders/MTLLoader.js",
"ddsloader" : "https://raw.githubusercontent.com/mrdoob/three.js/r116/examples/jsm/loaders/DDSLoader.js",
"aruco": "https://raw.githubusercontent.com/jcmellado/js-aruco/master/src/aruco.js",
"cv": "https://raw.githubusercontent.com/jcmellado/js-aruco/master/src/cv.js",
"codemirror" : "*",
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
{ "type": "module"}
arcs_module(
function (ARCS) {
var Animator;
import ARCS from '../build/arcs.js';
var Animator;
/**
* @class Animator
* @classdesc A component that request new frames for animation.
* This component is useful when you want to create animations in the
* context of a web browser.
*/
Animator = ARCS.Component.create(
function() {
var paused = false;
var self=this;
var tick = function () {
if (paused === false) {
requestAnimationFrame(tick);
self.emit("onAnimationFrame");
}
}
/**
* Starts requesting frames for animation. As soon as it is started,
* the signal <b>onAnimationFrame</b> is periodically triggered.
* @slot
* @emits onAnimationFrame
* @function Animator#start
*/
this.start = function () {
paused = false;
tick();
};
/**
* Stops requesting frames for animation.
* @slot
* @function Animator#stop
*/
this.stop = function () {
paused = true;
};
/**
* Signals that an animation frame is ready.
* @signal
* @function Animator#onAnimationFrame
*/
},
['start','stop'],
'onAnimationFrame'
);
/**
* @class Animator
* @classdesc A component that request new frames for animation.
* This component is useful when you want to create animations in the
* context of a web browser.
*/
Animator = ARCS.Component.create(
function() {
var paused = false;
var self=this;
var tick = function () {
if (paused === false) {
requestAnimationFrame(tick);
self.emit("onAnimationFrame");
}
}
/**
* Starts requesting frames for animation. As soon as it is started,
* the signal <b>onAnimationFrame</b> is periodically triggered.
* @slot
* @emits onAnimationFrame
* @function Animator#start
*/
this.start = function () {
paused = false;
tick();
};
/**
* Stops requesting frames for animation.
* @slot
* @function Animator#stop
*/
this.stop = function () {
paused = true;
};
/**
* Signals that an animation frame is ready.
* @signal
* @function Animator#onAnimationFrame
*/
},
['start','stop'],
'onAnimationFrame'
);
return {Animator: Animator};
}
);
\ No newline at end of file
export default {Animator: Animator};
......
arcs_module(
function (ARCS, CV, AR) {
var ARUCODetector;
import ARCS from '../build/arcs.js';
import CV from '../deps/cv/index.js';
import AR from '../deps/aruco/index.js';
var ARUCODetector;
/**
* @class ARUCODetector
* @classdesc Component that detects ARUCO markers in images
* This component encapsulate the {@link https://github.com/jcmellado/js-aruco|js-aruco} library.
*/
ARUCODetector = ARCS.Component.create(
function() {
var detector ;
/**
* @class ARUCODetector
* @classdesc Component that detects ARUCO markers in images
* This component encapsulate the {@link https://github.com/jcmellado/js-aruco|js-aruco} library.
*/
ARUCODetector = ARCS.Component.create(
function() {
var detector ;
/*1 Instanciate here the detector */
detector = new AR.Detector();
/*1 Instanciate here the detector */
detector = new AR.Detector();
/**
* Detects ARUCO markers in the given image.
* If markers are detected, this slot triggers the signal <b>onMarkers</b>.
* @param image {obj} the image in which markers should be detected
* @emits onMarkers
* @function ARUCODetector#detect
* @slot
*/
this.detect = function (image) {
/*1 recover markers from image
* then send they will be sent through onMarkers event
*/
var markers = detector.detect(image);
this.emit("onMarkers",markers);
};
/**
* Signal that is emitted when markers are detected in an image.
* @function ARUCODetector#onMarkers
* @param markers {Marker[]} Array of detected markers.
* @signal
*/
/**
* @typedef {Object} Marker
* @property {number} id - marker id
* @property {Object} pose - computed pose for the marker
* @property {number[]} pose.rotation - rotation matrix (3x3)
* @property {number[]} pose.position - translation (3 components)
*/
},
'detect',
['onMarkers']
);
/**
* Detects ARUCO markers in the given image.
* If markers are detected, this slot triggers the signal <b>onMarkers</b>.
* @param image {obj} the image in which markers should be detected
* @emits onMarkers
* @function ARUCODetector#detect
* @slot
*/
this.detect = function (image) {
/*1 recover markers from image
* then send they will be sent through onMarkers event
*/
var markers = detector.detect(image);
this.emit("onMarkers",markers);
};
/**
* Signal that is emitted when markers are detected in an image.
* @function ARUCODetector#onMarkers
* @param markers {Marker[]} Array of detected markers.
* @signal
*/
/**
* @typedef {Object} Marker
* @property {number} id - marker id
* @property {Object} pose - computed pose for the marker
* @property {number[]} pose.rotation - rotation matrix (3x3)
* @property {number[]} pose.position - translation (3 components)
*/
return {ARUCODetector: ARUCODetector};
},
[
{name:"deps/cv/index", exports:"CV"},
{name:"deps/aruco/index",exports:"AR"}
]
);
\ No newline at end of file
'detect',
['onMarkers']
);
export default {ARUCODetector: ARUCODetector};
......
This diff is collapsed. Click to expand it.
/* ugly hack in order to display data in web page instead of console */
import ARCS from '../build/arcs.js';
var Console;
/**
* @class Console
* @classdesc Redirects console messages to a given HTML element in the page.
* @param id {string} id of the HTML element in which console messages will be added.
*/
Console = ARCS.Component.create(
function (id) {
if (id === undefined) {
return ;
}
var output = document.getElementById(id);
if (output) {
window.console = {
timeRef: new Date().getTime(),
output : output,
display: function(color,args) {
var s = document.createElement("span");
s.style.color=color;
var elapsed = (new Date().getTime() - this.timeRef);
arcs_module(
function(ARCS) {
var Console;
/**
* @class Console
* @classdesc Redirects console messages to a given HTML element in the page.
* @param id {string} id of the HTML element in which console messages will be added.
*/
Console = ARCS.Component.create(
function (id) {
if (id === undefined) {
return ;
s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span> ' + Array.prototype.join.call(args, ' ');
output.appendChild(s);
output.appendChild(document.createElement("br"));
},
log: function () {
this.display('green',arguments);
},
error: function () {
this.display('red',arguments);
},
warn: function () {
this.display('orange',arguments);
}
var output = document.getElementById(id);
if (output) {
window.console = {
timeRef: new Date().getTime(),
output : output,
display: function(color,args) {
var s = document.createElement("span");
s.style.color=color;
var elapsed = (new Date().getTime() - this.timeRef);
s.innerHTML = '<span class="marker">' + (elapsed/1000).toFixed(3) + '</span>' + Array.prototype.join.call(args, ' ');
output.appendChild(s);
output.appendChild(document.createElement("br"));
},
log: function () {
this.display('green',arguments);
},
error: function () {
this.display('red',arguments);
},
warn: function () {
this.display('orange',arguments);
}
};
}
}
);
return { Console: Console};
};
}
}
);
);
\ No newline at end of file
export default { Console: Console};
......
......@@ -5,102 +5,99 @@
* @file
*/
arcs_module(function (ARCS) {
var Loop, DisplayInt, Sum;
/** @exports loop */
//console.log("loop: ", ARCS);
/**
* @class Loop
* @classdesc loop component creation using a compact style.
* This component iterates for a given number of times
*/
Loop = ARCS.Component.create(
function () {
/**
* Sets the number of times the component should iterate.
* It starts the iterations. At each iteration, a signal newIteration is
* emitted, then, at the end of the iterations, a signal sendToken is
* eventually triggered.
* @param n {numeric} number of iterations
* @function Loop#setIterations
* @slot
* @emits newIteration
* @emits sendToken
*/
this.setIterations = function (n) {
var i;
for (i = 0; i < n; i++) {
console.log("Loop : emitting ", i);
this.emit("newIteration", i);
}
this.emit("endLoop");
};
/** @function Loop#newIteration
* @signal
* @param n {number} current iteration number.
*/
/** @function Loop#sendToken
* @signal
* @param s {string} token to emit.
*/
},
"setIterations", //slotList
["endLoop", "newIteration"] // signalList
);
import ARCS from '../build/arcs.js';
/**
* @class DisplayInt
* @classdesc displayInt component creation using a variation with defined slots
* in the constructor (a slot is a function). DisplayInt will display an integer
* received on its display slot.
*/
DisplayInt = function () {
/**
* @class Loop
* @classdesc loop component creation using a compact style.
* This component iterates for a given number of times
*/
var Loop = ARCS.Component.create(
function () {
/**
* @param n {numeric} number to display
* @function DisplayInt#display
* @slot
*/
this.display = function (n) {
console.log(" DisplayInt : " + n);
* Sets the number of times the component should iterate.
* It starts the iterations. At each iteration, a signal newIteration is
* emitted, then, at the end of the iterations, a signal sendToken is
* eventually triggered.
* @param n {numeric} number of iterations
* @function Loop#setIterations
* @slot
* @emits newIteration
* @emits sendToken
*/
this.setIterations = function (n) {
var i;
for (i = 0; i < n; i++) {
console.log("Loop : emitting ", i);
this.emit("newIteration", i);
}
this.emit("endLoop");
};
};
/** @function Loop#newIteration
* @signal
* @param n {number} current iteration number.
*/
/** @function Loop#sendToken
* @signal
* @param s {string} token to emit.
*/
},
"setIterations", //slotList
["endLoop", "newIteration"] // signalList
);
ARCS.Component.create(DisplayInt);
DisplayInt.slot("display");
/**
* @class Sum
* @classdec Sum is a component summing integers passed to its slot "add"
* and the result is sent back by signal "sum".
* This component is declared in two different phases: declaration of the
* constructor and declaration of the slot "add".
*/
Sum = function () {
this.total = 0;
/**
* @class DisplayInt
* @classdesc displayInt component creation using a variation with defined slots
* in the constructor (a slot is a function). DisplayInt will display an integer
* received on its display slot.
*/
var DisplayInt = function () {
/**
* @param n {numeric} number to display
* @function DisplayInt#display
* @slot
*/
this.display = function (n) {
console.log(" DisplayInt : " + n);
};
};
ARCS.Component.create(DisplayInt);
DisplayInt.slot("display");
ARCS.Component.create(Sum);
/**
* This slot adds its parameter to its internal sum and send it back by using
* the signal "sum".
* @param n {integer} add n to the internal sum of the component.
* @function Sum#add
* @slot
*/
Sum.slot("add", function (n) {
this.total = this.total + n;
this.emit("sum", this.total); //console.log(" Total : " + this.total);
});
Sum.signal("sum");
// the anonymous function must return the components in one object:
// keys are factory names, value are actual constructors modified by
// ARCS.Component.create
/**
* @class Sum
* @classdec Sum is a component summing integers passed to its slot "add"
* and the result is sent back by signal "sum".
* This component is declared in two different phases: declaration of the
* constructor and declaration of the slot "add".
*/
var Sum = function () {
this.total = 0;
};
return {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum};
ARCS.Component.create(Sum);
/**
* This slot adds its parameter to its internal sum and send it back by using
* the signal "sum".
* @param n {integer} add n to the internal sum of the component.
* @function Sum#add
* @slot
*/
Sum.slot("add", function (n) {
this.total = this.total + n;
this.emit("sum", this.total); //console.log(" Total : " + this.total);
});
Sum.signal("sum");
// the anonymous function must return the components in one object:
// keys are factory names, value are actual constructors modified by
// ARCS.Component.create
export default {Loop: Loop, DisplayInt: DisplayInt, Sum: Sum};
......
import ARCS from '../build/arcs.js';
import POS from '../deps/pose/square_pose.js';
var MarkerLocator;
arcs_module(
function (ARCS, POS) {
var MarkerLocator;
MarkerLocator = ARCS.Component.create(
function () {
var square_pose = new POS.SquareFiducial();
this.setFocalLength = function (focalLength) {
square_pose.setFocalLength(focalLength);
};
this.setModelSize = function (modelSize) {
square_pose.setModelSize(modelSize);
};
this.setIntrinsics = function (intrinsics) {
square_pose.setMatrix(intrinsics);
};
this.setImageSource = function (id) {
var imageSource = document.getElementById(id);
if (id === undefined) {
return;
}
var imageSourceStyle = window.getComputedStyle(imageSource);
square_pose.setImageSize(parseInt(imageSourceStyle.width),parseInt( imageSourceStyle.height));
};
MarkerLocator = ARCS.Component.create(
function () {
var square_pose = new POS.SquareFiducial();
this.setFocalLength = function (focalLength) {
square_pose.setFocalLength(focalLength);
};
this.setModelSize = function (modelSize) {
square_pose.setModelSize(modelSize);
};
this.setIntrinsics = function (intrinsics) {
square_pose.setMatrix(intrinsics);
};
this.setImageSource = function (id) {
var imageSource = document.getElementById(id);
if (id === undefined) {
return;
}
var imageSourceStyle = window.getComputedStyle(imageSource);
square_pose.setImageSize(parseInt(imageSourceStyle.width),parseInt( imageSourceStyle.height));
};
this.locateMarkers = function (markers) {
var k, pose;
for (k=0; k < markers.length; k++) {
corners = markers[k].corners;
markers[k].pose = square_pose.pose(corners);
}
this.emit("onLocatedMarkers",markers);
};
},
['locateMarkers','setFocalLength','setModelSize','setImageSource'],
['onLocatedMarkers']
);
this.locateMarkers = function (markers) {
var k, pose;
for (k=0; k < markers.length; k++) {
corners = markers[k].corners;
markers[k].pose = square_pose.pose(corners);
}
this.emit("onLocatedMarkers",markers);
};
},
['locateMarkers','setFocalLength','setModelSize','setImageSource'],
['onLocatedMarkers']
);
return { MarkerLocator: MarkerLocator };
},
[ {name: "deps/pose/square_pose", exports: "POS"} ]
);
\ No newline at end of file
export default { MarkerLocator: MarkerLocator };
......
arcs_module(
function(ARCS,_three) {
var ObjectTransform ;
import ARCS from '../build/arcs.js';
import * as THREE from '../deps/three.js/index.js';
/**
* @class ObjectTransform
* @classdesc Apply transformations to objects
*/
ObjectTransform = ARCS.Component.create(
function() {
var objRoot;
var refMat;
var id = -1;
var ObjectTransform ;
/**
* Sets the object of interest on which we would like to apply transforms.
* @param obj {object} a Three.js Object3D
* @function ObjectTransform#setObject
*/
this.setObject = function (obj) {
objRoot = new THREE.Object3D();
obj.parent.add(objRoot);
obj.parent.remove(obj);
objRoot.add(obj);
var box = new THREE.Box3;
box.setFromObject(obj);
var s = box.size();
var scale = MAX3(s.x, s.y, s.z);
console.log(scale);
obj.add(new THREE.AxisHelper(scale / 2));
};
var MAX3 = function (a,b,c) {
if ( a >= b ) {
if ( a >= c) {
return a;
} else {
return c;
}
} else {
if (b >= c) {
return b;
} else {
return c;
}
}
};
/**
* @class ObjectTransform
* @classdesc Apply transformations to objects
*/
ObjectTransform = ARCS.Component.create(
function() {
var objRoot;
var refMat;
var id = -1;
// right now, we make something compatible with aruco markers
// it may evolve in the future
/**
* Takes an array of markers and then applies transformations
* to the referenced object.
* @function ObjectTransform#setTransform
* @param arr {Marker[]} an array of detected markers.
*/
this.setTransform = function ( arr ) {
/*2 set here the transformation we should apply on objRoot
* Each marker has 3 major properties :
* - id is the marker id;
* - pose.rotation gives its orientation using a rotation matrix
* and is a 3x3 array
* - pose.position gives its position with respect to the camera
* and is a vector with 3 components.
*/
if (objRoot === undefined) { return ; }
var i ;
for ( i = 0; i < arr.length; i++) {
if ( arr[i].id === id ) {
// insert your code here.
//<--
var rotation = arr[i].pose.rotation;
var translation = arr[i].pose.position;
/*var matrix = new THREE.Matrix4(
rotation[0][0], rotation[0][1], rotation[0][2], translation[0],
rotation[1][0], rotation[1][1], rotation[1][2], translation[1],
rotation[2][0], rotation[2][1], rotation[2][2], translation[2],
0 , 0, 0, 1);
/**
* Sets the object of interest on which we would like to apply transforms.
* @param obj {object} a Three.js Object3D
* @function ObjectTransform#setObject
*/
this.setObject = function (obj) {
objRoot = new THREE.Object3D();
obj.parent.add(objRoot);
obj.parent.remove(obj);
objRoot.add(obj);
var box = new THREE.Box3;
box.setFromObject(obj);
var s = box.size();
var scale = MAX3(s.x, s.y, s.z);
console.log(scale);
obj.add(new THREE.AxisHelper(scale / 2));
};
var r = new THREE.Euler();
r.setFromRotationMatrix(matrix);
objRoot.rotation.x = r.x;
objRoot.rotation.y = r.y;
objRoot.rotation.z = r.z;
objRoot.position.x = translation[0];
objRoot.position.y = translation[1];
objRoot.position.z = translation[2];
objRoot.scale.x = 1;
objRoot.scale.y = 1;
objRoot.scale.z = 1;*/
objRoot.rotation.x = -Math.asin(-rotation[1][2]);
objRoot.rotation.y = -Math.atan2(rotation[0][2], rotation[2][2]);
objRoot.rotation.z = Math.atan2(rotation[1][0], rotation[1][1]);
objRoot.position.x = translation[0];
objRoot.position.y = translation[1];
objRoot.position.z = -translation[2];
//-->
}
var MAX3 = function (a,b,c) {
if ( a >= b ) {
if ( a >= c) {
return a;
} else {
return c;
}
} else {
if (b >= c) {
return b;
} else {
return c;
}
};
this.setId = function (i) {
id = i;
};
},
['setObject', 'setTransform', 'setId'],
[]
);
}
};
// right now, we make something compatible with aruco markers
// it may evolve in the future
/**
* Takes an array of markers and then applies transformations
* to the referenced object.
* @function ObjectTransform#setTransform
* @param arr {Marker[]} an array of detected markers.
*/
this.setTransform = function ( arr ) {
/*2 set here the transformation we should apply on objRoot
* Each marker has 3 major properties :
* - id is the marker id;
* - pose.rotation gives its orientation using a rotation matrix
* and is a 3x3 array
* - pose.position gives its position with respect to the camera
* and is a vector with 3 components.
*/
if (objRoot === undefined) { return ; }
var i ;
for ( i = 0; i < arr.length; i++) {
if ( arr[i].id === id ) {
// insert your code here.
//<--
var rotation = arr[i].pose.rotation;
var translation = arr[i].pose.position;
/*var matrix = new THREE.Matrix4(
rotation[0][0], rotation[0][1], rotation[0][2], translation[0],
rotation[1][0], rotation[1][1], rotation[1][2], translation[1],
rotation[2][0], rotation[2][1], rotation[2][2], translation[2],
0 , 0, 0, 1);
var r = new THREE.Euler();
r.setFromRotationMatrix(matrix);
objRoot.rotation.x = r.x;
objRoot.rotation.y = r.y;
objRoot.rotation.z = r.z;
objRoot.position.x = translation[0];
objRoot.position.y = translation[1];
objRoot.position.z = translation[2];
objRoot.scale.x = 1;
objRoot.scale.y = 1;
objRoot.scale.z = 1;*/
objRoot.rotation.x = -Math.asin(-rotation[1][2]);
objRoot.rotation.y = -Math.atan2(rotation[0][2], rotation[2][2]);
objRoot.rotation.z = Math.atan2(rotation[1][0], rotation[1][1]);
return { ObjectTransform : ObjectTransform };
objRoot.position.x = translation[0];
objRoot.position.y = translation[1];
objRoot.position.z = -translation[2];
//-->
}
}
};
this.setId = function (i) {
id = i;
};
},
[ "deps/three.js/index" ]
);
\ No newline at end of file
['setObject', 'setTransform', 'setId'],
[]
);
export default { ObjectTransform : ObjectTransform };
......
arcs_module(
function(ARCS, three, _objloader, _mtlloader, _objmtlloader) {
var OBJLoader;
import ARCS from '../build/arcs.js';
import * as THREE from '../deps/three.js/index.js';
import { OBJLoader } from '../deps/objloader/objloader.js';
import { MTLLoader } from '../deps/mtlloader/mtlloader.js';
//import { DDSLoader } from '../deps/ddsloader/ddsloader.js';
var internalOBJLoader;
internalOBJLoader = ARCS.Component.create(
function() {
var self = this;
var innerObject;
OBJLoader = ARCS.Component.create(
function() {
var self = this;
var innerObject;
var onLoadWrapper = function(obj) {
innerObject = obj;
console.log("[OBJLoader] object has %d components", obj.children.length);
//console.log(obj);
self.emit("onLoad", obj);
};
var onLoadWrapper = function(obj) {
innerObject = obj;
console.log("[OBJLoader] object has %d components", obj.children.length);
//console.log(obj);
self.emit("onLoad", obj);
};
var onLoadJSON = function(geom, mat) {
innerObject = new THREE.Mesh(geom, new THREE.MeshFaceMaterial(mat));
self.emit("onLoad", innerObject);
};
var progress = function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
};
var error = function ( xhr ) {
console.log( 'An error happened' );
};
this.load = function(objURL, mtlURL) {
var loader;
// we may use a string tokenizer to determine file types
// then all would be in the same loading slot.
console.log("loading objects", objURL, mtlURL);
if (mtlURL === undefined) {
//console.log("using loader");
loader = new THREE.OBJLoader();
loader.load(objURL, onLoadWrapper, progress, error);
var onLoadJSON = function(geom, mat) {
innerObject = new THREE.Mesh(geom, new THREE.MeshFaceMaterial(mat));
self.emit("onLoad", innerObject);
};
var progress = function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
};
var error = function ( xhr ) {
console.log( 'An error happened' );
};
this.load = function(objURL, mtlURL) {
var loader;
// we may use a string tokenizer to determine file types
// then all would be in the same loading slot.
//console.log("loading objects", objURL, mtlURL);
var manager = new THREE.LoadingManager();
//manager.addHandler( /\.dds$/i, new DDSLoader() );
if (mtlURL === undefined) {
//console.log("using loader");
loader = new OBJLoader(manager);
loader.load(objURL, onLoadWrapper, progress, error);
} else {
//console.log("using mtl loader");
loader = new MTLLoader(manager);
loader.load(mtlURL, function(materials) {
materials.preload();
console.log(materials);
new OBJLoader(manager)
.setMaterials(materials)
.load(objURL, onLoadWrapper, progress, error);
}, progress, error);
}
};
this.loadJSON = function(jsonURL) {
var loader;
//console.log("loading objects", jsonURL);
loader = new THREE.ObjectLoader();
loader.load(jsonURL, onLoadJSON); //, progress, error);
};
var MAX3 = function (a,b,c) {
if ( a >= b ) {
if ( a >= c) {
return a;
} else {
//console.log("using mtl loader");
loader = new THREE.OBJMTLLoader();
loader.load(objURL, mtlURL, onLoadWrapper, progress, error);
return c;
}
};
this.loadJSON = function(jsonURL) {
var loader;
//console.log("loading objects", jsonURL);
loader = new THREE.JSONLoader();
loader.load(jsonURL, onLoadJSON); //, progress, error);
};
var MAX3 = function (a,b,c) {
if ( a >= b ) {
if ( a >= c) {
return a;
} else {
return c;
}
} else {
if (b >= c) {
return b;
} else {
if (b >= c) {
return b;
} else {
return c;
}
return c;
}
};
this.unitize = function() {
if (innerObject === undefined) { return ; }
var box = new THREE.Box3();
box.setFromObject(innerObject);
var s = box.size();
var c = box.center();
var scale = 1 / MAX3(s.x, s.y, s.z);
innerObject.scale.x = innerObject.scale.y = innerObject.scale.z = scale;
};
this.resize = function(s) {
this.unitize();
if (innerObject === undefined) { return ; }
innerObject.scale.x *= s;
innerObject.scale.y *= s;
innerObject.scale.z *= s;
};
},
["load","unitize", "resize"],
["onLoad"]
);
}
};
this.unitize = function() {
if (innerObject === undefined) { return ; }
var box = new THREE.Box3();
box.setFromObject(innerObject);
var s = box.size();
var c = box.center();
var scale = 1 / MAX3(s.x, s.y, s.z);
innerObject.scale.x = innerObject.scale.y = innerObject.scale.z = scale;
};
this.resize = function(s) {
this.unitize();
if (innerObject === undefined) { return ; }
innerObject.scale.x *= s;
innerObject.scale.y *= s;
innerObject.scale.z *= s;
};
return { OBJLoader: OBJLoader};
},
[ 'deps/three.js/index', 'deps/objloader/index', 'deps/mtlloader/index','deps/objmtlloader/index' ]
);
\ No newline at end of file
["load","unitize", "resize"],
["onLoad"]
);
export default { OBJLoader: internalOBJLoader};
......
{ "type": "module"}
arcs_module(function(ARCS) {
var TokenSender;
import ARCS from '../build/arcs.js';
TokenSender = ARCS.Component.create(
function( arr ) {
var i;
var self = this;
for (i=0; i< arr.length; i++) {
if (typeof arr[i] === "string") {
this.slots.push(arr[i]);
//TokenSender.prototype.slots.push(arr[i]);
this[arr[i]] = function( s ) {
return function() {
console.log("[TokenSender] emitting %s", s);
this.emit("sendToken",s);
};
} (arr[i]);
}
}
},
[],
['sendToken']
);
var TokenSender;
return { TokenSender : TokenSender };
});
\ No newline at end of file
TokenSender = ARCS.Component.create(
function( arr ) {
var i;
var self = this;
for (i=0; i< arr.length; i++) {
if (typeof arr[i] === "string") {
this.slots.push(arr[i]);
//TokenSender.prototype.slots.push(arr[i]);
this[arr[i]] = function( s ) {
return function() {
console.log("[TokenSender] emitting %s", s);
this.emit("sendToken",s);
};
} (arr[i]);
}
}
},
[],
['sendToken']
);
export default { TokenSender : TokenSender };
......
arcs_module(function(ARCS) {
var LiveSource, VideoSource;
LiveSource = ARCS.Component.create(
function () {
var context, canvas, video, imageData;
var defaultWidth = 320;
var defaultHeight = 240;
var self = this;
var handleMediaStream = function(stream) {
if (window.webkitURL) {
video.src = window.webkitURL.createObjectURL(stream);
} else if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
} else if (video.srcObject !== undefined) {
video.srcObject = stream;
} else {
video.src = stream;
}
video.videoWidth=defaultWidth;
video.videoHeight=defaultHeight;
self.emit("onReady");
};
var errorMediaStream = function(error) {
console.error("Cannot initialize video component:", error.code);
};
var setUserMedia = function() {
console.log("video test");
if (navigator.mediaDevices !== undefined) {
navigator.mediaDevices.getUserMedia({video:{facingMode : "environment"}})
.then(handleMediaStream)
.catch(errorMediaStream);
} else {
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (getUserMedia !== undefined) {
console.log(getUserMedia(), handleMediaStream, errorMediaStream);
/*getUserMedia({video:true}, handleMediaStream,
errorMediaStream
);*/
getUserMedia({video:true}).then(handleMediaStream);
}
}
};
this.grabFrame = function () {
if ( context === undefined || canvas === undefined || video === undefined)
return;
if (video.readyState === video.HAVE_ENOUGH_DATA) {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
this.emit("onImage",imageData);
import ARCS from '../build/arcs.js';
var LiveSource, VideoSource;
LiveSource = ARCS.Component.create(
function () {
var context, canvas, video, imageData;
var defaultWidth = 320;
var defaultHeight = 240;
var self = this;
var handleMediaStream = function(stream) {
console.log(video,stream);
if (window.webkitURL) {
video.src = window.webkitURL.createObjectURL(stream);
} else if (video.mozSrcObject !== undefined) {
video.mozSrcObject = stream;
} else if (video.srcObject !== undefined) {
video.srcObject = stream;
} else {
video.src = stream;
}
/*video.videoWidth=defaultWidth;
video.videoHeight=defaultHeight;*/
self.emit("onReady");
};
var errorMediaStream = function(error) {
console.error("Cannot initialize video component:", error.code);
};
var setUserMedia = function() {
if (navigator.mediaDevices !== undefined) {
navigator.mediaDevices.getUserMedia({video: {facingMode: "environment", width: defaultWidth, height: defaultHeight}})
.then(handleMediaStream)
.catch(errorMediaStream);
} else {
var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
if (getUserMedia !== undefined) {
getUserMedia({video:true}).then(handleMediaStream);
}
};
}
};
this.grabFrame = function () {
if ( context === undefined || canvas === undefined || video === undefined)
return;
if (video.readyState === video.HAVE_ENOUGH_DATA) {
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
this.emit("onImage",imageData);
}
};
this.setSize = function(x,y) {
this.setSize = function(x,y) {
};
};
this.setWidgets = function (videoId, canvasId) {
video = document.getElementById(videoId);
canvas = document.getElementById(canvasId);
this.setWidgets = function (videoId, canvasId) {
video = document.getElementById(videoId);
canvas = document.getElementById(canvasId);
if (video === undefined || canvas === undefined) {
console.log("video elements not defined");
return;
}
context = canvas.getContext("2d");
var canvasStyle= window.getComputedStyle(canvas);
canvas.width=parseInt(canvasStyle.width);
canvas.height=parseInt(canvasStyle.height);
setUserMedia();
};
},
['grabFrame','setWidgets'],
['onReady','onImage']
);
VideoSource = ARCS.Component.create(
function() {
var context, canvas, video, imageData;
var defaultWidth=320;
var defaultHeight=240;
var self=this;
if (video === undefined || canvas === undefined) {
console.log("video elements not defined");
return;
}
context = canvas.getContext("2d");
var canvasStyle= window.getComputedStyle(canvas);
canvas.width=parseInt(canvasStyle.width);
canvas.height=parseInt(canvasStyle.height);
setUserMedia();
};
},
['grabFrame','setWidgets'],
['onReady','onImage']
);
VideoSource = ARCS.Component.create(
function() {
var context, canvas, video, imageData;
var defaultWidth=320;
var defaultHeight=240;
var self=this;
this.setWidgets = function (videoId, canvasId) {
video = document.getElementById(videoId);
canvas = document.getElementById(canvasId);
this.setWidgets = function (videoId, canvasId) {
video = document.getElementById(videoId);
canvas = document.getElementById(canvasId);
if (video === undefined || canvas === undefined) {
return;
}
context = canvas.getContext("2d");
var canvasStyle= window.getComputedStyle(canvas);
canvas.width=parseInt(canvasStyle.width);
canvas.height=parseInt(canvasStyle.height);
if (video === undefined || canvas === undefined) {
return;
}
context = canvas.getContext("2d");
var canvasStyle= window.getComputedStyle(canvas);
canvas.width=parseInt(canvasStyle.width);
canvas.height=parseInt(canvasStyle.height);
if (video.paused || video.ended) {
video.addEventListener('play', function() {
self.emit("onReady");
});
} else {
if (video.paused || video.ended) {
video.addEventListener('play', function() {
self.emit("onReady");
}
};
});
} else {
self.emit("onReady");
}
this.grabFrame = function () {
if ( context === undefined || canvas === undefined || video === undefined)
return;
if (video.paused || video.ended) {
return;
}
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
this.emit("onImage",imageData);
};
};
this.grabFrame = function () {
if ( context === undefined || canvas === undefined || video === undefined)
return;
if (video.paused || video.ended) {
return;
}
context.drawImage(video, 0, 0, canvas.width, canvas.height);
imageData = context.getImageData(0, 0, canvas.width, canvas.height);
this.emit("onImage",imageData);
};
},
['grabFrame', 'setWidgets'],
['onReady', 'onImage']
);
return {LiveSource: LiveSource, VideoSource: VideoSource};
});
},
['grabFrame', 'setWidgets'],
['onReady', 'onImage']
);
export default {LiveSource: LiveSource, VideoSource: VideoSource};
......
arcs_module(
function (ARCS) {
var WindowEvent;
import ARCS from '../build/arcs.js';
WindowEvent = ARCS.Component.create(
function () {
var self= this;
window.onresize = function() {
self.emit("onResize",window.innerWidth, window.innerHeight);
};
},
[],
["onResize"]
);
let WindowEvent;
WindowEvent = ARCS.Component.create(
function () {
let self= this;
window.onresize = function() {
self.emit("onResize",window.innerWidth, window.innerHeight);
};
},
[],
["onResize"]
);
return { WindowEvent: WindowEvent};
}
);
\ No newline at end of file
export default { WindowEvent: WindowEvent};
......
......@@ -493,3 +493,5 @@ Mat3.prototype.row = function(index){
return new Vec3( m[index][0], m[index][1], m[index][2] );
};
export default POS;
......
......@@ -529,3 +529,5 @@ POS.Pose = function(error1, rotation1, translation1, error2, rotation2, translat
this.alternativeRotation = rotation2;
this.alternativeTranslation = translation2;
};
export default POS;
......
......@@ -129,4 +129,6 @@ POS.SquareFiducial.prototype.crossProduct = function(a,b) {
POS.SimplePose = function(pos, rot) {
this.position = pos;
this.rotation = rot;
};
\ No newline at end of file
};
export default POS;
......
......@@ -281,3 +281,5 @@ SVD.pythag = function(a, b){
SVD.sign = function(a, b){
return b >= 0.0? Math.abs(a): -Math.abs(a);
};
export default SVD;
......
arcs_module(function(ARCS) {
THREE.FrustumCamera = function ( left, right, bottom, top, near, far ) {
import * as THREE from './index.js';
let FrustumCamera = function ( left, right, bottom, top, near, far ) {
THREE.Camera.call( this );
......@@ -17,22 +18,22 @@ THREE.FrustumCamera = function ( left, right, bottom, top, near, far ) {
};
THREE.FrustumCamera.prototype = Object.create( THREE.Camera.prototype );
THREE.FrustumCamera.prototype.constructor = THREE.FrustumCamera;
FrustumCamera.prototype = Object.create( THREE.Camera.prototype );
FrustumCamera.prototype.constructor = FrustumCamera;
THREE.FrustumCamera.prototype.updateProjectionMatrix = function () {
FrustumCamera.prototype.updateProjectionMatrix = function () {
this.projectionMatrix.makeFrustum(
this.left, this.right, this.bottom, this.top, this.near, this.far
);
};
THREE.FrustumCamera.prototype.clone = function () {
FrustumCamera.prototype.clone = function () {
var camera = new THREE.FrustumCamera();
var camera = new FrustumCamera();
THREE.Camera.prototype.clone.call( this, camera );
......@@ -51,6 +52,4 @@ THREE.FrustumCamera.prototype.clone = function () {
};
return {};
}, ['deps/three.js/index']
);
export default FrustumCamera;
......
......@@ -11,14 +11,17 @@
"Reality"
],
"author": "Jean-Yves Didier",
"license": "GPL",
"license": "GPL-3.0-or-later",
"devDependencies": {
"bower": ">=1.3.9",
"grunt": ">=0.4.5",
"grunt-jslint": ">=1.1.12",
"grunt-contrib-uglify": ">=0.5.1",
"grunt-terser": "*",
"grunt-jsdoc": ">=0.5.6",
"grunt-bower-task": ">=0.4.0",
"grunt-contrib-concat": ">=0.5.0"
"grunt-contrib-concat": ">=0.5.0",
"grunt-contrib-copy": ">=1.0.0",
"grunt-file-append": ">=0.0.7",
"grunt-string-replace": ">=1.3.1"
}
}
......
......@@ -199,7 +199,7 @@ ARCS.Application = function () {
* Starts the application
*/
this.start = function () {
console.log("[ARCS] Starting application");
console.log("[ARCS] Starting application...");
context.instanciate().then(preProcess);
};
};
......
......@@ -22,19 +22,11 @@ var ARCS = ARCS || {};
* Helper functions to determine environment
* ***************************************************************************/
/**
* @return {boolean} true if ARCS is run in a node.js environment
*/
ARCS.isInNode = function () {
return (typeof require === 'function' && require.resolve);
return (typeof require === 'function' && require.resolve);
};
/**
* @return {boolean} true if ARCS is run with require.js
*/
ARCS.isInRequire = function () {
return (typeof define === 'function' && define.amd);
};
......
......@@ -6,43 +6,31 @@ import ARCS from './arcs.js';
* It relies on require.js to get the job done.
* @file
*/
"use strict";
// basically, here we start by importing the module ARCS
import ARCS from './arcs.js';
console.log("Bootstrapping ARCS...");
console.log("[ARCS] Bootstrapping...");
var baseUrl, appDescription, requireMarkup, xhr;
requireMarkup = document.querySelector('[data-main]');
requireMarkup = document.querySelector('[data-arcsapp]');
if (requireMarkup !== undefined) {
baseUrl = requireMarkup.dataset.baseUrl ;
appDescription = requireMarkup.dataset.arcsapp || "arcsapp.json";
}
// do not move these lines: xhr.open must be performed before require
// changes paths.
xhr = new XMLHttpRequest();
xhr.open('GET',appDescription,true);
xhr.overrideMimeType("application/json");
xhr.onerror = function (e) {
console.error("[ARCS] Failed to get app description (",appDescription,"):",e.target.status,e.message);
};
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
try {
console.log("ARCS application description loaded");
var applicationObject = JSON.parse(xhr.responseText);
if (baseUrl) {
// TODO change this line below
require.config( { baseUrl: baseUrl });
}
var aap = new ARCS.Application();
aap.import(applicationObject);
console.log("Starting application...");
aap.start();
} catch (e) {
console.error("[ARCS] Error while parsing JSON:",e);
}
}
};
xhr.send();
(async function toto() {
var description = await(fetch(appDescription));
var applicationObject = await(description.json());
console.log("[ARCS] Application description loaded");
var aap = new ARCS.Application();
aap.import(applicationObject);
aap.start();
})();
......
/**
* definition of the main module function:
* it takes an anonymous function as a parameter
* the anonymous function has one parameter: the object encompassing
* ARCS definitions (in order to able to use ARCS.Component.create, ...)
* @param moduleDefinition {function} main function of the module.
* It should return a list of components
* @param deps {mixed[]} dependencies
*/
// TODO remove dependency handling
// reimplementation using native promises
arcs_module = function(moduleDefinition) {
var storeComponents, i;
// TODO verify if this is still needed
if (typeof module !== 'undefined') {
if (module.parent.exports) {
ARCS = module.exports;
}
}
storeComponents = function () {
var mdef, p;
// we should insert ARCS at the beginning of deps !
mdef = (typeof moduleDefinition === 'function') ?
moduleDefinition.apply(this) : moduleDefinition;
if (mdef === undefined) {
throw new Error("[ARCS] Your module is undefined. Did you forget to export components?\nCode of module follows:\n" +moduleDefinition);
}
for (p in mdef) {
if (mdef.hasOwnProperty(p) && ARCS.Context.currentContext != null) {
ARCS.Context.currentContext.setFactory(p,mdef[p]); //.setFactory(ARCS.Application.currentApplication, p, mdef[p]);
}
}
return Promise.resolve();
};
// until now, it is the very same code.
ARCS.Context.currentContext.addLibraryPromise(
storeComponents,
function(reason) { console.error("[ARCS] Failed to load dependency ", reason ); })
);
}
#!/usr/bin/env node
var ARCS = require('./arcs.js');
var application = require('./appli.json');
var aap = new ARCS.Application();
aap.import(application);
aap.start();
#!/usr/bin/env -S node --experimental-modules --experimental-json-modules
import ARCS from './arcs.js';
import process from 'process';
import path from 'path';
import fs from 'fs';
//import application from './appli.json';
function usage() {
let sp = process.argv[1].lastIndexOf(path.delimiter);
console.log("usage:");
console.log("\t",
process.argv[1],
"description.json"
);
}
if (process.argv.length < 3) {
usage();
process.exit(1);
}
var appDescription = fs.readFileSync(process.argv[2]);
if (appDescription === '') {
console.error("File '"+process.argv[2]+"' is empty.");
process.exit(2);
}
var application = JSON.parse(appDescription);
var aap = new ARCS.Application();
aap.import(application);
aap.start();
......@@ -9,7 +9,7 @@ ARCS.Context = function( ctx ) {
var constants = {};
var factories = {};
var libraries = [];
var depLibPromises=[];
//var depLibPromises=[];
var self = this;
var loadLibraries;
var loadDataFile;
......@@ -23,6 +23,7 @@ ARCS.Context = function( ctx ) {
if (ctx !== undefined) {
libraries = ctx.libraries;
var p;
for (p in ctx.components) {
if (ctx.components.hasOwnProperty(p)) {
components[p] = ctx.components[p];
......@@ -39,8 +40,7 @@ ARCS.Context = function( ctx ) {
}
loadDataFile = function(fileName) {
var loadDataFile =async function(fileName) {
var dataPromise ;
if (ARCS.isInNode()) {
......@@ -53,59 +53,12 @@ ARCS.Context = function( ctx ) {
}
});
} else {
return new Promise(function(resolve, reject) {
var client = new XMLHttpRequest();
client.open('GET',fileName,true);
client.overrideMimeType("application/json");
client.send();
client.onload = function() {
if (this.status >= 200 && this.status < 300) {
resolve(JSON.parse(this.responseText));
} else {
console.error(this.statusText);
reject(this.statusText);
}
};
client.onerror = function() {
console.error(this.statusText);
reject(this.statusText);
};
});
var client = await fetch(fileName);
return client.json();
}
};
this.addLibraryPromise = function(p) {
depLibPromises.push(p);
};
promiseLibrary = function(libName) {
return new Promise(function(resolve, reject) {
if (libName.substr(-3) === '.js') {
reject(libName);
}
if (ARCS.isInNode()) {
if (require("./" + libraries[i] + ".js") === undefined) {
reject(libName);
} else {
resolve();
}
} else {
require([libName],
function() {
resolve();
},
function(err) {
reject(libName,err);
}
);
}
});
};
loadLibraries = function () {
var loadLibraries = function () {
var i;
// we will use different instances of require either the one of node
// or the one from require.js
......@@ -113,14 +66,13 @@ ARCS.Context = function( ctx ) {
var res=[];
for(i=0; i < libraries.length; i++) {
res.push(promiseLibrary(libraries[i]));
res.push(self.loadLibrary(libraries[i]));
}
return Promise.all(res);
};
instanciateComponents = function() {
var instanciateComponents = function() {
var p, promises=[];
console.log(components);
for (p in components) {
if (components.hasOwnProperty(p)) {
......@@ -129,7 +81,7 @@ ARCS.Context = function( ctx ) {
console.error("[ARCS] Context dump follows: ", libraries, components, constants);
return ;
}
factory = factories[components[p].type];
var factory = factories[components[p].type];
//console.log("instanciating ", p);
try {
if (components[p].value !== undefined || components[p].url !== undefined || components[p].ref !== undefined) {
......@@ -140,11 +92,12 @@ ARCS.Context = function( ctx ) {
// we need currying here !
var delayInstanciation = function(p,factory) {
return function(obj) {
console.log("instanciating from data file");
components[p].instance = new factory(obj);
return Promise.resolve();
}
};
console.log("loading data file", components[p].url);
promises.push(
loadDataFile(components[p].url).then(delayInstanciation(p,factory))
);
......@@ -177,13 +130,23 @@ ARCS.Context = function( ctx ) {
libActualName = libName.name;
libUrl = libName.url;
}
libraries.push(libActualName);
promiseLibrary(libUrl).then( function() {
if (libraries.indexOf(libActualName) < 0) {
libraries.push(libActualName);
}
// TODO promisify call to cbFunction
return import(libUrl).then( function(module) {
// TODO insert here component factories
for (p in module.default) {
if (module.default.hasOwnProperty(p)) {
ARCS.Context.currentContext.setFactory(p,module.default[p]);
}
}
if (cbFunction !== undefined) {
cbFunction();
}
});
}).catch( function(msg) { console.error("[ARCS] Trouble loading '",libUrl,"' with reason -", msg) });
};
/**
......@@ -300,9 +263,9 @@ ARCS.Context = function( ctx ) {
// this should return a promise !
this.instanciate = function () {
return loadLibraries().then(function() { return Promise.all(depLibPromises); })
.then(instanciateComponents)
.catch(function(msg) { console.log("[ARCS] Trouble instanciating context", msg); });
//! TODO
return loadLibraries().then(instanciateComponents)
.catch(function(msg) { console.error("[ARCS] Trouble instanciating context", msg); });
};
......
// no longer needed with the use of imports
// ARCS is then defined as a node.js module
if (!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;
// hack for require.js
// ARCS is then defined as a require.js module.
if (ARCS.isInRequire()) {
//console.log("module ARCS in require.js");
define(exports);
}
export { ARCS as default};
\ No newline at end of file
......
......@@ -35,7 +35,7 @@ ARCS.TransitionNetwork.build = function(tree, tokenEvents) {
}
res = ARCS.TransitionNetwork.build(tree[0],tokenEvents);
var i;
for (i=1; i < tree.length; i++) {
if (tree[i].hasOwnProperty('and')) {
rightTN = ARCS.TransitionNetwork.build(tree[i]['and'], tokenEvents);
......
{
"context": {
"libraries": [
"components/arviewer","components/animator",
"components/objloader","components/video",
"components/arucodetector", "components/markerlocator",
"components/windowevent", "components/tokensender", "components/objecttransform"
"../components/arviewer.js","../components/animator.js",
"../components/objloader.js","../components/video.js",
"../components/arucodetector.js", "../components/markerlocator.js",
"../components/windowevent.js", "../components/tokensender.js", "../components/objecttransform.js"
],
"components": {
"viewer": { "type": "ARViewer"},
......
......@@ -2,15 +2,15 @@
<head>
<title>ARCS: marker experiment</title>
<link type="text/css" rel="stylesheet" href="arcs.css">
<script data-main="../../build/arcs_browser"
<script src="../../build/arcs_browser.js"
data-base-url="../.."
data-arcsapp="arcsapp.json"
src="../../deps/requirejs/require.js">
type="module">
</script>
<meta charset="UTF-8">
</head>
<body>
<video id="video" width=320 height=240 autoplay="true" style="display: none;"></video>
<video id="video" width=640 height=480 autoplay="true" style="display: none;"></video>
<canvas id="canvas"></canvas>
<div id="container" ></div>
<div id="contents">
......
{
"context" : {
"libraries" : [ "components/loop","components/console"],
"libraries" : [ "../components/loop.js","../components/console.js"],
"components" : {
"loop": { "type": "Loop" },
"dint": { "type": "DisplayInt" },
......
<html>
<head>
<title>ARCS engine</title>
<script data-main="../../build/arcs_browser"
data-base-url="../.."
data-arcsapp="arcsapp.json"
src="../../deps/requirejs/require.js">
</script>
<script data-base-url="../.."
data-arcsapp="arcsapp.json"
type="module"
src="../../build/arcs_browser.js">
</script>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<h1>ARCS in Web Browser</h1>
<div style="height:100px; overflow: auto; border: solid 1px navy;">
<p id="output" style="margin: 5px; padding: 5px;"></p>
<div style="height:80vh; overflow: auto; border: solid 1px navy;">
<p id="output" style="margin: 5px; padding: 5px; font-family: monospace;"></p>
<div>
</body>
</html>
......