1/**************************************************************************/
2/* mesh_library.h */
3/**************************************************************************/
4/* This file is part of: */
5/* GODOT ENGINE */
6/* https://godotengine.org */
7/**************************************************************************/
8/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10/* */
11/* Permission is hereby granted, free of charge, to any person obtaining */
12/* a copy of this software and associated documentation files (the */
13/* "Software"), to deal in the Software without restriction, including */
14/* without limitation the rights to use, copy, modify, merge, publish, */
15/* distribute, sublicense, and/or sell copies of the Software, and to */
16/* permit persons to whom the Software is furnished to do so, subject to */
17/* the following conditions: */
18/* */
19/* The above copyright notice and this permission notice shall be */
20/* included in all copies or substantial portions of the Software. */
21/* */
22/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29/**************************************************************************/
30
31#ifndef MESH_LIBRARY_H
32#define MESH_LIBRARY_H
33
34#include "core/io/resource.h"
35#include "core/templates/rb_map.h"
36#include "scene/3d/navigation_region_3d.h"
37#include "scene/resources/mesh.h"
38#include "shape_3d.h"
39
40class MeshLibrary : public Resource {
41 GDCLASS(MeshLibrary, Resource);
42 RES_BASE_EXTENSION("meshlib");
43
44public:
45 struct ShapeData {
46 Ref<Shape3D> shape;
47 Transform3D local_transform;
48 };
49 struct Item {
50 String name;
51 Ref<Mesh> mesh;
52 Transform3D mesh_transform;
53 Vector<ShapeData> shapes;
54 Ref<Texture2D> preview;
55 Ref<NavigationMesh> navigation_mesh;
56 Transform3D navigation_mesh_transform;
57 uint32_t navigation_layers = 1;
58 };
59
60 RBMap<int, Item> item_map;
61
62 void _set_item_shapes(int p_item, const Array &p_shapes);
63 Array _get_item_shapes(int p_item) const;
64
65protected:
66 bool _set(const StringName &p_name, const Variant &p_value);
67 bool _get(const StringName &p_name, Variant &r_ret) const;
68 void _get_property_list(List<PropertyInfo> *p_list) const;
69
70 virtual void reset_state() override;
71 static void _bind_methods();
72
73public:
74 void create_item(int p_item);
75 void set_item_name(int p_item, const String &p_name);
76 void set_item_mesh(int p_item, const Ref<Mesh> &p_mesh);
77 void set_item_mesh_transform(int p_item, const Transform3D &p_transform);
78 void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh);
79 void set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform);
80 void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers);
81 void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
82 void set_item_preview(int p_item, const Ref<Texture2D> &p_preview);
83 String get_item_name(int p_item) const;
84 Ref<Mesh> get_item_mesh(int p_item) const;
85 Transform3D get_item_mesh_transform(int p_item) const;
86 Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const;
87 Transform3D get_item_navigation_mesh_transform(int p_item) const;
88 uint32_t get_item_navigation_layers(int p_item) const;
89 Vector<ShapeData> get_item_shapes(int p_item) const;
90 Ref<Texture2D> get_item_preview(int p_item) const;
91
92 void remove_item(int p_item);
93 bool has_item(int p_item) const;
94
95 void clear();
96
97 int find_item_by_name(const String &p_name) const;
98
99 Vector<int> get_item_list() const;
100 int get_last_unused_item_id() const;
101
102 MeshLibrary();
103 ~MeshLibrary();
104};
105
106#endif // MESH_LIBRARY_H
107