Debian Codegraph @

scene/resources/immediate_mesh.h

raw symbols SCIP
1 /**************************************************************************/
2 /* immediate_mesh.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/templates/local_vector.h"
34 #include "scene/resources/mesh.h"
35
36 class ImmediateMesh : public Mesh {
37 GDCLASS(ImmediateMesh, Mesh)
38
39 RID mesh;
40
41 bool uses_colors = false;
42 bool uses_normals = false;
43 bool uses_tangents = false;
44 bool uses_uvs = false;
45 bool uses_uv2s = false;
46
47 Color current_color;
48 Vector3 current_normal;
49 Plane current_tangent;
50 Vector2 current_uv;
51 Vector2 current_uv2;
52
53 LocalVector<Color> colors;
54 LocalVector<Vector3> normals;
55 LocalVector<Plane> tangents;
56 LocalVector<Vector2> uvs;
57 LocalVector<Vector2> uv2s;
58 LocalVector<Vector3> vertices;
59
60 struct Surface {
61 PrimitiveType primitive;
62 Ref<Material> material;
63 bool vertex_2d = false;
64 int array_len = 0;
65 uint64_t format = 0;
66 AABB aabb;
67 };
68
69 LocalVector<Surface> surfaces;
70
71 bool surface_active = false;
72 Surface active_surface_data;
73
74 Vector<uint8_t> surface_vertex_create_cache;
75 Vector<uint8_t> surface_attribute_create_cache;
76
77 const Vector3 SMALL_VEC3 = Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON);
78
79 protected:
80 static void _bind_methods();
81
82 public:
83 void surface_begin(PrimitiveType p_primitive, const Ref<Material> &p_material = Ref<Material>());
84 void surface_set_color(const Color &p_color);
85 void surface_set_normal(const Vector3 &p_normal);
86 void surface_set_tangent(const Plane &p_tangent);
87 void surface_set_uv(const Vector2 &p_uv);
88 void surface_set_uv2(const Vector2 &p_uv2);
89 void surface_add_vertex(const Vector3 &p_vertex);
90 void surface_add_vertex_2d(const Vector2 &p_vertex);
91 void surface_end();
92
93 void clear_surfaces();
94
95 virtual int get_surface_count() const override;
96 virtual int surface_get_array_len(int p_idx) const override;
97 virtual int surface_get_array_index_len(int p_idx) const override;
98 virtual Array surface_get_arrays(int p_surface) const override;
99 virtual TypedArray<Array> surface_get_blend_shape_arrays(int p_surface) const override;
100 virtual Dictionary surface_get_lods(int p_surface) const override;
101 virtual BitField<ArrayFormat> surface_get_format(int p_idx) const override;
102 virtual PrimitiveType surface_get_primitive_type(int p_idx) const override;
103 virtual void surface_set_material(int p_idx, const Ref<Material> &p_material) override;
104 virtual Ref<Material> surface_get_material(int p_idx) const override;
105 virtual int get_blend_shape_count() const override;
106 virtual StringName get_blend_shape_name(int p_index) const override;
107 virtual void set_blend_shape_name(int p_index, const StringName &p_name) override;
108
109 virtual AABB get_aabb() const override;
110
111 virtual RID get_rid() const override;
112
113 ImmediateMesh();
114 ~ImmediateMesh();
115 };