Skip to content

Commit

Permalink
feat: color blend mode in tileset on reearth/core (#496)
Browse files Browse the repository at this point in the history
* feat: color blend mode in tileset

* Update src/core/mantle/types/appearance.ts

Co-authored-by: rot1024 <aayhrot@gmail.com>

* Update src/core/engines/Cesium/common.ts

Co-authored-by: rot1024 <aayhrot@gmail.com>

---------

Co-authored-by: rot1024 <aayhrot@gmail.com>
  • Loading branch information
keiya01 and rot1024 committed Feb 28, 2023
1 parent 4f07b93 commit ca43dc1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/core/engines/Cesium/Feature/Tileset/index.tsx
Expand Up @@ -2,7 +2,7 @@ import { memo, useMemo } from "react";
import { Cesium3DTileset } from "resium";

import type { Cesium3DTilesAppearance, ComputedLayer } from "../../..";
import { shadowMode } from "../../common";
import { colorBlendModeFor3DTile, shadowMode } from "../../common";
import Box from "../Box";
import { type FeatureComponentConfig, type FeatureProps } from "../utils";

Expand All @@ -25,7 +25,7 @@ function Tileset({
onFeatureDelete,
...props
}: Props): JSX.Element | null {
const { shadows } = property ?? {};
const { shadows, colorBlendMode } = property ?? {};
const boxId = `${layer?.id}_box`;
const { tilesetUrl, ref, style, clippingPlanes, builtinBoxProps } = useHooks({
id,
Expand Down Expand Up @@ -57,6 +57,7 @@ function Tileset({
style={style}
shadows={shadowMode(shadows)}
clippingPlanes={clippingPlanes}
colorBlendMode={colorBlendModeFor3DTile(colorBlendMode)}
/>
{builtinBoxProps && (
<Box
Expand Down
12 changes: 12 additions & 0 deletions src/core/engines/Cesium/common.ts
Expand Up @@ -30,6 +30,7 @@ import {
Matrix4,
Color,
SceneMode,
Cesium3DTileColorBlendMode,
} from "cesium";
import { useCallback, MutableRefObject } from "react";

Expand Down Expand Up @@ -472,6 +473,17 @@ export const colorBlendMode = (colorBlendMode?: "highlight" | "replace" | "mix"
} as { [key in string]?: ColorBlendMode }
)[colorBlendMode || ""]);

export const colorBlendModeFor3DTile = (
colorBlendMode?: "highlight" | "replace" | "mix" | "default",
) =>
((
{
highlight: Cesium3DTileColorBlendMode.HIGHLIGHT,
replace: Cesium3DTileColorBlendMode.REPLACE,
mix: Cesium3DTileColorBlendMode.MIX,
} as { [key in string]?: Cesium3DTileColorBlendMode }
)[colorBlendMode || ""]);

export const heightReference = (
heightReference?: "none" | "clamp" | "relative",
): HeightReference | undefined =>
Expand Down
1 change: 1 addition & 0 deletions src/core/mantle/types/appearance.ts
Expand Up @@ -125,6 +125,7 @@ export type Cesium3DTilesAppearance = {
color?: string;
styleUrl?: string;
shadows?: "disabled" | "enabled" | "cast_only" | "receive_only";
colorBlendMode?: "highlight" | "replace" | "mix" | "default";
edgeWidth?: number;
edgeColor?: string;
experimental_clipping?: EXPERIMENTAL_clipping;
Expand Down

0 comments on commit ca43dc1

Please sign in to comment.