example that allows user to "paint" on a mesh?

I’m interested in allowing the user to “draw” on a mesh object. I thought I saw an example of this implemented in Cesium a while back, but maybe I’m misremembering. Basically the JS would need to do point picking on the mesh and then change the color at the nearest vertex.

Does anyone know of the example scene I’m talking about? Otherwise, any comments on how to implement this / whether it would be easy would be appreciated.

Maybe it’s this one - https://cesiumjs.org/2016/03/21/Drawing-on-the-Globe-and-3D-Models/

Yes! Thank you! I thought I had imagined it and was going crazy!

Unfortunately, this example works in 3D and 2.5D view only. Not in 2D. No exceptions thrown either. Wasn’t there a fix for scene.pick() in 1.31?

Yes, there was a bug with picking in 2D that was fixed in 1.31. Let me know if you still have problems after upgrading to that version.

-Hannah

I ran this example in Sandcastle… It says it’s using 1.31…

Ah, I see. For me, in 2D and Columbus View I’m able to draw on the models but not on the map. Is that what you see?
I’ve submitted an issue here: https://github.com/AnalyticalGraphicsInc/cesium/issues/5076

-Hannah

For drawing on terrain, I would recommend using

    var ray = viewer.camera.getPickRay(movement.endPosition);
    var position = viewer.scene.globe.pick(ray, viewer.scene);

``

That will work in 3D and Columbus View.

For 2D you’ll have to do something like

var position = viewer.camera.pickEllipsoid(movement.endPosition);

``

then use sampleTerrainMostDetailed to add a height to the positions when you’re finished drawing.

Actually it would probably be a good idea to use sampleTerrainMostDetailed to get the correct height for your positions drawn in any scene mode. The positions from getPickRay/scene.globe.pick won’t have a very accurate height if you were drawing when zoomed out from the globe because it depends on the LOD for the terrain currently loaded.

-Hannah

Thanks, will try! Would the later work in all scene modes?

Yep, using scene.pickEllipsoid will work in all scene modes, but there is a bit of latency in getting the results back from sampleTerrainMostDetailed. That function is asynchronous and returns a promise to the results. Using getPickRay in 3D and CV will give you a position with a decent height estimate while you’re waiting for the more accurate one to be fetched. pickEllipsoid will always return a height of 0. In 2D that doesn’t matter because you can’t see the terrain height anyway.

-Hannah

ClampToGround for Polylines would come handy here :wink: