Cesium 关于裁切官方回复

暂时不支持凹多边形、多个裁切的

Q1 Multiple ClippingPlaneCollections for concave clipping polygons

https://community.cesium.com/t/multiple-clippingplanecollections-for-concave-clipping-polygons/6479
Hi everyone
I find that clipping planes for globe and models can only cut a convex area.
What if I have a concave shape to clip?
My solution is to apply multiple clippingPlaneCollections.
So that I can triangulate the concave shape into triangles first, and then clip the area triangle by triangle with multiple clippingPlaneCollections.
However, modifying the source code is a little bit hard for me.
Can any help me with the idea?
Thanks
Chris

A1 Currently its not possible to have multiple clippingPlane 1Collections.

Hi,
Currently its not possible to have multiple multiple clippingPlane Collections. We have started some work on clipping volumes, which you would be able to have multiples of per tileset, and either use a concave ro convex mode. Keep and eye out for that feature.
You can also try setting clippingPlaneCollection.unionClippingRegions 8 to false, which will clip all regions outside any clipping plane.
Thanks,
Gabby

Q2 How to clipping multiple Polygon on the Cesium3DTileset?

https://community.cesium.com/t/how-to-clipping-multiple-polygon-on-the-cesium3dtileset/9182

  1. A concise explanation of the problem you’re experiencing.
    I want to clipping multiple Polygon on Cesium3DTileset, but now I can only clipping one.
  2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.
var tileset = viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
    url: tiles.url,
    clippingPlanes: [
        new Cesium.ClippingPlaneCollection({    // clipping one Polygon
            planes: [
                new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 1.0, 0.0), 1.0),
                new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, -1.0, 0.0), -1.0),
                new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), 1.0),
                new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), -1.0)
            ],
            unionClippingRegions: false,
        }),
        new Cesium.ClippingPlaneCollection({     // clipping two Polygon
            planes: [
                new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 1.0, 0.0), 2.0),
                new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, -1.0, 0.0), -2.0),
                new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), 2.0),
                new Cesium.ClippingPlane(new Cesium.Cartesian3(-1.0, 0.0, 0.0), -2.0)
            ],
            unionClippingRegions: false,
        })
    ]
}));
  1. Context. Why do you need to do this? We might know a better way to accomplish your goal.
    I want to clip multiple polygons in Cesium3DTileset,Used to display the pipeline model below.
  2. The Cesium version you’re using, your operating system and browser.
    1.66
    在这里插入图片描述

A2 It isn’t currently possible to add multiple clipping planes to one tileset

It isn’t currently possible to add multiple clipping planes to one tileset, but we’ve got a feature request for this here: https://github.com/CesiumGS/cesium/issues/8751 35.

Q3 Add support for concave /convex clipping planes + holes in CesiumJS

https://github.com/CesiumGS/cesium/issues/8751
https://community.cesium.com/t/multiple-clippingplanes/11809

The user should be able to define a 2D clipping polygon with zero or more holes.
We should support:
Multiple clipping planes
Multiple holes in each clipping plane
Overlapping holes
We should disallow:
Self-intersecting polygons / holes
Holes that extend beyond the region of their parent clipping plane.

A3 I urgently need multiple clipping on the globe!. Here is a simple effect I achieved.

These files are modified: GlobeSurfaceShaderSet.js, GlobeSurfaceTileProvieder.js, Globe.js, GlobeVS.glsl.
New files are created: MultiClippingPlaneCollection.js, getMultiClippingFunction.js.
files.zip

You can now clip multiple polygons on the globe by passing an instance of MultiClippingPlaneCollection which manages a list of ClippingPlaneCollection to the multiClippingPlanes property new added to the globe.

For example:

