Skip to content

Commit

Permalink
Add back stream idle mode
Browse files Browse the repository at this point in the history
  • Loading branch information
lf94 committed Feb 7, 2025
1 parent 67e60cb commit 63266ad
Show file tree
Hide file tree
Showing 19 changed files with 860 additions and 486 deletions.
38 changes: 29 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useEffect, useMemo, useRef, useState } from 'react'
import { useHotKeyListener } from './hooks/useHotKeyListener'
import { Stream } from './components/Stream'
import { AppHeader } from './components/AppHeader'
import { useHotkeys } from 'react-hotkeys-hook'
import { useLoaderData, useNavigate } from 'react-router-dom'
import { useLoaderData, useNavigate, useSearchParams } from 'react-router-dom'
import { type IndexLoaderData } from 'lib/types'
import { PATHS } from 'lib/paths'
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
Expand Down Expand Up @@ -33,6 +32,8 @@ import { useToken } from 'machines/appMachine'
maybeWriteToDisk()
.then(() => {})
.catch(() => {})
import EngineStreamContext from 'hooks/useEngineStreamContext'
import { EngineStream } from 'components/EngineStream'

export function App() {
const { project, file } = useLoaderData() as IndexLoaderData
Expand All @@ -57,6 +58,12 @@ export function App() {
// the coredump.
const ref = useRef<HTMLDivElement>(null)

// Stream related refs and data
const videoRef = useRef<HTMLVideoElement>(null)
const canvasRef = useRef<HTMLCanvasElement>(null)
let [searchParams] = useSearchParams()
const pool = searchParams.get('pool')

const projectName = project?.name || null
const projectPath = project?.path || null

Expand Down Expand Up @@ -137,13 +144,26 @@ export function App() {
/>
<ModalContainer />
<ModelingSidebar paneOpacity={paneOpacity} />
<Stream />
{/* <CamToggle /> */}
<LowerRightControls coreDumpManager={coreDumpManager}>
<UnitsMenu />
<Gizmo />
<CameraProjectionToggle />
</LowerRightControls>
<EngineStreamContext.Provider
options={{
input: {
videoRef,
canvasRef,
mediaStream: null,
authToken: token ?? null,
pool,
zoomToFit: true,
},
}}
>
<EngineStream />
{/* <CamToggle /> */}
<LowerRightControls coreDumpManager={coreDumpManager}>
<UnitsMenu />
<Gizmo />
<CameraProjectionToggle />
</LowerRightControls>
</EngineStreamContext.Provider>
</div>
)
}
4 changes: 3 additions & 1 deletion src/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { isDesktop } from 'lib/isDesktop'
import { openExternalBrowserIfDesktop } from 'lib/openWindow'
import { commandBarActor } from 'machines/commandBarMachine'
import { isArray } from 'lib/utils'
import { EngineConnectionStateType } from 'lang/std/engineConnection'

export function Toolbar({
className = '',
Expand All @@ -46,7 +47,7 @@ export function Toolbar({
}, [engineCommandManager.artifactGraph, context.selectionRanges])

const toolbarButtonsRef = useRef<HTMLUListElement>(null)
const { overallState } = useNetworkContext()
const { overallState, immediateState } = useNetworkContext()
const { isExecuting } = useKclContext()
const { isStreamReady } = useAppState()
const [showRichContent, setShowRichContent] = useState(false)
Expand All @@ -55,6 +56,7 @@ export function Toolbar({
(overallState !== NetworkHealthState.Ok &&
overallState !== NetworkHealthState.Weak) ||
isExecuting ||
immediateState.type !== EngineConnectionStateType.ConnectionEstablished ||
!isStreamReady

const currentMode =
Expand Down
28 changes: 28 additions & 0 deletions src/clientSideScene/CameraControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ export class CameraControls {
wasDragging: boolean
mouseDownPosition: Vector2
mouseNewPosition: Vector2
old:
| {
camera: PerspectiveCamera | OrthographicCamera
target: Vector3
}
| undefined
rotationSpeed = 0.3
enableRotate = true
enablePan = true
Expand Down Expand Up @@ -933,6 +939,28 @@ export class CameraControls {
})
}

async restoreCameraPosition(): Promise<void> {
if (!this.old) return

this.camera = this.old.camera.clone()
this.target = this.old.target.clone()

void this.engineCommandManager.sendSceneCommand({
type: 'modeling_cmd_req',
cmd_id: uuidv4(),
cmd: {
type: 'default_camera_look_at',
...convertThreeCamValuesToEngineCam({
isPerspective: true,
position: this.camera.position,
quaternion: this.camera.quaternion,
zoom: this.camera.zoom,
target: this.target,
}),
},
})
}

async tweenCameraToQuaternion(
targetQuaternion: Quaternion,
targetPosition = new Vector3(),
Expand Down
11 changes: 11 additions & 0 deletions src/components/CommandBar/CommandBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { Dialog, Popover, Transition } from '@headlessui/react'
import { Fragment, useEffect } from 'react'
import { useNetworkContext } from 'hooks/useNetworkContext'
import { EngineConnectionStateType } from 'lang/std/engineConnection'
import CommandBarArgument from './CommandBarArgument'
import CommandComboBox from '../CommandComboBox'
import CommandBarReview from './CommandBarReview'
Expand All @@ -14,6 +16,7 @@ export const COMMAND_PALETTE_HOTKEY = 'mod+k'
export const CommandBar = () => {
const { pathname } = useLocation()
const commandBarState = useCommandBarState()
const { immediateState } = useNetworkContext()
const {
context: { selectedCommand, currentArgument, commands },
} = commandBarState
Expand All @@ -26,6 +29,14 @@ export const CommandBar = () => {
commandBarActor.send({ type: 'Close' })
}, [pathname])

useEffect(() => {
if (
immediateState.type !== EngineConnectionStateType.ConnectionEstablished
) {
commandBarActor.send({ type: 'Close' })
}
}, [immediateState])

// Hook up keyboard shortcuts
useHotkeyWrapper([COMMAND_PALETTE_HOTKEY], () => {
if (commandBarState.context.commands.length === 0) return
Expand Down
8 changes: 8 additions & 0 deletions src/components/CommandBarOpenButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import usePlatform from 'hooks/usePlatform'
import { hotkeyDisplay } from 'lib/hotkeyWrapper'
import { COMMAND_PALETTE_HOTKEY } from './CommandBar/CommandBar'
import { commandBarActor } from 'machines/commandBarMachine'
import { useNetworkContext } from 'hooks/useNetworkContext'
import { EngineConnectionStateType } from 'lang/std/engineConnection'

export function CommandBarOpenButton() {
const { immediateState } = useNetworkContext()

const platform = usePlatform()

const isDisabled =
immediateState.type !== EngineConnectionStateType.ConnectionEstablished

return (
<button
disabled={isDisabled}
className="group rounded-full flex items-center justify-center gap-2 px-2 py-1 bg-primary/10 dark:bg-chalkboard-90 dark:backdrop-blur-sm border-primary hover:border-primary dark:border-chalkboard-50 dark:hover:border-inherit text-primary dark:text-inherit"
onClick={() => commandBarActor.send({ type: 'Open' })}
data-testid="command-bar-open-button"
Expand Down
Loading

0 comments on commit 63266ad

Please sign in to comment.