From 49db47cb3721d72245a3036230c64ac6be20e06b Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 22 Jan 2020 17:36:59 +0100 Subject: [PATCH 1/3] add draco/1.3.5 --- recipes/draco/all/CMakeLists.txt | 7 + recipes/draco/all/conandata.yml | 4 + recipes/draco/all/conanfile.py | 122 +++++++++++++++++ recipes/draco/all/test_package/CMakeLists.txt | 11 ++ recipes/draco/all/test_package/conanfile.py | 16 +++ .../draco/all/test_package/test_package.cpp | 124 ++++++++++++++++++ recipes/draco/config.yml | 3 + 7 files changed, 287 insertions(+) create mode 100644 recipes/draco/all/CMakeLists.txt create mode 100644 recipes/draco/all/conandata.yml create mode 100644 recipes/draco/all/conanfile.py create mode 100644 recipes/draco/all/test_package/CMakeLists.txt create mode 100644 recipes/draco/all/test_package/conanfile.py create mode 100644 recipes/draco/all/test_package/test_package.cpp create mode 100644 recipes/draco/config.yml diff --git a/recipes/draco/all/CMakeLists.txt b/recipes/draco/all/CMakeLists.txt new file mode 100644 index 0000000000000..217b9530b904d --- /dev/null +++ b/recipes/draco/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.11) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("source_subfolder") diff --git a/recipes/draco/all/conandata.yml b/recipes/draco/all/conandata.yml new file mode 100644 index 0000000000000..6a1f94d91853d --- /dev/null +++ b/recipes/draco/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.3.5": + url: "https://github.com/google/draco/archive/1.3.5.tar.gz" + sha256: "a3ac692397574166ad99493ff1efcd7b5c69b580e7eb4500d5d181b2f676aa6e" diff --git a/recipes/draco/all/conanfile.py b/recipes/draco/all/conanfile.py new file mode 100644 index 0000000000000..3e942ff469db5 --- /dev/null +++ b/recipes/draco/all/conanfile.py @@ -0,0 +1,122 @@ +import os + +from conans import ConanFile, CMake, tools + +class DracoConan(ConanFile): + name = "draco" + description = "Draco is a library for compressing and decompressing 3D " \ + "geometric meshes and point clouds. It is intended to " \ + "improve the storage and transmission of 3D graphics." + license = "Apache-2.0" + topics = ("conan", "draco", "3d", "graphics", "mesh", "compression", "decompression") + homepage = "https://google.github.io/draco/" + url = "https://github.com/conan-io/conan-center-index" + exports_sources = "CMakeLists.txt" + generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + "target": ["encode_and_decode", "encode_only", "decode_only"], + "enable_point_cloud_compression": [True, False], + "enable_mesh_compression": [True, False], + "enable_standard_edgebreaker": [True, False], + "enable_predictive_edgebreaker": [True, False], + "enable_backwards_compatibility": [True, False] + } + default_options = { + "shared": False, + "fPIC": True, + "target": "encode_and_decode", + "enable_point_cloud_compression": True, + "enable_mesh_compression": True, + "enable_standard_edgebreaker": True, + "enable_predictive_edgebreaker": True, + "enable_backwards_compatibility": True + } + + @property + def _source_subfolder(self): + return "source_subfolder" + + @property + def _build_subfolder(self): + return "build_subfolder" + + def config_options(self): + del self.options.fPIC + + def configure(self): + if not self.options.enable_mesh_compression: + del self.options.enable_standard_edgebreaker + del self.options.enable_predictive_edgebreaker + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename(self.name + "-" + self.version, self._source_subfolder) + + def build(self): + cmake = self._configure_cmake() + cmake.build(target=self._get_target()) + + def _configure_cmake(self): + cmake = CMake(self) + cmake.definitions["ENABLE_POINT_CLOUD_COMPRESSION"] = self.options.enable_point_cloud_compression + cmake.definitions["ENABLE_MESH_COMPRESSION"] = self.options.enable_mesh_compression + if self.options.enable_mesh_compression: + cmake.definitions["ENABLE_STANDARD_EDGEBREAKER"] = self.options.enable_standard_edgebreaker + cmake.definitions["ENABLE_PREDICTIVE_EDGEBREAKER"] = self.options.enable_predictive_edgebreaker + cmake.definitions["ENABLE_BACKWARDS_COMPATIBILITY"] = self.options.enable_backwards_compatibility + + # BUILD_FOR_GLTF is not needed, it is equivalent to: + # - enable_point_cloud_compression=False + # - enable_mesh_compression=True + # - enable_standard_edgebreaker=True + # - enable_predictive_edgebreaker=False + # - enable_backwards_compatibility=False + cmake.definitions["BUILD_FOR_GLTF"] = False + + cmake.definitions["BUILD_UNITY_PLUGIN"] = False + cmake.definitions["BUILD_MAYA_PLUGIN"] = False + cmake.definitions["BUILD_USD_PLUGIN"] = False + + cmake.definitions["ENABLE_CCACHE"] = False + cmake.definitions["ENABLE_DISTCC"] = False + cmake.definitions["ENABLE_EXTRA_SPEED"] = False + cmake.definitions["ENABLE_EXTRA_WARNINGS"] = False + cmake.definitions["ENABLE_GOMA"] = False + cmake.definitions["ENABLE_JS_GLUE"] = False + cmake.definitions["ENABLE_DECODER_ATTRIBUTE_DEDUPLICATION"] = False + cmake.definitions["ENABLE_TESTS"] = False + cmake.definitions["ENABLE_WASM"] = False + cmake.definitions["ENABLE_WERROR"] = False + cmake.definitions["ENABLE_WEXTRA"] = False + cmake.definitions["IGNORE_EMPTY_BUILD_TYPE"] = False + cmake.definitions["BUILD_ANIMATION_ENCODING"] = False + + cmake.configure(build_folder=self._build_subfolder) + return cmake + + def _get_target(self): + return { + "encode_and_decode": "draco", + "encode_only": "dracoenc", + "decode_only": "dracodec" + }.get(str(self.options.target)) + + def package(self): + self.copy("LICENSE", dst="licenses", src=self._source_subfolder) + + self.copy(pattern="*.h", dst="include", src=os.path.join(self._source_subfolder, "src")) + self.copy(pattern="*.h", dst=os.path.join("include", "draco"), src=os.path.join(self._build_subfolder, "draco")) + + build_lib_dir = os.path.join(self._build_subfolder, "lib") + build_bin_dir = os.path.join(self._build_subfolder, "bin") + self.copy(pattern="*.a", dst="lib", src=build_lib_dir, keep_path=False) + self.copy(pattern="*.lib", dst="lib", src=build_lib_dir, keep_path=False) + self.copy(pattern="*.dylib", dst="lib", src=build_lib_dir, keep_path=False) + self.copy(pattern="*.so*", dst="lib", src=build_lib_dir, keep_path=False, symlinks=True) + self.copy(pattern="*.dll", dst="bin", src=build_bin_dir, keep_path=False) + + def package_info(self): + self.cpp_info.libs = tools.collect_libs(self) diff --git a/recipes/draco/all/test_package/CMakeLists.txt b/recipes/draco/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..4eb783c61cd5c --- /dev/null +++ b/recipes/draco/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8.11) +project(test_package) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/draco/all/test_package/conanfile.py b/recipes/draco/all/test_package/conanfile.py new file mode 100644 index 0000000000000..d6618f3bb6168 --- /dev/null +++ b/recipes/draco/all/test_package/conanfile.py @@ -0,0 +1,16 @@ +import os + +from conans import ConanFile, CMake + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/draco/all/test_package/test_package.cpp b/recipes/draco/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..9f30b5dfd08f8 --- /dev/null +++ b/recipes/draco/all/test_package/test_package.cpp @@ -0,0 +1,124 @@ +#include + +#include +#include +#include +#include + +struct Vec3D { + float x, y, z; + Vec3D(float x, float y, float z): x(x), y(y), z(z) {} +}; + +struct Triangle { + uint32_t i1, i2, i3; + Triangle(uint32_t i1, uint32_t i2, uint32_t i3): i1(i1), i2(i2), i3(i3) {} +}; + +struct IndexedMesh { + std::vector vertices; + std::vector primitives; + + unsigned long long size() { + return vertices.size() * sizeof(Vec3D) + primitives.size() * sizeof(Triangle); + } +}; + +std::vector create_icosahedron_vertices() { + std::vector vertices; + vertices.reserve(12); + + const float t = (1.0f + std::sqrt(5.0f)) / 2.0f; + + vertices.emplace_back(-1.0f, t, 0.0f); + vertices.emplace_back( 1.0f, t, 0.0f); + vertices.emplace_back(-1.0f, -t, 0.0f); + vertices.emplace_back( 1.0f, -t, 0.0f); + + vertices.emplace_back(0.0f, -1.0f, t); + vertices.emplace_back(0.0f, 1.0f, t); + vertices.emplace_back(0.0f, -1.0f, -t); + vertices.emplace_back(0.0f, 1.0f, -t); + + vertices.emplace_back( t, 0.0f, -1.0f); + vertices.emplace_back( t, 0.0f, 1.0f); + vertices.emplace_back(-t, 0.0f, -1.0f); + vertices.emplace_back(-t, 0.0f, 1.0f); + + return vertices; +} + +std::vector create_icosahedron_primitives() { + std::vector primitives; + primitives.reserve(20); + + primitives.emplace_back(0 , 11, 5 ); + primitives.emplace_back(0 , 5 , 1 ); + primitives.emplace_back(0 , 1 , 7 ); + primitives.emplace_back(0 , 7 , 10); + primitives.emplace_back(0 , 10, 11); + + primitives.emplace_back(1 , 5 , 9 ); + primitives.emplace_back(5 , 11, 4 ); + primitives.emplace_back(11, 1 , 2 ); + primitives.emplace_back(10, 7 , 6 ); + primitives.emplace_back(7 , 1 , 8 ); + + primitives.emplace_back(3 , 9 , 4 ); + primitives.emplace_back(3 , 4 , 2 ); + primitives.emplace_back(3 , 2 , 6 ); + primitives.emplace_back(3 , 6 , 8 ); + primitives.emplace_back(3 , 8 , 9 ); + + primitives.emplace_back(4 , 9 , 5 ); + primitives.emplace_back(2 , 4 , 11); + primitives.emplace_back(6 , 2 , 10); + primitives.emplace_back(8 , 6 , 7 ); + primitives.emplace_back(9 , 8 , 1 ); + + return primitives; +} + +int main(int argc, char **argv) { + // Create initial Mesh + IndexedMesh mesh; + mesh.vertices = create_icosahedron_vertices(); + mesh.primitives = create_icosahedron_primitives(); + + // Create Draco Mesh from initial Mesh + std::unique_ptr dracoMesh(new draco::Mesh()); + dracoMesh->set_num_points(static_cast(mesh.vertices.size())); + + draco::GeometryAttribute pos_attr; + pos_attr.Init(draco::GeometryAttribute::POSITION, nullptr, 3, draco::DT_FLOAT32, false, sizeof(Vec3D), 0); + const uint32_t pos_att_id = dracoMesh->AddAttribute(pos_attr, true, static_cast(mesh.vertices.size())); + for (std::size_t i = 0; i < mesh.vertices.size(); ++i) { + dracoMesh->attribute(pos_att_id)->SetAttributeValue( + draco::AttributeValueIndex(static_cast(i)), + &mesh.vertices[i] + ); + } + + for (const auto &primitive : mesh.primitives) { + dracoMesh->AddFace({ + draco::PointIndex(primitive.i1), + draco::PointIndex(primitive.i2), + draco::PointIndex(primitive.i3) + }); + } + + std::cout << "Number of faces : " << dracoMesh->num_faces() << "\n"; + std::cout << "Number of vertices: " << dracoMesh->num_points() << "\n"; + + // Encode mesh with position's quantization of 16 bits and edgebreaker + draco::Encoder encoder; + encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 16); + encoder.SetEncodingMethod(draco::MESH_EDGEBREAKER_ENCODING); + draco::EncoderBuffer buffer; + encoder.EncodeMeshToBuffer(*dracoMesh, &buffer); + + std::cout << "Initial mesh in " << mesh.size() << " bytes\n"; + std::cout << "Encoded mesh in " << buffer.size() << " bytes\n"; + + return 0; +} \ No newline at end of file diff --git a/recipes/draco/config.yml b/recipes/draco/config.yml new file mode 100644 index 0000000000000..f6ff1e4bb62ce --- /dev/null +++ b/recipes/draco/config.yml @@ -0,0 +1,3 @@ +versions: + "1.3.5": + folder: all From b3bf31e4bb6ddfc9df48e82dc06b3f1a7983beaa Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 24 Jan 2020 14:29:58 +0100 Subject: [PATCH 2/3] enable short_paths Co-Authored-By: Uilian Ries --- recipes/draco/all/conanfile.py | 1 + 1 file changed, 1 insertion(+) diff --git a/recipes/draco/all/conanfile.py b/recipes/draco/all/conanfile.py index 3e942ff469db5..059bcd6edda00 100644 --- a/recipes/draco/all/conanfile.py +++ b/recipes/draco/all/conanfile.py @@ -14,6 +14,7 @@ class DracoConan(ConanFile): exports_sources = "CMakeLists.txt" generators = "cmake" settings = "os", "arch", "compiler", "build_type" + short_paths = True options = { "shared": [True, False], "fPIC": [True, False], From a110c2ac681288c081adf252ac27bf957b61ad6a Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Fri, 24 Jan 2020 18:46:16 +0100 Subject: [PATCH 3/3] keep fPIC option if static and non Windows Co-Authored-By: Anonymous Maarten --- recipes/draco/all/conanfile.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/recipes/draco/all/conanfile.py b/recipes/draco/all/conanfile.py index 059bcd6edda00..ec4e582e7ccc3 100644 --- a/recipes/draco/all/conanfile.py +++ b/recipes/draco/all/conanfile.py @@ -45,9 +45,12 @@ def _build_subfolder(self): return "build_subfolder" def config_options(self): - del self.options.fPIC + if self.settings.os == "Windows": + del self.options.fPIC def configure(self): + if self.options.shared: + del self.options.fPIC if not self.options.enable_mesh_compression: del self.options.enable_standard_edgebreaker del self.options.enable_predictive_edgebreaker