Hi,
I have been trying to use ar.js to find a marker and then anchor the object in the real world using webxr (immersive-ar).
I am able to get raw camera access and then pass it to ar.js to find the marker. And it is able to successfully find it.
I have setup two scenes since the projectionMatrix of both AR.js (arController) and WebXR (view.projectionMatrix) is locked.
Now the problem is I have to mimic the AR.js markerObject in the WebXR scene.
The closest I can reach is the following code:
function newRelativePositionMatrix(objectA, objectB, objectC, objectD) {
// Get the matrix of object A
var matrixA = new THREE.Matrix4();
matrixA.copy(objectA.matrixWorld);
// Get the matrix of object B
var matrixB = new THREE.Matrix4();
matrixB.copy(objectB.matrixWorld);
// Get the matrix of object C
var matrixC = new THREE.Matrix4();
matrixC.copy(objectC.matrixWorld);
// Get the matrix of object D
var matrixD = new THREE.Matrix4();
matrixD.copy(objectD.matrixWorld);
// Calculate the relative position of object B to object A using their matrices
var relativePositionB = new THREE.Vector3();
relativePositionB.setFromMatrixPosition(matrixB);
relativePositionB.sub(new THREE.Vector3().setFromMatrixPosition(matrixA));
// Calculate the relative position of object D to object C using their matrices
var relativePositionD = new THREE.Vector3();
relativePositionD.setFromMatrixPosition(matrixD);
relativePositionD.sub(new THREE.Vector3().setFromMatrixPosition(matrixC));
var inverseMatrixC = new THREE.Matrix4();
inverseMatrixC.copy(matrixC).invert();
relativePositionD.applyMatrix4(inverseMatrixC);
relativePositionD.copy(relativePositionB).add(relativePositionD);
relativePositionD.applyMatrix4(matrixC);
// Set the position of object D to the calculated relative position
objectD.position.copy(relativePositionD);
objectD.updateMatrix();
}
How do I go about this ?
Am I missing some fundamental piece ? like the relative scale of a AR.js scene vs the WebXR scene, etc