engine
engine copied to clipboard
Rendering Artifacts/Clipping when Synchronizing Pose in Distributed Engine Binary
Hi 8th Wall Team,
I am experiencing a critical rendering issue using the Distributed Engine Binary with a custom Three.js integration.
The Issue: When I attempt to synchronize the 3D model's position and rotation using the data from reality.detectedImages[0].position and .rotation, the model exhibits severe partial transparency and flickering faces (clipping).
Interestingly:
If I comment out the cube.position.set() and cube.quaternion.set() lines, the cube renders perfectly (but remains static at the origin and does not follow the target).
As soon as I apply the coordinates provided by the engine, the faces of the cube start to disappear or flicker depending on the camera angle.
Best regards,
My Code: `
<div id="overlay" onclick="handleStart()">
<h2 id="btn-text">AR </h2>
<p id="status-text" style="color: #aaa; font-size: 14px;">...</p>
</div>
<canvas id="camera-canvas"></canvas>
<script>
let scene, camera, renderer, cube;
let isStarted = false;
const initThreeScene = (canvas) => {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(70, window.innerWidth / window.innerHeight, 0.01, 1000);
renderer = new THREE.WebGLRenderer({
canvas: canvas,
context: canvas.getContext('webgl') || canvas.getContext('experimental-webgl'),
alpha: true,
antialias: true
});
renderer.autoClear = false;
renderer.setSize(window.innerWidth, window.innerHeight);
const geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
const material = new THREE.MeshNormalMaterial();
cube = new THREE.Mesh(geometry, material);
cube.position.set(0, 0, -1);
scene.add(cube);
};
async function handleStart() {
if (isStarted) return;
isStarted = true;
const statusText = document.getElementById('status-text');
try {
await navigator.mediaDevices.getUserMedia({ video: true }).then(s => s.getTracks().forEach(t => t.stop()));
await XR8.loadChunk('slam');
XR8.addCameraPipelineModules([
XR8.GlTextureRenderer ? XR8.GlTextureRenderer.pipelineModule() : {},
XR8.XrController.pipelineModule(),
{
name: 'app-logic',
onStart: ({canvas}) => {
initThreeScene(canvas);
cube.visible = false;
document.getElementById('overlay').style.display = 'none';
},
onUpdate: (e) => {
const {processCpuResult} = e;
if (!processCpuResult || !processCpuResult.reality) return;
const {reality} = processCpuResult;
if (reality.intrinsics) {
camera.projectionMatrix.fromArray(reality.intrinsics);
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
}
camera.position.set(reality.position.x, reality.position.y, reality.position.z);
camera.quaternion.set(reality.rotation.x, reality.rotation.y, reality.rotation.z, reality.rotation.w);
if (reality.detectedImages && reality.detectedImages.length > 0) {
const target = reality.detectedImages[0];
if (target && target.position && target.rotation) {
cube.visible = true;
cube.position.set(target.position.x, target.position.y, target.position.z);
cube.quaternion.set(target.rotation.x, target.rotation.y, target.rotation.z, target.rotation.w);
const s = target.scale || 1.0;
cube.scale.set(s, s, s);
cube.translateZ(0.11);
cube.updateMatrixWorld(true);
}
} else {
cube.visible = false;
}
},
onRender: () => {
if (renderer) {
renderer.state.reset();
renderer.render(scene, camera);
}
},
}
]);
XR8.XrController.configure({
disableWorldTracking: true,
imageTargetData: [{
"imagePath": "./assets/my-poster.png",
"name": "hero-poster",
"type": "PLANAR",
"metadata": null,
"properties": {
"left": 0,
"top": 0,
"width": 1080,
"height": 703,
"isRotated": false,
"originalWidth": 1080,
"originalHeight": 703
},
"resources": {
"originalImage": "hero-poster",
"luminanceImage": "hero-poster"
}
}]
});
XR8.run({
canvas: document.getElementById('camera-canvas'),
allowedDevices: XR8.XrConfig.device().ANY,
ownCamera: false
});
} catch (err) {
console.error("Error:", err);
statusText.innerText = err.message;
isStarted = false;
}
}
</script>
`