0

在 BabylonJs 中,如果一个相机被放置在离物体一定距离的地方,那么它的距离与物体的大小成正比,那么整个场景应该是大致相同的。

我创建了这个简单的测试(可以复制并粘贴到http://www.babylonjs-playground.com/以运行),它产生一个大小为 1000 的球体的场景,从位于 (0, 0) 的相机看到, 10000):

var createScene = function () {

    // This creates a basic Babylon Scene object (non-mesh)
    var scene = new BABYLON.Scene(engine);

    // This creates and positions a free camera (non-mesh)
    var camera = new BABYLON.FreeCamera("camera", new BABYLON.Vector3(0, 0, 10000), scene);

    // This targets the camera to scene origin
    camera.setTarget(BABYLON.Vector3.Zero());

    // This attaches the camera to the canvas
    camera.attachControl(canvas, true);

    // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
    var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(1, -1, -1), scene);

    // Default intensity is 1. Let's dim the light a small amount
    light.intensity = 0.7;

    // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
    var sphere = BABYLON.Mesh.CreateSphere("Sphere", 16, 1000, scene);  

    return scene;
};

请注意,如果球体的大小减小到 100,并且相机的距离也相应减小(因此相机位于 (0, 0, 1000)),场景看起来仍然相同。

如果实验重复减少另一个因素,即球体的大小减少到 10 并且相机定位到 (0, 0, 100),仍然没有任何变化。

到目前为止,一切都很好。但是,如果我尝试增加球体的大小和距离,那么一切都会消失:如果球体的大小为 10000 并且相机定位到 (0, 0, 100000),则场景看起来是空的。为什么?是否有可能改变这种行为?如何?我错过了什么?

谢谢!

4

1 回答 1

1

这很可能与相机的“剪裁平面”有关。在 3D 图形中,通常会限制相机可以“观察”该距离(沿其 z 轴)的距离,这样它就不必在背景中“绘制”很远的对象。

您可以通过将其添加到代码中来更改此值以延长相机的绘制距离:

camera.maxZ = 100000;

为了可视化这一点,您还可以在球体下方添加平面几何图形。然后,您可以将该maxZ属性设置为不同的值,并查看它停止绘制平面的位置。

于 2016-04-15T17:10:20.177 回答