Convert Figma logo to code with AI

galacean logoengine

A typescript interactive engine, support 2D, 3D, animation, physics, built on WebGL and glTF.

4,161
299
4,161
312

Top Related Projects

9,523

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

101,622

JavaScript 3D Library.

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.

43,739

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

🇨🇭 A React renderer for Three.js

Quick Overview

Galacean Engine is a high-performance 3D rendering engine for web applications. It provides a powerful set of tools and APIs for creating interactive 3D graphics, games, and visualizations in web browsers using WebGL technology.

Pros

  • High performance and optimized for web-based 3D rendering
  • Comprehensive feature set including physics, animation, and particle systems
  • Active development and regular updates
  • Cross-platform compatibility (works on desktop and mobile browsers)

Cons

  • Steeper learning curve compared to some simpler 3D libraries
  • Documentation could be more extensive and beginner-friendly
  • Limited ecosystem of third-party plugins and extensions
  • Performance may vary on older or less powerful devices

Code Examples

Creating a basic scene with a rotating cube:

import { Engine, Scene, Camera, Vector3, MeshRenderer, PrimitiveMesh } from "@galacean/engine";

const engine = await Engine.create();
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();

const cameraEntity = rootEntity.createChild("Camera");
cameraEntity.addComponent(Camera);
cameraEntity.transform.setPosition(0, 0, 10);

const cubeEntity = rootEntity.createChild("Cube");
const renderer = cubeEntity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);

engine.run();

function animate() {
  cubeEntity.transform.rotate(new Vector3(0, 1, 0), 0.01);
  requestAnimationFrame(animate);
}
animate();

Adding a point light to the scene:

import { PointLight } from "@galacean/engine";

const lightEntity = rootEntity.createChild("PointLight");
const pointLight = lightEntity.addComponent(PointLight);
pointLight.intensity = 1.5;
lightEntity.transform.setPosition(0, 2, 2);

Implementing basic physics:

import { PhysicsManager, BoxColliderShape, DynamicCollider } from "@galacean/engine";

PhysicsManager.initialize();

const collider = cubeEntity.addComponent(DynamicCollider);
const boxShape = new BoxColliderShape();
boxShape.size.set(1, 1, 1);
collider.addShape(boxShape);

Getting Started

To get started with Galacean Engine, follow these steps:

  1. Install the package:

    npm install @galacean/engine
    
  2. Import and initialize the engine in your project:

    import { Engine } from "@galacean/engine";
    
    async function init() {
      const engine = await Engine.create();
      const scene = engine.sceneManager.activeScene;
      // Add your scene setup code here
      engine.run();
    }
    
    init();
    
  3. Start building your 3D scene by adding entities, components, and implementing your desired functionality using the Galacean Engine APIs.

Competitor Comparisons

9,523

JavaScript game engine built on WebGL, WebGPU, WebXR and glTF

Pros of PlayCanvas Engine

  • More mature and established project with a larger community and ecosystem
  • Comprehensive documentation and extensive learning resources
  • Built-in visual editor for easier scene creation and management

Cons of PlayCanvas Engine

  • Larger file size and potentially higher performance overhead
  • Less flexible for low-level customization and optimization
  • Steeper learning curve for developers new to game engines

Code Comparison

PlayCanvas Engine:

var entity = new pc.Entity();
entity.addComponent('model', {
    type: 'box'
});
app.root.addChild(entity);

Galacean Engine:

const entity = engine.createEntity('box');
const renderer = entity.addComponent(MeshRenderer);
renderer.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);

Both engines use an entity-component system, but Galacean's approach appears more modular and explicit in component creation. PlayCanvas offers a more concise syntax for common operations, while Galacean provides finer control over entity and component creation.

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

Pros of Babylon.js

  • More mature and established project with a larger community and ecosystem
  • Extensive documentation and learning resources available
  • Wider range of features and plugins for advanced 3D rendering and physics

Cons of Babylon.js

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve for beginners due to its comprehensive feature set
  • Less focused on mobile and lightweight applications compared to Engine

