Skip to content

Commit

Permalink
Merge pull request #1521 from lvk88/meshlab-1032-add-3mf-export-and-i…
Browse files Browse the repository at this point in the history
…mport

Add 3mf export and import
  • Loading branch information
alemuntoni authored Sep 9, 2024
2 parents afcb02e + a032ec4 commit 1e1e815
Show file tree
Hide file tree
Showing 6 changed files with 738 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ if(NOT DEFINED MESHLAB_PLUGINS) # it may be already defined in parent directory
set(MESHLAB_PLUGINS
# IO plugins
meshlabplugins/io_3ds
meshlabplugins/io_3mf
meshlabplugins/io_base
meshlabplugins/io_bre
meshlabplugins/io_collada
Expand Down
3 changes: 3 additions & 0 deletions src/external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ if ((NOT MESHLAB_BUILD_MINI) AND MESHLAB_ALLOW_OPTIONAL_EXTERNAL_LIBRARIES)
# lib3ds - optional, for io_3ds
include(${CMAKE_CURRENT_SOURCE_DIR}/lib3ds.cmake)

# lib3mf - optional, for io_3mf
include(${CMAKE_CURRENT_SOURCE_DIR}/lib3mf.cmake)

# libigl - optional for filter_mesh_booleans
include(${CMAKE_CURRENT_SOURCE_DIR}/libigl.cmake)

Expand Down
73 changes: 73 additions & 0 deletions src/external/lib3mf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#############################################################################
# MeshLab o o #
# A versatile mesh processing toolbox o o #
# _ O _ #
# Copyright(C) 2023 - 2024 \/)\/ #
# Visual Computing Lab /\/| #
# ISTI - Italian National Research Council | #
# \ #
# All rights reserved. #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License (http://www.gnu.org/licenses/gpl.txt) #
# for more details. #
# #
#############################################################################

option(MESHLAB_ALLOW_DOWNLOAD_SOURCE_LIB3MF "Allow download and use of lib3MF source" ON)

if(MESHLAB_ALLOW_DOWNLOAD_SOURCE_LIB3MF)
set(LIB3MF_DIR ${MESHLAB_EXTERNAL_DOWNLOAD_DIR}/lib3mf-2.3.2)
set(LIB3MF_CHECK ${LIB3MF_DIR}/CMakeLists.txt)

if(NOT EXISTS ${LIB3MF_CHECK})
set(LIB3MF_LINK https://github.com/3MFConsortium/lib3mf/releases/download/v2.3.2/lib3mf-2.3.2-source-with-submodules.zip)
set(LIB3MF_MD5 e9f3f40de2bd58c3f9109d657c86f3a8)
download_and_unzip(
NAME "Lib3MF"
MD5 ${LIB3MF_MD5}
LINK ${LIB3MF_LINK}
DIR ${MESHLAB_EXTERNAL_DOWNLOAD_DIR})
if(NOT download_and_unzip_SUCCESS)
message(STATUS "- Lib3MF - download failed")
endif()
endif()

if(EXISTS ${LIB3MF_CHECK})
message(STATUS "- Lib3MF - Using downloaded Lib3MF sources")
set(MESSAGE_QUIET ON)
set(LIB3MF_TESTS OFF)
add_subdirectory(${LIB3MF_DIR} EXCLUDE_FROM_ALL)

# Well, this is extremely ugly
# But due to some bug in lib3mf CMake function `generate_product_version`,
# it is not possible to build lib3mf with ninja on Windows, because the following
# error message will appear when processing VersionResource.rc
#
# fatal error RC1106: invalid option: -3
#
# I don't know what causes the bug. A workaround is to just simply exclude VersionResource.rc from the list
# of sources associated to the lib3mf target.
if( WIN32 AND CMAKE_GENERATOR STREQUAL "Ninja" )
get_target_property(LIB3MF_SRCS lib3mf SOURCES)
LIST(FILTER LIB3MF_SRCS EXCLUDE REGEX "VersionResource.rc")
SET_TARGET_PROPERTIES(lib3mf PROPERTIES SOURCES "${LIB3MF_SRCS}")
endif()
unset(MESSAGE_QUIET)
else()
message(FATAL " - Lib3MF - Could not add lib3mf to source tree ")
endif()

add_library(external-lib3mf INTERFACE)
target_link_libraries(external-lib3mf INTERFACE lib3mf)
target_include_directories(external-lib3mf INTERFACE ${LIB3MF_DIR}/Autogenerated/Bindings/Cpp)
install(TARGETS lib3mf DESTINATION ${MESHLAB_LIB_INSTALL_DIR})

endif()
34 changes: 34 additions & 0 deletions src/meshlabplugins/io_3mf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#############################################################################
# MeshLab o o #
# A versatile mesh processing toolbox o o #
# _ O _ #
# Copyright(C) 2023 - 2024 \/)\/ #
# Visual Computing Lab /\/| #
# ISTI - Italian National Research Council | #
# \ #
# All rights reserved. #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License (http://www.gnu.org/licenses/gpl.txt) #
# for more details. #
# #
#############################################################################

set(HEADERS
io_3mf.h
)

set(SOURCES
io_3mf.cpp
)

add_meshlab_plugin(io_3mf ${SOURCES} ${HEADERS})

target_link_libraries(io_3mf PUBLIC external-lib3mf)
Loading

0 comments on commit 1e1e815

Please sign in to comment.