Skip to content

Feat/plugin support, allow third_party feat(spine) to create plugin for creator. - #306

Open
Tianze-Chen wants to merge 3 commits into
cocos:v4.0.0from
Tianze-Chen:feat/plugin_support
Open

Feat/plugin support, allow third_party feat(spine) to create plugin for creator.#306
Tianze-Chen wants to merge 3 commits into
cocos:v4.0.0from
Tianze-Chen:feat/plugin_support

Conversation

@Tianze-Chen

Copy link
Copy Markdown
Contributor

Re: #

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

Developer and others added 3 commits August 24, 2026 11:00
- Add UIMesh component consuming pre-baked vertex/index/segment data, enabling custom renderers (e.g. spine plugin) to batch through the 2D batcher.
- Export UIMesh from the 2d components index.

Co-Authored-By: Claude <noreply@anthropic.com>
(cherry picked from commit 75d217348f7bb2e91668ed4148966393473b6f0d)
- Default the built-in Spine feature (spine-3.8) to off in feature cropping, so it is only included when enabled in the editor.
- Recognize scale as a valid spine atlas page attribute in the texture inspector.
- Skip incomplete platform dirs when bundling runtime adapters.

Co-Authored-By: Claude <noreply@anthropic.com>
(cherry picked from commit 7f7922aaf42ff1857f0a6d38970a75d303032f57)
- Add exports/webassembly.ts re-exporting pal/wasm (instantiateWasm, fetchBuffer, fetchUrl, ensureWasmModuleReady) as the public cc.wasm namespace, so extensions/game code can load their own .wasm files through the engine's platform-adaptive path.
- Expose it as a croppable feature rather than an unconditional export from exports/base.ts: cc.config.json declares a `webassembly` feature and editor/engine-features/render-config.json adds the panel entry (default on, required), so it appears under Project Settings -> Feature Cropping. The label/description are plain text on purpose — i18n:ENGINE.* keys live in the editor package and a custom engine cannot add them.

(cherry picked from commit 92003ab4a21b6ee753cf3ba2ca0f4767658e9cdc)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Tianze-Chen
Tianze-Chen requested a review from star-e August 24, 2026 10:12
@Tianze-Chen

Copy link
Copy Markdown
Contributor Author

@cocos-robot run test cases

@github-actions

