google / draco

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.
https://google.github.io/draco/
Apache License 2.0
6.45k stars 961 forks source link

PointCloud Color compression #890

Open Robin-Wutschert opened 2 years ago

Robin-Wutschert commented 2 years ago

I have used PointCloudBuilder to encode positions and colors using

draco::PointCloudBuilder pcBuilder;
pcBuilder.Start(pointCount);
int posId = pcBuilder.AddAttribute(draco::GeometryAttribute::POSITION, 3, draco::DT_FLOAT32);
pcBuilder.SetAttributeValuesForAllPoints(posId, positions.data(), sizeOfPosition);
int colId = pcBuilder.AddAttribute(draco::GeometryAttribute::COLOR, 3, draco::DT_UINT8);
pcBuilder.SetAttributeValuesForAllPoints(colId, colors.data(), sizeOfColor);
std::unique_ptr<draco::PointCloud> pc = pcBuilder.Finalize(false);

draco::Encoder encoder;
encoder.SetSpeedOptions(7, 7);
encoder.SetAttributeQuantization(draco::GeometryAttribute::POSITION, 16);
encoder.SetAttributeQuantization(draco::GeometryAttribute::COLOR, 6);

draco::EncoderBuffer encBuff;
encoder.EncodePointCloudToBuffer(*pc, &encBuff);

Unfortunately, it appears that there is no compression happening on colors... Is it something that will be added?! To improve that, I have decided to encode colors with RGB565 manually. Thus, I modified only the following line :

int colId = pcBuilder.AddAttribute(draco::GeometryAttribute::COLOR, 1, draco::DT_UINT16);

Unfortunately, colors are inconsistent after decompression by using RGB565 (I tested it without draco compression and it works). Am I missing something ? Is there any issue there?!

Thank you for the great work, position compression is awesome!

ondys commented 1 year ago

Quantization is used only for floating points attributes. Integer attributes are compressed losslessly. Basically quantization converts floating point attributes into integer attributes (lossy operation) that are then compressed without loss. If integer attributes are provided, Draco treats them as pre-quantized.