Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

docs: add custom draw, geometry, post-processing, and editor extensions guides

esengine18defc485994
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjs
index b2b86604d..ef4f3445c 100644
--- a/docs/astro/astro.config.mjs
+++ b/docs/astro/astro.config.mjs
@@ -66,12 +66,16 @@ export default defineConfig({
{ label: 'Overview', translations: { 'zh-CN': '概览' }, slug: 'guides/rendering' },
{ label: 'Sprite', translations: { 'zh-CN': '精灵' }, slug: 'guides/sprite' },
{ label: 'Spine Animation', translations: { 'zh-CN': 'Spine 动画' }, slug: 'guides/spine' },
+ { label: 'Custom Draw', translations: { 'zh-CN': '自定义绘制' }, slug: 'guides/custom-draw' },
+ { label: 'Post-Processing', translations: { 'zh-CN': '后处理效果' }, slug: 'guides/post-processing' },
],
},
{ label: 'Input Handling', translations: { 'zh-CN': '输入处理' }, slug: 'guides/input' },
{ label: 'UI & Text', translations: { 'zh-CN': 'UI 与文本' }, slug: 'guides/ui' },
{ label: 'Asset Loading', translations: { 'zh-CN': '资源加载' }, slug: 'guides/assets' },
{ label: 'Materials & Shaders', translations: { 'zh-CN': '材质与着色器' }, slug: 'guides/materials' },
+ { label: 'Geometry & Meshes', translations: { 'zh-CN': '几何体与网格' }, slug: 'guides/geometry' },
+ { label: 'Editor Extensions', translations: { 'zh-CN': '编辑器扩展' }, slug: 'guides/editor-extensions' },
],
},
],
diff --git a/docs/astro/src/content/docs/guides/assets.mdx b/docs/astro/src/content/docs/guides/assets.mdx
index 7a12ed7b4..adca7416c 100644
--- a/docs/astro/src/content/docs/guides/assets.mdx
+++ b/docs/astro/src/content/docs/guides/assets.mdx
@@ -116,7 +116,7 @@ const config = bundle.json.get('assets/config.json');
| Field | Type | Description |
|-------|------|-------------|
| `textures` | string[] | Texture image paths |
-| `materials` | string[] | Material file paths (.material) |
+| `materials` | string[] | Material file paths (.esmaterial) |
| `spine` | SpineDescriptor[] | Spine skeleton/atlas pairs |
| `json` | string[] | JSON file paths |
| `text` | string[] | Text file paths |
@@ -138,11 +138,11 @@ The returned `AssetBundle` contains Maps keyed by path:
## Material Loading
```typescript
-const loaded = await assets.loadMaterial('assets/effects/glow.material');
+const loaded = await assets.loadMaterial('assets/effects/glow.esmaterial');
sprite.material = loaded.handle;
```
-See [Materials & Shaders](/microes/guides/materials/) for the full material API and `.material` file format.
+See [Materials & Shaders](/microes/guides/materials/) for the full material API and `.esmaterial` file format.
## Caching
diff --git a/docs/astro/src/content/docs/guides/custom-draw.mdx b/docs/astro/src/content/docs/guides/custom-draw.mdx
new file mode 100644
index 000000000..bd74ff3a2
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/custom-draw.mdx
@@ -0,0 +1,205 @@
+---
+title: Custom Draw
+description: Immediate-mode 2D drawing API for debug visualization and dynamic graphics
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The Draw API provides immediate-mode 2D drawing primitives. All draw commands are cleared each frame, making it ideal for debug visualization, custom UI overlays, and dynamic graphics.
+
+## Draw Callbacks
+
+Register a draw callback to execute drawing commands each frame. The engine calls your function automatically during the render pass:
+
+```typescript
+import { registerDrawCallback, Draw } from 'esengine';
+
+registerDrawCallback('my-debug', (elapsed) => {
+ Draw.line({ x: 0, y: 0 }, { x: 100, y: 100 }, { x: 1, y: 0, z: 0, w: 1 }, 2);
+});
+```
+
+Remove callbacks when no longer needed:
+
+```typescript
+import { unregisterDrawCallback, clearDrawCallbacks } from 'esengine';
+
+unregisterDrawCallback('my-debug');
+clearDrawCallbacks();
+```
+
+<Aside type="caution">
+ `Draw.begin()` and `Draw.end()` are called internally by the engine. Only use the Draw API inside a registered callback.
+</Aside>
+
+## Drawing Primitives
+
+### Lines
+
+```typescript
+Draw.line(
+ { x: 0, y: 0 }, // from
+ { x: 200, y: 150 }, // to
+ { x: 1, y: 1, z: 0, w: 1 }, // yellow
+ 2 // thickness
+);
+```
+
+### Rectangles
+
+```typescript
+Draw.rect(
+ { x: 100, y: 100 }, // center position
+ { x: 80, y: 60 }, // size
+ { x: 0, y: 0.5, z: 1, w: 0.5 }, // semi-transparent blue
+ true // filled (default)
+);
+
+Draw.rectOutline(
+ { x: 100, y: 100 },
+ { x: 80, y: 60 },
+ { x: 1, y: 0, z: 0, w: 1 }, // red
+ 2 // thickness
+);
+```
+
+### Circles
+
+```typescript
+Draw.circle(
+ { x: 200, y: 200 }, // center
+ 50, // radius
+ { x: 0, y: 1, z: 0, w: 1 }, // green
+ true, // filled
+ 32 // segments
+);
+
+Draw.circleOutline(
+ { x: 200, y: 200 },
+ 50,
+ { x: 1, y: 1, z: 1, w: 1 }, // white
+ 1, // thickness
+ 32 // segments
+);
+```
+
+### Textures
+
+```typescript
+Draw.texture(
+ { x: 300, y: 200 }, // position
+ { x: 64, y: 64 }, // size
+ textureHandle,
+ { x: 1, y: 1, z: 1, w: 1 } // tint (default: white)
+);
+
+Draw.textureRotated(
+ { x: 300, y: 200 },
+ { x: 64, y: 64 },
+ Math.PI / 4, // rotation in radians
+ textureHandle,
+ { x: 1, y: 1, z: 1, w: 1 }
+);
+```
+
+## Primitives Reference
+
+| Method | Parameters | Description |
+|--------|-----------|-------------|
+| `line(from, to, color, thickness?)` | Vec2, Vec2, Color, number=1 | Line segment |
+| `rect(position, size, color, filled?)` | Vec2, Vec2, Color, bool=true | Rectangle |
+| `rectOutline(position, size, color, thickness?)` | Vec2, Vec2, Color, number=1 | Rectangle outline |
+| `circle(center, radius, color, filled?, segments?)` | Vec2, number, Color, bool=true, number=32 | Circle |
+| `circleOutline(center, radius, color, thickness?, segments?)` | Vec2, number, Color, number=1, number=32 | Circle outline |
+| `texture(position, size, textureHandle, tint?)` | Vec2, Vec2, number, Color=white | Textured quad |
+| `textureRotated(position, size, rotation, textureHandle, tint?)` | Vec2, Vec2, number, number, Color=white | Rotated textured quad |
+
+## Render State
+
+Control how subsequent primitives are rendered:
+
+```typescript
+Draw.setLayer(5); // render layer (higher = on top)
+Draw.setDepth(0.5); // depth sorting within a layer
+Draw.setBlendMode(BlendMode.Additive); // blend mode
+Draw.setDepthTest(true); // enable depth testing
+```
+
+| Method | Description |
+|--------|-------------|
+| `setLayer(layer)` | Set render layer index |
+| `setDepth(depth)` | Set depth value for sorting |
+| `setBlendMode(mode)` | Set blend mode (Normal, Additive, Multiply, Screen, PremultipliedAlpha) |
+| `setDepthTest(enabled)` | Enable or disable depth testing |
+
+## Custom Mesh Drawing
+
+For advanced rendering, draw custom geometry with shaders or materials:
+
+```typescript
+import { Geometry, Draw, Material } from 'esengine';
+
+const quad = Geometry.createQuad(100, 100);
+const transform = new Float32Array([
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+]);
+
+Draw.drawMesh(quad, shaderHandle, transform);
+Draw.drawMeshWithMaterial(quad, materialHandle, transform);
+```
+
+`drawMeshWithMaterial` automatically applies the material's blend mode, depth test, and uniforms.
+
+See [Geometry & Meshes](/microes/guides/geometry/) for creating custom meshes and [Materials & Shaders](/microes/guides/materials/) for shader setup.
+
+## Performance Stats
+
+```typescript
+const drawCalls = Draw.getDrawCallCount();
+const primitives = Draw.getPrimitiveCount();
+```
+
+## Example: Debug Collision Boxes
+
+```typescript
+import { registerDrawCallback, Draw } from 'esengine';
+import { defineSystem, addSystem, Query, LocalTransform, Collider } from 'esengine';
+
+const colliders: Array<{ x: number; y: number; w: number; h: number }> = [];
+
+addSystem(defineSystem(
+ [Query(LocalTransform, Collider)],
+ (query) => {
+ colliders.length = 0;
+ for (const [entity, transform, collider] of query) {
+ colliders.push({
+ x: transform.position.x,
+ y: transform.position.y,
+ w: collider.width,
+ h: collider.height,
+ });
+ }
+ }
+));
+
+registerDrawCallback('debug-colliders', () => {
+ const green = { x: 0, y: 1, z: 0, w: 0.5 };
+ for (const c of colliders) {
+ Draw.rectOutline(
+ { x: c.x, y: c.y },
+ { x: c.w, y: c.h },
+ green,
+ 1
+ );
+ }
+});
+```
+
+## Next Steps
+
+- [Post-Processing](/microes/guides/post-processing/) — full-screen effects pipeline
+- [Geometry & Meshes](/microes/guides/geometry/) — custom mesh creation
+- [Materials & Shaders](/microes/guides/materials/) — shader and material management
diff --git a/docs/astro/src/content/docs/guides/editor-extensions.mdx b/docs/astro/src/content/docs/guides/editor-extensions.mdx
new file mode 100644
index 000000000..806cbbeea
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/editor-extensions.mdx
@@ -0,0 +1,575 @@
+---
+title: Editor Extensions
+description: Extend the ESEngine editor with custom menus, panels, gizmos, and settings
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The editor provides a registry-based extension system. Place TypeScript files in your project's `src/editor/` directory and the editor automatically compiles and loads them. Extensions can register menus, panels, gizmos, statusbar items, settings, and more.
+
+## Getting Started
+
+Create a TypeScript file in `src/editor/`:
+
+```
+my-project/
+├── src/
+│ ├── game.ts ← game script (bundled into runtime)
+│ └── editor/
+│ └── my-extension.ts ← editor extension (NOT bundled into runtime)
+├── assets/
+└── scenes/
+```
+
+The `src/editor/` directory is excluded from runtime bundling — only the editor loads these files. All `.ts` files under `src/` are compiled by the editor, but only files outside `editor/` are included in the game build. File changes trigger automatic hot-reload.
+
+### Accessing the API
+
+Import from `@esengine/editor` to access all editor and SDK APIs. The editor's build system shims this module automatically:
+
+```typescript
+import {
+ // Registry APIs
+ registerMenu,
+ registerMenuItem,
+ registerPanel,
+ registerGizmo,
+ registerStatusbarItem,
+ registerSettingsSection,
+ registerSettingsItem,
+ getSettingsValue,
+ setSettingsValue,
+ registerPropertyEditor,
+ registerComponentSchema,
+ registerBoundsProvider,
+
+ // UI utilities
+ showToast,
+ showSuccessToast,
+ showErrorToast,
+ showContextMenu,
+ showConfirmDialog,
+ showInputDialog,
+ icons,
+
+ // Editor access
+ getEditorInstance,
+ getEditorStore,
+
+ // Drawing and rendering (same as esengine SDK)
+ Draw,
+ Geometry,
+ Material,
+ BlendMode,
+ DataType,
+ ShaderSources,
+ PostProcess,
+ registerDrawCallback,
+ unregisterDrawCallback,
+
+ // Cleanup
+ onDispose,
+} from '@esengine/editor';
+```
+
+You can also import from `esengine` — both modules expose the same combined API in the editor context.
+
+<Aside type="tip">
+ Use `onDispose(fn)` to register cleanup callbacks. The editor calls them automatically when your extension is reloaded.
+</Aside>
+
+## Menus
+
+### Register a Menu
+
+Add a new top-level menu to the menu bar:
+
+```typescript
+registerMenu({
+ id: 'tools',
+ label: 'Tools',
+ order: 10,
+});
+```
+
+| Field | Type | Required | Description |
+|-------|------|----------|-------------|
+| `id` | string | Yes | Unique menu identifier |
+| `label` | string | Yes | Display text |
+| `order` | number | No | Sort order (lower = further left) |
+
+### Register a Menu Item
+
+Add items to existing or custom menus:
+
+```typescript
+registerMenuItem({
+ id: 'tools.export-png',
+ menu: 'tools',
+ label: 'Export as PNG',
+ shortcut: 'Ctrl+Shift+E',
+ order: 0,
+ action: () => {
+ showSuccessToast('Exported!');
+ },
+});
+
+registerMenuItem({
+ id: 'tools.clear-cache',
+ menu: 'tools',
+ label: 'Clear Cache',
+ order: 1,
+ separator: true,
+ enabled: () => cacheSize > 0,
+ action: () => clearCache(),
+});
+```
+
+| Field | Type | Required | Description |
+|-------|------|----------|-------------|
+| `id` | string | Yes | Unique item identifier |
+| `menu` | string | Yes | Parent menu ID (`file`, `edit`, `view`, `help`, or custom) |
+| `label` | string | Yes | Display text |
+| `icon` | string | No | SVG icon string |
+| `shortcut` | string | No | Keyboard shortcut display text |
+| `separator` | boolean | No | Show a separator line above this item |
+| `order` | number | No | Sort order within the menu |
+| `enabled` | () => boolean | No | Dynamic enable/disable |
+| `action` | () => void | Yes | Click handler |
+
+Built-in menus: `file`, `edit`, `view`, `help`.
+
+## Panels
+
+Register custom panels that appear in the editor layout:
+
+```typescript
+registerPanel({
+ id: 'my-debug-panel',
+ title: 'Debug Info',
+ icon: icons.settings(14),
+ position: 'right',
+ order: 10,
+ defaultVisible: false,
+ factory: (container, store) => {
+ const div = document.createElement('div');
+ div.style.padding = '8px';
+ div.textContent = 'Entity count: ' + store.entities.length;
+ container.appendChild(div);
+
+ const interval = setInterval(() => {
+ div.textContent = 'Entity count: ' + store.entities.length;
+ }, 1000);
+
+ return {
+ dispose() {
+ clearInterval(interval);
+ container.innerHTML = '';
+ },
+ onShow() {},
+ onHide() {},
+ };
+ },
+});
+```
+
+| Field | Type | Required | Description |
+|-------|------|----------|-------------|
+| `id` | string | Yes | Unique panel identifier |
+| `title` | string | Yes | Panel tab title |
+| `icon` | string | No | SVG icon string |
+| `position` | `'left' \| 'right' \| 'center' \| 'bottom'` | Yes | Layout position |
+| `defaultVisible` | boolean | No | Show on first load (default: false) |
+| `order` | number | No | Tab order within position |
+| `factory` | (container, store) => PanelInstance | Yes | Creates the panel UI |
+
+### PanelInstance
+
+The factory must return an object with at least a `dispose` method:
+
+```typescript
+interface PanelInstance {
+ dispose(): void;
+ onShow?(): void;
+ onHide?(): void;
+}
+```
+
+Optionally implement `resize()` to handle layout changes.
+
+## Gizmos
+
+Register custom scene view gizmos for visual editing tools:
+
+```typescript
+registerGizmo({
+ id: 'my-anchor-gizmo',
+ name: 'Anchor',
+ icon: icons.circle(16),
+ shortcut: 'A',
+ order: 20,
+
+ draw(ctx) {
+ const { store, ctx: canvas, zoom } = ctx;
+ const selected = store.selectedEntity;
+ if (selected === null) return;
+
+ const transform = ctx.getWorldTransform(selected);
+ canvas.beginPath();
+ canvas.arc(transform.x, transform.y, 8 / zoom, 0, Math.PI * 2);
+ canvas.strokeStyle = '#ff0';
+ canvas.lineWidth = 2 / zoom;
+ canvas.stroke();
+ },
+
+ hitTest(worldX, worldY, ctx) {
+ const selected = ctx.store.selectedEntity;
+ if (selected === null) return { hit: false };
+
+ const transform = ctx.getWorldTransform(selected);
+ const dx = worldX - transform.x;
+ const dy = worldY - transform.y;
+ const dist = Math.sqrt(dx * dx + dy * dy);
+ return { hit: dist < 10 / ctx.zoom, data: { entityId: selected } };
+ },
+
+ onDragStart(worldX, worldY, hitData, ctx) {},
+ onDrag(worldX, worldY, hitData, ctx) {},
+ onDragEnd(worldX, worldY, hitData, ctx) {},
+ getCursor(hitData) { return 'crosshair'; },
+});
+```
+
+### GizmoDescriptor
+
+| Field | Type | Required | Description |
+|-------|------|----------|-------------|
+| `id` | string | Yes | Unique gizmo identifier |
+| `name` | string | Yes | Display name in toolbar |
+| `icon` | string | Yes | SVG icon string |
+| `shortcut` | string | No | Keyboard shortcut |
+| `order` | number | No | Toolbar order |
+| `draw(ctx)` | function | Yes | Render the gizmo overlay |
+| `hitTest(worldX, worldY, ctx)` | function | Yes | Test if mouse hits the gizmo |
+| `onDragStart(worldX, worldY, hitData, ctx)` | function | No | Drag start handler |
+| `onDrag(worldX, worldY, hitData, ctx)` | function | No | Drag move handler |
+| `onDragEnd(worldX, worldY, hitData, ctx)` | function | No | Drag end handler |
+| `onHover(worldX, worldY, hitData, ctx)` | function | No | Mouse hover handler |
+| `getCursor(hitData)` | function | No | Custom cursor for hover |
+
+### GizmoContext
+
+The `ctx` parameter provides editor state and utilities:
+
+| Property / Method | Description |
+|-------------------|-------------|
+| `store` | Editor store (entities, selection, etc.) |
+| `ctx` | Canvas 2D rendering context for drawing overlays |
+| `zoom` | Current viewport zoom level |
+| `screenToWorld(clientX, clientY)` | Convert screen coordinates to world |
+| `getWorldTransform(entityId)` | Get entity's world transform |
+| `getEntityBounds(entityData)` | Get entity's visual bounds |
+| `requestRender()` | Request a scene redraw |
+
+Since `ctx.ctx` is a standard Canvas 2D context, you can use `fillText()` to draw viewport text directly inside `draw()`:
+
+```typescript
+draw(ctx) {
+ const { ctx: canvas, zoom } = ctx;
+ canvas.font = `${12 / zoom}px sans-serif`;
+ canvas.fillStyle = '#fff';
+ canvas.fillText('Label', worldX, worldY);
+},
+```
+
+## Settings
+
+### Register a Settings Section
+
+```typescript
+registerSettingsSection({
+ id: 'my-extension',
+ title: 'My Extension',
+ order: 10,
+});
+```
+
+### Register Settings Items
+
+```typescript
+registerSettingsItem({
+ id: 'my-extension.showOverlay',
+ section: 'my-extension',
+ label: 'Show Overlay',
+ type: 'boolean',
+ defaultValue: true,
+ order: 0,
+ onChange: (value) => {
+ // React to changes
+ },
+});
+
+registerSettingsItem({
+ id: 'my-extension.opacity',
+ section: 'my-extension',
+ label: 'Overlay Opacity',
+ type: 'range',
+ defaultValue: 0.8,
+ min: 0,
+ max: 1,
+ step: 0.1,
+ order: 1,
+});
+
+registerSettingsItem({
+ id: 'my-extension.theme',
+ section: 'my-extension',
+ label: 'Theme',
+ type: 'select',
+ defaultValue: 'dark',
+ options: [
+ { label: 'Dark', value: 'dark' },
+ { label: 'Light', value: 'light' },
+ ],
+ order: 2,
+});
+```
+
+### Settings Item Types
+
+| Type | Description | Extra fields |
+|------|-------------|-------------|
+| `boolean` | Toggle switch | — |
+| `number` | Number input | `min`, `max`, `step` |
+| `string` | Text input | — |
+| `color` | Color picker | — |
+| `select` | Dropdown | `options: [{ label, value }]` |
+| `range` | Slider | `min`, `max`, `step` |
+
+### Reading and Writing Settings
+
+```typescript
+const show = getSettingsValue<boolean>('my-extension.showOverlay');
+setSettingsValue('my-extension.opacity', 0.5);
+```
+
+Settings are persisted to `localStorage` automatically.
+
+## Statusbar Items
+
+Add widgets to the bottom status bar:
+
+```typescript
+registerStatusbarItem({
+ id: 'my-fps-counter',
+ position: 'right',
+ order: 0,
+ render: (container) => {
+ const span = document.createElement('span');
+ span.style.fontSize = '11px';
+ container.appendChild(span);
+
+ let lastTime = performance.now();
+ let frameCount = 0;
+
+ const tick = () => {
+ frameCount++;
+ const now = performance.now();
+ const elapsed = now - lastTime;
+ if (elapsed >= 1000) {
+ span.textContent = `FPS: ${Math.round(frameCount * 1000 / elapsed)}`;
+ frameCount = 0;
+ lastTime = now;
+ }
+ handle = requestAnimationFrame(tick);
+ };
+ let handle = requestAnimationFrame(tick);
+
+ return {
+ dispose() { cancelAnimationFrame(handle); },
+ update() {},
+ };
+ },
+});
+```
+
+| Field | Type | Required | Description |
+|-------|------|----------|-------------|
+| `id` | string | Yes | Unique identifier |
+| `position` | `'left' \| 'right'` | Yes | Bar position |
+| `order` | number | No | Sort order |
+| `render` | (container) => \{ dispose, update? \} | Yes | Create the widget |
+
+## UI Utilities
+
+### Toast Notifications
+
+```typescript
+showToast({ title: 'Hello', message: 'World', type: 'info', duration: 3000 });
+showSuccessToast('Done!', 'Build completed');
+showErrorToast('Error', 'Failed to compile');
+```
+
+### Dialogs
+
+```typescript
+const name = await showInputDialog({
+ title: 'Rename Entity',
+ label: 'New name:',
+ defaultValue: 'Entity',
+});
+
+const confirmed = await showConfirmDialog({
+ title: 'Delete Entity',
+ message: 'Are you sure?',
+});
+```
+
+### Context Menu
+
+```typescript
+showContextMenu({
+ x: event.clientX,
+ y: event.clientY,
+ items: [
+ { label: 'Copy', action: () => copy() },
+ { label: 'Paste', action: () => paste() },
+ { separator: true },
+ { label: 'Delete', action: () => del() },
+ ],
+});
+```
+
+## Component Schemas
+
+Register custom component schemas for the inspector panel:
+
+```typescript
+registerComponentSchema({
+ name: 'Health',
+ category: 'script',
+ properties: [
+ { name: 'current', type: 'number', min: 0, max: 1000 },
+ { name: 'max', type: 'number', min: 1, max: 1000 },
+ { name: 'regenRate', type: 'number', min: 0, step: 0.1 },
+ ],
+});
+```
+
+<Aside type="note">
+ Components defined with `defineComponent()` in game scripts are registered automatically. Use `registerComponentSchema` only when you need to customize property metadata (min/max, step, enum options, etc.).
+</Aside>
+
+## Property Editors
+
+Register custom inspector widgets for property types:
+
+```typescript
+registerPropertyEditor('my-gradient', (container, ctx) => {
+ const input = document.createElement('input');
+ input.type = 'color';
+ input.value = ctx.value as string;
+ input.addEventListener('input', () => ctx.onChange(input.value));
+ container.appendChild(input);
+
+ return {
+ update(value) { input.value = value as string; },
+ dispose() { container.innerHTML = ''; },
+ };
+});
+```
+
+Then reference the type in a component schema:
+
+```typescript
+registerComponentSchema({
+ name: 'Gradient',
+ category: 'script',
+ properties: [
+ { name: 'startColor', type: 'my-gradient' },
+ { name: 'endColor', type: 'my-gradient' },
+ ],
+});
+```
+
+## Bounds Providers
+
+Register custom bounds calculation for gizmo display:
+
+```typescript
+registerBoundsProvider('CircleCollider', {
+ getBounds(data: any) {
+ const r = data.radius ?? 50;
+ return { width: r * 2, height: r * 2 };
+ },
+});
+```
+
+## Resource Cleanup
+
+The editor automatically cleans up extension-registered menus, panels, gizmos, and settings on reload. For custom resources (timers, event listeners, GPU resources), use `onDispose`:
+
+```typescript
+const interval = setInterval(tick, 100);
+onDispose(() => clearInterval(interval));
+
+const shader = Material.createShader(vertSrc, fragSrc);
+// Shaders created through the extension API are auto-cleaned
+
+registerDrawCallback('my-overlay', drawFn);
+// Draw callbacks registered through the extension API are auto-cleaned
+```
+
+Resources tracked automatically:
+- Draw callbacks (`registerDrawCallback`)
+- Post-process passes (`PostProcess.addPass`)
+- Shaders (`Material.createShader`)
+
+## Example: Origin Crosshair
+
+A complete extension that draws a crosshair at the world origin with a settings toggle:
+
+```typescript
+import {
+ registerSettingsSection,
+ registerSettingsItem,
+ getSettingsValue,
+ registerDrawCallback,
+ Draw,
+} from '@esengine/editor';
+
+registerSettingsSection({ id: 'debug-overlay', title: 'Debug Overlay', order: 20 });
+registerSettingsItem({
+ id: 'debug-overlay.showOrigin',
+ section: 'debug-overlay',
+ label: 'Show Origin Crosshair',
+ type: 'boolean',
+ defaultValue: true,
+});
+registerSettingsItem({
+ id: 'debug-overlay.size',
+ section: 'debug-overlay',
+ label: 'Crosshair Size',
+ type: 'range',
+ defaultValue: 50,
+ min: 10,
+ max: 200,
+ step: 10,
+});
+
+registerDrawCallback('origin-crosshair', () => {
+ if (!getSettingsValue('debug-overlay.showOrigin')) return;
+ const size = getSettingsValue<number>('debug-overlay.size');
+ const red = { x: 1, y: 0, z: 0, w: 1 };
+ const green = { x: 0, y: 1, z: 0, w: 1 };
+ Draw.line({ x: 0, y: 0 }, { x: size, y: 0 }, red, 2);
+ Draw.line({ x: 0, y: 0 }, { x: 0, y: size }, green, 2);
+ Draw.circleOutline({ x: 0, y: 0 }, 4, { x: 1, y: 1, z: 1, w: 1 }, 1);
+});
+```
+
+## Next Steps
+
+- [Custom Draw](/microes/guides/custom-draw/) — Draw API for extension overlays
+- [Materials & Shaders](/microes/guides/materials/) — shader creation for custom gizmos
+- [Post-Processing](/microes/guides/post-processing/) — post-process passes from extensions
diff --git a/docs/astro/src/content/docs/guides/geometry.mdx b/docs/astro/src/content/docs/guides/geometry.mdx
new file mode 100644
index 000000000..c8138f1d7
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/geometry.mdx
@@ -0,0 +1,216 @@
+---
+title: Geometry & Meshes
+description: Custom mesh creation and management in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The Geometry API creates custom meshes for use with `Draw.drawMesh()` and `Draw.drawMeshWithMaterial()`. Build quads, circles, polygons, or fully custom vertex data for particles, trails, and procedural effects.
+
+## Creating a Mesh
+
+Define vertices in interleaved format with a layout describing each attribute:
+
+```typescript
+import { Geometry, DataType } from 'esengine';
+
+const triangle = Geometry.create({
+ vertices: new Float32Array([
+ // x, y, u, v
+ 0, 50, 0.5, 1,
+ -50, -50, 0, 0,
+ 50, -50, 1, 0,
+ ]),
+ layout: [
+ { name: 'a_position', type: DataType.Float2 },
+ { name: 'a_texCoord', type: DataType.Float2 },
+ ],
+ indices: new Uint16Array([0, 1, 2]),
+});
+```
+
+Returns a `GeometryHandle` (number). Pass it to `Draw.drawMesh()` or `Draw.drawMeshWithMaterial()` inside a draw callback.
+
+## DataType
+
+| Value | Name | Components |
+|-------|------|------------|
+| 1 | `Float` | 1 float |
+| 2 | `Float2` | 2 floats |
+| 3 | `Float3` | 3 floats |
+| 4 | `Float4` | 4 floats |
+| 5 | `Int` | 1 int |
+| 6 | `Int2` | 2 ints |
+| 7 | `Int3` | 3 ints |
+| 8 | `Int4` | 4 ints |
+
+## GeometryOptions
+
+| Field | Type | Required | Description |
+|-------|------|----------|-------------|
+| `vertices` | Float32Array | Yes | Vertex data in interleaved format |
+| `layout` | VertexAttributeDescriptor[] | Yes | Attribute layout describing the vertex format |
+| `indices` | Uint16Array \| Uint32Array | No | Index data for indexed drawing |
+| `dynamic` | boolean | No | Set to `true` for frequently updated meshes (default: `false`) |
+
+<Aside type="note">
+ Buffer limits: 64K floats for vertices, 16K for indices. Both `Uint16Array` and `Uint32Array` index formats are supported.
+</Aside>
+
+## Helper Functions
+
+### createQuad
+
+Creates a centered quad with texture coordinates:
+
+```typescript
+const quad = Geometry.createQuad(100, 80); // width, height
+```
+
+Layout: `a_position` (Float2) + `a_texCoord` (Float2). Default size is 1x1.
+
+### createCircle
+
+Creates a circle mesh using a center vertex and radial segments:
+
+```typescript
+const circle = Geometry.createCircle(50, 64); // radius, segments
+```
+
+Layout: `a_position` (Float2) + `a_texCoord` (Float2). Default radius is 1, segments is 32.
+
+### createPolygon
+
+Creates a polygon from an array of points with auto-generated texture coordinates and fan triangulation:
+
+```typescript
+const hex = Geometry.createPolygon([
+ { x: 50, y: 0 },
+ { x: 25, y: 43 },
+ { x: -25, y: 43 },
+ { x: -50, y: 0 },
+ { x: -25, y: -43 },
+ { x: 25, y: -43 },
+]);
+```
+
+Requires at least 3 points. Layout: `a_position` (Float2) + `a_texCoord` (Float2).
+
+## Drawing with Geometry
+
+Use geometry inside a draw callback:
+
+```typescript
+import { registerDrawCallback, Draw, Geometry, Material, BlendMode } from 'esengine';
+
+const quad = Geometry.createQuad(100, 100);
+const mat = Material.create({
+ shader: myShader,
+ uniforms: { u_color: { x: 1, y: 0, z: 0, w: 1 } },
+ blendMode: BlendMode.Normal,
+});
+
+const identity = new Float32Array([
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+]);
+
+registerDrawCallback('custom-mesh', () => {
+ Draw.drawMeshWithMaterial(quad, mat, identity);
+});
+```
+
+See [Custom Draw](/microes/guides/custom-draw/) for the full Draw API and [Materials & Shaders](/microes/guides/materials/) for creating shaders and materials.
+
+## Dynamic Updates
+
+For meshes that change every frame (particles, trails), create with `dynamic: true` and call `updateVertices`:
+
+```typescript
+const mesh = Geometry.create({
+ vertices: initialVertices,
+ layout: [
+ { name: 'a_position', type: DataType.Float2 },
+ { name: 'a_texCoord', type: DataType.Float2 },
+ ],
+ indices,
+ dynamic: true,
+});
+
+// Update each frame
+Geometry.updateVertices(mesh, newVertices);
+Geometry.updateVertices(mesh, partialData, offsetInFloats);
+```
+
+## Resource Management
+
+Release geometry when no longer needed:
+
+```typescript
+Geometry.release(handle);
+const valid = Geometry.isValid(handle);
+```
+
+## Example: Particle Trail
+
+A dynamic mesh updated every frame to render a trail behind a moving object:
+
+```typescript
+import { registerDrawCallback, Draw, Geometry, DataType, Material } from 'esengine';
+
+const MAX_POINTS = 64;
+const FLOATS_PER_VERTEX = 4; // x, y, u, v
+const vertices = new Float32Array(MAX_POINTS * 2 * FLOATS_PER_VERTEX);
+const indices = new Uint16Array((MAX_POINTS - 1) * 6);
+
+for (let i = 0; i < MAX_POINTS - 1; i++) {
+ const base = i * 2;
+ const idx = i * 6;
+ indices[idx] = base;
+ indices[idx + 1] = base + 1;
+ indices[idx + 2] = base + 2;
+ indices[idx + 3] = base + 2;
+ indices[idx + 4] = base + 1;
+ indices[idx + 5] = base + 3;
+}
+
+const trail = Geometry.create({
+ vertices,
+ layout: [
+ { name: 'a_position', type: DataType.Float2 },
+ { name: 'a_texCoord', type: DataType.Float2 },
+ ],
+ indices,
+ dynamic: true,
+});
+
+const transform = new Float32Array([
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
+]);
+
+registerDrawCallback('trail', () => {
+ // update vertices with trail point positions...
+ Geometry.updateVertices(trail, vertices);
+ Draw.drawMeshWithMaterial(trail, trailMaterial, transform);
+});
+```
+
+## Full API Reference
+
+| Method | Description |
+|--------|-------------|
+| `Geometry.create(options)` | Create geometry from vertices, layout, and optional indices |
+| `Geometry.updateVertices(handle, vertices, offset?)` | Update vertex data of a dynamic geometry |
+| `Geometry.release(handle)` | Release a geometry |
+| `Geometry.isValid(handle)` | Check if a handle is valid |
+| `Geometry.createQuad(width?, height?)` | Create a centered quad with UVs |
+| `Geometry.createCircle(radius?, segments?)` | Create a circle mesh |
+| `Geometry.createPolygon(points)` | Create a polygon from point array |
+
+## Next Steps
+
+- [Custom Draw](/microes/guides/custom-draw/) — drawing meshes and primitives
+- [Materials & Shaders](/microes/guides/materials/) — shaders and materials for meshes
+- [Post-Processing](/microes/guides/post-processing/) — full-screen effects
diff --git a/docs/astro/src/content/docs/guides/materials.mdx b/docs/astro/src/content/docs/guides/materials.mdx
index c83340b6c..566a2b29f 100644
--- a/docs/astro/src/content/docs/guides/materials.mdx
+++ b/docs/astro/src/content/docs/guides/materials.mdx
@@ -119,7 +119,7 @@ const instance = Material.createInstance(sourceMat);
Material.setUniform(instance, 'u_tint', { x: 0, y: 1, z: 0, w: 1 });
```
-## Shader File Format (.shader)
+## Shader File Format (.esshader)
Shader files use `#pragma` directives to separate vertex and fragment sections:
@@ -165,10 +165,10 @@ void main() {
Load shader files via the asset server:
```typescript
-const shader = await assets.loadShader('assets/effects/glow.shader');
+const shader = await assets.loadShader('assets/effects/glow.esshader');
```
-## Material File Format (.material)
+## Material File Format (.esmaterial)
Materials can be defined as JSON files and loaded via the asset server:
@@ -176,7 +176,7 @@ Materials can be defined as JSON files and loaded via the asset server:
{
"version": "1.0",
"type": "material",
- "shader": "effects/glow.shader",
+ "shader": "effects/glow.esshader",
"blendMode": 1,
"depthTest": false,
"properties": {
@@ -190,13 +190,13 @@ Materials can be defined as JSON files and loaded via the asset server:
|-------|------|-------------|
| `version` | string | Format version (`"1.0"`) |
| `type` | string | Must be `"material"` |
-| `shader` | string | Path to .shader file (relative to material or absolute) |
+| `shader` | string | Path to .esshader file (relative to material or absolute) |
| `blendMode` | number | BlendMode enum value |
| `depthTest` | boolean | Enable depth testing |
| `properties` | object | Uniform name/value pairs |
```typescript
-const loaded = await assets.loadMaterial('assets/effects/glow.material');
+const loaded = await assets.loadMaterial('assets/effects/glow.esmaterial');
sprite.material = loaded.handle;
```
@@ -245,7 +245,7 @@ addSystem(defineSystem(
| `Material.releaseShader(shader)` | Release a shader |
| `Material.create(options)` | Create a material |
| `Material.createInstance(source)` | Create a material instance sharing the shader |
-| `Material.createFromAsset(data, shader)` | Create from a parsed .material file |
+| `Material.createFromAsset(data, shader)` | Create from a parsed .esmaterial file |
| `Material.setUniform(mat, name, value)` | Set a uniform value |
| `Material.getUniform(mat, name)` | Get a uniform value |
| `Material.getUniforms(mat)` | Get all uniforms as a Map |
diff --git a/docs/astro/src/content/docs/guides/post-processing.mdx b/docs/astro/src/content/docs/guides/post-processing.mdx
new file mode 100644
index 000000000..843a20d73
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/post-processing.mdx
@@ -0,0 +1,213 @@
+---
+title: Post-Processing
+description: Full-screen post-processing effects pipeline in ESEngine
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The PostProcess API applies full-screen shader effects after the scene is rendered. Chain multiple passes to create blur, vignette, grayscale, chromatic aberration, or custom effects.
+
+## Initialization
+
+Initialize the pipeline with your canvas dimensions:
+
+```typescript
+import { PostProcess } from 'esengine';
+
+PostProcess.init(canvas.width, canvas.height);
+```
+
+<Aside type="note">
+ `PostProcess.begin()` and `PostProcess.end()` are called by the engine internally. You only need to configure passes and uniforms.
+</Aside>
+
+## Adding Passes
+
+Create a built-in effect shader and add it as a named pass:
+
+```typescript
+const blurShader = PostProcess.createBlur();
+PostProcess.addPass('blur', blurShader);
+PostProcess.setUniform('blur', 'u_intensity', 2.0);
+```
+
+Passes execute in the order they are added. Each pass reads the output of the previous pass as `u_texture`.
+
+## Built-in Effects
+
+| Method | Effect | Uniforms |
+|--------|--------|----------|
+| `createBlur()` | Gaussian blur | `u_intensity` (float) — blur spread, `u_resolution` (vec2) — auto |
+| `createVignette()` | Darkened edges | `u_intensity` (float) — radius, `u_softness` (float) — falloff |
+| `createGrayscale()` | Desaturation | `u_intensity` (float, 0–1) — blend ratio |
+| `createChromaticAberration()` | RGB channel offset | `u_intensity` (float) — offset amount, `u_resolution` (vec2) — auto |
+
+<Aside type="tip">
+ `u_resolution` is set automatically by the engine. You only need to set the other uniforms.
+</Aside>
+
+### Blur
+
+9-tap Gaussian blur. Higher `u_intensity` increases the blur spread:
+
+```typescript
+const blur = PostProcess.createBlur();
+PostProcess.addPass('blur', blur);
+PostProcess.setUniform('blur', 'u_intensity', 3.0);
+```
+
+### Vignette
+
+Darkens the screen edges. `u_intensity` controls the radius, `u_softness` controls the falloff:
+
+```typescript
+const vignette = PostProcess.createVignette();
+PostProcess.addPass('vignette', vignette);
+PostProcess.setUniform('vignette', 'u_intensity', 0.8);
+PostProcess.setUniform('vignette', 'u_softness', 0.4);
+```
+
+### Grayscale
+
+Blends between the original color and grayscale. `u_intensity` of `1.0` is fully gray:
+
+```typescript
+const gray = PostProcess.createGrayscale();
+PostProcess.addPass('grayscale', gray);
+PostProcess.setUniform('grayscale', 'u_intensity', 1.0);
+```
+
+### Chromatic Aberration
+
+Offsets the R and B channels for a lens distortion look:
+
+```typescript
+const ca = PostProcess.createChromaticAberration();
+PostProcess.addPass('chromatic', ca);
+PostProcess.setUniform('chromatic', 'u_intensity', 2.0);
+```
+
+## Pass Management
+
+```typescript
+PostProcess.setEnabled('blur', false); // disable a pass
+PostProcess.setEnabled('blur', true); // re-enable
+PostProcess.removePass('blur'); // remove entirely
+const count = PostProcess.getPassCount(); // number of passes
+```
+
+## Setting Uniforms
+
+```typescript
+PostProcess.setUniform('blur', 'u_intensity', 5.0);
+PostProcess.setUniformVec4('custom', 'u_tint', { x: 1, y: 0.8, z: 0.6, w: 1 });
+```
+
+## Bypass Mode
+
+When no passes are active, bypass the pipeline to skip FBO overhead:
+
+```typescript
+PostProcess.setBypass(true); // render directly to screen
+PostProcess.setBypass(false); // use the pipeline
+
+const bypassed = PostProcess.isBypassed();
+```
+
+## Window Resize
+
+Update framebuffer dimensions when the canvas resizes:
+
+```typescript
+window.addEventListener('resize', () => {
+ PostProcess.resize(canvas.width, canvas.height);
+});
+```
+
+## Custom Pass
+
+Write a custom fragment shader and add it as a pass. The vertex shader is a fixed full-screen quad — you only write the fragment shader:
+
+```typescript
+import { Material, PostProcess } from 'esengine';
+
+const invertShader = Material.createShader(
+ // vertex shader is provided internally for post-process,
+ // but createShader needs both — use the same pattern:
+ `#version 300 es
+ precision highp float;
+ layout(location = 0) in vec2 a_position;
+ layout(location = 1) in vec2 a_texCoord;
+ out vec2 v_texCoord;
+ void main() {
+ v_texCoord = a_texCoord;
+ gl_Position = vec4(a_position, 0.0, 1.0);
+ }`,
+ `#version 300 es
+ precision highp float;
+ in vec2 v_texCoord;
+ uniform sampler2D u_texture;
+ uniform float u_intensity;
+ out vec4 fragColor;
+ void main() {
+ vec4 color = texture(u_texture, v_texCoord);
+ vec3 inverted = mix(color.rgb, 1.0 - color.rgb, u_intensity);
+ fragColor = vec4(inverted, color.a);
+ }`
+);
+
+PostProcess.addPass('invert', invertShader);
+PostProcess.setUniform('invert', 'u_intensity', 1.0);
+```
+
+See [Materials & Shaders](/microes/guides/materials/) for more on writing shaders.
+
+## Example: Pause Menu Blur
+
+Enable blur and grayscale when the game is paused:
+
+```typescript
+import { PostProcess } from 'esengine';
+
+const blurShader = PostProcess.createBlur();
+const grayShader = PostProcess.createGrayscale();
+PostProcess.addPass('pause-blur', blurShader);
+PostProcess.addPass('pause-gray', grayShader);
+PostProcess.setEnabled('pause-blur', false);
+PostProcess.setEnabled('pause-gray', false);
+
+function setPaused(paused: boolean) {
+ PostProcess.setEnabled('pause-blur', paused);
+ PostProcess.setEnabled('pause-gray', paused);
+ PostProcess.setUniform('pause-blur', 'u_intensity', 4.0);
+ PostProcess.setUniform('pause-gray', 'u_intensity', 0.6);
+}
+```
+
+## Full API Reference
+
+| Method | Description |
+|--------|-------------|
+| `PostProcess.init(width, height)` | Initialize the pipeline |
+| `PostProcess.shutdown()` | Shut down the pipeline |
+| `PostProcess.resize(width, height)` | Update framebuffer size |
+| `PostProcess.addPass(name, shader)` | Add a named pass |
+| `PostProcess.removePass(name)` | Remove a pass |
+| `PostProcess.setEnabled(name, enabled)` | Enable or disable a pass |
+| `PostProcess.isEnabled(name)` | Check if a pass is enabled |
+| `PostProcess.setUniform(pass, name, value)` | Set a float uniform |
+| `PostProcess.setUniformVec4(pass, name, value)` | Set a vec4 uniform |
+| `PostProcess.getPassCount()` | Get the number of passes |
+| `PostProcess.isInitialized()` | Check if the pipeline is active |
+| `PostProcess.setBypass(bypass)` | Enable or disable bypass mode |
+| `PostProcess.isBypassed()` | Check bypass state |
+| `PostProcess.createBlur()` | Create a blur effect shader |
+| `PostProcess.createVignette()` | Create a vignette effect shader |
+| `PostProcess.createGrayscale()` | Create a grayscale effect shader |
+| `PostProcess.createChromaticAberration()` | Create a chromatic aberration shader |
+
+## Next Steps
+
+- [Custom Draw](/microes/guides/custom-draw/) — immediate-mode drawing primitives
+- [Materials & Shaders](/microes/guides/materials/) — shader creation and uniforms
+- [Rendering Overview](/microes/guides/rendering/) — camera, transform, render order
diff --git a/docs/astro/src/content/docs/guides/rendering.mdx b/docs/astro/src/content/docs/guides/rendering.mdx
index fb95cfc37..af75dc646 100644
--- a/docs/astro/src/content/docs/guides/rendering.mdx
+++ b/docs/astro/src/content/docs/guides/rendering.mdx
@@ -98,3 +98,11 @@ Set these values in the inspector when placing entities, or modify them at runti
<Aside type="tip">
The C++ backend handles all WebGL rendering. You just set component data and the engine draws everything automatically each frame.
</Aside>
+
+## Next Steps
+
+- [Sprite](/microes/guides/sprite/) — sprite rendering and animation
+- [Spine Animation](/microes/guides/spine/) — skeletal animation
+- [Custom Draw](/microes/guides/custom-draw/) — immediate-mode drawing for debug visualization and dynamic graphics
+- [Post-Processing](/microes/guides/post-processing/) — full-screen effects (blur, vignette, grayscale)
+- [Geometry & Meshes](/microes/guides/geometry/) — custom mesh creation for advanced rendering
diff --git a/docs/astro/src/content/docs/zh/guides/assets.mdx b/docs/astro/src/content/docs/zh/guides/assets.mdx
index 11fd508b8..cc07e425f 100644
--- a/docs/astro/src/content/docs/zh/guides/assets.mdx
+++ b/docs/astro/src/content/docs/zh/guides/assets.mdx
@@ -116,7 +116,7 @@ const config = bundle.json.get('assets/config.json');
| 字段 | 类型 | 说明 |
|------|------|------|
| `textures` | string[] | 纹理图片路径 |
-| `materials` | string[] | 材质文件路径(.material) |
+| `materials` | string[] | 材质文件路径(.esmaterial) |
| `spine` | SpineDescriptor[] | Spine 骨骼/图集对 |
| `json` | string[] | JSON 文件路径 |
| `text` | string[] | 文本文件路径 |
@@ -138,11 +138,11 @@ const config = bundle.json.get('assets/config.json');
## 材质加载
```typescript
-const loaded = await assets.loadMaterial('assets/effects/glow.material');
+const loaded = await assets.loadMaterial('assets/effects/glow.esmaterial');
sprite.material = loaded.handle;
```
-详见[材质与着色器](/microes/zh/guides/materials/)了解完整的材质 API 和 `.material` 文件格式。
+详见[材质与着色器](/microes/zh/guides/materials/)了解完整的材质 API 和 `.esmaterial` 文件格式。
## 缓存机制
diff --git a/docs/astro/src/content/docs/zh/guides/custom-draw.mdx b/docs/astro/src/content/docs/zh/guides/custom-draw.mdx
new file mode 100644
index 000000000..7a478cc40
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/custom-draw.mdx
@@ -0,0 +1,205 @@
+---
+title: 自定义绘制
+description: ESEngine 即时模式 2D 绘图 API,用于调试可视化和动态图形
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+Draw API 提供即时模式 2D 绘图图元。所有绘制命令每帧清空,适用于调试可视化、自定义 UI 叠加层和动态图形。
+
+## 绘制回调
+
+注册绘制回调,引擎会在渲染阶段自动调用你的函数:
+
+```typescript
+import { registerDrawCallback, Draw } from 'esengine';
+
+registerDrawCallback('my-debug', (elapsed) => {
+ Draw.line({ x: 0, y: 0 }, { x: 100, y: 100 }, { x: 1, y: 0, z: 0, w: 1 }, 2);
+});
+```
+
+不再需要时移除回调:
+
+```typescript
+import { unregisterDrawCallback, clearDrawCallbacks } from 'esengine';
+
+unregisterDrawCallback('my-debug');
+clearDrawCallbacks();
+```
+
+<Aside type="caution">
+ `Draw.begin()` 和 `Draw.end()` 由引擎内部调用。只在注册的回调中使用 Draw API。
+</Aside>
+
+## 绘制图元
+
+### 线段
+
+```typescript
+Draw.line(
+ { x: 0, y: 0 }, // 起点
+ { x: 200, y: 150 }, // 终点
+ { x: 1, y: 1, z: 0, w: 1 }, // 黄色
+ 2 // 线宽
+);
+```
+
+### 矩形
+
+```typescript
+Draw.rect(
+ { x: 100, y: 100 }, // 中心位置
+ { x: 80, y: 60 }, // 尺寸
+ { x: 0, y: 0.5, z: 1, w: 0.5 }, // 半透明蓝色
+ true // 填充(默认)
+);
+
+Draw.rectOutline(
+ { x: 100, y: 100 },
+ { x: 80, y: 60 },
+ { x: 1, y: 0, z: 0, w: 1 }, // 红色
+ 2 // 线宽
+);
+```
+
+### 圆形
+
+```typescript
+Draw.circle(
+ { x: 200, y: 200 }, // 中心
+ 50, // 半径
+ { x: 0, y: 1, z: 0, w: 1 }, // 绿色
+ true, // 填充
+ 32 // 段数
+);
+
+Draw.circleOutline(
+ { x: 200, y: 200 },
+ 50,
+ { x: 1, y: 1, z: 1, w: 1 }, // 白色
+ 1, // 线宽
+ 32 // 段数
+);
+```
+
+### 纹理
+
+```typescript
+Draw.texture(
+ { x: 300, y: 200 }, // 位置
+ { x: 64, y: 64 }, // 尺寸
+ textureHandle,
+ { x: 1, y: 1, z: 1, w: 1 } // 着色(默认白色)
+);
+
+Draw.textureRotated(
+ { x: 300, y: 200 },
+ { x: 64, y: 64 },
+ Math.PI / 4, // 旋转弧度
+ textureHandle,
+ { x: 1, y: 1, z: 1, w: 1 }
+);
+```
+
+## 图元参考
+
+| 方法 | 参数 | 说明 |
+|------|------|------|
+| `line(from, to, color, thickness?)` | Vec2, Vec2, Color, number=1 | 线段 |
+| `rect(position, size, color, filled?)` | Vec2, Vec2, Color, bool=true | 矩形 |
+| `rectOutline(position, size, color, thickness?)` | Vec2, Vec2, Color, number=1 | 矩形边框 |
+| `circle(center, radius, color, filled?, segments?)` | Vec2, number, Color, bool=true, number=32 | 圆形 |
+| `circleOutline(center, radius, color, thickness?, segments?)` | Vec2, number, Color, number=1, number=32 | 圆形边框 |
+| `texture(position, size, textureHandle, tint?)` | Vec2, Vec2, number, Color=白色 | 纹理四边形 |
+| `textureRotated(position, size, rotation, textureHandle, tint?)` | Vec2, Vec2, number, number, Color=白色 | 旋转纹理四边形 |
+
+## 渲染状态
+
+控制后续图元的渲染方式:
+
+```typescript
+Draw.setLayer(5); // 渲染层级(越大越在上)
+Draw.setDepth(0.5); // 层内深度排序
+Draw.setBlendMode(BlendMode.Additive); // 混合模式
+Draw.setDepthTest(true); // 启用深度测试
+```
+
+| 方法 | 说明 |
+|------|------|
+| `setLayer(layer)` | 设置渲染层级 |
+| `setDepth(depth)` | 设置深度排序值 |
+| `setBlendMode(mode)` | 设置混合模式(Normal、Additive、Multiply、Screen、PremultipliedAlpha) |
+| `setDepthTest(enabled)` | 启用或禁用深度测试 |
+
+## 自定义网格绘制
+
+使用着色器或材质绘制自定义几何体:
+
+```typescript
+import { Geometry, Draw, Material } from 'esengine';
+
+const quad = Geometry.createQuad(100, 100);
+const transform = new Float32Array([
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+]);
+
+Draw.drawMesh(quad, shaderHandle, transform);
+Draw.drawMeshWithMaterial(quad, materialHandle, transform);
+```
+
+`drawMeshWithMaterial` 会自动应用材质的混合模式、深度测试和 uniform。
+
+参见[几何体与网格](/microes/zh/guides/geometry/)了解自定义网格创建,以及[材质与着色器](/microes/zh/guides/materials/)了解着色器设置。
+
+## 性能统计
+
+```typescript
+const drawCalls = Draw.getDrawCallCount();
+const primitives = Draw.getPrimitiveCount();
+```
+
+## 示例:调试碰撞框
+
+```typescript
+import { registerDrawCallback, Draw } from 'esengine';
+import { defineSystem, addSystem, Query, LocalTransform, Collider } from 'esengine';
+
+const colliders: Array<{ x: number; y: number; w: number; h: number }> = [];
+
+addSystem(defineSystem(
+ [Query(LocalTransform, Collider)],
+ (query) => {
+ colliders.length = 0;
+ for (const [entity, transform, collider] of query) {
+ colliders.push({
+ x: transform.position.x,
+ y: transform.position.y,
+ w: collider.width,
+ h: collider.height,
+ });
+ }
+ }
+));
+
+registerDrawCallback('debug-colliders', () => {
+ const green = { x: 0, y: 1, z: 0, w: 0.5 };
+ for (const c of colliders) {
+ Draw.rectOutline(
+ { x: c.x, y: c.y },
+ { x: c.w, y: c.h },
+ green,
+ 1
+ );
+ }
+});
+```
+
+## 下一步
+
+- [后处理效果](/microes/zh/guides/post-processing/) — 全屏效果管线
+- [几何体与网格](/microes/zh/guides/geometry/) — 自定义网格创建
+- [材质与着色器](/microes/zh/guides/materials/) — 着色器和材质管理
diff --git a/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx b/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx
new file mode 100644
index 000000000..2aee7b229
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/editor-extensions.mdx
@@ -0,0 +1,575 @@
+---
+title: 编辑器扩展
+description: 通过自定义菜单、面板、Gizmo 和设置扩展 ESEngine 编辑器
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+编辑器提供基于注册表的扩展系统。将 TypeScript 文件放在项目的 `src/editor/` 目录中,编辑器会自动编译并加载。扩展可以注册菜单、面板、Gizmo、状态栏项、设置等。
+
+## 快速开始
+
+在 `src/editor/` 下创建 TypeScript 文件:
+
+```
+my-project/
+├── src/
+│ ├── game.ts ← 游戏脚本(打包进运行时)
+│ └── editor/
+│ └── my-extension.ts ← 编辑器扩展(不打包进运行时)
+├── assets/
+└── scenes/
+```
+
+`src/editor/` 目录会被运行时构建排除——只有编辑器会加载这些文件。`src/` 下所有 `.ts` 文件都会被编辑器编译,但只有 `editor/` 之外的文件会包含在游戏构建中。文件变更会触发自动热重载。
+
+### 访问 API
+
+从 `@esengine/editor` 导入所有编辑器和 SDK API。编辑器构建系统会自动处理模块解析:
+
+```typescript
+import {
+ // 注册 API
+ registerMenu,
+ registerMenuItem,
+ registerPanel,
+ registerGizmo,
+ registerStatusbarItem,
+ registerSettingsSection,
+ registerSettingsItem,
+ getSettingsValue,
+ setSettingsValue,
+ registerPropertyEditor,
+ registerComponentSchema,
+ registerBoundsProvider,
+
+ // UI 工具
+ showToast,
+ showSuccessToast,
+ showErrorToast,
+ showContextMenu,
+ showConfirmDialog,
+ showInputDialog,
+ icons,
+
+ // 编辑器访问
+ getEditorInstance,
+ getEditorStore,
+
+ // 绘制和渲染(与 esengine SDK 相同)
+ Draw,
+ Geometry,
+ Material,
+ BlendMode,
+ DataType,
+ ShaderSources,
+ PostProcess,
+ registerDrawCallback,
+ unregisterDrawCallback,
+
+ // 清理
+ onDispose,
+} from '@esengine/editor';
+```
+
+也可以从 `esengine` 导入——在编辑器上下文中两个模块暴露相同的合并 API。
+
+<Aside type="tip">
+ 使用 `onDispose(fn)` 注册清理回调。扩展重载时编辑器会自动调用它们。
+</Aside>
+
+## 菜单
+
+### 注册菜单
+
+在菜单栏添加新的顶级菜单:
+
+```typescript
+registerMenu({
+ id: 'tools',
+ label: 'Tools',
+ order: 10,
+});
+```
+
+| 字段 | 类型 | 必需 | 说明 |
+|------|------|------|------|
+| `id` | string | 是 | 唯一标识 |
+| `label` | string | 是 | 显示文本 |
+| `order` | number | 否 | 排序(越小越靠左) |
+
+### 注册菜单项
+
+向已有或自定义菜单添加项目:
+
+```typescript
+registerMenuItem({
+ id: 'tools.export-png',
+ menu: 'tools',
+ label: 'Export as PNG',
+ shortcut: 'Ctrl+Shift+E',
+ order: 0,
+ action: () => {
+ showSuccessToast('Exported!');
+ },
+});
+
+registerMenuItem({
+ id: 'tools.clear-cache',
+ menu: 'tools',
+ label: 'Clear Cache',
+ order: 1,
+ separator: true,
+ enabled: () => cacheSize > 0,
+ action: () => clearCache(),
+});
+```
+
+| 字段 | 类型 | 必需 | 说明 |
+|------|------|------|------|
+| `id` | string | 是 | 唯一标识 |
+| `menu` | string | 是 | 父菜单 ID(`file`、`edit`、`view`、`help` 或自定义) |
+| `label` | string | 是 | 显示文本 |
+| `icon` | string | 否 | SVG 图标字符串 |
+| `shortcut` | string | 否 | 快捷键显示文本 |
+| `separator` | boolean | 否 | 在此项上方显示分隔线 |
+| `order` | number | 否 | 菜单内排序 |
+| `enabled` | () => boolean | 否 | 动态启用/禁用 |
+| `action` | () => void | 是 | 点击处理函数 |
+
+内置菜单:`file`、`edit`、`view`、`help`。
+
+## 面板
+
+注册出现在编辑器布局中的自定义面板:
+
+```typescript
+registerPanel({
+ id: 'my-debug-panel',
+ title: 'Debug Info',
+ icon: icons.settings(14),
+ position: 'right',
+ order: 10,
+ defaultVisible: false,
+ factory: (container, store) => {
+ const div = document.createElement('div');
+ div.style.padding = '8px';
+ div.textContent = 'Entity count: ' + store.entities.length;
+ container.appendChild(div);
+
+ const interval = setInterval(() => {
+ div.textContent = 'Entity count: ' + store.entities.length;
+ }, 1000);
+
+ return {
+ dispose() {
+ clearInterval(interval);
+ container.innerHTML = '';
+ },
+ onShow() {},
+ onHide() {},
+ };
+ },
+});
+```
+
+| 字段 | 类型 | 必需 | 说明 |
+|------|------|------|------|
+| `id` | string | 是 | 唯一标识 |
+| `title` | string | 是 | 面板标签标题 |
+| `icon` | string | 否 | SVG 图标字符串 |
+| `position` | `'left' \| 'right' \| 'center' \| 'bottom'` | 是 | 布局位置 |
+| `defaultVisible` | boolean | 否 | 首次加载时显示(默认 false) |
+| `order` | number | 否 | 同位置内的标签排序 |
+| `factory` | (container, store) => PanelInstance | 是 | 创建面板 UI |
+
+### PanelInstance
+
+factory 必须返回至少包含 `dispose` 方法的对象:
+
+```typescript
+interface PanelInstance {
+ dispose(): void;
+ onShow?(): void;
+ onHide?(): void;
+}
+```
+
+可选实现 `resize()` 以处理布局变化。
+
+## Gizmo
+
+注册自定义场景视图 Gizmo 用于可视化编辑工具:
+
+```typescript
+registerGizmo({
+ id: 'my-anchor-gizmo',
+ name: 'Anchor',
+ icon: icons.circle(16),
+ shortcut: 'A',
+ order: 20,
+
+ draw(ctx) {
+ const { store, ctx: canvas, zoom } = ctx;
+ const selected = store.selectedEntity;
+ if (selected === null) return;
+
+ const transform = ctx.getWorldTransform(selected);
+ canvas.beginPath();
+ canvas.arc(transform.x, transform.y, 8 / zoom, 0, Math.PI * 2);
+ canvas.strokeStyle = '#ff0';
+ canvas.lineWidth = 2 / zoom;
+ canvas.stroke();
+ },
+
+ hitTest(worldX, worldY, ctx) {
+ const selected = ctx.store.selectedEntity;
+ if (selected === null) return { hit: false };
+
+ const transform = ctx.getWorldTransform(selected);
+ const dx = worldX - transform.x;
+ const dy = worldY - transform.y;
+ const dist = Math.sqrt(dx * dx + dy * dy);
+ return { hit: dist < 10 / ctx.zoom, data: { entityId: selected } };
+ },
+
+ onDragStart(worldX, worldY, hitData, ctx) {},
+ onDrag(worldX, worldY, hitData, ctx) {},
+ onDragEnd(worldX, worldY, hitData, ctx) {},
+ getCursor(hitData) { return 'crosshair'; },
+});
+```
+
+### GizmoDescriptor
+
+| 字段 | 类型 | 必需 | 说明 |
+|------|------|------|------|
+| `id` | string | 是 | 唯一标识 |
+| `name` | string | 是 | 工具栏显示名称 |
+| `icon` | string | 是 | SVG 图标字符串 |
+| `shortcut` | string | 否 | 快捷键 |
+| `order` | number | 否 | 工具栏排序 |
+| `draw(ctx)` | function | 是 | 渲染 Gizmo 叠加层 |
+| `hitTest(worldX, worldY, ctx)` | function | 是 | 检测鼠标是否命中 Gizmo |
+| `onDragStart(worldX, worldY, hitData, ctx)` | function | 否 | 拖拽开始 |
+| `onDrag(worldX, worldY, hitData, ctx)` | function | 否 | 拖拽中 |
+| `onDragEnd(worldX, worldY, hitData, ctx)` | function | 否 | 拖拽结束 |
+| `onHover(worldX, worldY, hitData, ctx)` | function | 否 | 鼠标悬停 |
+| `getCursor(hitData)` | function | 否 | 自定义悬停光标 |
+
+### GizmoContext
+
+`ctx` 参数提供编辑器状态和工具方法:
+
+| 属性 / 方法 | 说明 |
+|-------------|------|
+| `store` | 编辑器状态(实体、选择等) |
+| `ctx` | Canvas 2D 渲染上下文,用于绘制叠加层 |
+| `zoom` | 当前视口缩放级别 |
+| `screenToWorld(clientX, clientY)` | 屏幕坐标转世界坐标 |
+| `getWorldTransform(entityId)` | 获取实体的世界变换 |
+| `getEntityBounds(entityData)` | 获取实体的可视边界 |
+| `requestRender()` | 请求场景重绘 |
+
+`ctx.ctx` 是标准的 Canvas 2D 上下文,可以在 `draw()` 中直接使用 `fillText()` 绘制视口文本:
+
+```typescript
+draw(ctx) {
+ const { ctx: canvas, zoom } = ctx;
+ canvas.font = `${12 / zoom}px sans-serif`;
+ canvas.fillStyle = '#fff';
+ canvas.fillText('Label', worldX, worldY);
+},
+```
+
+## 设置
+
+### 注册设置分区
+
+```typescript
+registerSettingsSection({
+ id: 'my-extension',
+ title: 'My Extension',
+ order: 10,
+});
+```
+
+### 注册设置项
+
+```typescript
+registerSettingsItem({
+ id: 'my-extension.showOverlay',
+ section: 'my-extension',
+ label: 'Show Overlay',
+ type: 'boolean',
+ defaultValue: true,
+ order: 0,
+ onChange: (value) => {
+ // 响应变更
+ },
+});
+
+registerSettingsItem({
+ id: 'my-extension.opacity',
+ section: 'my-extension',
+ label: 'Overlay Opacity',
+ type: 'range',
+ defaultValue: 0.8,
+ min: 0,
+ max: 1,
+ step: 0.1,
+ order: 1,
+});
+
+registerSettingsItem({
+ id: 'my-extension.theme',
+ section: 'my-extension',
+ label: 'Theme',
+ type: 'select',
+ defaultValue: 'dark',
+ options: [
+ { label: 'Dark', value: 'dark' },
+ { label: 'Light', value: 'light' },
+ ],
+ order: 2,
+});
+```
+
+### 设置项类型
+
+| 类型 | 说明 | 额外字段 |
+|------|------|----------|
+| `boolean` | 开关 | — |
+| `number` | 数字输入 | `min`、`max`、`step` |
+| `string` | 文本输入 | — |
+| `color` | 颜色选择器 | — |
+| `select` | 下拉菜单 | `options: [{ label, value }]` |
+| `range` | 滑块 | `min`、`max`、`step` |
+
+### 读写设置
+
+```typescript
+const show = getSettingsValue<boolean>('my-extension.showOverlay');
+setSettingsValue('my-extension.opacity', 0.5);
+```
+
+设置自动持久化到 `localStorage`。
+
+## 状态栏项
+
+在底部状态栏添加自定义控件:
+
+```typescript
+registerStatusbarItem({
+ id: 'my-fps-counter',
+ position: 'right',
+ order: 0,
+ render: (container) => {
+ const span = document.createElement('span');
+ span.style.fontSize = '11px';
+ container.appendChild(span);
+
+ let lastTime = performance.now();
+ let frameCount = 0;
+
+ const tick = () => {
+ frameCount++;
+ const now = performance.now();
+ const elapsed = now - lastTime;
+ if (elapsed >= 1000) {
+ span.textContent = `FPS: ${Math.round(frameCount * 1000 / elapsed)}`;
+ frameCount = 0;
+ lastTime = now;
+ }
+ handle = requestAnimationFrame(tick);
+ };
+ let handle = requestAnimationFrame(tick);
+
+ return {
+ dispose() { cancelAnimationFrame(handle); },
+ update() {},
+ };
+ },
+});
+```
+
+| 字段 | 类型 | 必需 | 说明 |
+|------|------|------|------|
+| `id` | string | 是 | 唯一标识 |
+| `position` | `'left' \| 'right'` | 是 | 状态栏位置 |
+| `order` | number | 否 | 排序 |
+| `render` | (container) => \{ dispose, update? \} | 是 | 创建控件 |
+
+## UI 工具
+
+### Toast 通知
+
+```typescript
+showToast({ title: 'Hello', message: 'World', type: 'info', duration: 3000 });
+showSuccessToast('Done!', 'Build completed');
+showErrorToast('Error', 'Failed to compile');
+```
+
+### 对话框
+
+```typescript
+const name = await showInputDialog({
+ title: 'Rename Entity',
+ label: 'New name:',
+ defaultValue: 'Entity',
+});
+
+const confirmed = await showConfirmDialog({
+ title: 'Delete Entity',
+ message: 'Are you sure?',
+});
+```
+
+### 右键菜单
+
+```typescript
+showContextMenu({
+ x: event.clientX,
+ y: event.clientY,
+ items: [
+ { label: 'Copy', action: () => copy() },
+ { label: 'Paste', action: () => paste() },
+ { separator: true },
+ { label: 'Delete', action: () => del() },
+ ],
+});
+```
+
+## 组件 Schema
+
+为检查器面板注册自定义组件 Schema:
+
+```typescript
+registerComponentSchema({
+ name: 'Health',
+ category: 'script',
+ properties: [
+ { name: 'current', type: 'number', min: 0, max: 1000 },
+ { name: 'max', type: 'number', min: 1, max: 1000 },
+ { name: 'regenRate', type: 'number', min: 0, step: 0.1 },
+ ],
+});
+```
+
+<Aside type="note">
+ 使用 `defineComponent()` 定义的游戏脚本组件会自动注册。仅在需要自定义属性元数据(min/max、step、枚举选项等)时使用 `registerComponentSchema`。
+</Aside>
+
+## 属性编辑器
+
+为属性类型注册自定义检查器控件:
+
+```typescript
+registerPropertyEditor('my-gradient', (container, ctx) => {
+ const input = document.createElement('input');
+ input.type = 'color';
+ input.value = ctx.value as string;
+ input.addEventListener('input', () => ctx.onChange(input.value));
+ container.appendChild(input);
+
+ return {
+ update(value) { input.value = value as string; },
+ dispose() { container.innerHTML = ''; },
+ };
+});
+```
+
+然后在组件 Schema 中引用该类型:
+
+```typescript
+registerComponentSchema({
+ name: 'Gradient',
+ category: 'script',
+ properties: [
+ { name: 'startColor', type: 'my-gradient' },
+ { name: 'endColor', type: 'my-gradient' },
+ ],
+});
+```
+
+## Bounds Provider
+
+注册自定义边界计算用于 Gizmo 显示:
+
+```typescript
+registerBoundsProvider('CircleCollider', {
+ getBounds(data: any) {
+ const r = data.radius ?? 50;
+ return { width: r * 2, height: r * 2 };
+ },
+});
+```
+
+## 资源清理
+
+编辑器在重载时会自动清理扩展注册的菜单、面板、Gizmo 和设置。对于自定义资源(定时器、事件监听器、GPU 资源),使用 `onDispose`:
+
+```typescript
+const interval = setInterval(tick, 100);
+onDispose(() => clearInterval(interval));
+
+const shader = Material.createShader(vertSrc, fragSrc);
+// 通过扩展 API 创建的着色器会自动清理
+
+registerDrawCallback('my-overlay', drawFn);
+// 通过扩展 API 注册的绘制回调会自动清理
+```
+
+自动跟踪的资源:
+- 绘制回调(`registerDrawCallback`)
+- 后处理 Pass(`PostProcess.addPass`)
+- 着色器(`Material.createShader`)
+
+## 示例:原点十字准星
+
+一个完整的扩展示例,在世界原点绘制十字准星并提供设置开关:
+
+```typescript
+import {
+ registerSettingsSection,
+ registerSettingsItem,
+ getSettingsValue,
+ registerDrawCallback,
+ Draw,
+} from '@esengine/editor';
+
+registerSettingsSection({ id: 'debug-overlay', title: 'Debug Overlay', order: 20 });
+registerSettingsItem({
+ id: 'debug-overlay.showOrigin',
+ section: 'debug-overlay',
+ label: 'Show Origin Crosshair',
+ type: 'boolean',
+ defaultValue: true,
+});
+registerSettingsItem({
+ id: 'debug-overlay.size',
+ section: 'debug-overlay',
+ label: 'Crosshair Size',
+ type: 'range',
+ defaultValue: 50,
+ min: 10,
+ max: 200,
+ step: 10,
+});
+
+registerDrawCallback('origin-crosshair', () => {
+ if (!getSettingsValue('debug-overlay.showOrigin')) return;
+ const size = getSettingsValue<number>('debug-overlay.size');
+ const red = { x: 1, y: 0, z: 0, w: 1 };
+ const green = { x: 0, y: 1, z: 0, w: 1 };
+ Draw.line({ x: 0, y: 0 }, { x: size, y: 0 }, red, 2);
+ Draw.line({ x: 0, y: 0 }, { x: 0, y: size }, green, 2);
+ Draw.circleOutline({ x: 0, y: 0 }, 4, { x: 1, y: 1, z: 1, w: 1 }, 1);
+});
+```
+
+## 下一步
+
+- [自定义绘制](/microes/zh/guides/custom-draw/) — 扩展叠加层的 Draw API
+- [材质与着色器](/microes/zh/guides/materials/) — 自定义 Gizmo 的着色器创建
+- [后处理效果](/microes/zh/guides/post-processing/) — 从扩展添加后处理 Pass
diff --git a/docs/astro/src/content/docs/zh/guides/geometry.mdx b/docs/astro/src/content/docs/zh/guides/geometry.mdx
new file mode 100644
index 000000000..e09d076a6
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/geometry.mdx
@@ -0,0 +1,216 @@
+---
+title: 几何体与网格
+description: ESEngine 自定义网格创建与管理
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+Geometry API 创建自定义网格,用于 `Draw.drawMesh()` 和 `Draw.drawMeshWithMaterial()`。可以构建四边形、圆形、多边形,或完全自定义的顶点数据来实现粒子、拖尾等程序化效果。
+
+## 创建网格
+
+以交错格式定义顶点,并用 layout 描述每个属性:
+
+```typescript
+import { Geometry, DataType } from 'esengine';
+
+const triangle = Geometry.create({
+ vertices: new Float32Array([
+ // x, y, u, v
+ 0, 50, 0.5, 1,
+ -50, -50, 0, 0,
+ 50, -50, 1, 0,
+ ]),
+ layout: [
+ { name: 'a_position', type: DataType.Float2 },
+ { name: 'a_texCoord', type: DataType.Float2 },
+ ],
+ indices: new Uint16Array([0, 1, 2]),
+});
+```
+
+返回 `GeometryHandle`(number 类型)。将其传递给绘制回调中的 `Draw.drawMesh()` 或 `Draw.drawMeshWithMaterial()`。
+
+## DataType
+
+| 值 | 名称 | 分量数 |
+|----|------|--------|
+| 1 | `Float` | 1 float |
+| 2 | `Float2` | 2 floats |
+| 3 | `Float3` | 3 floats |
+| 4 | `Float4` | 4 floats |
+| 5 | `Int` | 1 int |
+| 6 | `Int2` | 2 ints |
+| 7 | `Int3` | 3 ints |
+| 8 | `Int4` | 4 ints |
+
+## GeometryOptions
+
+| 字段 | 类型 | 必需 | 说明 |
+|------|------|------|------|
+| `vertices` | Float32Array | 是 | 交错格式的顶点数据 |
+| `layout` | VertexAttributeDescriptor[] | 是 | 描述顶点格式的属性布局 |
+| `indices` | Uint16Array \| Uint32Array | 否 | 索引数据 |
+| `dynamic` | boolean | 否 | 设为 `true` 以支持频繁更新(默认 `false`) |
+
+<Aside type="note">
+ 缓冲区限制:顶点最多 64K floats,索引最多 16K。支持 `Uint16Array` 和 `Uint32Array` 两种索引格式。
+</Aside>
+
+## 辅助函数
+
+### createQuad
+
+创建居中的带纹理坐标的四边形:
+
+```typescript
+const quad = Geometry.createQuad(100, 80); // 宽, 高
+```
+
+布局:`a_position` (Float2) + `a_texCoord` (Float2)。默认尺寸 1x1。
+
+### createCircle
+
+使用中心顶点和径向段创建圆形网格:
+
+```typescript
+const circle = Geometry.createCircle(50, 64); // 半径, 段数
+```
+
+布局:`a_position` (Float2) + `a_texCoord` (Float2)。默认半径 1,段数 32。
+
+### createPolygon
+
+从点数组创建多边形,自动生成纹理坐标并进行扇形三角化:
+
+```typescript
+const hex = Geometry.createPolygon([
+ { x: 50, y: 0 },
+ { x: 25, y: 43 },
+ { x: -25, y: 43 },
+ { x: -50, y: 0 },
+ { x: -25, y: -43 },
+ { x: 25, y: -43 },
+]);
+```
+
+至少需要 3 个点。布局:`a_position` (Float2) + `a_texCoord` (Float2)。
+
+## 使用 Geometry 绘制
+
+在绘制回调中使用几何体:
+
+```typescript
+import { registerDrawCallback, Draw, Geometry, Material, BlendMode } from 'esengine';
+
+const quad = Geometry.createQuad(100, 100);
+const mat = Material.create({
+ shader: myShader,
+ uniforms: { u_color: { x: 1, y: 0, z: 0, w: 1 } },
+ blendMode: BlendMode.Normal,
+});
+
+const identity = new Float32Array([
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ 0, 0, 0, 1,
+]);
+
+registerDrawCallback('custom-mesh', () => {
+ Draw.drawMeshWithMaterial(quad, mat, identity);
+});
+```
+
+参见[自定义绘制](/microes/zh/guides/custom-draw/)了解完整 Draw API,以及[材质与着色器](/microes/zh/guides/materials/)了解着色器和材质创建。
+
+## 动态更新
+
+对于每帧变化的网格(粒子、拖尾),创建时设置 `dynamic: true` 并调用 `updateVertices`:
+
+```typescript
+const mesh = Geometry.create({
+ vertices: initialVertices,
+ layout: [
+ { name: 'a_position', type: DataType.Float2 },
+ { name: 'a_texCoord', type: DataType.Float2 },
+ ],
+ indices,
+ dynamic: true,
+});
+
+// 每帧更新
+Geometry.updateVertices(mesh, newVertices);
+Geometry.updateVertices(mesh, partialData, offsetInFloats);
+```
+
+## 资源管理
+
+不再需要时释放几何体:
+
+```typescript
+Geometry.release(handle);
+const valid = Geometry.isValid(handle);
+```
+
+## 示例:粒子拖尾
+
+每帧更新动态网格以渲染运动对象后面的拖尾:
+
+```typescript
+import { registerDrawCallback, Draw, Geometry, DataType, Material } from 'esengine';
+
+const MAX_POINTS = 64;
+const FLOATS_PER_VERTEX = 4; // x, y, u, v
+const vertices = new Float32Array(MAX_POINTS * 2 * FLOATS_PER_VERTEX);
+const indices = new Uint16Array((MAX_POINTS - 1) * 6);
+
+for (let i = 0; i < MAX_POINTS - 1; i++) {
+ const base = i * 2;
+ const idx = i * 6;
+ indices[idx] = base;
+ indices[idx + 1] = base + 1;
+ indices[idx + 2] = base + 2;
+ indices[idx + 3] = base + 2;
+ indices[idx + 4] = base + 1;
+ indices[idx + 5] = base + 3;
+}
+
+const trail = Geometry.create({
+ vertices,
+ layout: [
+ { name: 'a_position', type: DataType.Float2 },
+ { name: 'a_texCoord', type: DataType.Float2 },
+ ],
+ indices,
+ dynamic: true,
+});
+
+const transform = new Float32Array([
+ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1,
+]);
+
+registerDrawCallback('trail', () => {
+ // 用拖尾点位置更新顶点数据...
+ Geometry.updateVertices(trail, vertices);
+ Draw.drawMeshWithMaterial(trail, trailMaterial, transform);
+});
+```
+
+## 完整 API 参考
+
+| 方法 | 说明 |
+|------|------|
+| `Geometry.create(options)` | 从顶点、布局和可选索引创建几何体 |
+| `Geometry.updateVertices(handle, vertices, offset?)` | 更新动态几何体的顶点数据 |
+| `Geometry.release(handle)` | 释放几何体 |
+| `Geometry.isValid(handle)` | 检查句柄是否有效 |
+| `Geometry.createQuad(width?, height?)` | 创建居中四边形(带 UV) |
+| `Geometry.createCircle(radius?, segments?)` | 创建圆形网格 |
+| `Geometry.createPolygon(points)` | 从点数组创建多边形 |
+
+## 下一步
+
+- [自定义绘制](/microes/zh/guides/custom-draw/) — 绘制网格和图元
+- [材质与着色器](/microes/zh/guides/materials/) — 网格的着色器和材质
+- [后处理效果](/microes/zh/guides/post-processing/) — 全屏效果
diff --git a/docs/astro/src/content/docs/zh/guides/materials.mdx b/docs/astro/src/content/docs/zh/guides/materials.mdx
index ebc97efdd..ab7142461 100644
--- a/docs/astro/src/content/docs/zh/guides/materials.mdx
+++ b/docs/astro/src/content/docs/zh/guides/materials.mdx
@@ -119,7 +119,7 @@ const instance = Material.createInstance(sourceMat);
Material.setUniform(instance, 'u_tint', { x: 0, y: 1, z: 0, w: 1 });
```
-## 着色器文件格式(.shader)
+## 着色器文件格式(.esshader)
着色器文件使用 `#pragma` 指令分隔顶点和片段部分:
@@ -165,10 +165,10 @@ void main() {
通过资源服务器加载着色器文件:
```typescript
-const shader = await assets.loadShader('assets/effects/glow.shader');
+const shader = await assets.loadShader('assets/effects/glow.esshader');
```
-## 材质文件格式(.material)
+## 材质文件格式(.esmaterial)
材质可以定义为 JSON 文件,通过资源服务器加载:
@@ -176,7 +176,7 @@ const shader = await assets.loadShader('assets/effects/glow.shader');
{
"version": "1.0",
"type": "material",
- "shader": "effects/glow.shader",
+ "shader": "effects/glow.esshader",
"blendMode": 1,
"depthTest": false,
"properties": {
@@ -190,13 +190,13 @@ const shader = await assets.loadShader('assets/effects/glow.shader');
|------|------|------|
| `version` | string | 格式版本(`"1.0"`) |
| `type` | string | 必须为 `"material"` |
-| `shader` | string | .shader 文件路径(相对于材质文件或绝对路径) |
+| `shader` | string | .esshader 文件路径(相对于材质文件或绝对路径) |
| `blendMode` | number | BlendMode 枚举值 |
| `depthTest` | boolean | 启用深度测试 |
| `properties` | object | uniform 名称/值对 |
```typescript
-const loaded = await assets.loadMaterial('assets/effects/glow.material');
+const loaded = await assets.loadMaterial('assets/effects/glow.esmaterial');
sprite.material = loaded.handle;
```
@@ -245,7 +245,7 @@ addSystem(defineSystem(
| `Material.releaseShader(shader)` | 释放着色器 |
| `Material.create(options)` | 创建材质 |
| `Material.createInstance(source)` | 创建共享着色器的材质实例 |
-| `Material.createFromAsset(data, shader)` | 从解析的 .material 文件创建 |
+| `Material.createFromAsset(data, shader)` | 从解析的 .esmaterial 文件创建 |
| `Material.setUniform(mat, name, value)` | 设置 uniform 值 |
| `Material.getUniform(mat, name)` | 获取 uniform 值 |
| `Material.getUniforms(mat)` | 获取所有 uniform(Map) |
diff --git a/docs/astro/src/content/docs/zh/guides/post-processing.mdx b/docs/astro/src/content/docs/zh/guides/post-processing.mdx
new file mode 100644
index 000000000..5342a051c
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/post-processing.mdx
@@ -0,0 +1,211 @@
+---
+title: 后处理效果
+description: ESEngine 全屏后处理效果管线
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+PostProcess API 在场景渲染完成后应用全屏着色器效果。可以链式添加多个 pass 来实现模糊、暗角、灰度、色差等效果。
+
+## 初始化
+
+使用画布尺寸初始化管线:
+
+```typescript
+import { PostProcess } from 'esengine';
+
+PostProcess.init(canvas.width, canvas.height);
+```
+
+<Aside type="note">
+ `PostProcess.begin()` 和 `PostProcess.end()` 由引擎内部调用。你只需配置 pass 和 uniform。
+</Aside>
+
+## 添加 Pass
+
+创建内置效果着色器并添加为命名 pass:
+
+```typescript
+const blurShader = PostProcess.createBlur();
+PostProcess.addPass('blur', blurShader);
+PostProcess.setUniform('blur', 'u_intensity', 2.0);
+```
+
+Pass 按添加顺序执行。每个 pass 读取前一个 pass 的输出作为 `u_texture`。
+
+## 内置效果
+
+| 方法 | 效果 | Uniform |
+|------|------|---------|
+| `createBlur()` | 高斯模糊 | `u_intensity` (float) — 模糊扩散, `u_resolution` (vec2) — 自动 |
+| `createVignette()` | 暗角 | `u_intensity` (float) — 半径, `u_softness` (float) — 衰减 |
+| `createGrayscale()` | 灰度 | `u_intensity` (float, 0–1) — 混合比例 |
+| `createChromaticAberration()` | 色差 | `u_intensity` (float) — 偏移量, `u_resolution` (vec2) — 自动 |
+
+<Aside type="tip">
+ `u_resolution` 由引擎自动设置,你只需设置其他 uniform。
+</Aside>
+
+### 模糊
+
+9 次采样高斯模糊。`u_intensity` 越大模糊越强:
+
+```typescript
+const blur = PostProcess.createBlur();
+PostProcess.addPass('blur', blur);
+PostProcess.setUniform('blur', 'u_intensity', 3.0);
+```
+
+### 暗角
+
+使屏幕边缘变暗。`u_intensity` 控制半径,`u_softness` 控制衰减:
+
+```typescript
+const vignette = PostProcess.createVignette();
+PostProcess.addPass('vignette', vignette);
+PostProcess.setUniform('vignette', 'u_intensity', 0.8);
+PostProcess.setUniform('vignette', 'u_softness', 0.4);
+```
+
+### 灰度
+
+在原色和灰度之间混合。`u_intensity` 为 `1.0` 时完全灰度:
+
+```typescript
+const gray = PostProcess.createGrayscale();
+PostProcess.addPass('grayscale', gray);
+PostProcess.setUniform('grayscale', 'u_intensity', 1.0);
+```
+
+### 色差
+
+偏移 R 和 B 通道以产生镜头畸变效果:
+
+```typescript
+const ca = PostProcess.createChromaticAberration();
+PostProcess.addPass('chromatic', ca);
+PostProcess.setUniform('chromatic', 'u_intensity', 2.0);
+```
+
+## Pass 管理
+
+```typescript
+PostProcess.setEnabled('blur', false); // 禁用 pass
+PostProcess.setEnabled('blur', true); // 重新启用
+PostProcess.removePass('blur'); // 完全移除
+const count = PostProcess.getPassCount(); // pass 数量
+```
+
+## 设置 Uniform
+
+```typescript
+PostProcess.setUniform('blur', 'u_intensity', 5.0);
+PostProcess.setUniformVec4('custom', 'u_tint', { x: 1, y: 0.8, z: 0.6, w: 1 });
+```
+
+## 旁路模式
+
+没有活跃 pass 时,启用旁路模式跳过 FBO 开销:
+
+```typescript
+PostProcess.setBypass(true); // 直接渲染到屏幕
+PostProcess.setBypass(false); // 使用管线
+
+const bypassed = PostProcess.isBypassed();
+```
+
+## 窗口缩放
+
+画布尺寸变化时更新帧缓冲尺寸:
+
+```typescript
+window.addEventListener('resize', () => {
+ PostProcess.resize(canvas.width, canvas.height);
+});
+```
+
+## 自定义 Pass
+
+编写自定义片段着色器并添加为 pass。顶点着色器是固定的全屏四边形,你只需编写片段着色器:
+
+```typescript
+import { Material, PostProcess } from 'esengine';
+
+const invertShader = Material.createShader(
+ `#version 300 es
+ precision highp float;
+ layout(location = 0) in vec2 a_position;
+ layout(location = 1) in vec2 a_texCoord;
+ out vec2 v_texCoord;
+ void main() {
+ v_texCoord = a_texCoord;
+ gl_Position = vec4(a_position, 0.0, 1.0);
+ }`,
+ `#version 300 es
+ precision highp float;
+ in vec2 v_texCoord;
+ uniform sampler2D u_texture;
+ uniform float u_intensity;
+ out vec4 fragColor;
+ void main() {
+ vec4 color = texture(u_texture, v_texCoord);
+ vec3 inverted = mix(color.rgb, 1.0 - color.rgb, u_intensity);
+ fragColor = vec4(inverted, color.a);
+ }`
+);
+
+PostProcess.addPass('invert', invertShader);
+PostProcess.setUniform('invert', 'u_intensity', 1.0);
+```
+
+参见[材质与着色器](/microes/zh/guides/materials/)了解更多着色器编写方法。
+
+## 示例:暂停菜单模糊
+
+游戏暂停时启用模糊和灰度效果:
+
+```typescript
+import { PostProcess } from 'esengine';
+
+const blurShader = PostProcess.createBlur();
+const grayShader = PostProcess.createGrayscale();
+PostProcess.addPass('pause-blur', blurShader);
+PostProcess.addPass('pause-gray', grayShader);
+PostProcess.setEnabled('pause-blur', false);
+PostProcess.setEnabled('pause-gray', false);
+
+function setPaused(paused: boolean) {
+ PostProcess.setEnabled('pause-blur', paused);
+ PostProcess.setEnabled('pause-gray', paused);
+ PostProcess.setUniform('pause-blur', 'u_intensity', 4.0);
+ PostProcess.setUniform('pause-gray', 'u_intensity', 0.6);
+}
+```
+
+## 完整 API 参考
+
+| 方法 | 说明 |
+|------|------|
+| `PostProcess.init(width, height)` | 初始化管线 |
+| `PostProcess.shutdown()` | 关闭管线 |
+| `PostProcess.resize(width, height)` | 更新帧缓冲尺寸 |
+| `PostProcess.addPass(name, shader)` | 添加命名 pass |
+| `PostProcess.removePass(name)` | 移除 pass |
+| `PostProcess.setEnabled(name, enabled)` | 启用或禁用 pass |
+| `PostProcess.isEnabled(name)` | 检查 pass 是否启用 |
+| `PostProcess.setUniform(pass, name, value)` | 设置 float uniform |
+| `PostProcess.setUniformVec4(pass, name, value)` | 设置 vec4 uniform |
+| `PostProcess.getPassCount()` | 获取 pass 数量 |
+| `PostProcess.isInitialized()` | 检查管线是否活跃 |
+| `PostProcess.setBypass(bypass)` | 启用或禁用旁路模式 |
+| `PostProcess.isBypassed()` | 检查旁路状态 |
+| `PostProcess.createBlur()` | 创建模糊效果着色器 |
+| `PostProcess.createVignette()` | 创建暗角效果着色器 |
+| `PostProcess.createGrayscale()` | 创建灰度效果着色器 |
+| `PostProcess.createChromaticAberration()` | 创建色差效果着色器 |
+
+## 下一步
+
+- [自定义绘制](/microes/zh/guides/custom-draw/) — 即时模式绘图图元
+- [材质与着色器](/microes/zh/guides/materials/) — 着色器创建和 uniform
+- [渲染概览](/microes/zh/guides/rendering/) — 相机、变换、渲染顺序
diff --git a/docs/astro/src/content/docs/zh/guides/rendering.mdx b/docs/astro/src/content/docs/zh/guides/rendering.mdx
index de1c26ec2..a5774512f 100644
--- a/docs/astro/src/content/docs/zh/guides/rendering.mdx
+++ b/docs/astro/src/content/docs/zh/guides/rendering.mdx
@@ -98,3 +98,11 @@ transform.scale = { x: -1, y: 1, z: 1 }; // 水平翻转
<Aside type="tip">
C++ 后端负责所有 WebGL 渲染。你只需设置组件数据,引擎每帧自动绘制一切。
</Aside>
+
+## 下一步
+
+- [精灵](/microes/zh/guides/sprite/) — 精灵渲染和动画
+- [Spine 动画](/microes/zh/guides/spine/) — 骨骼动画
+- [自定义绘制](/microes/zh/guides/custom-draw/) — 即时模式绘图,用于调试可视化和动态图形
+- [后处理效果](/microes/zh/guides/post-processing/) — 全屏效果(模糊、暗角、灰度)
+- [几何体与网格](/microes/zh/guides/geometry/) — 自定义网格创建