Fix: Build error and format fixes after previous cleanup

This commit is contained in:
Hans Goudey
2023-12-08 17:19:46 -05:00
parent 854cdd1180
commit e0d95b95cc
8 changed files with 81 additions and 72 deletions

View File

@@ -43,7 +43,7 @@ struct BMeshFromMeshParams {
*
* \warning This function doesn't calculate face normals.
*/
void BM_mesh_bm_from_me(BMesh *bm, const struct Mesh *mesh, const struct BMeshFromMeshParams *params)
void BM_mesh_bm_from_me(BMesh *bm, const Mesh *mesh, const BMeshFromMeshParams *params)
ATTR_NONNULL(1, 3);
struct BMeshToMeshParams {
@@ -70,10 +70,8 @@ struct BMeshToMeshParams {
/**
* \param bmain: May be NULL in case \a calc_object_remap parameter option is not set.
*/
void BM_mesh_bm_to_me(struct Main *bmain,
BMesh *bm,
struct Mesh *mesh,
const struct BMeshToMeshParams *params) ATTR_NONNULL(2, 3, 4);
void BM_mesh_bm_to_me(struct Main *bmain, BMesh *bm, Mesh *mesh, const BMeshToMeshParams *params)
ATTR_NONNULL(2, 3, 4);
/**
* A version of #BM_mesh_bm_to_me intended for getting the mesh
@@ -91,7 +89,5 @@ void BM_mesh_bm_to_me(struct Main *bmain,
*
* \note Was `cddm_from_bmesh_ex` in 2.7x, removed `MFace` support.
*/
void BM_mesh_bm_to_me_for_eval(BMesh *bm,
struct Mesh *mesh,
const struct CustomData_MeshMasks *cd_mask_extra)
void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *mesh, const CustomData_MeshMasks *cd_mask_extra)
ATTR_NONNULL(1, 2);

View File

@@ -253,7 +253,8 @@ static void extract_edituv_stretch_angle_init_subdiv(const DRWSubdivCache &subdi
/* UVs are stored contiguously so we need to compute the offset in the UVs buffer for the active
* UV layer. */
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_MESH) ? &mr.mesh->loop_data : &mr.bm->ldata;
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_MESH) ? &mr.mesh->loop_data :
&mr.bm->ldata;
uint32_t uv_layers = cache.cd_used.uv;
/* HACK to fix #68857 */

View File

@@ -38,8 +38,10 @@ static void extract_tan_init_common(const MeshRenderData &mr,
{
GPU_vertformat_deinterleave(format);
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata : &mr.mesh->loop_data;
CustomData *cd_vdata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->vdata : &mr.mesh->vert_data;
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata :
&mr.mesh->loop_data;
CustomData *cd_vdata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->vdata :
&mr.mesh->vert_data;
uint32_t tan_layers = cache.cd_used.tan;
const float(*orco)[3] = (const float(*)[3])CustomData_get_layer(cd_vdata, CD_ORCO);
float(*orco_allocated)[3] = nullptr;

View File

@@ -89,7 +89,8 @@ static void extract_uv_init(const MeshRenderData &mr,
GPUVertBuf *vbo = static_cast<GPUVertBuf *>(buf);
GPUVertFormat format = {0};
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata : &mr.mesh->loop_data;
CustomData *cd_ldata = (mr.extract_type == MR_EXTRACT_BMESH) ? &mr.bm->ldata :
&mr.mesh->loop_data;
int v_len = mr.loop_len;
uint32_t uv_layers = cache.cd_used.uv;
if (!mesh_extract_uv_format_init(&format, cache, cd_ldata, mr.extract_type, uv_layers)) {

View File

@@ -539,7 +539,8 @@ const bool *ED_mesh_uv_map_edge_select_layer_get(const Mesh *mesh, int uv_map_in
const bool *ED_mesh_uv_map_pin_layer_get(const Mesh *mesh, int uv_map_index);
void ED_mesh_uv_ensure(Mesh *mesh, const char *name);
int ED_mesh_uv_add(Mesh *mesh, const char *name, bool active_set, bool do_init, ReportList *reports);
int ED_mesh_uv_add(
Mesh *mesh, const char *name, bool active_set, bool do_init, ReportList *reports);
void ED_mesh_uv_loop_reset(bContext *C, Mesh *mesh);
/**

View File

@@ -49,10 +49,10 @@ void GeometryExporter::operator()(Object *ob)
{
bool use_instantiation = this->export_settings.get_use_object_instantiation();
Mesh *mesh = bc_get_mesh_copy(blender_context,
ob,
this->export_settings.get_export_mesh_type(),
this->export_settings.get_apply_modifiers(),
this->export_settings.get_triangulate());
ob,
this->export_settings.get_export_mesh_type(),
this->export_settings.get_apply_modifiers(),
this->export_settings.get_triangulate());
std::string geom_id = get_geometry_id(ob, use_instantiation);
std::vector<Normal> nor;
@@ -390,7 +390,8 @@ void GeometryExporter::create_mesh_primitive_list(short material_index,
int map_index = 0;
for (int a = 0; a < totlayer_mcol; a++) {
const char *layer_name = bc_CustomData_get_layer_name(&mesh->loop_data, CD_PROP_BYTE_COLOR, a);
const char *layer_name = bc_CustomData_get_layer_name(
&mesh->loop_data, CD_PROP_BYTE_COLOR, a);
COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR,
makeUrl(makeVertexColorSourceId(geom_id, layer_name)),
(has_uvs) ? 3 : 2, /* all color layers have same index order */
@@ -580,7 +581,9 @@ bool operator<(const Normal &a, const Normal &b)
return a.x < b.x || (a.x == b.x && (a.y < b.y || (a.y == b.y && a.z < b.z)));
}
void GeometryExporter::createNormalsSource(std::string geom_id, Mesh *mesh, std::vector<Normal> &nor)
void GeometryExporter::createNormalsSource(std::string geom_id,
Mesh *mesh,
std::vector<Normal> &nor)
{
COLLADASW::FloatSourceF source(mSW);
source.setId(getIdBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL));

View File

@@ -452,11 +452,11 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh)
/* Add the data containers */
if (total_poly_count > 0) {
me->faces_num = total_poly_count;
me->totloop = total_loop_count;
BKE_mesh_face_offsets_ensure_alloc(me);
mesh->faces_num = total_poly_count;
mesh->totloop = total_loop_count;
BKE_mesh_face_offsets_ensure_alloc(mesh);
CustomData_add_layer_named(
&me->loop_data, CD_PROP_INT32, CD_SET_DEFAULT, me->totloop, ".corner_vert");
&mesh->loop_data, CD_PROP_INT32, CD_SET_DEFAULT, mesh->totloop, ".corner_vert");
uint totuvset = collada_mesh->getUVCoords().getInputInfosArray().getCount();
for (int i = 0; i < totuvset; i++) {
@@ -473,10 +473,10 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh)
COLLADAFW::String &uvname = info->mName;
/* Allocate space for UV_data */
CustomData_add_layer_named(
&me->loop_data, CD_PROP_FLOAT2, CD_SET_DEFAULT, me->totloop, uvname.c_str());
&mesh->loop_data, CD_PROP_FLOAT2, CD_SET_DEFAULT, mesh->totloop, uvname.c_str());
}
/* activate the first uv map */
CustomData_set_layer_active(&me->loop_data, CD_PROP_FLOAT2, 0);
CustomData_set_layer_active(&mesh->loop_data, CD_PROP_FLOAT2, 0);
}
int totcolset = collada_mesh->getColors().getInputInfosArray().getCount();
@@ -486,12 +486,12 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh)
collada_mesh->getColors().getInputInfosArray()[i];
COLLADAFW::String colname = extract_vcolname(info->mName);
CustomData_add_layer_named(
&me->loop_data, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, me->totloop, colname.c_str());
&mesh->loop_data, CD_PROP_BYTE_COLOR, CD_SET_DEFAULT, mesh->totloop, colname.c_str());
}
BKE_id_attributes_active_color_set(
&me->id, CustomData_get_layer_name(&me->loop_data, CD_PROP_BYTE_COLOR, 0));
&mesh->id, CustomData_get_layer_name(&mesh->loop_data, CD_PROP_BYTE_COLOR, 0));
BKE_id_attributes_default_color_set(
&me->id, CustomData_get_layer_name(&me->loop_data, CD_PROP_BYTE_COLOR, 0));
&mesh->id, CustomData_get_layer_name(&mesh->loop_data, CD_PROP_BYTE_COLOR, 0));
}
}
}
@@ -566,16 +566,16 @@ void MeshImporter::mesh_add_edges(Mesh *mesh, int len)
mesh->totedge = totedge;
}
void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *mesh)
void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *blender_mesh)
{
uint loose_edge_count = get_loose_edge_count(mesh);
if (loose_edge_count > 0) {
uint face_edge_count = me->totedge;
uint face_edge_count = blender_mesh->totedge;
// uint total_edge_count = loose_edge_count + face_edge_count; /* UNUSED. */
mesh_add_edges(me, loose_edge_count);
MutableSpan<blender::int2> edges = me->edges_for_write();
mesh_add_edges(blender_mesh, loose_edge_count);
MutableSpan<blender::int2> edges = blender_mesh->edges_for_write();
blender::int2 *edge = edges.data() + face_edge_count;
COLLADAFW::MeshPrimitiveArray &prim_arr = mesh->getMeshPrimitives();
@@ -603,24 +603,24 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
{
uint i;
allocate_poly_data(collada_mesh, me);
allocate_poly_data(collada_mesh, mesh);
UVDataWrapper uvs(collada_mesh->getUVCoords());
VCOLDataWrapper vcol(collada_mesh->getColors());
MutableSpan<int> face_offsets = me->face_offsets_for_write();
MutableSpan<int> corner_verts = me->corner_verts_for_write();
MutableSpan<int> face_offsets = mesh->face_offsets_for_write();
MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
int face_index = 0;
int loop_index = 0;
MaterialIdPrimitiveArrayMap mat_prim_map;
int *material_indices = BKE_mesh_material_indices_for_write(me);
int *material_indices = BKE_mesh_material_indices_for_write(mesh);
bool *sharp_faces = static_cast<bool *>(CustomData_get_layer_named_for_write(
&me->face_data, CD_PROP_BOOL, "sharp_face", me->faces_num));
&mesh->face_data, CD_PROP_BOOL, "sharp_face", mesh->faces_num));
if (!sharp_faces) {
sharp_faces = static_cast<bool *>(CustomData_add_layer_named(
&me->face_data, CD_PROP_BOOL, CD_SET_DEFAULT, me->faces_num, "sharp_face"));
&mesh->face_data, CD_PROP_BOOL, CD_SET_DEFAULT, mesh->faces_num, "sharp_face"));
}
COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
@@ -640,7 +640,8 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
int collada_meshtype = mp->getPrimitiveType();
/* Since we cannot set `poly->mat_nr` here, we store a portion of `me->mpoly` in Primitive. */
/* Since we cannot set `poly->mat_nr` here, we store a portion of `mesh->mpoly` in Primitive.
*/
Primitive prim = {face_index, &material_indices[face_index], 0};
/* If MeshPrimitive is TRIANGLE_FANS we split it into triangles
@@ -715,11 +716,11 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
COLLADAFW::IndexList &index_list = *index_list_array_uvcoord[uvset_index];
blender::float2 *mloopuv = static_cast<blender::float2 *>(
CustomData_get_layer_named_for_write(
&me->loop_data, CD_PROP_FLOAT2, index_list.getName().c_str(), me->totloop));
&mesh->loop_data, CD_PROP_FLOAT2, index_list.getName().c_str(), mesh->totloop));
if (mloopuv == nullptr) {
fprintf(stderr,
"Collada import: Mesh [%s] : Unknown reference to TEXCOORD [#%s].\n",
me->id.name,
mesh->id.name,
index_list.getName().c_str());
}
else {
@@ -756,11 +757,11 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
COLLADAFW::IndexList &color_index_list = *mp->getColorIndices(vcolor_index);
COLLADAFW::String colname = extract_vcolname(color_index_list.getName());
MLoopCol *mloopcol = (MLoopCol *)CustomData_get_layer_named_for_write(
&me->loop_data, CD_PROP_BYTE_COLOR, colname.c_str(), me->totloop);
&mesh->loop_data, CD_PROP_BYTE_COLOR, colname.c_str(), mesh->totloop);
if (mloopcol == nullptr) {
fprintf(stderr,
"Collada import: Mesh [%s] : Unknown reference to VCOLOR [#%s].\n",
me->id.name,
mesh->id.name,
color_index_list.getName().c_str());
}
else {
@@ -784,7 +785,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
if (invalid_loop_holes > 0) {
fprintf(stderr,
"Collada import: Mesh [%s] : contains %d unsupported loops (holes).\n",
me->id.name,
mesh->id.name,
invalid_loop_holes);
}
}
@@ -892,8 +893,8 @@ std::string *MeshImporter::get_geometry_name(const std::string &mesh_name)
static bool bc_has_out_of_bound_indices(Mesh *mesh)
{
for (const int vert_i : me->corner_verts()) {
if (vert_i >= me->totvert) {
for (const int vert_i : mesh->corner_verts()) {
if (vert_i >= mesh->totvert) {
return true;
}
}
@@ -937,7 +938,7 @@ static void bc_copy_materials_to_data(Object *ob, Mesh *mesh)
{
for (int index = 0; index < ob->totcol; index++) {
ob->matbits[index] = 0;
me->mat[index] = ob->mat[index];
mesh->mat[index] = ob->mat[index];
}
}
@@ -959,7 +960,7 @@ std::vector<Object *> MeshImporter::get_all_users_of(Mesh *reference_mesh)
if (bc_is_marked(ob)) {
bc_remove_mark(ob);
Mesh *mesh = (Mesh *)ob->data;
if (me == reference_mesh) {
if (mesh == reference_mesh) {
mesh_users.push_back(ob);
}
}
@@ -971,14 +972,14 @@ void MeshImporter::optimize_material_assignements()
{
for (Object *ob : imported_objects) {
Mesh *mesh = (Mesh *)ob->data;
if (ID_REAL_USERS(&me->id) == 1) {
bc_copy_materials_to_data(ob, me);
bc_remove_materials_from_object(ob, me);
if (ID_REAL_USERS(&mesh->id) == 1) {
bc_copy_materials_to_data(ob, mesh);
bc_remove_materials_from_object(ob, mesh);
bc_remove_mark(ob);
}
else if (ID_REAL_USERS(&me->id) > 1) {
else if (ID_REAL_USERS(&mesh->id) > 1) {
bool can_move = true;
std::vector<Object *> mesh_users = get_all_users_of(me);
std::vector<Object *> mesh_users = get_all_users_of(mesh);
if (mesh_users.size() > 1) {
Object *ref_ob = mesh_users[0];
for (int index = 1; index < mesh_users.size(); index++) {
@@ -988,9 +989,9 @@ void MeshImporter::optimize_material_assignements()
}
}
if (can_move) {
bc_copy_materials_to_data(ref_ob, me);
bc_copy_materials_to_data(ref_ob, mesh);
for (Object *object : mesh_users) {
bc_remove_materials_from_object(object, me);
bc_remove_materials_from_object(object, mesh);
bc_remove_mark(object);
}
}
@@ -1137,48 +1138,50 @@ bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom)
const std::string &str_geom_id = mesh->getName().empty() ? mesh->getOriginalId() :
mesh->getName();
Mesh *mesh = BKE_mesh_add(m_bmain, (char *)str_geom_id.c_str());
id_us_min(&me->id); /* is already 1 here, but will be set later in BKE_mesh_assign_object */
Mesh *blender_mesh = BKE_mesh_add(m_bmain, (char *)str_geom_id.c_str());
id_us_min(
&blender_mesh->id); /* is already 1 here, but will be set later in BKE_mesh_assign_object */
/* store the Mesh pointer to link it later with an Object
* mesh_geom_map needed to map mesh to its geometry name (for shape key naming) */
this->uid_mesh_map[mesh->getUniqueId()] = me;
this->mesh_geom_map[std::string(me->id.name)] = str_geom_id;
this->uid_mesh_map[mesh->getUniqueId()] = blender_mesh;
this->mesh_geom_map[std::string(blender_mesh->id.name)] = str_geom_id;
read_vertices(mesh, me);
read_vertices(mesh, blender_mesh);
blender::Vector<blender::float3> loop_normals;
read_polys(mesh, me, loop_normals);
read_polys(mesh, blender_mesh, loop_normals);
BKE_mesh_calc_edges(me, false, false);
BKE_mesh_calc_edges(blender_mesh, false, false);
/* We must apply custom normals after edges have been calculated, because
* BKE_mesh_set_custom_normals()'s internals expect me->medge to be populated
* BKE_mesh_set_custom_normals()'s internals expect mesh->medge to be populated
* and for the MLoops to have correct edge indices. */
if (use_custom_normals && !loop_normals.is_empty()) {
/* BKE_mesh_set_custom_normals()'s internals also expect that each corner
* has a valid vertex index, which may not be the case due to the existing
* logic in read_faces(). This check isn't necessary in the no-custom-normals
* case because the invalid MLoops get stripped in a later step. */
if (bc_has_out_of_bound_indices(me)) {
if (bc_has_out_of_bound_indices(blender_mesh)) {
fprintf(stderr, "Can't apply custom normals, encountered invalid loop vert indices!\n");
}
/* There may be a mismatch in lengths if one or more of the MeshPrimitives in
* the Geometry had missing or otherwise invalid normals. */
else if (me->totloop != loop_normals.size()) {
else if (blender_mesh->totloop != loop_normals.size()) {
fprintf(stderr,
"Can't apply custom normals, me->totloop != loop_normals.size() (%d != %d)\n",
me->totloop,
"Can't apply custom normals, mesh->totloop != loop_normals.size() (%d != %d)\n",
blender_mesh->totloop,
int(loop_normals.size()));
}
else {
BKE_mesh_set_custom_normals(me, reinterpret_cast<float(*)[3]>(loop_normals.data()));
BKE_mesh_set_custom_normals(blender_mesh,
reinterpret_cast<float(*)[3]>(loop_normals.data()));
}
}
/* read_lines() must be called after the face edges have been generated.
* Otherwise the loose edges will be silently deleted again. */
read_lines(mesh, me);
read_lines(mesh, blender_mesh);
return true;
}

View File

@@ -117,7 +117,7 @@ class MeshImporter : public MeshImporterBase {
*/
bool is_nice_mesh(COLLADAFW::Mesh *mesh);
void read_vertices(COLLADAFW::Mesh *mesh, Mesh *mesh);
void read_vertices(COLLADAFW::Mesh *mesh, Mesh *blender_mesh);
/**
* Condition 1: The Primitive has normals
@@ -159,14 +159,16 @@ class MeshImporter : public MeshImporterBase {
*
* TODO: import uv set names.
*/
void read_polys(COLLADAFW::Mesh *mesh, Mesh *mesh, blender::Vector<blender::float3> &loop_normals);
void read_polys(COLLADAFW::Mesh *mesh,
Mesh *blender_mesh,
blender::Vector<blender::float3> &loop_normals);
/**
* Read all loose edges.
* IMPORTANT: This function assumes that all edges from existing
* faces have already been generated and added to me->medge
* So this function MUST be called after read_faces() (see below)
*/
void read_lines(COLLADAFW::Mesh *mesh, Mesh *mesh);
void read_lines(COLLADAFW::Mesh *mesh, Mesh *blender_mesh);
uint get_vertex_count(COLLADAFW::Polygons *mp, int index);
void get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride);