2025-12-03 22:15:22 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* Rapier2D 加载器配置
|
|
|
|
|
|
* Rapier2D loader configuration
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import type { WasmLibraryConfig } from '@esengine/platform-common';
|
|
|
|
|
|
import { isEditorEnvironment } from '@esengine/platform-common';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取 WASM 路径
|
|
|
|
|
|
* Get WASM path based on environment
|
2025-12-16 12:46:14 +08:00
|
|
|
|
*
|
|
|
|
|
|
* Editor: engine/rapier2d/pkg/rapier_wasm2d_bg.wasm (deployed by vite build plugin)
|
|
|
|
|
|
* Runtime: wasm/rapier_wasm2d_bg.wasm (deployed by game build)
|
2025-12-03 22:15:22 +08:00
|
|
|
|
*/
|
|
|
|
|
|
function getWasmPath(): string {
|
|
|
|
|
|
const isEditor = isEditorEnvironment();
|
2025-12-16 12:46:14 +08:00
|
|
|
|
// Editor uses dist/engine/rapier2d/pkg/ structure (from vite copy-engine-modules plugin)
|
|
|
|
|
|
// 编辑器使用 dist/engine/rapier2d/pkg/ 结构(来自 vite copy-engine-modules 插件)
|
2025-12-03 22:15:22 +08:00
|
|
|
|
const path = isEditor
|
2025-12-16 12:46:14 +08:00
|
|
|
|
? 'engine/rapier2d/pkg/rapier_wasm2d_bg.wasm'
|
2025-12-03 22:15:22 +08:00
|
|
|
|
: 'wasm/rapier_wasm2d_bg.wasm';
|
|
|
|
|
|
|
|
|
|
|
|
console.log(`[Rapier2D] isEditor=${isEditor}, wasmPath=${path}`);
|
|
|
|
|
|
return path;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* Rapier2D 加载器配置
|
|
|
|
|
|
*
|
|
|
|
|
|
* Web 平台:使用标准版(独立 WASM 文件)
|
|
|
|
|
|
* 小游戏平台:使用独立 WASM 文件 + WXWebAssembly 加载
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const Rapier2DLoaderConfig: WasmLibraryConfig = {
|
|
|
|
|
|
name: 'Rapier2D',
|
|
|
|
|
|
|
|
|
|
|
|
web: {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* WASM 文件路径
|
2025-12-16 12:46:14 +08:00
|
|
|
|
* 编辑器: engine/rapier2d/pkg/rapier_wasm2d_bg.wasm
|
2025-12-03 22:15:22 +08:00
|
|
|
|
* 运行时: wasm/rapier_wasm2d_bg.wasm
|
|
|
|
|
|
*/
|
|
|
|
|
|
get wasmPath(): string {
|
|
|
|
|
|
return getWasmPath();
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
minigame: {
|
|
|
|
|
|
/**
|
|
|
|
|
|
* WASM 文件路径(相对于小游戏根目录)
|
|
|
|
|
|
*/
|
|
|
|
|
|
wasmPath: 'wasm/rapier_wasm2d_bg.wasm',
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* iOS 微信小游戏需要 TextDecoder polyfill
|
|
|
|
|
|
*/
|
|
|
|
|
|
needsTextDecoderPolyfill: true,
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* iOS 微信小游戏需要 TextEncoder polyfill
|
|
|
|
|
|
*/
|
|
|
|
|
|
needsTextEncoderPolyfill: true,
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|