Cesium - 为什么 scene.pickPositionSupported 是错误的

Cesium - why is scene.pickPositionSupported false

我最终想在我房子的顶部画一个多边形。我能做到。

问题是在 zoom-out、zoom-in 和旋转(或相机移动)时,多边形不会粘在我房子的顶部。我从 那里得到了很大的帮助。所以,现在我正在尝试浏览示例代码,但是我需要学习很多 Cesium 方法和功能。

我尝试遵循的示例代码位于 the gold standard that appears to be baked into the existing camera controller here

我调用testMe,mousePosition为Cartesian3,SceneMode为3D,所以pickGlobe被执行。

这是我的代码:

var pickedPosition;
var scratchZoomPickRay = new Cesium.Ray();
var scratchPickCartesian = new Cesium.Cartesian3();
function testMe(mousePosition) {
    if (Cesium.defined(scene.globe)) { 
        if(scene.mode !== Cesium.SceneMode.SCENE2D) {
            pickedPosition = pickGlobe(viewer, mousePosition, scratchPickCartesian);
        } else {
            pickedPosition = camera.getPickRay(mousePosition, scratchZoomPickRay).origin;
        }
    }
}

var pickGlobeScratchRay = new Cesium.Ray();
var scratchDepthIntersection = new Cesium.Cartesian3();
var scratchRayIntersection = new Cesium.Cartesian3();    
function pickGlobe(viewer, mousePosition, result) {

    var globe = scene.globe;
    var camera = scene.camera;

    if (!Cesium.defined(globe)) {
        return undefined;
    }

    var depthIntersection;
    if (scene.pickPositionSupported) {
        depthIntersection = scene.pickPosition(mousePosition, scratchDepthIntersection);
    }

    var ray = camera.getPickRay(mousePosition, pickGlobeScratchRay);
    var rayIntersection = globe.pick(ray, scene, scratchRayIntersection);

    var pickDistance;
    if(Cesium.defined(depthIntersection)) {
        pickDistance = Cesium.Cartesian3.distance(depthIntersection, camera.positionWC);
    } else {
        pickDistance = Number.POSITIVE_INFINITY;
    }

    var rayDistance;
    if(Cesium.defined(rayIntersection)) {
        rayDistance = Cesium.Cartesian3.distance(rayIntersection, camera.positionWC);
    } else {
        rayDistance = Number.POSITIVE_INFINITY;
    }

    var scratchCenterPosition = new Cesium.Cartesian3();
    if (pickDistance < rayDistance) {
        var cart = Cesium.Cartesian3.clone(depthIntersection, result);
        return cart;
    }

    var cart = Cesium.Cartesian3.clone(rayIntersection, result);
    return cart;
}

这是我的问题:

结果如下:

为了让这段代码正常工作,我提出以下问题:

1.如何将 scene.pickPositionSupported 设置为 true? 我在 Windows 上使用 Chrome 10。我在示例代码中找不到任何关于此的信息,我没有'文档或 Google.

运气不佳

2。为什么 rayIntersection 没有设置? 光线和场景在空 Cartesian3 中有值和 scratchRayIntersection。

我想如果我能让这两个语句起作用,我可能就能让 pickGlobe 方法的其余部分起作用。

WebGLGraphics 报告:

我点击了 获取 WebGL 并且 立方体正在旋转!

选择位置需要底层 WebGL 实现支持深度纹理,通过 WEBGL_depth_texture 或 WEBKIT_WEBGL_depth_texture 扩展。 scene.pickPositionSupported 是 returning false,因为缺少此扩展名。您可以通过转到 http://webglreport.com/ 并查看扩展列表来验证这一点;我上面列出了两个。您无法在代码本身中做任何事情来突然 return 为真,这是底层浏览器的反映。

也就是说,我知道 Chrome 支持深度纹理并且它适用于 Windows 10,所以这听起来可能是显卡驱动程序问题。我完全希望为您的系统下载并安装最新的驱动程序来解决问题。

至于 rayIntersection,通过快速查看您的代码,我只希望在鼠标实际位于地球上时定义它,但情况可能并非总是如此。如果你能把它简化成一个可运行的Sandcastle例子,我调试起来会更容易。

好的。所以事实证明我有一个完全混乱的铯环境。我不得不删除它并在我的项目中重新安装它 (npm install cesium --save-dev)。然后我不得不修复一些路径并且 VOILA! 它起作用了。感谢你们两位的帮助。