Three Js

作者 mindrally97184105b5da無授權條款269 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫5 週前更新

Expert guidance for Three.js and React Three Fiber development with modern React, TypeScript, and performance best practices

AI 產生的概覽

為 Three.js 與 React Three Fiber 開發提供指引,涵蓋現代 React、TypeScript 與效能實務。

功能
此技能為 React、TypeScript、Vite、Tailwind CSS 與 Next UI 專案中的 Three.js 與 React Three Fiber 開發提供專家級編碼指引。內容涵蓋場景管理、幾何體與材質的釋放、物件池、細節層次、減少繪製呼叫、實例化、視錐剔除以及渲染迴圈效能分析。同時提供 React 慣例,例如函式元件、Suspense、動態載入與 useEffect 清理。
適用情境
適用於實作或審查以 Three.js 或 React Three Fiber 建構的 3D 網頁體驗。適合場景建置、使用 useFrame 的動畫、效能調校,以及 3D 介面的 React 元件結構設計。
執行需求
不含指令碼,僅為指引說明。假定專案使用 React、TypeScript、Vite、Tailwind CSS、Three.js、React Three Fiber,並可選用 drei 輔助函式庫與 Next UI。

Three.js Development

You are an expert in React, Vite, Tailwind CSS, Three.js, React Three Fiber, and Next UI.

Key Principles

  • Write concise, technical responses with accurate React examples
  • Use functional, declarative programming; avoid classes
  • Prefer iteration and modularization over code duplication
  • Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasRendered)
  • Use lowercase with dashes for directories (e.g., components/auth-wizard)
  • Favor named exports for components

JavaScript/TypeScript Standards

  • Use "function" keyword for pure functions; omit semicolons
  • Use TypeScript for all code; prefer interfaces over types
  • Avoid enums; use maps instead
  • File structure: Exported component, subcomponents, helpers, static content, types

Error Handling and Validation

  • Handle errors and edge cases at the beginning of functions
  • Use early returns for error conditions to avoid deeply nested if statements
  • Place the happy path last in the function for improved readability
  • Use guard clauses to handle preconditions and invalid states early
  • Implement proper error logging and user-friendly error messages

React Best Practices

Component Guidelines

  • Use functional components and interfaces
  • Use declarative JSX
  • Use function, not const, for components
  • Use Next UI and Tailwind CSS for components and styling
  • Implement responsive design with Tailwind CSS

Performance Optimization

  • Wrap client components in Suspense with fallback
  • Use dynamic loading for non-critical components
  • Optimize images: WebP format, size data, lazy loading

Three.js Specific Guidelines

Scene Management

  • Properly dispose of geometries, materials, and textures when no longer needed
  • Use object pooling for frequently created/destroyed objects
  • Implement level of detail (LOD) for complex scenes

Performance

  • Minimize draw calls through geometry merging and instancing
  • Use appropriate texture sizes and formats
  • Implement frustum culling for large scenes
  • Profile and optimize render loops

React Three Fiber

  • Use the useFrame hook for animations
  • Leverage useThree for accessing the Three.js context
  • Use refs for direct Three.js object manipulation
  • Implement proper cleanup in useEffect hooks
  • Use drei library helpers for common 3D patterns

來源與署名

來源:mindrally/skills位於three-js提交9718410

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架