Code Comparison

Babylon.js:

const scene = new BABYLON.Scene(engine);
const camera = new BABYLON.FreeCamera("camera", new BABYLON.Vector3(0, 5, -10), scene);
const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2}, scene);

Engine:

const scene = new Scene();
const camera = new PerspectiveCamera(scene);
const light = new DirectionalLight(scene);
const sphere = new Sphere(scene);

Both libraries offer 3D rendering capabilities, but Babylon.js provides a more comprehensive set of features out of the box, while Engine focuses on simplicity and performance, especially for mobile devices. Babylon.js has a larger community and more resources, but may be overkill for simpler projects. Engine, on the other hand, offers a more streamlined approach but may lack some advanced features found in Babylon.js.

101,622

JavaScript 3D Library.

Pros of Three.js

  • Larger community and ecosystem, with more resources and third-party libraries
  • More comprehensive documentation and examples
  • Wider browser compatibility, including legacy support

Cons of Three.js

  • Steeper learning curve for beginners
  • Larger file size, which may impact load times for web applications
  • Less optimized for mobile devices compared to Engine

Code Comparison

Three.js:

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

Engine:

const engine = new Galacean.Engine(document.getElementById("canvas"));
const scene = engine.sceneManager.activeScene;
const camera = scene.createCamera(Galacean.Camera);
const rootEntity = scene.createRootEntity();
engine.run();

Both libraries provide similar functionality for creating 3D scenes, but Engine uses a more object-oriented approach with entities and components. Three.js offers more flexibility in setting up the rendering environment, while Engine abstracts some of these details for easier setup.

Cocos simplifies game creation and distribution with Cocos Creator, a free, open-source, cross-platform game engine. Empowering millions of developers to create high-performance, engaging 2D/3D games and instant web entertainment.

Pros of Cocos Engine

  • More mature and established project with a larger community and ecosystem
  • Comprehensive documentation and learning resources available
  • Supports multiple programming languages (JavaScript, TypeScript, C++)

Cons of Cocos Engine

  • Steeper learning curve for beginners compared to Galacean Engine
  • Larger codebase and potentially more complex architecture
  • May have more overhead for simpler projects

Code Comparison

Cocos Engine (TypeScript):

