-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
editor: light WebGPU preview and /editor scene redirect #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5022910
7179de9
99179c9
003ac55
a035819
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,14 +9,18 @@ import { | |
| type SceneGraph, | ||
| type SidebarTab, | ||
| } from '@pascal-app/editor' | ||
| import { useViewer } from '@pascal-app/viewer' | ||
| import { Hammer, Layers } from 'lucide-react' | ||
| import Image from 'next/image' | ||
| import Link from 'next/link' | ||
| import { useRouter } from 'next/navigation' | ||
| import { useRouter, useSearchParams } from 'next/navigation' | ||
| import { useCallback, useEffect, useRef, useState } from 'react' | ||
| import { BuildTab } from './build-tab' | ||
| import { CommunityViewerToolbarLeft, CommunityViewerToolbarRight } from './viewer-toolbar' | ||
|
|
||
| /** Lighter preview path: skips post-FX and outline passes (viewer `?disable=` flags). */ | ||
| export const LIGHT_PREVIEW_QUERY = 'disable=postFx,outline' | ||
|
|
||
| export interface SceneMeta { | ||
| id: string | ||
| name: string | ||
|
|
@@ -92,13 +96,35 @@ function sceneGraphSignature(graph: SceneGraphWithCollections): string { | |
| }) | ||
| } | ||
|
|
||
| function isLightPreviewQuery(searchParams: URLSearchParams): boolean { | ||
| const disable = searchParams.get('disable') ?? '' | ||
| return ( | ||
| disable.split(',').some((p) => p.trim() === 'postFx') || searchParams.get('safe') === '1' | ||
| ) | ||
| } | ||
|
|
||
| export function SceneLoader({ initialScene, meta }: SceneLoaderProps) { | ||
| const router = useRouter() | ||
| const searchParams = useSearchParams() | ||
| const versionRef = useRef(meta.version) | ||
| const lastRemoteGraphJsonRef = useRef<string | null>(null) | ||
| const suppressRemoteSaveUntilRef = useRef(0) | ||
| const [conflict, setConflict] = useState(false) | ||
| const [saveError, setSaveError] = useState<string | null>(null) | ||
| /** Bumps when Light preview is clicked while already active so effects re-apply. */ | ||
| const [lightApplyTick, setLightApplyTick] = useState(0) | ||
|
|
||
| const lightPreview = isLightPreviewQuery(searchParams) | ||
|
|
||
| // Light preview: host prop disablePostFx rebuilds the pipeline; solid shading pairs with it. | ||
| // When flags clear, restore rendered so post-FX can come back. | ||
| useEffect(() => { | ||
| try { | ||
| useViewer.getState().setShading(lightPreview ? 'solid' : 'rendered') | ||
| } catch { | ||
| // Viewer store may not be ready yet on first paint. | ||
| } | ||
| }, [lightPreview, lightApplyTick]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rendered shading leaks to homeMedium Severity When a scene loads without light-preview query params, Reviewed by Cursor Bugbot for commit a035819. Configure here. |
||
|
|
||
| const handleLoad = useCallback(async () => initialScene, [initialScene]) | ||
|
|
||
|
|
@@ -224,6 +250,24 @@ export function SceneLoader({ initialScene, meta }: SceneLoaderProps) { | |
| </div> | ||
| )} | ||
| <div className="pointer-events-none absolute top-4 right-4 z-40 flex items-center gap-2"> | ||
| <button | ||
| type="button" | ||
| className="pointer-events-auto rounded-md border border-border bg-background/90 px-3 py-1.5 font-medium text-xs shadow-sm backdrop-blur hover:bg-accent/40" | ||
| onClick={() => { | ||
| // Force re-apply even if URL already has light-preview flags (toolbar may have changed shading). | ||
| setLightApplyTick((n) => n + 1) | ||
| try { | ||
| useViewer.getState().setShading('solid') | ||
| } catch { | ||
| // ignore | ||
| } | ||
| if (!lightPreview) { | ||
| router.push(`/scene/${meta.id}?${LIGHT_PREVIEW_QUERY}`) | ||
| } | ||
| }} | ||
| > | ||
| Light preview | ||
|
cursor[bot] marked this conversation as resolved.
|
||
| </button> | ||
| <Link | ||
| className="pointer-events-auto rounded-md border border-border bg-background/90 px-3 py-1.5 font-medium text-xs shadow-sm backdrop-blur hover:bg-accent/40" | ||
| href="/scenes" | ||
|
|
@@ -232,6 +276,7 @@ export function SceneLoader({ initialScene, meta }: SceneLoaderProps) { | |
| </Link> | ||
| </div> | ||
| <Editor | ||
| disablePostFx={lightPreview} | ||
| layoutVersion="v2" | ||
| onLoad={handleLoad} | ||
| onSave={handleSave} | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Post-FX stuck after light preview
High Severity
The new light preview feature causes two viewer state issues: post-FX remains disabled after client navigation clears the
?disable=postFxquery, and theuseEffectincorrectly persists 'rendered' shading for the editor context, leading other editor instances (like the blank home editor) to load with 'rendered' instead of the default 'solid'.Additional Locations (1)
apps/editor/components/scene-loader.tsx#L120-L127Reviewed by Cursor Bugbot for commit a035819. Configure here.