2021-02-07 09:22:50 -08:00
|
|
|
#ifndef VOXEL_INSTANCE_DATA_H
|
|
|
|
#define VOXEL_INSTANCE_DATA_H
|
|
|
|
|
2021-05-31 08:48:49 -07:00
|
|
|
#include "../util/span.h"
|
2021-12-13 13:38:10 -08:00
|
|
|
#include <core/math/transform_3d.h>
|
2021-02-07 09:22:50 -08:00
|
|
|
|
2022-01-09 14:46:26 -08:00
|
|
|
namespace zylann::voxel {
|
|
|
|
|
2021-02-07 09:22:50 -08:00
|
|
|
// Stores data to pass around until it either gets saved or turned into actual instances
|
2022-01-09 14:46:26 -08:00
|
|
|
struct InstanceBlockData {
|
2021-02-07 09:22:50 -08:00
|
|
|
struct InstanceData {
|
2021-12-13 13:38:10 -08:00
|
|
|
Transform3D transform;
|
2021-02-07 09:22:50 -08:00
|
|
|
};
|
|
|
|
|
2021-07-18 11:42:42 -07:00
|
|
|
enum VoxelInstanceFormat {
|
|
|
|
// Position is lossy-compressed based on the size of the block
|
|
|
|
// - uint16_t x;
|
|
|
|
// - uint16_t y;
|
|
|
|
// - uint16_t z;
|
|
|
|
//
|
|
|
|
// Scale is uniform and is lossy-compressed to 256 values
|
|
|
|
// - uint8_t scale;
|
|
|
|
//
|
2021-07-25 12:37:47 -07:00
|
|
|
// Rotation is a compressed quaternion with naive quantization of its members to 256 values
|
2021-07-18 11:42:42 -07:00
|
|
|
// - uint8_t x;
|
|
|
|
// - uint8_t y;
|
|
|
|
// - uint8_t z;
|
|
|
|
// - uint8_t w;
|
|
|
|
FORMAT_SIMPLE_11B_V1 = 0
|
|
|
|
};
|
|
|
|
|
|
|
|
static const int POSITION_RESOLUTION = 65536;
|
2021-07-25 12:37:47 -07:00
|
|
|
// Because position is quantized we need its range, but it cannot be zero so it may be clamped to this.
|
2021-07-18 11:42:42 -07:00
|
|
|
static const float POSITION_RANGE_MINIMUM;
|
|
|
|
|
|
|
|
static const int SIMPLE_11B_V1_SCALE_RESOLUTION = 256;
|
|
|
|
static const int SIMPLE_11B_V1_QUAT_RESOLUTION = 256;
|
2021-07-25 12:37:47 -07:00
|
|
|
// Because scale is quantized we need its range, but it cannot be zero so it may be clamped to this.
|
2021-07-18 11:42:42 -07:00
|
|
|
static const float SIMPLE_11B_V1_SCALE_RANGE_MINIMUM;
|
|
|
|
|
2021-02-07 09:22:50 -08:00
|
|
|
struct LayerData {
|
|
|
|
uint16_t id;
|
|
|
|
float scale_min;
|
|
|
|
float scale_max;
|
|
|
|
std::vector<InstanceData> instances;
|
|
|
|
};
|
|
|
|
|
|
|
|
float position_range;
|
|
|
|
std::vector<LayerData> layers;
|
|
|
|
|
2022-01-09 14:46:26 -08:00
|
|
|
void copy_to(InstanceBlockData &dst) const {
|
2021-02-07 09:22:50 -08:00
|
|
|
// It's all POD so it should work for now
|
|
|
|
dst = *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-01-09 14:46:26 -08:00
|
|
|
bool serialize_instance_block_data(const InstanceBlockData &src, std::vector<uint8_t> &dst);
|
|
|
|
bool deserialize_instance_block_data(InstanceBlockData &dst, Span<const uint8_t> src);
|
|
|
|
|
|
|
|
} // namespace zylann::voxel
|
2021-02-07 09:22:50 -08:00
|
|
|
|
|
|
|
#endif // VOXEL_INSTANCE_DATA_H
|