45 const int triangulation_threshold = force_triangulation ? 4 : 255;
48 BM_mesh_triangulate(bmesh, 0, 3, triangulation_threshold,
false,
nullptr,
nullptr,
nullptr);
57 float r_world_and_axes_transform[4][4],
58 float r_world_and_axes_normal_transform[3][3])
60 float axes_transform[3][3];
64 mul_m4_m3m4(r_world_and_axes_transform, axes_transform,
object.object_to_world().ptr());
66 mul_v3_m3v3(r_world_and_axes_transform[3], axes_transform,
object.object_to_world().location());
67 r_world_and_axes_transform[3][3] =
object.object_to_world()[3][3];
70 float normal_matrix[3][3];
71 copy_m3_m4(normal_matrix, r_world_and_axes_transform);
72 invert_m3_m3(r_world_and_axes_normal_transform, normal_matrix);
98 bool export_uv =
false;
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);
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;
187 ELEM(iter.
name,
"position", color_name, uv_name))
201 attr[i] = typed[ply_to_vertex[i]];
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;
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;
355 bool force_triangulation =
false;
358 if (faces[i].size() > 255) {
359 force_triangulation =
true;
365 Mesh *manually_free_mesh =
nullptr;
368 mesh = manually_free_mesh;
369 faces =
mesh->faces();
372 Vector<int> ply_to_vertex, vertex_to_ply, loop_to_ply;
376 float world_and_axes_transform[4][4];
377 float world_and_axes_normal_transform[3][3];
381 world_and_axes_transform,
382 world_and_axes_normal_transform);
387 int ply_index = loop_to_ply[corner];
389 plyData.
face_vertices.append_unchecked(ply_index + vertex_offset);
401 for (
int vertex_index : ply_to_vertex) {
402 float3 pos = vert_positions[vertex_index];
403 mul_m4_v3(world_and_axes_transform, pos);
405 plyData.
vertices.append_unchecked(pos);
421 for (
int vertex_index : ply_to_vertex) {
422 float3 normal = vert_normals[vertex_index];
423 mul_m3_v3(world_and_axes_normal_transform, normal);
442 for (
int vertex_index : ply_to_vertex) {
460 mesh->loose_edges().foreach_index([&](
const int i) {
461 plyData.
edges.append({vertex_to_ply[edges[i][0]], vertex_to_ply[edges[i][1]]});
464 vertex_offset = int(plyData.
vertices.size());
465 if (manually_free_mesh) {
#define DEG_OBJECT_ITER_BEGIN(settings_, instance_)
#define DEG_OBJECT_ITER_END
Object is a sort of wrapper for general info.
#define BLI_assert_msg(a, msg)
constexpr int64_t size() const
constexpr IndexRange()=default
Value & lookup_or_add(const Key &key, const Value &value)
constexpr int64_t size() const
constexpr IndexRange index_range() const
void append(const T &value)
const T & last(const int64_t n=0) const
void resize(const int64_t new_size)
MutableSpan< T > as_mutable_span()
void reserve(const int64_t min_capacity)
void append_n_times(const T &value, const int64_t n)
GAttributeReader lookup_or_default(StringRef name, 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 name) const
GAttributeReader get() const
constexpr bool is_empty() const
constexpr bool is_empty() const
IndexRange index_range() const
void fill_index_range(MutableSpan< T > span, const T start=0)
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)
const Mesh * mesh_coerce_for_export_setup(MeshCoerceForExport &coerce, Depsgraph *depsgraph, Object *obj_eval, const bool apply_modifiers)
QuaternionBase< float > Quaternion
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void mul_m3_v3(const float M[3][3], float r[3])
unsigned __int64 uint64_t
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
void copy_m3_m4(float m1[3][3], const float m2[4][4])
MINLINE void linearrgb_to_srgb_v4(float srgb[4], const float linear[4])
bool invert_m3_m3(float inverse[3][3], const float mat[3][3])
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
MINLINE void mul_v3_fl(float r[3], float f)
VecBase< float, 4 > float4
void mul_m4_v3(const float M[4][4], float r[3])
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
BMesh * BKE_mesh_to_bmesh_ex(const Mesh *mesh, const BMeshCreateParams *create_params, const BMeshFromMeshParams *convert_params)
void transpose_m3(float R[3][3])
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET
@ DEG_ITER_OBJECT_FLAG_VISIBLE
@ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY
@ DEG_ITER_OBJECT_FLAG_DUPLI
bool mat3_from_axis_conversion(int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
void BKE_id_free(Main *bmain, void *idv)
MINLINE float normalize_v3(float n[3])
void unit_m3(float m[3][3])
VecBase< int16_t, 2 > short2
Mesh * BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra, const Mesh *me_settings)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
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)
VecBase< float, 3 > float3
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
bool export_selected_objects
ePLYVertexColorMode vertex_colors
bool export_triangulated_mesh
PlyCustomAttribute(const StringRef name_, int64_t size)
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
void reserve(int new_size)
void resize(int new_size)