Skip to content

Commit

Permalink
Add mesh opacity support
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed Aug 10, 2023
1 parent 4ca309e commit 6adf300
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions viser/_message_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ def add_mesh_simple(
faces: onp.ndarray,
color: RgbTupleOrArray = (90, 200, 255),
wireframe: bool = False,
opacity: Optional[float] = None,
side: Literal["front", "back", "double"] = "front",
wxyz: Tuple[float, float, float, float] | onp.ndarray = (1.0, 0.0, 0.0, 0.0),
position: Tuple[float, float, float] | onp.ndarray = (0.0, 0.0, 0.0),
Expand All @@ -277,6 +278,7 @@ def add_mesh_simple(
color=_encode_rgb(color),
vertex_colors=None,
wireframe=wireframe,
opacity=opacity,
side=side,
)
)
Expand Down Expand Up @@ -306,6 +308,7 @@ def add_mesh_trimesh(
vertex_colors.view(onp.ndarray).astype(onp.uint8)[..., :3]
),
wireframe=wireframe,
opacity=None,
side=side,
)
)
Expand Down
1 change: 1 addition & 0 deletions viser/_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class MeshMessage(Message):
vertex_colors: Optional[onpt.NDArray[onp.uint8]]

wireframe: bool
opacity: Optional[float]
side: Literal["front", "back", "double"] = "front"

def __post_init__(self):
Expand Down
4 changes: 3 additions & 1 deletion viser/client/src/ControlPanel/ControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export default function ControlPanel(props: {

// TODO: will result in unnecessary re-renders
const viewer = React.useContext(ViewerContext)!;
const showGenerated = viewer.useGui((state) => 'root' in state.guiIdSetFromContainerId);
const showGenerated = viewer.useGui(
(state) => "root" in state.guiIdSetFromContainerId,
);
const [showSettings, { toggle }] = useDisclosure(false);
const [collapsed, { toggle: toggleCollapse }] = useDisclosure(false);
const handleContents = (
Expand Down
2 changes: 1 addition & 1 deletion viser/client/src/ControlPanel/Generated.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function GeneratedGuiContainer({
if (viewer === undefined) viewer = React.useContext(ViewerContext)!;

const guiIdSet = viewer.useGui(
(state) => state.guiIdSetFromContainerId[containerId]
(state) => state.guiIdSetFromContainerId[containerId],
);
const guiConfigFromId = viewer.useGui((state) => state.guiConfigFromId);

Expand Down
4 changes: 2 additions & 2 deletions viser/client/src/ControlPanel/GuiState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function useGuiState(initialServer: string) {
set((state) => {
state.guiConfigFromId[guiConfig.id] = guiConfig;
state.guiIdSetFromContainerId[guiConfig.container_id] = new Set(
state.guiIdSetFromContainerId[guiConfig.container_id]
state.guiIdSetFromContainerId[guiConfig.container_id],
).add(guiConfig.id);
}),
addModal: (modalConfig) =>
Expand Down Expand Up @@ -123,7 +123,7 @@ export function useGuiState(initialServer: string) {
guiConfig.tab_container_ids.forEach(state.removeGuiContainer);

state.guiIdSetFromContainerId[guiConfig.container_id]!.delete(
guiConfig.id
guiConfig.id,
);
delete state.guiConfigFromId[id];
delete state.guiValueFromId[id];
Expand Down
2 changes: 2 additions & 0 deletions viser/client/src/WebsocketInterface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ function useMessageHandler() {
color: message.color || undefined,
vertexColors: message.vertex_colors !== null,
wireframe: message.wireframe,
transparent: message.opacity !== null,
opacity: message.opacity ?? undefined,
side: {
front: THREE.FrontSide,
back: THREE.BackSide,
Expand Down
1 change: 1 addition & 0 deletions viser/client/src/WebsocketMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export interface MeshMessage {
color: number | null;
vertex_colors: ArrayBuffer | null;
wireframe: boolean;
opacity: number | null;
side: "front" | "back" | "double";
}
export interface TransformControlsMessage {
Expand Down
2 changes: 1 addition & 1 deletion viser/client/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ReactDOM from "react-dom/client";
import { Root } from "./App";
import { enableMapSet } from "immer"
import { enableMapSet } from "immer";

enableMapSet();

Expand Down

0 comments on commit 6adf300

Please sign in to comment.