diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-17 20:59:10 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-17 20:59:10 +0300 |
commit | 37eea2253295602fbff4ba255fdb2ee8f1826df3 (patch) | |
tree | ee939acc8d0f5a395064692a2e65a289f4210a31 /source/blender/io | |
parent | f08ea76db591a1ca60715f19f3465da57b26f64e (diff) |
Initial patch from Martijn Versteegh
Diffstat (limited to 'source/blender/io')
-rw-r--r-- | source/blender/io/alembic/exporter/abc_writer_mesh.cc | 8 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_customdata.cc | 31 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_customdata.h | 5 | ||||
-rw-r--r-- | source/blender/io/alembic/intern/abc_reader_mesh.cc | 13 | ||||
-rw-r--r-- | source/blender/io/collada/EffectExporter.cpp | 4 | ||||
-rw-r--r-- | source/blender/io/collada/GeometryExporter.cpp | 24 | ||||
-rw-r--r-- | source/blender/io/collada/InstanceWriter.cpp | 6 | ||||
-rw-r--r-- | source/blender/io/collada/MeshImporter.cpp | 12 | ||||
-rw-r--r-- | source/blender/io/collada/MeshImporter.h | 2 | ||||
-rw-r--r-- | source/blender/io/collada/collada_utils.cpp | 10 | ||||
-rw-r--r-- | source/blender/io/usd/intern/usd_reader_mesh.cc | 16 | ||||
-rw-r--r-- | source/blender/io/usd/intern/usd_writer_abstract.cc | 2 | ||||
-rw-r--r-- | source/blender/io/usd/intern/usd_writer_mesh.cc | 7 | ||||
-rw-r--r-- | source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc | 6 | ||||
-rw-r--r-- | source/blender/io/wavefront_obj/importer/obj_import_mesh.cc | 8 | ||||
-rw-r--r-- | source/blender/io/wavefront_obj/tests/obj_importer_tests.cc | 6 |
16 files changed, 83 insertions, 77 deletions
diff --git a/source/blender/io/alembic/exporter/abc_writer_mesh.cc b/source/blender/io/alembic/exporter/abc_writer_mesh.cc index 07b185ffd64..f0a0501bf88 100644 --- a/source/blender/io/alembic/exporter/abc_writer_mesh.cc +++ b/source/blender/io/alembic/exporter/abc_writer_mesh.cc @@ -239,8 +239,10 @@ void ABCGenericMeshWriter::write_mesh(HierarchyContext &context, Mesh *mesh) mesh_sample.setUVs(uv_sample); } - write_custom_data( - abc_poly_mesh_schema_.getArbGeomParams(), m_custom_data_config, &mesh->ldata, CD_MLOOPUV); + write_custom_data(abc_poly_mesh_schema_.getArbGeomParams(), + m_custom_data_config, + &mesh->ldata, + CD_PROP_FLOAT2); } if (args_.export_params->normals) { @@ -306,7 +308,7 @@ void ABCGenericMeshWriter::write_subd(HierarchyContext &context, struct Mesh *me } write_custom_data( - abc_subdiv_schema_.getArbGeomParams(), m_custom_data_config, &mesh->ldata, CD_MLOOPUV); + abc_subdiv_schema_.getArbGeomParams(), m_custom_data_config, &mesh->ldata, CD_PROP_FLOAT2); } if (args_.export_params->orcos) { diff --git a/source/blender/io/alembic/intern/abc_customdata.cc b/source/blender/io/alembic/intern/abc_customdata.cc index 2820a128072..8585a032d78 100644 --- a/source/blender/io/alembic/intern/abc_customdata.cc +++ b/source/blender/io/alembic/intern/abc_customdata.cc @@ -50,7 +50,7 @@ static void get_uvs(const CDStreamConfig &config, std::vector<uint32_t> &uvidx, const void *cd_data) { - const MLoopUV *mloopuv_array = static_cast<const MLoopUV *>(cd_data); + const float2 *mloopuv_array = static_cast<const float2 *>(cd_data); if (!mloopuv_array) { return; @@ -68,14 +68,14 @@ static void get_uvs(const CDStreamConfig &config, /* Iterate in reverse order to match exported polygons. */ for (int i = 0; i < num_poly; i++) { MPoly ¤t_poly = polygons[i]; - const MLoopUV *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop; + const float2 *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop; for (int j = 0; j < current_poly.totloop; j++, count++) { loopuv--; uvidx[count] = count; - uvs[count][0] = loopuv->uv[0]; - uvs[count][1] = loopuv->uv[1]; + uvs[count][0] = (*loopuv)[0]; + uvs[count][1] = (*loopuv)[1]; } } } @@ -87,13 +87,13 @@ static void get_uvs(const CDStreamConfig &config, for (int i = 0; i < num_poly; i++) { MPoly ¤t_poly = polygons[i]; MLoop *looppoly = mloop + current_poly.loopstart + current_poly.totloop; - const MLoopUV *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop; + const float2 *loopuv = mloopuv_array + current_poly.loopstart + current_poly.totloop; for (int j = 0; j < current_poly.totloop; j++) { looppoly--; loopuv--; - Imath::V2f uv(loopuv->uv[0], loopuv->uv[1]); + Imath::V2f uv((*loopuv)[0], (*loopuv)[1]); bool found_same = false; /* Find UV already in uvs array. */ @@ -119,17 +119,17 @@ static void get_uvs(const CDStreamConfig &config, const char *get_uv_sample(UVSample &sample, const CDStreamConfig &config, CustomData *data) { - const int active_uvlayer = CustomData_get_active_layer(data, CD_MLOOPUV); + const int active_uvlayer = CustomData_get_active_layer(data, CD_PROP_FLOAT2); if (active_uvlayer < 0) { return ""; } - const void *cd_data = CustomData_get_layer_n(data, CD_MLOOPUV, active_uvlayer); + const void *cd_data = CustomData_get_layer_n(data, CD_PROP_FLOAT2, active_uvlayer); get_uvs(config, sample.uvs, sample.indices, cd_data); - return CustomData_get_layer_name(data, CD_MLOOPUV, active_uvlayer); + return CustomData_get_layer_name(data, CD_PROP_FLOAT2, active_uvlayer); } /* Convention to write UVs: @@ -286,7 +286,7 @@ void write_custom_data(const OCompoundProperty &prop, const void *cd_data = CustomData_get_layer_n(data, cd_data_type, i); const char *name = CustomData_get_layer_name(data, cd_data_type, i); - if (cd_data_type == CD_MLOOPUV) { + if (cd_data_type == CD_PROP_FLOAT2) { /* Already exported. */ if (i == active_layer) { continue; @@ -320,7 +320,7 @@ static void read_uvs(const CDStreamConfig &config, { MPoly *mpolys = config.mpoly; MLoop *mloops = config.mloop; - MLoopUV *mloopuvs = static_cast<MLoopUV *>(data); + float(*mloopuvs)[2] = static_cast<float(*)[2]>(data); unsigned int uv_index, loop_index, rev_loop_index; @@ -337,9 +337,9 @@ static void read_uvs(const CDStreamConfig &config, uv_index = (*indices)[loop_index]; const Imath::V2f &uv = (*uvs)[uv_index]; - MLoopUV &loopuv = mloopuvs[rev_loop_index]; - loopuv.uv[0] = uv[0]; - loopuv.uv[1] = uv[1]; + float *loopuv = mloopuvs[rev_loop_index]; + loopuv[0] = uv[0]; + loopuv[1] = uv[1]; } } } @@ -500,7 +500,8 @@ static void read_custom_data_uvs(const ICompoundProperty &prop, return; } - void *cd_data = config.add_customdata_cb(config.mesh, prop_header.getName().c_str(), CD_MLOOPUV); + void *cd_data = config.add_customdata_cb( + config.mesh, prop_header.getName().c_str(), CD_PROP_FLOAT2); read_uvs(config, cd_data, uv_scope, sample.getVals(), uvs_indices); } diff --git a/source/blender/io/alembic/intern/abc_customdata.h b/source/blender/io/alembic/intern/abc_customdata.h index 0ddba866016..203ae16fd4b 100644 --- a/source/blender/io/alembic/intern/abc_customdata.h +++ b/source/blender/io/alembic/intern/abc_customdata.h @@ -11,9 +11,10 @@ #include <map> +#include "BLI_math_vec_types.hh" + struct CustomData; struct MLoop; -struct MLoopUV; struct MPoly; struct MVert; struct Mesh; @@ -37,7 +38,7 @@ struct CDStreamConfig { MVert *mvert; int totvert; - MLoopUV *mloopuv; + float2 *mloopuv; CustomData *loopdata; diff --git a/source/blender/io/alembic/intern/abc_reader_mesh.cc b/source/blender/io/alembic/intern/abc_reader_mesh.cc index bacc1f06599..97f6f60efc3 100644 --- a/source/blender/io/alembic/intern/abc_reader_mesh.cc +++ b/source/blender/io/alembic/intern/abc_reader_mesh.cc @@ -174,7 +174,7 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) { MPoly *mpolys = config.mpoly; MLoop *mloops = config.mloop; - MLoopUV *mloopuvs = config.mloopuv; + float2 *mloopuvs = config.mloopuv; const Int32ArraySamplePtr &face_indices = mesh_data.face_indices; const Int32ArraySamplePtr &face_counts = mesh_data.face_counts; @@ -218,7 +218,6 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) last_vertex_index = loop.v; if (do_uvs) { - MLoopUV &loopuv = mloopuvs[rev_loop_index]; uv_index = (*uvs_indices)[do_uvs_per_loop ? loop_index : loop.v]; /* Some Alembic files are broken (or at least export UVs in a way we don't expect). */ @@ -226,8 +225,8 @@ static void read_mpolys(CDStreamConfig &config, const AbcMeshData &mesh_data) continue; } - loopuv.uv[0] = (*uvs)[uv_index][0]; - loopuv.uv[1] = (*uvs)[uv_index][1]; + mloopuvs[rev_loop_index][0] = (*uvs)[uv_index][0]; + mloopuvs[rev_loop_index][1] = (*uvs)[uv_index][1]; } } } @@ -369,8 +368,8 @@ BLI_INLINE void read_uvs_params(CDStreamConfig &config, name = uv.getName(); } - void *cd_ptr = config.add_customdata_cb(config.mesh, name.c_str(), CD_MLOOPUV); - config.mloopuv = static_cast<MLoopUV *>(cd_ptr); + void *cd_ptr = config.add_customdata_cb(config.mesh, name.c_str(), CD_PROP_FLOAT2); + config.mloopuv = static_cast<float2 *>(cd_ptr); } static void *add_customdata_cb(Mesh *mesh, const char *name, int data_type) @@ -378,7 +377,7 @@ static void *add_customdata_cb(Mesh *mesh, const char *name, int data_type) eCustomDataType cd_data_type = static_cast<eCustomDataType>(data_type); /* unsupported custom data type -- don't do anything. */ - if (!ELEM(cd_data_type, CD_MLOOPUV, CD_PROP_BYTE_COLOR)) { + if (!ELEM(cd_data_type, CD_PROP_FLOAT2, CD_PROP_BYTE_COLOR)) { return nullptr; } diff --git a/source/blender/io/collada/EffectExporter.cpp b/source/blender/io/collada/EffectExporter.cpp index 71a54e3a7c9..30fe492e240 100644 --- a/source/blender/io/collada/EffectExporter.cpp +++ b/source/blender/io/collada/EffectExporter.cpp @@ -29,9 +29,9 @@ static std::string getActiveUVLayerName(Object *ob) { Mesh *me = (Mesh *)ob->data; - int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); + int num_layers = CustomData_number_of_layers(&me->ldata, CD_PROP_FLOAT2); if (num_layers) { - return std::string(bc_CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV)); + return std::string(bc_CustomData_get_active_layer_name(&me->ldata, CD_PROP_FLOAT2)); } return ""; diff --git a/source/blender/io/collada/GeometryExporter.cpp b/source/blender/io/collada/GeometryExporter.cpp index 7e2a24aeb41..539cc96bf31 100644 --- a/source/blender/io/collada/GeometryExporter.cpp +++ b/source/blender/io/collada/GeometryExporter.cpp @@ -74,7 +74,7 @@ void GeometryExporter::operator()(Object *ob) /* writes <source> for normal coords */ createNormalsSource(geom_id, me, nor); - bool has_uvs = (bool)CustomData_has_layer(&me->ldata, CD_MLOOPUV); + bool has_uvs = (bool)CustomData_has_layer(&me->ldata, CD_PROP_FLOAT2); /* writes <source> for uv coords if mesh has uv coords */ if (has_uvs) { @@ -156,7 +156,7 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb) /* writes <source> for normal coords */ createNormalsSource(geom_id, me, nor); - bool has_uvs = (bool)CustomData_has_layer(&me->ldata, CD_MLOOPUV); + bool has_uvs = (bool)CustomData_has_layer(&me->ldata, CD_PROP_FLOAT2); /* writes <source> for uv coords if mesh has uv coords */ if (has_uvs) { @@ -361,13 +361,13 @@ void GeometryExporter::create_mesh_primitive_list(short material_index, til.push_back(normals_input); /* if mesh has uv coords writes <input> for TEXCOORD */ - int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); - int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV); + int num_layers = CustomData_number_of_layers(&me->ldata, CD_PROP_FLOAT2); + int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_PROP_FLOAT2); for (int i = 0; i < num_layers; i++) { - int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, i); + int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_PROP_FLOAT2, i); if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) { - // char *name = CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, i); + // char *name = CustomData_get_layer_name(&me->ldata, CD_PROP_FLOAT2, i); COLLADASW::Input texcoord_input( COLLADASW::InputSemantic::TEXCOORD, makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings.get_active_uv_only())), @@ -534,15 +534,15 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) int totuv = me->totloop; MPoly *mpolys = me->mpoly; - int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); + int num_layers = CustomData_number_of_layers(&me->ldata, CD_PROP_FLOAT2); /* write <source> for each layer * each <source> will get id like meshName + "map-channel-1" */ - int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV); + int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_PROP_FLOAT2); for (int a = 0; a < num_layers; a++) { - int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_MLOOPUV, a); + int layer_index = CustomData_get_layer_index_n(&me->ldata, CD_PROP_FLOAT2, a); if (!this->export_settings.get_active_uv_only() || layer_index == active_uv_index) { - MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a); + float(*mloops)[2] = (float(*)[2])CustomData_get_layer_n(&me->ldata, CD_PROP_FLOAT2, a); COLLADASW::FloatSourceF source(mSW); std::string layer_id = makeTexcoordSourceId( @@ -560,9 +560,9 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me) for (int index = 0; index < totpoly; index++) { MPoly *mpoly = mpolys + index; - MLoopUV *mloop = mloops + mpoly->loopstart; + float(*mloop)[2] = mloops + mpoly->loopstart; for (int j = 0; j < mpoly->totloop; j++) { - source.appendValues(mloop[j].uv[0], mloop[j].uv[1]); + source.appendValues(mloop[j][0], mloop[j][1]); } } diff --git a/source/blender/io/collada/InstanceWriter.cpp b/source/blender/io/collada/InstanceWriter.cpp index d88f24b8e8b..76ada0be099 100644 --- a/source/blender/io/collada/InstanceWriter.cpp +++ b/source/blender/io/collada/InstanceWriter.cpp @@ -38,13 +38,13 @@ void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial &bind_materia // create <bind_vertex_input> for each uv map Mesh *me = (Mesh *)ob->data; - int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); + int num_layers = CustomData_number_of_layers(&me->ldata, CD_PROP_FLOAT2); int map_index = 0; - int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV); + int active_uv_index = CustomData_get_active_layer_index(&me->ldata, CD_PROP_FLOAT2); for (int b = 0; b < num_layers; b++) { if (!active_uv_only || b == active_uv_index) { - char *name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, b); + char *name = bc_CustomData_get_layer_name(&me->ldata, CD_PROP_FLOAT2, b); im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++)); } } diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp index fa0348fbcf2..ea5ec2ee8f9 100644 --- a/source/blender/io/collada/MeshImporter.cpp +++ b/source/blender/io/collada/MeshImporter.cpp @@ -237,7 +237,7 @@ void MeshImporter::set_vcol(MLoopCol *mloopcol, } } -void MeshImporter::set_face_uv(MLoopUV *mloopuv, +void MeshImporter::set_face_uv(float (*mloopuv)[2], UVDataWrapper &uvs, int start_index, COLLADAFW::IndexList &index_list, @@ -248,7 +248,7 @@ void MeshImporter::set_face_uv(MLoopUV *mloopuv, for (int index = 0; index < count; index++) { int uv_index = indices[index + start_index]; - uvs.getUV(uv_index, mloopuv[index].uv); + uvs.getUV(uv_index, mloopuv[index]); } } @@ -468,10 +468,10 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me) COLLADAFW::String &uvname = info->mName; /* Allocate space for UV_data */ CustomData_add_layer_named( - &me->ldata, CD_MLOOPUV, CD_DEFAULT, nullptr, me->totloop, uvname.c_str()); + &me->ldata, CD_PROP_FLOAT2, CD_DEFAULT, nullptr, me->totloop, uvname.c_str()); } /* activate the first uv map */ - me->mloopuv = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, 0); + me->mloopuv = (float(*)[2])CustomData_get_layer_n(&me->ldata, CD_PROP_FLOAT2, 0); } int totcolset = collada_mesh->getColors().getInputInfosArray().getCount(); @@ -703,8 +703,8 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me) uvset_index++) { /* get mtface by face index and uv set index */ COLLADAFW::IndexList &index_list = *index_list_array_uvcoord[uvset_index]; - MLoopUV *mloopuv = (MLoopUV *)CustomData_get_layer_named( - &me->ldata, CD_MLOOPUV, index_list.getName().c_str()); + float(*mloopuv)[2] = (float(*)[2])CustomData_get_layer_named( + &me->ldata, CD_PROP_FLOAT2, index_list.getName().c_str()); if (mloopuv == nullptr) { fprintf(stderr, "Collada import: Mesh [%s] : Unknown reference to TEXCOORD [#%s].\n", diff --git a/source/blender/io/collada/MeshImporter.h b/source/blender/io/collada/MeshImporter.h index 416b5728b66..06e609b8f58 100644 --- a/source/blender/io/collada/MeshImporter.h +++ b/source/blender/io/collada/MeshImporter.h @@ -92,7 +92,7 @@ class MeshImporter : public MeshImporterBase { bool set_poly_indices( MPoly *mpoly, MLoop *mloop, int loop_index, const unsigned int *indices, int loop_count); - void set_face_uv(MLoopUV *mloopuv, + void set_face_uv(float (*mloopuv)[2], UVDataWrapper &uvs, int start_index, COLLADAFW::IndexList &index_list, diff --git a/source/blender/io/collada/collada_utils.cpp b/source/blender/io/collada/collada_utils.cpp index 75842734b08..a450ddee2b8 100644 --- a/source/blender/io/collada/collada_utils.cpp +++ b/source/blender/io/collada/collada_utils.cpp @@ -321,7 +321,7 @@ bool bc_is_root_bone(Bone *aBone, bool deform_bones_only) int bc_get_active_UVLayer(Object *ob) { Mesh *me = (Mesh *)ob->data; - return CustomData_get_active_layer_index(&me->ldata, CD_MLOOPUV); + return CustomData_get_active_layer_index(&me->ldata, CD_PROP_FLOAT2); } std::string bc_url_encode(std::string data) @@ -1070,9 +1070,9 @@ void bc_copy_m4d_v44(double (&r)[4][4], std::vector<std::vector<double>> &a) */ static std::string bc_get_active_uvlayer_name(Mesh *me) { - int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); + int num_layers = CustomData_number_of_layers(&me->ldata, CD_PROP_FLOAT2); if (num_layers) { - char *layer_name = bc_CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV); + char *layer_name = bc_CustomData_get_active_layer_name(&me->ldata, CD_PROP_FLOAT2); if (layer_name) { return std::string(layer_name); } @@ -1095,9 +1095,9 @@ static std::string bc_get_active_uvlayer_name(Object *ob) */ static std::string bc_get_uvlayer_name(Mesh *me, int layer) { - int num_layers = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV); + int num_layers = CustomData_number_of_layers(&me->ldata, CD_PROP_FLOAT2); if (num_layers && layer < num_layers) { - char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPUV, layer); + char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_PROP_FLOAT2, layer); if (layer_name) { return std::string(layer_name); } diff --git a/source/blender/io/usd/intern/usd_reader_mesh.cc b/source/blender/io/usd/intern/usd_reader_mesh.cc index 45657525527..29c05017435 100644 --- a/source/blender/io/usd/intern/usd_reader_mesh.cc +++ b/source/blender/io/usd/intern/usd_reader_mesh.cc @@ -180,7 +180,7 @@ static void *add_customdata_cb(Mesh *mesh, const char *name, const int data_type int numloops; /* unsupported custom data type -- don't do anything. */ - if (!ELEM(cd_data_type, CD_MLOOPUV, CD_PROP_BYTE_COLOR)) { + if (!ELEM(cd_data_type, CD_PROP_FLOAT2, CD_PROP_BYTE_COLOR)) { return nullptr; } @@ -345,7 +345,7 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; std::string layer_name = std::string(layer->name); - if (layer->type != CD_MLOOPUV) { + if (layer->type != CD_PROP_FLOAT2) { continue; } @@ -391,7 +391,7 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; - if (layer->type != CD_MLOOPUV) { + if (layer->type != CD_PROP_FLOAT2) { continue; } @@ -426,15 +426,15 @@ void USDMeshReader::read_uvs(Mesh *mesh, const double motionSampleTime, const bo continue; } - MLoopUV *mloopuv = static_cast<MLoopUV *>(layer->data); + float2 *mloopuv = static_cast<float2 *>(layer->data); if (is_left_handed_) { uv_index = rev_loop_index; } else { uv_index = loop_index; } - mloopuv[uv_index].uv[0] = sample.uvs[usd_uv_index][0]; - mloopuv[uv_index].uv[1] = sample.uvs[usd_uv_index][1]; + mloopuv[uv_index][0] = sample.uvs[usd_uv_index][0]; + mloopuv[uv_index][1] = sample.uvs[usd_uv_index][1]; } } } @@ -882,8 +882,8 @@ Mesh *USDMeshReader::read_mesh(Mesh *existing_mesh, existing_mesh, positions_.size(), 0, 0, face_indices_.size(), face_counts_.size()); for (pxr::TfToken token : uv_tokens) { - void *cd_ptr = add_customdata_cb(active_mesh, token.GetText(), CD_MLOOPUV); - active_mesh->mloopuv = static_cast<MLoopUV *>(cd_ptr); + void *cd_ptr = add_customdata_cb(active_mesh, token.GetText(), CD_PROP_FLOAT2); + active_mesh->mloopuv = static_cast<float(*)[2]>(cd_ptr); } } diff --git a/source/blender/io/usd/intern/usd_writer_abstract.cc b/source/blender/io/usd/intern/usd_writer_abstract.cc index 2be9b1c065a..f4ae9d20e52 100644 --- a/source/blender/io/usd/intern/usd_writer_abstract.cc +++ b/source/blender/io/usd/intern/usd_writer_abstract.cc @@ -30,7 +30,7 @@ static std::string get_mesh_active_uvlayer_name(const Object *ob) const Mesh *me = static_cast<Mesh *>(ob->data); - const char *name = CustomData_get_active_layer_name(&me->ldata, CD_MLOOPUV); + const char *name = CustomData_get_active_layer_name(&me->ldata, CD_PROP_FLOAT2); return name ? name : ""; } diff --git a/source/blender/io/usd/intern/usd_writer_mesh.cc b/source/blender/io/usd/intern/usd_writer_mesh.cc index b76f74cfd3d..874c1723535 100644 --- a/source/blender/io/usd/intern/usd_writer_mesh.cc +++ b/source/blender/io/usd/intern/usd_writer_mesh.cc @@ -8,6 +8,7 @@ #include <pxr/usd/usdShade/materialBindingAPI.h> #include "BLI_assert.h" +#include "BLI_math_vec_types.hh" #include "BLI_math_vector.h" #include "BKE_attribute.h" @@ -109,7 +110,7 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ const CustomData *ldata = &mesh->ldata; for (int layer_idx = 0; layer_idx < ldata->totlayer; layer_idx++) { const CustomDataLayer *layer = &ldata->layers[layer_idx]; - if (layer->type != CD_MLOOPUV) { + if (layer->type != CD_PROP_FLOAT2) { continue; } @@ -121,10 +122,10 @@ void USDGenericMeshWriter::write_uv_maps(const Mesh *mesh, pxr::UsdGeomMesh usd_ pxr::UsdGeomPrimvar uv_coords_primvar = usd_mesh.CreatePrimvar( primvar_name, pxr::SdfValueTypeNames->TexCoord2fArray, pxr::UsdGeomTokens->faceVarying); - MLoopUV *mloopuv = static_cast<MLoopUV *>(layer->data); + float2 *mloopuv = static_cast<float2 *>(layer->data); pxr::VtArray<pxr::GfVec2f> uv_coords; for (int loop_idx = 0; loop_idx < mesh->totloop; loop_idx++) { - uv_coords.push_back(pxr::GfVec2f(mloopuv[loop_idx].uv)); + uv_coords.push_back(pxr::GfVec2f((float *)(mloopuv[loop_idx]))); } if (!uv_coords_primvar.HasValue()) { diff --git a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc index e2ecda32717..0f46c8a45da 100644 --- a/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc +++ b/source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc @@ -287,8 +287,8 @@ void OBJMesh::store_uv_coords_and_indices() const MLoop *mloop = export_mesh_eval_->mloop; const int totpoly = export_mesh_eval_->totpoly; const int totvert = export_mesh_eval_->totvert; - const MLoopUV *mloopuv = static_cast<const MLoopUV *>( - CustomData_get_layer(&export_mesh_eval_->ldata, CD_MLOOPUV)); + const float(*mloopuv)[2] = static_cast<float(*)[2]>( + CustomData_get_layer(&export_mesh_eval_->ldata, CD_PROP_FLOAT2)); if (!mloopuv) { tot_uv_vertices_ = 0; return; @@ -315,7 +315,7 @@ void OBJMesh::store_uv_coords_and_indices() /* Store UV vertex coordinates. */ uv_coords_.resize(tot_uv_vertices_); const int loopstart = mpoly[uv_vert->poly_index].loopstart; - Span<float> vert_uv_coords(mloopuv[loopstart + uv_vert->loop_of_poly_index].uv, 2); + Span<float> vert_uv_coords(mloopuv[loopstart + uv_vert->loop_of_poly_index], 2); uv_coords_[tot_uv_vertices_ - 1] = float2(vert_uv_coords[0], vert_uv_coords[1]); /* Store UV vertex indices. */ diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc index 6f66ce5a6bd..aee82ea720b 100644 --- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc +++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc @@ -257,8 +257,10 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh) if (global_vertices_.uv_vertices.size() <= 0) { return; } - MLoopUV *mluv_dst = static_cast<MLoopUV *>(CustomData_add_layer( - &mesh->ldata, CD_MLOOPUV, CD_DEFAULT, nullptr, mesh_geometry_.total_loops_)); + + UVMap_Data data = BKE_id_attributes_create_uvmap_layers((ID *)mesh, "UVMap", NULL, 0); + float2 *mluv_dst = (float2 *)data.uv; + int tot_loop_idx = 0; for (const PolyElem &curr_face : mesh_geometry_.face_elements_) { @@ -267,7 +269,7 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh) if (curr_corner.uv_vert_index >= 0 && curr_corner.uv_vert_index < global_vertices_.uv_vertices.size()) { const float2 &mluv_src = global_vertices_.uv_vertices[curr_corner.uv_vert_index]; - copy_v2_v2(mluv_dst[tot_loop_idx].uv, mluv_src); + copy_v2_v2(mluv_dst[tot_loop_idx], mluv_src); tot_loop_idx++; } } diff --git a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc index 2b446042f33..ed91ba42bf5 100644 --- a/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc +++ b/source/blender/io/wavefront_obj/tests/obj_importer_tests.cc @@ -99,9 +99,9 @@ class obj_importer_test : public BlendfileLoadingBaseTest { const float3 *lnors = (const float3 *)(CustomData_get_layer(&mesh->ldata, CD_NORMAL)); float3 normal_first = lnors != nullptr ? lnors[0] : float3(0, 0, 0); EXPECT_V3_NEAR(normal_first, exp.normal_first, 0.0001f); - const MLoopUV *mloopuv = static_cast<const MLoopUV *>( - CustomData_get_layer(&mesh->ldata, CD_MLOOPUV)); - float2 uv_first = mloopuv ? float2(mloopuv->uv) : float2(0, 0); + const float2 *mloopuv = static_cast<const float2 *>( + CustomData_get_layer(&mesh->ldata, CD_PROP_FLOAT2)); + float2 uv_first = mloopuv ? *mloopuv : float2(0, 0); EXPECT_V2_NEAR(uv_first, exp.uv_first, 0.0001f); if (exp.color_first.x >= 0) { const float4 *colors = (const float4 *)(CustomData_get_layer(&mesh->vdata, |