godot_voxel/streams/instance_data.h

64 lines
1.8 KiB
C++

#ifndef VOXEL_INSTANCE_DATA_H
#define VOXEL_INSTANCE_DATA_H
#include "../util/span.h"
#include <core/math/transform_3d.h>
namespace zylann::voxel {
// Stores data to pass around until it either gets saved or turned into actual instances
struct InstanceBlockData {
struct InstanceData {
// Transform of the instance, relative to the origin of the data block.
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;
//
// 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;
// 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;
// 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;
void copy_to(InstanceBlockData &dst) const {
// It's all POD so it should work for now
dst = *this;
}
};
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