[Bf-blender-cvs] [685f576a43b] temp-T97352-3d-texturing-seam-bleeding-b2: Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding-b2

Jeroen Bakker noreply at git.blender.org
Mon Oct 10 13:29:17 CEST 2022


Commit: 685f576a43bb2d9f3a23eda098091c33ccb5cc24
Author: Jeroen Bakker
Date:   Mon Oct 10 12:45:22 2022 +0200
Branches: temp-T97352-3d-texturing-seam-bleeding-b2
https://developer.blender.org/rB685f576a43bb2d9f3a23eda098091c33ccb5cc24

Merge branch 'master' into temp-T97352-3d-texturing-seam-bleeding-b2

===================================================================



===================================================================

diff --cc source/blender/blenkernel/intern/pbvh.c
index ee337e32c24,a7595952cac..890c3697c1b
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@@ -693,12 -776,6 +776,8 @@@ void BKE_pbvh_free(PBVH *pbvh
  
    MEM_SAFE_FREE(pbvh->vert_bitmap);
  
-   if (pbvh->vbo_id) {
-     GPU_pbvh_free_format(pbvh->vbo_id);
-   }
- 
 +  pbvh_pixels_free(pbvh);
 +
    MEM_freeN(pbvh);
  }
  
diff --cc source/blender/blenkernel/intern/pbvh_uv_islands.cc
index 4c9b52ac958,00000000000..a2940a6c46a
mode 100644,000000..100644
--- a/source/blender/blenkernel/intern/pbvh_uv_islands.cc
+++ b/source/blender/blenkernel/intern/pbvh_uv_islands.cc
@@@ -1,1469 -1,0 +1,1469 @@@
 +/* SPDX-License-Identifier: GPL-2.0-or-later */
 +
 +#include "pbvh_uv_islands.hh"
 +
 +#include <optional>
 +
 +namespace blender::bke::pbvh::uv_islands {
 +
 +static void uv_edge_append_to_uv_vertices(UVEdge &uv_edge)
 +{
 +  for (UVVertex *vertex : uv_edge.vertices) {
 +    vertex->uv_edges.append_non_duplicates(&uv_edge);
 +  }
 +}
 +
 +static void uv_primitive_append_to_uv_edges(UVPrimitive &uv_primitive)
 +{
 +  for (UVEdge *uv_edge : uv_primitive.edges) {
 +    uv_edge->uv_primitives.append_non_duplicates(&uv_primitive);
 +  }
 +}
 +
 +static void uv_primitive_append_to_uv_vertices(UVPrimitive &uv_primitive)
 +{
 +  for (UVEdge *uv_edge : uv_primitive.edges) {
 +    uv_edge_append_to_uv_vertices(*uv_edge);
 +  }
 +}
 +
 +/* -------------------------------------------------------------------- */
 +/** \name MeshPrimitive
 + * \{ */
 +
 +MeshUVVert *MeshPrimitive::get_other_uv_vertex(const MeshVertex *v1, const MeshVertex *v2)
 +{
 +  BLI_assert(vertices[0].vertex == v1 || vertices[1].vertex == v1 || vertices[2].vertex == v1);
 +  BLI_assert(vertices[0].vertex == v2 || vertices[1].vertex == v2 || vertices[2].vertex == v2);
 +  for (MeshUVVert &uv_vertex : vertices) {
 +    if (uv_vertex.vertex != v1 && uv_vertex.vertex != v2) {
 +      return &uv_vertex;
 +    }
 +  }
 +  return nullptr;
 +}
 +
 +bool MeshPrimitive::has_shared_uv_edge(const MeshPrimitive *other) const
 +{
 +  int shared_uv_verts = 0;
 +  for (const MeshUVVert &vert : vertices) {
 +    for (const MeshUVVert &other_vert : other->vertices) {
 +      if (vert.uv == other_vert.uv) {
 +        shared_uv_verts += 1;
 +      }
 +    }
 +  }
 +  return shared_uv_verts >= 2;
 +}
 +
 +static const MeshUVVert &get_uv_vert(const MeshPrimitive &mesh_primitive, const MeshVertex *vert)
 +{
 +  for (const MeshUVVert &uv_vert : mesh_primitive.vertices) {
 +    if (uv_vert.vertex == vert) {
 +      return uv_vert;
 +    }
 +  }
 +  BLI_assert_unreachable();
 +  return mesh_primitive.vertices[0];
 +}
 +
- const bool has_vertex(const MeshPrimitive &mesh_primitive, const MeshVertex &mesh_vertex)
++static const bool has_vertex(const MeshPrimitive &mesh_primitive, const MeshVertex &mesh_vertex)
 +{
 +  for (int i = 0; i < 3; i++) {
 +    if (mesh_primitive.vertices[i].vertex == &mesh_vertex) {
 +      return true;
 +    }
 +  }
 +  return false;
 +}
 +
 +rctf MeshPrimitive::uv_bounds() const
 +{
 +  rctf result;
 +  BLI_rctf_init_minmax(&result);
 +  for (const MeshUVVert &uv_vertex : vertices) {
 +    BLI_rctf_do_minmax_v(&result, uv_vertex.uv);
 +  }
 +  return result;
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name MeshData
 + * \{ */
 +
 +static void mesh_data_init_vertices(MeshData &mesh_data)
 +{
 +  mesh_data.vertices.reserve(mesh_data.vert_len);
 +  for (int64_t i = 0; i < mesh_data.vert_len; i++) {
 +    MeshVertex vert;
 +    vert.v = i;
 +    mesh_data.vertices.append(vert);
 +  }
 +}
 +
 +static void mesh_data_init_primitives(MeshData &mesh_data)
 +{
 +  mesh_data.primitives.reserve(mesh_data.looptri_len);
 +  for (int64_t i = 0; i < mesh_data.looptri_len; i++) {
 +    const MLoopTri &tri = mesh_data.looptri[i];
 +    MeshPrimitive primitive;
 +    primitive.index = i;
 +    primitive.poly = tri.poly;
 +
 +    for (int j = 0; j < 3; j++) {
 +      MeshUVVert uv_vert;
 +      uv_vert.loop = tri.tri[j];
 +      uv_vert.vertex = &mesh_data.vertices[mesh_data.mloop[uv_vert.loop].v];
 +      uv_vert.uv = mesh_data.mloopuv[uv_vert.loop].uv;
 +      primitive.vertices.append(uv_vert);
 +    }
 +    mesh_data.primitives.append(primitive);
 +  }
 +}
 +
- void mesh_data_init_edges(MeshData &mesh_data)
++static void mesh_data_init_edges(MeshData &mesh_data)
 +{
 +  mesh_data.edges.reserve(mesh_data.looptri_len * 2);
 +  EdgeHash *eh = BLI_edgehash_new_ex(__func__, mesh_data.looptri_len * 3);
 +  for (int64_t i = 0; i < mesh_data.looptri_len; i++) {
 +    const MLoopTri &tri = mesh_data.looptri[i];
 +    MeshPrimitive &primitive = mesh_data.primitives[i];
 +    for (int j = 0; j < 3; j++) {
 +      int v1 = mesh_data.mloop[tri.tri[j]].v;
 +      int v2 = mesh_data.mloop[tri.tri[(j + 1) % 3]].v;
 +
 +      void **edge_index_ptr;
 +      int64_t edge_index;
 +      if (BLI_edgehash_ensure_p(eh, v1, v2, &edge_index_ptr)) {
 +        edge_index = POINTER_AS_INT(*edge_index_ptr) - 1;
 +        *edge_index_ptr = POINTER_FROM_INT(edge_index);
 +      }
 +      else {
 +        edge_index = mesh_data.edges.size();
 +        *edge_index_ptr = POINTER_FROM_INT(edge_index + 1);
 +        MeshEdge edge;
 +        edge.vert1 = &mesh_data.vertices[v1];
 +        edge.vert2 = &mesh_data.vertices[v2];
 +        mesh_data.edges.append(edge);
 +        MeshEdge *edge_ptr = &mesh_data.edges.last();
 +        mesh_data.vertices[v1].edges.append(edge_ptr);
 +        mesh_data.vertices[v2].edges.append(edge_ptr);
 +      }
 +
 +      MeshEdge *edge = &mesh_data.edges[edge_index];
 +      edge->primitives.append(&primitive);
 +      primitive.edges.append(edge);
 +    }
 +  }
 +  BLI_edgehash_free(eh, nullptr);
 +}
 +static const int64_t INVALID_UV_ISLAND_ID = -1;
 +/**
 + * NOTE: doesn't support weird topology where unconnected mesh primitives share the same uv
 + * island. For a accurate implementation we should use implement an uv_prim_lookup.
 + */
 +static void extract_uv_neighbors(Vector<MeshPrimitive *> &prims_to_add, MeshPrimitive *primitive)
 +{
 +  for (MeshEdge *edge : primitive->edges) {
 +    for (MeshPrimitive *other_primitive : edge->primitives) {
 +      if (primitive == other_primitive) {
 +        continue;
 +      }
 +      if (other_primitive->uv_island_id != INVALID_UV_ISLAND_ID) {
 +        continue;
 +      }
 +
 +      if (primitive->has_shared_uv_edge(other_primitive)) {
 +        prims_to_add.append(other_primitive);
 +      }
 +    }
 +  }
 +}
 +
- void mesh_data_init_primitive_uv_island_ids(MeshData &mesh_data)
++static void mesh_data_init_primitive_uv_island_ids(MeshData &mesh_data)
 +{
 +  for (MeshPrimitive &primitive : mesh_data.primitives) {
 +    primitive.uv_island_id = INVALID_UV_ISLAND_ID;
 +  }
 +
 +  int64_t uv_island_id = 0;
 +  Vector<MeshPrimitive *> prims_to_add;
 +  for (MeshPrimitive &primitive : mesh_data.primitives) {
 +    /* Early exit when uv island id is already extracted during uv neighbor extractions. */
 +    if (primitive.uv_island_id != INVALID_UV_ISLAND_ID) {
 +      continue;
 +    }
 +
 +    prims_to_add.append(&primitive);
 +    while (!prims_to_add.is_empty()) {
 +      MeshPrimitive *primitive = prims_to_add.pop_last();
 +      primitive->uv_island_id = uv_island_id;
 +      extract_uv_neighbors(prims_to_add, primitive);
 +    }
 +    uv_island_id++;
 +  }
 +  mesh_data.uv_island_len = uv_island_id;
 +}
 +
 +static void mesh_data_init(MeshData &mesh_data)
 +{
 +  mesh_data_init_vertices(mesh_data);
 +  mesh_data_init_primitives(mesh_data);
 +  mesh_data_init_edges(mesh_data);
 +  mesh_data_init_primitive_uv_island_ids(mesh_data);
 +}
 +
 +MeshData::MeshData(const MLoopTri *looptri,
 +                   const int64_t looptri_len,
 +                   const int64_t vert_len,
 +                   const MLoop *mloop,
 +                   const MLoopUV *mloopuv)
 +    : looptri(looptri),
 +      looptri_len(looptri_len),
 +      vert_len(vert_len),
 +      mloop(mloop),
 +      mloopuv(mloopuv)
 +{
 +  mesh_data_init(*this);
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name UVVertex
 + * \{ */
 +
 +static void uv_vertex_init_flags(UVVertex &uv_vertex)
 +{
 +  uv_vertex.flags.is_border = false;
 +  uv_vertex.flags.is_extended = false;
 +}
 +
 +UVVertex::UVVertex()
 +{
 +  uv_vertex_init_flags(*this);
 +}
 +
 +UVVertex::UVVertex(const MeshUVVert &vert) : vertex(vert.vertex), uv(vert.uv)
 +{
 +  uv_vertex_init_flags(*this);
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/** \name UVEdge
 + * \{ */
 +
 +bool UVEdge::has_shared_edge(const MeshUVVert &v1, const MeshUVVert &v2) const
 +{
 +  return (vertices[0]->uv == v1.uv && vertices[1]->uv == v2.uv) ||
 +         (vertices[0]->uv == v2.uv && vertices[1]->uv == v1.uv);
 +}
 +
 +bool UVEdge::has_shared_edge(const UVVertex &v1, const UVVertex &v2) const
 +{
 +  return (vertices[0]->uv == v1.uv && vertices[1]->uv == v2.uv) ||
 +         (vertices[0]->uv == v2.uv && vertices[1]->uv == v1.uv);
 +}
 +
 +bool UVEdge::has_shared_edge(const UVEdge &other) const
 +{
 +  return has_shared_edge(*other.vertices[0], *other.vertices[1]);
 +}
 +
 +bool UVEdge::has_same_vertices(const MeshVertex &vert1, const MeshVertex &vert2) const
 +{
 +  return (vertices[0]->vertex == &vert1 && vertices[1]->vertex == &vert2) ||
 +         (vertices[0]->vertex == &vert2 && vertices[1]->vertex == &vert1);
 +}
 +
 +bool UVEdge::has_same_uv_vertices(const UVEdge &other) const
 +{
 +  return has_shared_edge(other) &&
 +         has_same_vertices(*other.vertices[0]->vertex, *other.vertices[1]->vertex);
 +  ;
 +}
 +
 +bool UVEdge::has_same_vertices(const MeshEdge &edge) const
 +{
 +  return has_same_vertices(*edge.vert1, *edge.vert2);
 +}
 +
 +bool UVEdge::is_border_edge() const
 +{
 +  return uv_primitives.size() == 1;
 +}
 +
 +UVVertex *UVEdge::get_other_uv_vertex(const MeshVertex *vertex)
 +{
 +  if (vertices[0]->vertex == vertex) {
 +    return vertices[1];
 +  }
 +  return vertices[0];
 +}
 +
 +/** \} */
 +
 +/* -------------------------------------------------------------------- */
 +/

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list