2020-01-31 19:52:37 +01:00
|
|
|
/*
|
|
|
|
Copyright (c) 2019-2020 Péter Magyar
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2022-02-08 12:36:37 +01:00
|
|
|
#ifndef VOXEL_LIBRARY_H
|
|
|
|
#define VOXEL_LIBRARY_H
|
2019-05-31 22:54:31 +02:00
|
|
|
|
2021-02-06 11:51:50 +01:00
|
|
|
#include "core/version.h"
|
|
|
|
|
|
|
|
#if VERSION_MAJOR > 3
|
|
|
|
#include "core/io/resource.h"
|
|
|
|
#else
|
2019-05-31 22:54:31 +02:00
|
|
|
#include "core/resource.h"
|
2021-02-06 11:51:50 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "core/math/rect2.h"
|
2019-05-31 22:54:31 +02:00
|
|
|
#include "scene/resources/material.h"
|
|
|
|
|
|
|
|
#include "../data/voxel_light.h"
|
|
|
|
#include "voxel_surface.h"
|
|
|
|
|
2020-07-29 00:02:42 +02:00
|
|
|
#include "../defines.h"
|
|
|
|
|
|
|
|
#if GODOT4
|
|
|
|
#define Texture Texture2D
|
|
|
|
#endif
|
|
|
|
|
2022-02-08 23:41:17 +01:00
|
|
|
class VoxelMaterialCache;
|
|
|
|
class VoxelChunk;
|
2019-05-31 22:54:31 +02:00
|
|
|
class VoxelSurface;
|
|
|
|
class VoxelMesher;
|
2020-04-04 17:22:07 +02:00
|
|
|
class PackedScene;
|
2020-06-27 18:25:23 +02:00
|
|
|
#ifdef PROPS_PRESENT
|
2020-06-22 21:49:58 +02:00
|
|
|
class PropData;
|
2020-06-27 18:25:23 +02:00
|
|
|
#endif
|
2019-05-31 22:54:31 +02:00
|
|
|
|
2022-02-08 12:36:37 +01:00
|
|
|
class VoxelLibrary : public Resource {
|
|
|
|
GDCLASS(VoxelLibrary, Resource)
|
2019-05-31 22:54:31 +02:00
|
|
|
|
2019-11-25 12:03:45 +01:00
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
MATERIAL_INDEX_VOXELS = 0,
|
2020-04-04 17:22:07 +02:00
|
|
|
MATERIAL_INDEX_LIQUID = 1,
|
2020-06-22 21:49:58 +02:00
|
|
|
MATERIAL_INDEX_PROP = 2,
|
2019-11-25 12:03:45 +01:00
|
|
|
};
|
|
|
|
|
2019-05-31 22:54:31 +02:00
|
|
|
public:
|
2020-04-17 19:21:46 +02:00
|
|
|
bool get_initialized() const;
|
|
|
|
void set_initialized(const bool value);
|
|
|
|
|
2022-02-08 23:41:17 +01:00
|
|
|
bool supports_caching();
|
|
|
|
virtual bool _supports_caching();
|
|
|
|
|
2020-10-27 23:24:24 +01:00
|
|
|
Ref<Material> material_get(const int index);
|
2022-02-08 23:41:17 +01:00
|
|
|
Ref<Material> material_lod_get(const int index);
|
|
|
|
|
|
|
|
void material_cache_get_key(Ref<VoxelChunk> chunk);
|
|
|
|
virtual void _material_cache_get_key(Ref<VoxelChunk> chunk);
|
|
|
|
Ref<VoxelMaterialCache> material_cache_get(const int key);
|
|
|
|
virtual Ref<VoxelMaterialCache> _material_cache_get(const int key);
|
|
|
|
void material_cache_unref(const int key);
|
|
|
|
virtual void _material_cache_unref(const int key);
|
|
|
|
|
2020-10-27 23:24:24 +01:00
|
|
|
void material_add(const Ref<Material> &value);
|
|
|
|
void material_set(const int index, const Ref<Material> &value);
|
|
|
|
void material_remove(const int index);
|
|
|
|
int material_get_num() const;
|
|
|
|
void materials_clear();
|
|
|
|
|
|
|
|
Vector<Variant> materials_get();
|
|
|
|
void materials_set(const Vector<Variant> &materials);
|
|
|
|
|
|
|
|
Ref<Material> liquid_material_get(const int index);
|
2022-02-08 23:41:17 +01:00
|
|
|
Ref<Material> liquid_material_lod_get(const int index);
|
|
|
|
|
|
|
|
void liquid_material_cache_get_key(Ref<VoxelChunk> chunk);
|
|
|
|
virtual void _liquid_material_cache_get_key(Ref<VoxelChunk> chunk);
|
|
|
|
Ref<VoxelMaterialCache> liquid_material_cache_get(const int key);
|
|
|
|
virtual Ref<VoxelMaterialCache> _liquid_material_cache_get(const int key);
|
|
|
|
void liquid_material_cache_unref(const int key);
|
|
|
|
virtual void _liquid_material_cache_unref(const int key);
|
|
|
|
|
2020-10-27 23:24:24 +01:00
|
|
|
void liquid_material_add(const Ref<Material> &value);
|
|
|
|
void liquid_material_set(const int index, const Ref<Material> &value);
|
|
|
|
void liquid_material_remove(const int index);
|
|
|
|
int liquid_material_get_num() const;
|
|
|
|
void liquid_materials_clear();
|
|
|
|
|
|
|
|
Vector<Variant> liquid_materials_get();
|
|
|
|
void liquid_materials_set(const Vector<Variant> &materials);
|
|
|
|
|
|
|
|
Ref<Material> prop_material_get(const int index);
|
2022-02-08 23:41:17 +01:00
|
|
|
Ref<Material> prop_material_lod_get(const int index);
|
|
|
|
|
|
|
|
void prop_material_cache_get_key(Ref<VoxelChunk> chunk);
|
|
|
|
virtual void _prop_material_cache_get_key(Ref<VoxelChunk> chunk);
|
|
|
|
Ref<VoxelMaterialCache> prop_material_cache_get(const int key);
|
|
|
|
virtual Ref<VoxelMaterialCache> _prop_material_cache_get(const int key);
|
|
|
|
void prop_material_cache_unref(const int key);
|
|
|
|
virtual void _prop_material_cache_unref(const int key);
|
|
|
|
|
2020-10-27 23:24:24 +01:00
|
|
|
void prop_material_add(const Ref<Material> &value);
|
|
|
|
void prop_material_set(const int index, const Ref<Material> &value);
|
|
|
|
void prop_material_remove(const int index);
|
|
|
|
int prop_material_get_num() const;
|
|
|
|
void prop_materials_clear();
|
|
|
|
|
|
|
|
Vector<Variant> prop_materials_get();
|
|
|
|
void prop_materials_set(const Vector<Variant> &materials);
|
|
|
|
|
|
|
|
virtual Ref<VoxelSurface> voxel_surface_get(const int index);
|
|
|
|
virtual void voxel_surface_add(Ref<VoxelSurface> value);
|
|
|
|
virtual void voxel_surface_set(const int index, Ref<VoxelSurface> value);
|
|
|
|
virtual void voxel_surface_remove(const int index);
|
|
|
|
virtual int voxel_surface_get_num() const;
|
|
|
|
virtual void voxel_surfaces_clear();
|
|
|
|
|
|
|
|
virtual Ref<PackedScene> scene_get(const int id);
|
|
|
|
virtual void scene_add(Ref<PackedScene> value);
|
|
|
|
virtual void scene_set(const int id, Ref<PackedScene> value);
|
|
|
|
virtual void scene_remove(const int id);
|
|
|
|
virtual int scene_get_num() const;
|
|
|
|
virtual void scenes_clear();
|
2020-06-22 21:49:58 +02:00
|
|
|
|
2020-06-27 18:25:23 +02:00
|
|
|
#ifdef PROPS_PRESENT
|
2020-10-27 23:24:24 +01:00
|
|
|
virtual Ref<PropData> prop_get(const int id);
|
|
|
|
virtual void prop_add(Ref<PropData> value);
|
|
|
|
virtual bool prop_has(const Ref<PropData> &value) const;
|
|
|
|
virtual void prop_set(const int id, Ref<PropData> value);
|
|
|
|
virtual void prop_remove(const int id);
|
|
|
|
virtual int prop_get_num() const;
|
|
|
|
virtual void props_clear();
|
2020-06-28 21:31:26 +02:00
|
|
|
|
|
|
|
virtual Rect2 get_prop_uv_rect(const Ref<Texture> &texture);
|
2020-06-27 18:25:23 +02:00
|
|
|
#endif
|
2020-02-16 02:54:17 +01:00
|
|
|
|
2019-11-09 17:26:16 +01:00
|
|
|
virtual void refresh_rects();
|
2019-05-31 22:54:31 +02:00
|
|
|
|
2019-11-25 12:03:45 +01:00
|
|
|
void setup_material_albedo(int material_index, Ref<Texture> texture);
|
|
|
|
|
2022-02-07 00:15:44 +01:00
|
|
|
|
|
|
|
#if VERSION_MAJOR >= 4
|
|
|
|
GDVIRTUAL2(_setup_material_albedo, int, Ref<Texture>);
|
|
|
|
#endif
|
|
|
|
|
2022-02-08 12:36:37 +01:00
|
|
|
VoxelLibrary();
|
|
|
|
~VoxelLibrary();
|
2019-05-31 22:54:31 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2020-04-17 19:21:46 +02:00
|
|
|
bool _initialized;
|
2020-10-27 23:24:24 +01:00
|
|
|
Vector<Ref<Material> > _materials;
|
|
|
|
Vector<Ref<Material> > _liquid_materials;
|
|
|
|
Vector<Ref<Material> > _prop_materials;
|
2019-05-31 22:54:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VOXEL_LIBRARY_H
|