Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support point clouds #2

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/draco_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
47 changes: 35 additions & 12 deletions src/draco/unity/draco_unity_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,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<draco::Mesh> 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<void *>(in_mesh.release());
std::unique_ptr<draco::Mesh> 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<void *>(in_mesh.release());

} else if (geom_type == draco::POINT_CLOUD) {
auto statusor = (*decoder)->DecodePointCloudFromBuffer(*buffer);
if (!statusor.ok()) {
return -4;
}

std::unique_ptr<draco::PointCloud> 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<void *>(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;
Expand Down Expand Up @@ -291,7 +314,7 @@ bool EXPORT_API GetAttributeByUniqueId(const DracoMesh *mesh, int unique_id,
}

bool EXPORT_API GetMeshIndices(const DracoMesh *mesh, DracoData **indices, bool flip) {
if (mesh == nullptr || indices == nullptr || *indices != nullptr) {
if (mesh == nullptr || indices == nullptr || *indices != nullptr || mesh->is_point_cloud) {
return false;
}
const Mesh *const m = static_cast<const Mesh *>(mesh->private_mesh);
Expand Down
2 changes: 2 additions & 0 deletions src/draco/unity/draco_unity_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down