godot_voxel/streams/instance_data.h

63 lines
1.7 KiB
C
Raw Normal View History

#ifndef VOXEL_INSTANCE_DATA_H
#define VOXEL_INSTANCE_DATA_H
2021-05-31 08:48:49 -07:00
#include "../util/span.h"
#include <core/math/transform_3d.h>
2022-01-09 14:46:26 -08:00
namespace zylann::voxel {
// 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 {
struct InstanceData {
Transform3D transform;
};
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
// - 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.
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.
static const float SIMPLE_11B_V1_SCALE_RANGE_MINIMUM;
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 {
// 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
#endif // VOXEL_INSTANCE_DATA_H