【发布时间】:2013-12-15 22:10:58
【问题描述】:
我一直在做一个 3D 项目,我们使用 Three.js 库在网络浏览器中显示 3D 对象。
问题是:
- 1st 模型显示在一个小的 dom 元素中或当浏览器窗口本身很小时。
- 然后当窗口(或 dom 元素调整大小)时,模型变得像素化
以下是一些截图:
调整大小前:
调整大小后:
调整大小后应该如何:
这是设置模型尺寸(高度和宽度)的代码部分,如果触发了调整大小事件,则会调用此函数:
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);
谁能给我一个提示?我已经研究了几天了,但目前还没有任何线索
【问题讨论】:
-
AFAIK
setSize为您更改画布width/height(渲染分辨率)并为glViewport使用新尺寸。你能仔细检查instance.dom.clientWidth/Height是否真的在改变?看起来画布正在改变大小而不是其内部分辨率。
标签: javascript three.js