Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Zyie
Copy link
Member

@Zyie Zyie commented Aug 20, 2025

Summary

This PR introduces initial support for the gl2D file format, which enables serialization of PixiJS scenes into a JSON-based structure. The goal is to provide a standardized way to save, load, and share any 2D scenes, while ensuring resources can be efficiently reused across nodes and scenes.

Design

A scene is represented as two main components:

  • Resources – reusable assets such as textures, web fonts, spritesheets, images, and videos.
  • Nodes – scene graph elements that reference resources.

For textures specifically:

  • All textures are stored within the resources section.
  • Each texture defines a source (e.g., ImageSource, Spritesheet, VideoSource) to describe how it was created.

Additionally, all nodes and resources can be extended via extensions, allowing custom metadata and features to be attached.

Example API

// Import everything (serialize + deserialize)
import 'pixi.js/gl2d';
// Import all serialize mixins
import 'pixi.js/gl2d/serialize';
// Import all parsers
import 'pixi.js/gl2d/deserialize';

import { GL2D } from 'pixi.js';

// Serialize a PixiJS scene into gl2D
const serializedScene = await GL2D.serialize(app.stage);
// Deserialize without reloading (if resources are still present)
const clone = await GL2D.deserialize(serializedScene);

// Or load it directly via Assets
const clone = await Assets.load('path/to/scene.gl2d');

app.stage.addChild(clone);

gl2D Spec

gl2D Spec & Example

Example JSON

{
  "asset": {
    "generator": "PixiJS",
    "version": "1.0"
  },
  "extensionsUsed": [
    "pixi_container_node",
    "pixi_texture_source_resource",
    "pixi_texture_resource",
    "pixi_sprite_node"
  ],
  "extensionsRequired": ["pixi_container_node"],
  "resources": [
    {
      "uid": "texture_source_3",
      "type": "image_source",
      "uri": "/assets/bunny.1.webp",
      "width": 26,
      "height": 37,
      "resolution": 1,
      "format": "bgra8unorm",
      "antialias": false,
      "alphaMode": "premultiply-alpha-on-upload",
      "addressModeU": "clamp-to-edge",
      "addressModeV": "clamp-to-edge",
      "addressModeW": "clamp-to-edge",
      "magFilter": "linear",
      "minFilter": "linear",
      "mipmapFilter": "linear",
      "extensions": {
        "pixi_texture_source_resource": {
          "autoGarbageCollect": true,
          "mipLevelCount": 1,
          "maxAnisotropy": 1,
          "dimensions": "2d",
          "autoGenerateMipmaps": false
        }
      }
    },
    {
      "type": "texture",
      "uid": "texture_3",
      "name": "http://localhost:8081/assets/bunny.1.webp",
      "frame": [0, 0, 26, 37],
      "source": 0,
      "extensions": {
        "pixi_texture_resource": {
          "orig": [0, 0, 26, 37],
          "rotate": 0,
          "dynamic": false
        }
      }
    }
  ],
  "nodes": [
    {
      "type": "container",
      "uid": "container_2",
      "children": [1],
      "alpha": 1,
      "visible": true,
      "tint": 16777215,
      "blendMode": "inherit",
      "extensions": {
        "pixi_container_node": {
          "skew": [0, 0],
          "pivot": [0, 0],
          "origin": [0, 0],
          "isRenderGroup": false,
          "zIndex": 0,
          "sortableChildren": false,
          "renderable": true
        }
      }
    },
    {
      "name": "Sprite",
      "type": "sprite",
      "uid": "container_4",
      "children": [],
      "matrix": [1, 0, 24, 0, 1, 24, 0, 0, 1],
      "alpha": 1,
      "visible": true,
      "tint": 16777215,
      "blendMode": "inherit",
      "extensions": {
        "pixi_container_node": {
          "skew": [0, 0],
          "pivot": [0, 0],
          "origin": [0, 0],
          "isRenderGroup": false,
          "zIndex": 0,
          "sortableChildren": false,
          "renderable": true,
          "anchor": [0, 0]
        },
        "pixi_sprite_node": {
          "roundPixels": false
        }
      },
      "texture": 1
    }
  ]
}

NOTE

This is the first of several PR that will add all the different resources and node types, along with the deserialisation methods. Just splitting everything up to be more manageable.

Implements initial support for the gl2D file format, enabling the serialization of PixiJS scenes into a JSON-based structure.

- Introduces core gl2D file structure, including assets, scenes, nodes, and resources.
- Adds extension capabilities for custom metadata.
- Enables serialization of containers, sprites, textures, and sources.
- Adds documentation for the gl2D file format.
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR title doesn't match the required format. The title should be in this format:

chore: update Text docs
fix: text not rendering
feat: add new feature to Text
breaking: remove Text#resolution 

@Zyie Zyie changed the title Feat: Adds gl2D file format support feat: Adds gl2D file format support Aug 20, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your PR title doesn't match the required format. The title should be in this format:

chore: update Text docs
fix: text not rendering
feat: add new feature to Text
breaking: remove Text#resolution 

Copy link

pkg-pr-new bot commented Aug 20, 2025

pixi.js-basepixi.js-bunny-mark

npm i https://pkg.pr.new/pixijs/pixijs/pixi.js@11628

commit: 5e12f6e

@bigtimebuddy
Copy link
Member

I'm SUPER excited about the opportunities and tooling this will enable for working with Pixi. Remind me a lot of the best of working with Flash where it was so much easier to decouple the view and logic.

Zyie added 8 commits August 21, 2025 11:36
Moves gl2D serialization to a class for better organization
and future extensibility. It also renames a utility function
to more accurately reflect its purpose and updates relevant
references.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants