Closed Samulus closed 6 months ago
Requested on the forum here: https://community.cesium.com/t/how-to-clipping-multiple-polygon-on-the-cesium3dtileset/9182/2
I also need support for concave polygon
@NotEmptyWKL can you describe your use case?
@NotEmptyWKL您可以描述您的用例吗? After supporting concave polygon clipping, I can cut the earth into the scope of a country without showing the whole earth
Another request for multiple disjoint clipping polygons came from https://community.cesium.com/t/multiple-clippingplanes/11809
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.
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:
Hope this feautre will come out soon!
There are some mistakes in the MultiClippingPlaneCollection.js file. Please replace it with the new file below. Thanks to @andrevall.
I reuploaded files after I updated Cesium to 1.92. files.zip
I put the exmaple in the sandcaslte https://zhwy.github.io/cesium/Apps/Sandcastle/index.html?src=Terrain%20Multiple%20Clipping%20Planes.html.
Hello @zhwy,
thank you for your reply! I applied the changes you mentioned to the MultiClippingPlaneCollection.js
file and it worked perfectly 😀.
I really hope that @cesiumgs-admin will merge this feature in a future release: clipping multiple holes in the terrain is a feature that a lot of people would benefit from.
Thank you again!
Andrea
You are welcome, Andrea. @andrevall
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:
- Different styles and model matrix on each ClippingPlaneCollection are not supportive. They're set on the ClippingPlaneCollection and are the same for each collection.
- It dosen't support concave polygon directly. But you could try decomposing the polygon into convex polygons. The star below is actually two triangles.
- It only works on the globe terrain with every ClippingPlaneCollection's unionClippingRegions set to false. I didn't rewrite the union function.
- Clipping on 3dtiles and models is out of scope, but I think the concept is similar.
- There might be bugs. : P
Hope this feautre will come out soon!
There are some mistakes in the MultiClippingPlaneCollection.js file. Please replace it with the new file below. Thanks to @andrevall. MultiClippingPlaneCollection.zip
excuse me, how to works on the 3dtiles?
@abcdweiok Sorry, I'm not working on it now, might take some time to figure this out.
@Samulus Hi, When will this capability be supported?
Hi @zhwy,
again thank you so much for this amazing extension to CesiumJS! I would like to notify two bugs that I experience with the multiClippingPlaneCollection:
I tried fixing these problems, but my webGL and JS knowledge is too limited for this complex stuff 😌
Hi @andrevall,
Thank you for notifying!
The first problem seems to be a bug of Cesium. I found the same problem of the original terrain clipping example on iphone. https://sandcastle.cesium.com/?src=Terrain%20Clipping%20Planes.html I have no idea about how to fix it 😮, maybe we can open a new issue.
About the second problem, the copyFrom interface of Texture class has been modified from 1.84, a 'source' parameter is now required. Two places in MultiClippingPlaneCollection.js need correcting:
this._dataTexture.copyFrom({
source: {
width: widthTotal,
height: height,
arrayBufferView: arrayBuffer,
},
});
this._lengthTexture.copyFrom({
source: {
width: collections.length,
height: 1,
arrayBufferView: lengthArrayBuffer,
},
});
Here's the new file: MultiClippingPlaneCollection.zip
Hi @zhwy,
Following these lines, I reaffirm the importance of this extension. In my case, I am looking for a way to fit the holes in the tunnels of an underground infrastructure and without a doubt it would be great to have this active capacity. Thanks.
At the moment I can only apply a transparency when I approach the mouth of the tunnel.
Hi @raulvigueras,
Sorry for my replying late. You may try to use the MultiClippingPlaneCollection to clip the holes of tunnels.
Yet the effect is not very good, it's hard to fit the tunnel holes very well.
Thanks @zhwy. I've replaced the GlobeSurfaceTileProvider.js, GlobeSurfaceShaderSet.js, GlobeFS.glsl y Globe.js files, and copied the new MultiClippingPlaneCollection.js and getMultiClippingFunction.js files to their location in ./Source/Scene but I can't create the holes. In the brownser console I get the message 'Uncaught TypeError: Cesium.MultiClippingPlaneCollection is not a constructor'. I have tried with version 1.86 and 1.89. Am I doing something wrong? or am I missing something?
Thanks @zhwy. I've replaced the GlobeSurfaceTileProvider.js, GlobeSurfaceShaderSet.js, GlobeFS.glsl y Globe.js files, and copied the new MultiClippingPlaneCollection.js and getMultiClippingFunction.js files to their location in ./Source/Scene but I can't create the holes. In the brownser console I get the message 'Uncaught TypeError: Cesium.MultiClippingPlaneCollection is not a constructor'. I have tried with version 1.86 and 1.89. Am I doing something wrong? or am I missing something?
Hi @raulvigueras , did you run the compile command like 'npm run build' in the cesium root directory?
After doing this a new Cesium.js will be created in the 'Source' directory and you can import it as a module to use Cesium.MultiClippingPlaneCollection in your test page with *'import as Cesium from "path/to/Source/Cesium.js"'. You may need to add 'window.CESIUM_BASE_URL = "path/to/Source"'** to avoid the Unable to determine Cesium base URL automatically error.
If you want to make a release version, run the command 'npm run minifyRelease' in the root directory and this will create a 'Build/Cesium' directory which contains the Cesium.js. Put the entire 'Build/Cesium' directory on a server, now you can use it with .
I added six clipping surfaces to the project, which caused my page to get stuck
Another problem is that if I add clipping surfaces at the beginning and then I clear them, I need to add them twice if I want to add them again
Hi, @chenwwsdo Can you show some code snippets?
Please show me some code snippets or upload data for me to run tests.
Initial work was started in https://github.com/CesiumGS/cesium/pull/8915
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.
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:
- Different styles and model matrix on each ClippingPlaneCollection are not supportive. They're set on the ClippingPlaneCollection and are the same for each collection.
- It dosen't support concave polygon directly. But you could try decomposing the polygon into convex polygons. The star below is actually two triangles.
- It only works on the globe terrain with every ClippingPlaneCollection's unionClippingRegions set to false. I didn't rewrite the union function.
- Clipping on 3dtiles and models is out of scope, but I think the concept is similar.
- Having too many clipping collections or too many clipping planes in one collection will cause performance issues.
- There might be bugs. : P
Hope this feautre will come out soon!
There are some mistakes in the MultiClippingPlaneCollection.js file. Please replace it with the new file below. Thanks to @andrevall.
I reuploaded files after I updated Cesium to 1.92. files.zip
Hello,Can I ask how to modify this to apply it in 3DTiles? I apply it in terrain and it success, but it doesn't work in 3DTiles.
我迫切需要在地球上进行多次剪辑!这是我取得的一个简单的效果。
这些文件被修改:GlobeSurfaceShaderSet.js,GlobeSurfaceTileProvieder.js,Globe.js,GlobeVS.glsl。将创建新文件:MultiClippingPlaneCollection.js,getMultiClippingFunction.js。
现在,您可以通过将 MultiClippingPlaneCollection 的实例传递到新添加到 globe 的 multiClippingPlanes 属性来裁剪地球上的多个多边形,该实例管理 ClippingPlaneCollection 的列表。
例如:
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, });
关键点是重写原始的 getClippingFunction.js getMultiClippingFunction.js使片段着色器能够处理多个剪切平面集合。着色器还需要知道每个集合的长度,以便获得正确的剪切平面。
This is only a temporary solution on multi-clipping on terrain, more problems to be solved:
- Different styles and model matrix on each ClippingPlaneCollection are not supportive. They're set on the ClippingPlaneCollection and are the same for each collection.
- It dosen't support concave polygon directly. But you could try decomposing the polygon into convex polygons. The star below is actually two triangles.
- It only works on the globe terrain with every ClippingPlaneCollection's unionClippingRegions set to false. I didn't rewrite the union function.
- Clipping on 3dtiles and models is out of scope, but I think the concept is similar.
- Having too many clipping collections or too many clipping planes in one collection will cause performance issues.
- There might be bugs. : P
Hope this feautre will come out soon!
There are some mistakes in the MultiClippingPlaneCollection.js file. Please replace it with the new file below. Thanks to @andrevall.
I reuploaded files after I updated Cesium to 1.92. files.zip
Hello, for this fifth shortcoming, I need to load a long curved underground pipeline, and then after using your multiClippingPlanes, it can be loaded, but the page is really stuck. Later, I considered loading the pipeline dynamically, that is, when the camera is at a certain position, only the screen space coordinates of all pipeline points are loaded in the current screen, and these points are composed of pipeline loading. When the camera changes, re-acquire the pipeline points in the screen and reload the pipeline. Now I am indeed able to reacquire the pipe points, regenerate the pipe and load, but one problem I am having now: the clipping plane of the pipe disappears, pulling the camera to height 0, being able to see through the ground that the pipe is indeed loaded However, there is a layer of ground above, and I can't see the pipeline below from above the ground. What should I do? thank you very much.
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Sorry, I want to upload a gif, but it doesn't seem to work.
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
The red line at the beginning is the pipeline loaded through multiClippingPlanes, to make it obvious I used the red image. When the camera is away from the earth, you can see a very long red line, and indeed the page will be very stuck. When I brought the camera close to the ground room again, the red pipe disappeared. It never appears again. Only when the camera is pulled close to the ground, the red pit can be seen under the ground, but it is blocked by the ground. The pit is indeed loaded, but it cannot be displayed normally. I would like to know what are your thoughts? Can this problem be solved? thank you very much.
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Hello, I get the points inside the screen by dynamically updating the camera changes. By changing the number of points I can really see that every time the camera changes, I get new point data. What is uncertain now is whether the holes dug through these points have changed. But in the browser you can indeed listen to the change of the all array.
viewer.scene.globe.multiClippingPlanes = new Cesium.MultiClippingPlaneCollection({ collections: all, edgeWidth: 0, edgeColor: Cesium.Color.WHITE.withAlpha(0.9), });
In addition, if you stop rendering and updating the pipeline after a period of time is set in the camera change event, then the pipeline can be displayed normally, but the page will be very stuck.
var abc = 0; viewer.camera.changed.addEventListener(function () { abc++; if(abc<5){ ... }
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Hello @zhwy , I tried again yesterday. I figured out how to remove the multiclippingplanes, clear the data, and then recreate and add the multiclippingplanes. The final result was that multiclippingplanes were indeed removed, but could not be added again. Why is this? Thank you very much.
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Hello @zhwy , Just now, I tried again and found that there was no problem in cutting the ground for the first time. After a few seconds, I cut the ground for the second time. At this time, the pit for the first time will be covered by the pit for the second time, but there is a problem with the pit for the second time: the display is incomplete
Hello @kk1625846601 , can you upload a screenshot or a gif ? I don't understand "there is a layer of ground above, and I can't see the pipeline below from above the ground". Do you mean the ground is still visible after being clipped?
Hello, I have re studied the whole process and found that the problem lies in the method of generating pits. In the camera change event, the cutting plane can be dynamically updated. There are no problems with your multiclippingplanes.Thanks very much.
Sorry @kk1625846601 , I didn't read comments until now. Glad to know you have solved the problem. BTW, it's brilliant to update clipping planes dynamically to avoid the performance issue!👍
Sorry @kk1625846601 , I didn't read comments until now. Glad to know you have solved the problem. BTW, it's brilliant to update clipping planes dynamically to avoid the performance issue!👍
Hello @zhwy, thank you very much. I can't dig multiple holes without multiclippingplanes.
Hello I have one question for multiple clipping planes. How can I dig multiple holes on 3d tileset? Your solution is for globe, not 3d tileset. Please answer me. Thanks Best regards.
Also reported in https://github.com/CesiumGS/cesium/issues/11222
Add files such as MultiClippingPlaneCollection.js getMultiClippingFunction.js, and the npm run minifyRelease command succeeded.
I tried adding MultiClippingPlaneCollection on 3dTiles, but it didn't have any effect
I'm sorry but MultiClippingPlaneCollection only works on the globe for now.
I'm sorry but MultiClippingPlaneCollection only works on the globe for now.
Okay, I would like to know if future updates will consider adding 3dTIles' multiple cropping API
I am getting this error, anybody know the fix to it?
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.
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:
Different styles and model matrix on each ClippingPlaneCollection are not supportive. They're set on the ClippingPlaneCollection and are the same for each collection.
It dosen't support concave polygon directly. But you could try decomposing the polygon into convex polygons.
The star below is actually two triangles.
It only works on the globe terrain with every ClippingPlaneCollection's unionClippingRegions set to false. I didn't rewrite the union function.
Clipping on 3dtiles and models is out of scope, but I think the concept is similar.
Having too many clipping collections or too many clipping planes in one collection will cause performance issues.
There might be bugs. : P
Hope this feautre will come out soon!
There are some mistakes in the MultiClippingPlaneCollection.js file. Please replace it with the new file below. Thanks to @andrevall.
I reuploaded files after I updated Cesium to 1.92. files.zip
Hello! Is it possible to update the feature to the latest? 1.106 or 1.107? Thanks!
@zhwy any update on multiclipping for 3D Tileset?
针对铯 1.108 的更新。文件.zip
Hi, I tried in Cesium1.108, no error shows,but results are not displayed on earth.o(╥﹏╥)o
Hi,
We have tried the below update for multi-clipping, but have an issue if you could please assist? Developers code in .txt file attached.
From our developer;
I already also managed to add the version with Multi clipping code to our project. But the multi clipping code itself does not work. Or maybe it works, but due to the lack of documentation for it, I can’t understand what to set in the modelMatrix field of the options object or something else. If we have the opportunity to ask the Cesium developer who sent us this code, then we can try to ask:- How to correctly use their MultiClippingPlaneCollection?
If we built Cesium version release with multi clipping code, then what should we fix in the code below for Sandcastle so that clipping works? No error occurs. The array of ClippingPlaneCollections is successfully assigned to field collections. But clipping is not performed:
Kind Regards,
Clint Motley
Co-Founder / Managing Director
p 0431 461 763
e @.> @.
w http://www.immersiv.com.au/ www.immersiv.com.au
https://www.instagram.com/immersiv_3d/ https://www.linkedin.com/company/immersivau/
From: zhwy @.> Sent: Tuesday, August 15, 2023 5:53 PM To: CesiumGS/cesium @.> Cc: Immersiv-1 @.>; Mention @.> Subject: Re: [CesiumGS/cesium] Add support for concave /convex clipping planes + holes in CesiumJS (#8751)
Update for Cesium 1.108. files.zip https://github.com/CesiumGS/cesium/files/12342179/files.zip @Immersiv-1 https://github.com/Immersiv-1 @saadatali48 https://github.com/saadatali48
— Reply to this email directly, view it on GitHub https://github.com/CesiumGS/cesium/issues/8751#issuecomment-1678549984 , or unsubscribe https://github.com/notifications/unsubscribe-auth/A45M3UBM3VYN6RAZLHHBB7TXVMTFNANCNFSM4MG7R2FA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/A45M3UBFSMRGCC5NLATSEHTXVMTFNA5CNFSM4MG7R2FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOMQGKHYA.gif Message ID: @. @.> >
const viewer = new Cesium.Viewer("cesiumContainer", { terrain: Cesium.Terrain.fromWorldTerrain(), });
const globe = viewer.scene.globe; globe.depthTestAgainstTerrain = true;
const entity1 = createEntityAtLongitude(-2.086); const entity2 = createEntityAtLongitude(-2.0863); const entity3 = createEntityAtLongitude(-2.0866);
const collection1 = createClippingPlaneCollection(entity1); const collection2 = createClippingPlaneCollection(entity2); const collection3 = createClippingPlaneCollection(entity3);
//globe.clippingPlanes = collection1;
globe.collections = new Cesium.MultiClippingPlaneCollection({ modelMatrix: Cesium.Matrix4.IDENTITY, collections: [ collection1, collection2, collection3, ], });
viewer.trackedEntity = entity2;
function createEntityAtLongitude(longitude){ const position = Cesium.Cartesian3.fromRadians( longitude, 0.6586620013036164, 1400.0 );
const entity = viewer.entities.add({ position: position, box: { dimensions: new Cesium.Cartesian3(1400.0, 1400.0, 2800.0), material: Cesium.Color.WHITE.withAlpha(0.3), outline: true, outlineColor: Cesium.Color.WHITE, }, });
return entity; }
function createClippingPlaneCollection(entity){ const collection = new Cesium.ClippingPlaneCollection({ modelMatrix: entity.computeModelMatrix(Cesium.JulianDate.now()), planes: [ new Cesium.ClippingPlane( new Cesium.Cartesian3(1.0, 0.0, 0.0), -700.0 ), new Cesium.ClippingPlane( new Cesium.Cartesian3(-1.0, 0.0, 0.0), -700.0 ), new Cesium.ClippingPlane( new Cesium.Cartesian3(0.0, 1.0, 0.0), -700.0 ), new Cesium.ClippingPlane( new Cesium.Cartesian3(0.0, -1.0, 0.0), -700.0 ), ], edgeWidth: 1.0, edgeColor: Cesium.Color.WHITE, enabled: true, });
return collection; }
@Iron-john @Immersiv-1
I checked my codes and found that only the modelMatrix set on the MultiClippingCollection participates in the calculation, so the modelMatrix of each ClippingCollection has no effect. Better to calculate the clipping collections in the cartesian absolute coordinate system.
Here is an example:
const viewer = new Cesium.Viewer("cesiumContainer");
viewer.camera.setView({
destination: new Cesium.Cartesian3(1e7, 0, 0),
});
viewer.scene.debugShowFramesPerSecond = true;
const { globe } = viewer.scene;
globe.depthTestAgainstTerrain = true;
const multiCollections = new Cesium.MultiClippingPlaneCollection({
collections: [
generateClippingPlanesCollection([
Cesium.Cartesian3.fromDegrees(-10, -5),
Cesium.Cartesian3.fromDegrees(10, -5),
Cesium.Cartesian3.fromDegrees(0, 10),
]),
generateClippingPlanesCollection([
Cesium.Cartesian3.fromDegrees(-10, 5),
Cesium.Cartesian3.fromDegrees(0, -10),
Cesium.Cartesian3.fromDegrees(10, 5),
]),
],
modelMatrix: Cesium.Matrix4.IDENTITY,
edgeWidth: 5,
edgeColor: Cesium.Color.WHITE,
});
globe.multiClippingPlanes = multiCollections;
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
let positions = [];
// left click to add points to a clipping planes collection
handler.setInputAction(function (movement) {
const worldPosition = viewer.scene.pickPosition(movement.position);
if (Cesium.defined(worldPosition)) {
positions.push(worldPosition);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
// right click to end a clipping planes collection
handler.setInputAction(function (movement) {
const worldPosition = viewer.scene.pickPosition(movement.position);
if (Cesium.defined(worldPosition)) {
positions.push(worldPosition);
if (positions.length > 2) {
const collection = generateClippingPlanesCollection(positions);
multiCollections.add(collection);
positions = [];
}
}
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
function generateClippingPlanesCollection(points) {
const pointsLength = points.length;
const clippingPlanes = [];
for (let i = 0; i < pointsLength; ++i) {
const nextIndex = (i + 1) % pointsLength;
let midpoint = Cesium.Cartesian3.add(
points[i],
points[nextIndex],
new Cesium.Cartesian3()
);
midpoint = Cesium.Cartesian3.multiplyByScalar(
midpoint,
0.5,
midpoint
);
const up = Cesium.Cartesian3.normalize(
midpoint,
new Cesium.Cartesian3()
);
let right = Cesium.Cartesian3.subtract(
points[nextIndex],
midpoint,
new Cesium.Cartesian3()
);
right = Cesium.Cartesian3.normalize(right, right);
let normal = Cesium.Cartesian3.cross(
right,
up,
new Cesium.Cartesian3()
);
normal = Cesium.Cartesian3.normalize(normal, normal);
// Compute distance by pretending the plane is at the origin
const originCenteredPlane = new Cesium.Plane(normal, 0.0);
const distance = Cesium.Plane.getPointDistance(
originCenteredPlane,
midpoint
);
clippingPlanes.push(new Cesium.ClippingPlane(normal, distance));
}
return new Cesium.ClippingPlaneCollection({
planes: clippingPlanes,
modelMatrix: Cesium.Matrix4.IDENTITY,
});
}
Thank you! We’ll give that a try.
Kind Regards,
Clint Motley
Co-Founder / Managing Director
p 0431 461 763
e @.> @.
w http://www.immersiv.com.au/ www.immersiv.com.au
https://www.instagram.com/immersiv_3d/ https://www.linkedin.com/company/immersivau/
From: zhwy @.> Sent: Thursday, September 14, 2023 3:39 PM To: CesiumGS/cesium @.> Cc: Immersiv-1 @.>; Mention @.> Subject: Re: [CesiumGS/cesium] Add support for concave /convex clipping planes + holes in CesiumJS (#8751)
@Iron-john https://github.com/Iron-john @Immersiv-1 https://github.com/Immersiv-1
I checked my codes and found that only the modelMatrix set on the MultiClippingCollection participates in the calculation, so the modelMatrix of each ClippingCollection has no effect. Better to calculate the clipping collections in the cartesian absolute coordinate system.
Here is an example:
const viewer = new Cesium.Viewer("cesiumContainer"); viewer.camera.setView({ destination: new Cesium.Cartesian3(1e7, 0, 0), });
viewer.scene.debugShowFramesPerSecond = true;
const { globe } = viewer.scene; globe.depthTestAgainstTerrain = true;
const multiCollections = new Cesium.MultiClippingPlaneCollection({ collections: [ generateClippingPlanesCollection([ Cesium.Cartesian3.fromDegrees(-10, -5), Cesium.Cartesian3.fromDegrees(10, -5), Cesium.Cartesian3.fromDegrees(0, 10), ]), generateClippingPlanesCollection([ Cesium.Cartesian3.fromDegrees(-10, 5), Cesium.Cartesian3.fromDegrees(0, -10), Cesium.Cartesian3.fromDegrees(10, 5), ]), ], modelMatrix: Cesium.Matrix4.IDENTITY, edgeWidth: 5, edgeColor: Cesium.Color.WHITE, }); globe.multiClippingPlanes = multiCollections;
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas); let positions = [];
// left click to add points to a clipping planes collection handler.setInputAction(function (movement) { const worldPosition = viewer.scene.pickPosition(movement.position); if (Cesium.defined(worldPosition)) { positions.push(worldPosition); } }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
// right click to end a clipping planes collection handler.setInputAction(function (movement) { const worldPosition = viewer.scene.pickPosition(movement.position); if (Cesium.defined(worldPosition)) { positions.push(worldPosition); if (positions.length > 2) { const collection = generateClippingPlanesCollection(positions); multiCollections.add(collection); positions = []; } } }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
function generateClippingPlanesCollection(points) { const pointsLength = points.length; const clippingPlanes = []; for (let i = 0; i < pointsLength; ++i) { const nextIndex = (i + 1) % pointsLength; let midpoint = Cesium.Cartesian3.add( points[i], points[nextIndex], new Cesium.Cartesian3() ); midpoint = Cesium.Cartesian3.multiplyByScalar( midpoint, 0.5, midpoint );
const up = Cesium.Cartesian3.normalize(
midpoint,
new Cesium.Cartesian3()
);
let right = Cesium.Cartesian3.subtract(
points[nextIndex],
midpoint,
new Cesium.Cartesian3()
);
right = Cesium.Cartesian3.normalize(right, right);
let normal = Cesium.Cartesian3.cross(
right,
up,
new Cesium.Cartesian3()
);
normal = Cesium.Cartesian3.normalize(normal, normal);
// Compute distance by pretending the plane is at the origin
const originCenteredPlane = new Cesium.Plane(normal, 0.0);
const distance = Cesium.Plane.getPointDistance(
originCenteredPlane,
midpoint
);
clippingPlanes.push(new Cesium.ClippingPlane(normal, distance));
}
return new Cesium.ClippingPlaneCollection({ planes: clippingPlanes, modelMatrix: Cesium.Matrix4.IDENTITY, }); }
— Reply to this email directly, view it on GitHub https://github.com/CesiumGS/cesium/issues/8751#issuecomment-1718793891 , or unsubscribe https://github.com/notifications/unsubscribe-auth/A45M3UFYYBVKTZ5KGK2NDZ3X2KJ7ZANCNFSM4MG7R2FA . You are receiving this because you were mentioned. https://github.com/notifications/beacon/A45M3UD2PPLFLSZBDIHJ2JDX2KJ7ZA5CNFSM4MG7R2FKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOMZZLNIY.gif Message ID: @. @.> >
Hello!Do you happen to have an example in sandcastle by any chance?Thanks,ClintSent from my iPhoneOn 14 Sep 2023, at 15:40, @. @. { font-family: Helvetica; }
@font-face { font-family: "Cambria Math"; }
@font-face { font-family: Calibri; }
@font-face { font-family: Raleway; }
@font-face { font-family: Consolas; }
p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; }
a:link, span.MsoHyperlink { color: blue; text-decoration: underline; }
code { font-family: "Courier New"; }
pre { margin: 0cm; font-size: 10pt; font-family: "Courier New"; }
span.HTMLPreformattedChar { font-family: Consolas; }
span.EmailStyle24 { font-family: Calibri, sans-serif; color: windowtext; }
.MsoChpDefault { font-family: Calibri, sans-serif; }
@page WordSection1 { size: 612pt 792pt; margin: 72pt; }
div.WordSection1 { page: WordSection1; }Thank you! We’ll give that a try. Kind Regards, Clint MotleyCo-Founder / Managing Director
The user should be able to define a 2D clipping polygon with zero or more holes.
We should support:
We should disallow: