Understanding clippingPlanes

The planes are skewed and not aligned between the coordinates they are drawn between. I can see there are differences based on position on the globe, but I would like to know if there is a more robust way to construct the position/orientation of planes with arbitrary coordinates.

The planes are assigned a certain orientation (as you noticed: depending on the position). When you change the code that creates the plane to…

          const bluePlane = viewer.entities.add({
              name: "Blue plane",
              position: midpoint,

              // --------------------------------------------- ADD THIS LINE:
              orientation: new Cesium.Quaternion(0, 0, 0, 1), // Identity

              plane: {
                plane: new Cesium.Plane(normal, 0.0),
                dimensions: new Cesium.Cartesian2(15.0, 5.0),
                material: Cesium.Color.BLUE.withAlpha(0.5),
              },
          });

then the orientation of the planes should match what you expect.


Beyond that: Some questions related to clipping planes come up pretty frequently. I wrote a few general words in Clipping only a portion of 3d Tileset - #2 by Marco13 (which, in turn, is a description of some details from How to load only 3dtiles inside the polygon? - #7 by Marco13 ).

I tried to follow the computations in your sandcastle, but it requires a bit of time and effort to go through the code and figure out where exactly something goes wrong - particularly, since “something being wrong” might very well just be a sign error (e.g. some wrong order in some cross product, or maybe a point missing in some list).

So I re-used a few snippets from the sandcastles that I created in the threads above, and created this:

https://sandcastle.cesium.com/index.html#c=tVhbb9s2FP4rbLAHeXVoyYntXIulabYV6Nqu6bqHusBoiba4yaJGUjHcIv99hxdJlKykaZEFASxezv0755CMeS4VumF0QwU6RzndoEsqWbnGH8xcMN+LzfiS54qwnIr53uB0nseGTsY0p0Bm6bEZ1ourjC/0opnFZgRr81yJLfoyzxEajdCvbJXuCyp5VirGc0RErFiMFBUChKGl4GukUoou7PyLq99QIfjfNFYoeEczSiRFh4MhUiyjCSJ5glIuFXwuts4OBGyxk5YqVciT0Wiz2eBiFeNynWOalKOEKDKyohO6HundvkXYqfNW8BuWaD/pHQiRDWGqcpf9ed/eibUBL3l+ISVVL5Pg4Hgy1d67RTFRcYoC2M7FwLpjw/KEbzDJqFDBXz8TY5LiKOMkqTyC0Q9fDM3tX4aP9udodP6If5ofekEX5QqlNCuokPN8WeaxCY9M+eZtRnIaFFwyPTVE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goN+xq22fKBxuOXqSUmWJFtn2+vY5JRkRtUldOe/7h9uzAq1MP61roSl9V9Lo2vA179dfH9Z708+3+Nt+3ZEZflxk9gsxuabY9r7K72sWWKIAKfX5+X3EeD5rLyr1s64Z9222mXbLdQ1ZTN3XCEgTtmcPp6cmTJwOj28ocoyC+FO7vcDchWbZFCZWxYAuqQ2+74HyPl0rbAY3PJX51NLP2oU0KI6ZQSqS3bK5QuxcLK7hW2x6x7u2RhlHrzOVsv6iPOA9rtoYR+hHpC+vpDrfn38ht/w52RcdC3cExxpXOQ9QMnmNBb6iQNBjYxtqltVjozn4MPw1OTbLqgILnIaT+mbuzvUJGo14LlVo/Td2fAxZ9++PJ5ODg6AhH4eT4eHo4Dqcud/ajwzA8GB9gWIhms8PpxC1MppPZdBzi6PhgOo0mh8fmCjN8mKTZDI/Hs9kkjMKjtqAZPh5PZsdhdDg7bkka4+kkPDwKQYlKkj2IWLNtsM5RhMNT3xWdSD0YpFW0Wq4c2ocug3tbVTuPGm22dkudIKXsXD+CQf2S6KV098Kkey+Rkq3MSWldnVbNi+Q915SH3Hd21e1nd8mzrO7CfnT9Xc2m+uXGEJ90mPnvKMYIvKv7HdJ33pR8l1prPJ9eJOC4xp2CruqjqS2dhmAnseuEQb2mOjH9b1Fth1YvRzYrbAXwnpMbuxvBd0vsca8jqwV7rjVu6gHcqS75fV6Dhb3h3plU24w+q2z7ia0LLhQqRRZgPFJ0DSGFfB4tyvgfqnAsZdW/zkY+6VnCbhBLznue3yEggGZYWZZZdg1nqfnes7MR7N8h1S/HoOIbqKAZ2eptafTslZ2EGns2gmE/peI8WxDR4fwf

It takes the line that you defined, creates a polygon (“trench”) with a certain width, and then uses the points of this polygon to create a bunch of clipping planes. This is broken into a few functions with // short comments that hopefully show the most important steps:

  • Create a version of that line that is shifted “right”
  • Create a version of that line that is shifted “left”
  • Concatenate these (reversing the second list) to create a “polygon”
  • Create clipping planes from each two consecutive points of that polygon
  • Throw these clipping planes into a ClippingPlaneCollection

Note that the ClippingPlaneCollection has an inherent limitation: It can, by principle, always and only represent a convex polygon. When the “trench” that you are modeling there is not just a straight line, then this approach plainly won’t work. In that case, you should be able to simply use clipping polygons which have recently been introduced, are described in the blog post at Hide Regions of 3D Tiles or Terrain with Clipping Polygons – Cesium , and might be exactly what you’re looking for.

I tried it out, and the Sandcastle does include that approach (just uncomment the useClippingPolygon() call at the bottom). But unfortunately, there seems to be some precision issue when applying this to the given terrain: The polygon is not represented cleanly when it is very narrow. (When setting width = 10.0, then it somehow works, but still not perfectly).

1 Like