Skip to content

Commit c609e23

Browse files
committed
feat(PlanarView): add clippingPlanes options
1 parent 8f4c4e3 commit c609e23

File tree

5 files changed

+41
-6
lines changed

5 files changed

+41
-6
lines changed

src/Core/Prefab/Planar/PlanarLayer.js

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as THREE from 'three';
22

33
import TiledGeometryLayer from 'Layer/TiledGeometryLayer';
4-
import { globalExtentTMS } from 'Core/Geographic/Extent';
4+
import { globalExtentTMS, schemeTiles } from 'Core/Geographic/Extent';
55
import CRS from 'Core/Geographic/Crs';
66
import PlanarTileBuilder from './PlanarTileBuilder';
77

@@ -39,19 +39,47 @@ class PlanarLayer extends TiledGeometryLayer {
3939
*/
4040
constructor(id, extent, object3d, config = {}) {
4141
const tms = CRS.formatToTms(extent.crs);
42-
const tileMatrixSets = [tms];
42+
43+
const scheme = schemeTiles.get(tms);
44+
let schemeTile;
45+
let clipPlanes = [];
46+
if (scheme) {
47+
schemeTile = globalExtentTMS.get(extent.crs).subdivisionByScheme(scheme);
48+
clipPlanes = [
49+
new THREE.Plane(new THREE.Vector3(1, 0, 0), -extent.west),
50+
new THREE.Plane(new THREE.Vector3(-1, 0, 0), extent.east),
51+
new THREE.Plane(new THREE.Vector3(0, -1, 0), extent.north),
52+
new THREE.Plane(new THREE.Vector3(0, 1, 0), -extent.south),
53+
];
54+
config.materialOptions = { clippingPlanes: clipPlanes };
55+
} else {
56+
schemeTile = [extent];
57+
}
58+
4359
if (!globalExtentTMS.get(extent.crs)) {
4460
// Add new global extent for this new crs projection.
4561
globalExtentTMS.set(extent.crs, extent);
4662
}
47-
config.tileMatrixSets = tileMatrixSets;
48-
super(id, object3d || new THREE.Group(), [extent], new PlanarTileBuilder({ crs: extent.crs }), config);
63+
64+
config.tileMatrixSets = [tms];
65+
66+
const builder = new PlanarTileBuilder({ crs: extent.crs });
67+
68+
super(id, object3d || new THREE.Group(), schemeTile, builder, config);
69+
4970
this.isPlanarLayer = true;
5071
this.extent = extent;
5172
this.minSubdivisionLevel = this.minSubdivisionLevel == undefined ? 0 : this.minSubdivisionLevel;
52-
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 5 : this.maxSubdivisionLevel;
73+
this.maxSubdivisionLevel = this.maxSubdivisionLevel == undefined ? 19 : this.maxSubdivisionLevel;
5374
this.maxDeltaElevationLevel = this.maxDeltaElevationLevel || 4.0;
5475
}
76+
77+
culling(node, camera) {
78+
if (super.culling(node, camera)) {
79+
return true;
80+
}
81+
return !node.extent.intersectsExtent(this.extent);
82+
}
5583
}
5684

5785
export default PlanarLayer;

src/Renderer/LayeredMaterial.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const fragmentShader = [];
9898
class LayeredMaterial extends THREE.ShaderMaterial {
9999
#_visible = true;
100100
constructor(options = {}, crsCount) {
101+
options.clipping = options.clipping || options.clippingPlanes !== undefined;
101102
super(options);
102103

103104
nbSamplers = nbSamplers || [samplersElevationCount, getMaxColorSamplerUnitsCount()];

src/Renderer/Shader/TileFS.glsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88
#include <itowns/lighting_pars_fragment>
99
#endif
1010
#include <itowns/mode_pars_fragment>
11+
#include <clipping_planes_pars_fragment>
1112

1213
uniform vec3 diffuse;
1314
uniform float opacity;
1415
varying vec3 vUv; // uv.x/uv_1.x, uv.y, uv_1.y
1516
varying vec2 vHighPrecisionZW;
1617

1718
void main() {
19+
#include <clipping_planes_fragment>
1820
#include <logdepthbuf_fragment>
1921

2022
#if MODE == MODE_ID

src/Renderer/Shader/TileVS.glsl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <common>
33
#include <itowns/elevation_pars_vertex>
44
#include <logdepthbuf_pars_vertex>
5+
#include <clipping_planes_pars_vertex>
56
#if NUM_CRS > 1
67
attribute float uv_1;
78
#endif
@@ -15,10 +16,12 @@ varying vec3 vUv;
1516
varying vec3 vNormal;
1617
#endif
1718
void main() {
19+
1820
#include <begin_vertex>
1921
#include <itowns/elevation_vertex>
2022
#include <itowns/geoid_vertex>
21-
#include <project_vertex>
23+
#include <project_vertex> // mvPosition
24+
#include <clipping_planes_vertex>
2225
#include <logdepthbuf_vertex>
2326
vHighPrecisionZW = gl_Position.zw;
2427
#if MODE == MODE_FINAL

src/Renderer/c3DEngine.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class c3DEngine {
8787
alpha: options.alpha,
8888
logarithmicDepthBuffer: options.logarithmicDepthBuffer,
8989
});
90+
this.renderer.localClippingEnabled = true;
9091
this.renderer.domElement.style.position = 'relative';
9192
this.renderer.domElement.style.zIndex = 0;
9293
this.renderer.domElement.style.top = 0;

0 commit comments

Comments
 (0)