简体   繁体   English

如何使用Three.js按窗口宽度缩放内容?

[英]How to scale content by window width with Three.js?

So I'm using the basic window resize code: 所以我正在使用基本窗口调整大小代码:

function onWindowResize() {

    windowHalfX = window.innerWidth / 2;
    windowHalfY = window.innerHeight / 2;

    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();

    renderer.setSize( window.innerWidth, window.innerHeight );

}

and it resizes the window just fine - but it scales the content based on the height of the window, rather than the width of the window. 并且它可以很好地调整窗口大小 - 但它会根据窗口的高度而不是窗口的宽度来缩放内容。 For the site I'm building it is much more important that the visible width of the content is maintained than the height, but cannot figure out a way to reverse the code to scale based on the width instead of the height. 对于我正在构建的站点,保持内容的可见宽度比高度更重要,但是无法找到一种方法来反转代码以根据宽度而不是高度来缩放。

You can view the problem I'm working on here: http://sunsetfootclinicsign.com/signtest_9.html 你可以在这里查看我正在处理的问题: http//sunsetfootclinicsign.com/signtest_9.html

I'd appreciate any leads in the right direction! 我很欣赏任何正确方向的线索! Thank you so much! 非常感谢!

You could try 你可以试试

geometry.computeBoundingBox();

The dimensions can then be computed from geometry.boundingBox. 然后可以从geometry.boundingBox计算尺寸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM