From c7e60d2bcb45d59f52a4ea279a66ff0f4a6b219e Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 16 Aug 2022 10:48:12 +0800 Subject: [PATCH] Use swig to generate js bindings (#12410) --- .github/workflows/native-bindings.yml | 12 +- .github/workflows/native-compile-linux.yml | 15 +- .../workflows/native-compile-platforms.yml | 96 +-- .github/workflows/native-linter-android.yml | 22 +- .github/workflows/native-simulator.yml | 54 +- .github/workflows/native-unit-test.yml | 65 +- cocos/core/renderer/core/render-scene.jsb.ts | 11 + native/CMakeLists.txt | 4 +- native/cocos/base/memory/Memory.h | 2 +- .../bindings/manual/jsb_cocos_manual.cpp | 10 +- native/cocos/bindings/manual/jsb_global.h | 19 +- .../bindings/manual/jsb_module_register.cpp | 2 +- native/cocos/core/Root.h | 4 + native/cocos/core/scene-graph/Node.h | 10 + .../cocos/editor-support/middleware-adapter.h | 2 +- .../assets-manager/AssetsManagerEx.h | 9 +- .../assets-manager/EventAssetsManagerEx.cpp | 2 +- .../assets-manager/EventAssetsManagerEx.h | 8 +- native/external-config.json | 2 +- native/tools/swig-config/2d.i | 183 ++++++ native/tools/swig-config/README.md | 379 ++++++++++++ native/tools/swig-config/assets.i | 238 ++++++++ native/tools/swig-config/audio.i | 99 +++ native/tools/swig-config/cocos.i | 186 ++++++ native/tools/swig-config/dragonbones.i | 424 +++++++++++++ native/tools/swig-config/editor_support.i | 108 ++++ native/tools/swig-config/extension.i | 91 +++ native/tools/swig-config/genbindings.js | 128 ++++ native/tools/swig-config/geometry.i | 137 +++++ native/tools/swig-config/gfx.i | 264 ++++++++ native/tools/swig-config/network.i | 92 +++ native/tools/swig-config/physics.i | 109 ++++ native/tools/swig-config/pipeline.i | 220 +++++++ native/tools/swig-config/renderer.i | 109 ++++ native/tools/swig-config/scene.i | 578 ++++++++++++++++++ native/tools/swig-config/spine.i | 312 ++++++++++ native/tools/swig-config/video.i | 85 +++ native/tools/swig-config/webview.i | 85 +++ 38 files changed, 3962 insertions(+), 214 deletions(-) create mode 100644 native/tools/swig-config/2d.i create mode 100644 native/tools/swig-config/README.md create mode 100644 native/tools/swig-config/assets.i create mode 100644 native/tools/swig-config/audio.i create mode 100644 native/tools/swig-config/cocos.i create mode 100644 native/tools/swig-config/dragonbones.i create mode 100644 native/tools/swig-config/editor_support.i create mode 100644 native/tools/swig-config/extension.i create mode 100644 native/tools/swig-config/genbindings.js create mode 100644 native/tools/swig-config/geometry.i create mode 100644 native/tools/swig-config/gfx.i create mode 100644 native/tools/swig-config/network.i create mode 100644 native/tools/swig-config/physics.i create mode 100644 native/tools/swig-config/pipeline.i create mode 100644 native/tools/swig-config/renderer.i create mode 100644 native/tools/swig-config/scene.i create mode 100644 native/tools/swig-config/spine.i create mode 100644 native/tools/swig-config/video.i create mode 100644 native/tools/swig-config/webview.i diff --git a/.github/workflows/native-bindings.yml b/.github/workflows/native-bindings.yml index c2886910ff..975b0e7643 100644 --- a/.github/workflows/native-bindings.yml +++ b/.github/workflows/native-bindings.yml @@ -16,20 +16,18 @@ jobs: - name: Download external libraries run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external rm -rf native/external/.git - uses: nttld/setup-ndk@v1 id: setup-ndk with: ndk-version: r21e add-to-path: false - - name: Run genbindings.py - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} + - name: Generate Bindings run: | - python3 -m pip install PyYAML==5.4.1 Cheetah3 - python3 ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Update builtin-res env: ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} diff --git a/.github/workflows/native-compile-linux.yml b/.github/workflows/native-compile-linux.yml index b5d92b6913..e069944339 100644 --- a/.github/workflows/native-compile-linux.yml +++ b/.github/workflows/native-compile-linux.yml @@ -23,19 +23,12 @@ jobs: shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python3 -m pip install PyYAML==5.4.1 Cheetah3 - python3 ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Install dependencies run: | sudo apt install libx11-dev -y diff --git a/.github/workflows/native-compile-platforms.yml b/.github/workflows/native-compile-platforms.yml index 1c1fcd25f9..874e147b6d 100644 --- a/.github/workflows/native-compile-platforms.yml +++ b/.github/workflows/native-compile-platforms.yml @@ -23,26 +23,16 @@ jobs: shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - name: Install deps run: | choco install --forcex86 vulkan-sdk - python -m pip install PyYAML==5.4.1 Cheetah3 - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false - name: Generate bindings - shell: bash - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -V - cd ./native/tools/tojs + cd ./native/tools/swig-config echo "Create auto-generated jsbinding glue codes." - python ./genbindings.py - rm userconf.ini + node genbindings.js && + git status - name: Compile win64 shell: bash env: @@ -79,19 +69,17 @@ jobs: shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - uses: nttld/setup-ndk@v1 id: setup-ndk with: ndk-version: r21e add-to-path: false - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python3 -m pip install PyYAML==5.4.1 Cheetah3 - python3 ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Compile env: COCOS_ENGINE_DEV: 1 @@ -141,19 +129,18 @@ jobs: shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - uses: nttld/setup-ndk@v1 id: setup-ndk with: ndk-version: r21e add-to-path: false - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python3 -m pip install PyYAML==5.4.1 Cheetah3 - python3 ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status + - name: Compile env: COCOS_ENGINE_DEV: 1 @@ -203,26 +190,17 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - name: Download external libraries shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external + - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - python ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Compile env: COCOS_ENGINE_DEV: 1 @@ -265,26 +243,16 @@ jobs: runs-on: macos-latest steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - name: Download external libraries shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - python ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Compile env: COCOS_ENGINE_DEV: 1 @@ -328,26 +296,16 @@ jobs: with: xcode-version: latest-stable - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - name: Download external libraries shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - python ./native/tools/tojs/genbindings.py - rm ./native/tools/tojs/userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Compile env: COCOS_ENGINE_DEV: 1 @@ -401,7 +359,7 @@ jobs: shell: bash run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - name: Setup Emscripten run: | git clone https://github.com/emscripten-core/emsdk.git ../emsdk diff --git a/.github/workflows/native-linter-android.yml b/.github/workflows/native-linter-android.yml index 3a1b8e2709..2e92a0ea6c 100644 --- a/.github/workflows/native-linter-android.yml +++ b/.github/workflows/native-linter-android.yml @@ -26,34 +26,20 @@ jobs: # Checks out a copy of your repository on the ubuntu-latest machine - name: Checkout code uses: actions/checkout@v2 - - - name: Install Python3 - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - - name: Install python deps - run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - name: Download external run: | EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external - uses: nttld/setup-ndk@v1 id: setup-ndk with: ndk-version: r21e add-to-path: false - name: Generate bindings - shell: bash - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} - run: | - python -V - cd ./native/tools/tojs - python ./genbindings.py - rm userconf.ini + cd ./native/tools/swig-config + node genbindings.js + git status - name: Get changed files uses: PatriceJiang/paths-filter@master id: listchanged diff --git a/.github/workflows/native-simulator.yml b/.github/workflows/native-simulator.yml index 9c5c894e5c..7cb45ca321 100644 --- a/.github/workflows/native-simulator.yml +++ b/.github/workflows/native-simulator.yml @@ -23,37 +23,24 @@ jobs: steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: npm install run: | npm install - - name: download external libraries + - name: Download external libraries + shell: bash run: | - node ./utils/download-deps.js + EXT_VERSION=`node ../.github/workflows/get-native-external-version.js` + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external + - name: install vulkan-sdk run: | choco install vulkan-sdk - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false - - name: pip install - run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - name: generate bindings glue codes - shell: bash - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -V - cd ./tools/tojs + cd ./tools/swig-config echo "Create auto-generated jsbinding glue codes." - python ./genbindings.py - rm userconf.ini + node genbindings.js && + git status - name: gen simulator run: | gulp gen-simulator @@ -70,33 +57,20 @@ jobs: working-directory: ${{github.workspace}}/native steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - name: npm install run: | npm install npm install gulp -g - - name: pip install - run: | - python -m pip install PyYAML Cheetah3 - name: Download external libraries run: | - node ./utils/download-deps.js - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false + EXT_VERSION=`node ../.github/workflows/get-native-external-version.js` + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external + - name: Generate bindings - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - cd ./tools/tojs - echo "Create auto-generated jsbinding glue codes." - python ./genbindings.py - rm userconf.ini + cd ./tools/swig-config + node genbindings.js + git status - name: gen simulator run: | gulp gen-simulator-release diff --git a/.github/workflows/native-unit-test.yml b/.github/workflows/native-unit-test.yml index 4a1d3635fc..19baefe516 100644 --- a/.github/workflows/native-unit-test.yml +++ b/.github/workflows/native-unit-test.yml @@ -22,27 +22,17 @@ jobs: working-directory: ${{github.workspace}}/native steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - - name: Downlad external libraties - run: | - npm install - npm install gulp -g - node ./utils/download-deps.js - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false - - name: Generate bindings + - name: Download external libraries shell: bash - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - python ./tools/tojs/genbindings.py + EXT_VERSION=`node ../.github/workflows/get-native-external-version.js` + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external + - name: Generate bindings + run: | + cd ./tools/swig-config + echo "Create auto-generated jsbinding glue codes." + node genbindings.js && + git status - name: Run Unit Tests shell: bash @@ -67,29 +57,18 @@ jobs: working-directory: ${{github.workspace}}/native steps: - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - - name: Downlad external libraties - run: | - npm install - npm install gulp -g - node ./utils/download-deps.js - - - uses: nttld/setup-ndk@v1 - id: setup-ndk - with: - ndk-version: r21e - add-to-path: false - - name: Generate bindings + - name: Download external libraries shell: bash - env: - ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }} run: | - python -m pip install PyYAML==5.4.1 Cheetah3 - python ./tools/tojs/genbindings.py + EXT_VERSION=`node ../.github/workflows/get-native-external-version.js` + git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external external + - name: Generate bindings + run: | + cd ./tools/swig-config + echo "Create auto-generated jsbinding glue codes." + node genbindings.js + git status - name: Run Sebind Tests shell: bash run: | @@ -121,12 +100,12 @@ jobs: # shell: bash # run: | # EXT_VERSION=`node ./.github/workflows/get-native-external-version.js` - # git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos-creator/engine-native-external native/external + # git clone --branch $EXT_VERSION --depth 1 https://github.com/cocos/cocos-engine-external native/external # - name: Generate bindings # run: | - # python3 -m pip install PyYAML==5.4.1 Cheetah3 - # python3 ./native/tools/tojs/genbindings.py - # rm ./native/tools/tojs/userconf.ini + # cd ./native/tools/swig-config + # node genbindings.js + # git status # - name: Install dependencies # run: | # sudo apt install libx11-dev -y diff --git a/cocos/core/renderer/core/render-scene.jsb.ts b/cocos/core/renderer/core/render-scene.jsb.ts index 70043a4608..d6ce366e69 100644 --- a/cocos/core/renderer/core/render-scene.jsb.ts +++ b/cocos/core/renderer/core/render-scene.jsb.ts @@ -41,4 +41,15 @@ export interface IRaycastResult { distance: number; } +const renderSceneProto = jsb.RenderScene.prototype; + + +Object.defineProperty(renderSceneProto, 'mainLight', { + enumerable: true, + configurable: true, + get() { + return this.getMainLight(); + } +}); + export const RenderScene = jsb.RenderScene; diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 4c4816e307..0f045abc99 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -1714,8 +1714,8 @@ if(USE_PHYSICS_PHYSX) cocos/physics/physx/joints/PhysXDistance.cpp ) cocos_source_files( - cocos/bindings/auto/jsb_physics_auto.cpp - cocos/bindings/auto/jsb_physics_auto.h + NO_WERROR NO_UBUILD cocos/bindings/auto/jsb_physics_auto.cpp + cocos/bindings/auto/jsb_physics_auto.h ) endif() diff --git a/native/cocos/base/memory/Memory.h b/native/cocos/base/memory/Memory.h index 27fe149f8a..ae9407437c 100644 --- a/native/cocos/base/memory/Memory.h +++ b/native/cocos/base/memory/Memory.h @@ -125,7 +125,7 @@ public: (p)->addRef(); \ } -#if (CC_PLATFORM == CC_PLATFORM_IOS) && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_11_0) +#if ((CC_PLATFORM == CC_PLATFORM_IOS) && (__IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_11_0)) || SWIGCOCOS #define ALIGNAS(x) #else #define ALIGNAS(x) alignas(x) diff --git a/native/cocos/bindings/manual/jsb_cocos_manual.cpp b/native/cocos/bindings/manual/jsb_cocos_manual.cpp index 4560ee9d7c..bcd98d38ac 100644 --- a/native/cocos/bindings/manual/jsb_cocos_manual.cpp +++ b/native/cocos/bindings/manual/jsb_cocos_manual.cpp @@ -600,11 +600,11 @@ static bool register_device(se::Object * /*obj*/) { // NOLINT(readability-identi } static bool register_canvas_context2d(se::Object * /*obj*/) { // NOLINT(readability-identifier-naming) - __jsb_cc_CanvasRenderingContext2D_proto->defineFunction("_setCanvasBufferUpdatedCallback", _SE(js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback)); - __jsb_cc_CanvasRenderingContext2D_proto->defineFunction("fillText", _SE(js_engine_CanvasRenderingContext2D_fillText)); - __jsb_cc_CanvasRenderingContext2D_proto->defineFunction("strokeText", _SE(js_engine_CanvasRenderingContext2D_strokeText)); - __jsb_cc_CanvasRenderingContext2D_proto->defineFunction("fillRect", _SE(js_engine_CanvasRenderingContext2D_fillRect)); - __jsb_cc_CanvasRenderingContext2D_proto->defineFunction("measureText", _SE(js_engine_CanvasRenderingContext2D_measureText)); + __jsb_cc_ICanvasRenderingContext2D_proto->defineFunction("_setCanvasBufferUpdatedCallback", _SE(js_CanvasRenderingContext2D_setCanvasBufferUpdatedCallback)); + __jsb_cc_ICanvasRenderingContext2D_proto->defineFunction("fillText", _SE(js_engine_CanvasRenderingContext2D_fillText)); + __jsb_cc_ICanvasRenderingContext2D_proto->defineFunction("strokeText", _SE(js_engine_CanvasRenderingContext2D_strokeText)); + __jsb_cc_ICanvasRenderingContext2D_proto->defineFunction("fillRect", _SE(js_engine_CanvasRenderingContext2D_fillRect)); + __jsb_cc_ICanvasRenderingContext2D_proto->defineFunction("measureText", _SE(js_engine_CanvasRenderingContext2D_measureText)); se::ScriptEngine::getInstance()->clearException(); diff --git a/native/cocos/bindings/manual/jsb_global.h b/native/cocos/bindings/manual/jsb_global.h index c9e5be4a7c..d16b67fc81 100644 --- a/native/cocos/bindings/manual/jsb_global.h +++ b/native/cocos/bindings/manual/jsb_global.h @@ -53,9 +53,22 @@ jsb_make_private_object(ARGS &&...args) { //NOLINT(readability-identifier-naming return se::shared_private_object(std::make_shared(std::forward(args)...)); } -#define JSB_MAKE_PRIVATE_OBJECT(kls, ...) jsb_make_private_object(__VA_ARGS__) -#define JSB_ALLOC(kls, ...) jsb_override_new(__VA_ARGS__) -#define JSB_FREE(kls) jsb_override_delete(kls) +template +typename std::enable_if::value, se::PrivateObjectBase *>::type +jsb_make_private_object_with_instance(T *instance) { //NOLINT(readability-identifier-naming) + return se::ccshared_private_object(instance); +} + +template +typename std::enable_if::value, se::PrivateObjectBase *>::type +jsb_make_private_object_with_instance(T *instance) { //NOLINT(readability-identifier-naming) + return se::shared_private_object(std::shared_ptr(instance)); +} + +#define JSB_MAKE_PRIVATE_OBJECT(kls, ...) jsb_make_private_object(__VA_ARGS__) +#define JSB_MAKE_PRIVATE_OBJECT_WITH_INSTANCE(instance) jsb_make_private_object_with_instance(instance) +#define JSB_ALLOC(kls, ...) jsb_override_new(__VA_ARGS__) +#define JSB_FREE(kls) jsb_override_delete(kls) namespace se { class Class; class Value; diff --git a/native/cocos/bindings/manual/jsb_module_register.cpp b/native/cocos/bindings/manual/jsb_module_register.cpp index 9df4dcd318..2c6b736aa0 100644 --- a/native/cocos/bindings/manual/jsb_module_register.cpp +++ b/native/cocos/bindings/manual/jsb_module_register.cpp @@ -136,7 +136,7 @@ bool jsb_register_all_modules() { se->addRegisterCallback(register_all_scene); se->addRegisterCallback(register_all_scene_manual); se->addRegisterCallback(register_all_render); - se->addRegisterCallback(register_all_2d); + se->addRegisterCallback(register_all_native2d); #if (CC_PLATFORM == CC_PLATFORM_IOS || CC_PLATFORM == CC_PLATFORM_MACOS) se->addRegisterCallback(register_javascript_objc_bridge); diff --git a/native/cocos/core/Root.h b/native/cocos/core/Root.h index 32876f9653..75825f49b9 100644 --- a/native/cocos/core/Root.h +++ b/native/cocos/core/Root.h @@ -140,6 +140,7 @@ public: */ void destroyScenes(); +#ifndef SWIGCOCOS template ::value>> T *createModel() { //cjh TODO: need use model pool? @@ -147,9 +148,11 @@ public: model->initialize(); return model; } +#endif void destroyModel(scene::Model *model); +#ifndef SWIGCOCOS template ::value>> T *createLight() { //TODO(xwx): need use model pool? @@ -157,6 +160,7 @@ public: light->initialize(); return light; } +#endif void destroyLight(scene::Light *light); diff --git a/native/cocos/core/scene-graph/Node.h b/native/cocos/core/scene-graph/Node.h index 0da5314b59..2242150698 100644 --- a/native/cocos/core/scene-graph/Node.h +++ b/native/cocos/core/scene-graph/Node.h @@ -110,6 +110,10 @@ public: void walk(const WalkCallback &preFunc); void walk(const WalkCallback &preFunc, const WalkCallback &postFunc); + //NOTE: swig could not parse template function in a class. + // It will trigger an error: cocos/core/scene-graph/Node.h:115: Error: Syntax error in input(3). + // Therefore, hide them in swig environment. +#ifndef SWIGCOCOS template void on(const CallbacksInvoker::KeyType &type, void (Target::*memberFn)(Args...), Target *target, bool useCapture = false); @@ -195,6 +199,8 @@ public: void targetOff(const CallbacksInvoker::KeyType &type); +#endif // SWIGCOCOS + bool destroy() override { if (CCObject::destroy()) { setActive(false); @@ -713,6 +719,8 @@ bool Node::isNode(T *obj) { return dynamic_cast(obj) != nullptr && dynamic_cast(obj) == nullptr; } +#ifndef SWIGCOCOS + template void Node::emit(const CallbacksInvoker::KeyType &type, Args &&...args) { _eventProcessor->emit(type, std::forward(args)...); @@ -853,4 +861,6 @@ bool Node::hasEventListener(const CallbacksInvoker::KeyType &type, void (Target: return _eventProcessor->hasEventListener(type, memberFn, target); } +#endif // SWIGCOCOS + } // namespace cc diff --git a/native/cocos/editor-support/middleware-adapter.h b/native/cocos/editor-support/middleware-adapter.h index f4bf8458b9..e7cab80983 100644 --- a/native/cocos/editor-support/middleware-adapter.h +++ b/native/cocos/editor-support/middleware-adapter.h @@ -134,7 +134,7 @@ public: /** Extension to set the Min / Mag filter */ - using TexParams = struct _TexParams { // NOLINT + struct TexParams { // NOLINT uint32_t minFilter; uint32_t magFilter; uint32_t wrapS; diff --git a/native/extensions/assets-manager/AssetsManagerEx.h b/native/extensions/assets-manager/AssetsManagerEx.h index 08504b5131..a3c286a01b 100644 --- a/native/extensions/assets-manager/AssetsManagerEx.h +++ b/native/extensions/assets-manager/AssetsManagerEx.h @@ -24,8 +24,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __AssetsManagerEx__ -#define __AssetsManagerEx__ +#pragma once #include #include @@ -66,8 +65,8 @@ public: FAIL_TO_UPDATE }; - const static std::string VERSION_ID; - const static std::string MANIFEST_ID; + static const std::string VERSION_ID; + static const std::string MANIFEST_ID; using VersionCompareHandle = std::function; using VerifyCallback = std::function; @@ -411,5 +410,3 @@ private: }; NS_CC_EXT_END - -#endif /* defined(__AssetsManagerEx__) */ diff --git a/native/extensions/assets-manager/EventAssetsManagerEx.cpp b/native/extensions/assets-manager/EventAssetsManagerEx.cpp index cc89c047d0..badbde2f05 100644 --- a/native/extensions/assets-manager/EventAssetsManagerEx.cpp +++ b/native/extensions/assets-manager/EventAssetsManagerEx.cpp @@ -31,7 +31,7 @@ NS_CC_EXT_BEGIN -EventAssetsManagerEx::EventAssetsManagerEx(const std::string & /*eventName*/, cc::extension::AssetsManagerEx *manager, const EventCode &code, std::string assetId /* = "" */, std::string message /* = "" */, int curleCode /* = CURLE_OK*/, int curlmCode /* = CURLM_OK*/) +EventAssetsManagerEx::EventAssetsManagerEx(const std::string & /*eventName*/, cc::extension::AssetsManagerEx *manager, EventCode code, std::string assetId /* = "" */, std::string message /* = "" */, int curleCode /* = CURLE_OK*/, int curlmCode /* = CURLM_OK*/) : _code(code), _manager(manager), _message(std::move(message)), diff --git a/native/extensions/assets-manager/EventAssetsManagerEx.h b/native/extensions/assets-manager/EventAssetsManagerEx.h index 29903742e5..2d50cbb5aa 100644 --- a/native/extensions/assets-manager/EventAssetsManagerEx.h +++ b/native/extensions/assets-manager/EventAssetsManagerEx.h @@ -23,8 +23,7 @@ THE SOFTWARE. ****************************************************************************/ -#ifndef __cocos2d_libs__CCEventAssetsManagerEx__ -#define __cocos2d_libs__CCEventAssetsManagerEx__ +#pragma once #include #include "base/RefCounted.h" @@ -91,11 +90,11 @@ public: int getTotalFiles() const; /** Constructor */ - EventAssetsManagerEx(const std::string &eventName, cc::extension::AssetsManagerEx *manager, const EventCode &code, std::string assetId = "", std::string message = "", int curleCode = 0, int curlmCode = 0); + EventAssetsManagerEx(const std::string &eventName, cc::extension::AssetsManagerEx *manager, EventCode code, std::string assetId = "", std::string message = "", int curleCode = 0, int curlmCode = 0); -private: ~EventAssetsManagerEx() override = default; +private: EventCode _code; cc::extension::AssetsManagerEx *_manager; @@ -111,4 +110,3 @@ private: NS_CC_EXT_END -#endif /* defined(__cocos2d_libs__CCEventAssetsManagerEx__) */ diff --git a/native/external-config.json b/native/external-config.json index 9fcfd89886..d837e9d79f 100644 --- a/native/external-config.json +++ b/native/external-config.json @@ -3,6 +3,6 @@ "type": "github", "owner": "cocos-creator", "name": "engine-native-external", - "checkout": "v3d-gfx-128" + "checkout": "v3d-gfx-131" } } diff --git a/native/tools/swig-config/2d.i b/native/tools/swig-config/2d.i new file mode 100644 index 0000000000..b1a3549514 --- /dev/null +++ b/native/tools/swig-config/2d.i @@ -0,0 +1,183 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// native2d at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="n2d") native2d + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "2d/renderer/RenderDrawInfo.h" +#include "2d/renderer/UIMeshBuffer.h" +#include "2d/renderer/Batcher2d.h" +#include "2d/renderer/RenderEntity.h" +#include "2d/renderer/UIModelProxy.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_2d_auto.h" +#include "bindings/auto/jsb_scene_auto.h" +#include "bindings/auto/jsb_gfx_auto.h" +#include "bindings/auto/jsb_assets_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +%ignore UserData; + +%ignore cc::UIMeshBuffer::requireFreeIA; +%ignore cc::UIMeshBuffer::createNewIA; +%ignore cc::UIMeshBuffer::recycleIA; +%ignore cc::UIMeshBuffer::resetIA; +%ignore cc::UIMeshBuffer::parseLayout; +%ignore cc::UIMeshBuffer::getByteOffset; +%ignore cc::UIMeshBuffer::setByteOffset; +%ignore cc::UIMeshBuffer::getVertexOffset; +%ignore cc::UIMeshBuffer::setVertexOffset; +%ignore cc::UIMeshBuffer::getIndexOffset; +%ignore cc::UIMeshBuffer::setIndexOffset; +%ignore cc::UIMeshBuffer::getDirty; +%ignore cc::UIMeshBuffer::setDirty; +%ignore cc::UIMeshBuffer::getFloatsPerVertex; +%ignore cc::UIMeshBuffer::setFloatsPerVertex; +%ignore cc::UIMeshBuffer::getAttributes; + +%ignore cc::RenderDrawInfo::getBatcher; +%ignore cc::RenderDrawInfo::setBatcher; +%ignore cc::RenderDrawInfo::parseAttrLayout; +%ignore cc::RenderDrawInfo::getRender2dLayout; +%ignore cc::RenderDrawInfo::getStride; +%ignore cc::RenderDrawInfo::getSize; +%ignore cc::RenderDrawInfo::getEnumDrawInfoType; + +%ignore cc::Batcher2d::addVertDirtyRenderer; +%ignore cc::Batcher2d::getMeshBuffer; +%ignore cc::Batcher2d::getDevice; +%ignore cc::Batcher2d::updateDescriptorSet; +%ignore cc::Batcher2d::fillBuffersAndMergeBatches; +%ignore cc::Batcher2d::walk; +%ignore cc::Batcher2d::generateBatch; +%ignore cc::Batcher2d::resetRenderStates; +%ignore cc::Batcher2d::handleDrawInfo; +%ignore cc::Batcher2d::handleComponentDraw; +%ignore cc::Batcher2d::handleModelDraw; +%ignore cc::Batcher2d::handleIADraw; +%ignore cc::Batcher2d::handleSubNode; + +%ignore cc::RenderEntity::getDynamicRenderDrawInfo; +%ignore cc::RenderEntity::getDynamicRenderDrawInfos; +%ignore cc::RenderEntity::getRenderEntityType; +%ignore cc::RenderEntity::getColorDirty; +%ignore cc::RenderEntity::getColor; +%ignore cc::RenderEntity::isEnabled; +%ignore cc::RenderEntity::getEnumStencilStage; +%ignore cc::RenderEntity::setEnumStencilStage; +%ignore cc::RenderEntity::getVBColorDirty; +%ignore cc::RenderEntity::setVBColorDirty; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +%attribute(cc::UIMeshBuffer, float*, vData, getVData, setVData); +%attribute(cc::UIMeshBuffer, uint16_t*, iData, getIData, setIData); +%attribute(cc::UIMeshBuffer, bool, useLinkData, getUseLinkData, setUseLinkData); + +%attribute(cc::RenderDrawInfo, float*, vbBuffer, getVbBuffer, setVbBuffer); +%attribute(cc::RenderDrawInfo, uint16_t*, ibBuffer, getIbBuffer, setIbBuffer); +%attribute(cc::RenderDrawInfo, float*, vDataBuffer, getVDataBuffer, setVDataBuffer); +%attribute(cc::RenderDrawInfo, uint16_t*, iDataBuffer, getIDataBuffer, setIDataBuffer); +%attribute(cc::RenderDrawInfo, cc::Material*, material, getMaterial, setMaterial); +%attribute(cc::RenderDrawInfo, cc::gfx::Texture*, texture, getTexture, setTexture); +%attribute(cc::RenderDrawInfo, cc::gfx::Sampler*, sampler, getSampler, setSampler); +%attribute(cc::RenderDrawInfo, cc::scene::Model*, model, getModel, setModel); +%attribute(cc::RenderDrawInfo, cc::Node*, subNode, getSubNode, setSubNode); + +%attribute(cc::RenderEntity, cc::Node*, node, getNode, setNode); +%attribute(cc::RenderEntity, uint32_t, staticDrawInfoSize, getStaticDrawInfoSize, setStaticDrawInfoSize); +%attribute(cc::RenderEntity, uint32_t, stencilStage, getStencilStage, setStencilStage); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" +%import "base/TypeDef.h" +%import "base/Ptr.h" +%import "base/memory/Memory.h" +%import "base/RefCounted.h" + +%import "renderer/gfx-base/GFXObject.h" +%import "renderer/gfx-base/GFXDef-common.h" +%import "renderer/gfx-base/GFXInputAssembler.h" + +%import "core/data/Object.h" +%import "core/assets/Asset.h" +%import "core/assets/Material.h" +%import "core/scene-graph/BaseNode.h" +%import "core/scene-graph/Node.h" + +%import "2d/renderer/StencilManager.h" +%import "math/Color.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "2d/renderer/UIMeshBuffer.h" +%include "2d/renderer/RenderDrawInfo.h" +%include "2d/renderer/RenderEntity.h" +%include "2d/renderer/UIModelProxy.h" +%include "2d/renderer/Batcher2d.h" diff --git a/native/tools/swig-config/README.md b/native/tools/swig-config/README.md new file mode 100644 index 0000000000..fc270da726 --- /dev/null +++ b/native/tools/swig-config/README.md @@ -0,0 +1,379 @@ +## Introduction + +From Cocos Creator 3.7.0,we switch the approch of generating JS binding code from [bindings-generator](https://github.com/cocos/cocos-engine/tree/d08a11244d2a31da1aac7af7d2aa8f1b6152e30c/native/tools/bindings-generator) to [Swig](https://www.swig.org). Swig has many benefits in generating glue code by parsing its custom `interface` file (IDL) which is compatible with `c++`. For more about why we switch to Swig, you could refer to [the issue](https://github.com/cocos/cocos-engine/issues/10792) . + +## Re-generate JS Binding Code + +- Make sure you have installed NodeJS ( `>= v8.9.4` ) + +- Open Terminal ( macOS / Linux) or Command Line Tool ( Windows ), navigate to `engine/cocos/native/tools/swig-config` + +- Run `node genbindings.js` + +- If succeed, you'll see the text: + + ``` + ====================================================================== + Congratulations, JS binding code was generated successfully! + ====================================================================== + ``` + +- If failed, you need to check the output and figure whether there're some errors in `.i` files. + +## Bind a New Module in Engine Step by Step + +- For instance, we add a new module with two `.h` files located in `engine/native/cocos/my-new-module` + + ```c++ + #pragma once + + // NOTE: The '#include<...>' at the following will not be parsed by swig by default + #include "ForImportOnly.h" + // + + // Uncomment the following line if you wanna test MyNewBaseClass::getChild. + // #define ENABLE_GET_CHILD 1 + + namespace cc { + class MY_DLL ClassToBeIgnored { + public: + void hello() {}; + }; + + // MyGrandFather will not be bound since it's defined in ForImportOnly.h and Swig will not generate glue code for it. + class MY_DLL MyNewBaseClass : public my_sub_ns::MyGrandFather { + public: + MyNewBaseClass() = default; + virtual ~MyNewBaseClass() = default; + + void fooBase(int a, bool b) { + printf("fooBase: %d, %d\n", a, (int)b); + } + inline void setEnabled(bool v) { _enabled = v; } + inline bool isEnabled() const { return _enabled; } + + inline void setIntValue(int v) { _intValue = v; } + inline int getIntValue() const { return _intValue; } + + inline void setIntAttributeToBeIgnored(int v) { _intAttributeToBeIgnored = v; } + inline int getIntAttributeToBeIgnored() const { return _intAttributeToBeIgnored; } + + void methodToBeIgnored(); + + float floatPropertyToBeIgnored{0.F}; + int publicProperty{123}; + + // Only return valid object if ENABLE_GET_CHILD is defined, + // otherwise, return undefined to JS. + MyNewBaseClass* getChild() const { + auto* p = new MyNewBaseClass(); + p->_intValue = 1234; + p->_enabled = false; + return p; + } + + private: + int _intValue{100}; + int _intAttributeToBeIgnored{200}; + bool _enabled{true}; + }; + + class MY_DLL MyNewSubClass : public MyNewBaseClass { + public: + void fooSub(const std::string& v) { + printf("fooSub: %s\n", v.c_str()); + } + + void methodBeforeRenamed(int a, int b) { + printf("methodBeforeRenamed: %d, %d\n", a, b); + } + + my_sub_ns::DeclareClass* getDeclareClass() const { return new my_sub_ns::DeclareClass(); } + }; + + class MY_DLL MyModuleSpecificClass { + public: + void foo() { + printf("MyModuleSpecificClass::foo\n"); + } + }; + + class MY_DLL TestMyModuleSpecificMethod { + public: + MyModuleSpecificClass* getModuleSpecificClass() { return nullptr; } + void foo() { + printf("TestMyModuleSpecificMethod::foo\n"); + } + }; + } + ``` + + `engine/native/cocos/my-new-module/ForImportOnly.h` + + ```c++ + #pragma once + + // NOTE: The '#include<...>' at the following will not be parsed by swig by default + #include + #include + #include + + #define MY_DLL + + namespace cc::my_sub_ns { + class DeclareClass { + public: + void foo() {} + }; + + class MyGrandFather { + protected: + MyGrandFather() = default; + virtual ~MyGrandFather() = default; + public: + void helloGrandFather() { + printf("helloGrandFather\n"); + }; + }; + } + ``` + +- Add a new swig interface file in `engine/native/cocos/tools/swig-config` directory, e.g. `my_new_module.i` with its content: + + ```c++ + // Define module + // target_namespace means the name exported to JS, could be same as which in other modules + // my_new_module at the last means the suffix of binding function name, different modules should use unique name + // Note: doesn't support number prefix + %module(target_namespace="my_ns") my_new_module + + // Insert code at the beginning of generated header file (.h) + %insert(header_file) %{ + #pragma once + #include "bindings/jswrapper/SeApi.h" + #include "bindings/manual/jsb_conversions.h" + #include "my-new-module/MyNewModule.h" + %} + + // Insert code at the beginning of generated source file (.cpp) + %{ + #include "bindings/auto/jsb_my_new_module_auto.h" + %} + + // ----- Ignore Section ------ + // Brief: Classes, methods or attributes need to be ignored + // + // Usage: + // + // %ignore your_namespace::your_class_name; + // %ignore your_namespace::your_class_name::your_method_name; + // %ignore your_namespace::your_class_name::your_attribute_name; + // + // Note: + // 1. 'Ignore Section' should be placed before attribute definition and %import/%include + // 2. namespace is needed + // + + %ignore cc::ClassToBeIngored; + // We don't wanna MyGrandFather to be the parent of MyNewBaseClass, so ignore it. + %ignore cc::my_sub_ns::MyGrandFather; + + %ignore cc::MyNewBaseClass::methodToBeIgnored; + %ignore cc::MyNewBaseClass::floatPropertyToBeIgnored; + %ignore cc::MyNewBaseClass::intAttributeToBeIgnored; + + // ----- Rename Section ------ + // Brief: Classes, methods or attributes needs to be renamed + // + // Usage: + // + // %rename(rename_to_name) your_namespace::original_class_name; + // %rename(rename_to_name) your_namespace::original_class_name::method_name; + // %rename(rename_to_name) your_namespace::original_class_name::attribute_name; + // + // Note: + // 1. 'Rename Section' should be placed before attribute definition and %import/%include + // 2. namespace is needed + + %rename(foo) cc::MyNewBaseClass::fooBase; + %rename(hello) cc::MyNewSubClass::methodBeforeRenamed; + + // ----- Module Macro Section ------ + // Brief: Generated code should be wrapped inside a macro + // Usage: + // 1. Configure for class + // %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; + // 2. Configure for member function or attribute + // %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; + // Note: Should be placed before 'Attribute Section' + + // Write your code bellow + %module_macro(USE_MY_MODULE_SPCIFIC_CLASS) cc::MyModuleSpecificClass; + %module_macro(USE_MY_MODULE_SPCIFIC_CLASS) cc::TestMyModuleSpecificMethod::getModuleSpecificClass; + %module_macro(ENABLE_GET_CHILD) cc::MyNewBaseClass::getChild; + + // ----- Attribute Section ------ + // Brief: Define attributes ( JS properties with getter and setter ) + // Usage: + // 1. Define an attribute without setter + // %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) + // 2. Define an attribute with getter and setter + // %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) + // 3. Define an attribute without getter + // %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) + // + // Note: + // 1. Don't need to add 'const' prefix for cpp_member_variable_type + // 2. The return type of getter should keep the same as the type of setter's parameter + // 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment + // 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' + // + %attribute(cc::MyNewBaseClass, bool, enabled, isEnabled, setEnabled); + %attribute(cc::MyNewBaseClass, int, intValue, getIntValue, setIntValue); + %attribute(cc::MyNewBaseClass, int, intAttributeToBeIgnored, getIntAttributeToBeIgnored, setIntAttributeToBeIgnored); + + // ----- Import Section ------ + // Brief: Import header files which are depended by 'Include Section' + // Note: + // %import "your_header_file.h" will not generate code for that header file + // + + %import "cocos/my-new-module/ForImportOnly.h" + // If we don't import ForImportOnly.h here, MY_DLL defined inside it + // will not be known by Swig, an error will be triggered like the following: + // + // MyNewModule.h:16: Error: Syntax error in input(1). + + + // ----- Include Section ------ + // Brief: Include header files in which classes and methods will be bound + %include "cocos/my-new-module/MyNewModule.h" + ``` + +- Open`engine/native/cocos/tools/swig-config/genbindings.js` file + +- Find the following code and add `my_new_module.i` at the end + + ```js + const swigConfigMap = [ + [ '2d.i', 'jsb_2d_auto.cpp' ], + ... + ... + [ 'renderer.i', 'jsb_render_auto.cpp' ], + // Add the new module config here + [ 'my_new_module', 'jsb_my_new_module_auto.cpp' ], + ]; + ``` + +- Generate bindings + + ```bash + cd engine/native/tools/swig-config + node genbindings.js + ``` + +- Modify `engine/native/cocos/CMakeLists.txt`, add `jsb_my_new_module_auto.cpp` + + ```cmake + ######## auto + cocos_source_files( + NO_WERROR NO_UBUILD cocos/bindings/auto/jsb_my_new_module_auto.cpp # Added + cocos/bindings/auto/jsb_my_new_module_auto.h # Added + NO_WERROR NO_UBUILD cocos/bindings/auto/jsb_cocos_auto.cpp + cocos/bindings/auto/jsb_cocos_auto.h + ...... + ``` + +- Open jsb_module_register.cpp, register our new module + + ```c++ + ...... + #if CC_USE_PHYSICS_PHYSX + #include "cocos/bindings/auto/jsb_physics_auto.h" + #endif + #include "cocos/bindings/auto/jsb_my_new_module_auto.h" // Add this line + + bool jsb_register_all_modules() { + se::ScriptEngine *se = se::ScriptEngine::getInstance(); + ...... + se->addRegisterCallback(register_all_my_new_module); // Add this line + + se->addAfterCleanupHook([]() { + cc::DeferredReleasePool::clear(); + JSBClassType::cleanup(); + }); + return true; + } + ``` + + + +- Add test code in your project's script + + ```typescript + const sub = new my_ns.MyNewSubClass(); + sub.foo(111, false); + sub.fooSub("hello foo sub"); + sub.hello(334, 564); + + console.log('public property: ' + sub.publicProperty); + console.log('attribute int value: ' + sub.intValue); + console.log('attribute enabled: ' + sub.enabled); + + const child = sub.getChild(); + if (child) { + console.log('child.intValue=' + child.intValue); + console.log('child.enabled=' + child.enabled); + } else { + console.error('child is invalid: ' + child); + } + + const moduleTest = new my_ns.TestMyModuleSpecificMethod(); + console.log('getModuleSpecificClass: ' + moduleTest.getModuleSpecificClass()); + ``` + +- Re-run project, if it succeeds, you will get the following output: + + ``` + fooBase: 111, 0 + fooSub: hello foo sub + methodBeforeRenamed: 334, 564 + 17:25:10 [DEBUG]: D/ JS: public property: 123 + 17:25:10 [DEBUG]: D/ JS: attribute int value: 100 + 17:25:10 [DEBUG]: D/ JS: attribute enabled: true + 17:25:10 [DEBUG]: D/ JS: [ERROR]: child is invalid: undefined + 17:25:10 [DEBUG]: D/ JS: getModuleSpecificClass: undefined + ``` + + **NOTE:** We configure `getChild` should be controlled by module macro ``ENABLE_GET_CHILD` and it's disabled by default. So invoking `getChild` in JS will return `undefined` value. + +- Test c++ module configuration + + - Open MyNewModule.h, uncomment `ENABLE_GET_CHILD` definition + + ```c++ + // Uncomment the following line if you wanna test MyNewBaseClass::getChild. + #define ENABLE_GET_CHILD 1 + + namespace cc { + class MY_DLL ClassToBeIgnored { + public: + void hello() {}; + }; + ``` + + - Re-run project, we could get the correct value of `child` now, child values are `child.intValue=1234, child.enabled=false` + + ``` + fooBase: 111, 0 + fooSub: hello foo sub + methodBeforeRenamed: 334, 564 + 17:28:49 [DEBUG]: D/ JS: public property: 123 + 17:28:49 [DEBUG]: D/ JS: attribute int value: 100 + 17:28:49 [DEBUG]: D/ JS: attribute enabled: true + 17:28:49 [DEBUG]: D/ JS: child.intValue=1234 + 17:28:49 [DEBUG]: D/ JS: child.enabled=false + 17:28:49 [DEBUG]: D/ JS: getModuleSpecificClass: undefined + ``` + + \ No newline at end of file diff --git a/native/tools/swig-config/assets.i b/native/tools/swig-config/assets.i new file mode 100644 index 0000000000..fec01d1f6b --- /dev/null +++ b/native/tools/swig-config/assets.i @@ -0,0 +1,238 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// assets at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") assets + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "core/assets/Asset.h" +#include "core/assets/BufferAsset.h" +#include "core/assets/EffectAsset.h" +#include "core/assets/ImageAsset.h" +#include "core/assets/Material.h" +#include "core/builtin/BuiltinResMgr.h" +#include "3d/assets/Morph.h" +#include "3d/assets/Mesh.h" +#include "3d/assets/Skeleton.h" +#include "3d/misc/CreateMesh.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_assets_auto.h" +#include "bindings/auto/jsb_cocos_auto.h" +#include "bindings/auto/jsb_gfx_auto.h" +#include "bindings/auto/jsb_scene_auto.h" +#include "renderer/core/PassUtils.h" +#include "renderer/gfx-base/GFXDef-common.h" +#include "renderer/pipeline/Define.h" +#include "renderer/pipeline/RenderStage.h" +#include "scene/Pass.h" +#include "scene/RenderWindow.h" +#include "core/scene-graph/Scene.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::Asset::createNode; //FIXME: swig needs to support std::function +// %ignore cc::IMemoryImageSource::data; +%ignore cc::SimpleTexture::uploadDataWithArrayBuffer; +%ignore cc::TextureCube::_mipmaps; +// %ignore cc::Mesh::copyAttribute; +// %ignore cc::Mesh::copyIndices; +%ignore cc::Material::setProperty; +%ignore cc::ImageAsset::setData; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +%rename(cpp_keyword_struct) cc::Mesh::ICreateInfo::structInfo; +%rename(cpp_keyword_switch) cc::IPassInfoFull::switch_; +%rename(cpp_keyword_register) cc::EffectAsset::registerAsset; + +%rename(_getProperty) cc::Material::getProperty; +%rename(_propsInternal) cc::Material::_props; + +%rename(_getBindposes) cc::Skeleton::getBindposes; +%rename(_setBindposes) cc::Skeleton::setBindposes; + +%rename(_data) cc::IMemoryImageSource::data; +%rename(_compressed) cc::IMemoryImageSource::compressed; + +%rename(buffer) cc::BufferAsset::getBuffer; + + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +%attribute(cc::Asset, ccstd::string&, _uuid, getUuid, setUuid); +%attribute(cc::Asset, ccstd::string, nativeUrl, getNativeUrl); +%attribute(cc::Asset, cc::NativeDep, _nativeDep, getNativeDep); +%attribute(cc::Asset, bool, isDefault, isDefault); + +%attribute(cc::ImageAsset, cc::PixelFormat, format, getFormat, setFormat); +%attribute(cc::ImageAsset, ccstd::string&, url, getUrl, setUrl); + +%attribute(cc::BufferAsset, cc::ArrayBuffer*, _nativeAsset, getNativeAssetForJS, setNativeAssetForJS); + +%attribute(cc::TextureBase, bool, isCompressed, isCompressed); +%attribute(cc::TextureBase, uint32_t, _width, getWidth, setWidth); +%attribute(cc::TextureBase, uint32_t, width, getWidth, setWidth); +%attribute(cc::TextureBase, uint32_t, _height, getHeight, setHeight); +%attribute(cc::TextureBase, uint32_t, height, getHeight, setHeight); + +%attribute(cc::SimpleTexture, uint32_t, mipmapLevel, mipmapLevel); +%attribute(cc::RenderTexture, cc::scene::RenderWindow*, window, getWindow); + +%attribute(cc::Mesh, ccstd::hash_t, _hash, getHash); +%attribute(cc::Mesh, ccstd::hash_t, hash, getHash); +%attribute(cc::Mesh, cc::Uint8Array&, data, getData); +%attribute(cc::Mesh, cc::Uint8Array&, _data, getData); +%attribute(cc::Mesh, cc::Mesh::JointBufferIndicesType&, jointBufferIndices, getJointBufferIndices); +%attribute(cc::Mesh, cc::Vec3&, maxPosition, getMaxPosition); +%attribute(cc::Mesh, cc::Vec3&, minPosition, getMinPosition); +%attribute(cc::Mesh, cc::Mesh::RenderingSubMeshList&, renderingSubMeshes, getRenderingSubMeshes); +%attribute(cc::Mesh, uint32_t, subMeshCount, getSubMeshCount); +%attribute(cc::Mesh, cc::ArrayBuffer*, _nativeAsset, getAssetData, setAssetData); +%attribute(cc::Mesh, bool, _allowDataAccess, isAllowDataAccess, setAllowDataAccess); +%attribute(cc::Mesh, bool, allowDataAccess, isAllowDataAccess, setAllowDataAccess); + +%attribute(cc::Material, cc::EffectAsset*, effectAsset, getEffectAsset, setEffectAsset); +%attribute(cc::Material, ccstd::string, effectName, getEffectName); +%attribute(cc::Material, uint32_t, technique, getTechniqueIndex); +%attribute(cc::Material, ccstd::hash_t, hash, getHash); +%attribute(cc::Material, cc::Material*, parent, getParent); + +%attribute(cc::RenderingSubMesh, cc::Mesh*, mesh, getMesh, setMesh); +%attribute(cc::RenderingSubMesh, ccstd::optional&, subMeshIdx, getSubMeshIdx, setSubMeshIdx); +%attribute(cc::RenderingSubMesh, ccstd::vector&, flatBuffers, getFlatBuffers, setFlatBuffers); +%attribute(cc::RenderingSubMesh, ccstd::vector&, _flatBuffers, getFlatBuffers, setFlatBuffers); +%attribute(cc::RenderingSubMesh, cc::gfx::BufferList&, jointMappedBuffers, getJointMappedBuffers); +%attribute(cc::RenderingSubMesh, cc::gfx::InputAssemblerInfo&, iaInfo, getIaInfo); +%attribute(cc::RenderingSubMesh, cc::gfx::InputAssemblerInfo&, _iaInfo, getIaInfo); +%attribute(cc::RenderingSubMesh, cc::gfx::PrimitiveMode, primitiveMode, getPrimitiveMode); + +%attribute(cc::Skeleton, ccstd::vector&, joints, getJoints, setJoints); +%attribute(cc::Skeleton, ccstd::vector&, _joints, getJoints, setJoints); +%attribute(cc::Skeleton, ccstd::hash_t, hash, getHash, setHash); +%attribute(cc::Skeleton, ccstd::hash_t, _hash, getHash, setHash); +%attribute(cc::Skeleton, ccstd::vector&, _invBindposes, getInverseBindposes); +%attribute(cc::Skeleton, ccstd::vector&, inverseBindposes, getInverseBindposes); + +%attribute(cc::EffectAsset, ccstd::vector &, techniques, getTechniques, setTechniques); +%attribute(cc::EffectAsset, ccstd::vector &, shaders, getShaders, setShaders); +%attribute(cc::EffectAsset, ccstd::vector &, combinations, getCombinations, setCombinations); + + + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" +%import "base/TypeDef.h" +%import "base/Ptr.h" +%import "base/memory/Memory.h" + +%include "core/Types.h" + +%import "core/ArrayBuffer.h" +%import "core/data/Object.h" +%import "core/scene-graph/Node.h" +%import "core/TypedArray.h" +%import "core/assets/AssetEnum.h" + +%import "renderer/gfx-base/GFXDef-common.h" +%import "renderer/gfx-base/GFXTexture.h" +%import "renderer/pipeline/Define.h" +%import "renderer/pipeline/RenderStage.h" +%import "renderer/core/PassUtils.h" + +%import "math/MathBase.h" +%import "math/Vec2.h" +%import "math/Vec3.h" +%import "math/Vec4.h" +%import "math/Color.h" +%import "math/Mat3.h" +%import "math/Mat4.h" +%import "math/Quaternion.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound + +%include "3d/assets/Types.h" +%include "primitive/PrimitiveDefine.h" +%include "core/assets/Asset.h" +%include "core/assets/TextureBase.h" +%include "core/assets/SimpleTexture.h" +%include "core/assets/Texture2D.h" +%include "core/assets/TextureCube.h" +%include "core/assets/RenderTexture.h" +%include "core/assets/BufferAsset.h" +%include "core/assets/EffectAsset.h" +%include "core/assets/ImageAsset.h" +%include "core/assets/SceneAsset.h" +%include "core/assets/TextAsset.h" +%include "core/assets/Material.h" +%include "core/assets/RenderingSubMesh.h" +%include "core/builtin/BuiltinResMgr.h" +%include "3d/assets/Morph.h" +%include "3d/assets/MorphRendering.h" +%include "3d/assets/Mesh.h" +%include "3d/assets/Skeleton.h" +%include "3d/misc/CreateMesh.h" + + diff --git a/native/tools/swig-config/audio.i b/native/tools/swig-config/audio.i new file mode 100644 index 0000000000..8e9fa59d4b --- /dev/null +++ b/native/tools/swig-config/audio.i @@ -0,0 +1,99 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// audio at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") audio + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "audio/include/AudioEngine.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_audio_auto.h" +%} + +// ----- Ignore Section Begin ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::AudioEngine::getPCMHeader; +%ignore cc::AudioEngine::getOriginalPCMBuffer; +%ignore cc::AudioEngine::getPCMBufferByFormat; + + + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + + + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "audio/include/Export.h" + + + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "audio/include/AudioEngine.h" + + diff --git a/native/tools/swig-config/cocos.i b/native/tools/swig-config/cocos.i new file mode 100644 index 0000000000..8f02a15c0a --- /dev/null +++ b/native/tools/swig-config/cocos.i @@ -0,0 +1,186 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// engine at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") engine + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "core/data/Object.h" +#include "core/data/JSBNativeDataHolder.h" +#include "platform/interfaces/modules/canvas/CanvasRenderingContext2D.h" +#include "platform/interfaces/modules/Device.h" +#include "platform/FileUtils.h" +#include "platform/SAXParser.h" +#include "math/Vec2.h" +#include "math/Color.h" +#include "profiler/DebugRenderer.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_cocos_auto.h" +#include "bindings/auto/jsb_gfx_auto.h" +%} + +// ----- Ignore Section Begin ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +namespace cc { +%ignore ICanvasRenderingContext2D::Delegate; +%ignore ICanvasRenderingContext2D::setCanvasBufferUpdatedCallback; +%ignore ICanvasRenderingContext2D::fillText; +%ignore ICanvasRenderingContext2D::strokeText; +%ignore ICanvasRenderingContext2D::fillRect; +%ignore ICanvasRenderingContext2D::measureText; + +%ignore FileUtils::getFileData; +%ignore FileUtils::setFilenameLookupDictionary; +%ignore FileUtils::destroyInstance; +%ignore FileUtils::getFullPathCache; +%ignore FileUtils::getContents; +%ignore FileUtils::listFilesRecursively; +%ignore FileUtils::setDelegate; + +%ignore Device::getDeviceMotionValue; + +%ignore ResizableBuffer; + +%ignore Vec2::compOp; + +%ignore SAXDelegator; +%ignore SAXParser::parse(const char* xmlData, size_t dataLength); +%ignore SAXParser::setDelegator; +%ignore SAXParser::startElement; +%ignore SAXParser::endElement; +%ignore SAXParser::textHandler; + +%ignore DebugRenderer::activate; +%ignore DebugRenderer::render; +%ignore DebugRenderer::destroy; + +%ignore DebugFontInfo; +%ignore DebugRendererInfo; + +%ignore JSBNativeDataHolder::getData; +%ignore JSBNativeDataHolder::setData; + +} + + + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +%rename(_destroy) cc::CCObject::destroy; +%rename(_destroyImmediate) cc::CCObject::destroyImmediate; +// %rename(CanvasRenderingContext2D) cc::ICanvasRenderingContext2D; +// %rename(CanvasGradient) cc::ICanvasGradient; +%rename(PlistParser) cc::SAXParser; + + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +%module_macro(CC_USE_DEBUG_RENDERER) cc::DebugTextInfo; +%module_macro(CC_USE_DEBUG_RENDERER) cc::DebugRenderer; + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +%attribute_writeonly(cc::ICanvasRenderingContext2D, float, width, setWidth); +%attribute_writeonly(cc::ICanvasRenderingContext2D, float, height, setHeight); +%attribute_writeonly(cc::ICanvasRenderingContext2D, float, lineWidth, setLineWidth); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, fillStyle, setFillStyle); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, font, setFont); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, globalCompositeOperation, setGlobalCompositeOperation); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, lineCap, setLineCap); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, strokeStyle, setStrokeStyle); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, lineJoin, setLineJoin); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, textAlign, setTextAlign); +%attribute_writeonly(cc::ICanvasRenderingContext2D, ccstd::string&, textBaseline, setTextBaseline); + +%attribute(cc::CCObject, ccstd::string&, name, getName, setName); +%attribute(cc::CCObject, cc::CCObject::Flags, hideFlags, getHideFlags, setHideFlags); +%attribute(cc::CCObject, bool, replicated, isReplicated, setReplicated); +%attribute(cc::CCObject, bool, isValid, isValid); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" +%import "base/memory/Memory.h" +%import "base/Data.h" +%import "base/Value.h" + +%import "math/MathBase.h" +%import "math/Geometry.h" +%import "math/Vec4.h" +%import "platform/interfaces/modules/IScreen.h" +%import "platform/interfaces/modules/ISystem.h" +%import "platform/interfaces/modules/INetwork.h" + + + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "core/data/Object.h" +%include "core/data/JSBNativeDataHolder.h" + +%include "platform/interfaces/modules/canvas/ICanvasRenderingContext2D.h" +%include "platform/interfaces/modules/canvas/CanvasRenderingContext2D.h" +%include "platform/interfaces/modules/Device.h" +%include "platform/FileUtils.h" +%include "platform/SAXParser.h" +%include "math/Vec2.h" +%include "math/Color.h" + +%include "profiler/DebugRenderer.h" + diff --git a/native/tools/swig-config/dragonbones.i b/native/tools/swig-config/dragonbones.i new file mode 100644 index 0000000000..1fcf252434 --- /dev/null +++ b/native/tools/swig-config/dragonbones.i @@ -0,0 +1,424 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// dragonbonse at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="dragonBones") dragonbones + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "editor-support/dragonbones-creator-support/CCDragonBonesHeaders.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_dragonbones_auto.h" +%} + +// ----- Ignore Section Begin ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore dragonBones::DragonBonesData::DragonBonesData; +%ignore dragonBones::Armature::Armature; +%ignore dragonBones::CCSlot::CCSlot; +%ignore dragonBones::WorldClock::WorldClock; +%ignore dragonBones::Animation::Animation; +%ignore dragonBones::Slot::Slot; +%ignore dragonBones::BaseFactory::BaseFactory; +%ignore dragonBones::BaseObject::BaseObject; +%ignore dragonBones::TextureData::TextureData; +%ignore dragonBones::CCTextureData::CCTextureData; +%ignore dragonBones::TextureAtlasData::TextureAtlasData; +%ignore dragonBones::CCTextureAtlasData::CCTextureAtlasData; +%ignore dragonBones::AnimationState::AnimationState; +%ignore dragonBones::EventObject::EventObject; +%ignore dragonBones::Bone::Bone; +%ignore dragonBones::Transform::Transform; +%ignore dragonBones::Matrix::Matrix; +%ignore dragonBones::TransformObject::TransformObject; +%ignore dragonBones::ArmatureData::ArmatureData; +%ignore dragonBones::BoneData::BoneData; +%ignore dragonBones::SlotData::SlotData; +%ignore dragonBones::SkinData::SkinData; +%ignore dragonBones::AnimationData::AnimationData; + +%ignore dragonBones::CCFactory::destroyInstance; +%ignore dragonBones::CCFactory::loadDragonBonesData; +%ignore dragonBones::CCFactory::loadTextureAtlasData; +%ignore dragonBones::CCFactory::getRenderOrder; + +%ignore dragonBones::BaseFactory::replaceDisplay; +%ignore dragonBones::BaseFactory::getAllTextureAtlasData; +%ignore dragonBones::BaseFactory::getAllDragonBonesData; +%ignore dragonBones::BaseFactory::getClassTypeIndex; +%ignore dragonBones::BaseFactory::replaceSlotDisplayList; +%ignore dragonBones::BaseFactory::getTextureAtlasData; +%ignore dragonBones::BaseFactory::parseTextureAtlasData; + +%ignore dragonBones::Armature::intersectsSegment; +%ignore dragonBones::Armature::getAnimatable; +%ignore dragonBones::Armature::_addConstraint; +%ignore dragonBones::Armature::getReplacedTexture; +%ignore dragonBones::Armature::setReplacedTexture; +%ignore dragonBones::Armature::getBoneByDisplay; +%ignore dragonBones::Armature::getSlotByDisplay; +%ignore dragonBones::Armature::init; +%ignore dragonBones::Armature::_sortZOrder; +%ignore dragonBones::Armature::getBones; +%ignore dragonBones::Armature::getSlots; +%ignore dragonBones::Armature::getDisplay; +%ignore dragonBones::Armature::getTypeIndex; +%ignore dragonBones::Armature::getRenderOrder; +%ignore dragonBones::Armature::_dragonBones; +%ignore dragonBones::Armature::_constraints; + +%ignore dragonBones::Animation::playConfig; +%ignore dragonBones::Animation::getAnimationConfig; +%ignore dragonBones::Animation::getTypeIndex; +%ignore dragonBones::Animation::getStates; +%ignore dragonBones::Animation::setAnimations; +%ignore dragonBones::Animation::getAnimations; + +%ignore dragonBones::Slot::setRawDisplayDatas; +%ignore dragonBones::Slot::replaceDisplayData; +%ignore dragonBones::Slot::intersectsSegment; +%ignore dragonBones::Slot::init; +%ignore dragonBones::Slot::getDisplay; +%ignore dragonBones::Slot::getRawDisplay; +%ignore dragonBones::Slot::getMeshDisplay; +%ignore dragonBones::Slot::setDisplay; +%ignore dragonBones::Slot::setDisplayList; +%ignore dragonBones::Slot::_updateBlendMode; +%ignore dragonBones::Slot::_updateVisible; +%ignore dragonBones::Slot::_setDisplayIndex; +%ignore dragonBones::Slot::_setDisplayList; +%ignore dragonBones::Slot::getDisplayList; +%ignore dragonBones::Slot::_setColor; +%ignore dragonBones::Slot::_setDisplayList; +%ignore dragonBones::Slot::_displayData; +%ignore dragonBones::Slot::_deformVertices; +%ignore dragonBones::Slot::_cachedFrameIndices; +%ignore dragonBones::Slot::_colorDirty; +%ignore dragonBones::Slot::_blendMode; +%ignore dragonBones::Slot::_pivotX; +%ignore dragonBones::Slot::_pivotY; +%ignore dragonBones::Slot::_colorTransform; +%ignore dragonBones::Slot::_slotData; +%ignore dragonBones::Slot::_rawDisplay; +%ignore dragonBones::Slot::_meshDisplay; + +%ignore dragonBones::AnimationState::init; +%ignore dragonBones::AnimationState::copyFrom; +%ignore dragonBones::AnimationState::getTypeIndex; +%ignore dragonBones::AnimationState::_actionTimeline; + +%ignore dragonBones::CCSlot::getTexture; +%ignore dragonBones::CCSlot::_onClear; +%ignore dragonBones::CCSlot::getClassTypeIndex; +%ignore dragonBones::CCSlot::getTypeIndex; +%ignore dragonBones::CCSlot::worldVerts; +%ignore dragonBones::CCSlot::worldMatrix; +%ignore dragonBones::CCSlot::_worldMatDirty; +%ignore dragonBones::CCSlot::triangles; +%ignore dragonBones::CCSlot::color; +%ignore dragonBones::CCSlot::boundsRect; + +%ignore dragonBones::Transform::operator=; +%ignore dragonBones::Transform::fromMatrix; +%ignore dragonBones::Transform::add; +%ignore dragonBones::Transform::identity; +%ignore dragonBones::Transform::minus; +%ignore dragonBones::Transform::toMatrix; + +%ignore dragonBones::Matrix::operator=; +%ignore dragonBones::Matrix::identity; +%ignore dragonBones::Matrix::concat; +%ignore dragonBones::Matrix::invert; +%ignore dragonBones::Matrix::transformPoint; +%ignore dragonBones::Matrix::transformRectangle; + +%ignore dragonBones::WorldClock::contains; +%ignore dragonBones::WorldClock::add; +%ignore dragonBones::WorldClock::remove; +%ignore dragonBones::WorldClock::clock; + +%ignore dragonBones::ArmatureData::getData; +%ignore dragonBones::ArmatureData::setUserData; +%ignore dragonBones::ArmatureData::addConstraint; +%ignore dragonBones::ArmatureData::getUserData; +%ignore dragonBones::ArmatureData::getConstraint; +%ignore dragonBones::ArmatureData::addAction; +%ignore dragonBones::ArmatureData::setCacheFrame; +%ignore dragonBones::ArmatureData::getCacheFrame; +%ignore dragonBones::ArmatureData::getTypeIndex; +%ignore dragonBones::ArmatureData::getActions; +%ignore dragonBones::ArmatureData::getDefaultActions; +%ignore dragonBones::ArmatureData::cacheFrames; +%ignore dragonBones::ArmatureData::addBone; +%ignore dragonBones::ArmatureData::addSlot; +%ignore dragonBones::ArmatureData::addSkin; +%ignore dragonBones::ArmatureData::addAnimation; +%ignore dragonBones::ArmatureData::getSortedBones; +%ignore dragonBones::ArmatureData::getSortedSlots; + +%ignore dragonBones::ArmatureData::canvas; +%ignore dragonBones::ArmatureData::userData; +%ignore dragonBones::ArmatureData::defaultActions; +%ignore dragonBones::ArmatureData::actions; +%ignore dragonBones::ArmatureData::type; +%ignore dragonBones::ArmatureData::cacheFrameRate; +%ignore dragonBones::ArmatureData::scale; +%ignore dragonBones::ArmatureData::aabb; +%ignore dragonBones::ArmatureData::animationNames; +%ignore dragonBones::ArmatureData::sortedBones; +%ignore dragonBones::ArmatureData::sortedSlots; +%ignore dragonBones::ArmatureData::bones; +%ignore dragonBones::ArmatureData::slots; +%ignore dragonBones::ArmatureData::constraints; +%ignore dragonBones::ArmatureData::skins; +%ignore dragonBones::ArmatureData::animations; +%ignore dragonBones::ArmatureData::defaultSkin; +%ignore dragonBones::ArmatureData::defaultAnimation; +%ignore dragonBones::ArmatureData::parent; + +%ignore dragonBones::BoneData::getData; +%ignore dragonBones::BoneData::getUserData; +%ignore dragonBones::BoneData::setUserData; +%ignore dragonBones::BoneData::getTypeIndex; +%ignore dragonBones::BoneData::userData; +%ignore dragonBones::BoneData::inheritTranslation; +%ignore dragonBones::BoneData::inheritRotation; +%ignore dragonBones::BoneData::inheritScale; +%ignore dragonBones::BoneData::inheritReflection; +%ignore dragonBones::BoneData::length; +%ignore dragonBones::BoneData::transform; +%ignore dragonBones::BoneData::userData; + +%ignore dragonBones::SlotData::getUserData; +%ignore dragonBones::SlotData::setUserData; +%ignore dragonBones::SlotData::getDefaultColor; +%ignore dragonBones::SlotData::createColor; +%ignore dragonBones::SlotData::setColor; +%ignore dragonBones::SlotData::getColor; +%ignore dragonBones::SlotData::getDefaultColor; +%ignore dragonBones::SlotData::getTypeIndex; +%ignore dragonBones::SlotData::color; +%ignore dragonBones::SlotData::userData; +%ignore dragonBones::SlotData::DEFAULT_COLOR; + +%ignore dragonBones::AnimationData::getActionTimeline; +%ignore dragonBones::AnimationData::setActionTimeline; +%ignore dragonBones::AnimationData::addConstraintTimeline; +%ignore dragonBones::AnimationData::setZOrderTimeline; +%ignore dragonBones::AnimationData::cacheFrames; +%ignore dragonBones::AnimationData::addBoneTimeline; +%ignore dragonBones::AnimationData::addSlotTimeline; +%ignore dragonBones::AnimationData::getSlotTimelines; +%ignore dragonBones::AnimationData::getBoneTimelines; +%ignore dragonBones::AnimationData::getConstraintTimelines; +%ignore dragonBones::AnimationData::getClassTypeIndex; +%ignore dragonBones::AnimationData::getTypeIndex; +%ignore dragonBones::AnimationData::frameIntOffset; +%ignore dragonBones::AnimationData::frameFloatOffset; +%ignore dragonBones::AnimationData::frameOffset; +%ignore dragonBones::AnimationData::scale; +%ignore dragonBones::AnimationData::cacheFrameRate; +%ignore dragonBones::AnimationData::cachedFrames; +%ignore dragonBones::AnimationData::boneTimelines; +%ignore dragonBones::AnimationData::slotTimelines; +%ignore dragonBones::AnimationData::constraintTimelines; +%ignore dragonBones::AnimationData::boneCachedFrameIndices; +%ignore dragonBones::AnimationData::slotCachedFrameIndices; +%ignore dragonBones::AnimationData::actionTimeline; +%ignore dragonBones::AnimationData::zOrderTimeline; +%ignore dragonBones::AnimationData::parent; + +%ignore dragonBones::BaseObject::getClassTypeIndex; +%ignore dragonBones::BaseObject::setObjectRecycleOrDestroyCallback; +%ignore dragonBones::BaseObject::isInPool; +%ignore dragonBones::BaseObject::getAllObjects; + +%ignore dragonBones::TextureAtlasData::getTextures; +%ignore dragonBones::TextureAtlasData::copyFrom; +%ignore dragonBones::TextureAtlasData::autoSearch; +%ignore dragonBones::TextureAtlasData::format; +%ignore dragonBones::TextureAtlasData::width; +%ignore dragonBones::TextureAtlasData::height; +%ignore dragonBones::TextureAtlasData::scale; +%ignore dragonBones::TextureAtlasData::imagePath; +%ignore dragonBones::TextureAtlasData::textures; + +%ignore dragonBones::DragonBonesData::autoSearch; +%ignore dragonBones::DragonBonesData::frameRate; +%ignore dragonBones::DragonBonesData::version; +%ignore dragonBones::DragonBonesData::frameIndices; +%ignore dragonBones::DragonBonesData::cachedFrames; +%ignore dragonBones::DragonBonesData::armatureNames; +%ignore dragonBones::DragonBonesData::armatures; +%ignore dragonBones::DragonBonesData::binary; +%ignore dragonBones::DragonBonesData::intArray; +%ignore dragonBones::DragonBonesData::floatArray; +%ignore dragonBones::DragonBonesData::frameIntArray; +%ignore dragonBones::DragonBonesData::frameFloatArray; +%ignore dragonBones::DragonBonesData::frameArray; +%ignore dragonBones::DragonBonesData::timelineArray; +%ignore dragonBones::DragonBonesData::userData; +%ignore dragonBones::DragonBonesData::getUserData; +%ignore dragonBones::DragonBonesData::setUserData; +%ignore dragonBones::DragonBonesData::getTypeIndex; + +%ignore dragonBones::SkinData::replaceDisplay; +%ignore dragonBones::SkinData::setRawDisplayDatas; +%ignore dragonBones::SkinData::replaceDisplayData; +%ignore dragonBones::SkinData::addDisplay; +%ignore dragonBones::SkinData::getDisplay; +%ignore dragonBones::SkinData::getDisplays; +%ignore dragonBones::SkinData::getSlotDisplays; +%ignore dragonBones::SkinData::getTypeIndex; +%ignore dragonBones::SkinData::displays; +%ignore dragonBones::SkinData::parent; + +%ignore dragonBones::Bone::getTypeIndex; +%ignore dragonBones::Bone::_cachedFrameIndices; + +%ignore dragonBones::EventObject::getData; +%ignore dragonBones::EventObject::actionData; +%ignore dragonBones::EventObject::data; +%ignore dragonBones::EventObject::getTypeIndex; +%ignore dragonBones::EventObject::actionDataToInstance; + +%ignore dragonBones::TextureData::copyFrom; +%ignore dragonBones::TextureData::rotated; +%ignore dragonBones::TextureData::name; +%ignore dragonBones::TextureData::region; +%ignore dragonBones::TextureData::frame; +%ignore dragonBones::TextureData::parent; + +%ignore dragonBones::CCTextureAtlasData::setRenderTexture; +%ignore dragonBones::CCTextureAtlasData::getRenderTexture; +%ignore dragonBones::CCTextureAtlasData::getTypeIndex; + +%ignore dragonBones::CCTextureData::getTypeIndex; + +%ignore dragonBones::CCArmatureDisplay::render; +%ignore dragonBones::CCArmatureDisplay::update; +%ignore dragonBones::CCArmatureDisplay::getRenderOrder; + +%ignore dragonBones::RealTimeAttachUtil::syncAttachedNode; + +%ignore dragonBones::CacheModeAttachUtil::syncAttachedNode; + +%ignore dragonBones::AttachUtilBase::releaseAttachedNode; + +%ignore dragonBones::CCArmatureCacheDisplay::getRenderOrder; + +%ignore dragonBones::ArmatureCache::SegmentData; +%ignore dragonBones::ArmatureCache::BoneData; +%ignore dragonBones::ArmatureCache::ColorData; +%ignore dragonBones::ArmatureCache::FrameData; +%ignore dragonBones::ArmatureCache::AnimationData; + + + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +%rename (armature) dragonBones::CCArmatureCacheDisplay::getArmature; +%rename (armature) dragonBones::CCArmatureDisplay::getArmature; + + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + + + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "editor-support/dragonbones/core/DragonBones.h" + + + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "editor-support/dragonbones/geom/Rectangle.h" +%include "editor-support/dragonbones/geom/Transform.h" +%include "editor-support/dragonbones/geom/Matrix.h" + +%include "editor-support/dragonbones/core/BaseObject.h" +%include "editor-support/dragonbones/event/EventObject.h" +%include "editor-support/dragonbones/factory/BaseFactory.h" + +%include "editor-support/dragonbones/model/DragonBonesData.h" +%include "editor-support/dragonbones/model/TextureAtlasData.h" +%include "editor-support/dragonbones/model/ArmatureData.h" +%include "editor-support/dragonbones/model/SkinData.h" +%include "editor-support/dragonbones/model/AnimationData.h" + +%include "editor-support/dragonbones/animation/WorldClock.h" +%include "editor-support/dragonbones/animation/Animation.h" +%include "editor-support/dragonbones/animation/AnimationState.h" + +%include "editor-support/dragonbones/armature/TransformObject.h" +%include "editor-support/dragonbones/armature/Slot.h" +%include "editor-support/dragonbones/armature/Bone.h" +%include "editor-support/dragonbones/armature/Armature.h" + +%include "editor-support/dragonbones-creator-support/CCArmatureDisplay.h" +%include "editor-support/dragonbones-creator-support/CCFactory.h" +%include "editor-support/dragonbones-creator-support/CCSlot.h" +%include "editor-support/dragonbones-creator-support/CCArmatureCacheDisplay.h" +%include "editor-support/dragonbones-creator-support/ArmatureCache.h" +%include "editor-support/dragonbones-creator-support/ArmatureCacheMgr.h" + diff --git a/native/tools/swig-config/editor_support.i b/native/tools/swig-config/editor_support.i new file mode 100644 index 0000000000..bce9c9bf30 --- /dev/null +++ b/native/tools/swig-config/editor_support.i @@ -0,0 +1,108 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// editor_support at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="middleware") editor_support + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "editor-support/middleware-adapter.h" +#include "editor-support/MiddlewareManager.h" +#include "editor-support/SharedBufferManager.h" + +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_editor_support_auto.h" +%} + +// ----- Ignore Section Begin ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +%ignore cc::middleware::MiddlewareManager::addTimer; +%ignore cc::middleware::MiddlewareManager::removeTimer; +%ignore cc::middleware::MiddlewareManager::getMeshBuffer; +%ignore cc::middleware::SharedBufferManager::getBuffer; +%ignore cc::middleware::SharedBufferManager::reset; +%ignore cc::middleware::Texture2D::setTexParameters; + + + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + + + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "editor-support/MiddlewareMacro.h" +%import "editor-support/MeshBuffer.h" + + + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "editor-support/middleware-adapter.h" +%include "editor-support/SharedBufferManager.h" +%include "editor-support/MiddlewareManager.h" + diff --git a/native/tools/swig-config/extension.i b/native/tools/swig-config/extension.i new file mode 100644 index 0000000000..5cef04d741 --- /dev/null +++ b/native/tools/swig-config/extension.i @@ -0,0 +1,91 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// extension at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") extension + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "extensions/cocos-ext.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_extension_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +%rename(AssetsManager) cc::extension::AssetsManagerEx; +%rename(EventAssetsManager) cc::extension::EventAssetsManagerEx; + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "extensions/ExtensionExport.h" +%import "extensions/ExtensionMacros.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "extensions/assets-manager/EventAssetsManagerEx.h" +%include "extensions/assets-manager/Manifest.h" +%include "extensions/assets-manager/AssetsManagerEx.h" diff --git a/native/tools/swig-config/genbindings.js b/native/tools/swig-config/genbindings.js new file mode 100644 index 0000000000..8f018539d7 --- /dev/null +++ b/native/tools/swig-config/genbindings.js @@ -0,0 +1,128 @@ +const path = require('path'); +const os = require('os'); +const fs = require('fs'); +const util = require('util'); + +const assert = require('assert'); + +const { spawnSync } = require('child_process'); + +const nodeMainVersion = parseInt(process.version.match(/^v(\d+)\.\d+/)[1]); +console.log('node main version: ' + nodeMainVersion + ', version: ' + process.version); +if (nodeMainVersion < 8) { + console.error(`Node version (${process.version}) is too low, require at least NodeJS 8`); + process.exit(-1); +} + +console.log('platform: ' + os.platform()); +let hostName = os.platform(); +let exeSuffix = ''; +if (hostName == 'darwin') { + hostName = 'mac'; +} else if (hostName == 'win32') { + // NOTE: The external folder name is win64 for windows platform + // hostName here is for searching platform folder in native/cocos/external + hostName = 'win64'; + exeSuffix = '.exe'; +} + +const COCOS_NATIVE_ROOT = path.resolve('../..'); +console.log('COCOS_NATIVE_ROOT:' + COCOS_NATIVE_ROOT); + +// Release +const SWIG_ROOT=path.join(COCOS_NATIVE_ROOT, 'external', hostName, 'bin', 'swig'); +const SWIG_EXE=path.join(SWIG_ROOT, 'bin', 'swig') + exeSuffix; +const SWIG_LIB_ARRAY=[ + path.join(SWIG_ROOT, 'share', 'swig', '4.1.0', 'javascript', 'cocos'), + path.join(SWIG_ROOT, 'share', 'swig', '4.1.0'), +]; + +// // Debug +// // linux +// // const SWIG_ROOT=`/home/james/projects/swig`; +// // mac +// const SWIG_ROOT=`/Users/james/Project/cocos/swig`; + +// const SWIG_EXE=path.join(SWIG_ROOT, 'build', 'Debug', 'swig'); +// const SWIG_LIB_ARRAY=[ +// path.join(SWIG_ROOT, 'build'), +// path.join(SWIG_ROOT, 'Lib', 'javascript', 'cocos'), +// path.join(SWIG_ROOT, 'Lib'), +// ]; + +function exists(path) { + try { + if (fs.existsSync(path)) { + return true; + } + } catch(err) { + console.error(err) + } + return false; +} + +assert(exists(SWIG_EXE), `${SWIG_EXE} doesn't exist`); + +const includes = [...SWIG_LIB_ARRAY]; +includes.push(COCOS_NATIVE_ROOT); +includes.push(path.join(COCOS_NATIVE_ROOT, 'cocos')); +for (const includePath of includes) { + assert(exists(includePath), `${includePath} doesn't exist`); +} + +for (let i = 0, len = includes.length; i < len; ++i) { + includes[i] = '-I' + includes[i]; +} + +const swigConfigMap = [ + [ '2d.i', 'jsb_2d_auto.cpp' ], + [ 'assets.i', 'jsb_assets_auto.cpp' ], + [ 'audio.i', 'jsb_audio_auto.cpp' ], + [ 'cocos.i', 'jsb_cocos_auto.cpp' ], + [ 'dragonbones.i', 'jsb_dragonbones_auto.cpp' ], + [ 'editor_support.i', 'jsb_editor_support_auto.cpp' ], + [ 'extension.i', 'jsb_extension_auto.cpp' ], + [ 'geometry.i', 'jsb_geometry_auto.cpp' ], + [ 'gfx.i', 'jsb_gfx_auto.cpp' ], + [ 'network.i', 'jsb_network_auto.cpp' ], + [ 'physics.i', 'jsb_physics_auto.cpp' ], + [ 'pipeline.i', 'jsb_pipeline_auto.cpp' ], + [ 'scene.i', 'jsb_scene_auto.cpp' ], + [ 'spine.i', 'jsb_spine_auto.cpp' ], + [ 'webview.i', 'jsb_webview_auto.cpp' ], + [ 'video.i', 'jsb_video_auto.cpp' ], + [ 'renderer.i', 'jsb_render_auto.cpp' ], +]; + +function generateBindings(interfaceFile, generatedCppFile) { + console.log(`==> generateBindings: interface: ${interfaceFile}, cpp: ${generatedCppFile}`); + let args = [ + '-c++', '-cocos', '-fvirtual', '-noexcept', '-cpperraswarn', + '-D__clang__', '-Dfinal= ', '-DCC_PLATFORM=3', '-Dconstexpr=const', '-DCC_PLATFORM_ANDROID=3', + ]; + args = args.concat(includes, [ + '-o', path.join(COCOS_NATIVE_ROOT, 'cocos', 'bindings', 'auto', generatedCppFile), + path.join(COCOS_NATIVE_ROOT, 'tools', 'swig-config', interfaceFile) + ]); + console.log(`==> args:${args.join(' ')}`); + console.log(`exe: ${SWIG_EXE}`); + try { + const ret = spawnSync(SWIG_EXE, args, { + stdio: ['ignore', process.stdout, process.stderr], + }); + if (ret.status !== 0) { + process.exit(-1); + } + } catch (error) { + console.error('ERROR:', error); + process.exit(-2); + } +} + +for (const config of swigConfigMap) { + generateBindings(config[0], config[1]); +} + +console.info(`======================================================================`) +console.info(` Congratulations, JS binding code was generated successfully!`); +console.info(`======================================================================`) diff --git a/native/tools/swig-config/geometry.i b/native/tools/swig-config/geometry.i new file mode 100644 index 0000000000..68f9761378 --- /dev/null +++ b/native/tools/swig-config/geometry.i @@ -0,0 +1,137 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// geometry at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="ns") geometry + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "core/geometry/Geometry.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_geometry_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::geometry::AABB::getBoundary; +%ignore cc::geometry::AABB::aabbAabb; +%ignore cc::geometry::AABB::aabbFrustum; +%ignore cc::geometry::AABB::aabbPlan; +%ignore cc::geometry::AABB::merge; +%ignore cc::geometry::AABB::transform; +%ignore cc::geometry::AABB::transformExtentM4; +%ignore cc::geometry::AABB::isValid; +%ignore cc::geometry::AABB::setValid; +%ignore cc::geometry::AABB::set; +%ignore cc::geometry::AABB::fromPoints; +%ignore cc::geometry::AABB::getCenter; +%ignore cc::geometry::AABB::setCenter; +%ignore cc::geometry::AABB::getHalfExtents; +%ignore cc::geometry::AABB::setHalfExtents; + +%ignore cc::geometry::Frustum::update; +%ignore cc::geometry::Frustum::type; +%ignore cc::geometry::Frustum::split; + +%ignore cc::geometry::Plane::clone; +%ignore cc::geometry::Plane::copy; +%ignore cc::geometry::Plane::normalize; +%ignore cc::geometry::Plane::getSpotAngle; +%ignore cc::geometry::Plane::fromNormalAndPoint; +%ignore cc::geometry::Plane::fromPoints; +%ignore cc::geometry::Plane::set; + +%ignore cc::geometry::Ray::computeHit; + +%ignore cc::geometry::Sphere::getBoundary; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" + +%import "math/MathBase.h" +%import "math/Vec2.h" +%import "math/Vec3.h" +%import "math/Vec4.h" +%import "math/Color.h" +%import "math/Mat3.h" +%import "math/Mat4.h" +%import "math/Quaternion.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound + +%include "core/geometry/Enums.h" +%include "core/geometry/AABB.h" +// %include "core/geometry/Obb.h" +%include "core/geometry/Line.h" +%include "core/geometry/Plane.h" +%include "core/geometry/Frustum.h" +%include "core/geometry/Capsule.h" +%include "core/geometry/Sphere.h" +%include "core/geometry/Triangle.h" +%include "core/geometry/Ray.h" +%include "core/geometry/Spline.h" diff --git a/native/tools/swig-config/gfx.i b/native/tools/swig-config/gfx.i new file mode 100644 index 0000000000..dfddbce916 --- /dev/null +++ b/native/tools/swig-config/gfx.i @@ -0,0 +1,264 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// gfx at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="gfx") gfx + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "renderer/GFXDeviceManager.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_gfx_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +namespace cc { namespace gfx { + +// TODO(cjh): use regex to ignore +%ignore TextureInfo::_padding; +%ignore TextureViewInfo::_padding; +%ignore ColorAttachment::_padding; +%ignore DepthStencilAttachment::_padding; +%ignore SubpassDependency::_padding; +%ignore BufferInfo::_padding; + +%ignore Buffer::initialize; +%ignore Buffer::update; + +%ignore CommandBuffer::execute; +%ignore CommandBuffer::updateBuffer; +%ignore CommandBuffer::copyBuffersToTexture; +%rename(drawWithInfo) CommandBuffer::draw(const DrawInfo&); + +%ignore DescriptorSetLayout::getBindingIndices; +%ignore DescriptorSetLayout::descriptorIndices; +%ignore DescriptorSetLayout::getDescriptorIndices; + +%ignore DescriptorSet::DescriptorSet; +%ignore DescriptorSet::forceUpdate; + +%ignore BufferBarrier::BufferBarrier; + +%ignore CommandBuffer::execute; +%ignore CommandBuffer::updateBuffer; +%ignore CommandBuffer::copyBuffersToTexture; + +%ignore Device::copyBuffersToTexture; +%ignore Device::copyTextureToBuffers; + +%ignore FormatInfo; + +}} // namespace cc { namespace gfx { + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +// Device +%attribute(cc::gfx::Device, cc::gfx::API, gfxAPI, getGfxAPI); +%attribute(cc::gfx::Device, ccstd::string&, deviceName, getDeviceName); +%attribute(cc::gfx::Device, cc::gfx::MemoryStatus&, memoryStatus, getMemoryStatus); +%attribute(cc::gfx::Device, cc::gfx::Queue*, queue, getQueue); +%attribute(cc::gfx::Device, cc::gfx::CommandBuffer*, commandBuffer, getCommandBuffer); +%attribute(cc::gfx::Device, ccstd::string&, renderer, getRenderer); +%attribute(cc::gfx::Device, ccstd::string&, vendor, getVendor); +%attribute(cc::gfx::Device, uint32_t, numDrawCalls, getNumDrawCalls); +%attribute(cc::gfx::Device, uint32_t, numInstances, getNumInstances); +%attribute(cc::gfx::Device, uint32_t, numTris, getNumTris); +%attribute(cc::gfx::Device, cc::gfx::DeviceCaps&, capabilities, getCapabilities); + +// Shader +%attribute(cc::gfx::Shader, ccstd::string&, name, getName); +%attribute(cc::gfx::Shader, cc::gfx::ShaderStageList&, stages, getStages); +%attribute(cc::gfx::Shader, cc::gfx::AttributeList&, attributes, getAttributes); +%attribute(cc::gfx::Shader, cc::gfx::UniformBlockList&, blocks, getBlocks); +%attribute(cc::gfx::Shader, cc::gfx::UniformSamplerList&, samplers, getSamplers); + +// Texture +%attribute(cc::gfx::Texture, cc::gfx::TextureInfo&, info, getInfo); +%attribute(cc::gfx::Texture, cc::gfx::TextureViewInfo&, viewInfo, getViewInfo); +%attribute(cc::gfx::Texture, uint32_t, width, getWidth); +%attribute(cc::gfx::Texture, uint32_t, height, getHeight); +%attribute(cc::gfx::Texture, cc::gfx::Format, format, getFormat); +%attribute(cc::gfx::Texture, uint32_t, size, getSize); +%attribute(cc::gfx::Texture, ccstd::hash_t, hash, getHash); + +// Queue +%attribute(cc::gfx::Queue, cc::gfx::QueueType, type, getType); + +// RenderPass +%attribute(cc::gfx::RenderPass, ccstd::hash_t, hash, getHash); + +// DescriptorSet +%attribute(cc::gfx::DescriptorSet, cc::gfx::DescriptorSetLayout*, layout, getLayout); + +// PipelineState +%attribute(cc::gfx::PipelineState, cc::gfx::Shader*, shader, getShader); +%attribute(cc::gfx::PipelineState, cc::gfx::PrimitiveMode, primitive, getPrimitive); +%attribute(cc::gfx::PipelineState, cc::gfx::PipelineBindPoint, bindPoint, getBindPoint); +%attribute(cc::gfx::PipelineState, cc::gfx::InputState&, inputState, getInputState); +%attribute(cc::gfx::PipelineState, cc::gfx::RasterizerState&, rasterizerState, getRasterizerState); +%attribute(cc::gfx::PipelineState, cc::gfx::DepthStencilState&, depthStencilState, getDepthStencilState); +%attribute(cc::gfx::PipelineState, cc::gfx::BlendState&, blendState, getBlendState); +%attribute(cc::gfx::PipelineState, cc::gfx::RenderPass*, renderPass, getRenderPass); + +// InputAssembler +%attribute(cc::gfx::InputAssembler, cc::gfx::BufferList&, vertexBuffers, getVertexBuffers); +%attribute(cc::gfx::InputAssembler, cc::gfx::AttributeList&, attributes, getAttributes); +%attribute(cc::gfx::InputAssembler, cc::gfx::Buffer*, indexBuffer, getIndexBuffer); +%attribute(cc::gfx::InputAssembler, cc::gfx::Buffer*, indirectBuffer, getIndirectBuffer); +%attribute(cc::gfx::InputAssembler, uint32_t, attributesHash, getAttributesHash); + +%attribute(cc::gfx::InputAssembler, cc::gfx::DrawInfo&, drawInfo, getDrawInfo, setDrawInfo); +%attribute(cc::gfx::InputAssembler, uint32_t, vertexCount, getVertexCount, setVertexCount); +%attribute(cc::gfx::InputAssembler, uint32_t, firstVertex, getFirstVertex, setFirstVertex); +%attribute(cc::gfx::InputAssembler, uint32_t, indexCount, getIndexCount, setIndexCount); +%attribute(cc::gfx::InputAssembler, uint32_t, firstIndex, getFirstIndex, setFirstIndex); +%attribute(cc::gfx::InputAssembler, uint32_t, vertexOffset, getVertexOffset, setVertexOffset); +%attribute(cc::gfx::InputAssembler, uint32_t, instanceCount, getInstanceCount, setInstanceCount); + +// CommandBuffer +%attribute(cc::gfx::CommandBuffer, cc::gfx::CommandBufferType, type, getType); +%attribute(cc::gfx::CommandBuffer, cc::gfx::Queue*, queue, getQueue); +%attribute(cc::gfx::CommandBuffer, uint32_t, numDrawCalls, getNumDrawCalls); +%attribute(cc::gfx::CommandBuffer, uint32_t, numInstances, getNumInstances); +%attribute(cc::gfx::CommandBuffer, uint32_t, numTris, getNumTris); + +// Framebuffer +%attribute(cc::gfx::Framebuffer, cc::gfx::RenderPass*, renderPass, getRenderPass); +%attribute(cc::gfx::Framebuffer, cc::gfx::TextureList&, colorTextures, getColorTextures); +%attribute(cc::gfx::Framebuffer, cc::gfx::Texture*, depthStencilTexture, getDepthStencilTexture); + +// Buffer +%attribute(cc::gfx::Buffer, cc::gfx::BufferUsage, usage, getUsage); +%attribute(cc::gfx::Buffer, cc::gfx::MemoryUsage, memUsage, getMemUsage); +%attribute(cc::gfx::Buffer, uint32_t, stride, getStride); +%attribute(cc::gfx::Buffer, uint32_t, count, getCount); +%attribute(cc::gfx::Buffer, uint32_t, size, getSize); +%attribute(cc::gfx::Buffer, cc::gfx::BufferFlags, flags, getFlags); + +// Sampler +%attribute(cc::gfx::Sampler, cc::gfx::SamplerInfo&, info, getInfo); +%attribute(cc::gfx::Sampler, ccstd::hash_t, hash, getHash); + +// Swapchain +%attribute(cc::gfx::Swapchain, uint32_t, width, getWidth); +%attribute(cc::gfx::Swapchain, uint32_t, height, getHeight); +%attribute(cc::gfx::Swapchain, cc::gfx::SurfaceTransform, surfaceTransform, getSurfaceTransform); +%attribute(cc::gfx::Swapchain, cc::gfx::Texture*, colorTexture, getColorTexture); +%attribute(cc::gfx::Swapchain, cc::gfx::Texture*, depthStencilTexture, getDepthStencilTexture); + +// GFXObject +%attribute(cc::gfx::GFXObject, cc::gfx::ObjectType, objectType, getObjectType); +%attribute(cc::gfx::GFXObject, uint32_t, objectID, getObjectID); +%attribute(cc::gfx::GFXObject, uint32_t, typedID, getTypedID); + + + +// ----- Release Returned Cpp Object in GC Section ------ +%release_returned_cpp_object_in_gc(cc::gfx::Device::createCommandBuffer); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createQueue); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createQueryPool); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createSwapchain); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createBuffer); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createTexture); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createShader); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createInputAssembler); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createRenderPass); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createFramebuffer); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createDescriptorSet); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createDescriptorSetLayout); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createPipelineLayout); +%release_returned_cpp_object_in_gc(cc::gfx::Device::createPipelineState); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" +%import "base/memory/Memory.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "renderer/gfx-base/GFXDef-common.h" +%include "renderer/gfx-base/GFXObject.h" +%include "renderer/gfx-base/GFXBuffer.h" +%include "renderer/gfx-base/GFXCommandBuffer.h" +%include "renderer/gfx-base/GFXDescriptorSet.h" +%include "renderer/gfx-base/GFXDescriptorSetLayout.h" +%include "renderer/gfx-base/GFXFramebuffer.h" +%include "renderer/gfx-base/GFXInputAssembler.h" +%include "renderer/gfx-base/GFXPipelineLayout.h" +%include "renderer/gfx-base/GFXPipelineState.h" +%include "renderer/gfx-base/GFXQueryPool.h" +%include "renderer/gfx-base/GFXQueue.h" +%include "renderer/gfx-base/GFXRenderPass.h" +%include "renderer/gfx-base/GFXShader.h" +%include "renderer/gfx-base/GFXSwapchain.h" +%include "renderer/gfx-base/GFXTexture.h" + +%include "renderer/gfx-base/states/GFXGeneralBarrier.h" +%include "renderer/gfx-base/states/GFXSampler.h" +%include "renderer/gfx-base/states/GFXTextureBarrier.h" +%include "renderer/gfx-base/states/GFXBufferBarrier.h" + +%include "renderer/gfx-base/GFXDevice.h" + +%include "renderer/GFXDeviceManager.h" diff --git a/native/tools/swig-config/network.i b/native/tools/swig-config/network.i new file mode 100644 index 0000000000..69549aa23d --- /dev/null +++ b/native/tools/swig-config/network.i @@ -0,0 +1,92 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// network at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") network + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "network/Downloader.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_network_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::network::Downloader::createDataTask; +%ignore cc::network::Downloader::createDownloadTask; +%ignore cc::network::Downloader::abort; +%ignore cc::network::Downloader::setOnError; +%ignore cc::network::Downloader::setOnSuccess; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +%attribute_writeonly(cc::network::Downloader, std::function&, onProgress, setOnProgress); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "network/Downloader.h" diff --git a/native/tools/swig-config/physics.i b/native/tools/swig-config/physics.i new file mode 100644 index 0000000000..f1c37a9264 --- /dev/null +++ b/native/tools/swig-config/physics.i @@ -0,0 +1,109 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// physics at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb.physics") physics + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "physics/PhysicsSDK.h" +#include "bindings/auto/jsb_scene_auto.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_physics_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" +%import "core/scene-graph/Node.h" + +%import "core/geometry/Enums.h" +%import "core/geometry/AABB.h" +// %import "core/geometry/Obb.h" +%import "core/geometry/Line.h" +%import "core/geometry/Plane.h" +%import "core/geometry/Frustum.h" +%import "core/geometry/Capsule.h" +%import "core/geometry/Sphere.h" +%import "core/geometry/Triangle.h" +%import "core/geometry/Ray.h" +%import "core/geometry/Spline.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "physics/spec/ILifecycle.h" +%include "physics/spec/IWorld.h" +%include "physics/spec/IBody.h" +%include "physics/spec/IShape.h" +%include "physics/spec/IJoint.h" + +%include "physics/sdk/World.h" +%include "physics/sdk/RigidBody.h" +%include "physics/sdk/Shape.h" +%include "physics/sdk/Joint.h" diff --git a/native/tools/swig-config/pipeline.i b/native/tools/swig-config/pipeline.i new file mode 100644 index 0000000000..c231258d48 --- /dev/null +++ b/native/tools/swig-config/pipeline.i @@ -0,0 +1,220 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// pipeline at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="nr") pipeline + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "renderer/pipeline/forward/ForwardPipeline.h" +#include "renderer/pipeline/forward/ForwardFlow.h" +#include "renderer/pipeline/forward/ForwardStage.h" +#include "renderer/pipeline/shadow/ShadowFlow.h" +#include "renderer/pipeline/shadow/ShadowStage.h" +#include "renderer/pipeline/shadow/CSMLayers.h" +#include "renderer/pipeline/GlobalDescriptorSetManager.h" +#include "renderer/pipeline/InstancedBuffer.h" +#include "renderer/pipeline/deferred/DeferredPipeline.h" +#include "renderer/pipeline/deferred/MainFlow.h" +#include "renderer/pipeline/deferred/GbufferStage.h" +#include "renderer/pipeline/deferred/LightingStage.h" +#include "renderer/pipeline/deferred/BloomStage.h" +#include "renderer/pipeline/deferred/PostProcessStage.h" +#include "renderer/pipeline/PipelineSceneData.h" +#include "renderer/pipeline/BatchedBuffer.h" +#include "renderer/pipeline/GeometryRenderer.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_pipeline_auto.h" +#include "bindings/auto/jsb_scene_auto.h" +#include "bindings/auto/jsb_gfx_auto.h" +#include "renderer/pipeline/PipelineUBO.h" + +using namespace cc; +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::pipeline::convertQueueSortFunc; +%ignore cc::pipeline::RenderPipeline::getFrameGraph; +%ignore cc::pipeline::PipelineSceneData::getRenderObjects; +%ignore cc::pipeline::PipelineSceneData::setRenderObjects; +%ignore cc::pipeline::PipelineSceneData::getShadowObjects; +%ignore cc::pipeline::PipelineSceneData::setShadowObjects; +%ignore cc::pipeline::PipelineSceneData::getShadowFramebufferMap; +%ignore cc::pipeline::PipelineSceneData::getCSMLayers; +%ignore cc::pipeline::PipelineSceneData::getCSMSupported; +%ignore cc::pipeline::PipelineSceneData::setCSMSupported; +%ignore cc::pipeline::UBOBloom; + +//TODO: Use regex to write the following ignore pattern +%ignore cc::pipeline::RenderPipeline::fgStrHandleOutDepthTexture; +%ignore cc::pipeline::RenderPipeline::fgStrHandleOutColorTexture; +%ignore cc::pipeline::RenderPipeline::fgStrHandlePostprocessPass; +%ignore cc::pipeline::RenderPipeline::fgStrHandleBloomOutTexture; + +%ignore cc::pipeline::ForwardPipeline::fgStrHandleForwardColorTexture; +%ignore cc::pipeline::ForwardPipeline::fgStrHandleForwardDepthTexture; +%ignore cc::pipeline::ForwardPipeline::fgStrHandleForwardPass; + +%ignore cc::pipeline::DeferredPipeline::fgStrHandleGbufferTexture; +%ignore cc::pipeline::DeferredPipeline::fgStrHandleGbufferPass; +%ignore cc::pipeline::DeferredPipeline::fgStrHandleLightingPass; +%ignore cc::pipeline::DeferredPipeline::fgStrHandleTransparentPass; +%ignore cc::pipeline::DeferredPipeline::fgStrHandleSsprPass; + +%ignore cc::pipeline::CSMLayers::update; +%ignore cc::pipeline::CSMLayers::getCastShadowObjects; +%ignore cc::pipeline::CSMLayers::setCastShadowObjects; +%ignore cc::pipeline::CSMLayers::addCastShadowObject; +%ignore cc::pipeline::CSMLayers::clearCastShadowObjects; +%ignore cc::pipeline::CSMLayers::getLayerObjects; +%ignore cc::pipeline::CSMLayers::setLayerObjects; +%ignore cc::pipeline::CSMLayers::addLayerObject; +%ignore cc::pipeline::CSMLayers::clearLayerObjects; +%ignore cc::pipeline::CSMLayers::getLayers; +%ignore cc::pipeline::CSMLayers::getSpecialLayer; + +%ignore cc::pipeline::GeometryRendererInfo; +%ignore cc::pipeline::GeometryRenderer::activate; +%ignore cc::pipeline::GeometryRenderer::render; +%ignore cc::pipeline::GeometryRenderer::destroy; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' +%module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +%module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +%attribute(cc::pipeline::RenderPipeline, cc::pipeline::GlobalDSManager*, globalDSManager, getGlobalDSManager); +%attribute(cc::pipeline::RenderPipeline, cc::gfx::DescriptorSet*, descriptorSet, getDescriptorSet); +%attribute(cc::pipeline::RenderPipeline, cc::gfx::DescriptorSetLayout*, descriptorSetLayout, getDescriptorSetLayout); +%attribute(cc::pipeline::RenderPipeline, ccstd::string&, constantMacros, getConstantMacros); + +%attribute(cc::pipeline::RenderPipeline, bool, clusterEnabled, isClusterEnabled, setClusterEnabled); +%attribute(cc::pipeline::RenderPipeline, bool, bloomEnabled, isBloomEnabled, setBloomEnabled); +%attribute(cc::pipeline::RenderPipeline, cc::pipeline::PipelineSceneData*, pipelineSceneData, getPipelineSceneData); +%attribute(cc::pipeline::RenderPipeline, cc::pipeline::GeometryRenderer*, geometryRenderer, getGeometryRenderer); +%attribute(cc::pipeline::RenderPipeline, cc::scene::Model*, profiler, getProfiler, setProfiler); +%attribute(cc::pipeline::RenderPipeline, float, shadingScale, getShadingScale, setShadingScale); + + +%attribute(cc::pipeline::PipelineSceneData, bool, isHDR, isHDR, setHDR); +%attribute(cc::pipeline::PipelineSceneData, float, shadingScale, getShadingScale, setShadingScale); +%attribute(cc::pipeline::PipelineSceneData, cc::scene::Fog*, fog, getFog); +%attribute(cc::pipeline::PipelineSceneData, cc::scene::Ambient*, ambient, getAmbient); +%attribute(cc::pipeline::PipelineSceneData, cc::scene::Skybox*, skybox, getSkybox); +%attribute(cc::pipeline::PipelineSceneData, cc::scene::Shadows*, shadows, getShadows); + +%attribute(cc::pipeline::BloomStage, float, threshold, getThreshold, setThreshold); +%attribute(cc::pipeline::BloomStage, float, intensity, getIntensity, setIntensity); +%attribute(cc::pipeline::BloomStage, int, iterations, getIterations, setIterations); + + + +#define CC_USE_GEOMETRY_RENDERER 1 + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// + +%import "base/Macros.h" +%import "base/TypeDef.h" +%import "base/memory/Memory.h" +%import "base/Ptr.h" + +%import "math/MathBase.h" +%import "math/Vec2.h" +%import "math/Vec3.h" +%import "math/Vec4.h" +%import "math/Color.h" +%import "math/Mat3.h" +%import "math/Mat4.h" +%import "math/Quaternion.h" + +%import "core/assets/Material.h" + +%import "renderer/gfx-base/GFXDef-common.h" +%import "renderer/core/PassUtils.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound + +%include "renderer/pipeline/Define.h" + +%include "renderer/pipeline/RenderPipeline.h" +%include "renderer/pipeline/RenderFlow.h" +%include "renderer/pipeline/RenderStage.h" + +%include "renderer/pipeline/forward/ForwardPipeline.h" +%include "renderer/pipeline/forward/ForwardFlow.h" +%include "renderer/pipeline/forward/ForwardStage.h" + +%include "renderer/pipeline/shadow/ShadowFlow.h" +%include "renderer/pipeline/shadow/ShadowStage.h" +%include "renderer/pipeline/shadow/CSMLayers.h" + +%include "renderer/pipeline/GlobalDescriptorSetManager.h" +%include "renderer/pipeline/InstancedBuffer.h" +%include "renderer/pipeline/deferred/DeferredPipeline.h" +%include "renderer/pipeline/deferred/MainFlow.h" +%include "renderer/pipeline/deferred/GbufferStage.h" +%include "renderer/pipeline/deferred/LightingStage.h" +%include "renderer/pipeline/deferred/BloomStage.h" +%include "renderer/pipeline/deferred/PostProcessStage.h" +%include "renderer/pipeline/PipelineSceneData.h" +%include "renderer/pipeline/BatchedBuffer.h" +%include "renderer/pipeline/GeometryRenderer.h" + diff --git a/native/tools/swig-config/renderer.i b/native/tools/swig-config/renderer.i new file mode 100644 index 0000000000..3e085fcc91 --- /dev/null +++ b/native/tools/swig-config/renderer.i @@ -0,0 +1,109 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// native2d at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="render") render + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "renderer/pipeline/custom/RenderInterfaceTypes.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_render_auto.h" +#include "bindings/auto/jsb_scene_auto.h" +#include "bindings/auto/jsb_gfx_auto.h" +#include "bindings/auto/jsb_assets_auto.h" +#include "renderer/pipeline/GeometryRenderer.h" +#include "renderer/pipeline/GlobalDescriptorSetManager.h" +#include "renderer/pipeline/custom/LayoutGraphJsb.h" +#include "renderer/pipeline/custom/RenderCommonJsb.h" +#include "renderer/pipeline/custom/RenderGraphJsb.h" + +using namespace cc; +using namespace cc::render; +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' +%module_macro(CC_USE_GEOMETRY_RENDERER) cc::render::PipelineRuntime::geometryRenderer; + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +%attribute(cc::render::PipelineRuntime, cc::gfx::Device*, device, getDevice); +%attribute(cc::render::PipelineRuntime, cc::pipeline::GlobalDSManager *, globalDSManager, getGlobalDSManager); +%attribute(cc::render::PipelineRuntime, cc::gfx::DescriptorSetLayout*, descriptorSetLayout, getDescriptorSetLayout); +%attribute(cc::render::PipelineRuntime, cc::gfx::DescriptorSet *, descriptorSet, getDescriptorSet); +%attribute(cc::render::PipelineRuntime, ccstd::vector, commandBuffers, getCommandBuffers); +%attribute(cc::render::PipelineRuntime, cc::pipeline::PipelineSceneData *, pipelineSceneData, getPipelineSceneData); +%attribute(cc::render::PipelineRuntime, ccstd::string&, constantMacros, getConstantMacros); +%attribute(cc::render::PipelineRuntime, cc::scene::Model *, profiler, getProfiler, setProfiler); +%attribute(cc::render::PipelineRuntime, cc::pipeline::GeometryRenderer*, geometryRenderer, getGeometryRenderer); +%attribute(cc::render::PipelineRuntime, float, shadingScale, getShadingScale, setShadingScale); + + +%attribute(cc::render::SceneVisitor, cc::pipeline::PipelineSceneData*, pipelineSceneData, getPipelineSceneData); +%attribute(cc::render::SceneTask, cc::render::TaskType, taskType, getTaskType); +%attribute(cc::render::Pipeline, cc::render::LayoutGraphBuilder*, layoutGraphBuilder, getLayoutGraphBuilder); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "renderer/pipeline/custom/RenderInterfaceTypes.h" diff --git a/native/tools/swig-config/scene.i b/native/tools/swig-config/scene.i new file mode 100644 index 0000000000..761686d1ac --- /dev/null +++ b/native/tools/swig-config/scene.i @@ -0,0 +1,578 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// scene at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") scene + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "core/Root.h" +#include "core/scene-graph/Node.h" +#include "core/scene-graph/Scene.h" +#include "core/scene-graph/SceneGlobals.h" +#include "scene/Light.h" +#include "scene/Fog.h" +#include "scene/Shadow.h" +#include "scene/Skybox.h" +#include "scene/DirectionalLight.h" +#include "scene/SpotLight.h" +#include "scene/SphereLight.h" +#include "scene/Model.h" +#include "scene/SubModel.h" +#include "scene/Pass.h" +#include "scene/RenderScene.h" +#include "scene/DrawBatch2D.h" +#include "scene/RenderWindow.h" +#include "scene/Camera.h" +#include "scene/Define.h" +#include "scene/Ambient.h" +#include "renderer/core/PassInstance.h" +#include "renderer/core/MaterialInstance.h" +#include "3d/models/MorphModel.h" +#include "3d/models/SkinningModel.h" +#include "3d/models/BakedSkinningModel.h" +#include "renderer/core/ProgramLib.h" +#include "scene/Octree.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_scene_auto.h" +#include "bindings/auto/jsb_gfx_auto.h" +#include "bindings/auto/jsb_pipeline_auto.h" +#include "bindings/auto/jsb_geometry_auto.h" +#include "bindings/auto/jsb_assets_auto.h" +#include "bindings/auto/jsb_render_auto.h" +#include "bindings/auto/jsb_cocos_auto.h" +#include "bindings/auto/jsb_2d_auto.h" + +using namespace cc; +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore cc::scene::Pass::getBlocks; +%ignore cc::scene::Pass::initPassFromTarget; + +%ignore cc::Node::setRTSInternal; +%ignore cc::Node::setRTS; +%ignore cc::scene::Camera::syncCameraEditor; +//FIXME: These methods binding code will generate SwigValueWrapper type which is not supported now. +%ignore cc::scene::Model::getLocalData; +%ignore cc::scene::Model::getEventProcessor; +%ignore cc::scene::Model::getOctreeNode; +%ignore cc::scene::Model::setOctreeNode; +%ignore cc::scene::Model::updateOctree; + +%ignore cc::scene::SkinningModel::uploadJointData; + +%ignore cc::scene::RenderScene::updateBatches; +%ignore cc::scene::RenderScene::addBatch; +%ignore cc::scene::RenderScene::removeBatch; +%ignore cc::scene::RenderScene::removeBatches; +%ignore cc::scene::RenderScene::getBatches; + +%ignore cc::scene::BakedSkinningModel::updateInstancedJointTextureInfo; +%ignore cc::scene::BakedSkinningModel::updateModelBounds; + +%ignore cc::Node::setLayerPtr; +%ignore cc::Node::setUIPropsTransformDirtyCallback; +%ignore cc::Node::rotate; +%ignore cc::Node::setUserData; +%ignore cc::Node::getUserData; +%ignore cc::Node::getChildren; +%ignore cc::Node::rotateForJS; +%ignore cc::Node::setScale; +%ignore cc::Node::setRotation; +%ignore cc::Node::setRotationFromEuler; +%ignore cc::Node::setPosition; +%ignore cc::Node::isActiveInHierarchy; +%ignore cc::Node::setActiveInHierarchy; +%ignore cc::Node::setActiveInHierarchyPtr; +%ignore cc::Node::getUIProps; +%ignore cc::Node::getPosition; +%ignore cc::Node::getRotation; +%ignore cc::Node::getScale; +%ignore cc::Node::getEulerAngles; +%ignore cc::Node::getForward; +%ignore cc::Node::getUp; +%ignore cc::Node::getRight; +%ignore cc::Node::getWorldPosition; +%ignore cc::Node::getWorldRotation; +%ignore cc::Node::getWorldScale; +%ignore cc::Node::getWorldMatrix; +%ignore cc::Node::getWorldRS; +%ignore cc::Node::getWorldRT; + +%ignore cc::scene::Camera::screenPointToRay; +%ignore cc::scene::Camera::screenToWorld; +%ignore cc::scene::Camera::worldToScreen; +%ignore cc::scene::Camera::worldMatrixToScreen; +%ignore cc::scene::Camera::syncCameraEditor; +%ignore cc::scene::Camera::getMatView; +%ignore cc::scene::Camera::getMatProj; +%ignore cc::scene::Camera::getMatProjInv; +%ignore cc::scene::Camera::getMatViewProj; +%ignore cc::scene::Camera::getMatViewProjInv; + +%ignore cc::JointTexturePool::getDefaultPoseTexture; +// +%ignore cc::Layers::addLayer; +%ignore cc::Layers::deleteLayer; +%ignore cc::Layers::nameToLayer; +%ignore cc::Layers::layerToName; + +%ignore cc::JointInfo; +%ignore cc::BakedJointInfo; +%ignore cc::ITemplateInfo; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + +%rename(IInstancedAttributeBlock) cc::scene::InstancedAttributeBlock; + +%rename(_initialize) cc::Root::initialize; +%rename(resetHasChangedFlags) cc::Node::resetChangedFlags; +%rename(_parentInternal) cc::Node::_parent; +%rename(_updateSiblingIndex) cc::Node::updateSiblingIndex; +%rename(_onPreDestroyBase) cc::Node::onPreDestroyBase; +%rename(_onPreDestroy) cc::Node::onPreDestroy; + +%rename(_enabled) cc::scene::FogInfo::_isEnabled; +%rename(cpp_keyword_register) cc::ProgramLib::registerEffect; + +%rename(_initLocalDescriptors) cc::scene::Model::initLocalDescriptors; +%rename(_updateLocalDescriptors) cc::scene::Model::updateLocalDescriptors; +%rename(_updateInstancedAttributes) cc::scene::Model::updateInstancedAttributes; +%rename(_getInstancedAttributeIndex) cc::scene::Model::getInstancedAttributeIndex; + +%rename(_load) cc::Scene::load; +%rename(_activate) cc::Scene::activate; + +%rename(_updatePassHash) cc::scene::Pass::updatePassHash; + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' +%module_macro(CC_USE_GEOMETRY_RENDERER) cc::scene::Camera::geometryRenderer; + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// +//TODO: %attribute code needs to be generated from ts file automatically. +%attribute(cc::Root, cc::gfx::Device*, device, getDevice, setDevice); +%attribute(cc::Root, cc::gfx::Device*, _device, getDevice, setDevice); +%attribute(cc::Root, cc::scene::RenderWindow*, mainWindow, getMainWindow); +%attribute(cc::Root, cc::scene::RenderWindow*, curWindow, getCurWindow, setCurWindow); +%attribute(cc::Root, cc::scene::RenderWindow*, tempWindow, getTempWindow, setTempWindow); +%attribute(cc::Root, %arg(ccstd::vector> &), windows, getWindows); +%attribute(cc::Root, %arg(ccstd::vector> &), scenes, getScenes); +%attribute(cc::Root, float, cumulativeTime, getCumulativeTime); +%attribute(cc::Root, float, frameTime, getFrameTime); +%attribute(cc::Root, uint32_t, frameCount, getFrameCount); +%attribute(cc::Root, uint32_t, fps, getFps); +%attribute(cc::Root, uint32_t, fixedFPS, getFixedFPS, setFixedFPS); +%attribute(cc::Root, bool, useDeferredPipeline, isUsingDeferredPipeline); +%attribute(cc::Root, bool, usesCustomPipeline, usesCustomPipeline); +%attribute(cc::Root, cc::render::PipelineRuntime *, pipeline, getPipeline); +%attribute(cc::Root, cc::render::Pipeline*, customPipeline, getCustomPipeline); + +%attribute(cc::scene::RenderWindow, uint32_t, width, getWidth); +%attribute(cc::scene::RenderWindow, uint32_t, height, getHeight); +%attribute(cc::scene::RenderWindow, cc::gfx::Framebuffer*, framebuffer, getFramebuffer); +%attribute(cc::scene::RenderWindow, %arg(ccstd::vector> &), cameras, getCameras); +%attribute(cc::scene::RenderWindow, cc::gfx::Swapchain*, swapchain, getSwapchain); + +%attribute(cc::scene::Pass, cc::Root*, root, getRoot); +%attribute(cc::scene::Pass, cc::gfx::Device*, device, getDevice); +%attribute(cc::scene::Pass, cc::IProgramInfo*, shaderInfo, getShaderInfo); +%attribute(cc::scene::Pass, cc::gfx::DescriptorSetLayout*, localSetLayout, getLocalSetLayout); +%attribute(cc::scene::Pass, ccstd::string&, program, getProgram); +%attribute(cc::scene::Pass, %arg(Record &), properties, getProperties); +%attribute(cc::scene::Pass, cc::MacroRecord&, defines, getDefines); +%attribute(cc::scene::Pass, index_t, passIndex, getPassIndex); +%attribute(cc::scene::Pass, index_t, propertyIndex, getPropertyIndex); +%attribute(cc::scene::Pass, cc::scene::IPassDynamics &, dynamics, getDynamics); +%attribute(cc::scene::Pass, bool, rootBufferDirty, isRootBufferDirty); +%attribute(cc::scene::Pass, bool, _rootBufferDirty, isRootBufferDirty, _setRootBufferDirty); +%attribute(cc::scene::Pass, cc::pipeline::RenderPriority, priority, getPriority); +%attribute(cc::scene::Pass, cc::gfx::PrimitiveMode, primitive, getPrimitive); +%attribute(cc::scene::Pass, cc::pipeline::RenderPassStage, stage, getStage); +%attribute(cc::scene::Pass, uint32_t, phase, getPhase); +%attribute(cc::scene::Pass, cc::gfx::RasterizerState *, rasterizerState, getRasterizerState); +%attribute(cc::scene::Pass, cc::gfx::DepthStencilState *, depthStencilState, getDepthStencilState); +%attribute(cc::scene::Pass, cc::gfx::BlendState *, blendState, getBlendState); +%attribute(cc::scene::Pass, cc::gfx::DynamicStateFlagBit, dynamicStates, getDynamicStates); +%attribute(cc::scene::Pass, cc::scene::BatchingSchemes, batchingScheme, getBatchingScheme); +%attribute(cc::scene::Pass, cc::gfx::DescriptorSet *, descriptorSet, getDescriptorSet); +%attribute(cc::scene::Pass, ccstd::hash_t, hash, getHash); +%attribute(cc::scene::Pass, cc::gfx::PipelineLayout*, pipelineLayout, getPipelineLayout); + +%attribute(cc::PassInstance, cc::scene::Pass*, parent, getParent); + +%attribute(cc::Node, ccstd::string &, uuid, getUuid); +%attribute(cc::Node, float, angle, getAngle, setAngle); +%attribute_writeonly(cc::Node, Mat4&, matrix, setMatrix); +%attribute(cc::Node, uint32_t, hasChangedFlags, getChangedFlags, setChangedFlags); +%attribute(cc::Node, bool, _persistNode, isPersistNode, setPersistNode); + +%attribute(cc::scene::Ambient, cc::Vec4&, skyColor, getSkyColor, setSkyColor); +%attribute(cc::scene::Ambient, float, skyIllum, getSkyIllum, setSkyIllum); +%attribute(cc::scene::Ambient, Vec4&, groundAlbedo, getGroundAlbedo, setGroundAlbedo); +%attribute(cc::scene::Ambient, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::Ambient, uint8_t, mipmapCount, getMipmapCount, setMipmapCount); + +%attribute(cc::scene::Light, bool, baked, isBaked, setBaked); +%attribute(cc::scene::Light, cc::Vec3&, color, getColor, setColor); +%attribute(cc::scene::Light, bool, useColorTemperature, isUseColorTemperature, setUseColorTemperature); +%attribute(cc::scene::Light, float, colorTemperature, getColorTemperature, setColorTemperature); +%attribute(cc::scene::Light, cc::Node*, node, getNode, setNode); +%attribute(cc::scene::Light, cc::scene::LightType, type, getType, setType); +%attribute(cc::scene::Light, ccstd::string&, name, getName, setName); +%attribute(cc::scene::Light, cc::scene::RenderScene*, scene, getScene); + +%attribute(cc::scene::DirectionalLight, cc::Vec3&, direction, getDirection, setDirection); +%attribute(cc::scene::DirectionalLight, float, illuminance, getIlluminance, setIlluminance); +%attribute(cc::scene::DirectionalLight, float, illuminanceHDR, getIlluminanceHDR, setIlluminanceHDR); +%attribute(cc::scene::DirectionalLight, float, illuminanceLDR, getIlluminanceLDR, setIlluminanceLDR); +%attribute(cc::scene::DirectionalLight, bool, shadowEnabled, isShadowEnabled, setShadowEnabled); +%attribute(cc::scene::DirectionalLight, cc::scene::PCFType, shadowPcf, getShadowPcf, setShadowPcf); +%attribute(cc::scene::DirectionalLight, float, shadowBias, getShadowBias, setShadowBias); +%attribute(cc::scene::DirectionalLight, float, shadowNormalBias, getShadowNormalBias, setShadowNormalBias); +%attribute(cc::scene::DirectionalLight, float, shadowSaturation, getShadowSaturation, setShadowSaturation); +%attribute(cc::scene::DirectionalLight, float, shadowDistance, getShadowDistance, setShadowDistance); +%attribute(cc::scene::DirectionalLight, float, shadowInvisibleOcclusionRange, getShadowInvisibleOcclusionRange, setShadowInvisibleOcclusionRange); +%attribute(cc::scene::DirectionalLight, bool, shadowFixedArea, isShadowFixedArea, setShadowFixedArea); +%attribute(cc::scene::DirectionalLight, float, shadowNear, getShadowNear, setShadowNear); +%attribute(cc::scene::DirectionalLight, float, shadowFar, getShadowFar, setShadowFar); +%attribute(cc::scene::DirectionalLight, float, shadowOrthoSize, getShadowOrthoSize, setShadowOrthoSize); +%attribute(cc::scene::DirectionalLight, cc::scene::CSMLevel, csmLevel, getCSMLevel, setCSMLevel); +%attribute(cc::scene::DirectionalLight, bool, csmNeedUpdate, isCSMNeedUpdate, setCSMNeedUpdate); +%attribute(cc::scene::DirectionalLight, float, csmLayerLambda, getCSMLayerLambda, setCSMLayerLambda); +%attribute(cc::scene::DirectionalLight, cc::scene::CSMOptimizationMode, csmOptimizationMode, getCSMOptimizationMode, setCSMOptimizationMode); + +%attribute(cc::scene::SpotLight, cc::Vec3&, position, getPosition); +%attribute(cc::scene::SpotLight, float, range, getRange, setRange); +%attribute(cc::scene::SpotLight, float, luminance, getLuminance, setLuminance); +%attribute(cc::scene::SpotLight, float, luminanceHDR, getLuminanceHDR, setLuminanceHDR); +%attribute(cc::scene::SpotLight, float, luminanceLDR, getLuminanceLDR, setLuminanceLDR); +%attribute(cc::scene::SpotLight, cc::Vec3&, direction, getDirection); +%attribute(cc::scene::SpotLight, float, spotAngle, getSpotAngle, setSpotAngle); +%attribute(cc::scene::SpotLight, float, angle, getAngle); +%attribute(cc::scene::SpotLight, cc::geometry::AABB&, aabb, getAABB); +%attribute(cc::scene::SpotLight, cc::geometry::Frustum &, frustum, getFrustum, setFrustum); +%attribute(cc::scene::SpotLight, bool, shadowEnabled, isShadowEnabled, setShadowEnabled); +%attribute(cc::scene::SpotLight, float, shadowPcf, getShadowPcf, setShadowPcf); +%attribute(cc::scene::SpotLight, float, shadowBias, getShadowBias, setShadowBias); +%attribute(cc::scene::SpotLight, float, shadowNormalBias, getShadowNormalBias, setShadowNormalBias); +%attribute(cc::scene::SpotLight, float, size, getSize, setSize); + +%attribute(cc::scene::SphereLight, cc::Vec3&, position, getPosition, setPosition); +%attribute(cc::scene::SphereLight, float, size, getSize, setSize); +%attribute(cc::scene::SphereLight, float, range, getRange, setRange); +%attribute(cc::scene::SphereLight, float, luminance, getLuminance, setLuminance); +%attribute(cc::scene::SphereLight, float, luminanceHDR, getLuminanceHDR, setLuminanceHDR); +%attribute(cc::scene::SphereLight, float, luminanceLDR, getLuminanceLDR, setLuminanceLDR); +%attribute(cc::scene::SphereLight, cc::geometry::AABB&, aabb, getAABB); + +%attribute(cc::scene::Camera, cc::scene::CameraISO, iso, getIso, setIso); +%attribute(cc::scene::Camera, float, isoValue, getIsoValue); +%attribute(cc::scene::Camera, float, ec, getEc, setEc); +%attribute(cc::scene::Camera, float, exposure, getExposure); +%attribute(cc::scene::Camera, cc::scene::CameraShutter, shutter, getShutter, setShutter); +%attribute(cc::scene::Camera, float, shutterValue, getShutterValue); +%attribute(cc::scene::Camera, float, apertureValue, getApertureValue); +%attribute(cc::scene::Camera, uint32_t, width, getWidth); +%attribute(cc::scene::Camera, uint32_t, height, getHeight); +%attribute(cc::scene::Camera, float, aspect, getAspect); +%attribute(cc::scene::Camera, cc::scene::RenderScene*, scene, getScene); +%attribute(cc::scene::Camera, ccstd::string&, name, getName); +%attribute(cc::scene::Camera, cc::scene::RenderWindow*, window, getWindow, setWindow); +%attribute(cc::scene::Camera, cc::Vec3&, forward, getForward, setForward); +%attribute(cc::scene::Camera, cc::scene::CameraAperture, aperture, getAperture, setAperture); +%attribute(cc::scene::Camera, cc::Vec3&, position, getPosition, setPosition); +%attribute(cc::scene::Camera, cc::scene::CameraProjection, projectionType, getProjectionType, setProjectionType); +%attribute(cc::scene::Camera, cc::scene::CameraFOVAxis, fovAxis, getFovAxis, setFovAxis); +%attribute(cc::scene::Camera, float, fov, getFov, setFov); +%attribute(cc::scene::Camera, float, nearClip, getNearClip, setNearClip); +%attribute(cc::scene::Camera, float, farClip, getFarClip, setFarClip); +%attribute(cc::scene::Camera, cc::Rect&, viewport, getViewport, setViewport); +%attribute(cc::scene::Camera, float, orthoHeight, getOrthoHeight, setOrthoHeight); +%attribute(cc::scene::Camera, cc::gfx::Color&, clearColor, getClearColor, setClearColor); +%attribute(cc::scene::Camera, float, clearDepth, getClearDepth, setClearDepth); +%attribute(cc::scene::Camera, cc::gfx::ClearFlagBit, clearFlag, getClearFlag, setClearFlag); +%attribute(cc::scene::Camera, float, clearStencil, getClearStencil, setClearStencil); +%attribute(cc::scene::Camera, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::Camera, float, exposure, getExposure); +%attribute(cc::scene::Camera, cc::geometry::Frustum&, frustum, getFrustum, setFrustum); +%attribute(cc::scene::Camera, bool, isWindowSize, isWindowSize, setWindowSize); +%attribute(cc::scene::Camera, uint32_t, priority, getPriority, setPriority); +%attribute(cc::scene::Camera, float, screenScale, getScreenScale, setScreenScale); +%attribute(cc::scene::Camera, uint32_t, visibility, getVisibility, setVisibility); +%attribute(cc::scene::Camera, cc::Node*, node, getNode, setNode); +%attribute(cc::scene::Camera, cc::gfx::SurfaceTransform, surfaceTransform, getSurfaceTransform); +%attribute(cc::scene::Camera, cc::pipeline::GeometryRenderer *, geometryRenderer, getGeometryRenderer); + +%attribute(cc::scene::RenderScene, ccstd::string&, name, getName); +%attribute(cc::scene::RenderScene, ccstd::vector>&, cameras, getCameras); +%attribute(cc::scene::RenderScene, ccstd::vector>&, sphereLights, getSphereLights); +%attribute(cc::scene::RenderScene, ccstd::vector>&, spotLights, getSpotLights); +%attribute(cc::scene::RenderScene, ccstd::vector>&, models, getModels); + +%attribute(cc::scene::Skybox, cc::scene::Model*, model, getModel); +%attribute(cc::scene::Skybox, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::Skybox, bool, useHDR, isUseHDR, setUseHDR); +%attribute(cc::scene::Skybox, bool, useIBL, isUseIBL, setUseIBL); +%attribute(cc::scene::Skybox, bool, useDiffuseMap, isUseDiffuseMap, setUseDiffuseMap); +%attribute(cc::scene::Skybox, bool, isRGBE, isRGBE); +%attribute(cc::scene::Skybox, cc::TextureCube*, envmap, getEnvmap, setEnvmap); +%attribute(cc::scene::Skybox, cc::TextureCube*, diffuseMap, getDiffuseMap, setDiffuseMap); + +%attribute(cc::scene::Fog, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::Fog, bool, accurate, isAccurate, setAccurate); +%attribute(cc::scene::Fog, cc::Color&, fogColor, getFogColor, setFogColor); +%attribute(cc::scene::Fog, cc::scene::FogType, type, getType, setType); +%attribute(cc::scene::Fog, float, fogDensity, getFogDensity, setFogDensity); +%attribute(cc::scene::Fog, float, fogStart, getFogStart, setFogStart); +%attribute(cc::scene::Fog, float, fogEnd, getFogEnd, setFogEnd); +%attribute(cc::scene::Fog, float, fogAtten, getFogAtten, setFogAtten); +%attribute(cc::scene::Fog, float, fogTop, getFogTop, setFogTop); +%attribute(cc::scene::Fog, float, fogRange, getFogRange, setFogRange); +%attribute(cc::scene::Fog, cc::Vec4&, colorArray, getColorArray); + +%attribute(cc::scene::Model, cc::scene::RenderScene*, scene, getScene, setScene); +%attribute(cc::scene::Model, ccstd::vector> &, _subModels, getSubModels); +%attribute(cc::scene::Model, ccstd::vector> &, subModels, getSubModels); +%attribute(cc::scene::Model, bool, inited, isInited); +%attribute(cc::scene::Model, bool, _localDataUpdated, isLocalDataUpdated, setLocalDataUpdated); +%attribute(cc::scene::Model, cc::geometry::AABB *, _worldBounds, getWorldBounds, setWorldBounds); +%attribute(cc::scene::Model, cc::geometry::AABB *, worldBounds, getWorldBounds, setWorldBounds); +%attribute(cc::scene::Model, cc::geometry::AABB *, _modelBounds, getModelBounds, setModelBounds); +%attribute(cc::scene::Model, cc::geometry::AABB *, modelBounds, getModelBounds, setModelBounds); +%attribute(cc::scene::Model, cc::gfx::Buffer *, worldBoundBuffer, getWorldBoundBuffer, setWorldBoundBuffer); +%attribute(cc::scene::Model, cc::gfx::Buffer *, localBuffer, getLocalBuffer, setLocalBuffer); +%attribute(cc::scene::Model, uint32_t, updateStamp, getUpdateStamp); +%attribute(cc::scene::Model, bool, isInstancingEnabled, isInstancingEnabled); +%attribute(cc::scene::Model, bool, receiveShadow, isReceiveShadow, setReceiveShadow); +%attribute(cc::scene::Model, bool, castShadow, isCastShadow, setCastShadow); +%attribute(cc::scene::Model, float, shadowBias, getShadowBias, setShadowBias); +%attribute(cc::scene::Model, float, shadowNormalBias, getShadowNormalBias, setShadowNormalBias); +%attribute(cc::scene::Model, cc::Node*, node, getNode, setNode); +%attribute(cc::scene::Model, cc::Node*, transform, getTransform, setTransform); +%attribute(cc::scene::Model, cc::Layers::Enum, visFlags, getVisFlags, setVisFlags); +%attribute(cc::scene::Model, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::Model, cc::scene::Model::Type, type, getType, setType); +%attribute(cc::scene::Model, cc::scene::InstancedAttributeBlock&, instancedAttributes, getInstancedAttributeBlock, setInstancedAttributeBlock); +%attribute(cc::scene::Model, bool, isDynamicBatching, isDynamicBatching, setDynamicBatching); +%attribute(cc::scene::Model, uint32_t, priority, getPriority, setPriority); + +%attribute(cc::scene::SubModel, std::shared_ptr>> &, passes, getPasses, setPasses); +%attribute(cc::scene::SubModel, ccstd::vector> &, shaders, getShaders, setShaders); +%attribute(cc::scene::SubModel, cc::RenderingSubMesh*, subMesh, getSubMesh, setSubMesh); +%attribute(cc::scene::SubModel, cc::pipeline::RenderPriority, priority, getPriority, setPriority); +%attribute(cc::scene::SubModel, cc::gfx::InputAssembler *, inputAssembler, getInputAssembler, setInputAssembler); +%attribute(cc::scene::SubModel, cc::gfx::DescriptorSet *, descriptorSet, getDescriptorSet, setDescriptorSet); +%attribute(cc::scene::SubModel, ccstd::vector &, patches, getPatches); +%attribute(cc::scene::SubModel, cc::gfx::Shader*, planarInstanceShader, getPlanarInstanceShader, setPlanarInstanceShader); +%attribute(cc::scene::SubModel, cc::gfx::Shader*, planarShader, getPlanarShader, setPlanarShader); + +%attribute(cc::scene::ShadowsInfo, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::ShadowsInfo, cc::scene::ShadowType, type, getType, setType); +%attribute(cc::scene::ShadowsInfo, cc::Color&, shadowColor, getShadowColor, setShadowColor); +%attribute(cc::scene::ShadowsInfo, cc::Vec3&, planeDirection, getPlaneDirection, setPlaneDirection); +%attribute(cc::scene::ShadowsInfo, float, planeHeight, getPlaneHeight, setPlaneHeight); +%attribute(cc::scene::ShadowsInfo, uint32_t, maxReceived, getMaxReceived, setMaxReceived); +%attribute(cc::scene::ShadowsInfo, float, shadowMapSize, getShadowMapSize, setShadowMapSize); + +%attribute(cc::scene::Shadows, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::Shadows, cc::scene::ShadowType, type, getType, setType); +%attribute(cc::scene::Shadows, cc::Vec3&, normal, getNormal, setNormal); +%attribute(cc::scene::Shadows, float, distance, getDistance, setDistance); +%attribute(cc::scene::Shadows, cc::Color&, shadowColor, getShadowColor, setShadowColor); +%attribute(cc::scene::Shadows, uint32_t, maxReceived, getMaxReceived, setMaxReceived); +%attribute(cc::scene::Shadows, cc::Vec2&, size, getSize, setSize); +%attribute(cc::scene::Shadows, bool, shadowMapDirty, isShadowMapDirty, setShadowMapDirty); +%attribute(cc::scene::Shadows, cc::Mat4&, matLight, getMatLight); +%attribute(cc::scene::Shadows, cc::Material*, material, getMaterial); +%attribute(cc::scene::Shadows, cc::Material*, instancingMaterial, getInstancingMaterial); + +%attribute_writeonly(cc::scene::AmbientInfo, cc::Vec4&, skyColor, setSkyColor); +%attribute(cc::scene::AmbientInfo, float, skyIllum, getSkyIllum, setSkyIllum); +%attribute_writeonly(cc::scene::AmbientInfo, cc::Vec4&, groundAlbedo, setGroundAlbedo); +%attribute(cc::scene::AmbientInfo, cc::Vec4&, _skyColor, getSkyColorHDR, setSkyColorHDR); +%attribute(cc::scene::AmbientInfo, float, _skyIllum, getSkyIllumHDR, setSkyIllumHDR); +%attribute(cc::scene::AmbientInfo, cc::Vec4&, _groundAlbedo, getGroundAlbedoHDR, setGroundAlbedoHDR); +%attribute(cc::scene::AmbientInfo, cc::Vec4&, skyColorLDR, getSkyColorLDR); +%attribute(cc::scene::AmbientInfo, cc::Vec4&, groundAlbedoLDR, getGroundAlbedoLDR); +%attribute(cc::scene::AmbientInfo, float, skyIllumLDR, getSkyIllumLDR); +%attribute(cc::scene::AmbientInfo, cc::Color&, skyLightingColor, getSkyLightingColor, setSkyLightingColor); +%attribute(cc::scene::AmbientInfo, cc::Color&, groundLightingColor, getGroundLightingColor, setGroundLightingColor); + +%attribute(cc::scene::FogInfo, cc::scene::FogType, type, getType, setType); +%attribute(cc::scene::FogInfo, cc::Color&, fogColor, getFogColor, setFogColor); +%attribute(cc::scene::FogInfo, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::FogInfo, bool, accurate, isAccurate, setAccurate); +%attribute(cc::scene::FogInfo, float, fogDensity, getFogDensity, setFogDensity); +%attribute(cc::scene::FogInfo, float, fogStart, getFogStart, setFogStart); +%attribute(cc::scene::FogInfo, float, fogEnd, getFogEnd, setFogEnd); +%attribute(cc::scene::FogInfo, float, fogAtten, getFogAtten, setFogAtten); +%attribute(cc::scene::FogInfo, float, fogTop, getFogTop, setFogTop); +%attribute(cc::scene::FogInfo, float, fogRange, getFogRange, setFogRange); + +%attribute(cc::scene::SkyboxInfo, TextureCube*, _envmap, getEnvmapForJS, setEnvmapForJS); +%attribute(cc::scene::SkyboxInfo, bool, applyDiffuseMap, isApplyDiffuseMap, setApplyDiffuseMap); +%attribute(cc::scene::SkyboxInfo, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::SkyboxInfo, bool, useIBL, isUseIBL, setUseIBL); +%attribute(cc::scene::SkyboxInfo, bool, useHDR, isUseHDR, setUseHDR); +%attribute(cc::scene::SkyboxInfo, TextureCube*, envmap, getEnvmap, setEnvmap); +%attribute(cc::scene::SkyboxInfo, TextureCube*, diffuseMap, getDiffuseMap, setDiffuseMap); +%attribute(cc::scene::SkyboxInfo, cc::scene::EnvironmentLightingType, envLightingType, getEnvLightingType, setEnvLightingType); + +%attribute(cc::scene::OctreeInfo, bool, enabled, isEnabled, setEnabled); +%attribute(cc::scene::OctreeInfo, Vec3&, minPos, getMinPos, setMinPos); +%attribute(cc::scene::OctreeInfo, Vec3&, maxPos, getMaxPos, setMaxPos); +%attribute(cc::scene::OctreeInfo, uint32_t, depth, getDepth, setDepth); + +%attribute(cc::Scene, bool, autoReleaseAssets, isAutoReleaseAssets, setAutoReleaseAssets); + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "base/Macros.h" +%import "base/TypeDef.h" +%import "base/memory/Memory.h" +%import "base/Ptr.h" + +%import "core/ArrayBuffer.h" +%import "core/data/Object.h" +%import "core/TypedArray.h" + +%import "math/MathBase.h" +%import "math/Vec2.h" +%import "math/Vec3.h" +%import "math/Vec4.h" +%import "math/Color.h" +%import "math/Mat3.h" +%import "math/Mat4.h" +%import "math/Quaternion.h" + +// %import "renderer/gfx-base/GFXDef-common.h" +%import "core/data/Object.h" +%import "renderer/pipeline/RenderPipeline.h" +%import "renderer/core/PassUtils.h" + +%import "core/assets/Asset.h" +%import "core/assets/TextureBase.h" +%import "core/assets/SimpleTexture.h" +%import "core/assets/Texture2D.h" +%import "core/assets/TextureCube.h" +%import "core/assets/RenderTexture.h" +%import "core/assets/BufferAsset.h" +%import "core/assets/EffectAsset.h" +%import "core/assets/ImageAsset.h" +%import "core/assets/SceneAsset.h" +%import "core/assets/TextAsset.h" +%import "core/assets/Material.h" +%import "core/assets/RenderingSubMesh.h" + +%import "core/geometry/Enums.h" +%import "core/geometry/AABB.h" +%import "core/geometry/Capsule.h" +// %import "core/geometry/Curve.h" +%import "core/geometry/Distance.h" +%import "core/geometry/Frustum.h" +// %import "core/geometry/Intersect.h" +%import "core/geometry/Line.h" +%import "core/geometry/Obb.h" +%import "core/geometry/Plane.h" +%import "core/geometry/Ray.h" +%import "core/geometry/Spec.h" +%import "core/geometry/Sphere.h" +%import "core/geometry/Spline.h" +%import "core/geometry/Triangle.h" +%import "3d/assets/Skeleton.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "core/scene-graph/NodeEnum.h" +%include "core/scene-graph/Layers.h" +%include "core/scene-graph/BaseNode.h" +%include "core/scene-graph/Node.h" +%include "core/scene-graph/Scene.h" +%include "core/scene-graph/SceneGlobals.h" +%include "core/Root.h" +// %include "core/animation/SkeletalAnimationUtils.h" +// %include "3d/skeletal-animation/SkeletalAnimationUtils.h" + +%include "scene/Define.h" +%include "scene/Light.h" +%include "scene/Fog.h" +%include "scene/Shadow.h" +%include "scene/Skybox.h" +%include "scene/DirectionalLight.h" +%include "scene/SpotLight.h" +%include "scene/SphereLight.h" +%include "scene/Model.h" +%include "scene/SubModel.h" +%include "scene/Pass.h" +%include "scene/RenderScene.h" +%include "scene/RenderWindow.h" +%include "scene/Camera.h" +%include "scene/Ambient.h" +%include "renderer/core/PassInstance.h" +%include "renderer/core/MaterialInstance.h" + +%import "3d/assets/Morph.h" +%import "3d/assets/MorphRendering.h" + +%include "3d/models/MorphModel.h" +%include "3d/models/SkinningModel.h" +%include "3d/models/BakedSkinningModel.h" + +%include "renderer/core/ProgramLib.h" +%include "scene/Octree.h" + diff --git a/native/tools/swig-config/spine.i b/native/tools/swig-config/spine.i new file mode 100644 index 0000000000..9cf6adeb0a --- /dev/null +++ b/native/tools/swig-config/spine.i @@ -0,0 +1,312 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// spine at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="spine") spine + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "editor-support/spine-creator-support/spine-cocos2dx.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_spine_auto.h" +using namespace spine; +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// +%ignore *::rtti; +%ignore spine::SkeletonCache::SegmentData; +%ignore spine::SkeletonCache::BoneData; +%ignore spine::SkeletonCache::FrameData; +%ignore spine::SkeletonCache::AnimationData; +%ignore spine::Skin::AttachmentMap; + +%ignore spine::Animation::Animation; +%ignore spine::TrackEntry::TrackEntry; +%ignore spine::AnimationState::AnimationState; +%ignore spine::AnimationStateData::AnimationStateData; +%ignore spine::Attachment::Attachment; +%ignore spine::AttachmentTimeline::AttachmentTimeline; +%ignore spine::BoundingBoxAttachment::BoundingBoxAttachment; +%ignore spine::Bone::Bone; +%ignore spine::BoneData::BoneData; +%ignore spine::ClippingAttachment::ClippingAttachment; +%ignore spine::Color::Color; +%ignore spine::ColorTimeline::ColorTimeline; +%ignore spine::CurveTimeline::CurveTimeline; +%ignore spine::DeformTimeline::DeformTimeline; +%ignore spine::DrawOrderTimeline::DrawOrderTimeline; +%ignore spine::Event::Event; +%ignore spine::EventData::EventData; +%ignore spine::EventTimeline::EventTimeline; +%ignore spine::IkConstraint::IkConstraint; +%ignore spine::IkConstraintData::IkConstraintData; +%ignore spine::IkConstraintTimeline::IkConstraintTimeline; +%ignore spine::MeshAttachment::MeshAttachment; +%ignore spine::Polygon::Polygon; +%ignore spine::Polygon::_vertices; +%ignore spine::PathAttachment::PathAttachment; +%ignore spine::PathConstraint::PathConstraint; +%ignore spine::PathConstraintData::PathConstraintData; +%ignore spine::PathConstraintMixTimeline::PathConstraintMixTimeline; +%ignore spine::PathConstraintPositionTimeline::PathConstraintPositionTimeline; +%ignore spine::PathConstraintSpacingTimeline::PathConstraintSpacingTimeline; +%ignore spine::PointAttachment::PointAttachment; +%ignore spine::RegionAttachment::RegionAttachment; +%ignore spine::RotateTimeline::RotateTimeline; +%ignore spine::ScaleTimeline::ScaleTimeline; +%ignore spine::ShearTimeline::ShearTimeline; +%ignore spine::Skeleton::Skeleton; +%ignore spine::Slot::Slot; +%ignore spine::Skin::Skin; +%ignore spine::SlotData::SlotData; +%ignore spine::SkeletonBounds::SkeletonBounds; +%ignore spine::SkeletonData::SkeletonData; +%ignore spine::Timeline::Timeline; +%ignore spine::TransformConstraint::TransformConstraint; +%ignore spine::TransformConstraintData::TransformConstraintData; +%ignore spine::TransformConstraintTimeline::TransformConstraintTimeline; +%ignore spine::TranslateTimeline::TranslateTimeline; +%ignore spine::TwoColorTimeline::TwoColorTimeline; +%ignore spine::VertexAttachment::VertexAttachment; +%ignore spine::VertexEffect::VertexEffect; +%ignore spine::JitterVertexEffect::JitterVertexEffect; +%ignore spine::SwirlVertexEffect::SwirlVertexEffect; +%ignore spine::ConstraintData::ConstraintData; + +%ignore spine::SkeletonRenderer::create; +%ignore spine::SkeletonRenderer::initWithJsonFile; +%ignore spine::SkeletonRenderer::initWithBinaryFile; +%ignore spine::SkeletonRenderer::createWithData; +%ignore spine::SkeletonRenderer::initWithData; +%ignore spine::SkeletonRenderer::createWithSkeleton; +%ignore spine::SkeletonRenderer::createWithFile; +%ignore spine::SkeletonRenderer::getRenderOrder; +%ignore spine::SkeletonAnimation::createWithData; +%ignore spine::SkeletonAnimation::onTrackEntryEvent; +%ignore spine::SkeletonAnimation::onAnimationStateEvent; +%ignore spine::Animation::apply; +%ignore spine::TrackEntry::setListener; +%ignore spine::AnimationState::apply; +%ignore spine::AnimationState::setListener; +%ignore spine::Attachment::getRTTI; +%ignore spine::AttachmentTimeline::apply; +%ignore spine::AttachmentTimeline::getRTTI; +%ignore spine::BoundingBoxAttachment::getRTTI; +%ignore spine::Bone::worldToLocal; +%ignore spine::Bone::localToWorld; +%ignore spine::Bone::getRTTI; +%ignore spine::ClippingAttachment::getRTTI; +%ignore spine::Color::set; +%ignore spine::Color::add; +%ignore spine::ColorTimeline::apply; +%ignore spine::ColorTimeline::getRTTI; +%ignore spine::CurveTimeline::apply; +%ignore spine::CurveTimeline::getRTTI; +%ignore spine::DeformTimeline::apply; +%ignore spine::DeformTimeline::setFrame; +%ignore spine::DeformTimeline::getVertices; +%ignore spine::DeformTimeline::getRTTI; +%ignore spine::DrawOrderTimeline::apply; +%ignore spine::DrawOrderTimeline::setFrame; +%ignore spine::DrawOrderTimeline::getDrawOrders; +%ignore spine::DrawOrderTimeline::getRTTI; +%ignore spine::EventTimeline::apply; +%ignore spine::EventTimeline::getRTTI; +%ignore spine::IkConstraint::apply; +%ignore spine::IkConstraint::getRTTI; +%ignore spine::IkConstraintTimeline::apply; +%ignore spine::IkConstraintTimeline::getRTTI; +%ignore spine::MeshAttachment::getRTTI; +%ignore spine::PathAttachment::getRTTI; +%ignore spine::PathConstraint::getRTTI; +%ignore spine::PathConstraintMixTimeline::apply; +%ignore spine::PathConstraintMixTimeline::getRTTI; +%ignore spine::PathConstraintPositionTimeline::apply; +%ignore spine::PathConstraintPositionTimeline::getRTTI; +%ignore spine::PathConstraintSpacingTimeline::apply; +%ignore spine::PathConstraintSpacingTimeline::getRTTI; +%ignore spine::PointAttachment::computeWorldPosition; +%ignore spine::PointAttachment::getRTTI; +%ignore spine::PointAttachment::computeWorldRotation; +%ignore spine::RegionAttachment::computeWorldVertices; +%ignore spine::RegionAttachment::getRTTI; +%ignore spine::RotateTimeline::apply; +%ignore spine::RotateTimeline::getRTTI; +%ignore spine::ScaleTimeline::apply; +%ignore spine::ScaleTimeline::getRTTI; +%ignore spine::ShearTimeline::apply; +%ignore spine::ShearTimeline::getRTTI; +%ignore spine::Skeleton::getBounds; +%ignore spine::Skin::getAttachments; +%ignore spine::Skin::findAttachmentsForSlot; +%ignore spine::Skin::findNamesForSlot; +%ignore spine::SkeletonBounds::update; +%ignore spine::SkeletonBounds::aabbIntersectsSkeleton; +%ignore spine::Timeline::apply; +%ignore spine::Timeline::getRTTI; +%ignore spine::TransformConstraint::getRTTI; +%ignore spine::TransformConstraintTimeline::apply; +%ignore spine::TransformConstraintTimeline::getRTTI; +%ignore spine::TranslateTimeline::apply; +%ignore spine::TranslateTimeline::getRTTI; +%ignore spine::TwoColorTimeline::apply; +%ignore spine::TwoColorTimeline::getRTTI; +%ignore spine::VertexEffect::begin; +%ignore spine::VertexEffect::transform; +%ignore spine::VertexEffect::end; +%ignore spine::JitterVertexEffect::begin; +%ignore spine::JitterVertexEffect::transform; +%ignore spine::JitterVertexEffect::end; +%ignore spine::SwirlVertexEffect::begin; +%ignore spine::SwirlVertexEffect::transform; +%ignore spine::SwirlVertexEffect::end; +%ignore spine::VertexAttachment::computeWorldVertices; +%ignore spine::VertexAttachment::getBones; +%ignore spine::VertexAttachment::getRTTI; +%ignore spine::SkeletonDataMgr::destroyInstance; +%ignore spine::SkeletonDataMgr::hasSkeletonData; +%ignore spine::SkeletonDataMgr::setSkeletonData; +%ignore spine::SkeletonDataMgr::retainByUUID; +%ignore spine::SkeletonDataMgr::releaseByUUID; +%ignore spine::SkeletonCacheAnimation::render; +%ignore spine::SkeletonCacheAnimation::getRenderOrder; + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +%rename(create) spine::SkeletonAnimation::createWithFile; +%rename(setCompleteListenerNative) spine::SkeletonAnimation::setCompleteListener; +%rename(setTrackCompleteListenerNative) spine::SkeletonAnimation::setTrackCompleteListener; +%rename(create) spine::SkeletonRenderer::createWithFile; + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// +%import "editor-support/spine/dll.h" +%import "editor-support/spine/RTTI.h" +%import "editor-support/spine/SpineString.h" +%import "editor-support/spine/Vector.h" + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "editor-support/spine/MixBlend.h" +%include "editor-support/spine/MixDirection.h" +%include "editor-support/spine/TransformMode.h" +%include "editor-support/spine/PositionMode.h" +%include "editor-support/spine/SpacingMode.h" +%include "editor-support/spine/RotateMode.h" +%include "editor-support/spine/BlendMode.h" +%include "editor-support/spine/Timeline.h" +%include "editor-support/spine/Animation.h" +%include "editor-support/spine/AnimationState.h" +%include "editor-support/spine/AnimationStateData.h" +%include "editor-support/spine/Attachment.h" +%include "editor-support/spine/AttachmentTimeline.h" +%include "editor-support/spine/BoundingBoxAttachment.h" +%include "editor-support/spine/Bone.h" +%include "editor-support/spine/BoneData.h" +%include "editor-support/spine/ClippingAttachment.h" +%include "editor-support/spine/Color.h" +%include "editor-support/spine/ColorTimeline.h" +%include "editor-support/spine/CurveTimeline.h" +%include "editor-support/spine/DeformTimeline.h" +%include "editor-support/spine/DrawOrderTimeline.h" +%include "editor-support/spine/Event.h" +%include "editor-support/spine/EventData.h" +%include "editor-support/spine/EventTimeline.h" +%include "editor-support/spine/IkConstraint.h" +%include "editor-support/spine/IkConstraintData.h" +%include "editor-support/spine/IkConstraintTimeline.h" +%include "editor-support/spine/MeshAttachment.h" +%include "editor-support/spine/PathAttachment.h" +%include "editor-support/spine/PathConstraint.h" +%include "editor-support/spine/PathConstraintData.h" +%include "editor-support/spine/PathConstraintMixTimeline.h" +%include "editor-support/spine/PathConstraintPositionTimeline.h" +%include "editor-support/spine/PathConstraintSpacingTimeline.h" +%include "editor-support/spine/PointAttachment.h" +%include "editor-support/spine/RegionAttachment.h" +%include "editor-support/spine/RotateTimeline.h" +%include "editor-support/spine/ScaleTimeline.h" +%include "editor-support/spine/ShearTimeline.h" +%include "editor-support/spine/Skeleton.h" +%include "editor-support/spine/Slot.h" +%include "editor-support/spine/Skin.h" +%include "editor-support/spine/SkeletonBounds.h" +%include "editor-support/spine/SkeletonData.h" +%include "editor-support/spine/SlotData.h" + +%include "editor-support/spine/TransformConstraint.h" +%include "editor-support/spine/TransformConstraintData.h" +%include "editor-support/spine/TransformConstraintTimeline.h" +%include "editor-support/spine/TranslateTimeline.h" +%include "editor-support/spine/TwoColorTimeline.h" +%include "editor-support/spine/VertexAttachment.h" +%include "editor-support/spine/VertexEffect.h" +%include "editor-support/spine/ConstraintData.h" + +%include "editor-support/spine-creator-support/VertexEffectDelegate.h" +%include "editor-support/spine-creator-support/SkeletonRenderer.h" +%include "editor-support/spine-creator-support/SkeletonAnimation.h" +%include "editor-support/spine-creator-support/SkeletonDataMgr.h" +// %include "editor-support/spine-creator-support/SkeletonCache.h" +%include "editor-support/spine-creator-support/SkeletonCacheAnimation.h" +%include "editor-support/spine-creator-support/SkeletonCacheMgr.h" \ No newline at end of file diff --git a/native/tools/swig-config/video.i b/native/tools/swig-config/video.i new file mode 100644 index 0000000000..27746d7fc9 --- /dev/null +++ b/native/tools/swig-config/video.i @@ -0,0 +1,85 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// video at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") video + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "ui/videoplayer/VideoPlayer.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_video_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "ui/videoplayer/VideoPlayer.h" diff --git a/native/tools/swig-config/webview.i b/native/tools/swig-config/webview.i new file mode 100644 index 0000000000..5f93f45942 --- /dev/null +++ b/native/tools/swig-config/webview.i @@ -0,0 +1,85 @@ +// Define module +// target_namespace means the name exported to JS, could be same as which in other modules +// webview at the last means the suffix of binding function name, different modules should use unique name +// Note: doesn't support number prefix +%module(target_namespace="jsb") webview + +// Insert code at the beginning of generated header file (.h) +%insert(header_file) %{ +#pragma once +#include "bindings/jswrapper/SeApi.h" +#include "bindings/manual/jsb_conversions.h" +#include "ui/webview/WebView.h" +%} + +// Insert code at the beginning of generated source file (.cpp) +%{ +#include "bindings/auto/jsb_webview_auto.h" +%} + +// ----- Ignore Section ------ +// Brief: Classes, methods or attributes need to be ignored +// +// Usage: +// +// %ignore your_namespace::your_class_name; +// %ignore your_namespace::your_class_name::your_method_name; +// %ignore your_namespace::your_class_name::your_attribute_name; +// +// Note: +// 1. 'Ignore Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed +// + +// ----- Rename Section ------ +// Brief: Classes, methods or attributes needs to be renamed +// +// Usage: +// +// %rename(rename_to_name) your_namespace::original_class_name; +// %rename(rename_to_name) your_namespace::original_class_name::method_name; +// %rename(rename_to_name) your_namespace::original_class_name::attribute_name; +// +// Note: +// 1. 'Rename Section' should be placed before attribute definition and %import/%include +// 2. namespace is needed + + +// ----- Module Macro Section ------ +// Brief: Generated code should be wrapped inside a macro +// Usage: +// 1. Configure for class +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::GeometryRenderer; +// 2. Configure for member function or attribute +// %module_macro(CC_USE_GEOMETRY_RENDERER) cc::pipeline::RenderPipeline::geometryRenderer; +// Note: Should be placed before 'Attribute Section' + +// Write your code bellow + + +// ----- Attribute Section ------ +// Brief: Define attributes ( JS properties with getter and setter ) +// Usage: +// 1. Define an attribute without setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name) +// 2. Define an attribute with getter and setter +// %attribute(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_getter_name, cpp_setter_name) +// 3. Define an attribute without getter +// %attribute_writeonly(your_namespace::your_class_name, cpp_member_variable_type, js_property_name, cpp_setter_name) +// +// Note: +// 1. Don't need to add 'const' prefix for cpp_member_variable_type +// 2. The return type of getter should keep the same as the type of setter's parameter +// 3. If using reference, add '&' suffix for cpp_member_variable_type to avoid generated code using value assignment +// 4. 'Attribute Section' should be placed before 'Import Section' and 'Include Section' +// + +// ----- Import Section ------ +// Brief: Import header files which are depended by 'Include Section' +// Note: +// %import "your_header_file.h" will not generate code for that header file +// + +// ----- Include Section ------ +// Brief: Include header files in which classes and methods will be bound +%include "ui/webview/WebView.h"