@@ -424,7 +424,7 @@ Bool MMDMeshManagerObject::LoadPMX(
424424 {
425425 // statistics vertex weight data
426426 vertex_weight_data.resize (vertex_count);
427- maxon::ParallelFor::Dynamic (0i64 , Int (vertex_count), [&pmx_vertices, &vertex_weight_data](const Int vertex_index)
427+ maxon::ParallelFor::Dynamic (Int ( 0 ) , Int (vertex_count), [&pmx_vertices, &vertex_weight_data](const Int vertex_index)
428428 {
429429 auto & weight_data = vertex_weight_data[vertex_index];
430430 switch (const auto & pmx_vertex = pmx_vertices[vertex_index]; pmx_vertex.m_weightType )
@@ -509,7 +509,7 @@ Bool MMDMeshManagerObject::LoadPMX(
509509 break ;
510510 }
511511 }
512- });
512+ }, maxon::ParallelFor::Granularity ( 64 , vertex_count > 1024 ) );
513513 }
514514
515515 // create mesh
@@ -564,7 +564,7 @@ Bool MMDMeshManagerObject::LoadPMX(
564564 }
565565 }
566566
567- maxon::ParallelFor::Dynamic (0i64 , Int (vertex_count), [&pmx_vertices, &setting, &mesh_object_points, &joint_weight_maps, &vertex_weight_data](const Int vertex_index)
567+ maxon::ParallelFor::Dynamic (Int ( 0 ) , Int (vertex_count), [&pmx_vertices, &setting, &mesh_object_points, &joint_weight_maps, &vertex_weight_data](const Int vertex_index)
568568 {
569569 const auto & pmx_vertex = pmx_vertices[vertex_index];
570570
@@ -583,7 +583,7 @@ Bool MMDMeshManagerObject::LoadPMX(
583583 joint_weight_maps[joint_index][vi] = Clamp01 (weight);
584584 }
585585 }
586- });
586+ }, maxon::ParallelFor::Granularity ( 64 , vertex_count > 1024 ) );
587587
588588 if (setting.import_weights && weight_tag)
589589 {
@@ -621,7 +621,7 @@ Bool MMDMeshManagerObject::LoadPMX(
621621 mesh_object->InsertTag (uvw_tag);
622622 }
623623 // vertex index -> surface index
624- maxon::ParallelFor::Dynamic (0i64 , Int (faces_count), [&pmx_faces, &pmx_vertices, &setting, &mesh_object_polygons, &normal_handle, &uvw_handle](const Int surface_index)
624+ maxon::ParallelFor::Dynamic (Int ( 0 ) , Int (faces_count), [&pmx_faces, &pmx_vertices, &setting, &mesh_object_polygons, &normal_handle, &uvw_handle](const Int surface_index)
625625 {
626626 iferr_scope_handler
627627 {
@@ -669,7 +669,7 @@ Bool MMDMeshManagerObject::LoadPMX(
669669 Vector (pmx_vertex_uv_c[0 ], pmx_vertex_uv_c[1 ], 0 .),
670670 Vector{}));
671671 }
672- });
672+ }, maxon::ParallelFor::Granularity ( 128 , faces_count > 1024 ) );
673673
674674 // set weight tag
675675 if (setting.import_weights )
@@ -870,12 +870,9 @@ Bool MMDMeshManagerObject::LoadPMX(
870870 morph_uv_map.Insert (vertex_index, Vector (uv[0 ], uv[1 ], 0 .))iferr_return;
871871 }
872872
873- // add morph uv
874- maxon::ParallelFor::Dynamic (0i64, Int (faces_count), [&pmx_faces, &morph_node, &morph_uv_map]( const Int surface_index)
873+ // add morph uv (single-threaded: CAMorphNode::SetUV is not safe for concurrent calls on the same node)
874+ for (Int surface_index = 0 ; surface_index < Int (faces_count); ++ surface_index)
875875 {
876- iferr_scope_handler{
877- return ;
878- };
879876 const auto & pmx_surface = pmx_faces[surface_index];
880877 const auto & pmx_surface_vertex_a = pmx_surface.m_vertices [0 ];
881878 const auto & pmx_surface_vertex_b = pmx_surface.m_vertices [1 ];
@@ -901,7 +898,7 @@ Bool MMDMeshManagerObject::LoadPMX(
901898 {
902899 morph_node->SetUV (0 , static_cast <Int32>(surface_index), uvw);
903900 }
904- });
901+ }
905902
906903 morph->SetMode (setting.doc , morph_tag, CAMORPH_MODE_FLAGS::ALL | CAMORPH_MODE_FLAGS::COLLAPSE, CAMORPH_MODE::AUTO);
907904 morph_tag->UpdateMorphs ();
@@ -1146,7 +1143,7 @@ Bool MMDMeshManagerObject::LoadPMX(
11461143 }
11471144 }
11481145
1149- maxon::ParallelFor::Dynamic (0i64 , Int (part_vertex_count), [&setting, &pmx_vertices, &mesh_object_points, &joint_weight_maps, &vertex_weight_data, &pmx_vertex_index_array, &vertex_index_map, &vertex_info_map, &mesh_object, &morph_tag_infos ](const Int32 vertex_index)
1146+ maxon::ParallelFor::Dynamic (Int ( 0 ) , Int (part_vertex_count), [&setting, &pmx_vertices, &mesh_object_points, &joint_weight_maps, &vertex_weight_data, &pmx_vertex_index_array, &vertex_index_map](const Int32 vertex_index)
11501147 {
11511148 iferr_scope_handler
11521149 {
@@ -1158,23 +1155,9 @@ Bool MMDMeshManagerObject::LoadPMX(
11581155 const auto & c4d_vertex_index = vertex_index_map.Find (pmx_vertex_index)->GetValue ();
11591156 auto & mesh_object_point = mesh_object_points[c4d_vertex_index];
11601157 const auto & pmx_vertex_position = pmx_vertex.m_position ;
1161- mesh_object_point.x = pmx_vertex_position[0 ];
1162- mesh_object_point.y = pmx_vertex_position[1 ];
1163- mesh_object_point.z = pmx_vertex_position[2 ];
1164-
1165- if (setting.import_expression )
1166- {
1167- vertex_info_map.Write ([&pmx_vertex_index, &c4d_vertex_index, &mesh_object, &morph_tag_infos](maxon::HashMap<uint64_t , vertex_info>& map)->maxon ::Result<void >
1168- {
1169- iferr_scope;
1170- auto & entry = map.InsertMultiEntry (pmx_vertex_index)iferr_return;
1171- auto & vertex_info = entry.GetValue ();
1172- vertex_info.vertex_index = c4d_vertex_index;
1173- vertex_info.mesh_object = mesh_object;
1174- vertex_info.morph_tag_index = morph_tag_infos.GetCount () - 1 ;
1175- return maxon::OK;
1176- })iferr_return;
1177- }
1158+ mesh_object_point.x = pmx_vertex_position[0 ];
1159+ mesh_object_point.y = pmx_vertex_position[1 ];
1160+ mesh_object_point.z = pmx_vertex_position[2 ];
11781161
11791162 if (setting.import_weights )
11801163 {
@@ -1183,7 +1166,23 @@ Bool MMDMeshManagerObject::LoadPMX(
11831166 joint_weight_maps[joint_index][c4d_vertex_index] = Clamp01 (weight);
11841167 }
11851168 }
1186- });
1169+ }, maxon::ParallelFor::Granularity (64 , part_vertex_count > 1024 ));
1170+
1171+ if (setting.import_expression )
1172+ {
1173+ auto vertex_info_write = vertex_info_map.Write ();
1174+ maxon::HashMap<uint64_t , vertex_info>& vertex_info_hash = *vertex_info_write;
1175+ for (Int32 vi = 0 ; vi < part_vertex_count; ++vi)
1176+ {
1177+ const auto pmx_vi = pmx_vertex_index_array[vi];
1178+ const auto c4d_vi = vertex_index_map.Find (pmx_vi)->GetValue ();
1179+ auto & entry = vertex_info_hash.InsertMultiEntry (pmx_vi)iferr_return;
1180+ auto & vertex_info = entry.GetValue ();
1181+ vertex_info.vertex_index = c4d_vi;
1182+ vertex_info.mesh_object = mesh_object;
1183+ vertex_info.morph_tag_index = morph_tag_infos.GetCount () - 1 ;
1184+ }
1185+ }
11871186
11881187 if (setting.import_weights && weight_tag)
11891188 {
@@ -1284,7 +1283,7 @@ Bool MMDMeshManagerObject::LoadPMX(
12841283 Vector (pmx_vertex_uv_c[0 ], pmx_vertex_uv_c[1 ], 0 .),
12851284 Vector{}));
12861285 }
1287- });
1286+ }, maxon::ParallelFor::Granularity ( 128 , part_face_num > 1024 ) );
12881287
12891288 // set weight tag
12901289 if (setting.import_weights )
@@ -1449,8 +1448,8 @@ Bool MMDMeshManagerObject::LoadPMX(
14491448 }
14501449 }
14511450
1452- // add morph uv
1453- maxon::ParallelFor::Dynamic (0i64, Int (faces_count), [&pmx_faces, &morph_uv_map]( const Int surface_index)
1451+ // add morph uv (single-threaded: CAMorphNode::SetUV is not safe for concurrent calls on the same node)
1452+ for (Int surface_index = 0 ; surface_index < Int (faces_count); ++ surface_index)
14541453 {
14551454 const auto & pmx_surface = pmx_faces[surface_index];
14561455 const auto & pmx_surface_vertex_a = pmx_surface.m_vertices [0 ];
@@ -1480,7 +1479,7 @@ Bool MMDMeshManagerObject::LoadPMX(
14801479 {
14811480 morph_node->SetUV (0 , static_cast <Int32>(surface_index), uvw);
14821481 }
1483- });
1482+ }
14841483 break ;
14851484 }
14861485 case libmmd::PMXMorphType::Flip:
0 commit comments