diff --git a/CHANGELOG.md b/CHANGELOG.md index 20bcac0..fc01ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,9 @@ * Added, when an object is selected its material color changes to orange and slightly emissive yellow. * Added `Toolbar.vue` featuring existing transforms and views shortcuts into user-friendly buttons. * Added `NumberField` class to `compas_threejs.ui`. -* Added command to save views, select them and download a screenshot as image. +* Added commands to save views, select them and download a screenshot as image. * Added dark/light theme toggle. +* Added command to play/pause object motion. ### Changed diff --git a/README.md b/README.md index 4c72062..31c5745 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ View shortcuts (numpad): - `0`: Bottom view Display shortcuts: +- `spacebar`: Play/Pause object motion - `S`: Save current view - `F`: Save screenshot as image diff --git a/frontend/compas_threejs/src/communications/messages.ts b/frontend/compas_threejs/src/communications/messages.ts index 418a938..fe4438a 100644 --- a/frontend/compas_threejs/src/communications/messages.ts +++ b/frontend/compas_threejs/src/communications/messages.ts @@ -4,7 +4,7 @@ import type { AnyData } from "../protobuff/generated/compas_pb/data/message"; import { Dictionary } from "../protobuff/messages"; import * as THREE from "three"; import { lightManager } from "../viewer/light_manager"; -import { geometryManager } from "../viewer/geometry_manager"; +import { geometryManager, SCENE_GEOMETRIES } from "../viewer/geometry_manager"; import { materialManager } from "../viewer/material_manager"; import { sceneManager } from "../viewer/scene_manager"; import { themeManager } from "../viewer/theme_manager"; @@ -13,8 +13,8 @@ import { textManager } from "../viewer/text_manager"; import { objectInfoManager } from "./objectInfo"; import { objectActionManager } from "./objectInfo"; import { removeObjectFromScene } from "../viewer/scene_manager"; - -const SCENE_GEOMETRIES: { [guid: string]: THREE.Object3D } = {}; +import { objectMotionManager } from "./objectMotion"; +import { motionState } from "@/store/store"; export function dispatchMessage(message: Uint8Array) { const obj = unpackMessageToGeometry(message); @@ -23,6 +23,13 @@ export function dispatchMessage(message: Uint8Array) { analyzeDictionary(obj); return; } else { + if ( + motionState.objectMotionPaused && + obj?.guid && + SCENE_GEOMETRIES[obj.guid] + ) { + return; + } geometryManager(obj); } } @@ -59,6 +66,9 @@ function analyzeDictionary(dictionary: Dictionary) { case "remove_object": removeObjectFromScene(data); break; + case "object_motion": + objectMotionManager(data); + break; default: console.warn("Unknown dispatch value:", data.dispatch.value); } diff --git a/frontend/compas_threejs/src/communications/objectMotion.ts b/frontend/compas_threejs/src/communications/objectMotion.ts new file mode 100644 index 0000000..92c7f79 --- /dev/null +++ b/frontend/compas_threejs/src/communications/objectMotion.ts @@ -0,0 +1,57 @@ +import { sendData } from "@/communications/communication"; +import { motionState } from "@/store/store"; + +function notifyBackendObjectMotionPause(paused: boolean): void { + sendData({ + dispatch: "object_motion_control", + paused, + }); +} + +export function setObjectMotionPaused(paused: boolean): void { + if (!motionState.objectMotionAvailable) { + return; + } + + if (motionState.objectMotionPaused === paused) { + return; + } + + motionState.objectMotionPaused = paused; + notifyBackendObjectMotionPause(paused); +} + +export function toggleObjectMotionPaused(): boolean { + if (!motionState.objectMotionAvailable) { + return motionState.objectMotionPaused; + } + + setObjectMotionPaused(!motionState.objectMotionPaused); + return motionState.objectMotionPaused; +} + +export function isObjectMotionPaused(): boolean { + return motionState.objectMotionPaused; +} + +export function setObjectMotionAvailable(available: boolean): void { + motionState.objectMotionAvailable = available; + + if (!available) { + motionState.objectMotionPaused = false; + } +} + +export function isObjectMotionAvailable(): boolean { + return motionState.objectMotionAvailable; +} + +export function objectMotionManager(data: { [key: string]: any }): void { + switch (data.type.value) { + case "availability": + setObjectMotionAvailable(Boolean(data.enabled.value)); + break; + default: + console.warn("Unknown object motion type:", data.type.value); + } +} diff --git a/frontend/compas_threejs/src/components/tools/display/DisplayGroup.vue b/frontend/compas_threejs/src/components/tools/display/DisplayGroup.vue index 86afdc2..97944bb 100644 --- a/frontend/compas_threejs/src/components/tools/display/DisplayGroup.vue +++ b/frontend/compas_threejs/src/components/tools/display/DisplayGroup.vue @@ -1,6 +1,11 @@