### Example Build Configuration Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Controls whether example applications are built based on the `DNAC_BUILD_EXAMPLES` option. It also conditionally copies the shared library to the examples directory if shared libraries are being built. ```cmake option(DNAC_BUILD_EXAMPLES "Build examples" ON) if(DNAC_BUILD_EXAMPLES) set(COPY_LIB_TO_EXAMPLES OFF) if(BUILD_SHARED_LIBS) set(COPY_LIB_TO_EXAMPLES ON) endif() add_subdirectory(examples) ``` -------------------------------- ### Full Mesh Building Example Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer_api_build_meshes.md Demonstrates a complete workflow for building meshes from a DNA file, including environment setup, DNA loading, and mesh building with both default and custom configurations. ```python from dna_viewer import DNA, Config, build_meshes import os # if you use Maya, use absolute path ROOT_DIR = f"{os.path.dirname(os.path.abspath(__file__))}/..".replace("\", "/") # Sets DNA file path DNA_PATH_ADA = f"{ROOT_DIR}/data/dna_files/Ada.dna" dna_ada = DNA(DNA_PATH_ADA) # Starts the mesh build process with all the default values build_meshes(dna=dna_ada) # Creates the options to be passed in `build_meshes` config = Config( add_joints=True, add_blend_shapes=True, add_skin_cluster=True, add_ctrl_attributes_on_root_joint=True, add_animated_map_attributes_on_root_joint=True, lod_filter=[0, 1], mesh_filter=["head"], ) # Starts the mesh building process with the provided parameters # In this case it will create every mesh contained in LODs 0 and 1 with 'head` in it's name, build_meshes( dna=dna_ada, config=config, ) ``` -------------------------------- ### Installation and Packaging Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNACalib/python3/CMakeLists.txt Defines installation rules for the generated Python extension library, wrapper files, and example scripts. It also sets up a CMake component for packaging. ```cmake set(component_name "${PROJECT_NAME}-${py_version}") get_property(wrapper_files TARGET py3dnacalib PROPERTY SWIG_SUPPORT_FILES) install(FILES ${wrapper_files} DESTINATION ${output_dir} COMPONENT ${component_name}) install(TARGETS py3dnacalib RUNTIME DESTINATION ${output_dir} COMPONENT ${component_name} LIBRARY DESTINATION ${output_dir} COMPONENT ${component_name} NAMELINK_COMPONENT ${component_name} ARCHIVE DESTINATION ${output_dir} COMPONENT ${component_name}) install(FILES ${CMAKE_CURRENT_LIST_DIR}/examples/clear_blend_shapes.py DESTINATION ${output_dir}/examples RENAME dnacalib_clear_blend_shapes.py COMPONENT ${component_name}) install(FILES ${CMAKE_CURRENT_LIST_DIR}/examples/demo.py DESTINATION ${output_dir}/examples RENAME dnacalib_demo.py COMPONENT ${component_name}) install(FILES ${CMAKE_CURRENT_LIST_DIR}/examples/remove_joint.py DESTINATION ${output_dir}/examples RENAME dnacalib_remove_joint.py COMPONENT ${component_name}) set(CPACK_COMPONENTS_ALL "${CPACK_COMPONENTS_ALL};${component_name}" PARENT_SCOPE) ``` -------------------------------- ### Project Setup and Versioning Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Initializes the CMake project, sets the project name and version, and configures build options like disabling in-source builds and exporting compilation commands. ```cmake cmake_minimum_required(VERSION 3.13) ################################################ # Project setup set(DNAC dnacalib) set(DNAC_VERSION 6.8.0) # Prevent in-source-tree builds set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # Create compilation database set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "" FORCE) project(DNACalib VERSION ${DNAC_VERSION} LANGUAGES CXX) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_MODULES_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH ${CMAKE_MODULES_ROOT_DIR}) ``` -------------------------------- ### Build Rig Example Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer_api_build_rig.md An example demonstrating how to create a `RigConfig` instance and use the `build_rig` function to assemble a character rig in Maya from a DNA file. Requires environment setup. ```python from dna_viewer import DNA, RigConfig, build_rig import os # if you use Maya, use absolute path ROOT_DIR = f"{os.path.dirname(os.path.abspath(__file__))}/..".replace("\", "/") # Sets the values that will used DNA_PATH_ADA = f"{ROOT_DIR}/data/dna_files/Ada.dna" dna_ada = DNA(DNA_PATH_ADA) config = RigConfig( gui_path=f"{ROOT_DIR}/data/gui.ma", analog_gui_path=f"{ROOT_DIR}/data/analog_gui.ma", aas_path=f"{ROOT_DIR}/data/additional_assemble_script.py", ) # Creates the rig build_rig(dna=dna_ada, config=config) ``` -------------------------------- ### Example: Generates rig Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer.md Python script demonstrating how to generate a rig using the DNAViewer. ```python import dna_viewer # Example usage: dna_file = "path/to/your/dna/file.dna" output_rig_path = "path/to/save/rig.ma" dna_viewer.build_rig(dna_file, output_rig_path) ``` -------------------------------- ### CMake Build Configuration for Examples Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/examples/CMakeLists.txt This snippet demonstrates the CMake configuration for building example executables. It defines source files, iterates through them to create individual targets, links the DNAC library, and sets C++ standard properties. It also manages a list of created targets and conditionally copies the DNAC library after the build. ```cmake set(SOURCES CommandSequence.cpp SingleCommand.cpp) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) foreach(example IN LISTS SOURCES) get_filename_component(filename ${example} NAME_WE) string(TOLOWER ${filename} example_target_name) add_executable(${example_target_name} ${example}) target_link_libraries(${example_target_name} PRIVATE ${DNAC}) set_target_properties(${example_target_name} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED NO CXX_EXTENSIONS NO FOLDER examples) list(APPEND EXAMPLE_TARGETS ${example_target_name}) endforeach() set(DNAC_EXAMPLES ${EXAMPLE_TARGETS} PARENT_SCOPE) if(COPY_LIB_TO_EXAMPLES) list(GET EXAMPLE_TARGETS 0 EXAMPLE_TARGET) add_custom_command(TARGET ${EXAMPLE_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $) endif() ``` -------------------------------- ### Example: Simple UI Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer.md Python script demonstrating how to run the DNAViewer with a simple user interface in Maya. ```python import dna_viewer # Example usage: dna_viewer.run_in_maya() ``` -------------------------------- ### FAQ Guide Reference Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/README.md A link to the FAQ guide for additional specifications and troubleshooting information related to the MetaHuman DNA Calibration project. ```text See the [FAQ guide](docs/faq.md) for additional specifications. ``` -------------------------------- ### Spyus Library Definition and Installation Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/SPyUS/CMakeLists.txt Defines the Spyus library as an INTERFACE library, sets up public include directories for both build and installation contexts, and installs the library using a custom install_library macro. ```cmake ################################################ # Source code set(HEADERS include/spyus/ArrayView.i include/spyus/Caster.i include/spyus/ExceptionHandling.i include/spyus/TDM.i include/spyus/Vector3.i) source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS}) ################################################ # Add target and build options add_library(${SPYUS} INTERFACE) add_library(Spyus::spyus ALIAS ${SPYUS}) include(GNUInstallDirs) set(SPYUS_PUBLIC_INCLUDE_DIRS $ $) target_include_directories(${SPYUS} INTERFACE ${SPYUS_PUBLIC_INCLUDE_DIRS}) ################################################ # Export and install target include(InstallLibrary) install_library(${SPYUS}) ``` -------------------------------- ### Source Files Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Lists all source files for the MetaHuman DNA Calibration project, including implementation files for commands, DNA reading, types, and utilities. ```cmake set(SOURCES src/dnacalib/Command.cpp src/dnacalib/CommandImplBase.h src/dnacalib/TypeDefs.h src/dnacalib/commands/CalculateMeshLowerLODsCommand.cpp src/dnacalib/commands/CalculateMeshLowerLODsCommandImpl.cpp src/dnacalib/commands/CalculateMeshLowerLODsCommandImpl.h src/dnacalib/commands/ClearBlendShapesCommand.cpp src/dnacalib/commands/CommandSequence.cpp src/dnacalib/commands/PruneBlendShapeTargetsCommand.cpp src/dnacalib/commands/RemoveAnimatedMapCommand.cpp src/dnacalib/commands/RemoveBlendShapeCommand.cpp src/dnacalib/commands/RemoveJointAnimationCommand.cpp src/dnacalib/commands/RemoveJointCommand.cpp src/dnacalib/commands/RemoveMeshCommand.cpp src/dnacalib/commands/RenameAnimatedMapCommand.cpp src/dnacalib/commands/RenameBlendShapeCommand.cpp src/dnacalib/commands/RenameJointCommand.cpp src/dnacalib/commands/RenameMeshCommand.cpp src/dnacalib/commands/RenameResourceCommand.h src/dnacalib/commands/RotateCommand.cpp src/dnacalib/commands/ScaleCommand.cpp src/dnacalib/commands/SetBlendShapeTargetDeltasCommand.cpp src/dnacalib/commands/SetLODsCommand.cpp src/dnacalib/commands/SetNeutralJointRotationsCommand.cpp src/dnacalib/commands/SetNeutralJointTranslationsCommand.cpp src/dnacalib/commands/SetSkinWeightsCommand.cpp src/dnacalib/commands/SetVertexPositionsCommand.cpp src/dnacalib/commands/TranslateCommand.cpp src/dnacalib/commands/SupportFactories.h src/dnacalib/dna/DNACalibDNAReaderImpl.cpp src/dnacalib/dna/DNACalibDNAReaderImpl.h src/dnacalib/dna/BaseImpl.h src/dnacalib/dna/DenormalizedData.h src/dnacalib/dna/DNA.h src/dnacalib/dna/LODConstraint.cpp src/dnacalib/dna/LODConstraint.h src/dnacalib/dna/LODMapping.cpp src/dnacalib/dna/LODMapping.h src/dnacalib/dna/ReaderImpl.h src/dnacalib/dna/SurjectiveMapping.h src/dnacalib/dna/WriterImpl.h src/dnacalib/dna/filters/AnimatedMapFilter.cpp src/dnacalib/dna/filters/AnimatedMapFilter.h src/dnacalib/dna/filters/BlendShapeFilter.cpp src/dnacalib/dna/filters/BlendShapeFilter.h src/dnacalib/dna/filters/JointFilter.cpp src/dnacalib/dna/filters/JointFilter.h src/dnacalib/dna/filters/MeshFilter.cpp src/dnacalib/dna/filters/MeshFilter.h src/dnacalib/dna/filters/Remap.h src/dnacalib/types/BoundingBox.h src/dnacalib/types/Triangle.cpp src/dnacalib/types/Triangle.h src/dnacalib/types/UVBarycentricMapping.cpp src/dnacalib/types/UVBarycentricMapping.h src/dnacalib/utils/Algorithm.h src/dnacalib/utils/Extd.h src/dnacalib/utils/ScopedEnumEx.h src/dnacalib/version/VersionInfo.cpp) ``` -------------------------------- ### Header Files Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Lists all header files included in the MetaHuman DNA Calibration project, organized by their functionality and location within the include directory. ```cmake set(HEADERS include/dnacalib/DNACalib.h include/dnacalib/Command.h include/dnacalib/Defs.h include/dnacalib/commands/CalculateMeshLowerLODsCommand.h include/dnacalib/commands/ClearBlendShapesCommand.h include/dnacalib/commands/CommandSequence.h include/dnacalib/commands/ConditionalCommand.h include/dnacalib/commands/PruneBlendShapeTargetsCommand.h include/dnacalib/commands/RemoveAnimatedMapCommand.h include/dnacalib/commands/RemoveBlendShapeCommand.h include/dnacalib/commands/RemoveJointAnimationCommand.h include/dnacalib/commands/RemoveJointCommand.h include/dnacalib/commands/RemoveMeshCommand.h include/dnacalib/commands/RenameAnimatedMapCommand.h include/dnacalib/commands/RenameBlendShapeCommand.h include/dnacalib/commands/RenameJointCommand.h include/dnacalib/commands/RenameMeshCommand.h include/dnacalib/commands/RotateCommand.h include/dnacalib/commands/ScaleCommand.h include/dnacalib/commands/SetBlendShapeTargetDeltasCommand.h include/dnacalib/commands/SetLODsCommand.h include/dnacalib/commands/SetNeutralJointRotationsCommand.h include/dnacalib/commands/SetNeutralJointTranslationsCommand.h include/dnacalib/commands/SetSkinWeightsCommand.h include/dnacalib/commands/SetVertexPositionsCommand.h include/dnacalib/commands/TranslateCommand.h include/dnacalib/commands/VectorOperations.h include/dnacalib/dna/DNACalibDNAReader.h include/dnacalib/types/Aliases.h include/dnacalib/version/Version.h include/dnacalib/version/VersionInfo.h) ``` -------------------------------- ### Project Build Options Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Configures build options for the MetaHuman DNA Calibration library, including the choice between static and shared libraries. ```cmake option(BUILD_SHARED_LIBS "Build shared libraries" OFF) set(DNAC_DEFAULT_LIBRARY_TYPE STATIC) if(BUILD_SHARED_LIBS) set(DNAC_DEFAULT_LIBRARY_TYPE SHARED) endif() set(DNAC_LIBRARY_TYPE ${DNAC_DEFAULT_LIBRARY_TYPE} CACHE STRING "Build DNACalib as a library of type") set_property(CACHE DNAC_LIBRARY_TYPE PROPERTY STRINGS STATIC SHARED MODULE) ``` -------------------------------- ### Installation Configuration for py3dna and Demo Script Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNA/python3/CMakeLists.txt Configures the installation of the py3dna library and its wrapper files, as well as a demo Python script. It defines installation components and destinations based on the project name and Python version. ```cmake set(component_name "${PROJECT_NAME}-${py_version}") get_property(wrapper_files TARGET py3dna PROPERTY SWIG_SUPPORT_FILES) install(FILES ${wrapper_files} DESTINATION ${output_dir} COMPONENT ${component_name}) install(TARGETS py3dna RUNTIME DESTINATION ${output_dir} COMPONENT ${component_name} LIBRARY DESTINATION ${output_dir} COMPONENT ${component_name} NAMELINK_COMPONENT ${component_name} ARCHIVE DESTINATION ${output_dir} COMPONENT ${component_name}) install(FILES ${CMAKE_CURRENT_LIST_DIR}/examples/demo.py DESTINATION ${output_dir} RENAME dna_demo.py COMPONENT ${component_name}) set(CPACK_COMPONENTS_ALL "${CPACK_COMPONENTS_ALL};${component_name}" PARENT_SCOPE) ``` -------------------------------- ### Version Information Header Generation Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Generates a C++ header file containing version information for the project. This is conditionally executed if the source tree is not read-only, utilizing a `VersionHeader` module. ```cmake option(READ_ONLY_SOURCE_TREE "Prevent autogeneration of files in source tree" OFF) ################################################ # Generate version information header if (NOT READ_ONLY_SOURCE_TREE) include(VersionHeader) generate_version_header( OUTPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/dnacalib/version/Version.h" PREFIX "DNAC" MAJOR ${PROJECT_VERSION_MAJOR} MINOR ${PROJECT_VERSION_MINOR} PATCH ${PROJECT_VERSION_PATCH}) endif() ``` -------------------------------- ### Example: Export FBX per LOD Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer.md Python script demonstrating how to export FBX files per Level of Detail (LOD) using the DNAViewer. ```python import dna_viewer # Example usage: dna_file = "path/to/your/dna/file.dna" output_fbx_path = "path/to/export/fbx/" lods_to_export = [0, 1, 2] for lod in lods_to_export: dna_viewer.export_fbx(dna_file, lod, output_fbx_path) ``` -------------------------------- ### Dependency Management and Source Grouping Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Includes external dependencies and defines source groups for better organization within IDEs. It links the DNAC library with its public and private dependencies. ```cmake include(DNACDependencies) set(ADAPTABLE_HEADERS) foreach(hdr IN LISTS HEADERS) list(APPEND ADAPTABLE_HEADERS $ $) endforeach() source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${HEADERS} ${SOURCES}) target_sources(${DNAC} PRIVATE ${SOURCES} ${OBJECT_SOURCES} PUBLIC ${ADAPTABLE_HEADERS}) target_link_libraries(${DNAC} PUBLIC ${DNAC_PUBLIC_DEPENDENCIES} PRIVATE ${DNAC_PRIVATE_DEPENDENCIES}) ``` -------------------------------- ### Example: Propagate changes from Maya scene to DNA Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer.md Python script demonstrating how to propagate changes made in a Maya scene back to the DNA file using the DNAViewer. ```python import dna_viewer # Example usage: dna_file = "path/to/your/dna/file.dna" maya_scene = "path/to/your/maya/scene.ma" dna_viewer.propagate_changes(dna_file, maya_scene) ``` -------------------------------- ### Add Directories to Python Path Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/README.md Adds the project's root directory and library directory to the Python system path for module imports. This is a common setup step for Python projects. ```python import sys syspath.insert(0, ROOT_DIR) syspath.insert(0, LIB_DIR) ``` -------------------------------- ### CMake Project Setup and SWIG Integration Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNA/CMakeLists.txt Configures the CMake build system for the PyDNA project. It specifies the minimum required CMake version, project name, C++ standard, and integrates SWIG for C++/Python interoperability. It also includes a subdirectory for Python 3 related build targets. ```cmake cmake_minimum_required(VERSION 3.14) project(PyDNA) set(CMAKE_CXX_STANDARD 11) find_package(SWIG 4.0.0) include(UseSWIG) add_subdirectory(python3) ``` -------------------------------- ### Compiler Flags and Warning Management Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Sets compiler flags for both MSVC and GCC/Clang, including specific warning levels and options. It also includes logic to treat warnings as errors based on the `TREAT_WARNINGS_AS_ERRORS` option. ```cmake option(TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) if(MSVC) set(CXX_FLAGS /W4 /w14061 /w14062 /w14121 /w14242 /w14245 /w14254 /w14263 /w14265 /w14266 /w14287 /w14289 /w14296 /w14302 /w14311 /w14365 /w14388 /w14545 /w14546 /w14547 /w14549 /w14555 /w14619 /w14640 /w14826 /w14905 /w14906 /w14928 /w14987 /w14946) if(TREAT_WARNINGS_AS_ERRORS) list(APPEND CXX_FLAGS /WX) endif() set(CXX_EXTRA_FLAGS /permissive-) else() set(CXX_FLAGS -Wall -Wextra -Wpedantic) if(TREAT_WARNINGS_AS_ERRORS) list(APPEND CXX_FLAGS -Werror) endif() set(CXX_EXTRA_FLAGS -Wcast-align -Wconversion -Wduplicated-branches -Wduplicated-cond -Wexit-time-destructors -Wglobal-constructors -Wlogical-op -Wmissing-noreturn -Wnon-virtual-dtor -Wnull-dereference -Wold-style-cast -Woverloaded-virtual -Wshadow -Wsign-conversion -Wunreachable-code -Wunused -Wuseless-cast -Wweak-vtables -Wno-unknown-pragmas) endif() target_compile_options(${DNAC} PRIVATE "${CXX_FLAGS}") include(SupportedCompileOptions) target_supported_compile_options(${DNAC} PRIVATE "${CXX_EXTRA_FLAGS}") ``` -------------------------------- ### CMake Project Setup and Subdirectories Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/CMakeLists.txt Configures the CMake build environment, sets the minimum required version, defines the project name, and includes other subdirectories for modular build components. It also enables testing. ```cmake cmake_minimum_required(VERSION 3.14) project(dnacalib) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMakeModulesExtra") enable_testing() add_subdirectory(DNACalib) add_subdirectory(SPyUS) add_subdirectory(PyDNA) add_subdirectory(PyDNACalib) ``` -------------------------------- ### Loading DNA Files Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer_API.md Demonstrates how to load DNA files using the `DNA` class from the `dna_viewer` library. It shows examples of loading specific DNA files and mentions the parameters for the `DNA` constructor, including the DNA file path and optional layers. ```python from dna_viewer import DNA dna_ada = DNA(DNA_PATH_ADA) dna_taro = DNA(DNA_PATH_TARO) ``` -------------------------------- ### CMake Project Setup and Module Loading Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/SPyUS/CMakeLists.txt Configures the CMake build environment, sets project properties, and includes custom CMake modules. It ensures that the build is not performed in-source and generates compilation databases. ```cmake cmake_minimum_required(VERSION 3.14) ################################################ # Project setup set(SPYUS spyus) set(SPYUS_VERSION 1.2.1) # Prevent in-source-tree builds set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) # Create compilation database set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "" FORCE) project(Spyus VERSION ${SPYUS_VERSION} LANGUAGES CXX) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_MODULES_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH ${CMAKE_MODULES_ROOT_DIR}) include(FetchContent) function(module_exists module_name) include(${module_name} OPTIONAL RESULT_VARIABLE found) set("${module_name}_FOUND" ${found} PARENT_SCOPE) endfunction() # Make custom cmake modules available module_exists(CMakeModulesExtra) if(NOT CMakeModulesExtra_FOUND) include(CMakeModulesExtraLoader) endif() include(CMakeModulesExtra) list(APPEND CMAKE_MODULE_PATH ${CMakeModulesExtra_DIRS}) ``` -------------------------------- ### Environment Setup for DNA Viewer Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer_API.md Configures the Python environment by adding necessary directories to `sys.path` and setting the `MAYA_PLUG_IN_PATH` environment variable. This is crucial for importing modules from the dna_viewer library. It dynamically determines the library path based on the operating system. ```python from sys import path as syspath from os import environ, path as ospath ROOT_DIR = fr"{ospath.dirname(ospath.abspath(__file__))}/..".replace("\", "/") # if you use Maya, use an absolute path instead ROOT_LIB_DIR = fr"{ROOT_DIR}/lib" if platform == "win32": LIB_DIR = f"{ROOT_LIB_DIR}/windows" elif platform == "linux": LIB_DIR = f"{ROOT_LIB_DIR}/linux" else: raise OSError("OS not supported, please compile dependencies and add value to LIB_DIR") if "MAYA_PLUG_IN_PATH" in environ: separator = ":" if platform == "linux" else ";" environ["MAYA_PLUG_IN_PATH"] = separator.join([environ["MAYA_PLUG_IN_PATH"], LIB_DIR]) else: environ["MAYA_PLUG_IN_PATH"] = LIB_DIR syspath.append(ROOT_DIR) syspath.append(LIB_DIR) ``` -------------------------------- ### Custom CMake Module Loading Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Includes logic to check for and load custom CMake modules, extending the build system's capabilities. It defines a helper function `module_exists` to check if a module can be included. ```cmake include(FetchContent) function(module_exists module_name) include(${module_name} OPTIONAL RESULT_VARIABLE found) set("${module_name}_FOUND" ${found} PARENT_SCOPE) endfunction() # Make custom cmake modules available module_exists(CMakeModulesExtra) if(NOT CMakeModulesExtra_FOUND) include(CMakeModulesExtraLoader) endif() include(CMakeModulesExtra) list(APPEND CMAKE_MODULE_PATH ${CMakeModulesExtra_DIRS}) ``` -------------------------------- ### CMake Build Configuration for DNAC Library Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Configures the DNAC library build process, including setting C++ standards, visibility, position-independent code, source directories, and versioning. It also handles conditional compilation for shared libraries. ```cmake option(DNAC_BUILD_PIC "Build with position independent code" ON) add_library(${DNAC} ${DNAC_LIBRARY_TYPE}) add_library(DNACalib::dnacalib ALIAS ${DNAC}) set_target_properties(${DNAC} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED NO CXX_EXTENSIONS NO CXX_VISIBILITY_PRESET hidden POSITION_INDEPENDENT_CODE ${DNAC_BUILD_PIC} SOURCE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/src" SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) if (DNAC_LIBRARY_TYPE STREQUAL SHARED) target_compile_definitions(${DNAC} PUBLIC DNAC_SHARED PRIVATE DNAC_BUILD_SHARED) endif() include(GNUInstallDirs) set(DNAC_PUBLIC_INCLUDE_DIRS $ $) target_include_directories(${DNAC} PUBLIC ${DNAC_PUBLIC_INCLUDE_DIRS} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) ``` -------------------------------- ### Example Demo Script Execution Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNA/python3/CMakeLists.txt This Python script demonstrates the functionality of the DNA calibration library. It likely involves loading DNA data, performing calibration, and potentially converting it to JSON format, as indicated by the test names. ```python # This is a placeholder for the actual demo.py content. # The CMake configuration executes this script to test the library. # Example usage might involve: # import dna # calibration_data = dna.load_dna("path/to/dna/file") # calibrated_data = dna.calibrate(calibration_data) # json_output = dna.to_json(calibrated_data) # print("Done.") ``` -------------------------------- ### Windows Version Information Generation Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Generates version information for the DLL on Windows platforms when building a shared or module library. This includes project name, file name, version numbers, company name, and copyright. ```cmake if(WIN32 AND (DNAC_LIBRARY_TYPE STREQUAL SHARED OR DNAC_LIBRARY_TYPE STREQUAL MODULE)) include(VersionInfo) add_version_info(${DNAC} NAME ${PROJECT_NAME} FILENAME "${DNAC}.dll" MAJOR_VERSION ${PROJECT_VERSION_MAJOR} MINOR_VERSION ${PROJECT_VERSION_MINOR} PATCH_VERSION ${PROJECT_VERSION_PATCH} COMPANY_NAME "Epic Games" COPYRIGHT "Copyright Epic Games, Inc. All Rights Reserved.") endif() ``` -------------------------------- ### Maya Path Configuration Note Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/README.md Important note for users running examples in Maya, emphasizing the need to set the ROOT_DIR variable to an absolute path, using forward slashes for compatibility with Maya's path handling. ```text If a user runs examples in Maya, the value for `ROOT_DIR` should be changed and absolute paths must be used, e.g. `c:/MetaHuman-DNA-Calibration` in Windows or `/home/user/MetaHuman-DNA-Calibration` in Linux. Important: Use `/` (forward slash), Maya uses forward slashes in path. ``` -------------------------------- ### Python 3 Integration and SWIG Setup Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNACalib/python3/CMakeLists.txt Configures CMake to find and use Python 3, sets up SWIG for generating Python bindings from an interface file (DNACalib.i), and defines build properties for the SWIG module. ```cmake set(PYTHON3_EXACT_VERSION "" CACHE STRING "Specify exact python3 version against which the extension should be built") if(PYTHON3_EXACT_VERSION) set(find_python3_extra_args ${PYTHON3_EXACT_VERSION} EXACT) endif() find_package(Python3 ${find_python3_extra_args} COMPONENTS Development Interpreter) set(py_version "py${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}") set(output_dir "${py_version}") set_property(SOURCE DNACalib.i PROPERTY CPLUSPLUS ON) set_property(SOURCE DNACalib.i PROPERTY SWIG_MODULE_NAME dnacalib) set_property(SOURCE DNACalib.i PROPERTY SWIG_FLAGS "-doxygen") option(TYPEMAP_DEBUG "Debug deducing of typemaps" OFF) if(TYPEMAP_DEBUG) set_property(SOURCE DNACalib.i PROPERTY SWIG_FLAGS "-debug-tmsearch") endif() swig_add_library(py3dnacalib TYPE SHARED LANGUAGE python OUTPUT_DIR ${CMAKE_BINARY_DIR}/${output_dir} OUTFILE_DIR ${CMAKE_BINARY_DIR}/python3 SOURCES DNACalib.i) add_library(PyDNA::py3dnacalib ALIAS py3dnacalib) set_target_properties(py3dnacalib PROPERTIES SWIG_USE_TARGET_INCLUDE_DIRECTORIES ON) target_link_libraries(py3dnacalib PUBLIC PyDNA::py3dna PRIVATE Spyus::spyus DNACalib::dnacalib Python3::Python) ``` -------------------------------- ### Linux Library Linking Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/repository_organization.md Provides shell commands to create symbolic links for essential .so files and Maya plugin (.mll) files in the /usr/lib directory on Linux systems. This is necessary for the dnacalib library and Maya plugin to be accessible system-wide. Ensure the paths are updated to your MetaHuman-DNA-Calibration installation directory. ```Shell sudo ln -s ~/MetaHuman-DNA-Calibration/lib/Maya2022/linux/_py3dna.so /usr/lib/_py3dna.so sudo ln -s ~/MetaHuman-DNA-Calibration/lib/Maya2022/linux/libdnacalib.so /usr/lib/libdnacalib.so sudo ln -s ~/MetaHuman-DNA-Calibration/lib/Maya2022/linux/libdnacalib.so.6 /usr/lib/libdnacalib.so.6 sudo ln -s ~/MetaHuman-DNA-Calibration/lib/Maya2022/linux/libembeddedRL4.so /usr/lib/embeddedRL4.mll sudo ln -s ~/MetaHuman-DNA-Calibration/lib/Maya2022/linux/MayaUERBFPlugin.mll /usr/lib/MayaUERBFPlugin.mll ``` -------------------------------- ### CPack Package Generation Configuration Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/CMakeLists.txt Sets up CPack for generating distributable packages. It specifies the generator type (ZIP), component installation behavior, and constructs a detailed package file name based on build variables. ```cmake set(CPACK_GENERATOR "ZIP") set(CPACK_ARCHIVE_COMPONENT_INSTALL ON) set(CPACK_COMPONENT_INCLUDE_TOPLEVEL_DIRECTORY OFF) set(CPACK_COMPONENTS_GROUPING ALL_COMPONENTS_IN_ONE) string(CONCAT CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}" "-${CMAKE_PROJECT_VERSION}" "-${CMAKE_SYSTEM_NAME}" "-${CMAKE_SYSTEM_PROCESSOR}" "-${CMAKE_CXX_COMPILER_ID}${CMAKE_CXX_COMPILER_VERSION}" "-${CMAKE_BUILD_TYPE}" "-${PYTHON3_EXACT_VERSION}" "-SHARED") include(CPack) ``` -------------------------------- ### DNAViewer API: build_rig Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer.md Provides the API for building rigs using the DNAViewer. This documentation details the methods, parameters, and return values for rig construction. ```APIDOC build_rig: Description: Builds a functional rig in Maya from the DNA file. Parameters: - dna_file (str): Path to the DNA file. - maya_scene_path (str): Path to the Maya scene file. - rig_type (str): Type of rig to build (e.g., 'standard', 'facial'). Returns: - bool: True if the rig was built successfully, False otherwise. ``` -------------------------------- ### CMake Build Configuration Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNACalib/CMakeLists.txt This snippet outlines the basic CMake configuration for the PyDNACalib project. It specifies the minimum required CMake version, project name, C++ standard, and SWIG integration. It also includes a subdirectory for Python 3 related build targets. ```cmake cmake_minimum_required(VERSION 3.14) project(PyDNACalib) set(CMAKE_CXX_STANDARD 11) find_package(SWIG 4.0.0) include(UseSWIG) add_subdirectory(python3) ``` -------------------------------- ### Read Neutral Vertex Positions Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna.md Example of reading neutral vertex positions (X, Y, Z coordinates) for a specified mesh from a loaded DNA object. It includes a check for the presence of meshes. ```python dna = load_dna(input_path) if dna.getMeshCount() == 0: print("No meshes found in DNA.") return mesh_index = 0 xs = dna.getVertexPositionXs(mesh_index) ys = dna.getVertexPositionYs(mesh_index) zs = dna.getVertexPositionZs(mesh_index) ``` -------------------------------- ### Position Independent Code (PIC) Requirement Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Explains the requirement for building the DNACalib library with the -fPIC flag when creating a shared object (.pyd, .so). This is a crucial step for dynamic library creation. ```cpp # Python wrapper builds a shared object (e.g. .pyd, .so), so DNACalib library has to be built with -fPIC flag. ``` -------------------------------- ### Create DNA from Scratch Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/README.md A Python script that illustrates the process of creating a new DNA file from basic components. This is helpful for understanding the DNA file structure and generation. ```python # examples/dna_demo.py ``` -------------------------------- ### Export Definitions Header Generation Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/CMakeLists.txt Generates a header file defining export attributes for symbols, crucial for shared library creation. This process is controlled by the `READ_ONLY_SOURCE_TREE` option and uses a `Symbols` module. ```cmake ################################################ # Generate export definitions header if (NOT READ_ONLY_SOURCE_TREE) include(Symbols) generate_export_definitions( OUTPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/include/dnacalib/Defs.h" EXPORT_ATTR_NAME DNACAPI BUILD_SHARED_NAME DNAC_BUILD_SHARED USE_SHARED_NAME DNAC_SHARED) endif() ``` -------------------------------- ### Build DNACalib with CMake Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/DNACalib/README.md Instructions for generating build scripts and building the DNACalib project using CMake. This involves creating a build directory, configuring with CMake, and then executing the build command. ```cmake mkdir build cd build cmake .. cmake --build . ``` -------------------------------- ### Set Neutral Joint Rotations (C++) Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dnacalib.md Example of reading a DNA file, modifying neutral joint rotations using SetNeutralJointRotationsCommand, and overwriting the file. Demonstrates the use of FileStream, BinaryStreamReader, DNACalibDNAReader, and BinaryStreamWriter. ```C++ // Create DNA reader auto inOutStream = dnac::makeScoped("example.dna", dnac::FileStream::AccessMode::ReadWrite, dnac::FileStream::OpenMode::Binary); auto reader = dnac::makeScoped(inOutStream.get()); reader->read(); // Check if an error occurred while reading DNA file if (!dnac::Status::isOk()) { // handle reader error } // Create DNACalib reader in order to edit DNA auto dnaReader = dnac::makeScoped(reader.get()); std::vector rotations{dnaReader->getJointCount(), {1.0f, 2.0f, 3.0f}}; // Create command instance dnac::SetNeutralJointRotationsCommand cmd{dnac::ConstArrayView{rotations}}; // Execute command cmd.run(dnaReader.get()); // Write DNA file auto writer = dnac::makeScoped(inOutStream.get()); writer->setFrom(dnaReader.get()); writer->write(); // Check if an error occurred while writing DNA file if (!dnac::Status::isOk()) { // handle writer error } ``` -------------------------------- ### Read Neutral Joint Coordinates and Orientations Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna.md Example of reading neutral joint translation (coordinates) and orientation values from a loaded DNA object. It retrieves X, Y, and Z components for both translations and rotations. ```python dna = load_dna(input_path) # Read joint coordinates neutral_joint_translation_xs = dna.getNeutralJointTranslationXs() neutral_joint_translation_ys = dna.getNeutralJointTranslationYs() neutral_joint_translation_zs = dna.getNeutralJointTranslationZs() # Read joint orientations neutral_joint_orient_xs = dna.getNeutralJointRotationXs() neutral_joint_orient_ys = dna.getNeutralJointRotationYs() neutral_joint_orient_zs = dna.getNeutralJointRotationZs() ``` -------------------------------- ### Load Specific Data Layer (Behavior) Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna.md An example of loading a DNA file with only the behavior layer, which also includes definition and descriptor data. This demonstrates selective data loading using DataLayer_Behavior. ```python stream = FileStream(path, FileStream.AccessMode_Read, FileStream.OpenMode_Binary) reader = BinaryStreamReader(stream, DataLayer_Behavior) reader.read() if not Status.isOk(): status = Status.get() raise RuntimeError(f"Error loading DNA: {status.message}") ``` -------------------------------- ### Distribute Maya Scene Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/faq.md Guidelines for distributing Maya scenes, including necessary files like the scene file (.mb), DNA (.dna), and workspace.mel. It also covers how to share generated files and open them correctly. ```markdown ## How do I distribute a Maya scene? Your scene should work out of the box if you include the following in the distribution: - Scene file (`.mb` file) - DNA (`.dna` file) - Workspace (`workspace.mel` file) All of these files need to be distributed together. If those files are not bundled and you experience some issues with you rig in Maya, try the following steps: ### How do I share the generated files? If you want to distribute a generated Maya scene to other users, you must distribute the `.dna` file and `workspace.mel` together with the scene. ### How do I open a generated scene? Before you load a generated scene, follow these steps: - From the main menu, go to File > Set Project. - Select `workspace.mel` - Set the containing folder (with generated maya scene, `.dna` file and `workspace.mel`). ``` -------------------------------- ### Test Execution Configuration Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/dnacalib/PyDNACalib/python3/CMakeLists.txt Configures CTest to run various Python example scripts as tests. It sets up environment variables for library paths and Python execution, and defines expected output patterns for test success. ```cmake if(WIN32) set(extra_env "PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") endif() set(DNACALIB_TEST_NAMES dnacalib_clear_blend_shapes dnacalib_demo dnacalib_lod_demo dnacalib_neutral_mesh_subtract dnacalib_remove_joint dnacalib_rename_joint_demo) foreach(test_name ${DNACALIB_TEST_NAMES}) add_test(NAME ${test_name} COMMAND ${CMAKE_COMMAND} -E env ${extra_env} LD_LIBRARY_PATH=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} PYTHONPATH=. ${Python3_EXECUTABLE} "${CMAKE_CURRENT_LIST_DIR}/../../../examples/${test_name}.py" WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${output_dir}) set_property(TEST ${test_name} PROPERTY PASS_REGULAR_EXPRESSION "Done\.") endforeach() ``` -------------------------------- ### DNAViewer API: build_meshes Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dna_viewer.md Provides the API for building meshes using the DNAViewer. This documentation outlines the methods, parameters, and return values for mesh generation. ```APIDOC build_meshes: Description: Builds meshes from the DNA file. Parameters: - dna_file (str): Path to the DNA file. - lod (int): Level of detail for the meshes. - output_path (str): Directory to save the generated meshes. Returns: - bool: True if meshes were built successfully, False otherwise. ``` -------------------------------- ### Fix DNA Signature Mismatch Error Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/faq.md This section explains how to resolve the 'RuntimeError: Error loading DNA: DNA signature mismatched, expected DNA, got ver?' error by installing git-lfs or manually downloading DNA files. ```markdown ## Fix "RuntimeError: Error loading DNA: DNA signature mismatched, expected DNA, got ver?" In order to fix this issue, you should install [git-lfs](https://git-lfs.github.com/), and clone the repository again. DNA files will be downloaded correctly then. If you cannot install git-lfs, you can download DNA files manually. ``` -------------------------------- ### Build DNACalib with CMake Source: https://github.com/epicgames/metahuman-dna-calibration/blob/main/docs/dnacalib.md Instructions for building the DNACalib library using CMake. This involves creating a build directory, configuring the build with CMake, and then executing the build process. ```Shell mkdir build cd build cmake .. cmake --build ```