2016-05-01 15:00:02 +02:00
|
|
|
#ifndef VOXEL_TYPE_H
|
|
|
|
#define VOXEL_TYPE_H
|
|
|
|
|
|
|
|
#include <reference.h>
|
|
|
|
|
2016-05-01 22:20:27 +02:00
|
|
|
class VoxelLibrary;
|
|
|
|
|
2016-05-01 15:00:02 +02:00
|
|
|
// Definition of one type of voxel.
|
|
|
|
// A voxel can be a simple coloured cube, or a more complex model.
|
2016-05-01 22:20:27 +02:00
|
|
|
// Important: it is recommended that you create voxels from a library rather than using new().
|
2016-05-01 15:00:02 +02:00
|
|
|
class Voxel : public Reference {
|
2017-03-25 01:23:36 +01:00
|
|
|
GDCLASS(Voxel, Reference)
|
2016-05-01 15:00:02 +02:00
|
|
|
|
|
|
|
public:
|
2017-01-01 04:40:16 +01:00
|
|
|
enum Side {
|
|
|
|
SIDE_LEFT = 0,
|
|
|
|
SIDE_RIGHT,
|
|
|
|
SIDE_BOTTOM,
|
|
|
|
SIDE_TOP,
|
|
|
|
SIDE_BACK,
|
|
|
|
SIDE_FRONT,
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
SIDE_COUNT
|
|
|
|
};
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-04-06 23:44:11 +02:00
|
|
|
enum ChannelMode {
|
|
|
|
// For mapping to a Voxel type
|
|
|
|
CHANNEL_TYPE = 0,
|
|
|
|
// Distance to surface for smooth voxels
|
|
|
|
CHANNEL_ISOLEVEL,
|
|
|
|
// Arbitrary data not used by the module
|
|
|
|
CHANNEL_DATA
|
|
|
|
};
|
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
Voxel();
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
// Properties
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2017-01-02 02:19:02 +01:00
|
|
|
Ref<Voxel> set_name(String name);
|
2017-01-01 04:40:16 +01:00
|
|
|
_FORCE_INLINE_ String get_name() const { return _name; }
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
Ref<Voxel> set_id(int id);
|
|
|
|
_FORCE_INLINE_ int get_id() const { return _id; }
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-02 02:19:02 +01:00
|
|
|
Ref<Voxel> set_color(Color color);
|
2017-01-01 04:40:16 +01:00
|
|
|
_FORCE_INLINE_ Color get_color() const { return _color; }
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
Ref<Voxel> set_material_id(unsigned int id);
|
|
|
|
_FORCE_INLINE_ unsigned int get_material_id() const { return _material_id; }
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-02 02:19:02 +01:00
|
|
|
Ref<Voxel> set_transparent(bool t = true);
|
2017-01-01 04:40:16 +01:00
|
|
|
_FORCE_INLINE_ bool is_transparent() const { return _is_transparent; }
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
// Built-in geometry generators
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
Ref<Voxel> set_cube_geometry(float sy = 1);
|
|
|
|
Ref<Voxel> set_cube_uv_all_sides(Vector2 atlas_pos);
|
|
|
|
Ref<Voxel> set_cube_uv_tbs_sides(Vector2 top_atlas_pos, Vector2 side_atlas_pos, Vector2 bottom_atlas_pos);
|
|
|
|
//Ref<Voxel> set_xquad_geometry(Vector2 atlas_pos);
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
// Getters for native usage only
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-08-13 01:19:39 +02:00
|
|
|
const PoolVector<Vector3> &get_model_vertices() const { return _model_vertices; }
|
|
|
|
const PoolVector<Vector3> &get_model_normals() const { return _model_normals; }
|
|
|
|
const PoolVector<Vector2> &get_model_uv() const { return _model_uv; }
|
|
|
|
const PoolVector<Vector3> &get_model_side_vertices(unsigned int side) const { return _model_side_vertices[side]; }
|
|
|
|
const PoolVector<Vector2> &get_model_side_uv(unsigned int side) const { return _model_side_uv[side]; }
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-08-13 01:19:39 +02:00
|
|
|
void set_library_ptr(VoxelLibrary *lib) { _library = lib; }
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2016-05-01 15:00:02 +02:00
|
|
|
protected:
|
2017-01-01 04:40:16 +01:00
|
|
|
Ref<Voxel> _set_cube_uv_sides(const Vector2 atlas_pos[6]);
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
static void _bind_methods();
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-02 02:19:02 +01:00
|
|
|
private:
|
2017-08-13 01:19:39 +02:00
|
|
|
VoxelLibrary *_library;
|
2017-01-02 02:19:02 +01:00
|
|
|
|
|
|
|
// Identifiers
|
|
|
|
int _id;
|
|
|
|
String _name;
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
int _material_id;
|
|
|
|
bool _is_transparent;
|
|
|
|
|
|
|
|
// Model
|
|
|
|
Color _color;
|
2017-03-25 01:23:36 +01:00
|
|
|
PoolVector<Vector3> _model_vertices;
|
|
|
|
PoolVector<Vector3> _model_normals;
|
|
|
|
PoolVector<Vector2> _model_uv;
|
|
|
|
PoolVector<Vector3> _model_side_vertices[SIDE_COUNT];
|
|
|
|
PoolVector<Vector2> _model_side_uv[SIDE_COUNT];
|
2017-01-02 02:19:02 +01:00
|
|
|
|
|
|
|
// TODO Child voxel types
|
2016-05-01 15:00:02 +02:00
|
|
|
};
|
|
|
|
|
2017-04-06 23:44:11 +02:00
|
|
|
VARIANT_ENUM_CAST(Voxel::ChannelMode)
|
|
|
|
|
2016-05-01 15:00:02 +02:00
|
|
|
#endif // VOXEL_TYPE_H
|