@galacean/effects-core

中文文档
2.10.6发布于 2026/11/09MITTypeScriptESM + CJS近 30 天下载 3975

Galacean Effects runtime core for the web

原始使用文档
文档目录18 节
  1. Basic Concepts
  2. Core Architecture
  3. Core Modules
  4. 1. Engine Engine
  5. 2. Asset Management AssetManager
  6. 3. Composition Composition
  7. 4. VFX Element VFXItem
  8. 5. Component System Component
  9. 6. Renderer Component RendererComponent
  10. 7. Render Frame RenderFrame
  11. 8. Render Pass RenderPass
  12. 9. Geometry Geometry
  13. 10. Material Material
  14. 11. Texture Texture
  15. Plugin System
  16. Installation
  17. Dependencies
  18. API Documentation

Galacean Effects Core

The core runtime library for Galacean Effects, responsible for asset loading, scene management, and rendering.

Basic Concepts

The Composition is the fundamental unit of animation playback in Galacean Effects. The Composition class manages the entire lifecycle from data parsing (JSON -> VFXItem -> RendererComponent) to the creation, updating, and destruction of render frames (RenderFrame) and render passes (RenderPass).

Core Architecture

Engine
  ├── Composition
  │     ├── VFXItem (Element)
  │     │     ├── Component
  │     │     │     └── RendererComponent
  │     │     └── Transform
  │     ├── RenderFrame
  │     │     └── RenderPass
  │     └── Camera
  └── Resource Management
        ├── Texture
        ├── Material
        └── Geometry

Each composition contains different types of elements (VFXItem) and their components (Component), including:

  • Camera component
  • Sprite (layer) component
  • Particle system
  • Text component
  • Interactive component

When a composition is created, it completes:

  1. Loading of data assets
  2. Creation of elements (VFXItem) and their components
  3. Loading and creation of textures (Texture)
  4. Initialization of RenderFrame and RenderPass

Core Modules

1. Engine Engine

Engine is the core entry point, responsible for managing all GPU resources and the lifecycle of compositions.

import { Engine } from '@galacean/effects-core';

// Create engine
const engine = Engine.create(canvas, {
  fps: 60,
  pixelRatio: window.devicePixelRatio,
});

Main features:

  • Manages the renderer (Renderer)
  • Manages GPU resources (textures, materials, geometries)
  • Manages creation and destruction of compositions
  • Provides a ticker (Ticker) to drive the render loop
  • Handles interactive events

2. Asset Management AssetManager

Responsible for loading all resources needed for effects:

import { AssetManager } from '@galacean/effects-core';

const assetManager = new AssetManager(options);

Supported features:

  1. Loading JSON and binary resources
  2. Loading image and video resources
  3. Selective resource downloading based on render level
  4. Image/text template replacement
  5. Font loading (via AssetManager.loadFontFamily)

3. Composition Composition

Manages data processing and rendering for animation playback:

const composition = new Composition(props, scene);

// Playback control
composition.play();
composition.pause();
composition.resume();

// Update
composition.update(deltaTime);

// Dispose
composition.dispose();

Main properties:

  • renderFrame: The rendering data object for the current frame
  • rootItem: The root element of the composition
  • camera: The composition camera
  • speed: Playback speed

4. VFX Element VFXItem

The base class for all effect elements, supporting component-based architecture:

// Get component
const component = item.getComponent(SpriteComponent);

// Iterate children
item.children.forEach(child => {
  // ...
});

// Transform operations
item.transform.setPosition(x, y, z);

Main properties:

  • transform: Position, rotation, scale transforms
  • components: Component list
  • children: Child element list

5. Component System Component

Components are functional units attached to VFXItem:

abstract class Component extends EffectsObject {
  item: VFXItem;           // Owner element
  enabled: boolean;        // Whether enabled
  
  onAwake() {}             // Initialization
  onEnable() {}            // On enable
  onDisable() {}           // On disable
  onStart() {}             // Before first update
  onUpdate(dt: number) {}  // Per-frame update
  onLateUpdate(dt: number) {} // Late update
  onDestroy() {}           // On destroy
}

6. Renderer Component RendererComponent

The base class for all rendering components, responsible for adding renderable objects to render passes:

class RendererComponent extends Component {
  material: Material;      // Material
  materials: Material[];   // Material list
  priority: number;        // Render priority
  
  render(renderer: Renderer): void {}  // Render method
}

