| 280 | } |
| 281 | |
| 282 | Mesh::Ptr DracoCompressionEngine::decompress(const std::string& data) const { |
| 283 | draco::DecoderBuffer buffer; |
| 284 | buffer.Init(data.c_str(), data.size()); |
| 285 | auto type_statusor = draco::Decoder::GetEncodedGeometryType(&buffer); |
| 286 | if (!type_statusor.ok()) { |
| 287 | throw RuntimeError("Failed to decode Draco buffer."); |
| 288 | } |
| 289 | |
| 290 | draco::Decoder decoder; |
| 291 | draco::Mesh* draco_mesh = nullptr; |
| 292 | const draco::EncodedGeometryType geom_type = type_statusor.value(); |
| 293 | if (geom_type == draco::TRIANGULAR_MESH) { |
| 294 | auto statusor = decoder.DecodeMeshFromBuffer(&buffer); |
| 295 | if (!statusor.ok()) { |
| 296 | throw RuntimeError("Draco decoding from triangle mesh failed."); |
| 297 | } |
| 298 | std::unique_ptr<draco::Mesh> in_mesh = std::move(statusor).value(); |
| 299 | if (!in_mesh) { |
| 300 | throw RuntimeError("Draco decoding from triangle mesh failed."); |
| 301 | } |
| 302 | return DracoCompressionEngineHelper::from_draco_mesh(std::move(in_mesh)); |
| 303 | } else if (geom_type == draco::POINT_CLOUD) { |
| 304 | auto statusor = decoder.DecodePointCloudFromBuffer(&buffer); |
| 305 | if (!statusor.ok()) { |
| 306 | throw RuntimeError("Draco decoding from point cloud failed."); |
| 307 | } |
| 308 | std::unique_ptr<draco::PointCloud> in_mesh = std::move(statusor).value(); |
| 309 | if (!in_mesh) { |
| 310 | throw RuntimeError("Draco decoding from point cloud failed."); |
| 311 | } |
| 312 | return DracoCompressionEngineHelper::from_draco_point_cloud(std::move(in_mesh)); |
| 313 | } else { |
| 314 | throw NotImplementedError("Unsupported Draco mesh type."); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | #endif |