41 bm_convert_params.calc_vert_normal =
true;
42 const int triangulation_threshold = force_triangulation ? 4 : 255;
45 BM_mesh_triangulate(bmesh, 0, 3, triangulation_threshold,
false,
nullptr,
nullptr,
nullptr);
54 float r_world_and_axes_transform[4][4],
55 float r_world_and_axes_normal_transform[3][3])
57 float axes_transform[3][3];
61 mul_m4_m3m4(r_world_and_axes_transform, axes_transform,
object.object_to_world().
ptr());
63 mul_v3_m3v3(r_world_and_axes_transform[3], axes_transform,
object.object_to_world().location());
64 r_world_and_axes_transform[3][3] =
object.object_to_world()[3][3];
67 float normal_matrix[3][3];
68 copy_m3_m4(normal_matrix, r_world_and_axes_transform);
69 invert_m3_m3(r_world_and_axes_normal_transform, normal_matrix);
95 bool export_uv =
false;
106 const Span<int> corner_verts = mesh->corner_verts();
107 r_vertex_to_ply.
resize(mesh->verts_num, -1);
108 r_loop_to_ply.
resize(mesh->corners_num, -1);
112 r_ply_to_vertex.
resize(mesh->verts_num);
113 for (
int index = 0; index < mesh->verts_num; index++) {
114 r_vertex_to_ply[index] = index;
115 r_ply_to_vertex[index] = index;
117 for (
int index = 0; index < mesh->corners_num; index++) {
118 r_loop_to_ply[index] = corner_verts[index];
126 vertex_map.
reserve(mesh->verts_num);
127 r_ply_to_vertex.
reserve(mesh->verts_num);
128 r_uvs.
reserve(mesh->verts_num);
130 for (
int loop_index = 0; loop_index <
int(corner_verts.
size()); loop_index++) {
131 int vertex_index = corner_verts[loop_index];
134 r_vertex_to_ply[vertex_index] = ply_index;
135 r_loop_to_ply[loop_index] = ply_index;
136 while (r_uvs.
size() <= ply_index) {
138 r_ply_to_vertex.
append(key.vertex_index);
143 for (
int vertex_index = 0; vertex_index < mesh->verts_num; vertex_index++) {
144 if (r_vertex_to_ply[vertex_index] != -1) {
147 int ply_index =
int(r_uvs.
size());
148 r_vertex_to_ply[vertex_index] = ply_index;
150 r_ply_to_vertex.
append(vertex_index);
161 if (attr.name == name) {
162 BLI_assert(attr.data.size() == vertex_offset);
163 attr.data.resize(attr.data.size() + size, 0.0f);
164 return attr.data.data() + vertex_offset;
169 return r_attributes.
last().data.data() + vertex_offset;
178 const StringRef color_name = mesh->active_color_attribute;
186 ELEM(iter.
name,
"position", color_name, uv_name))
192 if (attribute.is_empty()) {
198 auto typed = attribute.typed<
float>();
200 attr[i] = typed[ply_to_vertex[i]];
206 auto typed = attribute.typed<
int8_t>();
208 attr[i] = typed[ply_to_vertex[i]];
214 auto typed = attribute.typed<
int32_t>();
216 attr[i] = typed[ply_to_vertex[i]];
223 auto typed = attribute.typed<
int2>();
225 int j = ply_to_vertex[i];
226 attr_x[i] = typed[j].x;
227 attr_y[i] = typed[j].y;
234 auto typed = attribute.typed<
float2>();
236 int j = ply_to_vertex[i];
237 attr_x[i] = typed[j].x;
238 attr_y[i] = typed[j].y;
246 auto typed = attribute.typed<
float3>();
248 int j = ply_to_vertex[i];
249 attr_x[i] = typed[j].x;
250 attr_y[i] = typed[j].y;
251 attr_z[i] = typed[j].z;
287 auto typed = attribute.typed<
bool>();
289 attr[i] = typed[ply_to_vertex[i]] ? 1.0f : 0.0f;
300 int j = ply_to_vertex[i];
301 attr_x[i] = typed[j].x;
302 attr_y[i] = typed[j].y;
303 attr_z[i] = typed[j].z;
304 attr_w[i] = typed[j].w;
341 bool force_triangulation =
false;
343 for (
const int i : faces.index_range()) {
344 if (faces[i].
size() > 255) {
345 force_triangulation =
true;
351 bool manually_free_mesh =
false;
354 faces = mesh->faces();
355 manually_free_mesh =
true;
358 Vector<int> ply_to_vertex, vertex_to_ply, loop_to_ply;
362 float world_and_axes_transform[4][4];
363 float world_and_axes_normal_transform[3][3];
367 world_and_axes_transform,
368 world_and_axes_normal_transform);
372 for (
const int corner :
IndexRange(mesh->corners_num)) {
373 int ply_index = loop_to_ply[corner];
379 for (
const int i : faces.index_range()) {
387 for (
int vertex_index : ply_to_vertex) {
388 float3 pos = vert_positions[vertex_index];
407 for (
int vertex_index : ply_to_vertex) {
408 float3 normal = vert_normals[vertex_index];
409 mul_m3_v3(world_and_axes_normal_transform, normal);
417 const StringRef name = mesh->active_color_attribute;
418 if (!name.is_empty()) {
428 for (
int vertex_index : ply_to_vertex) {
446 if (loose_edges.
count > 0) {
448 for (
int i = 0; i < edges.size(); ++i) {
450 plyData.
edges.
append({vertex_to_ply[edges[i][0]], vertex_to_ply[edges[i][1]]});
456 if (manually_free_mesh) {
469 BLI_assert(attr.data.size() <= vertex_offset);
470 attr.data.resize(vertex_offset, 0.0f);
const char * CustomData_get_active_layer_name(const CustomData *data, eCustomDataType type)
void BKE_id_free(Main *bmain, void *idv)
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
BMesh * BKE_mesh_to_bmesh_ex(const Mesh *mesh, const BMeshCreateParams *create_params, const BMeshFromMeshParams *convert_params)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
General operations, lookup, etc. for blender objects.
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
#define BLI_assert_msg(a, msg)
MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
void mul_m3_v3(const float M[3][3], float r[3])
void unit_m3(float m[3][3])
void copy_m3_m4(float m1[3][3], const float m2[4][4])
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void mul_m4_v3(const float M[4][4], float r[3])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void transpose_m3(float R[3][3])
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
bool mat3_from_axis_conversion(int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE float normalize_v3(float n[3])
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_DUPLI
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
#define BASE_SELECTED(v3d, base)
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
void BM_mesh_triangulate(BMesh *bm, const int quad_method, const int ngon_method, const int min_vertices, const bool tag_only, BMOperator *op, BMOpSlot *slot_facemap_out, BMOpSlot *slot_facemap_double_out)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Value & lookup_or_add(const Key &key, const Value &value)
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
constexpr bool is_empty() const
void append(const T &value)
const T & last(const int64_t n=0) const
void resize(const int64_t new_size)
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
void append_n_times(const T &value, const int64_t n)
eCustomDataType data_type
GAttributeReader get() const
const Depsgraph * depsgraph
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
bool attribute_name_is_anonymous(const StringRef name)
static void load_custom_attributes(const Mesh *mesh, const Span< int > ply_to_vertex, uint32_t vertex_offset, Vector< PlyCustomAttribute > &r_attributes)
void load_plydata(PlyData &plyData, Depsgraph *depsgraph, const PLYExportParams &export_params)
static void generate_vertex_map(const Mesh *mesh, const PLYExportParams &export_params, Vector< int > &r_ply_to_vertex, Vector< int > &r_vertex_to_ply, Vector< int > &r_loop_to_ply, Vector< float2 > &r_uvs)
static void set_world_axes_transform(const Object &object, const eIOAxis forward, const eIOAxis up, float r_world_and_axes_transform[4][4], float r_world_and_axes_normal_transform[3][3])
static Mesh * do_triangulation(const Mesh *mesh, bool force_triangulation)
static float * find_or_add_attribute(const StringRef name, int64_t size, uint32_t vertex_offset, Vector< PlyCustomAttribute > &r_attributes)
VecBase< float, 4 > float4
VecBase< float, 2 > float2
uint64_t get_default_hash(const T &v)
unsigned __int64 uint64_t
ePLYVertexColorMode vertex_colors
bool export_triangulated_mesh
bool export_selected_objects
blender::BitVector is_loose_bits
Vector< float3 > vertices
Vector< uint32_t > face_vertices
Vector< float4 > vertex_colors
Vector< float3 > vertex_normals
Vector< std::pair< int, int > > edges
Vector< PlyCustomAttribute > vertex_custom_attr
Vector< float2 > uv_coordinates
Vector< uint32_t > face_sizes
bool operator==(const uv_vertex_key &r) const