图像助手
- 作者仓库星标 29
- 许可证 MIT
- 作者更新于 实时读取
- 作者仓库 r3f-gamedev
- 领域
- 通用
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 94 / 100 · 已通过审计
- 作者 / 版本 / 许可
- @verekia · MIT
- Token 消耗评级
- 中等消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 底层运行要求
- 无特殊要求
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: verekia-architecture
description: Day-to-day coding style and patterns for R3F game development with Miniplex ECS. The core princi…
category: 通用
runtime: 无特殊运行时
---
# verekia-architecture 输出预览
## PART A: 任务判断
- 适用问题:通用任务拆解、检查和交付。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Systems vs Views / Headless-First Mindset / Miniplex: What NOT to Use”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于通用任务拆解、检查和交付,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Systems vs Views / Headless-First Mindset / Miniplex: What NOT to Use”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“Systems vs Views / Headless-First Mindset / Miniplex: What NOT to Use”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: verekia-architecture
description: Day-to-day coding style and patterns for R3F game development with Miniplex ECS. The core princi…
category: 通用
source: verekia/r3f-gamedev
---
# verekia-architecture
## 什么时候使用
- 把通用方向的常用动作沉淀成 Agent 可调用的技能 适合处理通用任务拆解、检查、交付和复盘,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步骤;通常不需要额外…
- 面向通用任务拆解、检查和交付,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Systems vs Views / Headless-First Mindset / Miniplex: What NOT to Use」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "verekia-architecture" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Systems vs Views / Headless-First Mindset / Miniplex: What NOT to Use
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> 无特殊运行时 | 读取文件、写入/修改文件、执行终端命令 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Architecture
The core principle of R3F game development is separating game logic from rendering. React components are views, not the source of truth.
Systems vs Views
Systems contain all game logic:
- Movement, physics, collision detection
- Spawning and destroying entities
- State mutations (health, score, timers)
- AI and behavior
- Syncing Three.js objects with entity state
Views (React components) only render:
<PlayerEntity>,<EnemyEntity>wrap models withModelContainer, process any data needed and pass it as props to the model<PlayerModel>,<EnemyModel>are dumb and only render meshes via props- They don't contain core game logic, just visuals logic
- No
useFramein view components unless it is purely visual and should not be part of the core logic
Headless-First Mindset
Games should be capable of running entirely without a renderer:
┌─────────────────────────────────────────┐
│ Game Logic Layer │
│ (Systems, ECS, World State, Entities) │
└─────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ View Layer (optional) │
│ React Three Fiber / DOM / Headless │
└─────────────────────────────────────────┘
This means:
- All state lives in the world/ECS, not in React components
- Systems iterate over entities and mutate state
- Views subscribe to state and render accordingly
- You could swap R3F for DOM elements or run tests headlessly
Miniplex: What NOT to Use
From miniplex-react:
ECS.Entity- Don't use this componentECS.Component- Don't use this componentECS.world- Don't access world through ECS, use direct importuseEntitieshook - Don't use this- Render props pattern - Don't use this
From miniplex core:
onEntityAdded/onEntityRemoved- Prefer using data and systems to trigger things (e.g., timers, flags).where()- Don't use predicate-based filtering, prefer iterating over all entities that have the component no matter its value. For example iterate over all entities that have health and filter out entities that have health < 0 in the system rather than querying entities where health < 0 (which would require reindexing).
Miniplex: Preferred Methods
Only use these:
world.add(entity)- Add a new entityworld.remove(entity)- Remove an entityworld.addComponent(entity, 'component', value)- Add component to existing entityworld.removeComponent(entity, 'component')- Remove component from entityworld.with('prop1', 'prop2')- Create queriescreateReactAPI(world)- GetEntitiescomponent for rendering
Entity Types and Queries
// lib/ecs.ts
import { World } from 'miniplex'
import createReactAPI from 'miniplex-react'
type Entity = {
position?: { x: number; y: number; z: number }
velocity?: { x: number; y: number; z: number }
isCharacter?: true
isEnemy?: true
three?: Object3D | null
}
export const world = new World<Entity>()
export const characterQuery = world.with('position', 'isCharacter', 'three')
export type CharacterEntity = (typeof characterQuery)['entities'][number]
// Only destructure Entities from React API
export const { Entities } = createReactAPI(world)
ModelContainer Pattern
Capture Three.js object references on entities using a wrapper component, allowing systems to manipulate objects directly.
Similar to the Redux container/component pattern:
*Entitycomponents are smart wrappers that connect entity data to the view*Modelcomponents are dumb and only responsible for rendering
┌─────────────────────────────────────────┐
│ PlayerEntity (smart) │
│ - Wraps with ModelContainer │
│ - Passes entity data as props │
│ │
│ ┌─────────────────────────────────┐ │
│ │ PlayerModel (dumb) │ │
│ │ - Pure rendering │ │
│ │ - Receives props │ │
│ │ - No knowledge of entities │ │
│ └─────────────────────────────────┘ │
└─────────────────────────────────────────┘
- Ref callback stores the Three.js object on the entity
- Cleanup function removes the reference when unmounted
- Systems access
entity.threedirectly inuseFrame - Models are reusable and testable in isolation
Entity as Props Pattern
The component passed to <Entities> receives the entity directly as props:
// Dumb component - only renders, no entity knowledge
const CharacterModel = () => (
<mesh>
<sphereGeometry />
<meshBasicMaterial color="blue" />
</mesh>
)
// Smart wrapper - connects entity to model via ModelContainer
const CharacterEntity = (entity: CharacterEntity) => (
<ModelContainer entity={entity}>
<CharacterModel />
</ModelContainer>
)
// entities/entities.tsx (contains <Entities> for all renderable entities)
const isCharacterQuery = world.with('isCharacter')
export const CharacterEntities = () => <Entities in={isCharacterQuery}>{CharacterEntity}</Entities>
Systems and Queries
Query Placement
Define queries near where they are used (in the system file), not in a central file. But define them outside the loop at module scope:
import { world } from '@/lib/ecs'
// ✅ Query defined at module scope, near where it's used
const movingEntities = world.with('position', 'velocity')
type MovingEntity = (typeof movingEntities)['entities'][number]
One + System Pattern
Split logic into a "One" function (operates on a single entity) and the system (iterates and calls One):
import { world } from '@/lib/ecs'
// Query at module scope
const movingEntities = world.with('position', 'velocity')
type MovingEntity = (typeof movingEntities)['entities'][number]
// "One" function - single entity logic, easy to test
const velocityOne = (e: MovingEntity, dt: number) => {
e.position.x += e.velocity.x * dt
e.position.y += e.velocity.y * dt
e.position.z += e.velocity.z * dt
}
// System - just iteration
export const VelocitySystem = () => {
useFrame((_, dt) => {
for (const e of movingEntities) {
velocityOne(e, dt)
}
})
return null
}
Query by Components, Not Types
Systems must iterate over queries tailored to their specific needs, not over entity types:
// ✅ GOOD - Query targets entities with the components the system needs
const entitiesWithVelocity = world.with('position', 'velocity')
const VelocitySystem = () => {
useFrame((_, delta) => {
for (const entity of entitiesWithVelocity) {
entity.position.x += entity.velocity.x * delta
}
})
return null
}
// ❌ BAD - Iterating over specific entity types
const VelocitySystem = () => {
useFrame((_, delta) => {
for (const player of players) {
/* ... */
}
for (const enemy of enemies) {
/* ... */
}
for (const projectile of projectiles) {
/* ... */
}
})
return null
}
The point of an ECS is that systems operate on a subset of entities matching exactly what they need. A VelocitySystem targets entities with velocity, not "players + enemies + projectiles".
ThreeSystem - Syncing Three.js
const threeEntities = world.with('position', 'three')
type ThreeEntity = (typeof threeEntities)['entities'][number]
const threeOne = (e: ThreeEntity) => {
e.three.position.set(e.position.x, e.position.y, e.position.z)
}
export const ThreeSystem = () => {
useFrame(() => {
for (const e of threeEntities) {
threeOne(e)
}
})
return null
}
Spawning Entities
const SpawnSystem = () => {
useEffect(() => {
world.add({ position: { x: 0, y: 0, z: 0 }, isCharacter: true })
}, [])
return null
}
Zustand Store Usage
Zustand stores are for state that doesn't belong in the ECS. Each store has a consistent API pattern:
// In React components (reactive)
const areSettingsOpen = useUI('areSettingsOpen')
// Outside React / in systems (non-reactive)
const settings = getUI().areSettingsOpen
// Setting values
setUI('areSettingsOpen', true)
setUI({ areSettingsOpen: true, debug: { drawCalls: 100 } })
// Reset to defaults
resetUI()
use*hooks for reactive access in React componentsget*for non-reactive access in systems or callbacksset*supports both single key-value and partial state updatesreset*restores default state- Attach
get*towindowfor debugging in browser console - Use
structuredClone(defaultState)to avoid mutation issues
Key Principles
- R3F imports from WebGPU entry: Always import from
@react-three/fiber/webgpu, not@react-three/fiber - No
useFramein view components: MostuseFramecalls belong in systems - Entity/Model separation:
*Entitycomponents are smart wrappers,*Modelcomponents are dumb renderers - Systems sync Three.js: Systems update both entity state AND
entity.threepositions/rotations - Decouple completely: The game should work if you delete all view components
- Query by components, not types: Systems iterate over queries based on required components
- World and queries are plain module exports: Not React context
<Entities>is the only React bridge: Only use this from miniplex-react- Derive typed entities from queries:
(typeof query)['entities'][number] - Define queries near where they're used: In the system file, at module scope
- Split system logic: "One" function for single entity, System for iteration
This skill is part of verekia's r3f-gamedev.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核