97 lines
2.0 KiB
JavaScript
97 lines
2.0 KiB
JavaScript
/**
|
|
* R3.System.AR
|
|
* @param apiSystem R3.API.System
|
|
* @constructor
|
|
*/
|
|
R3.System.AR = function(
|
|
apiSystem
|
|
) {
|
|
R3.System.call(
|
|
this,
|
|
apiSystem
|
|
);
|
|
|
|
this.instanceCreatedSubscription = null;
|
|
|
|
this.removeComponentSubscription = null;
|
|
|
|
this.beforeRenderSubscription = null;
|
|
|
|
this.arComponents = [];
|
|
|
|
};
|
|
|
|
R3.System.AR.prototype = Object.create(R3.System.prototype);
|
|
R3.System.AR.prototype.constructor = R3.System.AR;
|
|
|
|
/**
|
|
* Start this system (add all event listeners)
|
|
*/
|
|
R3.System.AR.prototype.start = function() {
|
|
|
|
R3.System.prototype.start.call(this);
|
|
|
|
this.instanceCreatedSubscription = this.subscribe(
|
|
R3.Event.INSTANCE_CREATED,
|
|
this.instanceCreated
|
|
);
|
|
|
|
this.removeComponentSubscription = this.subscribe(
|
|
R3.Event.REMOVE_COMPONENT,
|
|
this.removeComponent
|
|
);
|
|
|
|
this.beforeRenderSubscription = this.subscribe(
|
|
R3.Event.BEFORE_RENDER,
|
|
this.beforeRender
|
|
);
|
|
|
|
};
|
|
|
|
/**
|
|
* From now on we want to track everything about a component, only from the systems that are active
|
|
* @param data
|
|
*/
|
|
R3.System.AR.prototype.instanceCreated = function(data) {
|
|
if (data.component instanceof R3.D3.AR) {
|
|
R3.Utils.PushUnique(this.arComponents, data.component);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Removes an AR component from the System
|
|
* @param data
|
|
*/
|
|
R3.System.AR.prototype.removeComponent = function(data) {
|
|
|
|
if (data.component instanceof R3.D3.AR) {
|
|
|
|
var index = this.arComponents.indexOf(data.component);
|
|
|
|
if (index === -1) {
|
|
console.warn('AR system out of sync');
|
|
return;
|
|
}
|
|
|
|
this.arComponents.splice(index, 1);
|
|
}
|
|
};
|
|
|
|
R3.System.AR.prototype.beforeRender = function(data) {
|
|
console.log('AR Render');
|
|
};
|
|
|
|
|
|
/**
|
|
* Stop this system (remove all event listeners)
|
|
*/
|
|
R3.System.AR.prototype.stop = function() {
|
|
|
|
R3.System.prototype.stop.call(this);
|
|
|
|
this.instanceCreatedSubscription.remove();
|
|
this.removeComponentSubscription.remove();
|
|
this.beforeRenderSubscription.remove();
|
|
|
|
};
|