Skip to content

Commit

Permalink
Merge pull request #3 from atteneder/unity-point-clouds-v2
Browse files Browse the repository at this point in the history
Unity point clouds v2
  • Loading branch information
atteneder authored Sep 11, 2021
2 parents dcdc047 + 14736ed commit 427fc7e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 12 deletions.
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 @@ -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<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 @@ -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;
}

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

0 comments on commit 427fc7e

Please sign in to comment.