import { _decorator, Component, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('HelloWorld')
export class HelloWorld extends Component {
    start() {
        console.log('Hello, Cocos!');
    }
}

Galacean Engine (JavaScript):

import { Engine } from '@galacean/engine';

const engine = new Engine('canvas');
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity();

console.log('Hello, Galacean!');

Both engines provide ways to create and manage game objects, but Cocos Engine uses a component-based approach with decorators, while Galacean Engine focuses on a more straightforward entity-based system. Cocos Engine's syntax may be more familiar to developers coming from other game engines, while Galacean Engine's approach might be more intuitive for web developers.

43,739

The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.

Pros of PixiJS

  • More mature and widely adopted, with a larger community and ecosystem
  • Excellent performance for 2D rendering and sprite manipulation
  • Comprehensive documentation and extensive examples

Cons of PixiJS

  • Limited 3D capabilities compared to Engine
  • Steeper learning curve for complex applications
  • Larger file size, which may impact load times for web applications

Code Comparison

PixiJS:

const app = new PIXI.Application();
document.body.appendChild(app.view);
const sprite = PIXI.Sprite.from('image.png');
app.stage.addChild(sprite);
app.ticker.add(() => sprite.rotation += 0.01);

Engine:

const engine = new Galacean.Engine();
const scene = engine.sceneManager.activeScene;
const entity = scene.createEntity('sprite');
entity.addComponent(Galacean.SpriteRenderer, { texture: 'image.png' });
engine.run();

Both libraries provide easy ways to create and manipulate 2D graphics, but PixiJS focuses more on 2D rendering and sprite manipulation, while Engine offers a more comprehensive 3D-capable framework. PixiJS has a simpler API for basic 2D tasks, while Engine provides a more structured, entity-component approach that can be beneficial for larger, more complex projects.

🇨🇭 A React renderer for Three.js

Pros of react-three-fiber

  • Seamless integration with React ecosystem and component-based architecture
  • Declarative approach to 3D scene creation, making it more intuitive for React developers
  • Extensive community support and a wide range of ready-to-use components

Cons of react-three-fiber

  • Steeper learning curve for developers not familiar with React
  • Potential performance overhead due to React's reconciliation process
  • Limited low-level control compared to direct Three.js manipulation

Code Comparison

react-three-fiber:

function Cube() {
  return (
    <mesh>
      <boxGeometry args={[1, 1, 1]} />
      <meshStandardMaterial color="hotpink" />
    </mesh>
  )
}

engine:

const cube = new Mesh(engine);
cube.addComponent(MeshRenderer, {
  geometry: new BoxGeometry(engine, 1, 1, 1),
  material: new PBRMaterial(engine)
});
cube.getComponent(PBRMaterial).baseColor.set(1, 0, 0.5, 1);

react-three-fiber leverages React's component-based approach, making it more familiar to React developers. engine provides a more traditional object-oriented approach, offering finer control over individual elements but requiring more verbose code.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Galacean Engine

npm-size npm-download codecov

Galacean is a web-first and mobile-first high-performance real-time interactive engine. Use component system design and pursue ease of use and light weight. Developers can independently use and write Typescript scripts to develop projects using pure code.

image

Features

  • 🖥  Platform - Support HTML5 and Alipay miniprogram
  • 🔮  Graphics - Advanced 2D + 3D graphics engine
  • 🏃  Animation - Powerful animation system
  • 🧱  Physics - Powerful and easy-to-use physical features
  • 👆  Input - Easy-to-use interactive capabilities
  • 📑  Scripts - Use TypeScript to write logic efficiently

npm

The engine is published on npm with full typing support. To install, use:

npm install @galacean/engine

This will allow you to import engine entirely using:

import * as GALACEAN from "@galacean/engine";

or individual classes using:

import { Engine, Scene, Entity } from "@galacean/engine";

Usage

// Create engine by passing in the HTMLCanvasElement id and adjust canvas size
const engine = await WebGLEngine.create({ canvas: "canvas-id" });
engine.canvas.resizeByClientSize();

// Get scene and create root entity
const scene = engine.sceneManager.activeScene;
const rootEntity = scene.createRootEntity("Root");

// Create light
const lightEntity = rootEntity.createChild("Light");
const directLight = lightEntity.addComponent(DirectLight);
lightEntity.transform.setRotation(-45, -45, 0);
directLight.intensity = 0.4;

// Create camera
const cameraEntity = rootEntity.createChild("Camera");
cameraEntity.addComponent(Camera);
cameraEntity.transform.setPosition(0, 0, 12);

// Create sphere
const meshEntity = rootEntity.createChild("Sphere");
const meshRenderer = meshEntity.addComponent(MeshRenderer);
const material = new BlinnPhongMaterial(engine);
meshRenderer.setMaterial(material);
meshRenderer.mesh = PrimitiveMesh.createSphere(engine, 1);

// Run engine
engine.run();

Contributing

Everyone is welcome to join us! Whether you find a bug, have a great feature request or you fancy owning a task from the road map feel free to get in touch.

Make sure to read the Contributing Guide / 贡献指南 before submitting changes.

Clone

Prerequisites:

  • git-lfs (Install by official website)

Clone this repository:

git clone git@github.com:galacean/runtime.git

Build

Prerequisites:

  • Node.js v15.0.0+ and NPM (Install by official website)
  • PNPM (Install globally by npm install -g pnpm)

In the folder where you have cloned the repository, install the build dependencies using pnpm:

pnpm install

Then, to build the source, using npm:

npm run b:all

Links

License

The engine is released under the MIT license. See LICENSE file.

NPM DownloadsLast 30 Days