Cocos Creator:介绍

推荐:将NSDT场景编辑器加入你的3D工具链
3D工具集:NSDT简石数字孪生

介绍

从 Cocos Creator 3.7.0 开始,我们将生成 JS 绑定代码的方法从绑定生成器切换到 Swig。Swig 通过解析其与 .有关我们为什么切换到 Swig 的更多信息,您可以参考 这个问题 .interfaceC++

为引擎生成 JS 绑定代码

  • 确保您已安装 NodeJS (>= v8.9.4)
  • 打开终端 (macOS/Linux) 或命令行工具 (Windows),导航到engine/native/tools/swig-config
  • node genbindings.js

如果成功,您将看到以下文本:

======================================================================
    Congratulations, JS binding code was generated successfully!
======================================================================
  • 如果失败,则需要检查输出并确定文件中是否存在一些错误。.i

为开发人员的项目生成 JS 绑定代码

  • 确保您已安装 NodeJS (>= v8.9.4)
  • 打开终端 (macOS/Linux) 或命令行工具 (Windows)
  • 为生成的代码创建一个目录,例如/Users/abc/my-project/native/engine/common/Classes/bindings/auto

编写 JS 配置文件

创建 JS 配置文件,例如 包含以下内容/Users/abc/my-project/tools/swig-config/swig-config.js

'use strict';
const path = require('path');

// Developer's custom module configuration
// configList is required
const configList = [
  [ 'your_module_interface_0.i', 'jsb_your_module_interface_0_auto.cpp' ],
  [ 'your_module_interface_1.i', 'jsb_your_module_interface_1_auto.cpp' ],
  // ......
];

const projectRoot = path.resolve(path.join(__dirname, '..', '..'));
// interfaceDir is optional
const interfacesDir = path.join(projectRoot, 'tools', 'swig-config');
// bindingsOutDir is optional
const bindingsOutDir = path.join(projectRoot, 'native', 'engine', 'common', 'Classes', 'bindings', 'auto');

module.exports = {
  interfacesDir, // optional, if it isn't exported, the items in configList should be absolute or relative to current directory of swig-config.js
  bindingsOutDir, // optional, if it isn't exported, the items in configList should be absolute or relative to current directory of swig-config.js
  configList // required
};

运行以下命令

# If current workspace is not in '/Users/abc/my-project/tools/swig-config'
$ node < Engine Root Path >/native/tools/swig-config/genbindings.js -c /Users/abc/my-project/tools/swig-config/swig-config.js
# If you have already navigate to '/Users/abc/my-project/tools/swig-config' directory, you could run the command without -c argument like:
$ cd /Users/abc/my-project/tools/swig-config
$ node < Engine Root Path >/native/tools/swig-config/genbindings.js

切换界面文件

  • 目录中有一个swig-interface-template.i,只需将其复制并重命名到项目中的某个位置即可。有一些注释演示了如何在文件中配置模块。例如,您还可以在 中引用引擎内部文件,或者快速入门。engine/native/tools/swig-config.i.iengine/native/tools/swig-configscene.iassets.i
  • 如果您使用的是 ,则可以安装扩展,该扩展是为突出显示语法支持而开发的。Visual Studio CodeSWIG LanguageHong-She Liang
  • 有关编写文件的更多详细信息,请访问教程部分

3D建模学习工作室 翻译整理,转载请注明出处

上一篇:Cocos Creator:使用 JSB 自动绑定 (mvrlink.com)

下一篇:Cocos Creator:Cocos Creator 中的 Swig 工作流教程 (mvrlink.com)

NSDT场景编辑器 | NSDT 数字孪生 | GLTF在线编辑器 | 3D模型在线转换 | UnrealSynth虚幻合成数据生成器 | 3D模型自动纹理化工具
2023 power by nsdt©鄂ICP备2023000829号