diff --git a/cmake/draco_options.cmake b/cmake/draco_options.cmake index 832bfb69..95e7a103 100644 --- a/cmake/draco_options.cmake +++ b/cmake/draco_options.cmake @@ -128,6 +128,7 @@ macro(draco_set_optional_features) draco_enable_feature(FEATURE "DRACO_MESH_COMPRESSION_SUPPORTED") draco_enable_feature(FEATURE "DRACO_NORMAL_ENCODING_SUPPORTED") draco_enable_feature(FEATURE "DRACO_STANDARD_EDGEBREAKER_SUPPORTED") + draco_enable_feature(FEATURE "DRACO_POINT_CLOUD_COMPRESSION_SUPPORTED") else() if(DRACO_POINT_CLOUD_COMPRESSION) draco_enable_feature(FEATURE "DRACO_POINT_CLOUD_COMPRESSION_SUPPORTED") diff --git a/src/draco/unity/draco_unity_plugin.cc b/src/draco/unity/draco_unity_plugin.cc index 02fd0085..4d3acb4c 100644 --- a/src/draco/unity/draco_unity_plugin.cc +++ b/src/draco/unity/draco_unity_plugin.cc @@ -270,29 +270,52 @@ int EXPORT_API DecodeDracoMeshStep1( return -2; } const draco::EncodedGeometryType geom_type = type_statusor.value(); - if (geom_type != draco::TRIANGULAR_MESH) { + if (geom_type != draco::TRIANGULAR_MESH && geom_type != draco::POINT_CLOUD) { return -3; } *mesh = new DracoMesh(); *decoder = new draco::Decoder(); - auto statusor = (*decoder)->DecodeMeshFromBufferStep1(*buffer); - if (!statusor.ok()) { - return -4; - } - std::unique_ptr in_mesh = std::move(statusor).value(); + if (geom_type == draco::TRIANGULAR_MESH) { + auto statusor = (*decoder)->DecodeMeshFromBufferStep1(*buffer); + if (!statusor.ok()) { + return -4; + } - DracoMesh *const unity_mesh = *mesh; - unity_mesh->num_faces = in_mesh->num_faces(); - unity_mesh->num_vertices = in_mesh->num_points(); - unity_mesh->num_attributes = in_mesh->num_attributes(); - unity_mesh->private_mesh = static_cast(in_mesh.release()); + std::unique_ptr in_mesh = std::move(statusor).value(); + DracoMesh *const unity_mesh = *mesh; + unity_mesh->num_faces = in_mesh->num_faces(); + unity_mesh->num_vertices = in_mesh->num_points(); + unity_mesh->num_attributes = in_mesh->num_attributes(); + unity_mesh->is_point_cloud = false; + unity_mesh->private_mesh = static_cast(in_mesh.release()); + + } else if (geom_type == draco::POINT_CLOUD) { + auto statusor = (*decoder)->DecodePointCloudFromBuffer(*buffer); + if (!statusor.ok()) { + return -4; + } + std::unique_ptr in_cloud = std::move(statusor).value(); + DracoMesh *const unity_mesh = *mesh; + unity_mesh->num_faces = 0; + unity_mesh->num_vertices = in_cloud->num_points(); + unity_mesh->num_attributes = in_cloud->num_attributes(); + unity_mesh->is_point_cloud = true; + unity_mesh->private_mesh = static_cast(in_cloud.release()); + } return 0; } int EXPORT_API DecodeDracoMeshStep2(DracoMesh **mesh,draco::Decoder* decoder, draco::DecoderBuffer* buffer) { + DracoMesh *const unity_mesh = *mesh; + if (unity_mesh->is_point_cloud) { + delete decoder; + delete buffer; + return 0; + } + auto status = decoder->DecodeMeshFromBufferStep2(); delete decoder; delete buffer; @@ -348,7 +371,7 @@ bool EXPORT_API GetAttributeByUniqueId(const DracoMesh *mesh, int unique_id, } bool EXPORT_API GetMeshIndices(const DracoMesh *mesh, DataType dataType, void* indices, uint32_t indicesCount, bool flip) { - if (mesh == nullptr || indices == nullptr) { + if (mesh == nullptr || indices == nullptr || mesh->is_point_cloud) { return false; } diff --git a/src/draco/unity/draco_unity_plugin.h b/src/draco/unity/draco_unity_plugin.h index 6e82112b..d661988b 100644 --- a/src/draco/unity/draco_unity_plugin.h +++ b/src/draco/unity/draco_unity_plugin.h @@ -64,11 +64,13 @@ struct EXPORT_API DracoMesh { : num_faces(0), num_vertices(0), num_attributes(0), + is_point_cloud(false), private_mesh(nullptr) {} int num_faces; int num_vertices; int num_attributes; + bool is_point_cloud; void *private_mesh; };