### Minimal application example Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/LandingPage.md Complete main function examples for implicit and dynamic library loading. ```cpp #include #include "lib3mf_implicit.hpp" int main() { try { auto wrapper = Lib3MF::CWrapper::loadLibrary(); Lib3MF_uint32 nMajor, nMinor, nMicro; wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); std::cout << "Lib3MF.Version = " << nMajor << "." << nMinor << "." << nMicro; std::string sPreReleaseInfo; if (wrapper->GetPrereleaseInformation(sPreReleaseInfo)) { std::cout << "-" << sPreReleaseInfo; } std::string sBuildInfo; if (wrapper->GetBuildInformation(sBuildInfo)) { std::cout << "+" << sBuildInfo; } std::cout << std::endl; } catch (std::exception &e) { std::cout << e.what() << std::endl; return 1; } return 0; } ``` ```cpp #include #include "lib3mf_dynamic.hpp" int main() { try { std::string libpath = (""); // TODO: put the location of the Lib3MF-library file here. auto wrapper = Lib3MF::CWrapper::loadLibrary(libpath + "/lib3mf."); // TODO: add correct suffix of the library Lib3MF_uint32 nMajor, nMinor, nMicro; wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); std::cout << "Lib3MF.Version = " << nMajor << "." << nMinor << "." << nMicro; std::string sPreReleaseInfo; if (wrapper->GetPrereleaseInformation(sPreReleaseInfo)) { std::cout << "-" << sPreReleaseInfo; } std::string sBuildInfo; if (wrapper->GetBuildInformation(sBuildInfo)) { std::cout << "+" << sBuildInfo; } std::cout << std::endl; } catch (std::exception &e) { std::cout << e.what() << std::endl; return 1; } return 0; } ``` -------------------------------- ### Install Sphinx Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/README.md Install the Sphinx documentation generator using pip. ```shell pip install sphinx ``` -------------------------------- ### Install Directory Variables Source: https://github.com/3mfconsortium/lib3mf/blob/master/CMakeLists.txt Sets the default installation directories for binary, library, and header files. These can be overridden by users. ```cmake set(CMAKE_INSTALL_BINDIR bin CACHE PATH "directory for installing binary files") set(CMAKE_INSTALL_LIBDIR lib CACHE PATH "directory for installing library files") set(CMAKE_INSTALL_INCLUDEDIR include CACHE PATH "directory for installing header files") ``` -------------------------------- ### Configure C++ Example Build with Lib3MF Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/CMakeLists_implicit.txt This CMake script configures the build for a C++ example. It sets the C++ standard to C++11, defines the executable, locates the Lib3MF library, and links it to the executable. Ensure Lib3MF is installed or its path is correctly specified. ```cmake cmake_minimum_required(VERSION 3.5) set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.) project(Lib3MFExample_CPPImplicit) set(CMAKE_CXX_STANDARD 11) add_executable(Lib3MFExample_CPPImplicit "${CMAKE_CURRENT_SOURCE_DIR}/Lib3MF_example.cpp") find_library(LIB3MFLOCATION lib3mf "${CMAKE_CURRENT_SOURCE_DIR}/../../Implementations/*/*/*") target_link_libraries(Lib3MFExample_CPPImplicit ${LIB3MFLOCATION}) target_include_directories(Lib3MFExample_CPPImplicit PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/3mfconsortium/lib3mf/blob/master/CMakeLists.txt Configures and installs package files for CMake integration. ```cmake configure_file(lib3mf.pc.in lib3mf.pc @ONLY) set(LIB3MF_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/lib3mf") configure_package_config_file( cmake/lib3mfConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/lib3mfConfig.cmake" INSTALL_DESTINATION "${LIB3MF_CONFIG_INSTALL_DIR}" ) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/lib3mfConfigVersion.cmake" VERSION "${PROJECT_VERSION}" COMPATIBILITY SameMajorVersion ) install(FILES ${CMAKE_BINARY_DIR}/lib3mf.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/lib3mfConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/lib3mfConfigVersion.cmake" DESTINATION "${LIB3MF_CONFIG_INSTALL_DIR}" ) install(TARGETS ${PROJECT_NAME} EXPORT lib3mfTargets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") install(EXPORT lib3mfTargets FILE lib3mfTargets.cmake NAMESPACE lib3mf:: DESTINATION "${LIB3MF_CONFIG_INSTALL_DIR}" ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR_AUTOGENERATED}/Bindings DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}") ``` -------------------------------- ### Install node-gyp globally Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/Examples/NodeJS/Readme.md Install the node-gyp build tool globally to manage native addon compilation. ```bash npm install -g node-gyp ``` -------------------------------- ### Install LibreSSL Headers Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/include/CMakeLists.txt Installs LibreSSL header files to the installation directory while excluding unnecessary build files. ```cmake if(ENABLE_LIBRESSL_INSTALL) install(DIRECTORY . DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} PATTERN "CMakeLists.txt" EXCLUDE PATTERN "compat" EXCLUDE PATTERN "pqueue.h" EXCLUDE PATTERN "Makefile*" EXCLUDE PATTERN "arch" EXCLUDE) install(FILES ${CMAKE_BINARY_DIR}/include/openssl/opensslconf.h DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/openssl") endif(ENABLE_LIBRESSL_INSTALL) ``` -------------------------------- ### CMakeLists.txt for Lib3MF C Dynamic Example Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/Examples/CDynamic/CMakeLists.txt This CMake script sets up the build environment for a C dynamic example of the 3MF library. It configures platform-specific library suffixes and output names, adds source files, and sets up post-build commands for copying the library. ```cmake cmake_minimum_required(VERSION 3.5) project(Lib3MFExample_CDynamic C) if (WIN32) set(LSUFFIX "dll") set(LSUFFIXOUT ".dll") elseif(UNIX AND NOT APPLE) set(LSUFFIX "so") set(LSUFFIXOUT ".so.2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2") else() set(LSUFFIX "dylib") set(LSUFFIXOUT ".2.dylib") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2") endif() set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/CDynamic) SET_SOURCE_FILES_PROPERTIES("${CMAKE_CURRENT_BINDING_DIR}/lib3mf_dynamic.cc" PROPERTIES LANGUAGE C) add_executable(Lib3MFExample_CDynamic "${CMAKE_CURRENT_SOURCE_DIR}/Source/Lib3MF_example.c" "${CMAKE_CURRENT_BINDING_DIR}/lib3mf_dynamic.cc" ) set_property(TARGET Lib3MFExample_CDynamic PROPERTY C_STANDARD 99) if (UNIX) target_link_libraries(Lib3MFExample_CDynamic ${CMAKE_DL_LIBS}) endif (UNIX) target_include_directories(Lib3MFExample_CDynamic PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") function(PrepareExample MyTarget) add_custom_command(TARGET ${MyTarget} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../../Bin/lib3mf.${LSUFFIX}" $/lib3mf${LSUFFIXOUT}) if (UNIX) target_link_libraries(${MyTarget} ${CMAKE_DL_LIBS}) endif (UNIX) target_compile_options(${MyTarget} PRIVATE "-DLSUFFIXOUT=\"${LSUFFIXOUT}\" ") endfunction(PrepareExample) PrepareExample(Lib3MFExample_CDynamic) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") ELSE() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Lib3MFExample_CDynamic) ENDIF() endif() ``` -------------------------------- ### Execute the readwrite example Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/Examples/NodeJS/Readme.md Run the readwrite.js script after configuring the paths to the addon and binary. ```bash node readwrite.js ``` -------------------------------- ### Build LibreSSL with Autotools Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/README.md Standard commands to configure, test, and install the package on most systems. ```sh ./configure # see ./configure --help for configuration options make check # runs builtin unit tests make install # set DESTDIR= to install to an alternate location ``` -------------------------------- ### Install ocspcheck Executable and Man Page Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/apps/ocspcheck/CMakeLists.txt Installs the ocspcheck executable and its man page if ENABLE_LIBRESSL_INSTALL is enabled. Specifies installation destinations. ```cmake if(ENABLE_LIBRESSL_INSTALL) install(TARGETS ocspcheck DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES ocspcheck.8 DESTINATION ${CMAKE_INSTALL_MANDIR}/man8) endif(ENABLE_LIBRESSL_INSTALL) ``` -------------------------------- ### Install Sphinx Tabs Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/README.md Install the sphinx-tabs extension for creating tabbed content in Sphinx documentation. ```shell pip install sphinx-tabs ``` -------------------------------- ### Configure lib3mf Dynamic Example Build Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/CPackExamples/CDynamic/CMakeLists.txt This CMake script configures the build for a lib3mf dynamic example. It determines the platform, sets the lib3mf_DIR, and finds the lib3mf components. It also sets the C++ standard, defines the executable, and links the necessary libraries. ```cmake cmake_minimum_required(VERSION 3.5) project(Example_CDynamic CXX) # Determine the platform and set lib3mf_DIR accordingly if(WIN32) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Windows/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS CDynamic) elseif(APPLE) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Darwin/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS CDynamic) else() find_package(lib3mf QUIET COMPONENTS CDynamic) if(NOT lib3mf_FOUND) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Linux/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS CDynamic) endif() endif() set(CMAKE_CXX_STANDARD 11) add_executable(Example_CDynamic "${CMAKE_CURRENT_SOURCE_DIR}/Source/Version.cpp") target_link_libraries(Example_CDynamic lib3mf::lib3mf ${CMAKE_DL_LIBS}) # lib3mf_dynamic.cc provides the C dynamic loader symbols required by this example. if(DEFINED LIB3MF_CDYNAMIC_ADDITIONAL_SOURCE) target_sources(Example_CDynamic PRIVATE "${LIB3MF_CDYNAMIC_ADDITIONAL_SOURCE}") elseif(DEFINED lib3mf_INCLUDE_DIRS) target_sources(Example_CDynamic PRIVATE "${lib3mf_INCLUDE_DIRS}/lib3mf_dynamic.cc") endif() if(${MSVC}) if(${CMAKE_VERSION} VERSION_LESS 3.6.3) message("Note: You need to manually select a StartUp-project in Visual Studio.") else() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example_CDynamic) endif() endif() ``` -------------------------------- ### Configure C++ Dynamic Example Build Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/CMakeLists_dynamic.txt This CMake script configures the build for a C++ dynamic example executable. It sets the C++ standard to 11, defines the executable, and links the dynamic library loader on UNIX systems. Ensure the include directory is correctly set for the project. ```cmake cmake_minimum_required(VERSION 3.5) set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.) project(Lib3MFExample_CPPDynamic) set(CMAKE_CXX_STANDARD 11) add_executable(Lib3MFExample_CPPDynamic "${CMAKE_CURRENT_SOURCE_DIR}/Lib3MF_example.cpp") if (UNIX) target_link_libraries(Lib3MFExample_CPPDynamic ${CMAKE_DL_LIBS}) endif (UNIX) target_include_directories(Lib3MFExample_CPPDynamic PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") ``` -------------------------------- ### Install Man Pages Conditionally Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/man/CMakeLists.txt Installs man pages for version 3 and version 5 man page formats. This is conditional on ENABLE_LIBRESSL_INSTALL being true. ```cmake if(ENABLE_LIBRESSL_INSTALL) install( DIRECTORY . DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 FILES_MATCHING PATTERN "*.3" ) install( DIRECTORY . DESTINATION ${CMAKE_INSTALL_MANDIR}/man5 FILES_MATCHING PATTERN "*.5" ) endif(ENABLE_LIBRESSL_INSTALL) ``` -------------------------------- ### Configure Lib3MF CMake Project Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/CPackExamples/Cpp/CMakeLists.txt Sets up the build environment, locates the Lib3MF library based on the host platform, and defines executable targets for examples. ```cmake cmake_minimum_required (VERSION 3.5) project(Examples) set(CMAKE_CXX_STANDARD 11) # Determine the platform and set lib3mf_DIR accordingly if(WIN32) # Path for Windows set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Windows/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS Cpp) elseif(APPLE) # Path for macOS (Darwin) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Darwin/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS Cpp) else() # Path for Linux (Here we check twice to test for Debian / RPM packages properly) find_package(lib3mf QUIET COMPONENTS Cpp) # Check if the package was not found if(NOT lib3mf_FOUND) # lib3mf not found, so set lib3mf_DIR to the fallback directory set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Linux/lib/cmake/lib3mf") # Find package (lib3mf) find_package(lib3mf REQUIRED COMPONENTS Cpp) endif() endif() add_definitions(-DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/") add_executable(Example_ColorCube Source/ColorCube.cpp) target_link_libraries(Example_ColorCube lib3mf::lib3mf) copy_lib3mf_libraries(Example_ColorCube) add_executable(Example_Components Source/Components.cpp) target_link_libraries(Example_Components lib3mf::lib3mf) copy_lib3mf_libraries(Example_Components) add_executable(Example_Converter Source/Converter.cpp) target_link_libraries(Example_Converter lib3mf::lib3mf) copy_lib3mf_libraries(Example_Converter) add_executable(Example_Cube Source/Cube.cpp) target_link_libraries(Example_Cube lib3mf::lib3mf) copy_lib3mf_libraries(Example_Cube) add_executable(Example_SecureCube Source/SecureCube.cpp) target_link_libraries(Example_SecureCube lib3mf::lib3mf) copy_lib3mf_libraries(Example_SecureCube) add_executable(Example_ExtractInfo Source/ExtractInfo.cpp) target_link_libraries(Example_ExtractInfo lib3mf::lib3mf) copy_lib3mf_libraries(Example_ExtractInfo) add_executable(Example_TextureCube Source/TextureCube.cpp) target_link_libraries(Example_TextureCube lib3mf::lib3mf) copy_lib3mf_libraries(Example_TextureCube) add_executable(Example_Slice Source/Slice.cpp) target_link_libraries(Example_Slice lib3mf::lib3mf) copy_lib3mf_libraries(Example_Slice) add_executable(Example_BeamLattice Source/BeamLattice.cpp) target_link_libraries(Example_BeamLattice lib3mf::lib3mf) copy_lib3mf_libraries(Example_BeamLattice) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") ELSE() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example_Cube) ENDIF() endif() ``` -------------------------------- ### Lib3MF CMake Build Configuration Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/Examples/Cpp/CMakeLists.txt Configures the build environment for Lib3MF C++ examples, handling platform-specific library paths and executable creation. ```cmake cmake_minimum_required (VERSION 3.5) set(CMAKE_CXX_STANDARD 17) if (WIN32) set(LSUFFIX "dll") set(LSUFFIXOUT ".dll") elseif(UNIX AND NOT APPLE) set(LSUFFIX "so") set(LSUFFIXOUT ".so.2") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2") else() set(LSUFFIX "dylib") set(LSUFFIXOUT ".2.dylib") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O2") endif() add_definitions( -DTEXTURESPATH="${CMAKE_CURRENT_SOURCE_DIR}/../Files/Textures/" ) project(Examples) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../Bindings/Cpp) if (WIN32) link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../Lib) link_libraries(lib3mf) else() # Unix prefixes the name of the library with "lib" anyway link_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../Bin) link_libraries(3mf) link_directories(${CMAKE_CURRENT_BINARY_DIR}) endif() function(CopySharedLibrary MyTarget) add_custom_command(TARGET ${MyTarget} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/../../Bin/lib3mf.${LSUFFIX}" $/lib3mf${LSUFFIXOUT}) endfunction(CopySharedLibrary) add_executable(Example_ColorCube Source/ColorCube.cpp) CopySharedLibrary(Example_ColorCube) add_executable(Example_Components Source/Components.cpp) CopySharedLibrary(Example_Components) add_executable(Example_Converter Source/Converter.cpp) CopySharedLibrary(Example_Converter) add_executable(Example_Cube Source/Cube.cpp) CopySharedLibrary(Example_Cube) add_executable(Example_SecureCube Source/SecureCube.cpp) CopySharedLibrary(Example_SecureCube) add_executable(Example_ExtractInfo Source/ExtractInfo.cpp) CopySharedLibrary(Example_ExtractInfo) add_executable(Example_TextureCube Source/TextureCube.cpp) CopySharedLibrary(Example_TextureCube) add_executable(Example_Slice Source/Slice.cpp) CopySharedLibrary(Example_Slice) add_executable(Example_BeamLattice Source/BeamLattice.cpp) CopySharedLibrary(Example_BeamLattice) add_executable(Example_FillMeshWithGyroid Source/FillMeshWithGyroid.cpp) CopySharedLibrary(Example_FillMeshWithGyroid) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") ELSE() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example_Cube) ENDIF() endif() ``` -------------------------------- ### CConstVecNode Class Methods Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/lib3mf_ConstVecNode.md This section covers the methods available for the CConstVecNode class, including setting and getting vector values and retrieving output ports. ```APIDOC ## CConstVecNode Class ### Description Represents a constant vector node in the lib3mf library. ### Methods #### SetVector ##### Description Sets the vector value of the node. ##### Parameters - **Value** (sVector) - Required - The vector value to set. #### GetVector ##### Description Retrieves the vector value of the node. ##### Returns - **sVector** - The current vector value. #### GetOutputVector ##### Description Retrieves the output port associated with the vector. ##### Returns - **PImplicitPort** - The output port. ``` -------------------------------- ### Build Documentation Locally Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/README.md Build the HTML documentation locally using the make.bat script. Use an analogous command for Unix-based systems. ```shell make.bat html ``` -------------------------------- ### Build LibreSSL with Ninja Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/README.md Faster build workflow using the Ninja generator. ```sh mkdir build-ninja cd build-ninja cmake -G"Ninja" .. ninja ninja test ``` -------------------------------- ### Set Visual Studio Startup Project Source: https://github.com/3mfconsortium/lib3mf/blob/master/CMakeLists.txt Configures the startup project for MSVC builds. ```cmake if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") ELSE() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${STARTUPPROJECT}) ENDIF() endif() ``` -------------------------------- ### Get Stream Size Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/lib3mf_Writer.md Retrieves the total size of the 3MF file stream before writing. ```APIDOC ## Lib3MF_uint64 GetStreamSize() ### Description Retrieves the size of the full 3MF file stream. ### Method Lib3MF_uint64 ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp Lib3MF_uint64 streamSize = writer.GetStreamSize(); ``` ### Response #### Success Response (200) - **Return Value** (Lib3MF_uint64) - The stream size in bytes. #### Response Example ```json 10240 ``` ``` -------------------------------- ### CTriangleSet - Triangle List Management Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/lib3mf_TriangleSet.md Methods for setting, getting, and adding multiple triangles to the set. ```APIDOC ## CTriangleSet::SetTriangleList ### Description Sets all triangles in the list, clearing old values. Duplicates will be merged. ### Method void ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **TriangleIndicesBuffer** (CInputVector) - Required - A buffer containing the indices of triangles to add. Each element must be between 0 and TriangleCount - 1. ### Request Example ```json { "TriangleIndicesBuffer": [1, 2, 3, 5] } ``` ### Response #### Success Response (200) None (void method) #### Response Example None ``` ```APIDOC ## CTriangleSet::GetTriangleList ### Description Retrieves all the triangles in the TriangleSet. ### Method void ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **TriangleIndicesBuffer** (std::vector&) - Output - A vector to retrieve the indices of the triangles in this TriangleSet. ### Request Example None ### Response #### Success Response (200) * **TriangleIndicesBuffer** (std::vector) - The retrieved indices of the triangles in the set. #### Response Example ```json { "TriangleIndicesBuffer": [1, 2, 3, 5] } ``` ``` ```APIDOC ## CTriangleSet::AddTriangleList ### Description Adds multiple triangles to the list. Duplicates will be merged. ### Method void ### Endpoint N/A (Class Method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **TriangleIndicesBuffer** (CInputVector) - Required - A buffer containing the indices of triangles to add. Each element must be between 0 and TriangleCount - 1. ### Request Example ```json { "TriangleIndicesBuffer": [6, 7, 8] } ``` ### Response #### Success Response (200) None (void method) #### Response Example None ``` -------------------------------- ### CFunction Display Name Management Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/lib3mf_Function.md Methods to get and set the display name of a CFunction object. ```APIDOC ## GetDisplayName ### Description Retrieves the display name of the function. ### Returns - **string** - The display name ## SetDisplayName ### Description Sets the display name of the function. ### Parameters #### Request Body - **sDisplayName** (string) - Required - The display name ``` -------------------------------- ### Initialize Material Group Source: https://context7.com/3mfconsortium/lib3mf/llms.txt Sets up a basic mesh object for material assignment. ```python import lib3mf from lib3mf import get_wrapper wrapper = get_wrapper() model = wrapper.CreateModel() # Create a mesh object mesh_object = model.AddMeshObject() mesh_object.SetName("MaterialBox") ``` -------------------------------- ### Configure Build Environment and Include Directories Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/tests/CMakeLists.txt Sets global definitions and include paths required for compiling the project components. ```cmake add_definitions(-DLIBRESSL_CRYPTO_INTERNAL) include_directories( . ../crypto/asn1 ../crypto/bio ../crypto/bn ../crypto/curve25519 ../crypto/evp ../crypto/modes ../crypto/x509 ../ssl ../apps/openssl ../apps/openssl/compat ../include ${CMAKE_BINARY_DIR}/include ../include/compat ) add_definitions(-D_PATH_SSL_CA_FILE=\"${CMAKE_CURRENT_SOURCE_DIR}/../cert.pem\") file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR} TEST_SOURCE_DIR) ``` -------------------------------- ### CMake configuration for minimal project Source: https://github.com/3mfconsortium/lib3mf/blob/master/Documentation/source/Cpp/LandingPage.md CMake build configuration for implicit and dynamic library integration. ```cmake cmake_minimum_required(VERSION 3.5) set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.) project(Lib3MFExample_CPPImplicit) set(CMAKE_CXX_STANDARD 11) add_executable(Lib3MFExample_CPPImplicit "${CMAKE_CURRENT_SOURCE_DIR}/Lib3MF_example.cpp") find_library(LIB3MFLOCATION lib3mf "${CMAKE_CURRENT_SOURCE_DIR}/../../Implementations/*/*/*") target_link_libraries(Lib3MFExample_CPPImplicit ${LIB3MFLOCATION}) target_include_directories(Lib3MFExample_CPPImplicit PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") ``` ```cmake cmake_minimum_required(VERSION 3.5) set(CMAKE_CURRENT_BINDING_DIR ${CMAKE_CURRENT_SOURCE_DIR}/.) project(Lib3MFExample_CPPDynamic) set(CMAKE_CXX_STANDARD 11) add_executable(Lib3MFExample_CPPDynamic "${CMAKE_CURRENT_SOURCE_DIR}/Lib3MF_example.cpp") if (UNIX) target_link_libraries(Lib3MFExample_CPPDynamic ${CMAKE_DL_LIBS}) endif (UNIX) target_include_directories(Lib3MFExample_CPPDynamic PRIVATE "${CMAKE_CURRENT_BINDING_DIR}") ``` -------------------------------- ### Load and Manipulate 3MF Models in C++ Source: https://context7.com/3mfconsortium/lib3mf/llms.txt Demonstrates dynamic library loading, reading 3MF files, iterating through mesh objects, and creating new geometry with build items. ```cpp #include #include "lib3mf_dynamic.hpp" using namespace Lib3MF; int main(int argc, char** argv) { try { // Load the library dynamically std::string libpath = "."; auto wrapper = CWrapper::loadLibrary(libpath + "/lib3mf.so"); // Print version Lib3MF_uint32 nMajor, nMinor, nMicro; wrapper->GetLibraryVersion(nMajor, nMinor, nMicro); std::cout << "lib3mf version: " << nMajor << "." << nMinor << "." << nMicro << std::endl; // Create a model PModel model = wrapper->CreateModel(); // Read an existing 3MF file PReader reader = model->QueryReader("3mf"); reader->SetStrictModeActive(false); reader->ReadFromFile("input.3mf"); // Check for warnings for (Lib3MF_uint32 i = 0; i < reader->GetWarningCount(); i++) { Lib3MF_uint32 errorCode; std::string warning = reader->GetWarning(i, errorCode); std::cout << "Warning " << errorCode << ": " << warning << std::endl; } // Iterate through mesh objects PMeshObjectIterator meshIterator = model->GetMeshObjects(); while (meshIterator->MoveNext()) { PMeshObject mesh = meshIterator->GetCurrentMeshObject(); std::cout << "Mesh: " << mesh->GetName() << std::endl; std::cout << " Vertices: " << mesh->GetVertexCount() << std::endl; std::cout << " Triangles: " << mesh->GetTriangleCount() << std::endl; // Check for beam lattice PBeamLattice beamLattice = mesh->BeamLattice(); if (beamLattice->GetBeamCount() > 0) { std::cout << " Beams: " << beamLattice->GetBeamCount() << std::endl; } } // Create a new mesh object PMeshObject newMesh = model->AddMeshObject(); newMesh->SetName("NewBox"); // Add vertices sPosition vertices[8]; float size = 50.0f; int idx = 0; for (float z : {0.0f, size}) { for (float y : {0.0f, size}) { for (float x : {0.0f, size}) { vertices[idx].m_Coordinates[0] = x; vertices[idx].m_Coordinates[1] = y; vertices[idx].m_Coordinates[2] = z; newMesh->AddVertex(vertices[idx]); idx++; } } } // Add triangles for cube faces sTriangle triangles[12] = { {{0, 2, 1}}, {{1, 2, 3}}, {{4, 5, 6}}, {{5, 7, 6}}, {{0, 1, 4}}, {{1, 5, 4}}, {{2, 6, 3}}, {{3, 6, 7}}, {{0, 4, 2}}, {{2, 4, 6}}, {{1, 3, 5}}, {{3, 7, 5}} }; for (const auto& tri : triangles) { newMesh->AddTriangle(tri); } // Add build item with identity transform sTransform transform = wrapper->GetIdentityTransform(); model->AddBuildItem(newMesh.get(), transform); // Write to file PWriter writer = model->QueryWriter("3mf"); writer->WriteToFile("output.3mf"); std::cout << "Successfully wrote output.3mf" << std::endl; } catch (ELib3MFException& e) { std::cerr << "lib3mf error: " << e.what() << std::endl; return e.getErrorCode(); } return 0; } ``` -------------------------------- ### Configure Lib3MF CMake Project Source: https://github.com/3mfconsortium/lib3mf/blob/master/SDK/CPackExamples/CppDynamic/CMakeLists.txt Sets up the project, locates the Lib3MF package based on the operating system, and links the executable. ```cmake cmake_minimum_required(VERSION 3.5) project(Example_ExtractInfo) set(CMAKE_CXX_STANDARD 11) # Determine the platform and set lib3mf_DIR accordingly if(WIN32) # Path for Windows set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Windows/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS CppDynamic) elseif(APPLE) # Path for macOS (Darwin) set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Darwin/lib/cmake/lib3mf") find_package(lib3mf REQUIRED COMPONENTS CppDynamic) else() # Path for Linux (Here we check twice to test for Debian / RPM packages properly) find_package(lib3mf QUIET COMPONENTS CppDynamic) # Check if the package was not found if(NOT lib3mf_FOUND) # lib3mf not found, so set lib3mf_DIR to the fallback directory set(lib3mf_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../lib3mf-$ENV{LIB3MF_VERSION}-Linux/lib/cmake/lib3mf") # Find package (lib3mf) find_package(lib3mf REQUIRED COMPONENTS CppDynamic) endif() endif() add_executable(Example_ExtractInfo "${CMAKE_CURRENT_SOURCE_DIR}/Source/ExtractInfo.cpp") # In case of CDynamic and CppDynamic, the lib3mf::lib3mf is simply an alias to an interface target_link_libraries(Example_ExtractInfo lib3mf::lib3mf ${CMAKE_DL_LIBS}) if (${MSVC}) IF(${CMAKE_VERSION} VERSION_LESS 3.6.3) MESSAGE ("Note: You need to manually select a StartUp-project in Visual Studio.") ELSE() set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Example_ExtractInfo) ENDIF() endif() ``` -------------------------------- ### Example 8: Cryptographic Data Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/tests/aes_128_gcm_tests.txt This snippet shows a set of cryptographic parameters, including TAG, KEY, NONCE, IN, AD, and CT. These are fundamental for secure data operations. ```plaintext KEY: 021add6030bd9f3fed8b0d1f16f83783 NONCE: 4e460f51fe6b5eb9558c4571 IN: d9aa1d0db5de536cfbacb59bb75c592ae3f34a5f9c5ff4f22d14e8e4bd0754af19570221893797f60c89a251cd6a19c2953662dca51264afc21099ed5c80077b0e10a5295b3c4c6fe47d3c1c84fee69ebf7d8a7d9b1b338dae162e657e6cf5277ca70d47b9290aa7efe67b0ce574 ``` -------------------------------- ### Example 7: Cryptographic Data Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/tests/aes_128_gcm_tests.txt This snippet shows a set of cryptographic parameters, including TAG, KEY, NONCE, IN, AD, and CT. These are essential for secure data handling and processing. ```plaintext KEY: dec1b34b7b81fb19586c6ec948ecf462 NONCE: d9faf07e72e3c39a0165fecd IN: f7b0bbe9f0ff4dcf162792e9ee14d1ed286114f411c834ad06b143cadbbe10a6fbc86f6664e0e07ff7c6876d4543e5b01ff5ddb629f896c30c8cefd56c15d9f24dfd2ed590304a6aae24caac5870ddafc0e672ac3aacae1867891942998c712d45efbfa4d99a8a6f03 AD: d3c4fc4838cb3cda3937455229ddaf1cb9102e815cb9f519a5434677c68b11a0bae1280faee82f1a5bee593e669e6f81d5ece3675b8af63f1491bb298531aacc940f53678ba56ae96fc66be92b904bc35f2d5b68b3ed98569a4d04e8f8a9689ad9fa4b51db0938a9f3 CT: 2f44ecf549077b98ba551819538097bb80304a55c48ef853e20ed8c3f808dc8cb5eb41c2463d19fed2606b59cee4b458958ea75715f7654146df4519dc63524a0569a00d7bbc4b32a372f82d955be5f190d09d35c267da1017e8b16096ae84f8a671b45aaf0d1ca59c TAG: bc3af80cf9388d35deadecff5455d515 ``` -------------------------------- ### Build LibreSSL with CMake Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/README.md Standard CMake build workflow. ```sh mkdir build cd build cmake .. make make test ``` -------------------------------- ### Example 6: Cryptographic Data Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/tests/aes_128_gcm_tests.txt This snippet displays a set of cryptographic parameters, including TAG, KEY, NONCE, IN, AD, and CT. These are vital for ensuring the security and integrity of data. ```plaintext KEY: fe33f47136506e5cc14114eb62d26d64 NONCE: 9534a10af0c96d8981eaf6b3 IN: 3ca38385513eaf1fcd03ac837e4db95c0ed1a2528b7ab3ac8e09ecc95698d52b7d90bf974bf96d8f791aa595965e2527aa466fb76da53b5743eda30bb3ebd9f6a8a7721fbfe71fe637d99a7b4b622e6da89e0824ac8aea299ea15e43250d2eccb0d4d553 AD: 50b7bd342df76bea99b2e9118a525c0f7041c7acdf4a3b17912b5cbb9650900246ed945cfc7db2b34a988af822c763451ac2e769ec67361eded9bcab37ac41f04cdb1d2471c9520a02db9673daaf07001570f9d9f4ac38f09da03ff1c56fdefe16a855ac CT: 927fe3c924d914a7aae6695ddad54961142b7dd5ff4c0ba5ca3e0cf3d73bdb576afd59bd2b54d820d2a5da03286c124507a48008c571c28a0ce76f0ed68dbac3a61848e7e2162be8e0bee8147b9bf60da625cdab8601bfb37dfcd165f533e94a32c26952 TAG: 9bd47a4a2acaf865a8a260179aabf8ad ``` -------------------------------- ### Configure Version Information Source: https://github.com/3mfconsortium/lib3mf/blob/master/CMakeLists.txt Sets the build number from environment variables and generates product version files for Windows builds. ```cmake if(DEFINED ENV{BUILD_NUMBER}) set(BUILD_NUMBER $ENV{BUILD_NUMBER}) else() set(BUILD_NUMBER 0) endif() if (WIN32) message("BUILD_NUMBER ... " ${BUILD_NUMBER}) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/Include/VersionInfo) include(generate_product_version) generate_product_version( VERSION_FILES_OUTPUTLOCATION NAME "lib3mf" FILE_DESCRIPTION "lib3mf is an implementation of the 3D Manufacturing Format file standard" BUNDLE "3MF Consortium" VERSION_MAJOR ${LIB3MF_VERSION_MAJOR} VERSION_MINOR ${LIB3MF_VERSION_MINOR} VERSION_PATCH ${LIB3MF_VERSION_MICRO} VERSION_REVISION ${BUILD_NUMBER} PRODUCT_VERSION_MAJOR ${LIB3MF_VERSION_MAJOR} PRODUCT_VERSION_MINOR ${LIB3MF_VERSION_MINOR} PRODUCT_VERSION_PATCH ${LIB3MF_VERSION_MICRO} PRODUCT_VERSION_REVISION ${LIB3MF_VERSION_PRERELEASE} COMPANY_NAME "3MF Consortium" ) message("VERSION_FILES_OUTPUTLOCATION ... " ${VERSION_FILES_OUTPUTLOCATION}) else() set(VERSION_FILES_OUTPUTLOCATION "") endif() ``` -------------------------------- ### Example 1: Cryptographic Data Source: https://github.com/3mfconsortium/lib3mf/blob/master/Libraries/libressl/tests/aes_128_gcm_tests.txt This snippet shows a set of cryptographic parameters including TAG, KEY, NONCE, IN, AD, and CT. These are typically used in encryption and authentication processes. ```plaintext TAG: dce7198728bfc1b5f949b9b5374199c6 KEY: fd1dd6a237a12d7f64f68eb96890c872 NONCE: 459ced97ebc385ab3a8da8d5 IN: 04a9709fdc0a4edb423fe8cf61c33a40043f1a585d5458c7512ec8e4e066a0f95e2e6609abf3c95a5d3ae2c738269533855daedd92eca20bdedbbd5677cd4eee84b7a1efae0904364f1e54 AD: d253b829a2fbc5877b0fbe92e7b79f38886a49ca889ae72b91f2c3aebe257a3ffe0d390b5d320bea22d6a5536cd9213612f5ed6e3b0ea33ac91cfee284cb25eaaf6b85b15f7ca894317182 CT: 4a565d3ba4f2ec461c9bd8dd0f96bc00d2a561bfb56443c8cf47681bdf1c61f55854bea060c4219696cac79c09aa9400a7e5c59c6b6ca556f38c619a662905fc5f0e8437b906af6138e3fb TAG: be5f93201d7980af4c5bceb24ac1d238 ``` -------------------------------- ### Create and Write 3MF Files Source: https://context7.com/3mfconsortium/lib3mf/llms.txt Initializes a model, defines mesh geometry using vertices and triangles, and exports the result to a 3MF file. ```python import lib3mf from lib3mf import get_wrapper # Initialize the library wrapper wrapper = get_wrapper() # Get library version major, minor, micro = wrapper.GetLibraryVersion() print(f"lib3mf version: {major}.{minor}.{micro}") # Create a new model model = wrapper.CreateModel() # Add an empty mesh object mesh_object = model.AddMeshObject() mesh_object.SetName("Box") # Define cube dimensions fSizeX, fSizeY, fSizeZ = 100.0, 200.0, 300.0 # Create vertex positions position = lib3mf.Position() vertices = [] for coords in [(0,0,0), (fSizeX,0,0), (fSizeX,fSizeY,0), (0,fSizeY,0), (0,0,fSizeZ), (fSizeX,0,fSizeZ), (fSizeX,fSizeY,fSizeZ), (0,fSizeY,fSizeZ)]: pos = lib3mf.Position() pos.Coordinates[0], pos.Coordinates[1], pos.Coordinates[2] = coords mesh_object.AddVertex(pos) vertices.append(pos) # Create triangles (12 triangles for a cube, 2 per face) triangle_indices = [ (2, 1, 0), (0, 3, 2), (4, 5, 6), (6, 7, 4), (0, 1, 5), (5, 4, 0), (2, 3, 7), (7, 6, 2), (1, 2, 6), (6, 5, 1), (3, 0, 4), (4, 7, 3) ] triangles = [] for v0, v1, v2 in triangle_indices: tri = lib3mf.Triangle() tri.Indices[0], tri.Indices[1], tri.Indices[2] = v0, v1, v2 mesh_object.AddTriangle(tri) triangles.append(tri) # Set geometry in bulk (alternative to adding one by one) mesh_object.SetGeometry(vertices, triangles) # Add to build with identity transform model.AddBuildItem(mesh_object, wrapper.GetIdentityTransform()) # Write to 3MF file writer = model.QueryWriter("3mf") writer.WriteToFile("cube.3mf") # Output: Creates cube.3mf file containing a 100x200x300mm box ```