MCPcopy Create free account
hub / github.com/esengine/esengine / Viewport

Function Viewport

packages/editor-app/src/components/Viewport.tsx:233–2556  ·  view source on GitHub ↗
({ locale = 'en', messageHub, commandManager }: ViewportProps)

Source from the content-addressed store, hash-verified

231}
232
233export function Viewport({ locale = 'en', messageHub, commandManager }: ViewportProps) {
234 const { t } = useLocale();
235 const canvasRef = useRef<HTMLCanvasElement>(null);
236 const containerRef = useRef<HTMLDivElement>(null);
237 const [playState, setPlayState] = useState<PlayState>('stopped');
238 const [showGrid, setShowGrid] = useState(true);
239 const [showGizmos, setShowGizmos] = useState(true);
240 const [showStats, setShowStats] = useState(false);
241 const [transformMode, setTransformMode] = useState<TransformMode>('select');
242 const [showRunMenu, setShowRunMenu] = useState(false);
243 const [showQRDialog, setShowQRDialog] = useState(false);
244 const [devicePreviewUrl, setDevicePreviewUrl] = useState('');
245 const runMenuRef = useRef<HTMLDivElement>(null);
246
247 // Prefab edit mode state | 预制体编辑模式状态
248 const [prefabEditMode, setPrefabEditMode] = useState<{
249 isActive: boolean;
250 prefabName: string;
251 prefabPath: string;
252 } | null>(null);
253
254 // Snap settings
255 const [snapEnabled, setSnapEnabled] = useState(true);
256 const [gridSnapValue, setGridSnapValue] = useState(10);
257 const [rotationSnapValue, setRotationSnapValue] = useState(15);
258 const [scaleSnapValue, setScaleSnapValue] = useState(0.25);
259 const [showGridSnapMenu, setShowGridSnapMenu] = useState(false);
260 const [showRotationSnapMenu, setShowRotationSnapMenu] = useState(false);
261 const [showScaleSnapMenu, setShowScaleSnapMenu] = useState(false);
262 const gridSnapMenuRef = useRef<HTMLDivElement>(null);
263 const rotationSnapMenuRef = useRef<HTMLDivElement>(null);
264 const scaleSnapMenuRef = useRef<HTMLDivElement>(null);
265
266 // Store editor camera state when entering play mode
267 const editorCameraRef = useRef({ x: 0, y: 0, zoom: 1 });
268 const playStateRef = useRef<PlayState>('stopped');
269
270 // Runtime scene manager for play mode scene switching | Play 模式场景切换管理器
271 const runtimeSceneManagerRef = useRef<IRuntimeSceneManager | null>(null);
272
273 // Live transform display state | 实时变换显示状态
274 const [liveTransform, setLiveTransform] = useState<{
275 type: 'move' | 'rotate' | 'scale';
276 x: number;
277 y: number;
278 rotation?: number;
279 scaleX?: number;
280 scaleY?: number;
281 } | null>(null);
282
283 // Rust engine hook with multi-viewport support
284 const engine = useEngine({
285 viewportId: 'editor-viewport',
286 canvasId: 'viewport-canvas',
287 showGrid: true,
288 showGizmos: true,
289 autoInit: true
290 });

Callers

nothing calls this directly

Calls 15

useLocaleFunction · 0.90
useEngineFunction · 0.90
startFlyLoopFunction · 0.85
isPrefabEditModeMethod · 0.80
savePrefabMethod · 0.80
exitPrefabEditModeMethod · 0.80
getDataMethod · 0.80
popMethod · 0.80
resizeCanvasFunction · 0.70
publishMethod · 0.65
subscribeMethod · 0.65

Tested by

no test coverage detected