Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

r3f-scene

БесплатноБез исполняемых скриптовНе проверен

Build one React Three Fiber scene that loads late, stops rendering off-screen, holds a designed still under reduced motion, and falls back to a poster without…

frankxaiот frankxai★ 51 звезда на GitHub

Об этом скилле

R3F scene

A 3D scene is the most expensive surface a page can carry: about 244 kB of JavaScript transferred before the first model, and a render loop that runs until something stops it. This skill builds the scene so the cost is paid late and only while someone is looking.

Run gpu-surface section 1 first. The job sentence must need depth: an object turned in the hand, a space moved through, a structure whose shape is the point. A flat field of colour is a shader-backdrop.

1. Before installing

  • node .claude/skills/web-steward/peer-check.mjs --root . As of 2026-11-12, @react-three/[email protected] declares react >=19 <19.4 and @react-three/[email protected] declares react ^19. A repo on React 18 with R3F 9 installed has an unmet peer: fix that first.
  • three, @react-three/fiber, and @types/three move together. Pin them.
  • Add @react-three/drei only for a helper the scene uses. Add postprocessing only when the job sentence names the effect.

2. Build

use-surface.ts is in gpu-surface section 3.

// components/effects/SceneLayer.tsx
'use client'

import { Canvas, useFrame } from '@react-three/fiber'
import { useRef, type ReactNode } from 'react'
import type { Mesh } from 'three'

type SceneLayerProps = {
  /** Animate only while true: on screen and motion allowed. */
  running: boolean
  children: ReactNode
}

// The only file that imports three or @react-three/*: the whole 3D stack stays in this chunk.
export default function SceneLayer({ running, children }: SceneLayerProps) {
  return (
    <Canvas
      aria-hidden
      dpr={[1, 1.5]}
      frameloop={running ? 'always' : 'demand'}
      camera={{ position: [0, 0, 4.2], fov: 40 }}
      gl={{ antialias: true, alpha: true, powerPreference: 'default' }}
      style={{ position: 'absolute', inset: 0 }}
    >
      {children}
    </Canvas>
  )
}

/** A scene takes time as a value, so the still is a moment someone chose. */
export function Knot({ color, running, stillTime }: { color: string; running: boolean; stillTime: number }) {
  const mesh = useRef<Mesh>(null)
  useFrame(({ clock }) => {
    const t = running ? stillTime + clock.elapsedTime : stillTime
    if (!mesh.current) return
    mesh.current.rotation.x = t * 0.25
    mesh.current.rotation.y = t * 0.4
  })
  return (
    <>
      <ambientLight intensity={0.6} />
      <directionalLight position={[3, 4, 5]} intensity={2.2} />
      <mesh ref={mesh}>
        <torusKnotGeometry args={[0.9, 0.3, 160, 24]} />
        <meshStandardMaterial color={color} metalness={0.85} roughness={0.25} />
      </mesh>
    </>
  )
}
// components/effects/SceneSurface.tsx
'use client'

import dynamic from 'next/dynamic'
import { useEffect, useRef, useState, type ReactNode } from 'react'
import { useGpu, useReducedMotion } from './use-surface'

const SceneLayer = dynamic(() => import('./SceneLayer'), { ssr: false })
const Knot = dynamic(() => import('./SceneLayer').then((m) => m.Knot), { ssr: false })

type SceneSurfaceProps = {
  /** Painted before and without WebGL: an image of the still, or a token gradient. */
  poster: string
  /** Seconds into the motion. The reduced-motion render, and where the motion starts. */
  stillTime: number
  color: string
  className?: string
  children?: ReactNode
}

export function SceneSurface({ poster, stillTime, color, className = '', children }: SceneSurfaceProps) {
  const reduced = useReducedMotion()
  const gpu = useGpu()
  const box = useRef<HTMLDivElement>(null)
  const [onScreen, setOnScreen] = useState(false)

  // R3F keeps rendering off-screen. This stops the loop when the surface leaves the viewport.
  useEffect(() => {
    const node = box.current
    if (!node) return
    const observer = new IntersectionObserver(([entry]) => setOnScreen(entry.isIntersecting))
    observer.observe(node)
    return () => observer.disconnect()
  }, [])

  const running = onScreen && !reduced

  return (
    <div ref={box} className={className} style={{ position: 'relative', isolation: 'isolate', overflow: 'hidden', background: poster }}>
      {gpu && (
        <div style={{ position: 'absolute', inset: 0, zIndex: -1 }}>
          <SceneLayer running={running}>
            <Knot color={color} running={running} stillTime={stillTime} />
          </SceneLayer>
        </div>
      )}
      {children}
    </div>
  )
}

Knot stands in for the scene. Replace it and keep its three rules.

Measured in headless Chromium: the scene rendered 18 frames a second on screen (software rendering), 0 after it scrolled out of view, and resumed on return. Under reduced motion it rendered 3 frames in total and stopped. Zero console errors in the moving, reduced-motion, and no-WebGL states.

3. The three rules of a scene component

  1. Time is a value. Derive every animated property from t, as Knot does. Then stillTime is a moment someone chose, and the reduced-motion render is exactly that moment.
  2. running decides. frameloop
Полный SKILL.md на GitHub

Установить r3f-scene в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл r3f-scene?

Build one React Three Fiber scene that loads late, stops rendering off-screen, holds a designed still under reduced motion, and falls back to a poster without WebGL. Use when a page needs real geometry, a camera, lights, a model, or 3D interaction; when someone shares three.js, react-three-fiber, drei, or Three.js Journey material and asks for the effect; or when reviewing or repairing an existing <Canvas> for cost. Starts and ends in gpu-surface.

Как установить скилл r3f-scene?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл r3f-scene запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить r3f-scene с