Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_array.h28
-rw-r--r--source/blender/blenlib/BLI_bpath.h72
-rw-r--r--source/blender/blenlib/BLI_listbase.h4
-rw-r--r--source/blender/blenlib/BLI_math_geom.h2
-rw-r--r--source/blender/blenlib/BLI_math_matrix.h8
-rw-r--r--source/blender/blenlib/BLI_path_util.h2
-rw-r--r--source/blender/blenlib/BLI_pbvh.h270
-rw-r--r--source/blender/blenlib/CMakeLists.txt8
-rw-r--r--source/blender/blenlib/SConscript32
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c23
-rw-r--r--source/blender/blenlib/intern/BLI_kdopbvh.c2
-rw-r--r--source/blender/blenlib/intern/bpath.c733
-rw-r--r--source/blender/blenlib/intern/endian_switch.c2
-rw-r--r--source/blender/blenlib/intern/fileops.c2
-rw-r--r--source/blender/blenlib/intern/freetypefont.c2
-rw-r--r--source/blender/blenlib/intern/listbase.c2
-rw-r--r--source/blender/blenlib/intern/math_geom.c38
-rw-r--r--source/blender/blenlib/intern/math_matrix.c150
-rw-r--r--source/blender/blenlib/intern/math_rotation.c32
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c2
-rw-r--r--source/blender/blenlib/intern/path_util.c2
-rw-r--r--source/blender/blenlib/intern/pbvh.c1911
-rw-r--r--source/blender/blenlib/intern/rct.c8
-rw-r--r--source/blender/blenlib/intern/winstuff.c2
24 files changed, 212 insertions, 3125 deletions
diff --git a/source/blender/blenlib/BLI_array.h b/source/blender/blenlib/BLI_array.h
index a21778307c1..6d34b0d48d5 100644
--- a/source/blender/blenlib/BLI_array.h
+++ b/source/blender/blenlib/BLI_array.h
@@ -196,3 +196,31 @@
if (_##arr##_is_static) { \
MEM_freeN(arr); \
} (void)0
+
+
+/* alloca */
+#ifdef _MSC_VER
+# define alloca _alloca
+#endif
+
+#if defined(__MINGW32__)
+# include <malloc.h> /* mingw needs for alloca() */
+#endif
+
+#if defined(__GNUC__) || defined(__clang__)
+#define BLI_array_alloca(arr, realsize) \
+ (typeof(arr))alloca(sizeof(*arr) * (realsize))
+
+#define BLI_array_alloca_and_count(arr, realsize) \
+ (typeof(arr))alloca(sizeof(*arr) * (realsize)); \
+ const int _##arr##_count = (realsize)
+
+#else
+#define BLI_array_alloca(arr, realsize) \
+ alloca(sizeof(*arr) * (realsize))
+
+#define BLI_array_alloca_and_count(arr, realsize) \
+ alloca(sizeof(*arr) * (realsize)); \
+ const int _##arr##_count = (realsize)
+#endif
+
diff --git a/source/blender/blenlib/BLI_bpath.h b/source/blender/blenlib/BLI_bpath.h
deleted file mode 100644
index 438bffb2fc5..00000000000
--- a/source/blender/blenlib/BLI_bpath.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BLI_bpath.h
- * \ingroup bli
- * \attention Based on ghash, difference is ghash is not a fixed size,
- * so for BPath we don't need to malloc
- */
-
-#ifndef __BLI_BPATH_H__
-#define __BLI_BPATH_H__
-
-struct ID;
-struct ListBase;
-struct Main;
-struct ReportList;
-
-/* Function that does something with an ID's file path. Should return 1 if the
- * path has changed, and in that case, should write the result to pathOut. */
-typedef int (*BPathVisitor)(void *userdata, char *path_dst, const char *path_src);
-/* Executes 'visit' for each path associated with 'id'. */
-void BLI_bpath_traverse_id(struct Main *bmain, struct ID *id, BPathVisitor visit_cb, const int flag, void *userdata);
-void BLI_bpath_traverse_id_list(struct Main *bmain, struct ListBase *lb, BPathVisitor visit_cb, const int flag, void *userdata);
-void BLI_bpath_traverse_main(struct Main *bmain, BPathVisitor visit_cb, const int flag, void *userdata);
-int BLI_bpath_relocate_visitor(void *oldbasepath, char *path_dst, const char *path_src);
-
-/* Functions for temp backup/restore of paths, path count must NOT change */
-void *BLI_bpath_list_backup(struct Main *bmain, const int flag);
-void BLI_bpath_list_restore(struct Main *bmain, const int flag, void *ls_handle);
-void BLI_bpath_list_free(void *ls_handle);
-
-#define BLI_BPATH_TRAVERSE_ABS (1 << 0) /* convert paths to absolute */
-#define BLI_BPATH_TRAVERSE_SKIP_LIBRARY (1 << 2) /* skip library paths */
-#define BLI_BPATH_TRAVERSE_SKIP_PACKED (1 << 3) /* skip packed data */
-#define BLI_BPATH_TRAVERSE_SKIP_MULTIFILE (1 << 4) /* skip paths where a single dir is used with an array of files, eg.
- * sequence strip images and pointcache. in this case only use the first
- * file, this is needed for directory manipulation functions which might
- * otherwise modify the same directory multiple times */
-
-/* high level funcs */
-
-/* creates a text file with missing files if there are any */
-void BLI_bpath_missing_files_check(struct Main *bmain, struct ReportList *reports);
-void BLI_bpath_missing_files_find(struct Main *bmain, const char *searchpath, struct ReportList *reports);
-void BLI_bpath_relative_convert(struct Main *bmain, const char *basedir, struct ReportList *reports);
-void BLI_bpath_absolute_convert(struct Main *bmain, const char *basedir, struct ReportList *reports);
-
-#endif /* __BLI_BPATH_H__ */
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index 1330a74bea3..d06956e39de 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -41,7 +41,7 @@ extern "C" {
#endif
void BLI_insertlink(struct ListBase *listbase, void *vprevlink, void *vnewlink);
-int BLI_findindex(const struct ListBase *listbase, void *vlink);
+int BLI_findindex(const struct ListBase *listbase, const void *vlink);
int BLI_findstringindex(const struct ListBase *listbase, const char *id, const int offset);
/* find forwards */
@@ -79,4 +79,4 @@ struct LinkData *BLI_genericNodeN(void *data);
}
#endif
-#endif
+#endif /* __BLI_LISTBASE_H__ */
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index cfd163d4e57..423765bad3d 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -202,7 +202,7 @@ void perspective_m4(float mat[4][4], const float left, const float right,
const float bottom, const float top, const float nearClip, const float farClip);
void orthographic_m4(float mat[4][4], const float left, const float right,
const float bottom, const float top, const float nearClip, const float farClip);
-void window_translate_m4(float winmat[][4], float perspmat[][4],
+void window_translate_m4(float winmat[4][4], float perspmat[4][4],
const float x, const float y);
int box_clip_bounds_m4(float boundbox[2][3],
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index f51bd1cf840..c12ec62ca1b 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -144,10 +144,14 @@ float determinant_m2(float a, float b,
float determinant_m3(float a, float b, float c,
float d, float e, float f,
float g, float h, float i);
+float determinant_m3_array(float m[3][3]);
float determinant_m4(float A[4][4]);
+#define PSEUDOINVERSE_EPSILON 1e-8f
+
void svd_m4(float U[4][4], float s[4], float V[4][4], float A[4][4]);
void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon);
+void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon);
/****************************** Transformations ******************************/
@@ -167,8 +171,8 @@ void translate_m4(float mat[4][4], float tx, float ty, float tz);
void rotate_m4(float mat[4][4], const char axis, const float angle);
-void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[][3]);
-void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4]);
+void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]);
+void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4]);
void loc_eul_size_to_mat4(float R[4][4],
const float loc[3], const float eul[3], const float size[3]);
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index 5e47adf25ef..557ecb3dd0c 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -67,6 +67,8 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check);
#define BLENDER_RESOURCE_PATH_SYSTEM 2
#define BLENDER_STARTUP_FILE "startup.blend"
+#define BLENDER_USERPREF_FILE "userpref.blend"
+#define BLENDER_QUIT_FILE "quit.blend"
#define BLENDER_BOOKMARK_FILE "bookmarks.txt"
#define BLENDER_HISTORY_FILE "recent-files.txt"
diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h
deleted file mode 100644
index 59ecdb359c9..00000000000
--- a/source/blender/blenlib/BLI_pbvh.h
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __BLI_PBVH_H__
-#define __BLI_PBVH_H__
-
-/** \file BLI_pbvh.h
- * \ingroup bli
- * \brief A BVH for high poly meshes.
- */
-
-#include "BLI_bitmap.h"
-
-struct CCGElem;
-struct CCGKey;
-struct CustomData;
-struct DMFlagMat;
-struct DMGridAdjacency;
-struct ListBase;
-struct MFace;
-struct MVert;
-struct PBVH;
-struct PBVHNode;
-
-typedef struct PBVH PBVH;
-typedef struct PBVHNode PBVHNode;
-
-typedef struct {
- float (*co)[3];
-} PBVHProxyNode;
-
-/* Callbacks */
-
-/* returns 1 if the search should continue from this node, 0 otherwise */
-typedef int (*BLI_pbvh_SearchCallback)(PBVHNode *node, void *data);
-
-typedef void (*BLI_pbvh_HitCallback)(PBVHNode *node, void *data);
-typedef void (*BLI_pbvh_HitOccludedCallback)(PBVHNode *node, void *data, float *tmin);
-
-/* Building */
-
-PBVH *BLI_pbvh_new(void);
-void BLI_pbvh_build_mesh(PBVH *bvh, struct MFace *faces, struct MVert *verts,
- int totface, int totvert, struct CustomData *vdata);
-void BLI_pbvh_build_grids(PBVH *bvh, struct CCGElem **grid_elems,
- struct DMGridAdjacency *gridadj, int totgrid,
- struct CCGKey *key, void **gridfaces, struct DMFlagMat *flagmats,
- unsigned int **grid_hidden);
-void BLI_pbvh_free(PBVH *bvh);
-
-/* Hierarchical Search in the BVH, two methods:
- * - for each hit calling a callback
- * - gather nodes in an array (easy to multithread) */
-
-void BLI_pbvh_search_callback(PBVH *bvh,
- BLI_pbvh_SearchCallback scb, void *search_data,
- BLI_pbvh_HitCallback hcb, void *hit_data);
-
-void BLI_pbvh_search_gather(PBVH *bvh,
- BLI_pbvh_SearchCallback scb, void *search_data,
- PBVHNode ***array, int *tot);
-
-/* Raycast
- * the hit callback is called for all leaf nodes intersecting the ray;
- * it's up to the callback to find the primitive within the leaves that is
- * hit first */
-
-void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data,
- const float ray_start[3], const float ray_normal[3],
- int original);
-
-int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
- const float ray_start[3], const float ray_normal[3],
- float *dist);
-
-/* Drawing */
-
-void BLI_pbvh_node_draw(PBVHNode *node, void *data);
-void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
- int (*setMaterial)(int, void *attribs));
-
-/* PBVH Access */
-typedef enum {
- PBVH_FACES,
- PBVH_GRIDS,
-} PBVHType;
-
-PBVHType BLI_pbvh_type(const PBVH *bvh);
-
-/* multires hidden data, only valid for type == PBVH_GRIDS */
-unsigned int **BLI_pbvh_grid_hidden(const PBVH *bvh);
-
-/* multires level, only valid for type == PBVH_GRIDS */
-void BLI_pbvh_get_grid_key(const PBVH *pbvh, struct CCGKey *key);
-
-/* Node Access */
-
-typedef enum {
- PBVH_Leaf = 1,
-
- PBVH_UpdateNormals = 2,
- PBVH_UpdateBB = 4,
- PBVH_UpdateOriginalBB = 8,
- PBVH_UpdateDrawBuffers = 16,
- PBVH_UpdateRedraw = 32,
-
- PBVH_RebuildDrawBuffers = 64,
- PBVH_FullyHidden = 128
-} PBVHNodeFlags;
-
-void BLI_pbvh_node_mark_update(PBVHNode *node);
-void BLI_pbvh_node_mark_rebuild_draw(PBVHNode *node);
-void BLI_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden);
-
-void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node,
- int **grid_indices, int *totgrid, int *maxgrid, int *gridsize,
- struct CCGElem ***grid_elems, struct DMGridAdjacency **gridadj);
-void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node,
- int *uniquevert, int *totvert);
-void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node,
- int **vert_indices, struct MVert **verts);
-
-void BLI_pbvh_node_get_BB(PBVHNode * node, float bb_min[3], float bb_max[3]);
-void BLI_pbvh_node_get_original_BB(PBVHNode * node, float bb_min[3], float bb_max[3]);
-
-float BLI_pbvh_node_get_tmin(PBVHNode *node);
-
-/* test if AABB is at least partially inside the planes' volume */
-int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data);
-/* test if AABB is at least partially outside the planes' volume */
-int BLI_pbvh_node_planes_exclude_AABB(PBVHNode *node, void *data);
-
-/* Update Normals/Bounding Box/Draw Buffers/Redraw and clear flags */
-
-void BLI_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
-void BLI_pbvh_redraw_BB(PBVH * bvh, float bb_min[3], float bb_max[3]);
-void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface);
-void BLI_pbvh_grids_update(PBVH *bvh, struct CCGElem **grid_elems,
- struct DMGridAdjacency *gridadj, void **gridfaces,
- struct DMFlagMat *flagmats, unsigned int **grid_hidden);
-
-/* vertex deformer */
-float (*BLI_pbvh_get_vertCos(struct PBVH *pbvh))[3];
-void BLI_pbvh_apply_vertCos(struct PBVH *pbvh, float (*vertCos)[3]);
-int BLI_pbvh_isDeformed(struct PBVH *pbvh);
-
-
-/* Vertex Iterator */
-
-/* this iterator has quite a lot of code, but it's designed to:
- * - allow the compiler to eliminate dead code and variables
- * - spend most of the time in the relatively simple inner loop */
-
-/* note: PBVH_ITER_ALL does not skip hidden vertices,
- * PBVH_ITER_UNIQUE does */
-#define PBVH_ITER_ALL 0
-#define PBVH_ITER_UNIQUE 1
-
-typedef struct PBVHVertexIter {
- /* iteration */
- int g;
- int width;
- int height;
- int gx;
- int gy;
- int i;
-
- /* grid */
- struct CCGElem **grids;
- struct CCGElem *grid;
- struct CCGKey *key;
- BLI_bitmap *grid_hidden, gh;
- int *grid_indices;
- int totgrid;
- int gridsize;
-
- /* mesh */
- struct MVert *mverts;
- int totvert;
- int *vert_indices;
- float *vmask;
-
- /* result: these are all computed in the macro, but we assume
- * that compiler optimization's will skip the ones we don't use */
- struct MVert *mvert;
- float *co;
- short *no;
- float *fno;
- float *mask;
-} PBVHVertexIter;
-
-#ifdef _MSC_VER
-#pragma warning (disable:4127) // conditional expression is constant
-#endif
-
-void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
- PBVHVertexIter *vi, int mode);
-
-#define BLI_pbvh_vertex_iter_begin(bvh, node, vi, mode) \
- pbvh_vertex_iter_init(bvh, node, &vi, mode); \
- \
- for (vi.i = 0, vi.g = 0; vi.g < vi.totgrid; vi.g++) { \
- if (vi.grids) { \
- vi.width = vi.gridsize; \
- vi.height = vi.gridsize; \
- vi.grid = vi.grids[vi.grid_indices[vi.g]]; \
- if (mode == PBVH_ITER_UNIQUE) \
- vi.gh = vi.grid_hidden[vi.grid_indices[vi.g]]; \
- } \
- else { \
- vi.width = vi.totvert; \
- vi.height = 1; \
- } \
- \
- for (vi.gy = 0; vi.gy < vi.height; vi.gy++) { \
- for (vi.gx = 0; vi.gx < vi.width; vi.gx++, vi.i++) { \
- if (vi.grid) { \
- vi.co = CCG_elem_co(vi.key, vi.grid); \
- vi.fno = CCG_elem_no(vi.key, vi.grid); \
- vi.mask = vi.key->has_mask ? CCG_elem_mask(vi.key, vi.grid) : NULL; \
- vi.grid = CCG_elem_next(vi.key, vi.grid); \
- if (vi.gh) { \
- if (BLI_BITMAP_GET(vi.gh, vi.gy * vi.gridsize + vi.gx)) \
- continue; \
- } \
- } \
- else { \
- vi.mvert = &vi.mverts[vi.vert_indices[vi.gx]]; \
- if (mode == PBVH_ITER_UNIQUE && vi.mvert->flag & ME_HIDE) \
- continue; \
- vi.co = vi.mvert->co; \
- vi.no = vi.mvert->no; \
- if (vi.vmask) \
- vi.mask = &vi.vmask[vi.vert_indices[vi.gx]]; \
- } \
-
-#define BLI_pbvh_vertex_iter_end \
- } \
- } \
- }
-
-void BLI_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *proxy_count);
-void BLI_pbvh_node_free_proxies(PBVHNode *node);
-PBVHProxyNode *BLI_pbvh_node_add_proxy(PBVH *bvh, PBVHNode *node);
-void BLI_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***nodes, int *totnode);
-
-//void BLI_pbvh_node_BB_reset(PBVHNode *node);
-//void BLI_pbvh_node_BB_expand(PBVHNode *node, float co[3]);
-
-void pbvh_show_diffuse_color_set(PBVH *bvh, int show_diffuse_color);
-
-#endif /* __BLI_PBVH_H__ */
-
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 8a3b1c9675b..6644c58611f 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -25,9 +25,7 @@
set(INC
.
- ../blenkernel
- ../blenloader
- ../gpu
+ # ../blenkernel # dont add this back!
../makesdna
../../../intern/ghost
../../../intern/guardedalloc
@@ -50,7 +48,6 @@ set(SRC
intern/BLI_mempool.c
intern/DLRB_tree.c
intern/boxpack2d.c
- intern/bpath.c
intern/callbacks.c
intern/cpu.c
intern/dynlib.c
@@ -78,7 +75,6 @@ set(SRC
intern/md5.c
intern/noise.c
intern/path_util.c
- intern/pbvh.c
intern/quadric.c
intern/rand.c
intern/rct.c
@@ -101,7 +97,6 @@ set(SRC
BLI_bitmap.h
BLI_blenlib.h
BLI_boxpack2d.h
- BLI_bpath.h
BLI_callbacks.h
BLI_cpu.h
BLI_dlrbTree.h
@@ -137,7 +132,6 @@ set(SRC
BLI_mempool.h
BLI_noise.h
BLI_path_util.h
- BLI_pbvh.h
BLI_quadric.h
BLI_rand.h
BLI_rect.h
diff --git a/source/blender/blenlib/SConscript b/source/blender/blenlib/SConscript
index e53f622a5c4..2be06f7311d 100644
--- a/source/blender/blenlib/SConscript
+++ b/source/blender/blenlib/SConscript
@@ -1,11 +1,37 @@
-#!/usr/bin/python
+#!/usr/bin/env python
+#
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# 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) 2006, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Nathan Letwory.
+#
+# ***** END GPL LICENSE BLOCK *****
+
Import ('env')
sources = env.Glob('intern/*.c')
cflags=''
-incs = '. ../makesdna ../blenkernel #/intern/guardedalloc #/intern/ghost ../editors/include ../gpu ../blenloader'
-incs += ' ../windowmanager ../bmesh #/extern/glew/include'
+# don't add ../blenkernel back!
+incs = '. ../makesdna #/intern/guardedalloc #/intern/ghost'
incs += ' ' + env['BF_FREETYPE_INC']
incs += ' ' + env['BF_ZLIB_INC']
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index c4094920c2a..7d2fc38272d 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -39,7 +39,7 @@
#include "BLI_mempool.h"
#include "BLI_ghash.h"
-#include "BLO_sys_types.h" // for intptr_t support
+#include "MEM_sys_types.h" /* for intptr_t support */
/***/
unsigned int hashsizes[] = {
@@ -312,17 +312,25 @@ int BLI_ghashutil_intcmp(const void *a, const void *b)
return (a < b) ? -1 : 1;
}
+/**
+ * This function implements the widely used "djb" hash apparently posted
+ * by Daniel Bernstein to comp.lang.c some time ago. The 32 bit
+ * unsigned hash value starts at 5381 and for each byte 'c' in the
+ * string, is updated: <literal>hash = hash * 33 + c</literal>. This
+ * function uses the signed value of each byte.
+ *
+ * note: this is the same hash method that glib 2.34.0 uses.
+ */
unsigned int BLI_ghashutil_strhash(const void *ptr)
{
- const char *s = ptr;
- unsigned int i = 0;
- unsigned char c;
+ const signed char *p;
+ unsigned int h = 5381;
- while ((c = *s++)) {
- i = i * 37 + c;
+ for (p = ptr; *p != '\0'; p++) {
+ h = (h << 5) + h + *p;
}
- return i;
+ return h;
}
int BLI_ghashutil_strcmp(const void *a, const void *b)
{
@@ -376,4 +384,3 @@ void BLI_ghashutil_pairfree(void *ptr)
{
MEM_freeN((void *)ptr);
}
-
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c
index 6cf167b8823..55f67cedfc6 100644
--- a/source/blender/blenlib/intern/BLI_kdopbvh.c
+++ b/source/blender/blenlib/intern/BLI_kdopbvh.c
@@ -1237,7 +1237,7 @@ static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node)
#define DEFAULT_FIND_NEAREST_HEAP_SIZE 1024
-#define NodeDistance_priority(a, b) ( (a).dist < (b).dist)
+#define NodeDistance_priority(a, b) ((a).dist < (b).dist)
static void NodeDistance_push_heap(NodeDistance *heap, int heap_size)
PUSH_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size)
diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c
deleted file mode 100644
index e97ad3b11ba..00000000000
--- a/source/blender/blenlib/intern/bpath.c
+++ /dev/null
@@ -1,733 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Campbell barton, Alex Fraser
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenlib/intern/bpath.c
- * \ingroup bli
- */
-
-/* TODO,
- * currently there are some cases we don't support.
- * - passing output paths to the visitor?, like render out.
- * - passing sequence strips with many images.
- * - passing directory paths - visitors don't know which path is a dir or a file.
- * */
-
-#include <sys/stat.h>
-
-#include <string.h>
-#include <assert.h>
-
-/* path/file handling stuff */
-#ifndef WIN32
-# include <dirent.h>
-# include <unistd.h>
-#else
-# include <io.h>
-# include "BLI_winstuff.h"
-#endif
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_brush_types.h"
-#include "DNA_image_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_movieclip_types.h"
-#include "DNA_object_fluidsim.h"
-#include "DNA_object_force.h"
-#include "DNA_object_types.h"
-#include "DNA_particle_types.h"
-#include "DNA_sequence_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_text_types.h"
-#include "DNA_material_types.h"
-#include "DNA_node_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_vfont_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_smoke_types.h"
-#include "DNA_freestyle_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_bpath.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_font.h"
-#include "BKE_library.h"
-#include "BKE_main.h"
-#include "BKE_node.h"
-#include "BKE_report.h"
-#include "BKE_sequencer.h"
-#include "BKE_image.h" /* so we can check the image's type */
-
-static int checkMissingFiles_visit_cb(void *userdata, char *UNUSED(path_dst), const char *path_src)
-{
- ReportList *reports = (ReportList *)userdata;
-
- if (!BLI_exists(path_src)) {
- BKE_reportf(reports, RPT_WARNING, "Path '%s' not found", path_src);
- }
-
- return FALSE;
-}
-
-/* high level function */
-void BLI_bpath_missing_files_check(Main *bmain, ReportList *reports)
-{
- BLI_bpath_traverse_main(bmain, checkMissingFiles_visit_cb, BLI_BPATH_TRAVERSE_ABS, reports);
-}
-
-typedef struct BPathRemap_Data {
- const char *basedir;
- ReportList *reports;
-
- int count_tot;
- int count_changed;
- int count_failed;
-} BPathRemap_Data;
-
-static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char *path_src)
-{
- BPathRemap_Data *data = (BPathRemap_Data *)userdata;
-
- data->count_tot++;
-
- if (BLI_path_is_rel(path_src)) {
- return FALSE; /* already relative */
- }
- else {
- strcpy(path_dst, path_src);
- BLI_path_rel(path_dst, data->basedir);
- if (BLI_path_is_rel(path_dst)) {
- data->count_changed++;
- }
- else {
- BKE_reportf(data->reports, RPT_WARNING, "Path '%s' cannot be made relative", path_src);
- data->count_failed++;
- }
- return TRUE;
- }
-}
-
-void BLI_bpath_relative_convert(Main *bmain, const char *basedir, ReportList *reports)
-{
- BPathRemap_Data data = {NULL};
-
- if (basedir[0] == '\0') {
- printf("%s: basedir='', this is a bug\n", __func__);
- return;
- }
-
- data.basedir = basedir;
- data.reports = reports;
-
- BLI_bpath_traverse_main(bmain, makeFilesRelative_visit_cb, 0, (void *)&data);
-
- BKE_reportf(reports, data.count_failed ? RPT_WARNING : RPT_INFO,
- "Total files %d | Changed %d | Failed %d",
- data.count_tot, data.count_changed, data.count_failed);
-}
-
-static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char *path_src)
-{
- BPathRemap_Data *data = (BPathRemap_Data *)userdata;
-
- data->count_tot++;
-
- if (BLI_path_is_rel(path_src) == FALSE) {
- return FALSE; /* already absolute */
- }
- else {
- strcpy(path_dst, path_src);
- BLI_path_abs(path_dst, data->basedir);
- if (BLI_path_is_rel(path_dst) == FALSE) {
- data->count_changed++;
- }
- else {
- BKE_reportf(data->reports, RPT_WARNING, "Path '%s' cannot be made absolute", path_src);
- data->count_failed++;
- }
- return TRUE;
- }
-}
-
-/* similar to BLI_bpath_relative_convert - keep in sync! */
-void BLI_bpath_absolute_convert(Main *bmain, const char *basedir, ReportList *reports)
-{
- BPathRemap_Data data = {NULL};
-
- if (basedir[0] == '\0') {
- printf("%s: basedir='', this is a bug\n", __func__);
- return;
- }
-
- data.basedir = basedir;
- data.reports = reports;
-
- BLI_bpath_traverse_main(bmain, makeFilesAbsolute_visit_cb, 0, (void *)&data);
-
- BKE_reportf(reports, data.count_failed ? RPT_WARNING : RPT_INFO,
- "Total files %d | Changed %d | Failed %d",
- data.count_tot, data.count_changed, data.count_failed);
-}
-
-/**
- * find this file recursively, use the biggest file so thumbnails don't get used by mistake
- * \param filename_new: the path will be copied here, caller must initialize as empty string.
- * \param dirname: subdir to search
- * \param filename: set this filename
- * \param filesize: filesize for the file
- *
- * \returns found: 1/0.
- */
-#define MAX_RECUR 16
-static int findFileRecursive(char *filename_new,
- const char *dirname,
- const char *filename,
- int *filesize,
- int *recur_depth)
-{
- /* file searching stuff */
- DIR *dir;
- struct dirent *de;
- struct stat status;
- char path[FILE_MAX];
- int size;
- int found = FALSE;
-
- dir = opendir(dirname);
-
- if (dir == NULL)
- return found;
-
- if (*filesize == -1)
- *filesize = 0; /* dir opened fine */
-
- while ((de = readdir(dir)) != NULL) {
-
- if (strcmp(".", de->d_name) == 0 || strcmp("..", de->d_name) == 0)
- continue;
-
- BLI_join_dirfile(path, sizeof(path), dirname, de->d_name);
-
- if (stat(path, &status) != 0)
- continue; /* cant stat, don't bother with this file, could print debug info here */
-
- if (S_ISREG(status.st_mode)) { /* is file */
- if (strncmp(filename, de->d_name, FILE_MAX) == 0) { /* name matches */
- /* open the file to read its size */
- size = status.st_size;
- if ((size > 0) && (size > *filesize)) { /* find the biggest file */
- *filesize = size;
- BLI_strncpy(filename_new, path, FILE_MAX);
- found = TRUE;
- }
- }
- }
- else if (S_ISDIR(status.st_mode)) { /* is subdir */
- if (*recur_depth <= MAX_RECUR) {
- (*recur_depth)++;
- found |= findFileRecursive(filename_new, path, filename, filesize, recur_depth);
- (*recur_depth)--;
- }
- }
- }
- closedir(dir);
- return found;
-}
-
-typedef struct BPathFind_Data {
- const char *basedir;
- char searchdir[FILE_MAX];
- ReportList *reports;
-} BPathFind_Data;
-
-static int findMissingFiles_visit_cb(void *userdata, char *path_dst, const char *path_src)
-{
- BPathFind_Data *data = (BPathFind_Data *)userdata;
- char filename_new[FILE_MAX];
-
- int filesize = -1;
- int recur_depth = 0;
- int found;
-
- filename_new[0] = '\0';
-
- found = findFileRecursive(filename_new,
- data->searchdir, BLI_path_basename((char *)path_src),
- &filesize, &recur_depth);
-
- if (filesize == -1) { /* could not open dir */
- BKE_reportf(data->reports, RPT_WARNING,
- "Could not open directory '%s'",
- BLI_path_basename(data->searchdir));
- return FALSE;
- }
- else if (found == FALSE) {
- BKE_reportf(data->reports, RPT_WARNING,
- "Could not find '%s' in '%s'",
- BLI_path_basename((char *)path_src), data->searchdir);
- return FALSE;
- }
- else {
- BLI_strncpy(path_dst, filename_new, FILE_MAX);
- return TRUE;
- }
-}
-
-void BLI_bpath_missing_files_find(Main *bmain, const char *searchpath, ReportList *reports)
-{
- struct BPathFind_Data data = {NULL};
-
- data.reports = reports;
- BLI_split_dir_part(searchpath, data.searchdir, sizeof(data.searchdir));
-
- BLI_bpath_traverse_main(bmain, findMissingFiles_visit_cb, 0, (void *)&data);
-}
-
-/* Run a visitor on a string, replacing the contents of the string as needed. */
-static int rewrite_path_fixed(char *path, BPathVisitor visit_cb, const char *absbase, void *userdata)
-{
- char path_src_buf[FILE_MAX];
- const char *path_src;
- char path_dst[FILE_MAX];
-
- if (absbase) {
- BLI_strncpy(path_src_buf, path, sizeof(path_src_buf));
- BLI_path_abs(path_src_buf, absbase);
- path_src = path_src_buf;
- }
- else {
- path_src = path;
- }
-
- if (visit_cb(userdata, path_dst, path_src)) {
- BLI_strncpy(path, path_dst, FILE_MAX);
- return TRUE;
- }
- else {
- return FALSE;
- }
-}
-
-static int rewrite_path_fixed_dirfile(char path_dir[FILE_MAXDIR],
- char path_file[FILE_MAXFILE],
- BPathVisitor visit_cb,
- const char *absbase,
- void *userdata)
-{
- char path_src[FILE_MAX];
- char path_dst[FILE_MAX];
-
- BLI_join_dirfile(path_src, sizeof(path_src), path_dir, path_file);
-
- if (absbase) {
- BLI_path_abs(path_src, absbase);
- }
-
- if (visit_cb(userdata, path_dst, (const char *)path_src)) {
- BLI_split_dirfile(path_dst, path_dir, path_file, FILE_MAXDIR, FILE_MAXFILE);
- return TRUE;
- }
- else {
- return FALSE;
- }
-}
-
-static int rewrite_path_alloc(char **path, BPathVisitor visit_cb, const char *absbase, void *userdata)
-{
- char path_src_buf[FILE_MAX];
- const char *path_src;
- char path_dst[FILE_MAX];
-
- if (absbase) {
- BLI_strncpy(path_src_buf, *path, sizeof(path_src_buf));
- BLI_path_abs(path_src_buf, absbase);
- path_src = path_src_buf;
- }
- else {
- path_src = *path;
- }
-
- if (visit_cb(userdata, path_dst, path_src)) {
- MEM_freeN((*path));
- (*path) = BLI_strdup(path_dst);
- return TRUE;
- }
- else {
- return FALSE;
- }
-}
-
-/* Run visitor function 'visit' on all paths contained in 'id'. */
-void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int flag, void *bpath_user_data)
-{
- const char *absbase = (flag & BLI_BPATH_TRAVERSE_ABS) ? ID_BLEND_PATH(bmain, id) : NULL;
-
- if ((flag & BLI_BPATH_TRAVERSE_SKIP_LIBRARY) && id->lib) {
- return;
- }
-
- switch (GS(id->name)) {
- case ID_IM:
- {
- Image *ima;
- ima = (Image *)id;
- if (ima->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
- if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
- rewrite_path_fixed(ima->name, visit_cb, absbase, bpath_user_data);
- }
- }
- break;
- }
- case ID_BR:
- {
- Brush *brush = (Brush *)id;
- if (brush->icon_filepath[0]) {
- rewrite_path_fixed(brush->icon_filepath, visit_cb, absbase, bpath_user_data);
- }
- break;
- }
- case ID_OB:
- {
- Object *ob = (Object *)id;
- ModifierData *md;
- ParticleSystem *psys;
-
-#define BPATH_TRAVERSE_POINTCACHE(ptcaches) \
- { \
- PointCache *cache; \
- for (cache = (ptcaches).first; cache; cache = cache->next) { \
- if (cache->flag & PTCACHE_DISK_CACHE) { \
- rewrite_path_fixed(cache->path, \
- visit_cb, \
- absbase, \
- bpath_user_data); \
- } \
- } \
- } (void)0
-
- /* do via modifiers instead */
-#if 0
- if (ob->fluidsimSettings) {
- rewrite_path_fixed(ob->fluidsimSettings->surfdataPath, visit_cb, absbase, bpath_user_data);
- }
-#endif
-
- for (md = ob->modifiers.first; md; md = md->next) {
- if (md->type == eModifierType_Fluidsim) {
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
- if (fluidmd->fss) {
- rewrite_path_fixed(fluidmd->fss->surfdataPath, visit_cb, absbase, bpath_user_data);
- }
- }
- else if (md->type == eModifierType_Smoke) {
- SmokeModifierData *smd = (SmokeModifierData *)md;
- if (smd->type & MOD_SMOKE_TYPE_DOMAIN) {
- BPATH_TRAVERSE_POINTCACHE(smd->domain->ptcaches[0]);
- }
- }
- else if (md->type == eModifierType_Cloth) {
- ClothModifierData *clmd = (ClothModifierData *) md;
- BPATH_TRAVERSE_POINTCACHE(clmd->ptcaches);
- }
- else if (md->type == eModifierType_Ocean) {
- OceanModifierData *omd = (OceanModifierData *) md;
- rewrite_path_fixed(omd->cachepath, visit_cb, absbase, bpath_user_data);
- }
- }
-
- if (ob->soft) {
- BPATH_TRAVERSE_POINTCACHE(ob->soft->ptcaches);
- }
-
- for (psys = ob->particlesystem.first; psys; psys = psys->next) {
- BPATH_TRAVERSE_POINTCACHE(psys->ptcaches);
- }
-
-#undef BPATH_TRAVERSE_POINTCACHE
-
- break;
- }
- case ID_SO:
- {
- bSound *sound = (bSound *)id;
- if (sound->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
- rewrite_path_fixed(sound->name, visit_cb, absbase, bpath_user_data);
- }
- break;
- }
- case ID_TXT:
- if (((Text *)id)->name) {
- rewrite_path_alloc(&((Text *)id)->name, visit_cb, absbase, bpath_user_data);
- }
- break;
- case ID_VF:
- {
- VFont *vfont = (VFont *)id;
- if (vfont->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) {
- if (BKE_vfont_is_builtin(vfont) == FALSE) {
- rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, bpath_user_data);
- }
- }
- break;
- }
- case ID_MA:
- {
- Material *ma = (Material *)id;
- bNodeTree *ntree = ma->nodetree;
-
- if (ntree) {
- bNode *node;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->type == SH_NODE_SCRIPT) {
- NodeShaderScript *nss = (NodeShaderScript *)node->storage;
- rewrite_path_fixed(nss->filepath, visit_cb, absbase, bpath_user_data);
- }
- }
- }
- break;
- }
- case ID_NT:
- {
- bNodeTree *ntree = (bNodeTree *)id;
- bNode *node;
-
- if (ntree->type == NTREE_SHADER) {
- /* same as lines above */
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->type == SH_NODE_SCRIPT) {
- NodeShaderScript *nss = (NodeShaderScript *)node->storage;
- rewrite_path_fixed(nss->filepath, visit_cb, absbase, bpath_user_data);
- }
- }
- }
- break;
- }
- case ID_TE:
- {
- Tex *tex = (Tex *)id;
- if (tex->type == TEX_VOXELDATA && TEX_VD_IS_SOURCE_PATH(tex->vd->file_format)) {
- rewrite_path_fixed(tex->vd->source_path, visit_cb, absbase, bpath_user_data);
- }
- break;
- }
- case ID_SCE:
- {
- Scene *scene = (Scene *)id;
- SceneRenderLayer *srl= scene->r.layers.first;
- if (scene->ed) {
- Sequence *seq;
-
- SEQ_BEGIN(scene->ed, seq)
- {
- if (SEQ_HAS_PATH(seq)) {
- if (ELEM(seq->type, SEQ_TYPE_MOVIE, SEQ_TYPE_SOUND_RAM)) {
- rewrite_path_fixed_dirfile(seq->strip->dir, seq->strip->stripdata->name,
- visit_cb, absbase, bpath_user_data);
- }
- else if (seq->type == SEQ_TYPE_IMAGE) {
- /* might want an option not to loop over all strips */
- StripElem *se = seq->strip->stripdata;
- int len = MEM_allocN_len(se) / sizeof(*se);
- int i;
-
- if (flag & BLI_BPATH_TRAVERSE_SKIP_MULTIFILE) {
- /* only operate on one path */
- len = MIN2(1, len);
- }
-
- for (i = 0; i < len; i++, se++) {
- rewrite_path_fixed_dirfile(seq->strip->dir, se->name,
- visit_cb, absbase, bpath_user_data);
- }
- }
- else {
- /* simple case */
- rewrite_path_fixed(seq->strip->dir, visit_cb, absbase, bpath_user_data);
- }
- }
-
- }
- SEQ_END
- }
- for(; srl; srl= srl->next) {
- FreestyleModuleConfig* module= srl->freestyleConfig.modules.first;
- for (; module; module= module->next) {
- rewrite_path_fixed(module->module_path, visit_cb, absbase, bpath_user_data);
- }
- }
- break;
- }
- case ID_ME:
- {
- Mesh *me = (Mesh *)id;
- if (me->ldata.external) {
- rewrite_path_fixed(me->ldata.external->filename, visit_cb, absbase, bpath_user_data);
- }
- break;
- }
- case ID_LI:
- {
- Library *lib = (Library *)id;
- if (rewrite_path_fixed(lib->name, visit_cb, absbase, bpath_user_data)) {
- BKE_library_filepath_set(lib, lib->name);
- }
- break;
- }
- case ID_MC:
- {
- MovieClip *clip = (MovieClip *)id;
- rewrite_path_fixed(clip->name, visit_cb, absbase, bpath_user_data);
- break;
- }
- default:
- /* Nothing to do for other IDs that don't contain file paths. */
- break;
- }
-}
-
-void BLI_bpath_traverse_id_list(Main *bmain, ListBase *lb, BPathVisitor visit_cb, const int flag, void *bpath_user_data)
-{
- ID *id;
- for (id = lb->first; id; id = id->next) {
- BLI_bpath_traverse_id(bmain, id, visit_cb, flag, bpath_user_data);
- }
-}
-
-void BLI_bpath_traverse_main(Main *bmain, BPathVisitor visit_cb, const int flag, void *bpath_user_data)
-{
- ListBase *lbarray[MAX_LIBARRAY];
- int a = set_listbasepointers(bmain, lbarray);
- while (a--) {
- BLI_bpath_traverse_id_list(bmain, lbarray[a], visit_cb, flag, bpath_user_data);
- }
-}
-
-/* Rewrites a relative path to be relative to the main file - unless the path is
- * absolute, in which case it is not altered. */
-int BLI_bpath_relocate_visitor(void *pathbase_v, char *path_dst, const char *path_src)
-{
- /* be sure there is low chance of the path being too short */
- char filepath[(FILE_MAXDIR * 2) + FILE_MAXFILE];
- const char *base_new = ((char **)pathbase_v)[0];
- const char *base_old = ((char **)pathbase_v)[1];
-
- if (BLI_path_is_rel(base_old)) {
- printf("%s: error, old base path '%s' is not absolute.\n",
- __func__, base_old);
- return FALSE;
- }
-
- /* Make referenced file absolute. This would be a side-effect of
- * BLI_cleanup_file, but we do it explicitly so we know if it changed. */
- BLI_strncpy(filepath, path_src, FILE_MAX);
- if (BLI_path_abs(filepath, base_old)) {
- /* Path was relative and is now absolute. Remap.
- * Important BLI_cleanup_dir runs before the path is made relative
- * because it wont work for paths that start with "//../" */
- BLI_cleanup_file(base_new, filepath);
- BLI_path_rel(filepath, base_new);
- BLI_strncpy(path_dst, filepath, FILE_MAX);
- return TRUE;
- }
- else {
- /* Path was not relative to begin with. */
- return FALSE;
- }
-}
-
-
-/* -------------------------------------------------------------------- */
-/**
- * Backup/Restore/Free functions,
- * \note These functions assume the data won't chane order.
- */
-
-struct PathStore {
- struct PathStore *next, *prev;
-} PathStore;
-
-static int bpath_list_append(void *userdata, char *UNUSED(path_dst), const char *path_src)
-{
- /* store the path and string in a single alloc */
- ListBase *ls = userdata;
- size_t path_size = strlen(path_src) + 1;
- struct PathStore *path_store = MEM_mallocN(sizeof(PathStore) + path_size, __func__);
- char *filepath = (char *)(path_store + 1);
-
- memcpy(filepath, path_src, path_size);
- BLI_addtail(ls, path_store);
- return FALSE;
-}
-
-static int bpath_list_restore(void *userdata, char *path_dst, const char *path_src)
-{
- /* assume ls->first wont be NULL because the number of paths can't change!
- * (if they do caller is wrong) */
- ListBase *ls = userdata;
- struct PathStore *path_store = ls->first;
- const char *filepath = (char *)(path_store + 1);
- int ret;
-
- if (strcmp(path_src, filepath) == 0) {
- ret = FALSE;
- }
- else {
- BLI_strncpy(path_dst, filepath, FILE_MAX);
- ret = TRUE;
- }
-
- BLI_freelinkN(ls, path_store);
- return ret;
-}
-
-/* return ls_handle */
-void *BLI_bpath_list_backup(Main *bmain, const int flag)
-{
- ListBase *ls = MEM_callocN(sizeof(ListBase), __func__);
-
- BLI_bpath_traverse_main(bmain, bpath_list_append, flag, ls);
-
- return ls;
-}
-
-void BLI_bpath_list_restore(Main *bmain, const int flag, void *ls_handle)
-{
- ListBase *ls = ls_handle;
-
- BLI_bpath_traverse_main(bmain, bpath_list_restore, flag, ls);
-}
-
-void BLI_bpath_list_free(void *ls_handle)
-{
- ListBase *ls = ls_handle;
- BLI_assert(ls->first == NULL); /* assumes we were used */
- BLI_freelistN(ls);
- MEM_freeN(ls);
-}
diff --git a/source/blender/blenlib/intern/endian_switch.c b/source/blender/blenlib/intern/endian_switch.c
index b9b18136863..e3ed88b6f8d 100644
--- a/source/blender/blenlib/intern/endian_switch.c
+++ b/source/blender/blenlib/intern/endian_switch.c
@@ -24,7 +24,7 @@
* \ingroup bli
*/
-#include "BLO_sys_types.h"
+#include "MEM_sys_types.h"
#include "BLI_utildefines.h"
#include "BLI_endian_switch.h"
diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c
index 883cdfde426..0f42fca9f12 100644
--- a/source/blender/blenlib/intern/fileops.c
+++ b/source/blender/blenlib/intern/fileops.c
@@ -63,7 +63,7 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
-#include "BLO_sys_types.h" // for intptr_t support
+#include "MEM_sys_types.h" // for intptr_t support
/* gzip the file in from and write it to "to".
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index 0a87316aa81..353b73a6403 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -52,8 +52,6 @@
#include "BLI_math.h"
#include "BLI_utildefines.h"
-#include "BKE_font.h"
-
#include "DNA_vfont_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_curve_types.h"
diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c
index 9f6f409c473..c60a9ae6bfc 100644
--- a/source/blender/blenlib/intern/listbase.c
+++ b/source/blender/blenlib/intern/listbase.c
@@ -345,7 +345,7 @@ void *BLI_rfindlink(const ListBase *listbase, int number)
return link;
}
-int BLI_findindex(const ListBase *listbase, void *vlink)
+int BLI_findindex(const ListBase *listbase, const void *vlink)
{
Link *link = NULL;
int number = 0;
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 74abd7e8c7e..931025606db 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -180,7 +180,7 @@ float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2])
/* distance p to line-piece v1-v2 */
float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2])
{
- float labda, rc[2], pt[2], len;
+ float lambda, rc[2], pt[2], len;
rc[0] = l2[0] - l1[0];
rc[1] = l2[1] - l1[1];
@@ -191,18 +191,18 @@ float dist_squared_to_line_segment_v2(const float p[2], const float l1[2], const
return (rc[0] * rc[0] + rc[1] * rc[1]);
}
- labda = (rc[0] * (p[0] - l1[0]) + rc[1] * (p[1] - l1[1])) / len;
- if (labda <= 0.0f) {
+ lambda = (rc[0] * (p[0] - l1[0]) + rc[1] * (p[1] - l1[1])) / len;
+ if (lambda <= 0.0f) {
pt[0] = l1[0];
pt[1] = l1[1];
}
- else if (labda >= 1.0f) {
+ else if (lambda >= 1.0f) {
pt[0] = l2[0];
pt[1] = l2[1];
}
else {
- pt[0] = labda * rc[0] + l1[0];
- pt[1] = labda * rc[1] + l1[1];
+ pt[0] = lambda * rc[0] + l1[0];
+ pt[1] = lambda * rc[1] + l1[1];
}
rc[0] = pt[0] - p[0];
@@ -301,17 +301,17 @@ float dist_to_line_segment_v3(const float v1[3], const float v2[3], const float
/* intersect Line-Line, shorts */
int isect_line_line_v2_int(const int v1[2], const int v2[2], const int v3[2], const int v4[2])
{
- float div, labda, mu;
+ float div, lambda, mu;
div = (float)((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]));
if (div == 0.0f) return ISECT_LINE_LINE_COLINEAR;
- labda = ((float)(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
+ lambda = ((float)(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
mu = ((float)(v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
- if (labda >= 0.0f && labda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
- if (labda == 0.0f || labda == 1.0f || mu == 0.0f || mu == 1.0f) return ISECT_LINE_LINE_EXACT;
+ if (lambda >= 0.0f && lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
+ if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) return ISECT_LINE_LINE_EXACT;
return ISECT_LINE_LINE_CROSS;
}
return ISECT_LINE_LINE_NONE;
@@ -335,17 +335,17 @@ int isect_line_line_v2_point(const float v1[2], const float v2[2], const float v
/* intersect Line-Line, floats */
int isect_line_line_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
{
- float div, labda, mu;
+ float div, lambda, mu;
div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]);
if (div == 0.0f) return ISECT_LINE_LINE_COLINEAR;
- labda = ((float)(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
+ lambda = ((float)(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
mu = ((float)(v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
- if (labda >= 0.0f && labda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
- if (labda == 0.0f || labda == 1.0f || mu == 0.0f || mu == 1.0f) return ISECT_LINE_LINE_EXACT;
+ if (lambda >= 0.0f && lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
+ if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) return ISECT_LINE_LINE_EXACT;
return ISECT_LINE_LINE_CROSS;
}
return ISECT_LINE_LINE_NONE;
@@ -2435,7 +2435,7 @@ void interp_barycentric_tri_v3(float data[3][3], float u, float v, float res[3])
/***************************** View & Projection *****************************/
-void orthographic_m4(float matrix[][4], const float left, const float right, const float bottom, const float top,
+void orthographic_m4(float matrix[4][4], const float left, const float right, const float bottom, const float top,
const float nearClip, const float farClip)
{
float Xdelta, Ydelta, Zdelta;
@@ -2481,7 +2481,7 @@ void perspective_m4(float mat[4][4], const float left, const float right, const
}
/* translate a matrix created by orthographic_m4 or perspective_m4 in XY coords (used to jitter the view) */
-void window_translate_m4(float winmat[][4], float perspmat[][4], const float x, const float y)
+void window_translate_m4(float winmat[4][4], float perspmat[4][4], const float x, const float y)
{
if (winmat[2][3] == -1.0f) {
/* in the case of a win-matrix, this means perspective always */
@@ -2509,7 +2509,7 @@ void window_translate_m4(float winmat[][4], float perspmat[][4], const float x,
}
}
-static void i_multmatrix(float icand[][4], float Vm[][4])
+static void i_multmatrix(float icand[4][4], float Vm[4][4])
{
int row, col;
float temp[4][4];
@@ -2523,7 +2523,7 @@ static void i_multmatrix(float icand[][4], float Vm[][4])
copy_m4_m4(Vm, temp);
}
-void polarview_m4(float Vm[][4], float dist, float azimuth, float incidence, float twist)
+void polarview_m4(float Vm[4][4], float dist, float azimuth, float incidence, float twist)
{
unit_m4(Vm);
@@ -2534,7 +2534,7 @@ void polarview_m4(float Vm[][4], float dist, float azimuth, float incidence, flo
rotate_m4(Vm, 'Z', -azimuth);
}
-void lookat_m4(float mat[][4], float vx, float vy, float vz, float px, float py, float pz, float twist)
+void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py, float pz, float twist)
{
float sine, cosine, hyp, hyp1, dx, dy, dz;
float mat1[4][4] = MAT4_UNITY;
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 38214f9c6b0..3a294769eb3 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -43,7 +43,7 @@ void zero_m4(float m[4][4])
memset(m, 0, 4 * 4 * sizeof(float));
}
-void unit_m3(float m[][3])
+void unit_m3(float m[3][3])
{
m[0][0] = m[1][1] = m[2][2] = 1.0;
m[0][1] = m[0][2] = 0.0;
@@ -51,7 +51,7 @@ void unit_m3(float m[][3])
m[2][0] = m[2][1] = 0.0;
}
-void unit_m4(float m[][4])
+void unit_m4(float m[4][4])
{
m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
m[0][1] = m[0][2] = m[0][3] = 0.0;
@@ -60,18 +60,18 @@ void unit_m4(float m[][4])
m[3][0] = m[3][1] = m[3][2] = 0.0;
}
-void copy_m3_m3(float m1[][3], float m2[][3])
+void copy_m3_m3(float m1[3][3], float m2[3][3])
{
/* destination comes first: */
memcpy(&m1[0], &m2[0], 9 * sizeof(float));
}
-void copy_m4_m4(float m1[][4], float m2[][4])
+void copy_m4_m4(float m1[4][4], float m2[4][4])
{
memcpy(m1, m2, 4 * 4 * sizeof(float));
}
-void copy_m3_m4(float m1[][3], float m2[][4])
+void copy_m3_m4(float m1[3][3], float m2[4][4])
{
m1[0][0] = m2[0][0];
m1[0][1] = m2[0][1];
@@ -86,7 +86,7 @@ void copy_m3_m4(float m1[][3], float m2[][4])
m1[2][2] = m2[2][2];
}
-void copy_m4_m3(float m1[][4], float m2[][3]) /* no clear */
+void copy_m4_m3(float m1[4][4], float m2[3][3]) /* no clear */
{
m1[0][0] = m2[0][0];
m1[0][1] = m2[0][1];
@@ -112,7 +112,7 @@ void copy_m4_m3(float m1[][4], float m2[][3]) /* no clear */
}
-void swap_m3m3(float m1[][3], float m2[][3])
+void swap_m3m3(float m1[3][3], float m2[3][3])
{
float t;
int i, j;
@@ -126,7 +126,7 @@ void swap_m3m3(float m1[][3], float m2[][3])
}
}
-void swap_m4m4(float m1[][4], float m2[][4])
+void swap_m4m4(float m1[4][4], float m2[4][4])
{
float t;
int i, j;
@@ -142,7 +142,7 @@ void swap_m4m4(float m1[][4], float m2[][4])
/******************************** Arithmetic *********************************/
-void mult_m4_m4m4(float m1[][4], float m3_[][4], float m2_[][4])
+void mult_m4_m4m4(float m1[4][4], float m3_[4][4], float m2_[4][4])
{
float m2[4][4], m3[4][4];
@@ -173,7 +173,7 @@ void mult_m4_m4m4(float m1[][4], float m3_[][4], float m2_[][4])
}
-void mul_m3_m3m3(float m1[][3], float m3_[][3], float m2_[][3])
+void mul_m3_m3m3(float m1[3][3], float m3_[3][3], float m2_[3][3])
{
float m2[3][3], m3[3][3];
@@ -195,7 +195,7 @@ void mul_m3_m3m3(float m1[][3], float m3_[][3], float m2_[][3])
m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
}
-void mul_m4_m4m3(float m1[][4], float m3_[][4], float m2_[][3])
+void mul_m4_m4m3(float m1[4][4], float m3_[4][4], float m2_[3][3])
{
float m2[3][3], m3[4][4];
@@ -215,7 +215,7 @@ void mul_m4_m4m3(float m1[][4], float m3_[][4], float m2_[][3])
}
/* m1 = m2 * m3, ignore the elements on the 4th row/column of m3 */
-void mult_m3_m3m4(float m1[][3], float m3_[][4], float m2_[][3])
+void mult_m3_m3m4(float m1[3][3], float m3_[4][4], float m2_[3][3])
{
float m2[3][3], m3[4][4];
@@ -237,7 +237,7 @@ void mult_m3_m3m4(float m1[][3], float m3_[][4], float m2_[][3])
m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
}
-void mul_m4_m3m4(float m1[][4], float m3_[][3], float m2_[][4])
+void mul_m4_m3m4(float m1[4][4], float m3_[3][3], float m2_[4][4])
{
float m2[4][4], m3[3][3];
@@ -256,10 +256,10 @@ void mul_m4_m3m4(float m1[][4], float m3_[][3], float m2_[][4])
m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
}
-void mul_serie_m3(float answ[][3],
- float m1[][3], float m2[][3], float m3[][3],
- float m4[][3], float m5[][3], float m6[][3],
- float m7[][3], float m8[][3])
+void mul_serie_m3(float answ[3][3],
+ float m1[3][3], float m2[3][3], float m3[3][3],
+ float m4[3][3], float m5[3][3], float m6[3][3],
+ float m7[3][3], float m8[3][3])
{
float temp[3][3];
@@ -289,10 +289,10 @@ void mul_serie_m3(float answ[][3],
}
}
-void mul_serie_m4(float answ[][4], float m1[][4],
- float m2[][4], float m3[][4], float m4[][4],
- float m5[][4], float m6[][4], float m7[][4],
- float m8[][4])
+void mul_serie_m4(float answ[4][4], float m1[4][4],
+ float m2[4][4], float m3[4][4], float m4[4][4],
+ float m5[4][4], float m6[4][4], float m7[4][4],
+ float m8[4][4])
{
float temp[4][4];
@@ -322,7 +322,7 @@ void mul_serie_m4(float answ[][4], float m1[][4],
}
}
-void mul_m4_v3(float mat[][4], float vec[3])
+void mul_m4_v3(float mat[4][4], float vec[3])
{
float x, y;
@@ -333,7 +333,7 @@ void mul_m4_v3(float mat[][4], float vec[3])
vec[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2];
}
-void mul_v3_m4v3(float in[3], float mat[][4], const float vec[3])
+void mul_v3_m4v3(float in[3], float mat[4][4], const float vec[3])
{
float x, y;
@@ -345,7 +345,7 @@ void mul_v3_m4v3(float in[3], float mat[][4], const float vec[3])
}
/* same as mul_m4_v3() but doesnt apply translation component */
-void mul_mat3_m4_v3(float mat[][4], float vec[3])
+void mul_mat3_m4_v3(float mat[4][4], float vec[3])
{
float x, y;
@@ -356,7 +356,7 @@ void mul_mat3_m4_v3(float mat[][4], float vec[3])
vec[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2];
}
-void mul_project_m4_v3(float mat[][4], float vec[3])
+void mul_project_m4_v3(float mat[4][4], float vec[3])
{
const float w = vec[0] * mat[0][3] + vec[1] * mat[1][3] + vec[2] * mat[2][3] + mat[3][3];
mul_m4_v3(mat, vec);
@@ -419,7 +419,7 @@ void mul_m3_v3(float M[3][3], float r[3])
copy_v3_v3(r, tmp);
}
-void mul_transposed_m3_v3(float mat[][3], float vec[3])
+void mul_transposed_m3_v3(float mat[3][3], float vec[3])
{
float x, y;
@@ -457,7 +457,7 @@ void mul_mat3_m4_fl(float m[4][4], float f)
m[i][j] *= f;
}
-void mul_m3_v3_double(float mat[][3], double vec[3])
+void mul_m3_v3_double(float mat[3][3], double vec[3])
{
double x, y;
@@ -468,7 +468,7 @@ void mul_m3_v3_double(float mat[][3], double vec[3])
vec[2] = x * (double)mat[0][2] + y * (double)mat[1][2] + (double)mat[2][2] * vec[2];
}
-void add_m3_m3m3(float m1[][3], float m2[][3], float m3[][3])
+void add_m3_m3m3(float m1[3][3], float m2[3][3], float m3[3][3])
{
int i, j;
@@ -477,7 +477,7 @@ void add_m3_m3m3(float m1[][3], float m2[][3], float m3[][3])
m1[i][j] = m2[i][j] + m3[i][j];
}
-void add_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
+void add_m4_m4m4(float m1[4][4], float m2[4][4], float m3[4][4])
{
int i, j;
@@ -486,7 +486,7 @@ void add_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
m1[i][j] = m2[i][j] + m3[i][j];
}
-void sub_m3_m3m3(float m1[][3], float m2[][3], float m3[][3])
+void sub_m3_m3m3(float m1[3][3], float m2[3][3], float m3[3][3])
{
int i, j;
@@ -495,7 +495,7 @@ void sub_m3_m3m3(float m1[][3], float m2[][3], float m3[][3])
m1[i][j] = m2[i][j] - m3[i][j];
}
-void sub_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
+void sub_m4_m4m4(float m1[4][4], float m2[4][4], float m3[4][4])
{
int i, j;
@@ -504,8 +504,7 @@ void sub_m4_m4m4(float m1[][4], float m2[][4], float m3[][4])
m1[i][j] = m2[i][j] - m3[i][j];
}
-/* why not make this a standard part of the API? */
-static float determinant_m3_local(float m[3][3])
+float determinant_m3_array(float m[3][3])
{
return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) -
m[1][0] * (m[0][1] * m[2][2] - m[0][2] * m[2][1]) +
@@ -534,7 +533,7 @@ int invert_m3_m3_ex(float m1[3][3], float m2[3][3], const float epsilon)
adjoint_m3_m3(m1, m2);
/* then determinant old matrix! */
- det = determinant_m3_local(m2);
+ det = determinant_m3_array(m2);
success = (fabsf(det) > epsilon);
@@ -569,7 +568,7 @@ int invert_m3_m3(float m1[3][3], float m2[3][3])
adjoint_m3_m3(m1, m2);
/* then determinant old matrix! */
- det = determinant_m3_local(m2);
+ det = determinant_m3_array(m2);
success = (det != 0.0f);
@@ -613,6 +612,8 @@ int invert_m4_m4(float inverse[4][4], float mat[4][4])
float max;
int maxj;
+ BLI_assert(inverse != mat);
+
/* Set inverse to identity */
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
@@ -665,7 +666,7 @@ int invert_m4_m4(float inverse[4][4], float mat[4][4])
/****************************** Linear Algebra *******************************/
-void transpose_m3(float mat[][3])
+void transpose_m3(float mat[3][3])
{
float t;
@@ -680,7 +681,7 @@ void transpose_m3(float mat[][3])
mat[2][1] = t;
}
-void transpose_m4(float mat[][4])
+void transpose_m4(float mat[4][4])
{
float t;
@@ -706,7 +707,7 @@ void transpose_m4(float mat[][4])
mat[3][2] = t;
}
-void orthogonalize_m3(float mat[][3], int axis)
+void orthogonalize_m3(float mat[3][3], int axis)
{
float size[3];
mat3_to_size(size, mat);
@@ -784,7 +785,7 @@ void orthogonalize_m3(float mat[][3], int axis)
mul_v3_fl(mat[2], size[2]);
}
-void orthogonalize_m4(float mat[][4], int axis)
+void orthogonalize_m4(float mat[4][4], int axis)
{
float size[3];
mat4_to_size(size, mat);
@@ -863,7 +864,7 @@ void orthogonalize_m4(float mat[][4], int axis)
mul_v3_fl(mat[2], size[2]);
}
-int is_orthogonal_m3(float m[][3])
+int is_orthogonal_m3(float m[3][3])
{
int i, j;
@@ -877,7 +878,7 @@ int is_orthogonal_m3(float m[][3])
return 1;
}
-int is_orthogonal_m4(float m[][4])
+int is_orthogonal_m4(float m[4][4])
{
int i, j;
@@ -892,7 +893,7 @@ int is_orthogonal_m4(float m[][4])
return 1;
}
-int is_orthonormal_m3(float m[][3])
+int is_orthonormal_m3(float m[3][3])
{
if (is_orthogonal_m3(m)) {
int i;
@@ -907,7 +908,7 @@ int is_orthonormal_m3(float m[][3])
return 0;
}
-int is_orthonormal_m4(float m[][4])
+int is_orthonormal_m4(float m[4][4])
{
if (is_orthogonal_m4(m)) {
int i;
@@ -922,7 +923,7 @@ int is_orthonormal_m4(float m[][4])
return 0;
}
-int is_uniform_scaled_m3(float m[][3])
+int is_uniform_scaled_m3(float m[3][3])
{
const float eps = 1e-7;
float t[3][3];
@@ -951,21 +952,21 @@ int is_uniform_scaled_m3(float m[][3])
return 0;
}
-void normalize_m3(float mat[][3])
+void normalize_m3(float mat[3][3])
{
normalize_v3(mat[0]);
normalize_v3(mat[1]);
normalize_v3(mat[2]);
}
-void normalize_m3_m3(float rmat[][3], float mat[][3])
+void normalize_m3_m3(float rmat[3][3], float mat[3][3])
{
normalize_v3_v3(rmat[0], mat[0]);
normalize_v3_v3(rmat[1], mat[1]);
normalize_v3_v3(rmat[2], mat[2]);
}
-void normalize_m4(float mat[][4])
+void normalize_m4(float mat[4][4])
{
float len;
@@ -977,7 +978,7 @@ void normalize_m4(float mat[][4])
if (len != 0.0f) mat[2][3] /= len;
}
-void normalize_m4_m4(float rmat[][4], float mat[][4])
+void normalize_m4_m4(float rmat[4][4], float mat[4][4])
{
float len;
@@ -998,7 +999,7 @@ void adjoint_m2_m2(float m1[][2], float m[][2])
m1[1][1] = m[0][0];
}
-void adjoint_m3_m3(float m1[][3], float m[][3])
+void adjoint_m3_m3(float m1[3][3], float m[3][3])
{
BLI_assert(m1 != m);
m1[0][0] = m[1][1] * m[2][2] - m[1][2] * m[2][1];
@@ -1014,7 +1015,7 @@ void adjoint_m3_m3(float m1[][3], float m[][3])
m1[2][2] = m[0][0] * m[1][1] - m[0][1] * m[1][0];
}
-void adjoint_m4_m4(float out[][4], float in[][4]) /* out = ADJ(in) */
+void adjoint_m4_m4(float out[4][4], float in[4][4]) /* out = ADJ(in) */
{
float a1, a2, a3, a4, b1, b2, b3, b4;
float c1, c2, c3, c4, d1, d2, d3, d4;
@@ -1080,7 +1081,7 @@ float determinant_m3(float a1, float a2, float a3,
return ans;
}
-float determinant_m4(float m[][4])
+float determinant_m4(float m[4][4])
{
float ans;
float a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4;
@@ -1115,7 +1116,7 @@ float determinant_m4(float m[][4])
/****************************** Transformations ******************************/
-void size_to_mat3(float mat[][3], const float size[3])
+void size_to_mat3(float mat[3][3], const float size[3])
{
mat[0][0] = size[0];
mat[0][1] = 0.0f;
@@ -1128,7 +1129,7 @@ void size_to_mat3(float mat[][3], const float size[3])
mat[2][0] = 0.0f;
}
-void size_to_mat4(float mat[][4], const float size[3])
+void size_to_mat4(float mat[4][4], const float size[3])
{
float tmat[3][3];
@@ -1137,14 +1138,14 @@ void size_to_mat4(float mat[][4], const float size[3])
copy_m4_m3(mat, tmat);
}
-void mat3_to_size(float size[3], float mat[][3])
+void mat3_to_size(float size[3], float mat[3][3])
{
size[0] = len_v3(mat[0]);
size[1] = len_v3(mat[1]);
size[2] = len_v3(mat[2]);
}
-void mat4_to_size(float size[3], float mat[][4])
+void mat4_to_size(float size[3], float mat[4][4])
{
size[0] = len_v3(mat[0]);
size[1] = len_v3(mat[1]);
@@ -1154,7 +1155,7 @@ void mat4_to_size(float size[3], float mat[][4])
/* this gets the average scale of a matrix, only use when your scaling
* data that has no idea of scale axis, examples are bone-envelope-radius
* and curve radius */
-float mat3_to_scale(float mat[][3])
+float mat3_to_scale(float mat[3][3])
{
/* unit length vector */
float unit_vec[3] = {0.577350269189626f, 0.577350269189626f, 0.577350269189626f};
@@ -1162,7 +1163,7 @@ float mat3_to_scale(float mat[][3])
return len_v3(unit_vec);
}
-float mat4_to_scale(float mat[][4])
+float mat4_to_scale(float mat[4][4])
{
float tmat[3][3];
copy_m3_m4(tmat, mat);
@@ -1200,7 +1201,7 @@ void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3])
size[2] = mat3[2][2];
}
-void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[][4])
+void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4])
{
float mat3[3][3]; /* wmat -> 3x3 */
@@ -1211,7 +1212,7 @@ void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wm
copy_v3_v3(loc, wmat[3]);
}
-void scale_m3_fl(float m[][3], float scale)
+void scale_m3_fl(float m[3][3], float scale)
{
m[0][0] = m[1][1] = m[2][2] = scale;
m[0][1] = m[0][2] = 0.0;
@@ -1219,7 +1220,7 @@ void scale_m3_fl(float m[][3], float scale)
m[2][0] = m[2][1] = 0.0;
}
-void scale_m4_fl(float m[][4], float scale)
+void scale_m4_fl(float m[4][4], float scale)
{
m[0][0] = m[1][1] = m[2][2] = scale;
m[3][3] = 1.0;
@@ -1229,14 +1230,14 @@ void scale_m4_fl(float m[][4], float scale)
m[3][0] = m[3][1] = m[3][2] = 0.0;
}
-void translate_m4(float mat[][4], float Tx, float Ty, float Tz)
+void translate_m4(float mat[4][4], float Tx, float Ty, float Tz)
{
mat[3][0] += (Tx * mat[0][0] + Ty * mat[1][0] + Tz * mat[2][0]);
mat[3][1] += (Tx * mat[0][1] + Ty * mat[1][1] + Tz * mat[2][1]);
mat[3][2] += (Tx * mat[0][2] + Ty * mat[1][2] + Tz * mat[2][2]);
}
-void rotate_m4(float mat[][4], const char axis, const float angle)
+void rotate_m4(float mat[4][4], const char axis, const float angle)
{
int col;
float temp[4] = {0.0f, 0.0f, 0.0f, 0.0f};
@@ -1276,7 +1277,7 @@ void rotate_m4(float mat[][4], const char axis, const float angle)
}
}
-void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], const float srcweight)
+void blend_m3_m3m3(float out[3][3], float dst[3][3], float src[3][3], const float srcweight)
{
float srot[3][3], drot[3][3];
float squat[4], dquat[4], fquat[4];
@@ -1299,7 +1300,7 @@ void blend_m3_m3m3(float out[][3], float dst[][3], float src[][3], const float s
mul_m3_m3m3(out, rmat, smat);
}
-void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], const float srcweight)
+void blend_m4_m4m4(float out[4][4], float dst[4][4], float src[4][4], const float srcweight)
{
float sloc[3], dloc[3], floc[3];
float srot[3][3], drot[3][3];
@@ -1321,14 +1322,14 @@ void blend_m4_m4m4(float out[][4], float dst[][4], float src[][4], const float s
loc_quat_size_to_mat4(out, floc, fquat, fsize);
}
-int is_negative_m3(float mat[][3])
+int is_negative_m3(float mat[3][3])
{
float vec[3];
cross_v3_v3v3(vec, mat[0], mat[1]);
return (dot_v3v3(vec, mat[2]) < 0.0f);
}
-int is_negative_m4(float mat[][4])
+int is_negative_m4(float mat[4][4])
{
float vec[3];
cross_v3_v3v3(vec, mat[0], mat[1]);
@@ -1418,7 +1419,7 @@ void loc_axisangle_size_to_mat4(float mat[4][4], const float loc[3], const float
/*********************************** Other ***********************************/
-void print_m3(const char *str, float m[][3])
+void print_m3(const char *str, float m[3][3])
{
printf("%s\n", str);
printf("%f %f %f\n", m[0][0], m[1][0], m[2][0]);
@@ -1427,7 +1428,7 @@ void print_m3(const char *str, float m[][3])
printf("\n");
}
-void print_m4(const char *str, float m[][4])
+void print_m4(const char *str, float m[4][4])
{
printf("%s\n", str);
printf("%f %f %f %f\n", m[0][0], m[1][0], m[2][0], m[3][0]);
@@ -1901,3 +1902,16 @@ void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon)
mul_serie_m4(Ainv, U, Wm, V, NULL, NULL, NULL, NULL, NULL);
}
+
+void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon)
+{
+ /* try regular inverse when possible, otherwise fall back to slow svd */
+ if (!invert_m3_m3(Ainv, A)) {
+ float tmp[4][4], tmpinv[4][4];
+
+ copy_m4_m3(tmp, A);
+ pseudoinverse_m4_m4(tmpinv, tmp, epsilon);
+ copy_m3_m4(Ainv, tmpinv);
+ }
+}
+
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 3069542107e..71f146e8131 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -185,7 +185,7 @@ void mul_fac_qt_fl(float q[4], const float fac)
}
/* skip error check, currently only needed by mat3_to_quat_is_ok */
-static void quat_to_mat3_no_error(float m[][3], const float q[4])
+static void quat_to_mat3_no_error(float m[3][3], const float q[4])
{
double q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc;
@@ -217,7 +217,7 @@ static void quat_to_mat3_no_error(float m[][3], const float q[4])
m[2][2] = (float)(1.0 - qaa - qbb);
}
-void quat_to_mat3(float m[][3], const float q[4])
+void quat_to_mat3(float m[3][3], const float q[4])
{
#ifdef DEBUG
float f;
@@ -229,7 +229,7 @@ void quat_to_mat3(float m[][3], const float q[4])
quat_to_mat3_no_error(m, q);
}
-void quat_to_mat4(float m[][4], const float q[4])
+void quat_to_mat4(float m[4][4], const float q[4])
{
double q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc;
@@ -273,7 +273,7 @@ void quat_to_mat4(float m[][4], const float q[4])
m[3][3] = 1.0f;
}
-void mat3_to_quat(float q[4], float wmat[][3])
+void mat3_to_quat(float q[4], float wmat[3][3])
{
double tr, s;
float mat[3][3];
@@ -325,7 +325,7 @@ void mat3_to_quat(float q[4], float wmat[][3])
normalize_qt(q);
}
-void mat4_to_quat(float q[4], float m[][4])
+void mat4_to_quat(float q[4], float m[4][4])
{
float mat[3][3];
@@ -861,7 +861,7 @@ void single_axis_angle_to_mat3(float mat[3][3], const char axis, const float ang
/* TODO: the following calls should probably be deprecated sometime */
/* TODO, replace use of this function with axis_angle_to_mat3() */
-void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi)
+void vec_rot_to_mat3(float mat[3][3], const float vec[3], const float phi)
{
/* rotation of phi radials around vec */
float vx, vx2, vy, vy2, vz, vz2, co, si;
@@ -889,7 +889,7 @@ void vec_rot_to_mat3(float mat[][3], const float vec[3], const float phi)
/******************************** XYZ Eulers *********************************/
/* XYZ order */
-void eul_to_mat3(float mat[][3], const float eul[3])
+void eul_to_mat3(float mat[3][3], const float eul[3])
{
double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -917,7 +917,7 @@ void eul_to_mat3(float mat[][3], const float eul[3])
}
/* XYZ order */
-void eul_to_mat4(float mat[][4], const float eul[3])
+void eul_to_mat4(float mat[4][4], const float eul[3])
{
double ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
@@ -950,7 +950,7 @@ void eul_to_mat4(float mat[][4], const float eul[3])
/* returns two euler calculation methods, so we can pick the best */
/* XYZ order */
-static void mat3_to_eul2(float tmat[][3], float eul1[3], float eul2[3])
+static void mat3_to_eul2(float tmat[3][3], float eul1[3], float eul2[3])
{
float cy, quat[4], mat[3][3];
@@ -982,7 +982,7 @@ static void mat3_to_eul2(float tmat[][3], float eul1[3], float eul2[3])
}
/* XYZ order */
-void mat3_to_eul(float *eul, float tmat[][3])
+void mat3_to_eul(float *eul, float tmat[3][3])
{
float eul1[3], eul2[3];
@@ -998,7 +998,7 @@ void mat3_to_eul(float *eul, float tmat[][3])
}
/* XYZ order */
-void mat4_to_eul(float *eul, float tmat[][4])
+void mat4_to_eul(float *eul, float tmat[4][4])
{
float tempMat[3][3];
@@ -1107,7 +1107,7 @@ void compatible_eul(float eul[3], const float oldrot[3])
/* uses 2 methods to retrieve eulers, and picks the closest */
/* XYZ order */
-void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[][3])
+void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[3][3])
{
float eul1[3], eul2[3];
float d1, d2;
@@ -1388,7 +1388,7 @@ void rotate_eulO(float beul[3], const short order, char axis, float ang)
}
/* the matrix is written to as 3 axis vectors */
-void eulO_to_gimbal_axis(float gmat[][3], const float eul[3], const short order)
+void eulO_to_gimbal_axis(float gmat[3][3], const float eul[3], const short order)
{
const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order);
@@ -1447,7 +1447,7 @@ void eulO_to_gimbal_axis(float gmat[][3], const float eul[3], const short order)
* - added support for scaling
*/
-void mat4_to_dquat(DualQuat *dq, float basemat[][4], float mat[][4])
+void mat4_to_dquat(DualQuat *dq, float basemat[4][4], float mat[4][4])
{
float *t, *q, dscale[3], scale[3], basequat[4];
float baseRS[4][4], baseinv[4][4], baseR[4][4], baseRinv[4][4];
@@ -1502,7 +1502,7 @@ void mat4_to_dquat(DualQuat *dq, float basemat[][4], float mat[][4])
dq->trans[3] = 0.5f * ( t[0] * q[2] - t[1] * q[1] + t[2] * q[0]);
}
-void dquat_to_mat4(float mat[][4], DualQuat *dq)
+void dquat_to_mat4(float mat[4][4], DualQuat *dq)
{
float len, *t, q0[4];
@@ -1583,7 +1583,7 @@ void normalize_dq(DualQuat *dq, float totweight)
}
}
-void mul_v3m3_dq(float co[3], float mat[][3], DualQuat *dq)
+void mul_v3m3_dq(float co[3], float mat[3][3], DualQuat *dq)
{
float M[3][3], t[3], scalemat[3][3], len2;
float w = dq->quat[0], x = dq->quat[1], y = dq->quat[2], z = dq->quat[3];
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 3ede8636aa5..04b9d574347 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -544,7 +544,7 @@ MINLINE void add_newell_cross_v3_v3v3(float n[3], const float v_prev[3], const f
n[2] += (v_prev[0] - v_curr[0]) * (v_prev[1] + v_curr[1]);
}
-MINLINE void star_m3_v3(float rmat[][3], float a[3])
+MINLINE void star_m3_v3(float rmat[3][3], float a[3])
{
rmat[0][0] = rmat[1][1] = rmat[2][2] = 0.0;
rmat[0][1] = -a[2];
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 444daf8817c..7c1842b10f2 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -47,7 +47,7 @@
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
-#include "BKE_blender.h" /* BLENDER_VERSION */
+#include "../blenkernel/BKE_blender.h" /* BLENDER_VERSION, bad level include (no function call) */
#include "GHOST_Path-api.h"
diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c
deleted file mode 100644
index 6fa6d86589f..00000000000
--- a/source/blender/blenlib/intern/pbvh.c
+++ /dev/null
@@ -1,1911 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenlib/intern/pbvh.c
- * \ingroup bli
- */
-
-
-
-#include "DNA_meshdata_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_bitmap.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_pbvh.h"
-
-#include "BKE_ccg.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_mesh.h" /* for BKE_mesh_calc_normals */
-#include "BKE_global.h" /* for BKE_mesh_calc_normals */
-#include "BKE_paint.h"
-#include "BKE_subsurf.h"
-
-#include "GPU_buffers.h"
-
-#define LEAF_LIMIT 10000
-
-//#define PERFCNTRS
-
-/* Axis-aligned bounding box */
-typedef struct {
- float bmin[3], bmax[3];
-} BB;
-
-/* Axis-aligned bounding box with centroid */
-typedef struct {
- float bmin[3], bmax[3], bcentroid[3];
-} BBC;
-
-struct PBVHNode {
- /* Opaque handle for drawing code */
- GPU_Buffers *draw_buffers;
-
- /* Voxel bounds */
- BB vb;
- BB orig_vb;
-
- /* For internal nodes, the offset of the children in the PBVH
- * 'nodes' array. */
- int children_offset;
-
- /* Pointer into the PBVH prim_indices array and the number of
- * primitives used by this leaf node.
- *
- * Used for leaf nodes in both mesh- and multires-based PBVHs.
- */
- int *prim_indices;
- unsigned int totprim;
-
- /* Array of indices into the mesh's MVert array. Contains the
- * indices of all vertices used by faces that are within this
- * node's bounding box.
- *
- * Note that a vertex might be used by a multiple faces, and
- * these faces might be in different leaf nodes. Such a vertex
- * will appear in the vert_indices array of each of those leaf
- * nodes.
- *
- * In order to support cases where you want access to multiple
- * nodes' vertices without duplication, the vert_indices array
- * is ordered such that the first part of the array, up to
- * index 'uniq_verts', contains "unique" vertex indices. These
- * vertices might not be truly unique to this node, but if
- * they appear in another node's vert_indices array, they will
- * be above that node's 'uniq_verts' value.
- *
- * Used for leaf nodes in a mesh-based PBVH (not multires.)
- */
- int *vert_indices;
- unsigned int uniq_verts, face_verts;
-
- /* An array mapping face corners into the vert_indices
- * array. The array is sized to match 'totprim', and each of
- * the face's corners gets an index into the vert_indices
- * array, in the same order as the corners in the original
- * MFace. The fourth value should not be used if the original
- * face is a triangle.
- *
- * Used for leaf nodes in a mesh-based PBVH (not multires.)
- */
- int (*face_vert_indices)[4];
-
- /* Indicates whether this node is a leaf or not; also used for
- * marking various updates that need to be applied. */
- PBVHNodeFlags flag : 8;
-
- /* Used for raycasting: how close bb is to the ray point. */
- float tmin;
-
- int proxy_count;
- PBVHProxyNode *proxies;
-};
-
-struct PBVH {
- PBVHType type;
-
- PBVHNode *nodes;
- int node_mem_count, totnode;
-
- int *prim_indices;
- int totprim;
- int totvert;
-
- int leaf_limit;
-
- /* Mesh data */
- MVert *verts;
- MFace *faces;
- CustomData *vdata;
-
- /* Grid Data */
- CCGKey gridkey;
- CCGElem **grids;
- DMGridAdjacency *gridadj;
- void **gridfaces;
- const DMFlagMat *grid_flag_mats;
- int totgrid;
- BLI_bitmap *grid_hidden;
-
- /* Only used during BVH build and update,
- * don't need to remain valid after */
- BLI_bitmap vert_bitmap;
-
-#ifdef PERFCNTRS
- int perf_modified;
-#endif
-
- /* flag are verts/faces deformed */
- int deformed;
-
- int show_diffuse_color;
-};
-
-#define STACK_FIXED_DEPTH 100
-
-typedef struct PBVHStack {
- PBVHNode *node;
- int revisiting;
-} PBVHStack;
-
-typedef struct PBVHIter {
- PBVH *bvh;
- BLI_pbvh_SearchCallback scb;
- void *search_data;
-
- PBVHStack *stack;
- int stacksize;
-
- PBVHStack stackfixed[STACK_FIXED_DEPTH];
- int stackspace;
-} PBVHIter;
-
-static void BB_reset(BB *bb)
-{
- bb->bmin[0] = bb->bmin[1] = bb->bmin[2] = FLT_MAX;
- bb->bmax[0] = bb->bmax[1] = bb->bmax[2] = -FLT_MAX;
-}
-
-/* Expand the bounding box to include a new coordinate */
-static void BB_expand(BB *bb, float co[3])
-{
- int i;
- for (i = 0; i < 3; ++i) {
- bb->bmin[i] = min_ff(bb->bmin[i], co[i]);
- bb->bmax[i] = max_ff(bb->bmax[i], co[i]);
- }
-}
-
-/* Expand the bounding box to include another bounding box */
-static void BB_expand_with_bb(BB *bb, BB *bb2)
-{
- int i;
- for (i = 0; i < 3; ++i) {
- bb->bmin[i] = min_ff(bb->bmin[i], bb2->bmin[i]);
- bb->bmax[i] = max_ff(bb->bmax[i], bb2->bmax[i]);
- }
-}
-
-/* Return 0, 1, or 2 to indicate the widest axis of the bounding box */
-static int BB_widest_axis(BB *bb)
-{
- float dim[3];
- int i;
-
- for (i = 0; i < 3; ++i)
- dim[i] = bb->bmax[i] - bb->bmin[i];
-
- if (dim[0] > dim[1]) {
- if (dim[0] > dim[2])
- return 0;
- else
- return 2;
- }
- else {
- if (dim[1] > dim[2])
- return 1;
- else
- return 2;
- }
-}
-
-static void BBC_update_centroid(BBC *bbc)
-{
- int i;
- for (i = 0; i < 3; ++i)
- bbc->bcentroid[i] = (bbc->bmin[i] + bbc->bmax[i]) * 0.5f;
-}
-
-/* Not recursive */
-static void update_node_vb(PBVH *bvh, PBVHNode *node)
-{
- BB vb;
-
- BB_reset(&vb);
-
- if (node->flag & PBVH_Leaf) {
- PBVHVertexIter vd;
-
- BLI_pbvh_vertex_iter_begin(bvh, node, vd, PBVH_ITER_ALL)
- {
- BB_expand(&vb, vd.co);
- }
- BLI_pbvh_vertex_iter_end;
- }
- else {
- BB_expand_with_bb(&vb,
- &bvh->nodes[node->children_offset].vb);
- BB_expand_with_bb(&vb,
- &bvh->nodes[node->children_offset + 1].vb);
- }
-
- node->vb = vb;
-}
-
-//void BLI_pbvh_node_BB_reset(PBVHNode *node)
-//{
-// BB_reset(&node->vb);
-//}
-//
-//void BLI_pbvh_node_BB_expand(PBVHNode *node, float co[3])
-//{
-// BB_expand(&node->vb, co);
-//}
-
-static int face_materials_match(const MFace *f1, const MFace *f2)
-{
- return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) &&
- (f1->mat_nr == f2->mat_nr));
-}
-
-static int grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2)
-{
- return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) &&
- (f1->mat_nr == f2->mat_nr));
-}
-
-/* Adapted from BLI_kdopbvh.c */
-/* Returns the index of the first element on the right of the partition */
-static int partition_indices(int *prim_indices, int lo, int hi, int axis,
- float mid, BBC *prim_bbc)
-{
- int i = lo, j = hi;
- for (;; ) {
- for (; prim_bbc[prim_indices[i]].bcentroid[axis] < mid; i++) ;
- for (; mid < prim_bbc[prim_indices[j]].bcentroid[axis]; j--) ;
-
- if (!(i < j))
- return i;
-
- SWAP(int, prim_indices[i], prim_indices[j]);
- i++;
- }
-}
-
-/* Returns the index of the first element on the right of the partition */
-static int partition_indices_material(PBVH *bvh, int lo, int hi)
-{
- const MFace *faces = bvh->faces;
- const DMFlagMat *flagmats = bvh->grid_flag_mats;
- const int *indices = bvh->prim_indices;
- const void *first;
- int i = lo, j = hi;
-
- if (bvh->faces)
- first = &faces[bvh->prim_indices[lo]];
- else
- first = &flagmats[bvh->prim_indices[lo]];
-
- for (;; ) {
- if (bvh->faces) {
- for (; face_materials_match(first, &faces[indices[i]]); i++) ;
- for (; !face_materials_match(first, &faces[indices[j]]); j--) ;
- }
- else {
- for (; grid_materials_match(first, &flagmats[indices[i]]); i++) ;
- for (; !grid_materials_match(first, &flagmats[indices[j]]); j--) ;
- }
-
- if (!(i < j))
- return i;
-
- SWAP(int, bvh->prim_indices[i], bvh->prim_indices[j]);
- i++;
- }
-}
-
-static void grow_nodes(PBVH *bvh, int totnode)
-{
- if (totnode > bvh->node_mem_count) {
- PBVHNode *prev = bvh->nodes;
- bvh->node_mem_count *= 1.33;
- if (bvh->node_mem_count < totnode)
- bvh->node_mem_count = totnode;
- bvh->nodes = MEM_callocN(sizeof(PBVHNode) * bvh->node_mem_count,
- "bvh nodes");
- memcpy(bvh->nodes, prev, bvh->totnode * sizeof(PBVHNode));
- MEM_freeN(prev);
- }
-
- bvh->totnode = totnode;
-}
-
-/* Add a vertex to the map, with a positive value for unique vertices and
- * a negative value for additional vertices */
-static int map_insert_vert(PBVH *bvh, GHash *map,
- unsigned int *face_verts,
- unsigned int *uniq_verts, int vertex)
-{
- void *value, *key = SET_INT_IN_POINTER(vertex);
-
- if (!BLI_ghash_haskey(map, key)) {
- if (BLI_BITMAP_GET(bvh->vert_bitmap, vertex)) {
- value = SET_INT_IN_POINTER(~(*face_verts));
- ++(*face_verts);
- }
- else {
- BLI_BITMAP_SET(bvh->vert_bitmap, vertex);
- value = SET_INT_IN_POINTER(*uniq_verts);
- ++(*uniq_verts);
- }
-
- BLI_ghash_insert(map, key, value);
- return GET_INT_FROM_POINTER(value);
- }
- else
- return GET_INT_FROM_POINTER(BLI_ghash_lookup(map, key));
-}
-
-/* Find vertices used by the faces in this node and update the draw buffers */
-static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node)
-{
- GHashIterator *iter;
- GHash *map;
- int i, j, totface;
-
- map = BLI_ghash_int_new("build_mesh_leaf_node gh");
-
- node->uniq_verts = node->face_verts = 0;
- totface = node->totprim;
-
- node->face_vert_indices = MEM_callocN(sizeof(int) * 4 * totface,
- "bvh node face vert indices");
-
- for (i = 0; i < totface; ++i) {
- MFace *f = bvh->faces + node->prim_indices[i];
- int sides = f->v4 ? 4 : 3;
-
- for (j = 0; j < sides; ++j) {
- node->face_vert_indices[i][j] =
- map_insert_vert(bvh, map, &node->face_verts,
- &node->uniq_verts, (&f->v1)[j]);
- }
- }
-
- node->vert_indices = MEM_callocN(sizeof(int) *
- (node->uniq_verts + node->face_verts),
- "bvh node vert indices");
-
- /* Build the vertex list, unique verts first */
- for (iter = BLI_ghashIterator_new(map), i = 0;
- BLI_ghashIterator_isDone(iter) == FALSE;
- BLI_ghashIterator_step(iter), ++i)
- {
- void *value = BLI_ghashIterator_getValue(iter);
- int ndx = GET_INT_FROM_POINTER(value);
-
- if (ndx < 0)
- ndx = -ndx + node->uniq_verts - 1;
-
- node->vert_indices[ndx] =
- GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(iter));
- }
-
- BLI_ghashIterator_free(iter);
-
- for (i = 0; i < totface; ++i) {
- MFace *f = bvh->faces + node->prim_indices[i];
- int sides = f->v4 ? 4 : 3;
-
- for (j = 0; j < sides; ++j) {
- if (node->face_vert_indices[i][j] < 0)
- node->face_vert_indices[i][j] =
- -node->face_vert_indices[i][j] +
- node->uniq_verts - 1;
- }
- }
-
- if (!G.background) {
- node->draw_buffers =
- GPU_build_mesh_buffers(node->face_vert_indices,
- bvh->faces, bvh->verts,
- node->prim_indices,
- node->totprim);
- }
-
- node->flag |= PBVH_UpdateDrawBuffers;
-
- BLI_ghash_free(map, NULL, NULL);
-}
-
-static void build_grids_leaf_node(PBVH *bvh, PBVHNode *node)
-{
- if (!G.background) {
- node->draw_buffers =
- GPU_build_grid_buffers(node->prim_indices,
- node->totprim, bvh->grid_hidden, bvh->gridkey.grid_size);
- }
- node->flag |= PBVH_UpdateDrawBuffers;
-}
-
-static void update_vb(PBVH *bvh, PBVHNode *node, BBC *prim_bbc,
- int offset, int count)
-{
- int i;
-
- BB_reset(&node->vb);
- for (i = offset + count - 1; i >= offset; --i) {
- BB_expand_with_bb(&node->vb, (BB *)(&prim_bbc[bvh->prim_indices[i]]));
- }
- node->orig_vb = node->vb;
-}
-
-static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc,
- int offset, int count)
-{
- bvh->nodes[node_index].flag |= PBVH_Leaf;
-
- bvh->nodes[node_index].prim_indices = bvh->prim_indices + offset;
- bvh->nodes[node_index].totprim = count;
-
- /* Still need vb for searches */
- update_vb(bvh, &bvh->nodes[node_index], prim_bbc, offset, count);
-
- if (bvh->faces)
- build_mesh_leaf_node(bvh, bvh->nodes + node_index);
- else
- build_grids_leaf_node(bvh, bvh->nodes + node_index);
-}
-
-/* Return zero if all primitives in the node can be drawn with the
- * same material (including flat/smooth shading), non-zerootherwise */
-static int leaf_needs_material_split(PBVH *bvh, int offset, int count)
-{
- int i, prim;
-
- if (count <= 1)
- return 0;
-
- if (bvh->faces) {
- const MFace *first = &bvh->faces[bvh->prim_indices[offset]];
-
- for (i = offset + count - 1; i > offset; --i) {
- prim = bvh->prim_indices[i];
- if (!face_materials_match(first, &bvh->faces[prim]))
- return 1;
- }
- }
- else {
- const DMFlagMat *first = &bvh->grid_flag_mats[bvh->prim_indices[offset]];
-
- for (i = offset + count - 1; i > offset; --i) {
- prim = bvh->prim_indices[i];
- if (!grid_materials_match(first, &bvh->grid_flag_mats[prim]))
- return 1;
- }
- }
-
- return 0;
-}
-
-
-/* Recursively build a node in the tree
- *
- * vb is the voxel box around all of the primitives contained in
- * this node.
- *
- * cb is the bounding box around all the centroids of the primitives
- * contained in this node
- *
- * offset and start indicate a range in the array of primitive indices
- */
-
-static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc,
- int offset, int count)
-{
- int i, axis, end, below_leaf_limit;
- BB cb_backing;
-
- /* Decide whether this is a leaf or not */
- below_leaf_limit = count <= bvh->leaf_limit;
- if (below_leaf_limit) {
- if (!leaf_needs_material_split(bvh, offset, count)) {
- build_leaf(bvh, node_index, prim_bbc, offset, count);
- return;
- }
- }
-
- /* Add two child nodes */
- bvh->nodes[node_index].children_offset = bvh->totnode;
- grow_nodes(bvh, bvh->totnode + 2);
-
- /* Update parent node bounding box */
- update_vb(bvh, &bvh->nodes[node_index], prim_bbc, offset, count);
-
- if (!below_leaf_limit) {
- /* Find axis with widest range of primitive centroids */
- if (!cb) {
- cb = &cb_backing;
- BB_reset(cb);
- for (i = offset + count - 1; i >= offset; --i)
- BB_expand(cb, prim_bbc[bvh->prim_indices[i]].bcentroid);
- }
- axis = BB_widest_axis(cb);
-
- /* Partition primitives along that axis */
- end = partition_indices(bvh->prim_indices,
- offset, offset + count - 1,
- axis,
- (cb->bmax[axis] + cb->bmin[axis]) * 0.5f,
- prim_bbc);
- }
- else {
- /* Partition primitives by material */
- end = partition_indices_material(bvh, offset, offset + count - 1);
- }
-
- /* Build children */
- build_sub(bvh, bvh->nodes[node_index].children_offset, NULL,
- prim_bbc, offset, end - offset);
- build_sub(bvh, bvh->nodes[node_index].children_offset + 1, NULL,
- prim_bbc, end, offset + count - end);
-}
-
-static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim)
-{
- int i;
-
- if (totprim != bvh->totprim) {
- bvh->totprim = totprim;
- if (bvh->nodes) MEM_freeN(bvh->nodes);
- if (bvh->prim_indices) MEM_freeN(bvh->prim_indices);
- bvh->prim_indices = MEM_callocN(sizeof(int) * totprim,
- "bvh prim indices");
- for (i = 0; i < totprim; ++i)
- bvh->prim_indices[i] = i;
- bvh->totnode = 0;
- if (bvh->node_mem_count < 100) {
- bvh->node_mem_count = 100;
- bvh->nodes = MEM_callocN(sizeof(PBVHNode) *
- bvh->node_mem_count,
- "bvh initial nodes");
- }
- }
-
- bvh->totnode = 1;
- build_sub(bvh, 0, cb, prim_bbc, 0, totprim);
-}
-
-/* Do a full rebuild with on Mesh data structure */
-void BLI_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int totvert, struct CustomData *vdata)
-{
- BBC *prim_bbc = NULL;
- BB cb;
- int i, j;
-
- bvh->type = PBVH_FACES;
- bvh->faces = faces;
- bvh->verts = verts;
- bvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap");
- bvh->totvert = totvert;
- bvh->leaf_limit = LEAF_LIMIT;
- bvh->vdata = vdata;
-
- BB_reset(&cb);
-
- /* For each face, store the AABB and the AABB centroid */
- prim_bbc = MEM_mallocN(sizeof(BBC) * totface, "prim_bbc");
-
- for (i = 0; i < totface; ++i) {
- MFace *f = faces + i;
- const int sides = f->v4 ? 4 : 3;
- BBC *bbc = prim_bbc + i;
-
- BB_reset((BB *)bbc);
-
- for (j = 0; j < sides; ++j)
- BB_expand((BB *)bbc, verts[(&f->v1)[j]].co);
-
- BBC_update_centroid(bbc);
-
- BB_expand(&cb, bbc->bcentroid);
- }
-
- if (totface)
- pbvh_build(bvh, &cb, prim_bbc, totface);
-
- MEM_freeN(prim_bbc);
- MEM_freeN(bvh->vert_bitmap);
-}
-
-/* Do a full rebuild with on Grids data structure */
-void BLI_pbvh_build_grids(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj,
- int totgrid, CCGKey *key, void **gridfaces, DMFlagMat *flagmats, BLI_bitmap *grid_hidden)
-{
- BBC *prim_bbc = NULL;
- BB cb;
- int gridsize = key->grid_size;
- int i, j;
-
- bvh->type = PBVH_GRIDS;
- bvh->grids = grids;
- bvh->gridadj = gridadj;
- bvh->gridfaces = gridfaces;
- bvh->grid_flag_mats = flagmats;
- bvh->totgrid = totgrid;
- bvh->gridkey = *key;
- bvh->grid_hidden = grid_hidden;
- bvh->leaf_limit = max_ii(LEAF_LIMIT / ((gridsize - 1) * (gridsize - 1)), 1);
-
- BB_reset(&cb);
-
- /* For each grid, store the AABB and the AABB centroid */
- prim_bbc = MEM_mallocN(sizeof(BBC) * totgrid, "prim_bbc");
-
- for (i = 0; i < totgrid; ++i) {
- CCGElem *grid = grids[i];
- BBC *bbc = prim_bbc + i;
-
- BB_reset((BB *)bbc);
-
- for (j = 0; j < gridsize * gridsize; ++j)
- BB_expand((BB *)bbc, CCG_elem_offset_co(key, grid, j));
-
- BBC_update_centroid(bbc);
-
- BB_expand(&cb, bbc->bcentroid);
- }
-
- if (totgrid)
- pbvh_build(bvh, &cb, prim_bbc, totgrid);
-
- MEM_freeN(prim_bbc);
-}
-
-PBVH *BLI_pbvh_new(void)
-{
- PBVH *bvh = MEM_callocN(sizeof(PBVH), "pbvh");
-
- return bvh;
-}
-
-void BLI_pbvh_free(PBVH *bvh)
-{
- PBVHNode *node;
- int i;
-
- for (i = 0; i < bvh->totnode; ++i) {
- node = &bvh->nodes[i];
-
- if (node->flag & PBVH_Leaf) {
- if (node->draw_buffers)
- GPU_free_buffers(node->draw_buffers);
- if (node->vert_indices)
- MEM_freeN(node->vert_indices);
- if (node->face_vert_indices)
- MEM_freeN(node->face_vert_indices);
- }
- }
-
- if (bvh->deformed) {
- if (bvh->verts) {
- /* if pbvh was deformed, new memory was allocated for verts/faces -- free it */
-
- MEM_freeN(bvh->verts);
- if (bvh->faces)
- MEM_freeN(bvh->faces);
- }
- }
-
- if (bvh->nodes)
- MEM_freeN(bvh->nodes);
-
- if (bvh->prim_indices)
- MEM_freeN(bvh->prim_indices);
-
- MEM_freeN(bvh);
-}
-
-static void pbvh_iter_begin(PBVHIter *iter, PBVH *bvh, BLI_pbvh_SearchCallback scb, void *search_data)
-{
- iter->bvh = bvh;
- iter->scb = scb;
- iter->search_data = search_data;
-
- iter->stack = iter->stackfixed;
- iter->stackspace = STACK_FIXED_DEPTH;
-
- iter->stack[0].node = bvh->nodes;
- iter->stack[0].revisiting = 0;
- iter->stacksize = 1;
-}
-
-static void pbvh_iter_end(PBVHIter *iter)
-{
- if (iter->stackspace > STACK_FIXED_DEPTH)
- MEM_freeN(iter->stack);
-}
-
-static void pbvh_stack_push(PBVHIter *iter, PBVHNode *node, int revisiting)
-{
- if (iter->stacksize == iter->stackspace) {
- PBVHStack *newstack;
-
- iter->stackspace *= 2;
- newstack = MEM_callocN(sizeof(PBVHStack) * iter->stackspace, "PBVHStack");
- memcpy(newstack, iter->stack, sizeof(PBVHStack) * iter->stacksize);
-
- if (iter->stackspace > STACK_FIXED_DEPTH)
- MEM_freeN(iter->stack);
- iter->stack = newstack;
- }
-
- iter->stack[iter->stacksize].node = node;
- iter->stack[iter->stacksize].revisiting = revisiting;
- iter->stacksize++;
-}
-
-static PBVHNode *pbvh_iter_next(PBVHIter *iter)
-{
- PBVHNode *node;
- int revisiting;
-
- /* purpose here is to traverse tree, visiting child nodes before their
- * parents, this order is necessary for e.g. computing bounding boxes */
-
- while (iter->stacksize) {
- /* pop node */
- iter->stacksize--;
- node = iter->stack[iter->stacksize].node;
-
- /* on a mesh with no faces this can happen
- * can remove this check if we know meshes have at least 1 face */
- if (node == NULL)
- return NULL;
-
- revisiting = iter->stack[iter->stacksize].revisiting;
-
- /* revisiting node already checked */
- if (revisiting)
- return node;
-
- if (iter->scb && !iter->scb(node, iter->search_data))
- continue; /* don't traverse, outside of search zone */
-
- if (node->flag & PBVH_Leaf) {
- /* immediately hit leaf node */
- return node;
- }
- else {
- /* come back later when children are done */
- pbvh_stack_push(iter, node, 1);
-
- /* push two child nodes on the stack */
- pbvh_stack_push(iter, iter->bvh->nodes + node->children_offset + 1, 0);
- pbvh_stack_push(iter, iter->bvh->nodes + node->children_offset, 0);
- }
- }
-
- return NULL;
-}
-
-static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter)
-{
- PBVHNode *node;
-
- while (iter->stacksize) {
- /* pop node */
- iter->stacksize--;
- node = iter->stack[iter->stacksize].node;
-
- /* on a mesh with no faces this can happen
- * can remove this check if we know meshes have at least 1 face */
- if (node == NULL) return NULL;
-
- if (iter->scb && !iter->scb(node, iter->search_data)) continue; /* don't traverse, outside of search zone */
-
- if (node->flag & PBVH_Leaf) {
- /* immediately hit leaf node */
- return node;
- }
- else {
- pbvh_stack_push(iter, iter->bvh->nodes + node->children_offset + 1, 0);
- pbvh_stack_push(iter, iter->bvh->nodes + node->children_offset, 0);
- }
- }
-
- return NULL;
-}
-
-void BLI_pbvh_search_gather(PBVH *bvh,
- BLI_pbvh_SearchCallback scb, void *search_data,
- PBVHNode ***r_array, int *r_tot)
-{
- PBVHIter iter;
- PBVHNode **array = NULL, **newarray, *node;
- int tot = 0, space = 0;
-
- pbvh_iter_begin(&iter, bvh, scb, search_data);
-
- while ((node = pbvh_iter_next(&iter))) {
- if (node->flag & PBVH_Leaf) {
- if (tot == space) {
- /* resize array if needed */
- space = (tot == 0) ? 32 : space * 2;
- newarray = MEM_callocN(sizeof(PBVHNode) * space, "PBVHNodeSearch");
-
- if (array) {
- memcpy(newarray, array, sizeof(PBVHNode) * tot);
- MEM_freeN(array);
- }
-
- array = newarray;
- }
-
- array[tot] = node;
- tot++;
- }
- }
-
- pbvh_iter_end(&iter);
-
- if (tot == 0 && array) {
- MEM_freeN(array);
- array = NULL;
- }
-
- *r_array = array;
- *r_tot = tot;
-}
-
-void BLI_pbvh_search_callback(PBVH *bvh,
- BLI_pbvh_SearchCallback scb, void *search_data,
- BLI_pbvh_HitCallback hcb, void *hit_data)
-{
- PBVHIter iter;
- PBVHNode *node;
-
- pbvh_iter_begin(&iter, bvh, scb, search_data);
-
- while ((node = pbvh_iter_next(&iter)))
- if (node->flag & PBVH_Leaf)
- hcb(node, hit_data);
-
- pbvh_iter_end(&iter);
-}
-
-typedef struct node_tree {
- PBVHNode *data;
-
- struct node_tree *left;
- struct node_tree *right;
-} node_tree;
-
-static void node_tree_insert(node_tree *tree, node_tree *new_node)
-{
- if (new_node->data->tmin < tree->data->tmin) {
- if (tree->left) {
- node_tree_insert(tree->left, new_node);
- }
- else {
- tree->left = new_node;
- }
- }
- else {
- if (tree->right) {
- node_tree_insert(tree->right, new_node);
- }
- else {
- tree->right = new_node;
- }
- }
-}
-
-static void traverse_tree(node_tree *tree, BLI_pbvh_HitOccludedCallback hcb, void *hit_data, float *tmin)
-{
- if (tree->left) traverse_tree(tree->left, hcb, hit_data, tmin);
-
- hcb(tree->data, hit_data, tmin);
-
- if (tree->right) traverse_tree(tree->right, hcb, hit_data, tmin);
-}
-
-static void free_tree(node_tree *tree)
-{
- if (tree->left) {
- free_tree(tree->left);
- tree->left = 0;
- }
-
- if (tree->right) {
- free_tree(tree->right);
- tree->right = 0;
- }
-
- free(tree);
-}
-
-float BLI_pbvh_node_get_tmin(PBVHNode *node)
-{
- return node->tmin;
-}
-
-static void BLI_pbvh_search_callback_occluded(PBVH *bvh,
- BLI_pbvh_SearchCallback scb, void *search_data,
- BLI_pbvh_HitOccludedCallback hcb, void *hit_data)
-{
- PBVHIter iter;
- PBVHNode *node;
- node_tree *tree = 0;
-
- pbvh_iter_begin(&iter, bvh, scb, search_data);
-
- while ((node = pbvh_iter_next_occluded(&iter))) {
- if (node->flag & PBVH_Leaf) {
- node_tree *new_node = malloc(sizeof(node_tree));
-
- new_node->data = node;
-
- new_node->left = NULL;
- new_node->right = NULL;
-
- if (tree) {
- node_tree_insert(tree, new_node);
- }
- else {
- tree = new_node;
- }
- }
- }
-
- pbvh_iter_end(&iter);
-
- if (tree) {
- float tmin = FLT_MAX;
- traverse_tree(tree, hcb, hit_data, &tmin);
- free_tree(tree);
- }
-}
-
-static int update_search_cb(PBVHNode *node, void *data_v)
-{
- int flag = GET_INT_FROM_POINTER(data_v);
-
- if (node->flag & PBVH_Leaf)
- return (node->flag & flag);
-
- return 1;
-}
-
-static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes,
- int totnode, float (*face_nors)[3])
-{
- float (*vnor)[3];
- int n;
-
- if (bvh->type != PBVH_FACES)
- return;
-
- /* could be per node to save some memory, but also means
- * we have to store for each vertex which node it is in */
- vnor = MEM_callocN(sizeof(float) * 3 * bvh->totvert, "bvh temp vnors");
-
- /* subtle assumptions:
- * - We know that for all edited vertices, the nodes with faces
- * adjacent to these vertices have been marked with PBVH_UpdateNormals.
- * This is true because if the vertex is inside the brush radius, the
- * bounding box of it's adjacent faces will be as well.
- * - However this is only true for the vertices that have actually been
- * edited, not for all vertices in the nodes marked for update, so we
- * can only update vertices marked with ME_VERT_PBVH_UPDATE.
- */
-
- #pragma omp parallel for private(n) schedule(static)
- for (n = 0; n < totnode; n++) {
- PBVHNode *node = nodes[n];
-
- if ((node->flag & PBVH_UpdateNormals)) {
- int i, j, totface, *faces;
-
- faces = node->prim_indices;
- totface = node->totprim;
-
- for (i = 0; i < totface; ++i) {
- MFace *f = bvh->faces + faces[i];
- float fn[3];
- unsigned int *fv = &f->v1;
- int sides = (f->v4) ? 4 : 3;
-
- if (f->v4)
- normal_quad_v3(fn, bvh->verts[f->v1].co, bvh->verts[f->v2].co,
- bvh->verts[f->v3].co, bvh->verts[f->v4].co);
- else
- normal_tri_v3(fn, bvh->verts[f->v1].co, bvh->verts[f->v2].co,
- bvh->verts[f->v3].co);
-
- for (j = 0; j < sides; ++j) {
- int v = fv[j];
-
- if (bvh->verts[v].flag & ME_VERT_PBVH_UPDATE) {
- /* this seems like it could be very slow but profile
- * does not show this, so just leave it for now? */
- #pragma omp atomic
- vnor[v][0] += fn[0];
- #pragma omp atomic
- vnor[v][1] += fn[1];
- #pragma omp atomic
- vnor[v][2] += fn[2];
- }
- }
-
- if (face_nors)
- copy_v3_v3(face_nors[faces[i]], fn);
- }
- }
- }
-
- #pragma omp parallel for private(n) schedule(static)
- for (n = 0; n < totnode; n++) {
- PBVHNode *node = nodes[n];
-
- if (node->flag & PBVH_UpdateNormals) {
- int i, *verts, totvert;
-
- verts = node->vert_indices;
- totvert = node->uniq_verts;
-
- for (i = 0; i < totvert; ++i) {
- const int v = verts[i];
- MVert *mvert = &bvh->verts[v];
-
- if (mvert->flag & ME_VERT_PBVH_UPDATE) {
- float no[3];
-
- copy_v3_v3(no, vnor[v]);
- normalize_v3(no);
- normal_float_to_short_v3(mvert->no, no);
-
- mvert->flag &= ~ME_VERT_PBVH_UPDATE;
- }
- }
-
- node->flag &= ~PBVH_UpdateNormals;
- }
- }
-
- MEM_freeN(vnor);
-}
-
-static void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes,
- int totnode, int flag)
-{
- int n;
-
- /* update BB, redraw flag */
- #pragma omp parallel for private(n) schedule(static)
- for (n = 0; n < totnode; n++) {
- PBVHNode *node = nodes[n];
-
- if ((flag & PBVH_UpdateBB) && (node->flag & PBVH_UpdateBB))
- /* don't clear flag yet, leave it for flushing later */
- update_node_vb(bvh, node);
-
- if ((flag & PBVH_UpdateOriginalBB) && (node->flag & PBVH_UpdateOriginalBB))
- node->orig_vb = node->vb;
-
- if ((flag & PBVH_UpdateRedraw) && (node->flag & PBVH_UpdateRedraw))
- node->flag &= ~PBVH_UpdateRedraw;
- }
-}
-
-static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
-{
- PBVHNode *node;
- int n;
-
- /* can't be done in parallel with OpenGL */
- for (n = 0; n < totnode; n++) {
- node = nodes[n];
-
- if (node->flag & PBVH_RebuildDrawBuffers) {
- GPU_free_buffers(node->draw_buffers);
- switch (bvh->type) {
- case PBVH_GRIDS:
- node->draw_buffers =
- GPU_build_grid_buffers(node->prim_indices,
- node->totprim,
- bvh->grid_hidden,
- bvh->gridkey.grid_size);
- break;
- case PBVH_FACES:
- node->draw_buffers =
- GPU_build_mesh_buffers(node->face_vert_indices,
- bvh->faces, bvh->verts,
- node->prim_indices,
- node->totprim);
- break;
- }
-
- node->flag &= ~PBVH_RebuildDrawBuffers;
- }
-
- if (node->flag & PBVH_UpdateDrawBuffers) {
- switch (bvh->type) {
- case PBVH_GRIDS:
- GPU_update_grid_buffers(node->draw_buffers,
- bvh->grids,
- bvh->grid_flag_mats,
- node->prim_indices,
- node->totprim,
- &bvh->gridkey,
- bvh->show_diffuse_color);
- break;
- case PBVH_FACES:
- GPU_update_mesh_buffers(node->draw_buffers,
- bvh->verts,
- node->vert_indices,
- node->uniq_verts +
- node->face_verts,
- CustomData_get_layer(bvh->vdata,
- CD_PAINT_MASK),
- node->face_vert_indices,
- bvh->show_diffuse_color);
- break;
- }
-
- node->flag &= ~PBVH_UpdateDrawBuffers;
- }
- }
-}
-
-static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag)
-{
- int update = 0;
-
- /* difficult to multithread well, we just do single threaded recursive */
- if (node->flag & PBVH_Leaf) {
- if (flag & PBVH_UpdateBB) {
- update |= (node->flag & PBVH_UpdateBB);
- node->flag &= ~PBVH_UpdateBB;
- }
-
- if (flag & PBVH_UpdateOriginalBB) {
- update |= (node->flag & PBVH_UpdateOriginalBB);
- node->flag &= ~PBVH_UpdateOriginalBB;
- }
-
- return update;
- }
- else {
- update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset, flag);
- update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset + 1, flag);
-
- if (update & PBVH_UpdateBB)
- update_node_vb(bvh, node);
- if (update & PBVH_UpdateOriginalBB)
- node->orig_vb = node->vb;
- }
-
- return update;
-}
-
-void BLI_pbvh_update(PBVH *bvh, int flag, float (*face_nors)[3])
-{
- PBVHNode **nodes;
- int totnode;
-
- if (!bvh->nodes)
- return;
-
- BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(flag),
- &nodes, &totnode);
-
- if (flag & PBVH_UpdateNormals)
- pbvh_update_normals(bvh, nodes, totnode, face_nors);
-
- if (flag & (PBVH_UpdateBB | PBVH_UpdateOriginalBB | PBVH_UpdateRedraw))
- pbvh_update_BB_redraw(bvh, nodes, totnode, flag);
-
- if (flag & (PBVH_UpdateBB | PBVH_UpdateOriginalBB))
- pbvh_flush_bb(bvh, bvh->nodes, flag);
-
- if (nodes) MEM_freeN(nodes);
-}
-
-void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3])
-{
- PBVHIter iter;
- PBVHNode *node;
- BB bb;
-
- BB_reset(&bb);
-
- pbvh_iter_begin(&iter, bvh, NULL, NULL);
-
- while ((node = pbvh_iter_next(&iter)))
- if (node->flag & PBVH_UpdateRedraw)
- BB_expand_with_bb(&bb, &node->vb);
-
- pbvh_iter_end(&iter);
-
- copy_v3_v3(bb_min, bb.bmin);
- copy_v3_v3(bb_max, bb.bmax);
-}
-
-void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *totface)
-{
- PBVHIter iter;
- PBVHNode *node;
- GHashIterator *hiter;
- GHash *map;
- void *face, **faces;
- unsigned i;
- int tot;
-
- map = BLI_ghash_ptr_new("pbvh_get_grid_updates gh");
-
- pbvh_iter_begin(&iter, bvh, NULL, NULL);
-
- while ((node = pbvh_iter_next(&iter))) {
- if (node->flag & PBVH_UpdateNormals) {
- for (i = 0; i < node->totprim; ++i) {
- face = bvh->gridfaces[node->prim_indices[i]];
- if (!BLI_ghash_lookup(map, face))
- BLI_ghash_insert(map, face, face);
- }
-
- if (clear)
- node->flag &= ~PBVH_UpdateNormals;
- }
- }
-
- pbvh_iter_end(&iter);
-
- tot = BLI_ghash_size(map);
- if (tot == 0) {
- *totface = 0;
- *gridfaces = NULL;
- BLI_ghash_free(map, NULL, NULL);
- return;
- }
-
- faces = MEM_callocN(sizeof(void *) * tot, "PBVH Grid Faces");
-
- for (hiter = BLI_ghashIterator_new(map), i = 0;
- !BLI_ghashIterator_isDone(hiter);
- BLI_ghashIterator_step(hiter), ++i)
- {
- faces[i] = BLI_ghashIterator_getKey(hiter);
- }
-
- BLI_ghashIterator_free(hiter);
-
- BLI_ghash_free(map, NULL, NULL);
-
- *totface = tot;
- *gridfaces = faces;
-}
-
-/***************************** PBVH Access ***********************************/
-
-PBVHType BLI_pbvh_type(const PBVH *bvh)
-{
- return bvh->type;
-}
-
-BLI_bitmap *BLI_pbvh_grid_hidden(const PBVH *bvh)
-{
- BLI_assert(bvh->type == PBVH_GRIDS);
- return bvh->grid_hidden;
-}
-
-void BLI_pbvh_get_grid_key(const PBVH *bvh, CCGKey *key)
-{
- BLI_assert(bvh->type == PBVH_GRIDS);
- *key = bvh->gridkey;
-}
-
-/***************************** Node Access ***********************************/
-
-void BLI_pbvh_node_mark_update(PBVHNode *node)
-{
- node->flag |= PBVH_UpdateNormals | PBVH_UpdateBB | PBVH_UpdateOriginalBB | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
-}
-
-void BLI_pbvh_node_mark_rebuild_draw(PBVHNode *node)
-{
- node->flag |= PBVH_RebuildDrawBuffers | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
-}
-
-void BLI_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden)
-{
- BLI_assert(node->flag & PBVH_Leaf);
-
- if (fully_hidden)
- node->flag |= PBVH_FullyHidden;
- else
- node->flag &= ~PBVH_FullyHidden;
-}
-
-void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, int **vert_indices, MVert **verts)
-{
- if (vert_indices) *vert_indices = node->vert_indices;
- if (verts) *verts = bvh->verts;
-}
-
-void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *totvert)
-{
- int tot;
-
- switch (bvh->type) {
- case PBVH_GRIDS:
- tot = node->totprim * bvh->gridkey.grid_area;
- if (totvert) *totvert = tot;
- if (uniquevert) *uniquevert = tot;
- break;
- case PBVH_FACES:
- if (totvert) *totvert = node->uniq_verts + node->face_verts;
- if (uniquevert) *uniquevert = node->uniq_verts;
- break;
- }
-}
-
-void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, CCGElem ***griddata, DMGridAdjacency **gridadj)
-{
- switch (bvh->type) {
- case PBVH_GRIDS:
- if (grid_indices) *grid_indices = node->prim_indices;
- if (totgrid) *totgrid = node->totprim;
- if (maxgrid) *maxgrid = bvh->totgrid;
- if (gridsize) *gridsize = bvh->gridkey.grid_size;
- if (griddata) *griddata = bvh->grids;
- if (gridadj) *gridadj = bvh->gridadj;
- break;
- case PBVH_FACES:
- if (grid_indices) *grid_indices = NULL;
- if (totgrid) *totgrid = 0;
- if (maxgrid) *maxgrid = 0;
- if (gridsize) *gridsize = 0;
- if (griddata) *griddata = NULL;
- if (gridadj) *gridadj = NULL;
- break;
- }
-}
-
-void BLI_pbvh_node_get_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
-{
- copy_v3_v3(bb_min, node->vb.bmin);
- copy_v3_v3(bb_max, node->vb.bmax);
-}
-
-void BLI_pbvh_node_get_original_BB(PBVHNode *node, float bb_min[3], float bb_max[3])
-{
- copy_v3_v3(bb_min, node->orig_vb.bmin);
- copy_v3_v3(bb_max, node->orig_vb.bmax);
-}
-
-void BLI_pbvh_node_get_proxies(PBVHNode *node, PBVHProxyNode **proxies, int *proxy_count)
-{
- if (node->proxy_count > 0) {
- if (proxies) *proxies = node->proxies;
- if (proxy_count) *proxy_count = node->proxy_count;
- }
- else {
- if (proxies) *proxies = 0;
- if (proxy_count) *proxy_count = 0;
- }
-}
-
-/********************************* Raycast ***********************************/
-
-typedef struct {
- IsectRayAABBData ray;
- int original;
-} RaycastData;
-
-static int ray_aabb_intersect(PBVHNode *node, void *data_v)
-{
- RaycastData *rcd = data_v;
- float bb_min[3], bb_max[3];
-
- if (rcd->original)
- BLI_pbvh_node_get_original_BB(node, bb_min, bb_max);
- else
- BLI_pbvh_node_get_BB(node, bb_min, bb_max);
-
- return isect_ray_aabb(&rcd->ray, bb_min, bb_max, &node->tmin);
-}
-
-void BLI_pbvh_raycast(PBVH *bvh, BLI_pbvh_HitOccludedCallback cb, void *data,
- const float ray_start[3], const float ray_normal[3],
- int original)
-{
- RaycastData rcd;
-
- isect_ray_aabb_initialize(&rcd.ray, ray_start, ray_normal);
- rcd.original = original;
-
- BLI_pbvh_search_callback_occluded(bvh, ray_aabb_intersect, &rcd, cb, data);
-}
-
-static int ray_face_intersection(const float ray_start[3],
- const float ray_normal[3],
- const float *t0, const float *t1,
- const float *t2, const float *t3,
- float *fdist)
-{
- float dist;
-
- if ((isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t1, t2, &dist, NULL, 0.1f) && dist < *fdist) ||
- (t3 && isect_ray_tri_epsilon_v3(ray_start, ray_normal, t0, t2, t3, &dist, NULL, 0.1f) && dist < *fdist))
- {
- *fdist = dist;
- return 1;
- }
- else {
- return 0;
- }
-}
-
-static int pbvh_faces_node_raycast(PBVH *bvh, const PBVHNode *node,
- float (*origco)[3],
- const float ray_start[3],
- const float ray_normal[3], float *dist)
-{
- const MVert *vert = bvh->verts;
- const int *faces = node->prim_indices;
- int i, hit = 0, totface = node->totprim;
-
- for (i = 0; i < totface; ++i) {
- const MFace *f = bvh->faces + faces[i];
- const int *face_verts = node->face_vert_indices[i];
-
- if (paint_is_face_hidden(f, vert))
- continue;
-
- if (origco) {
- /* intersect with backuped original coordinates */
- hit |= ray_face_intersection(ray_start, ray_normal,
- origco[face_verts[0]],
- origco[face_verts[1]],
- origco[face_verts[2]],
- f->v4 ? origco[face_verts[3]] : NULL,
- dist);
- }
- else {
- /* intersect with current coordinates */
- hit |= ray_face_intersection(ray_start, ray_normal,
- vert[f->v1].co,
- vert[f->v2].co,
- vert[f->v3].co,
- f->v4 ? vert[f->v4].co : NULL,
- dist);
- }
- }
-
- return hit;
-}
-
-static int pbvh_grids_node_raycast(PBVH *bvh, PBVHNode *node,
- float (*origco)[3],
- const float ray_start[3],
- const float ray_normal[3], float *dist)
-{
- int totgrid = node->totprim;
- int gridsize = bvh->gridkey.grid_size;
- int i, x, y, hit = 0;
-
- for (i = 0; i < totgrid; ++i) {
- CCGElem *grid = bvh->grids[node->prim_indices[i]];
- BLI_bitmap gh;
-
- if (!grid)
- continue;
-
- gh = bvh->grid_hidden[node->prim_indices[i]];
-
- for (y = 0; y < gridsize - 1; ++y) {
- for (x = 0; x < gridsize - 1; ++x) {
- /* check if grid face is hidden */
- if (gh) {
- if (paint_is_grid_face_hidden(gh, gridsize, x, y))
- continue;
- }
-
- if (origco) {
- hit |= ray_face_intersection(ray_start, ray_normal,
- origco[y * gridsize + x],
- origco[y * gridsize + x + 1],
- origco[(y + 1) * gridsize + x + 1],
- origco[(y + 1) * gridsize + x],
- dist);
- }
- else {
- hit |= ray_face_intersection(ray_start, ray_normal,
- CCG_grid_elem_co(&bvh->gridkey, grid, x, y),
- CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y),
- CCG_grid_elem_co(&bvh->gridkey, grid, x + 1, y + 1),
- CCG_grid_elem_co(&bvh->gridkey, grid, x, y + 1),
- dist);
- }
- }
- }
-
- if (origco)
- origco += gridsize * gridsize;
- }
-
- return hit;
-}
-
-int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3],
- const float ray_start[3], const float ray_normal[3],
- float *dist)
-{
- int hit = 0;
-
- if (node->flag & PBVH_FullyHidden)
- return 0;
-
- switch (bvh->type) {
- case PBVH_FACES:
- hit |= pbvh_faces_node_raycast(bvh, node, origco,
- ray_start, ray_normal, dist);
- break;
- case PBVH_GRIDS:
- hit |= pbvh_grids_node_raycast(bvh, node, origco,
- ray_start, ray_normal, dist);
- break;
- }
-
- return hit;
-}
-
-//#include <GL/glew.h>
-
-void BLI_pbvh_node_draw(PBVHNode *node, void *setMaterial)
-{
-#if 0
- /* XXX: Just some quick code to show leaf nodes in different colors */
- float col[3]; int i;
-
- if (0) { //is_partial) {
- col[0] = (rand() / (float)RAND_MAX); col[1] = col[2] = 0.6;
- }
- else {
- srand((long long)node);
- for (i = 0; i < 3; ++i)
- col[i] = (rand() / (float)RAND_MAX) * 0.3 + 0.7;
- }
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col);
-
- glColor3f(1, 0, 0);
-#endif
-
- if (!(node->flag & PBVH_FullyHidden))
- GPU_draw_buffers(node->draw_buffers, setMaterial);
-}
-
-typedef enum {
- ISECT_INSIDE,
- ISECT_OUTSIDE,
- ISECT_INTERSECT
-} PlaneAABBIsect;
-
-/* Adapted from:
- * http://www.gamedev.net/community/forums/topic.asp?topic_id=512123
- * Returns true if the AABB is at least partially within the frustum
- * (ok, not a real frustum), false otherwise.
- */
-static PlaneAABBIsect test_planes_aabb(const float bb_min[3],
- const float bb_max[3],
- const float (*planes)[4])
-{
- float vmin[3], vmax[3];
- PlaneAABBIsect ret = ISECT_INSIDE;
- int i, axis;
-
- for (i = 0; i < 4; ++i) {
- for (axis = 0; axis < 3; ++axis) {
- if (planes[i][axis] > 0) {
- vmin[axis] = bb_min[axis];
- vmax[axis] = bb_max[axis];
- }
- else {
- vmin[axis] = bb_max[axis];
- vmax[axis] = bb_min[axis];
- }
- }
-
- if (dot_v3v3(planes[i], vmin) + planes[i][3] > 0)
- return ISECT_OUTSIDE;
- else if (dot_v3v3(planes[i], vmax) + planes[i][3] >= 0)
- ret = ISECT_INTERSECT;
- }
-
- return ret;
-}
-
-int BLI_pbvh_node_planes_contain_AABB(PBVHNode *node, void *data)
-{
- float bb_min[3], bb_max[3];
-
- BLI_pbvh_node_get_BB(node, bb_min, bb_max);
- return test_planes_aabb(bb_min, bb_max, data) != ISECT_OUTSIDE;
-}
-
-int BLI_pbvh_node_planes_exclude_AABB(PBVHNode *node, void *data)
-{
- float bb_min[3], bb_max[3];
-
- BLI_pbvh_node_get_BB(node, bb_min, bb_max);
- return test_planes_aabb(bb_min, bb_max, data) != ISECT_INSIDE;
-}
-
-static void pbvh_node_check_diffuse_changed(PBVH *bvh, PBVHNode *node)
-{
- if (!node->draw_buffers)
- return;
-
- if (GPU_buffers_diffuse_changed(node->draw_buffers, bvh->show_diffuse_color))
- node->flag |= PBVH_UpdateDrawBuffers;
-}
-
-void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
- DMSetMaterial setMaterial)
-{
- PBVHNode **nodes;
- int a, totnode;
-
- for (a = 0; a < bvh->totnode; a++)
- pbvh_node_check_diffuse_changed(bvh, &bvh->nodes[a]);
-
- BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(PBVH_UpdateNormals | PBVH_UpdateDrawBuffers),
- &nodes, &totnode);
-
- pbvh_update_normals(bvh, nodes, totnode, face_nors);
- pbvh_update_draw_buffers(bvh, nodes, totnode);
-
- if (nodes) MEM_freeN(nodes);
-
- if (planes) {
- BLI_pbvh_search_callback(bvh, BLI_pbvh_node_planes_contain_AABB,
- planes, BLI_pbvh_node_draw, setMaterial);
- }
- else {
- BLI_pbvh_search_callback(bvh, NULL, NULL, BLI_pbvh_node_draw, setMaterial);
- }
-}
-
-void BLI_pbvh_grids_update(PBVH *bvh, CCGElem **grids, DMGridAdjacency *gridadj, void **gridfaces,
- DMFlagMat *flagmats, BLI_bitmap *grid_hidden)
-{
- int a;
-
- bvh->grids = grids;
- bvh->gridadj = gridadj;
- bvh->gridfaces = gridfaces;
-
- if (flagmats != bvh->grid_flag_mats || bvh->grid_hidden != grid_hidden) {
- bvh->grid_flag_mats = flagmats;
- bvh->grid_hidden = grid_hidden;
-
- for (a = 0; a < bvh->totnode; ++a)
- BLI_pbvh_node_mark_rebuild_draw(&bvh->nodes[a]);
- }
-}
-
-float (*BLI_pbvh_get_vertCos(PBVH * pbvh))[3]
-{
- int a;
- float (*vertCos)[3] = NULL;
-
- if (pbvh->verts) {
- float *co;
- MVert *mvert = pbvh->verts;
-
- vertCos = MEM_callocN(3 * pbvh->totvert * sizeof(float), "BLI_pbvh_get_vertCoords");
- co = (float *)vertCos;
-
- for (a = 0; a < pbvh->totvert; a++, mvert++, co += 3) {
- copy_v3_v3(co, mvert->co);
- }
- }
-
- return vertCos;
-}
-
-void BLI_pbvh_apply_vertCos(PBVH *pbvh, float (*vertCos)[3])
-{
- int a;
-
- if (!pbvh->deformed) {
- if (pbvh->verts) {
- /* if pbvh is not already deformed, verts/faces points to the */
- /* original data and applying new coords to this arrays would lead to */
- /* unneeded deformation -- duplicate verts/faces to avoid this */
-
- pbvh->verts = MEM_dupallocN(pbvh->verts);
- pbvh->faces = MEM_dupallocN(pbvh->faces);
-
- pbvh->deformed = 1;
- }
- }
-
- if (pbvh->verts) {
- MVert *mvert = pbvh->verts;
- /* copy new verts coords */
- for (a = 0; a < pbvh->totvert; ++a, ++mvert) {
- copy_v3_v3(mvert->co, vertCos[a]);
- mvert->flag |= ME_VERT_PBVH_UPDATE;
- }
-
- /* coordinates are new -- normals should also be updated */
- BKE_mesh_calc_normals_tessface(pbvh->verts, pbvh->totvert, pbvh->faces, pbvh->totprim, NULL);
-
- for (a = 0; a < pbvh->totnode; ++a)
- BLI_pbvh_node_mark_update(&pbvh->nodes[a]);
-
- BLI_pbvh_update(pbvh, PBVH_UpdateBB, NULL);
- BLI_pbvh_update(pbvh, PBVH_UpdateOriginalBB, NULL);
-
- }
-}
-
-int BLI_pbvh_isDeformed(PBVH *pbvh)
-{
- return pbvh->deformed;
-}
-/* Proxies */
-
-PBVHProxyNode *BLI_pbvh_node_add_proxy(PBVH *bvh, PBVHNode *node)
-{
- int index, totverts;
-
- #pragma omp critical
- {
-
- index = node->proxy_count;
-
- node->proxy_count++;
-
- if (node->proxies)
- node->proxies = MEM_reallocN(node->proxies, node->proxy_count * sizeof(PBVHProxyNode));
- else
- node->proxies = MEM_mallocN(sizeof(PBVHProxyNode), "PBVHNodeProxy");
-
- BLI_pbvh_node_num_verts(bvh, node, &totverts, NULL);
- node->proxies[index].co = MEM_callocN(sizeof(float[3]) * totverts, "PBVHNodeProxy.co");
- }
-
- return node->proxies + index;
-}
-
-void BLI_pbvh_node_free_proxies(PBVHNode *node)
-{
- #pragma omp critical
- {
- int p;
-
- for (p = 0; p < node->proxy_count; p++) {
- MEM_freeN(node->proxies[p].co);
- node->proxies[p].co = 0;
- }
-
- MEM_freeN(node->proxies);
- node->proxies = 0;
-
- node->proxy_count = 0;
- }
-}
-
-void BLI_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***r_array, int *r_tot)
-{
- PBVHNode **array = NULL, **newarray, *node;
- int tot = 0, space = 0;
- int n;
-
- for (n = 0; n < pbvh->totnode; n++) {
- node = pbvh->nodes + n;
-
- if (node->proxy_count > 0) {
- if (tot == space) {
- /* resize array if needed */
- space = (tot == 0) ? 32 : space * 2;
- newarray = MEM_callocN(sizeof(PBVHNode) * space, "BLI_pbvh_gather_proxies");
-
- if (array) {
- memcpy(newarray, array, sizeof(PBVHNode) * tot);
- MEM_freeN(array);
- }
-
- array = newarray;
- }
-
- array[tot] = node;
- tot++;
- }
- }
-
- if (tot == 0 && array) {
- MEM_freeN(array);
- array = NULL;
- }
-
- *r_array = array;
- *r_tot = tot;
-}
-
-void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
- PBVHVertexIter *vi, int mode)
-{
- struct CCGElem **grids;
- struct MVert *verts;
- int *grid_indices, *vert_indices;
- int totgrid, gridsize, uniq_verts, totvert;
-
- vi->grid = 0;
- vi->no = 0;
- vi->fno = 0;
- vi->mvert = 0;
-
- BLI_pbvh_node_get_grids(bvh, node, &grid_indices, &totgrid, NULL, &gridsize, &grids, NULL);
- BLI_pbvh_node_num_verts(bvh, node, &uniq_verts, &totvert);
- BLI_pbvh_node_get_verts(bvh, node, &vert_indices, &verts);
- vi->key = &bvh->gridkey;
-
- vi->grids = grids;
- vi->grid_indices = grid_indices;
- vi->totgrid = (grids) ? totgrid : 1;
- vi->gridsize = gridsize;
-
- if (mode == PBVH_ITER_ALL)
- vi->totvert = totvert;
- else
- vi->totvert = uniq_verts;
- vi->vert_indices = vert_indices;
- vi->mverts = verts;
-
- vi->gh = NULL;
- if (vi->grids && mode == PBVH_ITER_UNIQUE)
- vi->grid_hidden = bvh->grid_hidden;
-
- vi->mask = NULL;
- if (!vi->grids)
- vi->vmask = CustomData_get_layer(bvh->vdata, CD_PAINT_MASK);
-}
-
-void pbvh_show_diffuse_color_set(PBVH *bvh, int show_diffuse_color)
-{
- bvh->show_diffuse_color = show_diffuse_color;
-}
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index ee073d5d309..fb767f54e55 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -109,9 +109,9 @@ static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], c
return 1; /* co-linear */
}
else {
- const double labda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
+ const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
- return (labda >= 0.0 && labda <= 1.0 && mu >= 0.0 && mu <= 1.0);
+ return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
}
}
static int isect_segments_fl(const float v1[2], const float v2[2], const float v3[2], const float v4[2])
@@ -121,9 +121,9 @@ static int isect_segments_fl(const float v1[2], const float v2[2], const float v
return 1; /* co-linear */
}
else {
- const double labda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
+ const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
- return (labda >= 0.0 && labda <= 1.0 && mu >= 0.0 && mu <= 1.0);
+ return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
}
}
diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c
index 68d9d74cca4..65fb490b218 100644
--- a/source/blender/blenlib/intern/winstuff.c
+++ b/source/blender/blenlib/intern/winstuff.c
@@ -41,7 +41,7 @@
#include "BLI_path_util.h"
#include "BLI_string.h"
-#include "BKE_global.h"
+#include "../blenkernel/BKE_global.h" /* G.background, bad level include (no function calls) */
#define WIN32_SKIP_HKEY_PROTECTION // need to use HKEY
#include "BLI_winstuff.h"