Skip to content

Commit

Permalink
fix: allow enter ground option for clipping box on reearth/core (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 committed Mar 1, 2023
1 parent 6448bac commit f8e1293
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/core/engines/Cesium/Feature/Box/hooks/box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ import { computeMouseMoveAmount, updateTrs } from "../utils";
export const useHooks = ({
property,
geometry,
sceneProperty,
feature,
onLayerEdit,
}: Pick<FeatureProps<Property>, "property" | "sceneProperty" | "geometry" | "feature"> & {
}: Pick<FeatureProps<Property>, "property" | "geometry" | "feature"> & {
onLayerEdit?: (e: LayerEditEvent) => void;
}) => {
const { viewer } = useCesium();
Expand All @@ -49,8 +48,8 @@ export const useHooks = ({
activePointOutlineColor,
axisLineColor,
cursor,
allowEnterGround,
} = property ?? {};
const { allowEnterGround } = sceneProperty?.default || {};

const [terrainHeightEstimate, setTerrainHeightEstimate] = useState(0);
const [trs] = useState(() =>
Expand Down
3 changes: 1 addition & 2 deletions src/core/engines/Cesium/Feature/Box/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const Box: React.FC<Props> = memo(function BoxPresenter({
property,
geometry,
isVisible,
sceneProperty,
layer,
feature,
onLayerEdit,
Expand Down Expand Up @@ -50,7 +49,7 @@ const Box: React.FC<Props> = memo(function BoxPresenter({
handleEdgeMouseDown,
handleEdgeMouseMove,
handleEdgeMouseUp,
} = useHooks({ property, geometry, sceneProperty, feature, onLayerEdit });
} = useHooks({ property, geometry, feature, onLayerEdit });

const scalePointDimension = ((width + height + length) / 3) * 0.05;

Expand Down
5 changes: 2 additions & 3 deletions src/core/engines/Cesium/Feature/Tileset/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export const useHooks = ({
boxId,
isVisible,
property,
sceneProperty,
layer,
feature,
meta,
Expand Down Expand Up @@ -277,8 +276,8 @@ export const useHooks = ({
visible: clippingVisible = true,
direction = "inside",
builtinBoxProps,
} = useClippingBox({ clipping: experimental_clipping, sceneProperty, boxId });
const { allowEnterGround } = sceneProperty?.default || {};
allowEnterGround,
} = useClippingBox({ clipping: experimental_clipping, boxId });
const [style, setStyle] = useState<Cesium3DTileStyle>();
const { url, type } = useData(layer);

Expand Down
1 change: 0 additions & 1 deletion src/core/engines/Cesium/Feature/Tileset/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ function Tileset({
layer,
feature,
property,
sceneProperty,
meta,
evalFeature,
onComputedFeatureFetch,
Expand Down
24 changes: 9 additions & 15 deletions src/core/engines/Cesium/Feature/Tileset/useClippingBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { RootEventTarget, useCesium } from "resium";

import { computeMoveAmount } from "@reearth/components/molecules/Visualizer/Engine/Cesium/Box/utils";
import { Camera, EXPERIMENTAL_clipping } from "@reearth/core/mantle";
import { LayerEditEvent, SceneProperty } from "@reearth/core/Map";
import { LayerEditEvent } from "@reearth/core/Map";

import {
getCamera,
Expand Down Expand Up @@ -84,17 +84,15 @@ export const BUILTIN_BOX_SIDE_PLANES = [

export const useClippingBox = ({
clipping,
sceneProperty,
boxId,
}: {
clipping?: EXPERIMENTAL_clipping;
sceneProperty?: SceneProperty;
boxId: string;
}) => {
const {
useBuiltinBox,
visible,
keepAboveGround,
allowEnterGround,
coordinates,
width,
height,
Expand All @@ -106,11 +104,6 @@ export const useClippingBox = ({

const { viewer }: { viewer: Viewer } = useCesium();

const allowEnterGround = useCallback(
() => !!sceneProperty?.default?.allowEnterGround || !keepAboveGround,
[sceneProperty?.default?.allowEnterGround, keepAboveGround],
);

const isBoxClicked = useRef(false);
const isTopBottomSidePlaneClicked = useRef(false);
const currentCameraPosition = useRef<Camera | undefined>();
Expand Down Expand Up @@ -229,7 +222,7 @@ export const useClippingBox = ({
if (isTopBottomSidePlaneClicked.current) {
const locationHeight = coords?.[2] || 0;
const terrainHeight = await (async () => {
if (!allowEnterGround()) {
if (!allowEnterGround) {
const boxBottomHeight = locationHeight - (dimensions?.height || 0) / 2;
const floorHeight =
(await sampleTerrainHeight(viewer.scene, coords?.[0] || 0, coords?.[1] || 0)) || 0;
Expand All @@ -250,9 +243,6 @@ export const useClippingBox = ({
);
const direction = new Cartesian3(0, 0, vector.y < 0 ? -1 : 1);

// FIXME()
// const scale =
// Math.floor(locationHeight) > 5 ? getCamera().height / locationHeight : 1;
const { moveAmount } = computeMoveAmount(
viewer.scene,
{
Expand All @@ -263,15 +253,19 @@ export const useClippingBox = ({
direction,
);
const moveVector = Cartesian3.multiplyByScalar(direction, moveAmount, new Cartesian3());
setCoords(v => [v?.[0] || 0, v?.[1] || 0, (v?.[2] || 0) + moveVector.z + terrainHeight]);
setCoords(v => [
v?.[0] || 0,
v?.[1] || 0,
(terrainHeight ? terrainHeight : v?.[2] || 0) + moveVector.z,
]);
} else {
const position = e.endPosition
? getLocationFromScreen(viewer.scene, e.endPosition.x, e.endPosition.y, true)
: undefined;
setCoords(v => [
position?.lng || 0,
position?.lat || 0,
(!allowEnterGround() ? position?.height : undefined) || v?.[2] || 0,
(!allowEnterGround ? position?.height : undefined) || v?.[2] || 0,
]);
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/core/mantle/types/value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export type Plane = {
// Familiar with Cesium
export type EXPERIMENTAL_clipping = {
useBuiltinBox?: boolean;
keepAboveGround?: boolean;
allowEnterGround?: boolean;
planes?: {
normal: {
x: number;
Expand Down

0 comments on commit f8e1293

Please sign in to comment.