2

I'm ultimately trying to draw a polygon on top of my house. I can do that.

The problem is that on zoom-out, zoom-in, and rotation (or camera move) the polygon doesn't stick to the top of my house. I received great help from this answer. So, now I'm trying to go through the sample code but there is a lot of Cesium methods and functionality that I need to learn.

The sample code I am trying to follow is located in the gold standard that appears to be baked into the existing camera controller here.

I call testMe with the mousePosition as Cartesian3 and the SceneMode is 3D, so pickGlobe is executed.

Here is my code:

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;
}

Here is my problem:

enter image description here

Here is the result:

enter image description here

Here are my questions to get this code working:

1. How do I get the scene.pickPositionSupported set to true? I'm using Chrome on Windows 10. I cannot find in the sample code anything about this and I haven't had much luck with the documentation or Google.

2. Why is rayIntersection not getting set? ray and scene have values and scratchRayIntersection in an empty Cartesian3.

I think if I can get those two statements working, I can probably get the rest of the pickGlobe method working.

WebGLGraphics Report:

enter image description here

enter image description here

enter image description here

I clicked on Get WebGL and the cube is spinning!

Community
  • 1
  • 1
Patricia
  • 5,019
  • 14
  • 72
  • 152
  • 1
    Can you post a screenshot of [WebGL Report](http://webglreport.com/)? Looks like [pickPositionSupported](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.19/Source/Scene/Scene.js#L667-L669) comes from [WEBGL_depth_texture](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.19/Source/Renderer/Context.js#L278). Lack of that extension is kind of a show-stopper here. What 3D graphics card do you have? Chrome 49 on Win10 works for me. – emackey Mar 22 '16 at 01:39
  • My 3D graphics card is Intel(R) HD Graphics 4600. I updated Chrome but I can't figure out how to get / install the extensions. I'll update my question with the WebGL Report. – Patricia Mar 22 '16 at 17:09
  • It appears to not be supported in Firefox either. – Patricia Mar 23 '16 at 11:49
  • 1
    Hi Miss Lucy, something here is odd. WEBGL_depth_texture is a well-supported extension, and indeed your screenshot of WebGL Report shows the extension is enabled already on your system. According to Cesium source, this should directly result in `viewer.scene.pickPositionSupported` being `true` as there is no other logic along that path. I haven't had time to dig into the sample code you posted yet, but I wonder if your `scene` is not really `viewer.scene` somehow. – emackey Mar 23 '16 at 13:37
  • 1
    Another thing to try: Find the nearest mountain, and grab near the peak of it with your mouse, and move it a little. If the piece of land you grabbed moves in lock-step with the mouse pointer, then that means this value is true and the depth texture worked. If the land slides away rapidly from the mouse pointer, that means you grabbed the ellipsoid instead. – emackey Mar 23 '16 at 13:40
  • Hey, emackey! Now that the scene.pickPositionSupported is true, I'm moving on. The next issue is the scene.pickPosition(mousePosition, scratchDepthIntersection) is returning depthIntersection = undefined. Both parameters passed in are Cartesian3. The mousePosition contains valid coordinates and the scratchDepthIntersection is initialized as a new Cartesian3. Is there something else that needs to be set to return the correct depthIntersection? I don't know where to look for this info, so I'll post another question and give you a link. – Patricia Mar 25 '16 at 15:20
  • Here's my new question: http://stackoverflow.com/q/36223668/1735836 – Patricia Mar 25 '16 at 17:53

2 Answers2

3

Picking positions requires that the underlying WebGL implementation support depth textures, either through the WEBGL_depth_texture or WEBKIT_WEBGL_depth_texture extensions. scene.pickPositionSupported is returning false because this extension is missing. You can verify this by going to http://webglreport.com/ and looking at the list of extensions; I have both of the above listed there. There is nothing you can do in your code itself to make it suddenly return true, it's a reflection of the underlying browser.

That being said, I know for a fact that Chrome supports the depth texture and it works on Windows 10, so this sounds like a likely video card driver issue. I full expect downloading and installing the latest drivers for your system to solve the problem.

As for rayIntersection, from a quick look at your code I only expect it to be defined if the mouse is actually over the globe, which may not always be the case. If you can reduce this to a runnable Sandcastle example, it would be easier for me to debug.

Matthew Amato
  • 1,992
  • 17
  • 21
  • Apparently, I'm not smart enough to figure out how to get the extension installed. A little help? – Patricia Mar 22 '16 at 16:06
  • 1
    You are misunderstanding me, there is no extension to install, it's totally determined by the browser. Your best course of action is to make sure your video card drivers are up to date. Can you share the output of webglreport.com? What video card are you using? – Matthew Amato Mar 22 '16 at 17:31
  • My 3D graphics card is Intel(R) HD Graphics 4600 and it is up-to-date. I also updated Chrome. I update my question with the WebGL Report. – Patricia Mar 22 '16 at 17:33
  • It appears to not be supported in Firefox either. – Patricia Mar 23 '16 at 11:50
1

OK. So it turned out that I had a totally messed up Cesium environment. I had to delete it and reinstall it in my project (npm install cesium --save-dev). Then I had to fix a few paths and VOILA! It worked. Thanks to both of you for all your help.

Patricia
  • 5,019
  • 14
  • 72
  • 152