Thanks for pointing that out! Yes, the right side viewer container is where the live 3D preview should show up.
If you're seeing nothing there, let's troubleshoot the most common issues that might cause the 3D canvas to not appear or render blank:
1. Renderer canvas not appended
Make sure the Three.js renderer's canvas is appended to viewerContainer.
In the code, this line should do that:
renderer = new THREE.WebGLRenderer({antialias:true, alpha: false});
renderer.setSize(viewerContainer.clientWidth, viewerContainer.clientHeight);
viewerContainer.appendChild(renderer.domElement);
If for some reason this line is missing or fails, the viewer will be blank.
2. Mesh and geometry created and added
If no mesh exists in the scene, or if it's too small/big/out of camera view, nothing will appear. The code should create a mesh and add it to the scene:
mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI / 2;
scene.add(mesh);
Sometimes the rotation or camera position causes the mesh not to be visible.
3. Camera position and controls
Camera is positioned here:
camera.position.set(0, maxHeight/2, maxHeight * 1.7);
And orbit controls target:
controls.target.set(0, 0, 0);
If the camera or controls target is wrong or never updated, the mesh might be off-screen.
4. Animation loop being called
animate() is called once during init, and it calls itself every frame. This renders the scene regularly.
Check that the render loop is running:
function animate() {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
}
animate();
5. Canvas CSS / container sizes
Make sure the #viewerContainer has a size, and its canvas fills it.
If the container or canvas has zero width or height, it appears blank.
The CSS sets flex layout — make sure the page is big enough and container isn't collapsed.
6. WebGL context failure or errors
Open Browser DevTools Console and check for errors like:
- WebGL context creation failed
- Shader compile errors
- Other JS errors halting execution
Debug steps you can try:
- Add a background color or a test cube
Add a simple test cube in the scene right after initialization to check rendering:
const boxGeom = new THREE.BoxGeometry(50, 50, 50);
const boxMat = new THREE.MeshStandardMaterial({color: 0x00ff00});
const boxMesh = new THREE.Mesh(boxGeom, boxMat);
boxMesh.position.set(0, 25, 0);
scene.add(boxMesh);
If this test cube shows, it confirms viewer works and problem is the heightmap mesh or texture update.
- Log container sizes and rendering steps
Add during init:
console.log('Viewer size:', viewerContainer.clientWidth, viewerContainer.clientHeight);
console.log('Image Size:', imageWidth, imageHeight);
Important fix if you are testing the current code directly:
Your 3D mesh’s geometry has imageWidth-1 and imageHeight-1 segments.
However, if the image is very large, the geometry might overload or be too detailed for your GPU, causing rendering issues or errors.
Try with a small image at first (like 256x256 or less).
One fix I suggest: change the geometry dividers to a smaller number (resolution reduction)
For better performance and guaranteed rendering, change this line:
geometry = new THREE.PlaneGeometry(imageWidth, imageHeight, imageWidth - 1, imageHeight - 1);
To something that subdivides to e.g. 128 segments max (keep aspect ratio):
const maxSegments = 128;
const segX = Math.min(maxSegments, imageWidth - 1);
const segY = Math.min(maxSegments, imageHeight - 1);
geometry = new THREE.PlaneGeometry(imageWidth, imageHeight, segX, segY);
And adjust the heightData and paintedHeightData arrays accordingly (interpolate or downsample) OR just use lower res images for now.
Summary
- The code’s Three.js canvas is appended to right container — verify it actually appears in the DOM.
- The camera and mesh exist and are positioned correctly.
- The render loop runs.
- Container sizes > 0.
- The geometry subdivisions are manageable for your hardware.
- No console errors.
If you want, I can prepare a minimal demo snippet that puts a simple box plus your 3D mesh to check rendering for you.
Final quick check - here’s the initialization snippet you must have (check if this runs and appends the canvas):
function initThree() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0x222222);
camera = new THREE.PerspectiveCamera(45, viewerContainer.clientWidth/viewerContainer.clientHeight, 0.1, 1000);
camera.position.set(0, maxHeight/2, maxHeight * 1.7);
controls = new THREE.OrbitControls(camera);
renderer = new THREE.WebGLRenderer({antialias:true, alpha:false});
renderer.setSize(viewerContainer.clientWidth, viewerContainer.clientHeight);
viewerContainer.appendChild(renderer.domElement);
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.07;
controls.minDistance = 30;
controls.maxDistance = 800;
window.addEventListener('resize', onWindowResize);
animate();
}
Please check this and let me know if you want me to prepare a special minimal debug version that just shows a simple cube and your mesh, so we isolate the problem.
If you can share what image size or file you use, that helps too.
Summary: Yes, the 3D viewer is on the right side, but most likely the canvas is there but blank because of a problem with mesh visibility or texture update. Try the debugging tips above.
If you want, I can prepare a small snippet for you to test viewer rendering independently — just ask!