var clippingPlanecollection1 = new Cesium.ClippingPlaneCollection({
      planes: [
        new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0.0), 0.0),
        new Cesium.ClippingPlane(
          new Cesium.Cartesian3(-1.0, 0.0, 0.0),
          -500.0
        ),
        new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 1.0, 0.0), -15.0),
        new Cesium.ClippingPlane(
          new Cesium.Cartesian3(0.0, -1.0, 0.0),
          -15.0
        ),
      ],
    });
    var clippingPlanecollection2 = new Cesium.ClippingPlaneCollection({
      planes: [
        new Cesium.ClippingPlane(new Cesium.Cartesian3(1.0, 0.0, 0.0), 1000),
        new Cesium.ClippingPlane(
          new Cesium.Cartesian3(-1.0, 0.0, 0.0),
          -2000.0
        ),
        new Cesium.ClippingPlane(new Cesium.Cartesian3(0.0, 1.0, 0.0), -15.0),
        new Cesium.ClippingPlane(
          new Cesium.Cartesian3(0.0, -1.0, 0.0),
          -15.0
        ),
      ],
    });

    globe.multiClippingPlanes = new Cesium.MultiClippingPlaneCollection({
      collections: [clippingPlanecollection1, clippingPlanecollection2],
      modelMatrix: entity.computeModelMatrix(Cesium.JulianDate.now()),
      edgeWidth: 1,
      edgeColor: Cesium.Color.WHITE,
    });

The key point is to rewrite the orginal getClippingFunction.js to getMultiClippingFunction.js to make the fragment shader able to handle multiple clipping plane collections. The shader also needs to know the length of every collection so it can get the correct clipping plane.

This is only a temporary solution on multi-clipping on terrain, more problems to be solved:

  1. Different styles and model matrix on each ClippingPlaneCollection
    are not supportive. They’re set on the ClippingPlaneCollection and
    are the same for each collection.

  2. It dosen’t support concave polygon
    directly. But you could try decomposing the polygon into convex
    polygons. The star below is actually two triangles.

  3. It only works on the globe terrain with every ClippingPlaneCollection’s
    unionClippingRegions set to false.

  4. I didn’t rewrite the union function. Clipping on 3dtiles and models is out of scope, but I
    think the concept is similar.

  5. There might be bugs. : P

Hope this feautre will come out soon!

### Cesium 中实现模型单面和多面裁切的方法 为了在 Cesium 中实现模型的单面或多面裁切,可以利用 `Cesium.ClippingPlane` 和 `Cesium.ClippingPlaneCollection` 类来定义裁剪平面。这些类允许创建一个或多个用于裁剪场景对象(如3D Tiles 或其他几何体)的平面。 对于单面裁切: ```javascript const plane = new Cesium.ClippingPlane( Cesium.Cartesian3.UNIT_Z, // 法向量方向设置为Z轴正方向 -100.0 // 平移距离设定为-100单位长度 ); m_b3dm.clippingPlanes = new Cesium.ClippingPlaneCollection({ planes : [plane], edgeColor : Cesium.Color.RED, edgeWidth : 2.0 }); ``` 上述代码片段展示了如何通过指定法线方向和平移参数构建单一裁剪平面,并将其应用于已加载的 b3dm 模型上[^2]。 当涉及到多面裁切时,则需创建一组不同的裁剪平面并加入到同一个集合中: ```javascript // 定义三个相互垂直相交于一点的裁剪平面 let clippingPlanes = new Cesium.ClippingPlaneCollection(); clippingPlanes.add(new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_X, -50)); clippingPlanes.add(new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_Y, -75)); clippingPlanes.add(new Cesium.ClippingPlane(Cesium.Cartesian3.UNIT_Z, -100)); // 将此组裁剪平面应用至目标模型 m_b3dm.clippingPlanes = clippingPlanes; m_b3dm.classificationType = Cesium.ClassificationType.BOTH; // 可选配置项 ``` 这段脚本说明了怎样组合多个不同方位上的裁剪平面形成一个多维裁剪空间,并同样作用在一个给定的数据集之上。 值得注意的是,在实际开发过程中可能还需要调整各个属性比如边缘颜色(`edgeColor`)、宽度(`edgeWidth`)以及分类类型(`classificationType`)等以满足具体需求。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值