Feat/plugin support, allow third_party feat(spine) to create plugin for creator. - #306
Open
Tianze-Chen wants to merge 3 commits into
Open
Feat/plugin support, allow third_party feat(spine) to create plugin for creator.#306Tianze-Chen wants to merge 3 commits into
Tianze-Chen wants to merge 3 commits into
Conversation
- 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>
Contributor
Author
|
@cocos-robot run test cases |
Code Size Check Report
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 无。
|
|
@Tianze-Chen, Please check the result of
Task Details
|
|
@Tianze-Chen, Please check the result of
Task Details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Re: #
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: