My webxr camera is not at position of camera given in three.js perspective camera used in render function !!
I found somewhere that the way to make webxr camera appear in same position in the camera is this so I added this in the animate function
const xrManager = renderer.xr
let firstTime = true
function animate(now: number) {
let delta = clock.getDelta()
delta = Math.max(delta, 0.1)
world.step(delta)
if (ballAdded) {
balls.forEach((element, index) => {
element.position.set(
ballBodies[index].position.x,
ballBodies[index].position.y,
ballBodies[index].position.z
)
})
}
if (orbitControls.enabled) {
orbitControls.update()
}
cannonDebugRenderer.update()
TWEEN.update()
KeyBoardHandler.keyUpdate(handlers, keys, delta * 1000)
if (character) {
character.position.copy(camera.position)
}
if (xrManager.isPresenting && firstTime) {
firstTime = false
const baseReferenceSpace = xrManager.getReferenceSpace(),
offsetPosition = camera!.position,
offsetRotation = camera!.rotation
console.log(baseReferenceSpace)
const transform = new XRRigidTransform(
{ x: offsetPosition.x, y: offsetPosition.y, z: offsetPosition.z, w: 1 },
{
x: offsetRotation.x,
y: -1 * offsetRotation.y,
z: offsetRotation.z,
w: 1,
}
),
//const transform = new XRRigidTransform( offsetPosition, { x: offsetRotation.x, y: -(offsetRotation.y - 0.5) , z: offsetRotation.z, w: offsetRotation.w } ),
teleportSpaceOffset = baseReferenceSpace!.getOffsetReferenceSpace(transform)
xrManager.setReferenceSpace(teleportSpaceOffset)
}
updateControllerAction()
render(delta)
}
function render(delta) {
// renderer.setViewport(0, 0, window.innerWidth, window.innerHeight)
// composerScreen.render(delta)
// renderer.clear(false, true, false)
// renderer.setViewport(20, window.innerHeight - 256, 256, 256)
// composerMap.render(delta)
renderer.render(scene, camera)
labelRenderer.render(scene, camera)
// scene.background = new THREE.Color(0xffffff)
}
renderer.setAnimationLoop(animate)
but the problem is that camera scene is this:
but after adding that code camera render this:
I guess this is either outside of my mesh
when i go out without VR mode, this is my mesh outside
after changing camera position to somewhere and positioning VR headset in webxr emulator for so many time,
I managed to get this manually
Is there anyway i can have webxr camera at the camera position !!!