From f8c8c3f5b74668229f25128bb9afaf8a10738cae Mon Sep 17 00:00:00 2001 From: "azykov@mail.ru" Date: Tue, 2 Jun 2026 18:19:55 +0300 Subject: [PATCH] box around selected objects in editor --- src/components/ObjectView.tsx | 11 +++++++---- src/components/Toolbar.tsx | 1 - src/state/gameState.ts | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/ObjectView.tsx b/src/components/ObjectView.tsx index 95df579..91826a3 100644 --- a/src/components/ObjectView.tsx +++ b/src/components/ObjectView.tsx @@ -2,7 +2,8 @@ import { observer } from "mobx-react-lite"; import type { ObjectInstance } from "../types"; import { useEffect, useRef, type RefObject } from "react"; import type { Group } from "three"; -import { Edges, TransformControls } from "@react-three/drei"; +import { TransformControls, useHelper } from "@react-three/drei"; +import { BoxHelper } from "three"; import type { ThreeEvent } from "@react-three/fiber"; import { state } from "../state"; import { nextSelectionEditMode } from "../state/worldEditorState"; @@ -16,11 +17,14 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) { const groupRef = useRef(null); const controlsRef = useRef(null); + const isSelected = state.worldEditor.isEnabled && + state.worldEditor.selectedObjectId === object.id; + + useHelper(isSelected ? groupRef : { current: null } as any, BoxHelper, 'white'); + const objectType = state.world.getObjectTypeById(object.typeId); if (!objectType) return null; - const isSelected = state.worldEditor.isEnabled && - state.worldEditor.selectedObjectId === object.id; const selectionMode = isSelected ? state.worldEditor.selectedObjectMode : undefined; @@ -91,7 +95,6 @@ export const ObjectView = observer(function ({ object }: ObjectViewProps) { opacity={opacity} transparent={opacity < 1} /> - {isSelected && } ); }) diff --git a/src/components/Toolbar.tsx b/src/components/Toolbar.tsx index faa61d1..aaba570 100644 --- a/src/components/Toolbar.tsx +++ b/src/components/Toolbar.tsx @@ -1,7 +1,6 @@ import { observer } from "mobx-react-lite"; import { state } from "../state"; -import type { RunningGameState } from "../types"; export const Toolbar = observer(function () { diff --git a/src/state/gameState.ts b/src/state/gameState.ts index 311511e..e663660 100644 --- a/src/state/gameState.ts +++ b/src/state/gameState.ts @@ -2,7 +2,6 @@ import { makeAutoObservable } from "mobx"; import type { WorldState } from "./worldState"; import type { RunningGameState, Scene } from "../types"; import { clone } from "../utils"; -import { state } from "./rootState"; import type { Pos3 } from "../types/3d"; import type { CameraProps } from "@react-three/fiber";