Blender V5.3
fbx_import_mesh.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_attribute.h"
10#include "BKE_attribute.hh"
11#include "BKE_deform.hh"
12#include "BKE_key.hh"
13#include "BKE_lib_id.hh"
14#include "BKE_material.hh"
15#include "BKE_mesh.hh"
16#include "BKE_modifier.hh"
17#include "BKE_object.hh"
18#include "BKE_object_deform.h"
19
20#include "BLI_color_types.hh"
21#include "BLI_listbase.hh"
22#include "BLI_math_color_c.hh"
23#include "BLI_string.hh"
24#include "BLI_string_utf8.hh"
25#include "BLI_task.hh"
26#include "BLI_vector_set.hh"
27
28#include "BLT_translation.hh"
29
30#include "DNA_key_types.h"
31#include "DNA_meshdata_types.h"
32#include "DNA_object_types.h"
33
34#include "IO_fbx.hh"
35#include "IO_validate.hh"
36
37#include "fbx_import_mesh.hh"
38
39#include "CLG_log.h"
40
41namespace blender::io::fbx {
42
43static CLG_LogRef LOG = {"io.fbx"};
44
45static constexpr const char *temp_custom_normals_name = "fbx_temp_custom_normals";
46
47static bool is_skin_deformer_usable(const ufbx_mesh *mesh, const ufbx_skin_deformer *skin)
48{
49 return mesh != nullptr && skin != nullptr && skin->clusters.count > 0 &&
50 mesh->num_vertices > 0 && skin->vertices.count == mesh->num_vertices;
51}
52
53static void import_vertex_positions(const ufbx_mesh *fmesh, Mesh *mesh)
54{
55 MutableSpan<float3> positions = mesh->vert_positions_for_write();
56#if 0 // @TODO: "bake" skinned meshes
57 if (skin != nullptr) {
58 /* For a skinned mesh, transform the vertices into bind pose position, in local space. */
59 const ufbx_matrix &geom_to_world = fmesh->instances[0]->geometry_to_world;
60 ufbx_matrix world_to_geom = ufbx_matrix_invert(&geom_to_world);
61 for (size_t i = 0; i < fmesh->vertex_position.values.count; i++) {
62 ufbx_matrix skin_mat = ufbx_get_skin_vertex_matrix(skin, i, &geom_to_world);
63 skin_mat = ufbx_matrix_mul(&world_to_geom, &skin_mat);
64 ufbx_vec3 val = ufbx_transform_position(&skin_mat, fmesh->vertex_position.values[i]);
65 positions[i] = float3(val.x, val.y, val.z);
66 //@TODO: skin normals
67 }
68 return;
69 }
70#endif
71
72 BLI_assert(positions.size() == fmesh->vertex_position.values.count);
73 for (const int64_t i : positions.index_range()) {
74 ufbx_vec3 val = fmesh->vertex_position.values[i];
75 positions[i] = float3(val.x, val.y, val.z);
76 }
77}
78
79static void import_faces(const ufbx_mesh *fmesh, Mesh *mesh)
80{
81 MutableSpan<int> face_offsets = mesh->face_offsets_for_write();
82 MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
83 BLI_assert((face_offsets.size() == fmesh->num_faces + 1) ||
84 (face_offsets.is_empty() && fmesh->num_faces == 0));
85 for (size_t face_idx = 0; face_idx < fmesh->num_faces; face_idx++) {
86 //@TODO: skip < 3 vertex faces?
87 const ufbx_face &fface = fmesh->faces[face_idx];
88 face_offsets[face_idx] = fface.index_begin;
89 for (uint32_t i = 0; i < fface.num_indices; i++) {
90 const uint32_t corner_idx = fface.index_begin + i;
91 corner_verts[corner_idx] = fmesh->vertex_indices[corner_idx];
92 }
93 }
94}
95
96static void import_face_material_indices(const ufbx_mesh *fmesh,
98{
99 if (fmesh->face_material.count == fmesh->num_faces) {
101 "material_index", bke::AttrDomain::Face);
102 for (const int64_t i : materials.span.index_range()) {
103 materials.span[i] = fmesh->face_material[i];
104 }
105 materials.finish();
106 }
107}
108
109static void import_face_smoothing(const ufbx_mesh *fmesh,
111{
112 if (fmesh->face_smoothing.count > 0 && fmesh->face_smoothing.count == fmesh->num_faces) {
114 "sharp_face", bke::AttrDomain::Face);
115 for (const int64_t i : smooth.span.index_range()) {
116 smooth.span[i] = !fmesh->face_smoothing[i];
117 }
118 smooth.finish();
119 }
120}
121
122static void import_edges(const ufbx_mesh *fmesh,
123 Mesh *mesh,
125{
126 MutableSpan<int2> edges = mesh->edges_for_write();
127 BLI_assert(edges.size() == fmesh->num_edges);
128 for (size_t i = 0; i < fmesh->num_edges; i++) {
129 const ufbx_edge &fedge = fmesh->edges[i];
130 const int va = fmesh->vertex_indices[fedge.a];
131 const int vb = fmesh->vertex_indices[fedge.b];
132 edges[i] = int2(va, vb);
133 }
134
135 /* Edge attributes are written here in the same order as the FBX edges. Mesh validation
136 * preserves edge attributes when removing degenerate edges or computing missing ones. */
137 if (fmesh->edge_crease.count > 0 && fmesh->edge_crease.count == fmesh->num_edges) {
139 "crease_edge", bke::AttrDomain::Edge);
140 for (int64_t i = 0; i < fmesh->num_edges; i++) {
141 /* Python fbx importer was squaring the incoming crease values. */
142 creases.span[i] = sqrtf(fmesh->edge_crease[i]);
143 }
144 creases.finish();
145 }
146
147 if (fmesh->edge_smoothing.count > 0 && fmesh->edge_smoothing.count == fmesh->num_edges) {
149 "sharp_edge", bke::AttrDomain::Edge);
150 for (int64_t i = 0; i < fmesh->num_edges; i++) {
151 sharp.span[i] = !fmesh->edge_smoothing[i];
152 }
153 sharp.finish();
154 }
155}
156
157static void import_uvs(const ufbx_mesh *fmesh,
158 Mesh *mesh,
160 AttributeOwner attr_owner)
161{
162 bool set_active_uv = true;
163 for (const ufbx_uv_set &fuv_set : fmesh->uv_sets) {
164 std::string attr_name = BKE_attribute_calc_unique_name(attr_owner, fuv_set.name.data);
165 if (set_active_uv) {
166 mesh->uv_maps_active_set(attr_name);
167 mesh->uv_maps_default_set(attr_name);
168 set_active_uv = false;
169 }
171 attr_name, bke::AttrDomain::Corner);
172 BLI_assert(fuv_set.vertex_uv.indices.count == uvs.span.size());
173 for (const int64_t i : uvs.span.index_range()) {
174 const int val_idx = fuv_set.vertex_uv.indices[i];
175 const ufbx_vec2 &uv = fuv_set.vertex_uv.values[val_idx];
176 uvs.span[i] = float2(uv.x, uv.y);
177 }
178 uvs.finish();
179 }
180}
181
182static void import_colors(const ufbx_mesh *fmesh,
183 Mesh *mesh,
185 AttributeOwner attr_owner,
186 eFBXVertexColorMode color_mode)
187{
188 std::string first_color_name;
189 for (const ufbx_color_set &fcol_set : fmesh->color_sets) {
190 std::string attr_name = BKE_attribute_calc_unique_name(attr_owner, fcol_set.name.data);
191 if (first_color_name.empty()) {
192 first_color_name = attr_name;
193 }
194 if (color_mode == eFBXVertexColorMode::sRGB) {
195 /* sRGB colors, use 4 bytes per color. */
199 BLI_assert(fcol_set.vertex_color.indices.count == cols.span.size());
200 for (const int64_t i : cols.span.index_range()) {
201 const int val_idx = fcol_set.vertex_color.indices[i];
202 const ufbx_vec4 &col = fcol_set.vertex_color.values[val_idx];
203 /* Note: color values are expected to already be in sRGB space. */
204 float4 fcol = float4(col.x, col.y, col.z, col.w);
205 uchar4 bcol;
206 rgba_float_to_uchar(bcol, fcol);
207 cols.span[i] = ColorGeometry4b(bcol);
208 }
209 cols.finish();
210 }
211 else if (color_mode == eFBXVertexColorMode::Linear) {
212 /* Linear colors, use 4 floats per color. */
216 BLI_assert(fcol_set.vertex_color.indices.count == cols.span.size());
217 for (const int64_t i : cols.span.index_range()) {
218 const int val_idx = fcol_set.vertex_color.indices[i];
219 const ufbx_vec4 &col = fcol_set.vertex_color.values[val_idx];
220 cols.span[i] = ColorGeometry4f(col.x, col.y, col.z, col.w);
221 }
222 cols.finish();
223 }
224 else {
226 }
227 }
228 if (!first_color_name.empty()) {
229 mesh->active_color_attribute = BLI_strdup(first_color_name.c_str());
230 mesh->default_color_attribute = BLI_strdup(first_color_name.c_str());
231 }
232}
233
234static bool import_normals_into_temp_attribute(const ufbx_mesh *fmesh,
236{
237 if (!fmesh->vertex_normal.exists) {
238 return false;
239 }
242 BLI_assert(fmesh->vertex_normal.indices.count == normals.span.size());
243 for (const int64_t i : normals.span.index_range()) {
244 const int val_idx = fmesh->vertex_normal.indices[i];
245 const ufbx_vec3 &normal = fmesh->vertex_normal.values[val_idx];
246 normals.span[i] = float3(normal.x, normal.y, normal.z);
247 }
248 normals.finish();
249 return true;
250}
251
253 const ufbx_mesh *fmesh)
254{
255 VectorSet<std::string> name_set;
256 for (const ufbx_skin_deformer *skin : fmesh->skin_deformers) {
257 if (!is_skin_deformer_usable(fmesh, skin)) {
258 continue;
259 }
260
261 for (const ufbx_skin_cluster *cluster : skin->clusters) {
262 if (cluster->num_weights == 0) {
263 continue;
264 }
265
266 std::string bone_name = mapping.node_to_name.lookup_default(cluster->bone_node, "");
267 name_set.add(bone_name);
268 }
269 }
270 return name_set;
271}
272
274 const ufbx_mesh *fmesh,
275 Mesh *mesh)
276{
277 if (fmesh->skin_deformers.count == 0) {
278 return;
279 }
280
281 /* A single mesh can be skinned by several armatures, so we need to build bone (vertex group)
282 * name set, taking all skin deformers into account. */
283 VectorSet<std::string> bone_set = get_skin_bone_name_set(mapping, fmesh);
284 if (bone_set.is_empty()) {
285 return;
286 }
287
288 MutableSpan<MDeformVert> dverts = mesh->deform_verts_for_write();
289
290 for (const ufbx_skin_deformer *skin : fmesh->skin_deformers) {
291 if (!is_skin_deformer_usable(fmesh, skin)) {
292 continue;
293 }
294
295 for (const ufbx_skin_cluster *cluster : skin->clusters) {
296 if (cluster->num_weights == 0) {
297 continue;
298 }
299 std::string bone_name = mapping.node_to_name.lookup_default(cluster->bone_node, "");
300 const int group_index = bone_set.index_of_try(bone_name);
301 if (group_index < 0) {
302 continue;
303 }
304
305 for (int64_t i = 0; i < cluster->num_weights; i++) {
306 const int vertex = cluster->vertices[i];
307 if (validate::index_in_range(vertex, dverts.size())) {
308 MDeformWeight *dw = BKE_defvert_ensure_index(&dverts[vertex], group_index);
309 dw->weight = cluster->weights[i];
310 }
311 }
312 }
313 }
314}
315
316static bool import_blend_shapes(Main &bmain,
317 FbxElementMapping &mapping,
318 const ufbx_mesh *fmesh,
319 Mesh *mesh)
320{
321 Key *mesh_key = nullptr;
322 for (const ufbx_blend_deformer *fdeformer : fmesh->blend_deformers) {
323 for (const ufbx_blend_channel *fchan : fdeformer->channels) {
324 /* In theory fbx supports multiple keyframes within one blend shape
325 * channel; we only take the final target keyframe. */
326 if (fchan->target_shape == nullptr) {
327 continue;
328 }
329
330 if (mesh_key == nullptr) {
331 mesh_key = BKE_key_add(&bmain, &mesh->id);
332 mesh_key->type = KEY_RELATIVE;
333 mesh->key = mesh_key;
334
335 KeyBlock *kb = BKE_keyblock_add(mesh_key, nullptr);
337 }
338
339 KeyBlock *kb = BKE_keyblock_add(mesh_key, fchan->target_shape->name.data);
340 kb->curval = fchan->weight;
342 if (!kb->data) {
343 /* Nothing to do. This can happen if the mesh has no vertices. */
344 continue;
345 }
346 float3 *kb_data = static_cast<float3 *>(kb->data);
347 for (size_t i = 0; i < fchan->target_shape->num_offsets; i++) {
348 const int idx = fchan->target_shape->offset_vertices[i];
349 if (!validate::index_in_range(idx, mesh->verts_num)) {
350 continue;
351 }
352 const ufbx_vec3 &delta = fchan->target_shape->position_offsets[i];
353 kb_data[idx] += float3(delta.x, delta.y, delta.z);
354 }
355 mapping.el_to_shape_key.add(&fchan->element, mesh_key);
356 }
357 }
358 return mesh_key != nullptr;
359}
360
361/* Handle Blender-specific "FullWeights" that for each blend shape also create
362 * a weighted vertex group for itself. */
364 const ufbx_mesh *fmesh,
365 Mesh *mesh,
366 Object *obj)
367{
368 for (const ufbx_blend_deformer *fdeformer : fmesh->blend_deformers) {
369 for (const ufbx_blend_channel *fchan : fdeformer->channels) {
370 Key *key = mapping.el_to_shape_key.lookup_default(&fchan->element, nullptr);
371 if (fchan->target_shape == nullptr || key == nullptr) {
372 continue;
373 }
374 if (fchan->target_shape->offset_weights.count != fchan->target_shape->num_offsets) {
375 continue;
376 }
377
378 KeyBlock *kb = BKE_keyblock_find_name(key, fchan->target_shape->name.data);
379 if (kb == nullptr) {
380 continue;
381 }
382
383 /* Ignore cases where all weights are 1.0 (group has no effect),
384 * and cases where any weights are outside of 0..1 range (apparently some files have
385 * invalid negative weights and should be ignored). */
386 bool all_one = true;
387 bool all_unorm = true;
388 for (ufbx_real w : fchan->target_shape->offset_weights) {
389 if (w != 1.0) {
390 all_one = false;
391 }
392 if (w < 0.0 || w > 1.0) {
393 all_unorm = false;
394 }
395 }
396 if (all_one || !all_unorm) {
397 continue;
398 }
399
400 int group_index = BKE_defgroup_name_index(&mesh->vertex_group_names, kb->name);
401 if (group_index < 0) {
403 group_index = BKE_defgroup_name_index(&mesh->vertex_group_names, kb->name);
404 if (group_index < 0) {
405 continue;
406 }
407 }
408
409 MutableSpan<MDeformVert> dverts = mesh->deform_verts_for_write();
410 for (size_t i = 0; i < fchan->target_shape->num_offsets; i++) {
411 const int idx = fchan->target_shape->offset_vertices[i];
412 if (validate::index_in_range(idx, dverts.size())) {
413 const float w = fchan->target_shape->offset_weights[i];
414 MDeformWeight *dw = BKE_defvert_ensure_index(&dverts[idx], group_index);
415 dw->weight = w;
416 }
417 }
418
419 STRNCPY_UTF8(kb->vgroup, kb->name);
420 }
421 }
422}
423
424void import_meshes(Main &bmain,
425 const ufbx_scene &fbx,
426 FbxElementMapping &mapping,
427 const FBXImportParams &params)
428{
429 /* Create Mesh objects outside of Main, in parallel. */
430 Vector<Mesh *> meshes(fbx.meshes.count);
431 threading::parallel_for_each(IndexRange(fbx.meshes.count), [&](const int64_t index) {
432 const ufbx_mesh *fmesh = fbx.meshes.data[index];
433 if (fmesh->instances.count == 0) {
434 meshes[index] = nullptr; /* Ignore if not used by any objects. */
435 return;
436 }
437
438 if (!validate::size_fits_in_int(fmesh->num_vertices) ||
439 !validate::size_fits_in_int(fmesh->num_edges) ||
440 !validate::size_fits_in_int(fmesh->num_faces) ||
441 !validate::size_fits_in_int(fmesh->num_indices))
442 {
443 CLOG_WARN(&LOG, "Mesh '%s' too large to import, exceeds max int size", fmesh->name.data);
444 meshes[index] = nullptr;
445 return;
446 }
447
448 /* Create Mesh outside of main. */
450 fmesh->num_vertices, fmesh->num_edges, fmesh->num_faces, fmesh->num_indices);
451 bke::MutableAttributeAccessor attributes = mesh->attributes_for_write();
453
455 import_faces(fmesh, mesh);
456 import_face_material_indices(fmesh, attributes);
457 import_face_smoothing(fmesh, attributes);
458 import_edges(fmesh, mesh, attributes);
459 import_uvs(fmesh, mesh, attributes, attr_owner);
461 import_colors(fmesh, mesh, attributes, attr_owner, params.vertex_colors);
462 }
463 bool has_custom_normals = false;
464 if (params.use_custom_normals) {
465 /* Mesh validation below can alter the mesh, so we first write custom normals
466 * into a temporary custom corner domain attribute, and then re-apply that
467 * data as custom normals after the validation. */
468 has_custom_normals = import_normals_into_temp_attribute(fmesh, attributes);
469 }
470 import_skin_vertex_groups(mapping, fmesh, mesh);
471
472 /* Add vertex groups to the object. */
473 VectorSet<std::string> bone_set = get_skin_bone_name_set(mapping, fmesh);
474 for (const std::string &name : bone_set) {
475 bDeformGroup *defgroup = MEM_new<bDeformGroup>("bDeformGroup");
476 StringRef(name).copy_utf8_truncated(defgroup->name);
477 BLI_addtail(&mesh->vertex_group_names, defgroup);
478 }
479
480 /* FBX files may not contain all edges, so missing edges must be added here.
481 * Validation will do this, and otherwise calculate them explicitly. */
482 if (params.validate_meshes) {
483 const bool allow_missing_edges = true;
484#ifndef NDEBUG
485 const bool verbose_validate = true;
486#else
487 const bool verbose_validate = false;
488#endif
489 bke::mesh_validate(*mesh, verbose_validate, allow_missing_edges);
490 }
491 else {
492 bke::mesh_calc_edges(*mesh, true, false);
493 }
494
495 if (has_custom_normals) {
496 /* Actually set custom normals after the validation. */
498 attributes.lookup_or_add_for_write_only_span<float3>(temp_custom_normals_name,
501 normals.finish();
502 attributes.remove(temp_custom_normals_name);
503 }
504
505 meshes[index] = mesh;
506 });
507
508 /* Create final mesh objects in Main, serially. And do steps that need to be done on the final
509 * objects. */
510 for (int64_t index : meshes.index_range()) {
511 Mesh *mesh = meshes[index];
512 if (mesh == nullptr) {
513 continue;
514 }
515 const ufbx_mesh *fmesh = fbx.meshes[index];
516 BLI_assert(fmesh != nullptr);
517
518 Mesh *mesh_main = static_cast<Mesh *>(
519 BKE_object_obdata_add_from_type(&bmain, OB_MESH, get_fbx_name(fmesh->name, "Mesh")));
520 BKE_mesh_nomain_to_mesh(mesh, mesh_main, nullptr);
521 meshes[index] = mesh_main;
522 mesh = mesh_main;
523 if (params.use_custom_props) {
524 read_custom_properties(fmesh->props, mesh->id, params.props_enum_as_string);
525 }
526
527 const bool any_shapes = import_blend_shapes(bmain, mapping, fmesh, mesh);
528
529 /* Create objects that use this mesh. */
530 for (const ufbx_node *node : fmesh->instances) {
531 std::string name;
532 if (node->is_geometry_transform_helper) {
533 /* Name geometry transform adjustment helpers with parent name and _GeomAdjust suffix. */
534 name = get_fbx_name(node->parent->name) + std::string("_GeomAdjust");
535 }
536 else {
537 name = get_fbx_name(node->name);
538 }
539 Object *obj = BKE_object_add_only_object(&bmain, OB_MESH, name.c_str());
540 obj->data = id_cast<ID *>(mesh_main);
541 if (!node->visible) {
542 obj->visibility_flag |= OB_HIDE_VIEWPORT;
543 }
544
545 if (any_shapes) {
546 obj->shapenr = 1;
547 }
548
549 bool matrix_already_set = false;
550
551 /* Skinned mesh. */
552 if (fmesh->skin_deformers.count > 0) {
553 /* Add armature modifiers for each skin deformer. */
554 for (const ufbx_skin_deformer *skin : fmesh->skin_deformers) {
555 if (!is_skin_deformer_usable(fmesh, skin)) {
556 continue;
557 }
558 Object *arm_obj = nullptr;
559 for (const ufbx_skin_cluster *cluster : skin->clusters) {
560 if (cluster->num_weights == 0) {
561 continue;
562 }
563 arm_obj = mapping.bone_to_armature.lookup_default(cluster->bone_node, nullptr);
564 if (arm_obj != nullptr) {
565 break;
566 }
567 }
568 /* Add armature modifier. */
569 if (arm_obj != nullptr) {
570 ModifierData *md = BKE_modifier_new(eModifierType_Armature);
571 STRNCPY_UTF8(md->name, BKE_id_name(arm_obj->id));
572 BLI_addtail(&obj->modifiers, md);
574 ArmatureModifierData *ad = reinterpret_cast<ArmatureModifierData *>(md);
575 ad->object = arm_obj;
576
577 if (!matrix_already_set) {
578 matrix_already_set = true;
579 obj->parent = arm_obj;
580
581 /* We are setting mesh parent to the armature, so set the matrix that is
582 * armature-local. Note that the matrix needs to be relative to the FBX
583 * node matrix (not the root bone pose matrix). */
584 ufbx_matrix world_to_arm = mapping.armature_world_to_arm_node_matrix.lookup_default(
585 arm_obj, ufbx_identity_matrix);
586 ufbx_matrix world_to_arm_pose = mapping.armature_world_to_arm_pose_matrix
587 .lookup_default(arm_obj, ufbx_identity_matrix);
588
589 ufbx_matrix mtx = ufbx_matrix_mul(&world_to_arm, &node->geometry_to_world);
590 ufbx_matrix_to_obj(mtx, obj);
591
592 /* Setup parent inverse matrix of the mesh, to account for the mesh possibly being in
593 * different bind pose than what the node is at. */
594 ufbx_matrix mtx_inv = ufbx_matrix_invert(&mtx);
595 ufbx_matrix mtx_world = mapping.get_node_bind_matrix(node);
596 ufbx_matrix mtx_parent_inverse = ufbx_matrix_mul(&mtx_world, &mtx_inv);
597 mtx_parent_inverse = ufbx_matrix_mul(&world_to_arm_pose, &mtx_parent_inverse);
598 matrix_to_m44(mtx_parent_inverse, obj->parentinv);
599 }
600 }
601 }
602 }
603
604 if (any_shapes) {
605 import_blend_shape_full_weights(mapping, fmesh, mesh, obj);
606 }
607
608 /* Assign materials. */
609 if (fmesh->materials.count > 0 && node->materials.count == fmesh->materials.count) {
610 int mat_index = 0;
611 for (size_t mi = 0; mi < fmesh->materials.count; mi++) {
612 const ufbx_material *mesh_fmat = fmesh->materials[mi];
613 const ufbx_material *node_fmat = node->materials[mi];
614 Material *mesh_mat = mapping.mat_to_material.lookup_default(mesh_fmat, nullptr);
615 Material *node_mat = mapping.mat_to_material.lookup_default(node_fmat, nullptr);
616 if (mesh_mat != nullptr) {
617 mat_index++;
618 /* Assign material to the data block. */
619 BKE_object_material_assign_single_obdata(&bmain, obj, mesh_mat, mat_index);
620
621 /* If object material is different, assign that to object. */
622 if (!ELEM(node_mat, nullptr, mesh_mat)) {
623 BKE_object_material_assign(&bmain, obj, node_mat, mat_index, BKE_MAT_ASSIGN_OBJECT);
624 }
625 }
626 }
627 if (mat_index > 0) {
628 obj->actcol = 1;
629 }
630 }
631
632 /* Subdivision. */
633 if (params.import_subdivision &&
634 fmesh->subdivision_display_mode != UFBX_SUBDIVISION_DISPLAY_DISABLED &&
635 (fmesh->subdivision_preview_levels > 0 || fmesh->subdivision_render_levels > 0))
636 {
637 ModifierData *md = BKE_modifier_new(eModifierType_Subsurf);
638 BLI_addtail(&obj->modifiers, md);
640
641 SubsurfModifierData *ssd = reinterpret_cast<SubsurfModifierData *>(md);
642 ssd->subdivType = SUBSURF_TYPE_CATMULL_CLARK;
643 ssd->levels = fmesh->subdivision_preview_levels;
644 ssd->renderLevels = fmesh->subdivision_render_levels;
645 ssd->boundary_smooth = fmesh->subdivision_boundary ==
646 UFBX_SUBDIVISION_BOUNDARY_SHARP_CORNERS ?
649 }
650
651 if (params.use_custom_props) {
652 read_custom_properties(node->props, obj->id, params.props_enum_as_string);
653 }
654 if (!matrix_already_set) {
655 node_matrix_to_obj(node, obj, mapping);
656 }
657 mapping.el_to_object.add(&node->element, obj);
658 mapping.imported_objects.add(obj);
659 }
660 }
661}
662
663} // namespace blender::io::fbx
Generic geometry attributes built on CustomData.
support for deformation groups and hooks.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
Functions for dealing with objects and deform verts, used by painting and tools.
#define STRNCPY_UTF8(dst, src)
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
#define ELEM(...)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
static AttributeOwner from_id(ID *id)
constexpr IndexRange()=default
Value lookup_default(const Key &key, const Value &default_value) const
Definition BLI_map.hh:570
constexpr int64_t size() const
Definition BLI_span.hh:499
constexpr bool is_empty() const
Definition BLI_span.hh:515
constexpr IndexRange index_range() const
Definition BLI_span.hh:676
constexpr StringRef()
int64_t index_of_try(const Key &key) const
bool add(const Key &key)
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
#define vertex
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
bool mesh_validate(Mesh &mesh, bool verbose=false, bool allow_missing_edges=false)
void mesh_set_custom_normals(Mesh &mesh, MutableSpan< float3 > corner_normals)
static VectorSet< std::string > get_skin_bone_name_set(const FbxElementMapping &mapping, const ufbx_mesh *fmesh)
void ufbx_matrix_to_obj(const ufbx_matrix &mtx, Object *obj)
static void import_blend_shape_full_weights(const FbxElementMapping &mapping, const ufbx_mesh *fmesh, Mesh *mesh, Object *obj)
static void import_colors(const ufbx_mesh *fmesh, Mesh *mesh, bke::MutableAttributeAccessor &attributes, AttributeOwner attr_owner, eFBXVertexColorMode color_mode)
const char * get_fbx_name(const ufbx_string &name, const char *def)
static bool import_blend_shapes(Main &bmain, FbxElementMapping &mapping, const ufbx_mesh *fmesh, Mesh *mesh)
void read_custom_properties(const ufbx_props &props, ID &id, bool enums_as_strings)
void node_matrix_to_obj(const ufbx_node *node, Object *obj, const FbxElementMapping &mapping)
static bool is_skin_deformer_usable(const ufbx_mesh *mesh, const ufbx_skin_deformer *skin)
static constexpr const char * temp_custom_normals_name
void matrix_to_m44(const ufbx_matrix &src, float dst[4][4])
static void import_skin_vertex_groups(const FbxElementMapping &mapping, const ufbx_mesh *fmesh, Mesh *mesh)
static void import_uvs(const ufbx_mesh *fmesh, Mesh *mesh, bke::MutableAttributeAccessor &attributes, AttributeOwner attr_owner)
static void import_face_smoothing(const ufbx_mesh *fmesh, bke::MutableAttributeAccessor &attributes)
static void import_faces(const ufbx_mesh *fmesh, Mesh *mesh)
static void import_face_material_indices(const ufbx_mesh *fmesh, bke::MutableAttributeAccessor &attributes)
static bool import_normals_into_temp_attribute(const ufbx_mesh *fmesh, bke::MutableAttributeAccessor &attributes)
static void import_vertex_positions(const ufbx_mesh *fmesh, Mesh *mesh)
static void import_edges(const ufbx_mesh *fmesh, Mesh *mesh, bke::MutableAttributeAccessor &attributes)
void import_meshes(Main &bmain, const ufbx_scene &fbx, FbxElementMapping &mapping, const FBXImportParams &params)
bool size_fits_in_int(const int64_t size)
bool index_in_range(const int64_t index, const int64_t size)
void parallel_for_each(Range &&range, const Function &function)
Definition BLI_task.hh:31
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
VecBase< uint8_t, 4 > uchar4
__int64 int64_t
Definition BKE_text.h:90
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
void * BKE_object_obdata_add_from_type(Main *bmain, ObjectType type, const char *name) ATTR_NONNULL(1)
Definition object.cc:2185
KeyBlock * BKE_keyblock_find_name(Key *key, const char name[])
Definition key.cc:1434
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
std::string BKE_attribute_calc_unique_name(const AttributeOwner &owner, StringRef name)
const char * BKE_id_name(const ID &id)
void BKE_modifiers_persistent_uid_init(const Object &object, ModifierData &md)
int BKE_defgroup_name_index(const ListBaseT< bDeformGroup > *defbase, StringRef name)
Definition deform.cc:544
VecBase< float, 4 > float4
unsigned int uint32_t
Definition BKE_text.h:81
eFBXVertexColorMode
Definition IO_fbx.hh:32
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
Key * BKE_key_add(Main *bmain, ID *id)
Definition key.cc:228
ModifierData * BKE_modifier_new(int type)
@ BKE_MAT_ASSIGN_OBJECT
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
MDeformWeight * BKE_defvert_ensure_index(MDeformVert *dv, int defgroup)
Definition deform.cc:830
struct bDeformGroup * BKE_object_defgroup_add_name(struct Object *ob, const char *name)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
char * BLI_strdup(const char *str) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC
KeyBlock * BKE_keyblock_add(Key *key, const char *name)
Definition key.cc:1322
@ SUBSURF_BOUNDARY_SMOOTH_PRESERVE_CORNERS
@ SUBSURF_BOUNDARY_SMOOTH_ALL
static CLG_LogRef LOG
Definition fbx_import.cc:43
void BKE_object_material_assign_single_obdata(Main *bmain, Object *ob, Material *ma, short act)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
VecBase< float, 3 > float3
Object * BKE_object_add_only_object(Main *bmain, ObjectType type, const char *name) ATTR_RETURNS_NONNULL
Definition object.cc:2265
void BKE_keyblock_convert_from_mesh(const Mesh *mesh, const Key *key, KeyBlock *kb)
Definition key.cc:1681
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
MINLINE void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
#define sqrtf
eFBXVertexColorMode vertex_colors
Definition IO_fbx.hh:42
ShapekeyContainerType type
Map< const ufbx_node *, std::string > node_to_name
Map< const ufbx_element *, Key * > el_to_shape_key