Skip to content

Commit

Permalink
feat: support clipping box direction on reearth/core (#467)
Browse files Browse the repository at this point in the history
feat: support clipping box direction
  • Loading branch information
keiya01 authored Feb 17, 2023
1 parent 55334ec commit 70f74e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/core/engines/Cesium/Feature/Tileset/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export const useHooks = ({
pitch,
planes: _planes,
visible: clippingVisible = true,
direction = "inside",
} = experimental_clipping || {};
const { allowEnterGround } = sceneProperty?.default || {};
const [style, setStyle] = useState<Cesium3DTileStyle>();
Expand All @@ -242,6 +243,7 @@ export const useHooks = ({
}
return prevPlanes.current;
}, [_planes]);
const clipDirection = direction === "inside" ? -1 : 1;
// Create immutable object
const [clippingPlanes] = useState(
() =>
Expand All @@ -250,9 +252,10 @@ export const useHooks = ({
plane =>
new ClippingPlane(
new Cartesian3(plane.normal?.x, plane.normal?.y, plane.normal?.z),
(plane.distance || 0) * -1,
(plane.distance || 0) * clipDirection,
),
),
unionClippingRegions: direction === "outside",
edgeWidth: edgeWidth,
edgeColor: toColor(edgeColor),
}),
Expand Down Expand Up @@ -348,10 +351,10 @@ export const useHooks = ({
Matrix4.multiply(inverseOriginalModelMatrix, boxTransform, clippingPlanes.modelMatrix);
};

prepareClippingPlanes();
if (!allowEnterGround) {
updateTerrainHeight(Matrix4.getTranslation(clippingPlanes.modelMatrix, new Cartesian3()));
}
prepareClippingPlanes();
}, [
width,
length,
Expand All @@ -371,17 +374,21 @@ export const useHooks = ({
clippingPlanes.enabled = clippingVisible;
}, [clippingPlanes, clippingVisible]);

useEffect(() => {
clippingPlanes.unionClippingRegions = direction === "outside";
}, [clippingPlanes, direction]);

useEffect(() => {
clippingPlanes.removeAll();
planes?.forEach(plane =>
clippingPlanes.add(
new ClippingPlane(
new Cartesian3(plane.normal?.x, plane.normal?.y, plane.normal?.z),
(plane.distance || 0) * -1,
(plane.distance || 0) * clipDirection,
),
),
);
}, [planes, clippingPlanes]);
}, [planes, clippingPlanes, clipDirection]);

useEffect(() => {
if (!styleUrl) {
Expand Down
1 change: 1 addition & 0 deletions src/core/mantle/types/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export type EXPERIMENTAL_clipping = {
heading?: number;
pitch?: number;
roll?: number;
direction?: "inside" | "outside";
};

// Don't forget adding a new field to valueTypeMapper also!
Expand Down

0 comments on commit 70f74e3

Please sign in to comment.