[Bf-blender-cvs] [6a9d7139f7d] master: Cleanup: ID management: remove unused old `BKE_libblock_copy_for_localize` function.
Bastien Montagne
noreply at git.blender.org
Wed Aug 11 14:50:03 CEST 2021
Commit: 6a9d7139f7d05e0c51827a3a4b862c0547dc0513
Author: Bastien Montagne
Date: Wed Aug 11 14:49:17 2021 +0200
Branches: master
https://developer.blender.org/rB6a9d7139f7d05e0c51827a3a4b862c0547dc0513
Cleanup: ID management: remove unused old `BKE_libblock_copy_for_localize` function.
===================================================================
M source/blender/blenkernel/BKE_lib_id.h
M source/blender/blenkernel/intern/lib_id.c
A source/blender/blenkernel/intern/mesh_normals.cc.orig
===================================================================
diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index 5de669cb620..bb875f8d1c9 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -152,8 +152,6 @@ void BKE_libblock_copy_ex(struct Main *bmain,
const int orig_flag);
void *BKE_libblock_copy(struct Main *bmain, const struct ID *id) ATTR_WARN_UNUSED_RESULT
ATTR_NONNULL();
-/* Special version: used by data-block localization. */
-void *BKE_libblock_copy_for_localize(const struct ID *id);
void BKE_libblock_rename(struct Main *bmain, struct ID *id, const char *name) ATTR_NONNULL();
void BLI_libblock_ensure_unique_name(struct Main *bmain, const char *name) ATTR_NONNULL();
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 5e1027c62af..0f880d16358 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1321,14 +1321,6 @@ void *BKE_libblock_copy(Main *bmain, const ID *id)
return idn;
}
-/* XXX TODO: get rid of this useless wrapper at some point... */
-void *BKE_libblock_copy_for_localize(const ID *id)
-{
- ID *idn;
- BKE_libblock_copy_ex(NULL, id, &idn, LIB_ID_COPY_LOCALIZE | LIB_ID_COPY_NO_ANIMDATA);
- return idn;
-}
-
/* ***************** ID ************************ */
ID *BKE_libblock_find_name(struct Main *bmain, const short type, const char *name)
{
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc.orig b/source/blender/blenkernel/intern/mesh_normals.cc.orig
new file mode 100644
index 00000000000..18d384e8589
--- /dev/null
+++ b/source/blender/blenkernel/intern/mesh_normals.cc.orig
@@ -0,0 +1,2217 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bke
+ *
+ * Mesh normal calculation functions.
+ *
+ * \see bmesh_mesh_normals.c for the equivalent #BMesh functionality.
+ */
+
+#include <climits>
+
+#include "CLG_log.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BLI_alloca.h"
+#include "BLI_bitmap.h"
+
+#include "BLI_linklist.h"
+#include "BLI_linklist_stack.h"
+#include "BLI_math.h"
+#include "BLI_memarena.h"
+#include "BLI_stack.h"
+#include "BLI_task.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_customdata.h"
+#include "BKE_editmesh_cache.h"
+#include "BKE_global.h"
+#include "BKE_mesh.h"
+
+<<<<<<< Updated upstream
+#include "atomic_ops.h"
+
+// #define DEBUG_TIME
+=======
+#define DEBUG_TIME
+>>>>>>> Stashed changes
+
+#ifdef DEBUG_TIME
+# include "PIL_time.h"
+# include "PIL_time_utildefines.h"
+#endif
+
+static CLG_LogRef LOG = {"bke.mesh_normals"};
+
+/* -------------------------------------------------------------------- */
+/** \name Private Utility Functions
+ * \{ */
+
+/**
+ * A thread-safe version of #add_v3_v3 that uses a spin-lock.
+ *
+ * \note Avoid using this when the chance of contention is high.
+ */
+static void add_v3_v3_atomic(float r[3], const float a[3])
+{
+#define FLT_EQ_NONAN(_fa, _fb) (*((const uint32_t *)&_fa) == *((const uint32_t *)&_fb))
+
+ float virtual_lock = r[0];
+ while (true) {
+ /* This loops until following conditions are met:
+ * - `r[0]` has same value as virtual_lock (i.e. it did not change since last try).
+ * - `r[0]` was not `FLT_MAX`, i.e. it was not locked by another thread. */
+ const float test_lock = atomic_cas_float(&r[0], virtual_lock, FLT_MAX);
+ if (_ATOMIC_LIKELY(FLT_EQ_NONAN(test_lock, virtual_lock) && (test_lock != FLT_MAX))) {
+ break;
+ }
+ virtual_lock = test_lock;
+ }
+ virtual_lock += a[0];
+ r[1] += a[1];
+ r[2] += a[2];
+
+ /* Second atomic operation to 'release'
+ * our lock on that vector and set its first scalar value. */
+ /* Note that we do not need to loop here, since we 'locked' `r[0]`,
+ * nobody should have changed it in the mean time. */
+ virtual_lock = atomic_cas_float(&r[0], FLT_MAX, virtual_lock);
+ BLI_assert(virtual_lock == FLT_MAX);
+
+#undef FLT_EQ_NONAN
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Mesh Normal Calculation
+ * \{ */
+
+void BKE_mesh_normals_tag_dirty(Mesh *mesh)
+{
+ mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
+ mesh->runtime.cd_dirty_poly |= CD_MASK_NORMAL;
+}
+
+/**
+ * Call when there are no polygons.
+ */
+static void mesh_calc_normals_vert_fallback(MVert *mverts, int numVerts)
+{
+ for (int i = 0; i < numVerts; i++) {
+ MVert *mv = &mverts[i];
+ float no[3];
+
+ normalize_v3_v3(no, mv->co);
+ normal_float_to_short_v3(mv->no, no);
+ }
+}
+
+/* TODO(Sybren): we can probably rename this to BKE_mesh_calc_normals_mapping(),
+ * and remove the function of the same name below, as that one doesn't seem to be
+ * called anywhere. */
+void BKE_mesh_calc_normals_mapping_simple(struct Mesh *mesh)
+{
+ const bool only_face_normals = CustomData_is_referenced_layer(&mesh->vdata, CD_MVERT);
+
+ BKE_mesh_calc_normals_mapping_ex(mesh->mvert,
+ mesh->totvert,
+ mesh->mloop,
+ mesh->mpoly,
+ mesh->totloop,
+ mesh->totpoly,
+ nullptr,
+ mesh->mface,
+ mesh->totface,
+ nullptr,
+ nullptr,
+ only_face_normals);
+}
+
+/* Calculate vertex and face normals, face normals are returned in *r_faceNors if non-nullptr
+ * and vertex normals are stored in actual mverts.
+ */
+void BKE_mesh_calc_normals_mapping(MVert *mverts,
+ int numVerts,
+ const MLoop *mloop,
+ const MPoly *mpolys,
+ int numLoops,
+ int numPolys,
+ float (*r_polyNors)[3],
+ const MFace *mfaces,
+ int numFaces,
+ const int *origIndexFace,
+ float (*r_faceNors)[3])
+{
+ BKE_mesh_calc_normals_mapping_ex(mverts,
+ numVerts,
+ mloop,
+ mpolys,
+ numLoops,
+ numPolys,
+ r_polyNors,
+ mfaces,
+ numFaces,
+ origIndexFace,
+ r_faceNors,
+ false);
+}
+/* extended version of 'BKE_mesh_calc_normals_poly' with option not to calc vertex normals */
+void BKE_mesh_calc_normals_mapping_ex(MVert *mverts,
+ int numVerts,
+ const MLoop *mloop,
+ const MPoly *mpolys,
+ int numLoops,
+ int numPolys,
+ float (*r_polyNors)[3],
+ const MFace *mfaces,
+ int numFaces,
+ const int *origIndexFace,
+ float (*r_faceNors)[3],
+ const bool only_face_normals)
+{
+ float(*pnors)[3] = r_polyNors, (*fnors)[3] = r_faceNors;
+
+ if (numPolys == 0) {
+ if (only_face_normals == false) {
+ mesh_calc_normals_vert_fallback(mverts, numVerts);
+ }
+ return;
+ }
+
+ /* if we are not calculating verts and no verts were passes then we have nothing to do */
+ if ((only_face_normals == true) && (r_polyNors == nullptr) && (r_faceNors == nullptr)) {
+ CLOG_WARN(&LOG, "called with nothing to do");
+ return;
+ }
+
+ if (!pnors) {
+ pnors = (float(*)[3])MEM_calloc_arrayN((size_t)numPolys, sizeof(float[3]), __func__);
+ }
+ /* NO NEED TO ALLOC YET */
+ /* if (!fnors) fnors = MEM_calloc_arrayN(numFaces, sizeof(float[3]), "face nors mesh.c"); */
+
+ if (only_face_normals == false) {
+ /* vertex normals are optional, they require some extra calculations,
+ * so make them optional */
+ BKE_mesh_calc_normals_poly(
+ mverts, nullptr, numVerts, mloop, mpolys, numLoops, numPolys, pnors, false);
+ }
+ else {
+ /* only calc poly normals */
+ const MPoly *mp = mpolys;
+ for (int i = 0; i < numPolys; i++, mp++) {
+ BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]);
+ }
+ }
+
+ if (origIndexFace &&
+ /* fnors == r_faceNors */ /* NO NEED TO ALLOC YET */
+ fnors != nullptr &&
+ numFaces) {
+ const MFace *mf = mfaces;
+ for (int i = 0; i < numFaces; i++, mf++, origIndexFace++) {
+ if (*origIndexFace < numPolys) {
+ copy_v3_v3(fnors[i], pnors[*origIndexFace]);
+ }
+ else {
+ /* eek, we're not corresponding to polys */
+ CLOG_ERROR(&LOG, "tessellation face indices are incorrect. normals may look bad.");
+ }
+ }
+ }
+
+ if (pnors != r_polyNors) {
+ MEM_freeN
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list