Get Cartesian3 points from drillPick primitives

1. A concise explanation of the problem you’re experiencing.

I’m trying to implement a function combining the scene.pickPosition function (Scene - Cesium Documentation) and the scene.drillPick function (Scene - Cesium Documentation).

The main objective is to create a method that can receive the windowPosition in Cartesian2 coordinates and return an array of Cartesian3 coordinates corresponding to the collision points with the primitives found.

2. Some solutions that I’ve tried

  1. Using the primitives given by the drillPick function, hide them one by one and use the method pickPosition to get the collision point beyond the primitive found.

Here’s a code snipet of that solution:

//consider given values for i and j
const drillPicks = viewer.scene.drillPick(new Cesium.Cartesian2(i,j))

var collisionPoints = [];

for (let a = 0; a < drillPicks.length; a++) {
      const collisionObject = drillPicks[a];

      //hide the object
      collisionObject.show = false;

      // get the point behind said object
      const point = viewer.scene.pickPosition(new Cesium.Cartesian2(i,j) , new Cesium.Cartesian3());

      collisionPoints.push(point)
}

for (let a = 0; a < drillPicks.length; a++) {
     //change the primitives back to normal
     drillPicks[a].show = true;            
}

//use collisionPoints
  1. A second solution that I’ve tried is changing the color of the drillPicked primitives, using alpha values (Cesium.Color.YELLOW.withAlpha(0.5) for example) to make it translucent, so that the drillPick function ignores the transculent primitives.
    Similarly to the previous solution, after the Cartesian3 points are retrived, the color of the primitives is changed back to normal.

None of the presented solutions have worked so far. The results observed contained only collisions with the first primitive or no collisions at all. I don’t know if it’s because the change of color or visibility of a primitive is done asynchrony or for some other reason.

3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

I’m trying to create a method that can return the all points of collision, between 2 points, along a volume of space, using ray casting (using the pickPosition function basicaly)

4. The Cesium version you’re using, your operating system and browser.

Cesium version: 1.89
OS: Windows 11
Browser: Chrome