Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/resources/3d/mesh_library.h
9898 views
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
#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_server.h"
38
39
#ifndef PHYSICS_3D_DISABLED
40
#include "shape_3d.h"
41
#endif // PHYSICS_3D_DISABLED
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 // PHYSICS_3D_DISABLED
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 // PHYSICS_3D_DISABLED
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 // PHYSICS_3D_DISABLED
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 // PHYSICS_3D_DISABLED
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 // PHYSICS_3D_DISABLED
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
};
121
122