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:
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).