From e3b116851fd63929088333ac96ea6322ade8f72d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 22 Oct 2024 09:41:45 +0800 Subject: [PATCH 1/2] Don't export enums in c++ since they're defined in spine-core.js. And using `_enum` will generate a different enum format like `var TimelineType = { rotate: { value: 0} }; ` rather than `var TimelineType = { rotate: 0 };` --- .../spine-wasm/spine-type-export.cpp | 109 ------------------ 1 file changed, 109 deletions(-) diff --git a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp index 40468f9886c..5765f49b5fc 100644 --- a/native/cocos/editor-support/spine-wasm/spine-type-export.cpp +++ b/native/cocos/editor-support/spine-wasm/spine-type-export.cpp @@ -313,119 +313,10 @@ EMSCRIPTEN_BINDINGS(spine) { std::string stdStr(obj.buffer(), obj.length()); return stdStr; }), allow_raw_pointers()); - enum_("TimelineType") - .value("rotate", TimelineType_Rotate) - .value("translate", TimelineType_Translate) - .value("scale", TimelineType_Scale) - .value("shear", TimelineType_Shear) - .value("attachment", TimelineType_Attachment) - .value("color", TimelineType_Color) - .value("deform", TimelineType_Deform) - .value("event", TimelineType_Event) - .value("drawOrder", TimelineType_DrawOrder) - .value("ikConstraint", TimelineType_IkConstraint) - .value("transformConstraint", TimelineType_TransformConstraint) - .value("pathConstraintPosition", TimelineType_PathConstraintPosition) - .value("pathConstraintSpacing", TimelineType_PathConstraintSpacing) - .value("pathConstraintMix", TimelineType_PathConstraintMix) - .value("twoColor", TimelineType_TwoColor); - - enum_("MixDirection") - .value("mixIn", MixDirection_In) - .value("mixOut", MixDirection_Out); - - enum_("MixBlend") - .value("setup", MixBlend_Setup) - .value("first", MixBlend_First) - .value("replace", MixBlend_Replace) - .value("add", MixBlend_Add); - - enum_("BlendMode") - .value("Normal", BlendMode_Normal) - .value("Additive", BlendMode_Additive) - .value("Multiply", BlendMode_Multiply) - .value("Screen", BlendMode_Screen); - - enum_("EventType") - .value("start", EventType_Start) - .value("interrupt", EventType_Interrupt) - .value("end", EventType_End) - .value("dispose", EventType_Dispose) - .value("complete", EventType_Complete) - .value("event", EventType_Event); - - enum_("TransformMode") - .value("Normal", TransformMode_Normal) - .value("OnlyTranslation", TransformMode_OnlyTranslation) - .value("NoRotationOrReflection", TransformMode_NoRotationOrReflection) - .value("NoScale", TransformMode_NoScale) - .value("NoScaleOrReflection", TransformMode_NoScaleOrReflection); - - enum_("PositionMode") - .value("Fixed", PositionMode_Fixed) - .value("Percent", PositionMode_Percent); - - enum_("SpacingMode") - .value("Length", SpacingMode_Length) - .value("Fixed", SpacingMode_Fixed) - .value("Percent", SpacingMode_Percent); - - enum_("RotateMode") - .value("Tangent", RotateMode_Tangent) - .value("Chain", RotateMode_Chain) - .value("ChainScale", RotateMode_ChainScale); - - enum_("TextureFilter") - .value("Unknown", TextureFilter_Unknown) - .value("Nearest", TextureFilter_Nearest) - .value("Linear", TextureFilter_Linear) - .value("MipMap", TextureFilter_MipMap) - .value("MipMapNearestNearest", TextureFilter_MipMapNearestNearest) - .value("MipMapLinearNearest", TextureFilter_MipMapLinearNearest) - .value("MipMapNearestLinear", TextureFilter_MipMapNearestLinear) - .value("MipMapLinearLinear", TextureFilter_MipMapLinearLinear); - - enum_("TextureWrap") - .value("MirroredRepeat", TextureWrap_MirroredRepeat) - .value("ClampToEdge", TextureWrap_ClampToEdge) - .value("Repeat", TextureWrap_Repeat); - - enum_("AttachmentType") - .value("Region", AttachmentType_Region) - .value("BoundingBox", AttachmentType_Boundingbox) - .value("Mesh", AttachmentType_Mesh) - .value("LinkedMesh", AttachmentType_Linkedmesh) - .value("Path", AttachmentType_Path) - .value("Point", AttachmentType_Point) - .value("Clipping", AttachmentType_Clipping); ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////// - class_("MathUtils") - .class_property("PI", &MathUtil::Pi) - .class_property("PI2", &MathUtil::Pi_2) - .class_property("radDeg", &MathUtil::Rad_Deg) - .class_property("degreesToRadians", &MathUtil::Rad_Deg) - .class_property("degRad", &MathUtil::Deg_Rad) - .class_property("degreesToRadians", &MathUtil::Deg_Rad) - .class_function("abs", &MathUtil::abs) - .class_function("signum", &MathUtil::sign) - .class_function("clamp", &MathUtil::clamp) - .class_function("fmod", &MathUtil::fmod) - .class_function("atan2", &MathUtil::atan2) - .class_function("cos", &MathUtil::cos) - .class_function("sin", &MathUtil::sin) - .class_function("sqrt", &MathUtil::sqrt) - .class_function("acos", &MathUtil::acos) - .class_function("sinDeg", &MathUtil::sinDeg) - .class_function("cosDeg", &MathUtil::cosDeg) - .class_function("isNan", &MathUtil::isNan) - .class_function("random", &MathUtil::random) - .class_function("randomTriangular", select_overload(&MathUtil::randomTriangular)) - .class_function("randomTriangularWith", select_overload(&MathUtil::randomTriangular)) - .class_function("pow", &MathUtil::pow); - class_("Color") .constructor<>() .constructor() From 89eb783df0c0f786eeedbb9ca4d0804da738587d Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 22 Oct 2024 10:17:13 +0800 Subject: [PATCH 2/2] Update CMakeLists.txt, add a variable `BUILD_WASM` to control whether to build wasm or asmjs. --- native/cocos/editor-support/spine-wasm/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/native/cocos/editor-support/spine-wasm/CMakeLists.txt b/native/cocos/editor-support/spine-wasm/CMakeLists.txt index 9e95bfb2575..0568e62b522 100644 --- a/native/cocos/editor-support/spine-wasm/CMakeLists.txt +++ b/native/cocos/editor-support/spine-wasm/CMakeLists.txt @@ -3,6 +3,8 @@ cmake_minimum_required(VERSION 3.0) set(CMAKE_VERBOSE_MAKEFILE ON) set(CMAKE_BUILD_TYPE "MinSizeRel") +set(BUILD_WASM 1) + set(APP_NAME "spine" CACHE STRING "Project Name") project(${APP_NAME}_wasm) @@ -21,7 +23,7 @@ file(GLOB COCOS_ADAPTER_SRC "./*.cpp") add_executable(${APP_NAME} ${SPINE_CORE_SRC} ${COCOS_ADAPTER_SRC} ) #add_executable(${APP_NAME} ${COCOS_ADAPTER_SRC}) -set(EMS_LINK_FLAGS "-O3 -s WASM=1 -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ +set(EMS_LINK_FLAGS "-O3 -s WASM=${BUILD_WASM} -s INITIAL_MEMORY=33554432 -s ALLOW_MEMORY_GROWTH=1 -s DYNAMIC_EXECUTION=0 -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -flto --no-entry --bind -s USE_ES6_IMPORT_META=0 -s EXPORT_ES6=1 -s MODULARIZE=1 -s EXPORT_NAME='spineWasm' \ -s ENVIRONMENT=web -s FILESYSTEM=0 -s NO_EXIT_RUNTIME=1 -s LLD_REPORT_UNDEFINED \ -s MIN_SAFARI_VERSION=110000 \