Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  19] [ 6]  / answers: 1 / hits: 79200  / 11 Years ago, fri, november 29, 2013, 12:00:00

I have been working on a 3D project where we show 3D object in the web browser using Three.js Library.


The problem is:



  • 1st the model is displayed in a small dom element or when the browser window itself is small.

  • Then when the window (or the dom element is resized) the model become pixelated


Following are some screenshots:


Before resize:


enter


After resize:


enter


How it should be after resize:


enter


Here is the part of code that is setting the the model dimensions (height and width), and this function gets called when the resize event if fired:


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: fire event to expose it to site developers

// here we should update several values regarding width,height,position
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);

Can anybody give me a hint? I've been working on that a couple of days already but no clue so far


More From » three.js

 Answers
12

Finally the problem were solved the actually problem was coming from because the application is using the THREE.EffectComposer object, in the class constructor a composer object were created like following:



this.composer = new THREE.EffectComposer(this.renderer3D);


So as for the renderer, the composer needed to have the size updated after the event handler function like following:



if(instance.renderer3D)
instance.renderer3D.setSize(instance.dom.clientWidth, instance.dom.clientHeight);
if(instance.composer)
instance.composer.setSize(instance.dom.clientWidth, instance.dom.clientHeight);


And this fixed the issue perfectly :)


[#73987] Thursday, November 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
krystadesiraeo

Total Points: 493
Total Questions: 93
Total Answers: 100

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
;