I've been immersed in a 3D project where we showcase 3D objects in a web browser using the Three.js Library.
One major issue has cropped up:
- Initially, the model appears small within a
dom
element or when the browser window is resized to a smaller size. - Upon resizing the window (or the
dom
element), the model starts to appear pixelated and loses its crispness.
Here are some snapshots showcasing this problem:
Before resizing:
After resizing:
How it ideally should look after resizing:
The following code snippet determines the dimensions (height and width) of the model, and is executed upon triggering the resize event:
console.log("domChanged fired")
instance.domBoundingBox = instance.dom.getBoundingClientRect();
instance.domCenterPos.x = instance.domBoundingBox.width / 2 + instance.domBoundingBox.left;
instance.domCenterPos.y = instance.domBoundingBox.height / 2 + instance.domBoundingBox.top;
var width = instance.dom.clientWidth, height = instance.dom.clientHeight;
instance.domWidthHalf = width / 2, instance.domHeightHalf = height / 2;
// TODO: emit an event to make it accessible for site developers
// updating various values related to width, height, and position here
if(instance.cameraReal) {
instance.cameraReal.aspect = instance.dom.clientWidth / instance.dom.clientHeight;
instance.cameraReal.updateProjectionMatrix();
}
if(instance.renderer3D)
instance.renderer3D.setSize(instance.dom.clientWidth, instance.dom.clientHeight);
Could anyone provide any insights? I've been at it for a few days now with no breakthrough so far.