Copy link
Copy Markdown

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1015436 bytes 1018274 bytes ⚠️ +2838 bytes
2D All (legacy pipeline) 2683233 bytes 2686084 bytes ⚠️ +2851 bytes
2D All (new pipeline) 2775492 bytes 2778338 bytes ⚠️ +2846 bytes
(2D + 3D) All 10032934 bytes 10036178 bytes ⚠️ +3244 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16869352 bytes 16872406 bytes ⚠️ +3054 bytes

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -2681,8 +2681,61 @@
         protected _applyFontTexture(): void;
         protected changeMaterialForDefine(): void;
     }
     /**
+     * @en A segment of the mesh: a range of indices drawn with one texture+material.
+     * @zh 网格的一个片段:一段索引,用同一纹理+材质绘制。
+     */
+    export interface UIMeshSegment {
+        indexOffset: number;
+        indexCount: number;
+        texture: Texture2D | null;
+        material: renderer.MaterialInstance | null;
+    }
+    /**
+     * @en Pre-baked mesh data for one frame.
+     * @zh 一帧的预烘焙网格数据。
+     * vertexStride: 24 (single-color V3F_T2F_C4B) or 28 (two-color V3F_T2F_C4B_C4B).
+     */
+    export interface UIMeshData {
+        vertexCount: number;
+        vertexStride: number;
+        vertexData: Uint8Array;
+        indexCount: number;
+        indexData: Uint8Array;
+        segments: UIMeshSegment[];
+    }
+    /**
+     * @en A generic 2D mesh renderer that consumes pre-baked vertex/index data.
+     * The data provider (e.g. a spine plugin) fills setMeshData every frame; this
+     * component handles buffer allocation, batching and submission.
+     * @zh 通用 2D 网格渲染器,消费预烘焙的顶点/索引数据。数据提供方(如 spine 插件)
+     * 每帧调用 setMeshData,本组件负责缓冲分配、合批与提交。
+     */
+    export class UIMesh extends UIRenderer {
+        protected _enableBatch: boolean;
+        protected _meshData: UIMeshData | null;
+        protected _useTint: boolean;
+        protected _accessor: __private._cocos_2d_renderer_static_vb_accessor__StaticVBAccessor | null;
+        protected _tintAccessor: __private._cocos_2d_renderer_static_vb_accessor__StaticVBAccessor | null;
+        constructor();
+        /**
+         * @en Feeds the pre-baked mesh data for the current frame.
+         * @zh 喂入当前帧的预烘焙网格数据。
+         */
+        setMeshData(data: UIMeshData): void;
+        /**
+         * @en Whether to enable sprite batching.
+         * @zh 是否启用合批。
+         */
+        get enableBatch(): boolean;
+        set enableBatch(value: boolean);
+        protected _flushAssembler(): void;
+        updateRenderer(): void;
+        protected _render(batcher: any): void;
+        protected createRenderEntity(): __private._cocos_2d_renderer_render_entity__RenderEntity;
+    }
+    /**
      * @en
      * The Mask Component.
      *
      * @zh
@@ -61334,8 +61387,34 @@
         stop(): void;
     }
     /**
      * @en
+     * The engine's packaged cross-platform WebAssembly interface (pal/wasm).
+     *
+     * Re-exported under the public `cc.wasm` namespace so extension/game code can
+     * load its own `.wasm` files through the same platform-adaptive path the engine
+     * uses internally for box2d / physx / spine / webgpu:
+     *
+     *   - web:      fetch the `.wasm` bytes, then `WebAssembly.instantiate`;
+     *   - mini-game: resolve the path into `cocos-js/` and delegate to the platform's
+     *               `CCWebAssembly.instantiate` (which accepts a file path, never
+     *               raw bytes — this is why embedded-base64 wasm fails there);
+     *   - native:   read the file from `src/cocos-js/` via `fileUtils`.
+     *
+     * The `wasmUrl` argument is a bare file name (e.g. `'foo.wasm'`) whose file is
+     * expected to land in the build output's `cocos-js/` directory.
+     * @zh
+     * 引擎封装好的跨平台 WebAssembly 接口(pal/wasm),通过 `cc.wasm` 命名空间公开,
+     * 供扩展/游戏代码用与引擎内部一致的路径加载自己的 `.wasm`。
+     */
+    export const wasm: {
+        instantiateWasm: typeof __private._pal_wasm__instantiateWasm;
+        fetchBuffer: typeof __private._pal_wasm__fetchBuffer;
+        fetchUrl: typeof __private._pal_wasm__fetchUrl;
+        ensureWasmModuleReady: typeof __private._pal_wasm__ensureWasmModuleReady;
+    };
+    /**
+     * @en
      * WebView component, used to display web pages in the game.
      * Since different platforms have different authorizations, APIs, and control methods for WebView components, there is no unified standard yet.
      * So currently only Web, iOS, and Android platforms are supported.
      * @zh
@@ -75998,8 +76077,33 @@
             enable(): void;
             disable(noPause?: boolean): void;
             syncMatrix(): void;
         }
+        /**
+         * The first parameter of standard `Webassembly.instantiate` interface is the arraybuffer of wasm.
+         * But the implementation on some platforms is not standard.
+         * So here we provide a more commonly used interface, whose first parameter is the url of wasm.
+         *
+         * @param wasmUrl the url of wasm, this should be a url relative from build output chunk.
+         * @param importObject the standard `WebAssembly.Imports` instance
+         */
+        export function _pal_wasm__instantiateWasm(wasmUrl: string, importObject: WebAssembly.Imports): Promise<WebAssembly.WebAssemblyInstantiatedSource>;
+        /**
+         * Fetch binary data from wasm url or js mem url.
+         * NOTE: This method should only use to instantiate asm.js compiled with `-O2` options,
+         * because not all platforms support instantiate wasm by wasm binary.
+         * eg. WeChat can only instantiate wasm by wasm url.
+         *
+         * @param binaryUrl the url of wasm or js mem, this should be a url relative from build output chunk.
+         */
+        export function _pal_wasm__fetchBuffer(binaryUrl: string): Promise<ArrayBuffer>;
+        export function _pal_wasm__fetchUrl(binaryUrl: string): Promise<string>;
+        /**
+         * Sometimes we need to put wasm modules in subpackage to reduce code size.
+         * In this case we need to ensure that the wasm modules is ready before we import them.
+         * Please remember to invoke this method before we import wasm modules.
+         */
+        export function _pal_wasm__ensureWasmModuleReady(): Promise<void>;
         export enum _cocos_web_view_web_view_enums__WebViewEventType {
             /**
              * @en None.
              * @zh 无。

@github-actions

Copy link
Copy Markdown

@Tianze-Chen, Please check the result of run test cases:

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS FAIL graphics-line-join
ios PASS PASS PASS
mac PASS PASS PASS

@github-actions

Copy link
Copy Markdown

@Tianze-Chen, Please check the result of run test cases:

Task Details

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.

1 participant