When a component is enabled, it is automatically added to the default render pass of RenderFrame.

7. Render Frame RenderFrame

The rendering data object for each frame, managing render passes and global uniforms:

interface RenderFrameOptions {
  camera: Camera,
  renderer: Renderer,
  globalVolume?: PostProcessVolume,
  postProcessingEnabled?: boolean,
}

Main features:

  • Manages RenderPass list
  • Stores camera properties
  • Manages global uniform variables (GlobalUniforms)
  • Supports post-processing (Bloom, ToneMapping)

Main methods:

  • addMeshToDefaultRenderPass(mesh: RendererComponent): Add renderer component to default render pass
  • removeMeshFromDefaultRenderPass(mesh: RendererComponent): Remove renderer component from default render pass

8. Render Pass RenderPass

Manages a group of objects to be rendered:

interface RenderPassClearAction {
  clearColor?: vec4,
  colorAction?: TextureLoadAction,
  clearDepth?: number,
  depthAction?: TextureLoadAction,
}

Features:

  • Manages render object list
  • Configures color, depth, stencil attachments
  • Sets clear behavior

9. Geometry Geometry

Abstract class for managing vertex and index data:

const geometry = Geometry.create(engine, {
  attributes: {
    aPosition: { size: 3, data: positions },
    aTexCoord: { size: 2, data: texCoords },
  },
  indices: { data: indices },
  mode: WebGLRenderingContext.TRIANGLES,
});

// Update data
geometry.setAttributeData('aPosition', newPositions);
geometry.setAttributeSubData('aPosition', offset, partialData);
geometry.setIndexData(newIndices);
geometry.setDrawCount(count);

10. Material Material

Abstract class for managing shaders and render states:

const material = Material.create(engine, {
  shader: shaderSource,
  uniformValues: {
    uColor: [1, 0, 0, 1],
  },
});

// Set render states
material.blending = true;
material.depthTest = true;
material.depthMask = true;

Render state properties:

  • blending: Color blending switch
  • blendFunction: Blend function
  • depthTest: Depth test switch
  • depthMask: Depth write switch
  • stencilTest: Stencil test switch
  • culling: Back-face culling switch

11. Texture Texture

Abstract class for managing GPU texture resources:

// From image
const texture = await Texture.fromImage(url, engine);

// From video
const texture = await Texture.fromVideo(url, engine);

// From data
const texture = Texture.create(engine, {
  sourceType: TextureSourceType.data,
  data: {
    width: 256,
    height: 256,
    data: pixelData,
  },
});

Plugin System

Supports extending functionality through plugins:

import { registerPlugin } from '@galacean/effects-core';

registerPlugin('custom', CustomLoader);

Built-in plugins:

  • sprite: Layer rendering
  • particle: Particle system
  • text: Text rendering
  • interact: Interaction handling
  • camera: Camera control

Installation

npm install @galacean/effects-core

Dependencies

  • @galacean/effects-specification: Data specification definitions
  • @galacean/effects-math: Math library

API Documentation

版本与发布记录

@galacean/effects-core 共发布 273 个版本,首次发布于 2023/11/13;过去 12 个月发布了 49 个版本。

版本发布日期距今
2.10.6latest2026/11/096 天前
2.10.52026/11/069 天前
2.11.0-alpha.3alpha2026/10/2620 天前
2.11.0-alpha.22026/10/2125 天前
2.11.0-alpha.12026/10/121 个月前
2.11.0-alpha.02026/10/121 个月前

其他发布通道:latest-2.3.x → 2.3.8,experimental → 0.0.0-experimental-20250915,beta → 2.7.0-beta.0,latest-1.x → 1.6.10,alpha → 2.11.0-alpha.3。

关于 @galacean/effects-core 的常见问题

@galacean/effects-core 是什么?

Galacean Effects runtime core for the web

如何安装 @galacean/effects-core?

在项目目录运行 npm install @galacean/effects-core,或使用 pnpm add / yarn add / bun add。

@galacean/effects-core 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@galacean/effects-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@galacean/effects-core 可以商用吗?

@galacean/effects-core 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@galacean/effects-core 的下载量有多少?

根据 npm 官方下载统计,@galacean/effects-core 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,975 次,日均约 133 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@galacean/effects-core 还在维护吗?

最新版本 2.10.6 发布于 2026/11/09(6 天前);至今共发布 273 个版本,其中过去 12 个月发布了 49 个;首次发布于 2023/11/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。