Skip to content

Commit

Permalink
Merge pull request #725 from SpaceIm/add-draco-1.3.5
Browse files Browse the repository at this point in the history
add draco/1.3.5
  • Loading branch information
danimtb authored Jan 29, 2020
2 parents f609dbc + a110c2a commit 50f0769
Show file tree
Hide file tree
Showing 7 changed files with 291 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/draco/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/draco/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.3.5":
url: "https://github.com/google/draco/archive/1.3.5.tar.gz"
sha256: "a3ac692397574166ad99493ff1efcd7b5c69b580e7eb4500d5d181b2f676aa6e"
126 changes: 126 additions & 0 deletions recipes/draco/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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"
short_paths = True
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):
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

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)
11 changes: 11 additions & 0 deletions recipes/draco/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
16 changes: 16 additions & 0 deletions recipes/draco/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
124 changes: 124 additions & 0 deletions recipes/draco/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <draco/compression/encode.h>

#include <cmath>
#include <iostream>
#include <memory>
#include <vector>

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<Vec3D> vertices;
std::vector<Triangle> primitives;

unsigned long long size() {
return vertices.size() * sizeof(Vec3D) + primitives.size() * sizeof(Triangle);
}
};

std::vector<Vec3D> create_icosahedron_vertices() {
std::vector<Vec3D> 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<Triangle> create_icosahedron_primitives() {
std::vector<Triangle> 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<draco::Mesh> dracoMesh(new draco::Mesh());
dracoMesh->set_num_points(static_cast<uint32_t>(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<uint32_t>(mesh.vertices.size()));
for (std::size_t i = 0; i < mesh.vertices.size(); ++i) {
dracoMesh->attribute(pos_att_id)->SetAttributeValue(
draco::AttributeValueIndex(static_cast<uint32_t>(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;
}
3 changes: 3 additions & 0 deletions recipes/draco/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.3.5":
folder: all

0 comments on commit 50f0769

Please sign in to comment.