Blender V5.0
obj_export_mesh.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
13#include "BLI_offset_indices.hh"
14#include "BLI_utility_mixins.hh"
15#include "BLI_vector.hh"
16#include "BLI_virtual_array.hh"
17
18#include "DNA_material_types.h"
19#include "DNA_object_types.h"
20
21#include "IO_wavefront_obj.hh"
22
23namespace blender::io::obj {
25const int NOT_FOUND = -1;
27const int NEGATIVE_INIT = -10;
28
30 private:
31 std::string object_name_;
33 const Mesh *export_mesh_;
35 Mesh *owned_export_mesh_ = nullptr;
36 Span<int2> mesh_edges_;
37 OffsetIndices<int> mesh_faces_;
38 Span<int> mesh_corner_verts_;
39 VArray<bool> sharp_faces_;
40
45 float4x4 world_and_axes_transform_;
46 float3x3 world_and_axes_normal_transform_;
47 bool mirrored_transform_;
48
50 Array<int> corner_to_uv_index_;
52 Vector<float2> uv_coords_;
53
55 Array<int> corner_to_normal_index_;
57 Array<float3> normal_coords_;
61 int tot_smooth_groups_ = NEGATIVE_INIT;
65 int *face_smooth_groups_ = nullptr;
69 Array<int> face_order_;
70
71 public:
73
78 OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *mesh_object);
79 ~OBJMesh();
80
81 /* Clear various arrays to release potentially large memory allocations. */
82 void clear();
83
84 int tot_vertices() const;
85 int tot_faces() const;
86 int tot_uv_vertices() const;
87 int tot_edges() const;
88 int tot_deform_groups() const;
90 {
91 return mirrored_transform_;
92 }
93
97 int16_t tot_materials() const;
98
103 void calc_smooth_groups(bool use_bitflags);
107 int ith_smooth_group(int face_index) const;
108 bool is_ith_face_smooth(int face_index) const;
109
118
120 {
121 return world_and_axes_transform_;
122 }
123
127 Span<int> calc_face_vert_indices(const int face_index) const
128 {
129 return mesh_corner_verts_.slice(mesh_faces_[face_index]);
130 }
131
137 /* Get UV coordinates computed by store_uv_coords_and_indices. */
139 {
140 return uv_coords_;
141 }
142 Span<int> get_face_uv_indices(const int face_index) const
143 {
144 if (uv_coords_.is_empty()) {
145 return {};
146 }
147 BLI_assert(face_index < mesh_faces_.size());
148 return corner_to_uv_index_.as_span().slice(mesh_faces_[face_index]);
149 }
150
156 /* Get normals calculate by store_normal_coords_and_indices. */
158 {
159 return normal_coords_;
160 }
161
166 Span<int> get_face_normal_indices(const int face_index) const
167 {
168 if (corner_to_normal_index_.is_empty()) {
169 return {};
170 }
171 const IndexRange face = mesh_faces_[face_index];
172 return corner_to_normal_index_.as_span().slice(face);
173 }
174
184 int16_t get_face_deform_group_index(int face_index, MutableSpan<float> group_weights) const;
189 const char *get_face_deform_group_name(int16_t def_group_index) const;
190
195 void calc_face_order();
196
202 int remap_face_index(int i) const
203 {
204 return i < 0 || i >= face_order_.size() ? i : face_order_[i];
205 }
206
207 const Mesh *get_mesh() const
208 {
209 return export_mesh_;
210 }
211
212 private:
214 void set_mesh(Mesh *mesh);
219 void triangulate_mesh_eval();
223 void set_world_axes_transform(const Object &obj_eval,
224 eIOAxis forward,
225 eIOAxis up,
226 float global_scale,
227 bool apply_transform);
228};
229} // namespace blender::io::obj
#define BLI_assert(a)
Definition BLI_assert.h:46
Object is a sort of wrapper for general info.
eIOAxis
BPy_StructRNA * depsgraph
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:137
constexpr IndexRange slice(int64_t start, int64_t size) const
NonCopyable(const NonCopyable &other)=delete
const char * get_face_deform_group_name(int16_t def_group_index) const
int16_t get_face_deform_group_index(int face_index, MutableSpan< float > group_weights) const
bool is_ith_face_smooth(int face_index) const
void calc_smooth_groups(bool use_bitflags)
StringRef get_object_mesh_name() const
Span< int > get_face_uv_indices(const int face_index) const
int remap_face_index(int i) const
Array< const Material * > materials
Span< float3 > get_normal_coords() const
const float4x4 & get_world_axes_transform() const
StringRef get_object_name() const
Span< int > get_face_normal_indices(const int face_index) const
Span< int > calc_face_vert_indices(const int face_index) const
Span< float2 > get_uv_coords() const
OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *mesh_object)
int ith_smooth_group(int face_index) const
const Mesh * get_mesh() const
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 3 > float3x3
i
Definition text_draw.cc:230