Changeset View
Changeset View
Standalone View
Standalone View
source/blender/io/alembic/intern/abc_reader_mesh.cc
| Show First 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) | ||||
| const UInt32ArraySamplePtr &uvs_indices = mesh_data.uvs_indices; | const UInt32ArraySamplePtr &uvs_indices = mesh_data.uvs_indices; | ||||
| const bool do_uvs = (mloopuvs && uvs && uvs_indices) && | const bool do_uvs = (mloopuvs && uvs && uvs_indices) && | ||||
| (uvs_indices->size() == face_indices->size()); | (uvs_indices->size() == face_indices->size()); | ||||
| unsigned int loop_index = 0; | unsigned int loop_index = 0; | ||||
| unsigned int rev_loop_index = 0; | unsigned int rev_loop_index = 0; | ||||
| unsigned int uv_index = 0; | unsigned int uv_index = 0; | ||||
| bool seen_invalid_geometry = false; | |||||
| for (int i = 0; i < face_counts->size(); i++) { | for (int i = 0; i < face_counts->size(); i++) { | ||||
| const int face_size = (*face_counts)[i]; | const int face_size = (*face_counts)[i]; | ||||
| MPoly &poly = mpolys[i]; | MPoly &poly = mpolys[i]; | ||||
| poly.loopstart = loop_index; | poly.loopstart = loop_index; | ||||
| poly.totloop = face_size; | poly.totloop = face_size; | ||||
| /* Polygons are always assumed to be smooth-shaded. If the Alembic mesh should be flat-shaded, | /* Polygons are always assumed to be smooth-shaded. If the Alembic mesh should be flat-shaded, | ||||
| * this is encoded in custom loop normals. See T71246. */ | * this is encoded in custom loop normals. See T71246. */ | ||||
| poly.flag |= ME_SMOOTH; | poly.flag |= ME_SMOOTH; | ||||
| /* NOTE: Alembic data is stored in the reverse order. */ | /* NOTE: Alembic data is stored in the reverse order. */ | ||||
| rev_loop_index = loop_index + (face_size - 1); | rev_loop_index = loop_index + (face_size - 1); | ||||
| uint last_vertex_index = 0; | |||||
| for (int f = 0; f < face_size; f++, loop_index++, rev_loop_index--) { | for (int f = 0; f < face_size; f++, loop_index++, rev_loop_index--) { | ||||
| MLoop &loop = mloops[rev_loop_index]; | MLoop &loop = mloops[rev_loop_index]; | ||||
| loop.v = (*face_indices)[loop_index]; | loop.v = (*face_indices)[loop_index]; | ||||
| if (f > 0 && loop.v == last_vertex_index) { | |||||
| /* This face is invalid, as it has consecutive loops from the same vertex. This is caused | |||||
| * by invalid geometry in the Alembic file, such as in T76514. */ | |||||
| seen_invalid_geometry = true; | |||||
| } | |||||
| last_vertex_index = loop.v; | |||||
| if (do_uvs) { | if (do_uvs) { | ||||
| MLoopUV &loopuv = mloopuvs[rev_loop_index]; | MLoopUV &loopuv = mloopuvs[rev_loop_index]; | ||||
| uv_index = (*uvs_indices)[loop_index]; | uv_index = (*uvs_indices)[loop_index]; | ||||
| /* Some Alembic files are broken (or at least export UVs in a way we don't expect). */ | /* Some Alembic files are broken (or at least export UVs in a way we don't expect). */ | ||||
| if (uv_index >= uvs_size) { | if (uv_index >= uvs_size) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| loopuv.uv[0] = (*uvs)[uv_index][0]; | loopuv.uv[0] = (*uvs)[uv_index][0]; | ||||
| loopuv.uv[1] = (*uvs)[uv_index][1]; | loopuv.uv[1] = (*uvs)[uv_index][1]; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| BKE_mesh_calc_edges(config.mesh, false, false); | BKE_mesh_calc_edges(config.mesh, false, false); | ||||
| if (seen_invalid_geometry) { | |||||
| if (config.modifier_error_message) { | |||||
| *config.modifier_error_message = "Mesh hash invalid geometry; more details on the console"; | |||||
| } | |||||
| BKE_mesh_validate(config.mesh, true, true); | |||||
| } | |||||
| } | } | ||||
| static void process_no_normals(CDStreamConfig &config) | static void process_no_normals(CDStreamConfig &config) | ||||
| { | { | ||||
| /* Absense of normals in the Alembic mesh is interpreted as 'smooth'. */ | /* Absense of normals in the Alembic mesh is interpreted as 'smooth'. */ | ||||
| BKE_mesh_calc_normals(config.mesh); | BKE_mesh_calc_normals(config.mesh); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | if (face_counts->size() != existing_mesh->totpoly || | ||||
| "Topology has changed, perhaps by triangulating the" | "Topology has changed, perhaps by triangulating the" | ||||
| " mesh. Only vertices will be read!"; | " mesh. Only vertices will be read!"; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| CDStreamConfig config = get_config(new_mesh ? new_mesh : existing_mesh); | CDStreamConfig config = get_config(new_mesh ? new_mesh : existing_mesh); | ||||
| config.time = sample_sel.getRequestedTime(); | config.time = sample_sel.getRequestedTime(); | ||||
| config.modifier_error_message = err_str; | |||||
| read_mesh_sample(m_iobject.getFullName(), &settings, m_schema, sample_sel, config); | read_mesh_sample(m_iobject.getFullName(), &settings, m_schema, sample_sel, config); | ||||
| if (new_mesh) { | if (new_mesh) { | ||||
| /* Here we assume that the number of materials doesn't change, i.e. that | /* Here we assume that the number of materials doesn't change, i.e. that | ||||
| * the material slots that were created when the object was loaded from | * the material slots that were created when the object was loaded from | ||||
| * Alembic are still valid now. */ | * Alembic are still valid now. */ | ||||
| size_t num_polys = new_mesh->totpoly; | size_t num_polys = new_mesh->totpoly; | ||||
| ▲ Show 20 Lines • Show All 285 Lines • Show Last 20 Lines | |||||