| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/io/resource.h" |
| 34 |
#include "core/templates/rb_map.h" |
| 35 |
#include "scene/resources/mesh.h" |
| 36 |
#include "scene/resources/navigation_mesh.h" |
| 37 |
#include "servers/rendering/rendering_server.h" |
| 38 |
|
| 39 |
#ifndef PHYSICS_3D_DISABLED |
| 40 |
#include "shape_3d.h" |
| 41 |
#endif |
| 42 |
|
| 43 |
class MeshLibrary : public Resource { |
| 44 |
GDCLASS(MeshLibrary, Resource); |
| 45 |
RES_BASE_EXTENSION("meshlib"); |
| 46 |
|
| 47 |
public: |
| 48 |
#ifndef PHYSICS_3D_DISABLED |
| 49 |
struct ShapeData { |
| 50 |
Ref<Shape3D> shape; |
| 51 |
Transform3D local_transform; |
| 52 |
}; |
| 53 |
#endif |
| 54 |
struct Item { |
| 55 |
String name; |
| 56 |
Ref<Mesh> mesh; |
| 57 |
Transform3D mesh_transform; |
| 58 |
RS::ShadowCastingSetting mesh_cast_shadow = RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON; |
| 59 |
#ifndef PHYSICS_3D_DISABLED |
| 60 |
Vector<ShapeData> shapes; |
| 61 |
#endif |
| 62 |
Ref<Texture2D> preview; |
| 63 |
Ref<NavigationMesh> navigation_mesh; |
| 64 |
Transform3D navigation_mesh_transform; |
| 65 |
uint32_t navigation_layers = 1; |
| 66 |
}; |
| 67 |
|
| 68 |
RBMap<int, Item> item_map; |
| 69 |
|
| 70 |
#ifndef PHYSICS_3D_DISABLED |
| 71 |
void _set_item_shapes(int p_item, const Array &p_shapes); |
| 72 |
Array _get_item_shapes(int p_item) const; |
| 73 |
#endif |
| 74 |
|
| 75 |
protected: |
| 76 |
bool _set(const StringName &p_name, const Variant &p_value); |
| 77 |
bool _get(const StringName &p_name, Variant &r_ret) const; |
| 78 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 79 |
|
| 80 |
virtual void reset_state() override; |
| 81 |
static void _bind_methods(); |
| 82 |
|
| 83 |
public: |
| 84 |
void create_item(int p_item); |
| 85 |
void set_item_name(int p_item, const String &p_name); |
| 86 |
void set_item_mesh(int p_item, const Ref<Mesh> &p_mesh); |
| 87 |
void set_item_mesh_transform(int p_item, const Transform3D &p_transform); |
| 88 |
void set_item_mesh_cast_shadow(int p_item, RS::ShadowCastingSetting p_shadow_casting_setting); |
| 89 |
void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh); |
| 90 |
void set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform); |
| 91 |
void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers); |
| 92 |
#ifndef PHYSICS_3D_DISABLED |
| 93 |
void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes); |
| 94 |
#endif |
| 95 |
void set_item_preview(int p_item, const Ref<Texture2D> &p_preview); |
| 96 |
String get_item_name(int p_item) const; |
| 97 |
Ref<Mesh> get_item_mesh(int p_item) const; |
| 98 |
Transform3D get_item_mesh_transform(int p_item) const; |
| 99 |
RS::ShadowCastingSetting get_item_mesh_cast_shadow(int p_item) const; |
| 100 |
Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const; |
| 101 |
Transform3D get_item_navigation_mesh_transform(int p_item) const; |
| 102 |
uint32_t get_item_navigation_layers(int p_item) const; |
| 103 |
#ifndef PHYSICS_3D_DISABLED |
| 104 |
Vector<ShapeData> get_item_shapes(int p_item) const; |
| 105 |
#endif |
| 106 |
Ref<Texture2D> get_item_preview(int p_item) const; |
| 107 |
|
| 108 |
void remove_item(int p_item); |
| 109 |
bool has_item(int p_item) const; |
| 110 |
|
| 111 |
void clear(); |
| 112 |
|
| 113 |
int find_item_by_name(const String &p_name) const; |
| 114 |
|
| 115 |
Vector<int> get_item_list() const; |
| 116 |
int get_last_unused_item_id() const; |
| 117 |
|
| 118 |
MeshLibrary(); |
| 119 |
~MeshLibrary(); |
| 120 |
}; |