From 389bdedda7f43128339da558cde4cdf2d3299895 Mon Sep 17 00:00:00 2001 From: Haixi <64693535+fuhaixi@users.noreply.github.com> Date: Fri, 30 Aug 2024 03:38:34 +0800 Subject: [PATCH 1/4] FBX: add metadata as properties (#5675) Co-authored-by: Kim Kulling --- code/AssetLib/FBX/FBXExporter.cpp | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/code/AssetLib/FBX/FBXExporter.cpp b/code/AssetLib/FBX/FBXExporter.cpp index bfefc92c9..79fa572af 100644 --- a/code/AssetLib/FBX/FBXExporter.cpp +++ b/code/AssetLib/FBX/FBXExporter.cpp @@ -2487,6 +2487,57 @@ const std::map> transform_types = { {"GeometricScalingInverse", {"GeometricScalingInverse", 'i'}} }; +//add metadata to fbx property +void add_meta(FBX::Node& fbx_node, const aiNode* node){ + if(node->mMetaData == nullptr) return; + aiMetadata* meta = node->mMetaData; + for (unsigned int i = 0; i < meta->mNumProperties; ++i) { + aiString key = meta->mKeys[i]; + aiMetadataEntry* entry = &meta->mValues[i]; + switch (entry->mType) { + case AI_BOOL:{ + bool val = *static_cast(entry->mData); + fbx_node.AddP70bool(key.C_Str(), val); + break; + } + case AI_INT32:{ + int32_t val = *static_cast(entry->mData); + fbx_node.AddP70int(key.C_Str(), val); + break; + } + case AI_UINT64:{ + //use string to add uint64 + uint64_t val = *static_cast(entry->mData); + fbx_node.AddP70string(key.C_Str(), std::to_string(val).c_str()); + break; + } + case AI_FLOAT:{ + float val = *static_cast(entry->mData); + fbx_node.AddP70double(key.C_Str(), val); + break; + } + case AI_DOUBLE:{ + double val = *static_cast(entry->mData); + fbx_node.AddP70double(key.C_Str(), val); + break; + } + case AI_AISTRING:{ + aiString val = *static_cast(entry->mData); + fbx_node.AddP70string(key.C_Str(), val.C_Str()); + break; + } + case AI_AIMETADATA: { + //ignore + break; + } + default: + break; + } + + } + +} + // write a single model node to the stream void FBXExporter::WriteModelNode( StreamWriterLE& outstream, @@ -2554,6 +2605,7 @@ void FBXExporter::WriteModelNode( } } } + add_meta(p, node); m.AddChild(p); // not sure what these are for, From 924106188ecb2bae5ae7d1ec23a617261aaa54de Mon Sep 17 00:00:00 2001 From: Aliaksandr Kasmachou Date: Thu, 29 Aug 2024 17:05:32 -0400 Subject: [PATCH 2/4] feat: add option for creating XCFramework and configure minimum iOS target (#5648) * feat: add option for creating XCFramework and configure minimum iOS target with a build parameter * style: update indents for iOS bash script --------- Co-authored-by: Kim Kulling --- include/assimp/module.modulemap | 33 +++++++++++++++++++++++++ port/iOS/README.md | 12 ++++++--- port/iOS/build.sh | 43 ++++++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 include/assimp/module.modulemap diff --git a/include/assimp/module.modulemap b/include/assimp/module.modulemap new file mode 100644 index 000000000..b29725bfc --- /dev/null +++ b/include/assimp/module.modulemap @@ -0,0 +1,33 @@ +// Export headers for Swift (iOS) +module libassimp { + header "ColladaMetaData.h" + header "GltfMaterial.h" + header "ObjMaterial.h" + header "anim.h" + header "camera.h" + header "cexport.h" + header "cfileio.h" + header "cimport.h" + header "color4.h" + header "commonMetaData.h" + header "config.h" + header "defs.h" + header "importerdesc.h" + header "light.h" + header "material.h" + header "matrix3x3.h" + header "matrix4x4.h" + header "mesh.h" + header "metadata.h" + header "pbrmaterial.h" + header "postprocess.h" + header "quaternion.h" + header "revision.h" + header "scene.h" + header "texture.h" + header "types.h" + header "vector2.h" + header "vector3.h" + header "version.h" + export * +} diff --git a/port/iOS/README.md b/port/iOS/README.md index ca5632a1f..7204694a9 100644 --- a/port/iOS/README.md +++ b/port/iOS/README.md @@ -1,7 +1,13 @@ # assimp for iOS (deployment target 6.0+, 32/64bit) -Builds assimp libraries for several iOS CPU architectures at once, and outputs a fat binary from the result. +### Requirements +- cmake +- pkg-config + +Note: all these packages can be installed with [brew](https://brew.sh) + +Builds assimp libraries for several iOS CPU architectures at once, and outputs a fat binary / XCFramework from the result. Run the **build.sh** script from the ```./port/iOS/``` directory. See **./build.sh --help** for information about command line options. @@ -15,11 +21,11 @@ shadeds-Mac:iOS arul$ ./build.sh --help Example: ```bash cd ./port/iOS/ -./build.sh --stdlib=libc++ --archs="armv7 arm64 i386" +./build.sh --stdlib=libc++ --archs="arm64 x86_64" --no-fat --min-version="16.0" ``` Supported architectures/devices: -### Simulator +### Simulator [CPU Architectures](https://docs.elementscompiler.com/Platforms/Cocoa/CpuArchitectures/) - i386 - x86_64 diff --git a/port/iOS/build.sh b/port/iOS/build.sh index 64e564848..39df1e3d0 100755 --- a/port/iOS/build.sh +++ b/port/iOS/build.sh @@ -76,7 +76,7 @@ build_arch() rm CMakeCache.txt - CMAKE_CLI_INPUT="-DCMAKE_C_COMPILER=$CMAKE_C_COMPILER -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER -DCMAKE_TOOLCHAIN_FILE=./port/iOS/IPHONEOS_$(echo $1 | tr '[:lower:]' '[:upper:]')_TOOLCHAIN.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS" + CMAKE_CLI_INPUT="-DCMAKE_C_COMPILER=$CMAKE_C_COMPILER -DCMAKE_CXX_COMPILER=$CMAKE_CXX_COMPILER -DCMAKE_TOOLCHAIN_FILE=./port/iOS/IPHONEOS_$(echo $1 | tr '[:lower:]' '[:upper:]')_TOOLCHAIN.cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBUILD_SHARED_LIBS=$BUILD_SHARED_LIBS -DASSIMP_BUILD_ZLIB=ON" echo "[!] Running CMake with -G 'Unix Makefiles' $CMAKE_CLI_INPUT" @@ -102,6 +102,7 @@ CPP_STD_LIB=${CPP_STD_LIB_LIST[0]} CPP_STD=${CPP_STD_LIST[0]} DEPLOY_ARCHS=${BUILD_ARCHS_ALL[*]} DEPLOY_FAT=1 +DEPLOY_XCFramework=1 for i in "$@"; do case $i in @@ -117,6 +118,11 @@ for i in "$@"; do DEPLOY_ARCHS=`echo $i | sed 's/[-a-zA-Z0-9]*=//'` echo "[!] Selecting architectures: $DEPLOY_ARCHS" ;; + --min-version=*) + MIN_IOS_VERSION=`echo $i | sed 's/[-a-zA-Z0-9]*=//'` + IOS_SDK_TARGET=$MIN_IOS_VERSION + echo "[!] Selecting minimum iOS version: $MIN_IOS_VERSION" + ;; --debug) BUILD_TYPE=Debug echo "[!] Selecting build type: Debug" @@ -129,11 +135,17 @@ for i in "$@"; do DEPLOY_FAT=0 echo "[!] Fat binary will not be created." ;; + --no-xcframework) + DEPLOY_XCFramework=0 + echo "[!] XCFramework will not be created." + ;; -h|--help) echo " - don't build fat library (--no-fat)." + echo " - don't build XCFramework (--no-xcframework)." echo " - Include debug information and symbols, no compiler optimizations (--debug)." echo " - generate dynamic libraries rather than static ones (--shared-lib)." echo " - supported architectures (--archs): $(echo $(join , ${BUILD_ARCHS_ALL[*]}) | sed 's/,/, /g')" + echo " - minimum iOS version (--min-version): 16.0" echo " - supported C++ STD libs (--stdlib): $(echo $(join , ${CPP_STD_LIB_LIST[*]}) | sed 's/,/, /g')" echo " - supported C++ standards (--std): $(echo $(join , ${CPP_STD_LIST[*]}) | sed 's/,/, /g')" exit @@ -196,3 +208,32 @@ if [[ "$DEPLOY_FAT" -eq 1 ]]; then echo "[!] Done! The fat binaries can be found at $BUILD_DIR" fi + +make_xcframework() +{ + LIB_NAME=$1 + FRAMEWORK_PATH=$BUILD_DIR/$LIB_NAME.xcframework + + ARGS = "" + for ARCH_TARGET in $DEPLOY_ARCHS; do + if [[ "$BUILD_SHARED_LIBS" =~ "ON" ]]; then + ARGS="$ARGS -library $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.dylib -headers ./include " + else + ARGS="$ARGS -library $BUILD_DIR/$ARCH_TARGET/$LIB_NAME.a -headers ./include " + fi + done + + xcodebuild -create-xcframework $ARGS -output $FRAMEWORK_PATH +} + +if [[ "$DEPLOY_XCFramework" -eq 1 ]]; then + echo '[+] Creating XCFramework ...' + + if [[ "$BUILD_TYPE" =~ "Debug" ]]; then + make_xcframework 'libassimpd' + else + make_xcframework 'libassimp' + fi + + echo "[!] Done! The XCFramework can be found at $BUILD_DIR" +fi \ No newline at end of file From ae0ff8a88af479ddad9e2545eb9cd660cf4c110f Mon Sep 17 00:00:00 2001 From: Vincent Fazio Date: Fri, 30 Aug 2024 07:45:35 +1000 Subject: [PATCH 3/4] Update PyAssimp structs with Skeleton & SkeletonBone members (#5734) Co-authored-by: Kim Kulling --- port/PyAssimp/pyassimp/structs.py | 61 ++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/port/PyAssimp/pyassimp/structs.py b/port/PyAssimp/pyassimp/structs.py index d442df9fb..e34ddd800 100644 --- a/port/PyAssimp/pyassimp/structs.py +++ b/port/PyAssimp/pyassimp/structs.py @@ -1,6 +1,6 @@ #-*- coding: utf-8 -*- -from ctypes import POINTER, c_void_p, c_uint, c_char, c_float, Structure, c_double, c_ubyte, c_size_t, c_uint32 +from ctypes import POINTER, c_void_p, c_uint, c_char, c_float, Structure, c_double, c_ubyte, c_size_t, c_uint32, c_int class Vector2D(Structure): @@ -78,7 +78,7 @@ class String(Structure): # the number of bytes from the beginning of the string to its end. ("length", c_uint32), - # String buffer. Size limit is MAXLEN + # String buffer. Size limit is AI_MAXLEN ("data", c_char*AI_MAXLEN), ] @@ -1010,6 +1010,54 @@ class Animation(Structure): ] +class SkeletonBone(Structure): + """ + See 'mesh.h' for details + """ + _fields_ = [ + # The parent bone index, is -1 one if this bone represents the root bone. + ("mParent", c_int), + + # The number of weights + ("mNumnWeights", c_uint), + + # The mesh index, which will get influenced by the weight + ("mMeshId", POINTER(Mesh)), + + # The influence weights of this bone, by vertex index. + ("mWeights", POINTER(VertexWeight)), + + # Matrix that transforms from bone space to mesh space in bind pose. + # + # This matrix describes the position of the mesh + # in the local space of this bone when the skeleton was bound. + # Thus it can be used directly to determine a desired vertex position, + # given the world-space transform of the bone when animated, + # and the position of the vertex in mesh space. + # + # It is sometimes called an inverse-bind matrix, + # or inverse bind pose matrix + ("mOffsetMatrix", Matrix4x4), + + # Matrix that transforms the locale bone in bind pose. + ("mLocalMatrix", Matrix4x4) + ] + +class Skeleton(Structure): + """ + See 'mesh.h' for details + """ + _fields_ = [ + # Name + ("mName", String), + + # Number of bones + ("mNumBones", c_uint), + + # Bones + ("mBones", POINTER(POINTER(SkeletonBone))) + ] + class ExportDataBlob(Structure): """ See 'cexport.h' for details. @@ -1131,6 +1179,15 @@ class Scene(Structure): # can be used to store format-specific metadata as well. ("mMetadata", POINTER(Metadata)), + # The name of the scene itself + ("mName", String), + + # Number of skeletons + ("mNumSkeletons", c_uint), + + # Skeletons + ("mSkeletons", POINTER(POINTER(Skeleton))), + # Internal data, do not touch ("mPrivate", POINTER(c_char)), ] From 5e912e68da5cf17ca500cf1ae8fe8c15d0b65dae Mon Sep 17 00:00:00 2001 From: Fav Date: Fri, 30 Aug 2024 05:55:18 +0800 Subject: [PATCH 4/4] Update glTF2AssetWriter.inl (#5647) The total length is incorrect when exporting gltf2 Co-authored-by: Kim Kulling --- code/AssetLib/glTF2/glTF2AssetWriter.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/glTF2/glTF2AssetWriter.inl b/code/AssetLib/glTF2/glTF2AssetWriter.inl index 3e42ffe57..0ca23863c 100644 --- a/code/AssetLib/glTF2/glTF2AssetWriter.inl +++ b/code/AssetLib/glTF2/glTF2AssetWriter.inl @@ -940,7 +940,7 @@ namespace glTF2 { if (outfile->Write(bodyBuffer->GetPointer(), 1, bodyBuffer->byteLength) != bodyBuffer->byteLength) { throw DeadlyExportError("Failed to write body data!"); } - if (curPaddingLength && outfile->Write(&padding, 1, paddingLength) != paddingLength) { + if (curPaddingLength && outfile->Write(&padding, 1, curPaddingLength) != curPaddingLength) { throw DeadlyExportError("Failed to write body data padding!"); } }