Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding the WebWorker feature to WebARStudio #1

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
listeners works correctly, removed onTrackableNFTFound
  • Loading branch information
kalwalt committed May 14, 2020
commit adaf63de9b193f91641b150ddc45f6303eaee264
70 changes: 34 additions & 36 deletions editor/js/components/arcontroller.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,42 @@ ArControllerComponent.prototype.onRemovedFromScene = function( scene ) {
ArControllerComponent.prototype.startAR = function() {
console.log("Start AR");
this._video = this.getUserMedia()
window.addEventListener('getDataFromWorker', this.onTrackableNFTFound.bind(this));
};

this._arTrackable2DList.forEach(arTrackable => {
var self = this;
window.addEventListener('getDataFromWorker', function(ev) {

const markerIndex = ev.detail.data.index;
const markerType = ev.detail.data.type;
const marker = ev.detail.data.marker;

if (ev.detail.data.type === 2) {
trackableId = ev.detail.data.marker.id;
}
if (trackableId !== -1) {
console.log("saw a trackable with id", trackableId);

let markerRoot = arTrackable.attachedGameObject;
arTrackable.visible = true;
console.log("visible")
// Note that you need to copy the values of the transformation matrix,
// as the event transformation matrix is reused for each marker event
// sent by an ARController.
var transform = ev.detail.data.matrix;

// Apply transform to marker root

let cameraGlobalMatrix = self.arCameraNode.transform.getGlobalMatrix();
let markerRootMatrix = mat4.create();
mat4.multiply(markerRootMatrix, cameraGlobalMatrix, transform);
let outQuat = quat.create();
quat.fromMat4(outQuat,markerRootMatrix);
outQuat[0]*=-1;
markerRoot.transform.setPosition(vec3.fromValues(markerRootMatrix[12],markerRootMatrix[13]*-1,markerRootMatrix[14]*-1));
markerRoot.transform.setRotation(outQuat);
}
});
});
};

ArControllerComponent.prototype.getUserMedia = async function() {
var self = this;
Expand Down Expand Up @@ -269,39 +300,6 @@ ArControllerComponent.prototype.unRegisterTrackable = function(arTrackable2D){
}
}

ArControllerComponent.prototype.onTrackableNFTFound = function (ev){
const markerIndex = ev.detail.data.index;
const markerType = ev.detail.data.type;
const marker = ev.detail.data.marker;

if (ev.detail.data.type === 2) {
trackableId = ev.detail.data.marker.id;
}
if (trackableId !== -1) {
console.log("saw a trackable with id", trackableId);

let markerRoot = arTrackable.attachedGameObject;
arTrackable.visible = true;
console.log("visible")
// Note that you need to copy the values of the transformation matrix,
// as the event transformation matrix is reused for each marker event
// sent by an ARController.
var transform = ev.detail.data.matrix;
// console.log(transform);

// Apply transform to marker root

let cameraGlobalMatrix = this.arCameraNode.transform.getGlobalMatrix();
let markerRootMatrix = mat4.create();
mat4.multiply(markerRootMatrix, cameraGlobalMatrix, transform);
let outQuat = quat.create();
quat.fromMat4(outQuat,markerRootMatrix);
outQuat[0]*=-1;
markerRoot.transform.setPosition(vec3.fromValues(markerRootMatrix[12],markerRootMatrix[13]*-1,markerRootMatrix[14]*-1));
markerRoot.transform.setRotation(outQuat);
}
}

ArControllerComponent.prototype._setupCameraForScreenOrientation = function (orientation) {

// Camera matrix is used to define the “perspective” that the camera would see.
Expand Down