Blender V4.3
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
9#pragma once
10
11#include <optional>
12
15#include "BLI_offset_indices.hh"
16#include "BLI_utility_mixins.hh"
17#include "BLI_vector.hh"
18#include "BLI_virtual_array.hh"
19
20#include "DNA_material_types.h"
21#include "DNA_object_types.h"
22
23#include "IO_wavefront_obj.hh"
24
25namespace blender::io::obj {
27const int NOT_FOUND = -1;
29const int NEGATIVE_INIT = -10;
30
32 private:
33 std::string object_name_;
35 const Mesh *export_mesh_;
37 Mesh *owned_export_mesh_ = nullptr;
38 Span<int2> mesh_edges_;
39 OffsetIndices<int> mesh_faces_;
40 Span<int> mesh_corner_verts_;
41 VArray<bool> sharp_faces_;
42
47 float4x4 world_and_axes_transform_;
48 float3x3 world_and_axes_normal_transform_;
49 bool mirrored_transform_;
50
52 Array<int> corner_to_uv_index_;
54 Vector<float2> uv_coords_;
55
57 Array<int> corner_to_normal_index_;
59 Array<float3> normal_coords_;
63 int tot_smooth_groups_ = NEGATIVE_INIT;
67 int *face_smooth_groups_ = nullptr;
71 Array<int> face_order_;
72
73 public:
75
80 OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *mesh_object);
81 ~OBJMesh();
82
83 /* Clear various arrays to release potentially large memory allocations. */
84 void clear();
85
86 int tot_vertices() const;
87 int tot_faces() const;
88 int tot_uv_vertices() const;
89 int tot_edges() const;
90 int tot_deform_groups() const;
92 {
93 return mirrored_transform_;
94 }
95
99 int16_t tot_materials() const;
100
105 void calc_smooth_groups(bool use_bitflags);
109 int ith_smooth_group(int face_index) const;
110 bool is_ith_face_smooth(int face_index) const;
111
120
122 {
123 return world_and_axes_transform_;
124 }
125
129 Span<int> calc_face_vert_indices(const int face_index) const
130 {
131 return mesh_corner_verts_.slice(mesh_faces_[face_index]);
132 }
133
139 /* Get UV coordinates computed by store_uv_coords_and_indices. */
141 {
142 return uv_coords_;
143 }
144 Span<int> get_face_uv_indices(const int face_index) const
145 {
146 if (uv_coords_.is_empty()) {
147 return {};
148 }
149 BLI_assert(face_index < mesh_faces_.size());
150 return corner_to_uv_index_.as_span().slice(mesh_faces_[face_index]);
151 }
152
158 /* Get normals calculate by store_normal_coords_and_indices. */
160 {
161 return normal_coords_;
162 }
168 Span<int> get_face_normal_indices(const int face_index) const
169 {
170 if (corner_to_normal_index_.is_empty()) {
171 return {};
172 }
173 const IndexRange face = mesh_faces_[face_index];
174 return corner_to_normal_index_.as_span().slice(face);
175 }
176
186 int16_t get_face_deform_group_index(int face_index, MutableSpan<float> group_weights) const;
191 const char *get_face_deform_group_name(int16_t def_group_index) const;
192
197 void calc_face_order();
198
204 int remap_face_index(int i) const
205 {
206 return i < 0 || i >= face_order_.size() ? i : face_order_[i];
207 }
208
209 const Mesh *get_mesh() const
210 {
211 return export_mesh_;
212 }
213
214 private:
216 void set_mesh(Mesh *mesh);
221 void triangulate_mesh_eval();
225 void set_world_axes_transform(const Object &obj_eval,
226 eIOAxis forward,
227 eIOAxis up,
228 float global_scale);
229};
230} // namespace blender::io::obj
#define BLI_assert(a)
Definition BLI_assert.h:50
Object is a sort of wrapper for general info.
eIOAxis
int64_t size() const
Definition BLI_array.hh:245
Span< T > as_span() const
Definition BLI_array.hh:232
bool is_empty() const
Definition BLI_array.hh:253
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:138
bool is_empty() const
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
const Span< float2 > get_uv_coords() const
Span< int > get_face_normal_indices(const int face_index) const
Span< int > calc_face_vert_indices(const int face_index) const
OBJMesh(Depsgraph *depsgraph, const OBJExportParams &export_params, Object *mesh_object)
int ith_smooth_group(int face_index) const
const Mesh * get_mesh() const
const Depsgraph * depsgraph
signed short int16_t
Definition stdint.h:76