43 const int triangulation_threshold = force_triangulation ? 4 : 255;
46 BM_mesh_triangulate(bmesh, 0, 3, triangulation_threshold,
false,
nullptr,
nullptr,
nullptr);
55 float r_world_and_axes_transform[4][4],
56 float r_world_and_axes_normal_transform[3][3])
58 float axes_transform[3][3];
62 mul_m4_m3m4(r_world_and_axes_transform, axes_transform,
object.object_to_world().
ptr());
64 mul_v3_m3v3(r_world_and_axes_transform[3], axes_transform,
object.object_to_world().location());
65 r_world_and_axes_transform[3][3] =
object.object_to_world()[3][3];
68 float normal_matrix[3][3];
69 copy_m3_m4(normal_matrix, r_world_and_axes_transform);
70 invert_m3_m3(r_world_and_axes_normal_transform, normal_matrix);
96 bool export_uv =
false;
107 const Span<int> corner_verts = mesh->corner_verts();
114 for (
int index = 0; index < mesh->
verts_num; index++) {
115 r_vertex_to_ply[index] = index;
116 r_ply_to_vertex[index] = index;
118 for (
int index = 0; index < mesh->
corners_num; index++) {
119 r_loop_to_ply[index] = corner_verts[index];
131 for (
int loop_index = 0; loop_index < int(corner_verts.
size()); loop_index++) {
132 int vertex_index = corner_verts[loop_index];
135 r_vertex_to_ply[vertex_index] = ply_index;
136 r_loop_to_ply[loop_index] = ply_index;
137 while (r_uvs.
size() <= ply_index) {
144 for (
int vertex_index = 0; vertex_index < mesh->
verts_num; vertex_index++) {
145 if (r_vertex_to_ply[vertex_index] != -1) {
148 int ply_index = int(r_uvs.
size());
149 r_vertex_to_ply[vertex_index] = ply_index;
151 r_ply_to_vertex.
append(vertex_index);
157 uint32_t vertex_offset,
162 if (attr.name ==
name) {
163 BLI_assert(attr.data.size() == vertex_offset);
164 attr.data.resize(attr.data.size() +
size, 0.0f);
165 return attr.data.data() + vertex_offset;
170 return r_attributes.
last().data.data() + vertex_offset;
175 uint32_t vertex_offset,
187 ELEM(iter.
name,
"position", color_name, uv_name))
199 auto typed = attribute.
typed<
float>();
201 attr[
i] = typed[ply_to_vertex[
i]];
207 auto typed = attribute.
typed<int8_t>();
209 attr[
i] = typed[ply_to_vertex[
i]];
217 attr[
i] = typed[ply_to_vertex[
i]];
226 int j = ply_to_vertex[
i];
227 attr_x[
i] = typed[j].x;
228 attr_y[
i] = typed[j].y;
237 int j = ply_to_vertex[
i];
238 attr_x[
i] = typed[j].x;
239 attr_y[
i] = typed[j].y;
248 int j = ply_to_vertex[
i];
249 attr_x[
i] = typed[j].x;
250 attr_y[
i] = typed[j].y;
260 int j = ply_to_vertex[
i];
261 attr_x[
i] = typed[j].x;
262 attr_y[
i] = typed[j].y;
263 attr_z[
i] = typed[j].z;
299 auto typed = attribute.
typed<
bool>();
301 attr[
i] = typed[ply_to_vertex[
i]] ? 1.0f : 0.0f;
312 int j = ply_to_vertex[
i];
313 attr_x[
i] = typed[j].x;
314 attr_y[
i] = typed[j].y;
315 attr_z[
i] = typed[j].z;
316 attr_w[
i] = typed[j].w;
335 uint32_t vertex_offset = 0;
353 bool force_triangulation =
false;
355 for (
const int i :
faces.index_range()) {
357 force_triangulation =
true;
363 Mesh *manually_free_mesh =
nullptr;
366 mesh = manually_free_mesh;
367 faces = mesh->faces();
370 Vector<int> ply_to_vertex, vertex_to_ply, loop_to_ply;
374 float world_and_axes_transform[4][4];
375 float world_and_axes_normal_transform[3][3];
379 world_and_axes_transform,
380 world_and_axes_normal_transform);
385 int ply_index = loop_to_ply[corner];
391 for (
const int i :
faces.index_range()) {
399 for (
int vertex_index : ply_to_vertex) {
400 float3 pos = vert_positions[vertex_index];
419 for (
int vertex_index : ply_to_vertex) {
420 float3 normal = vert_normals[vertex_index];
421 mul_m3_v3(world_and_axes_normal_transform, normal);
430 if (!
name.is_empty()) {
440 for (
int vertex_index : ply_to_vertex) {
458 if (loose_edges.
count > 0) {
460 for (
int i = 0;
i < edges.
size(); ++
i) {
462 plyData.
edges.
append({vertex_to_ply[edges[
i][0]], vertex_to_ply[edges[
i][1]]});
467 vertex_offset = int(plyData.
vertices.size());
468 if (manually_free_mesh) {
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.
const Mesh * BKE_object_get_pre_modified_mesh(const Object *object)
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
#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
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ 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)
BPy_StructRNA * depsgraph
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void append(const T &value)
void resize(const int64_t new_size)
void append_unchecked(const T &value)
void reserve(const int64_t min_capacity)
constexpr int64_t size() const
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 reserve(const int64_t min_capacity)
void append_n_times(const T &value, const int64_t n)
GAttributeReader lookup_or_default(StringRef attribute_id, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader lookup(const StringRef attribute_id) const
GAttributeReader get() const
bool attribute_name_is_anonymous(const StringRef name)
BLI_INLINE ColorSceneLinear4f< Alpha > decode(const ColorSceneLinearByteEncoded4b< Alpha > &color)
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)
QuaternionBase< float > Quaternion
VecBase< float, 4 > float4
uint64_t get_default_hash(const T &v, const Args &...args)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
blender::VecBase< int16_t, 2 > short2
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
char * active_color_attribute
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