Skip to content

Commit

Permalink
Merge pull request #6 from camnewnham/color-pad
Browse files Browse the repository at this point in the history
add support for overriding component count (padding color attributes)
  • Loading branch information
atteneder authored Jan 25, 2023
2 parents 9f7cc97 + f58e9d7 commit 20640a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
45 changes: 21 additions & 24 deletions src/draco/unity/draco_unity_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,25 @@ draco::DracoAttribute *CreateDracoAttribute(const draco::PointAttribute *attr) {

// Returns the attribute data in |attr| as an array of type T.
template <typename T>
T *CopyAttributeData(int num_points, const draco::PointAttribute *attr) {
T *CopyAttributeData(int num_points, const draco::PointAttribute *attr, int component_stride) {
const int num_components = attr->num_components();
T *const data = new T[num_points * num_components];
T *const data = new T[num_points * component_stride];

for (draco::PointIndex i(0); i < num_points; ++i) {
const draco::AttributeValueIndex val_index = attr->mapped_index(i);
bool got_data = false;
switch (num_components) {
case 1:
got_data = attr->ConvertValue<T, 1>(val_index,
data + i.value() * num_components);
got_data = attr->ConvertValue<T, 1>(val_index, data + i.value() * component_stride);
break;
case 2:
got_data = attr->ConvertValue<T, 2>(val_index,
data + i.value() * num_components);
got_data = attr->ConvertValue<T, 2>(val_index, data + i.value() * component_stride);
break;
case 3:
got_data = attr->ConvertValue<T, 3>(val_index,
data + i.value() * num_components);
got_data = attr->ConvertValue<T, 3>(val_index, data + i.value() * component_stride);
break;
case 4:
got_data = attr->ConvertValue<T, 4>(val_index,
data + i.value() * num_components);
got_data = attr->ConvertValue<T, 4>(val_index, data + i.value() * component_stride);
break;
default:
break;
Expand All @@ -69,14 +65,14 @@ T *CopyAttributeData(int num_points, const draco::PointAttribute *attr) {

// Returns the attribute data in |attr| as an array of type T.
template <typename T>
T *CopyAttributeDataFlipped(int num_points, const draco::PointAttribute *attr) {
T *CopyAttributeDataFlipped(int num_points, const draco::PointAttribute *attr, int component_stride) {
const int num_components = attr->num_components();
T *const data = new T[num_points * num_components];
T *const data = new T[num_points * component_stride];

for (draco::PointIndex i(0); i < num_points; ++i) {
const draco::AttributeValueIndex val_index = attr->mapped_index(i);
bool got_data = false;
T* outPtr = data + i.value() * num_components;
T *outPtr = data + i.value() * component_stride;
switch (num_components) {
case 1:
got_data = attr->ConvertValue<T, 1>(val_index,outPtr);
Expand Down Expand Up @@ -110,22 +106,23 @@ T *CopyAttributeDataFlipped(int num_points, const draco::PointAttribute *attr) {
}

// Returns the attribute data in |attr| as an array of void*.
void *ConvertAttributeData(int num_points, const draco::PointAttribute *attr, bool flip) {
void *ConvertAttributeData(int num_points, const draco::PointAttribute *attr,
bool flip, int component_stride) {
switch (attr->data_type()) {
case draco::DataType::DT_INT8:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<int8_t>(num_points, attr) : CopyAttributeData<int8_t>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<int8_t>(num_points, attr, component_stride) : CopyAttributeData<int8_t>(num_points, attr, component_stride));
case draco::DataType::DT_UINT8:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<uint8_t>(num_points, attr) : CopyAttributeData<uint8_t>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<uint8_t>(num_points, attr, component_stride) : CopyAttributeData<uint8_t>(num_points, attr, component_stride));
case draco::DataType::DT_INT16:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<int16_t>(num_points, attr) : CopyAttributeData<int16_t>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<int16_t>(num_points, attr, component_stride) : CopyAttributeData<int16_t>(num_points, attr, component_stride));
case draco::DataType::DT_UINT16:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<uint16_t>(num_points, attr) : CopyAttributeData<uint16_t>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<uint16_t>(num_points, attr, component_stride) : CopyAttributeData<uint16_t>(num_points, attr, component_stride));
case draco::DataType::DT_INT32:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<int32_t>(num_points, attr) : CopyAttributeData<int32_t>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<int32_t>(num_points, attr, component_stride) : CopyAttributeData<int32_t>(num_points, attr, component_stride));
case draco::DataType::DT_UINT32:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<uint32_t>(num_points, attr) : CopyAttributeData<uint32_t>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<uint32_t>(num_points, attr, component_stride) : CopyAttributeData<uint32_t>(num_points, attr, component_stride));
case draco::DataType::DT_FLOAT32:
return static_cast<void *>(flip ? CopyAttributeDataFlipped<float>(num_points, attr) : CopyAttributeData<float>(num_points, attr));
return static_cast<void *>(flip ? CopyAttributeDataFlipped<float>(num_points, attr, component_stride) : CopyAttributeData<float>(num_points, attr, component_stride));
default:
return nullptr;
}
Expand Down Expand Up @@ -294,7 +291,7 @@ int EXPORT_API DecodeDracoMeshStep1(
} else if (geom_type == draco::POINT_CLOUD) {
auto statusor = (*decoder)->DecodePointCloudFromBuffer(*buffer);
if (!statusor.ok()) {
return -4;
return -5;
}

std::unique_ptr<draco::PointCloud> in_cloud = std::move(statusor).value();
Expand Down Expand Up @@ -390,15 +387,15 @@ bool EXPORT_API GetMeshIndices(const DracoMesh *mesh, DataType dataType, void* i

bool EXPORT_API GetAttributeData(const DracoMesh *mesh,
const DracoAttribute *attribute,
DracoData **data, bool flip) {
DracoData **data, bool flip,int stride) {
if (mesh == nullptr || data == nullptr || *data != nullptr) {
return false;
}
const Mesh *const m = static_cast<const Mesh *>(mesh->private_mesh);
const PointAttribute *const attr =
static_cast<const PointAttribute *>(attribute->private_attribute);

void *temp_data = ConvertAttributeData(m->num_points(), attr, flip);
void *temp_data = ConvertAttributeData(m->num_points(), attr, flip, stride);
if (temp_data == nullptr) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/draco/unity/draco_unity_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool EXPORT_API GetMeshIndices(const DracoMesh *mesh, DataType dataType, void* i
// with ReleaseDracoData.
bool EXPORT_API GetAttributeData(const DracoMesh *mesh,
const DracoAttribute *attribute,
DracoData **data, bool flip);
DracoData **data, bool flip, int component_stride);

// DracoToUnityMesh is deprecated.
struct EXPORT_API DracoToUnityMesh {
Expand Down

0 comments on commit 20640a7

Please sign in to comment.