diff --git a/docs/superpowers/specs/2026-11-18-generation-logo-loader-design.md b/docs/superpowers/specs/2026-11-18-generation-logo-loader-design.md new file mode 100644 index 00000000..f1819a92 --- /dev/null +++ b/docs/superpowers/specs/2026-11-18-generation-logo-loader-design.md @@ -0,0 +1,25 @@ +# Generate: playful logo loader while a mesh is generated + +## Intent + +While a mesh generates, the Generate viewer shows nothing but the small progress card. Showing the real mesh as it forms is not possible (generators work in latent space; the mesh exists only after the final decode, and extensions are black boxes). Instead, the maintainer wants an animated, playful Modly logo the user can play with while waiting. + +## Approaches + +- **A. Logo assembles with the progress.** Ties the animation to the %, but the maintainer preferred a free loop. +- **B. Decorative loop with hover and click (picked).** Slow rotation; hover highlights a piece; click detaches it, it floats away, then returns. + +## Design + +- An overlay over the Generate viewer, shown only while `currentJob.status` is `uploading` or `generating`. The scene behind is dimmed; `GenerationHUD` stays on top at the bottom. The overlay captures the pointer (no orbiting the scene meanwhile). +- Its own `@react-three/fiber` canvas, transparent background. The three pieces are the three paths of `src/shared/components/ui/ModlyLogo.tsx`, parsed (e.g. three's `SVGLoader`), centered, extruded thin. +- Look: violet wireframe with a visible triangulated mesh and small vertex dots, a soft glow, as in the reference image (dark background, `#c084fc` to `#9333ea` palette). +- Idle: the logo rotates slowly around the vertical axis. +- Hover: the hovered piece lights up (brighter violet fill and edges), cursor becomes a pointer. +- Click: the piece moves outward from the logo center (with a slight tilt) and leaves a short trail of particles, holds briefly, then returns and snaps back; total about 1.5 s. Clicks during its flight are ignored for that piece. +- End: the overlay fades out when the job leaves `uploading`/`generating`. +- `prefers-reduced-motion`: no rotation, no float-away; hover highlight stays. + +## Left to the builder + +Exact geometry (extrude depth, how the face is triangulated for the wireframe look), easing curves, glow technique (postprocessing bloom or additive materials), file layout under `src/areas/generate/components/`. diff --git a/package.json b/package.json index 605c5726..45baa960 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "prepare-resources": "node scripts/download-python-embed.js", "test": "npm run test:py && npm run test:node", "test:py": "node scripts/run-pytests.mjs", - "test:node": "node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs src/shared/types/assetLibrary.test.ts src/areas/generate/assetLibraryProjection.test.ts src/areas/generate/assetLibraryService.test.ts src/areas/generate/assetLibraryUi.test.ts src/areas/library/libraryView.test.ts src/areas/library/gridWindow.test.ts src/areas/generate/orcaSlicerLink.test.ts src/shared/utils/agentStream.test.ts src/shared/thumbnails/assetThumbnailQueue.test.ts src/shared/thumbnails/assetThumbnailStore.test.ts src/shared/components/agent/clientTools.test.ts src/shared/components/agent/agentContext.test.ts src/shared/utils/ollamaHealth.test.ts src/shared/utils/notification.test.ts src/shared/utils/agentConversations.test.ts electron/main/artifact-registry-service.test.ts electron/main/asset-thumbnail-cache.test.ts electron/main/extension-path-guard.test.ts electron/main/storage-directory-guard.test.ts electron/main/storage-ownership.test.ts electron/main/startup-error.test.ts electron/main/api-port.test.ts electron/main/api-guard.test.ts electron/main/agent-conversations.test.ts electron/main/gpu-memory.test.ts electron/preload/artifact-registry-preload.test.ts src/shared/stores/meshHistory.test.ts src/areas/generate/meshEditPanel.test.ts src/areas/generate/sculpt/SculptMesh.test.ts src/areas/generate/sculpt/SculptMesh.perf.test.ts src/areas/generate/sculpt/sculptLogic.test.ts src/shared/pages/pageRegistry.test.ts src/shared/pages/startPage.test.ts src/areas/home/recents.test.ts src/areas/workflows/workflowRunRecord.test.ts src/areas/queue/queueModel.test.ts electron/main/workspace-images.test.ts src/areas/image-studio/imageStudioStore.test.ts src/areas/image-studio/imageOps.test.ts src/areas/image-studio/cropGeometry.test.ts src/shared/utils/imageInput.test.ts src/areas/print/printBed.test.ts src/shared/three/viewScale.test.ts src/areas/workflows/nodes/mesh-exporter/obj.test.ts && node --test electron/main/*.test.mjs src/**/*.test.mjs", + "test:node": "node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs src/shared/types/assetLibrary.test.ts src/areas/generate/assetLibraryProjection.test.ts src/areas/generate/assetLibraryService.test.ts src/areas/generate/assetLibraryUi.test.ts src/areas/library/libraryView.test.ts src/areas/library/gridWindow.test.ts src/areas/generate/orcaSlicerLink.test.ts src/shared/utils/agentStream.test.ts src/shared/thumbnails/assetThumbnailQueue.test.ts src/shared/thumbnails/assetThumbnailStore.test.ts src/shared/components/agent/clientTools.test.ts src/shared/components/agent/agentContext.test.ts src/shared/utils/ollamaHealth.test.ts src/shared/utils/notification.test.ts src/shared/utils/agentConversations.test.ts electron/main/artifact-registry-service.test.ts electron/main/asset-thumbnail-cache.test.ts electron/main/extension-path-guard.test.ts electron/main/storage-directory-guard.test.ts electron/main/storage-ownership.test.ts electron/main/startup-error.test.ts electron/main/api-port.test.ts electron/main/api-guard.test.ts electron/main/agent-conversations.test.ts electron/main/gpu-memory.test.ts electron/preload/artifact-registry-preload.test.ts src/shared/stores/meshHistory.test.ts src/areas/generate/meshEditPanel.test.ts src/areas/generate/sculpt/SculptMesh.test.ts src/areas/generate/sculpt/SculptMesh.perf.test.ts src/areas/generate/sculpt/sculptLogic.test.ts src/shared/pages/pageRegistry.test.ts src/shared/pages/startPage.test.ts src/areas/home/recents.test.ts src/areas/workflows/workflowRunRecord.test.ts src/areas/queue/queueModel.test.ts electron/main/workspace-images.test.ts src/areas/image-studio/imageStudioStore.test.ts src/areas/image-studio/imageOps.test.ts src/areas/image-studio/cropGeometry.test.ts src/areas/generate/components/logoLoaderGeometry.test.ts src/areas/generate/components/logoLoaderMotion.test.ts src/shared/utils/imageInput.test.ts src/areas/print/printBed.test.ts src/shared/three/viewScale.test.ts src/areas/workflows/nodes/mesh-exporter/obj.test.ts && node --test electron/main/*.test.mjs src/**/*.test.mjs", "package": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false npm run build && npm run prepare-resources && electron-builder", "package:mac": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false npm run build && npm run prepare-resources && electron-builder --mac --arm64", "lint": "eslint ." diff --git a/src/areas/generate/GeneratePage.tsx b/src/areas/generate/GeneratePage.tsx index 819009f6..ee5def6a 100644 --- a/src/areas/generate/GeneratePage.tsx +++ b/src/areas/generate/GeneratePage.tsx @@ -7,6 +7,7 @@ import { redoDepth, undoDepth } from '@shared/stores/meshHistory' import { useApi } from '@shared/hooks/useApi' import { ColorPicker } from '@shared/components/ui' import GenerationHUD from './components/GenerationHUD' +import GenerationLogoLoader from './components/GenerationLogoLoader' import Viewer3D from './components/Viewer3D' import WorkflowPanel from './components/WorkflowPanel' import EditPanel from './components/EditPanel' @@ -1359,6 +1360,7 @@ export default function GeneratePage(): JSX.Element { onSelectPointLight={handleSelectPointLight} onPointLightsChange={setPointLights} /> + {editPanelOpen && { void closeEditPanel() }} />} diff --git a/src/areas/generate/components/GenerationLogoLoader.tsx b/src/areas/generate/components/GenerationLogoLoader.tsx new file mode 100644 index 00000000..8dc95b31 --- /dev/null +++ b/src/areas/generate/components/GenerationLogoLoader.tsx @@ -0,0 +1,349 @@ +import { useEffect, useMemo, useRef, useState } from 'react' +import * as THREE from 'three' +import { Canvas, useFrame, useThree, type ThreeEvent } from '@react-three/fiber' +import { useAppStore } from '@shared/stores/appStore' +import { MODLY_LOGO_PATHS } from '@shared/components/ui/modlyLogoPaths' +import { buildLogoPieces, pieceDirection, uniqueEdges, type LogoPiece, type Vec2 } from './logoLoaderGeometry' +import { flightPose, trailSample } from './logoLoaderMotion' + +// ─── Tuning ───────────────────────────────────────────────────────────────── + +const LOGO_SIZE = 2.1 // world units across the logo's largest side +const MESH_SPACING = 0.17 // target triangle edge length (the low-poly grain) +const DEPTH = 0.14 // extrusion thickness +const FLY_DISTANCE = 0.6 // how far a clicked piece travels outward +const FLY_LIFT = 0.35 // and how far it comes toward the camera +const FLY_TILT = 0.55 // radians of tilt at the far point +const TRAIL_POINTS = 20 // outline samples that shed trail particles +const TRAIL_STEPS = 7 // particles per sample, each further back in time +const TRAIL_LAG_MS = 38 +const SPIN_SPEED = 0.4 // rad/s idle rotation +const SPIN_SPEED_HOVER = 0.1 +const FADE_MS = 450 + +const VIOLET_DEEP = new THREE.Color('#7e22ce') +const VIOLET = new THREE.Color('#9333ea') +const VIOLET_LIGHT = new THREE.Color('#c084fc') +const LILAC = new THREE.Color('#e9d5ff') + +// ─── Per-piece GPU resources ──────────────────────────────────────────────── + +interface PieceResources { + piece: LogoPiece + dir: Vec2 + face: THREE.BufferGeometry + inner: THREE.BufferGeometry + outline: THREE.BufferGeometry + dots: THREE.BufferGeometry + trail: THREE.BufferGeometry + /** Piece-local XY of the outline samples that emit trail particles. */ + trailOrigins: Vec2[] + faceMat: THREE.MeshBasicMaterial + innerMat: THREE.LineBasicMaterial + outlineMat: THREE.LineBasicMaterial + dotsMat: THREE.PointsMaterial + trailMat: THREE.PointsMaterial +} + +function additive(mat: T): T { + mat.transparent = true + mat.depthWrite = false + mat.blending = THREE.AdditiveBlending + return mat +} + +function buildPieceResources(piece: LogoPiece, dotTexture: THREE.Texture): PieceResources { + const { vertices, triangles, boundaryCount: b } = piece + const n = vertices.length + const h = DEPTH / 2 + + // Closed slab: front face, back face, and side walls along the outline. + const pos = new Float32Array(n * 2 * 3) + vertices.forEach((v, k) => { + pos.set([v.x, v.y, h], k * 3) + pos.set([v.x, v.y, -h], (k + n) * 3) + }) + const index: number[] = [] + for (const [a, c, d] of triangles) index.push(a, c, d, a + n, d + n, c + n) + for (let i = 0; i < b; i++) { + const j = (i + 1) % b + index.push(i, j + n, j, i, i + n, j + n) + } + const face = new THREE.BufferGeometry() + face.setAttribute('position', new THREE.BufferAttribute(pos, 3)) + face.setIndex(index) + face.computeBoundingSphere() + + // Inner triangulation on both faces, plus the ribs joining front and back. + const isOutlineEdge = (u: number, v: number): boolean => + u < b && v < b && (Math.abs(u - v) === 1 || Math.abs(u - v) === b - 1) + const innerPts: number[] = [] + for (const [u, v] of uniqueEdges(triangles)) { + if (isOutlineEdge(u, v)) continue + for (const z of [h, -h]) innerPts.push(vertices[u]!.x, vertices[u]!.y, z, vertices[v]!.x, vertices[v]!.y, z) + } + for (let i = 0; i < b; i++) innerPts.push(vertices[i]!.x, vertices[i]!.y, h, vertices[i]!.x, vertices[i]!.y, -h) + const inner = new THREE.BufferGeometry() + inner.setAttribute('position', new THREE.Float32BufferAttribute(innerPts, 3)) + + // Crisp outline on both faces. + const outlinePts: number[] = [] + for (const z of [h, -h]) { + for (let i = 0; i < b; i++) { + const p = vertices[i]!, q = vertices[(i + 1) % b]! + outlinePts.push(p.x, p.y, z, q.x, q.y, z) + } + } + const outline = new THREE.BufferGeometry() + outline.setAttribute('position', new THREE.Float32BufferAttribute(outlinePts, 3)) + + // Vertex dots on both faces. + const dotPts: number[] = [] + for (const z of [h, -h]) vertices.forEach((v) => dotPts.push(v.x, v.y, z)) + const dots = new THREE.BufferGeometry() + dots.setAttribute('position', new THREE.Float32BufferAttribute(dotPts, 3)) + + // Trail: positions and colors are rewritten every frame while the piece flies. + const trailOrigins: Vec2[] = [] + const stride = Math.max(1, Math.floor(b / TRAIL_POINTS)) + for (let i = 0; i < b && trailOrigins.length < TRAIL_POINTS; i += stride) trailOrigins.push(vertices[i]!) + const trailCount = trailOrigins.length * TRAIL_STEPS + const trail = new THREE.BufferGeometry() + trail.setAttribute('position', new THREE.BufferAttribute(new Float32Array(trailCount * 3), 3)) + trail.setAttribute('color', new THREE.BufferAttribute(new Float32Array(trailCount * 3), 3)) + + return { + piece, + dir: pieceDirection(piece.center, { x: 0, y: 0 }), + face, inner, outline, dots, trail, trailOrigins, + faceMat: additive(new THREE.MeshBasicMaterial({ color: VIOLET_DEEP, opacity: 0.07, side: THREE.DoubleSide })), + innerMat: additive(new THREE.LineBasicMaterial({ color: VIOLET_LIGHT, opacity: 0.4 })), + outlineMat: additive(new THREE.LineBasicMaterial({ color: LILAC, opacity: 0.85 })), + dotsMat: additive(new THREE.PointsMaterial({ color: LILAC, map: dotTexture, size: 0.05, opacity: 0.9, sizeAttenuation: true })), + trailMat: additive(new THREE.PointsMaterial({ map: dotTexture, size: 0.055, vertexColors: true, sizeAttenuation: true })), + } +} + +function disposePieceResources(r: PieceResources): void { + for (const g of [r.face, r.inner, r.outline, r.dots, r.trail]) g.dispose() + for (const m of [r.faceMat, r.innerMat, r.outlineMat, r.dotsMat, r.trailMat]) m.dispose() +} + +function makeDotTexture(): THREE.Texture { + const size = 64 + const canvas = document.createElement('canvas') + canvas.width = canvas.height = size + const ctx = canvas.getContext('2d')! + const g = ctx.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2) + g.addColorStop(0, 'rgba(255,255,255,1)') + g.addColorStop(0.35, 'rgba(255,255,255,0.85)') + g.addColorStop(1, 'rgba(255,255,255,0)') + ctx.fillStyle = g + ctx.fillRect(0, 0, size, size) + const tex = new THREE.CanvasTexture(canvas) + tex.colorSpace = THREE.SRGBColorSpace + return tex +} + +/** Deterministic jitter in [-1, 1) so trail particles scatter the same way every flight. */ +function jitter(i: number, k: number, axis: number): number { + const s = Math.sin(i * 12.9898 + k * 78.233 + axis * 37.719) * 43758.5453 + return (s - Math.floor(s)) * 2 - 1 +} + +// ─── Scene ────────────────────────────────────────────────────────────────── + +interface SceneProps { + hovered: number | null + onHover: (index: number | null) => void + reducedMotion: boolean +} + +function LogoScene({ hovered, onHover, reducedMotion }: SceneProps): JSX.Element { + const resources = useMemo(() => { + const dotTexture = makeDotTexture() + const pieces = buildLogoPieces(MODLY_LOGO_PATHS, LOGO_SIZE, MESH_SPACING) + return { dotTexture, pieces: pieces.map((p) => buildPieceResources(p, dotTexture)) } + }, []) + useEffect(() => () => { + resources.pieces.forEach(disposePieceResources) + resources.dotTexture.dispose() + }, [resources]) + + const clock = useThree((s) => s.clock) + const logoRef = useRef(null) + const pieceRefs = useRef<(THREE.Group | null)[]>([]) + const flightStart = useRef<(number | null)[]>(resources.pieces.map(() => null)) + const spin = useRef(SPIN_SPEED) + const hoveredRef = useRef(hovered) + hoveredRef.current = hovered + + const axis = useMemo(() => new THREE.Vector3(), []) + const color = useMemo(() => new THREE.Color(), []) + + useFrame((state, dt) => { + const now = state.clock.elapsedTime * 1000 + const ease = 1 - Math.exp(-dt * 12) + const logo = logoRef.current + if (logo) { + if (reducedMotion) { + logo.rotation.set(-0.12, -0.45, 0) + logo.position.y = 0.12 + } else { + spin.current += ((hoveredRef.current === null ? SPIN_SPEED : SPIN_SPEED_HOVER) - spin.current) * (1 - Math.exp(-dt * 3)) + logo.rotation.y += spin.current * dt + logo.rotation.x = -0.12 + logo.position.y = 0.12 + Math.sin(state.clock.elapsedTime * 0.9) * 0.04 + } + } + + resources.pieces.forEach((r, i) => { + const group = pieceRefs.current[i] + if (!group) return + const start = flightStart.current[i] + const elapsed = start === null ? -1 : now - start + const pose = flightPose(elapsed) + if (start !== null && !pose.inFlight) flightStart.current[i] = null + + const { center } = r.piece + group.position.set( + center.x + r.dir.x * FLY_DISTANCE * pose.offset, + center.y + r.dir.y * FLY_DISTANCE * pose.offset, + FLY_LIFT * pose.offset, + ) + axis.set(-r.dir.y, r.dir.x, 0) + group.quaternion.setFromAxisAngle(axis, -FLY_TILT * pose.tilt) + group.scale.setScalar(pose.scale) + + const hot = hoveredRef.current === i ? 1 : 0 + const lit = Math.min(1, hot + pose.flash * 0.8) + r.faceMat.opacity += (0.07 + 0.24 * lit - r.faceMat.opacity) * ease + r.faceMat.color.lerp(color.lerpColors(VIOLET_DEEP, VIOLET, lit), ease) + r.innerMat.opacity += (0.4 + 0.45 * lit - r.innerMat.opacity) * ease + r.outlineMat.opacity += (0.85 + 0.15 * lit - r.outlineMat.opacity) * ease + r.dotsMat.size += (0.05 + 0.02 * lit - r.dotsMat.size) * ease + + // Trail particles, in logo space, lagging behind the flying piece. + const posAttr = r.trail.getAttribute('position') as THREE.BufferAttribute + const colAttr = r.trail.getAttribute('color') as THREE.BufferAttribute + const visible = start !== null + r.trailMat.visible = visible + if (!visible) return + let p = 0 + for (let s = 0; s < r.trailOrigins.length; s++) { + const o = r.trailOrigins[s]! + for (let k = 1; k <= TRAIL_STEPS; k++, p++) { + const sample = trailSample(elapsed, k * TRAIL_LAG_MS) + const spread = 0.012 * k + posAttr.setXYZ( + p, + center.x + o.x + r.dir.x * FLY_DISTANCE * sample.offset + jitter(s, k, 0) * spread, + center.y + o.y + r.dir.y * FLY_DISTANCE * sample.offset + jitter(s, k, 1) * spread, + FLY_LIFT * sample.offset + jitter(s, k, 2) * spread, + ) + const a = sample.alpha * (1 - (k - 1) / TRAIL_STEPS) + colAttr.setXYZ(p, VIOLET_LIGHT.r * a, VIOLET_LIGHT.g * a, VIOLET_LIGHT.b * a) + } + } + posAttr.needsUpdate = true + colAttr.needsUpdate = true + }) + }) + + function handleClick(i: number, e: ThreeEvent): void { + e.stopPropagation() + if (reducedMotion || flightStart.current[i] !== null) return + flightStart.current[i] = clock.elapsedTime * 1000 + } + + return ( + + {resources.pieces.map((r, i) => ( + + { pieceRefs.current[i] = g }}> + { e.stopPropagation(); onHover(i) }} + onPointerOut={() => { if (hoveredRef.current === i) onHover(null) }} + onClick={(e) => handleClick(i, e)} + /> + + + + + + + ))} + + ) +} + +// ─── Overlay ──────────────────────────────────────────────────────────────── + +function usePrefersReducedMotion(): boolean { + const [reduced, setReduced] = useState(() => window.matchMedia('(prefers-reduced-motion: reduce)').matches) + useEffect(() => { + const mq = window.matchMedia('(prefers-reduced-motion: reduce)') + const update = (): void => setReduced(mq.matches) + mq.addEventListener('change', update) + return () => mq.removeEventListener('change', update) + }, []) + return reduced +} + +/** + * Playful 3D Modly logo shown over the Generate viewer while a mesh is being + * generated. Hover lights a piece up; a click sends it flying and back. + */ +export default function GenerationLogoLoader(): JSX.Element | null { + const status = useAppStore((s) => s.currentJob?.status) + const active = status === 'uploading' || status === 'generating' + const [mounted, setMounted] = useState(active) + const [shown, setShown] = useState(false) + const [hovered, setHovered] = useState(null) + const reducedMotion = usePrefersReducedMotion() + + useEffect(() => { + if (active) { + setMounted(true) + // Two frames so the transparent state is painted before fading in. + let id = requestAnimationFrame(() => { id = requestAnimationFrame(() => setShown(true)) }) + return () => cancelAnimationFrame(id) + } + setShown(false) + const id = setTimeout(() => { setMounted(false); setHovered(null) }, FADE_MS) + return () => clearTimeout(id) + }, [active]) + + if (!mounted) return null + + return ( +