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:
authorRay Molenkamp <github@lazydodo.com>2018-10-19 18:16:26 +0300
committerRay Molenkamp <github@lazydodo.com>2018-10-19 18:16:26 +0300
commitbe52fd0d0fb0add1724600f162cde1219f3bdb7e (patch)
tree37c71d03631474075c14bba60ee0ccf7c223b6f9
parentcdef1e911b8effbdabb071cc8c35563ef651a840 (diff)
parentdcef3c30e306788b856f642ad9638aa98fe06517 (diff)
Merge remote-tracking branch 'origin/master' into blender2.8
-rw-r--r--build_files/build_environment/cmake/versions.cmake2
-rw-r--r--source/blender/editors/uvedit/uvedit_parametrizer.c111
-rw-r--r--source/blender/editors/uvedit/uvedit_parametrizer.h3
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c4
4 files changed, 57 insertions, 63 deletions
diff --git a/build_files/build_environment/cmake/versions.cmake b/build_files/build_environment/cmake/versions.cmake
index 7ede80a2be9..7bd994c3491 100644
--- a/build_files/build_environment/cmake/versions.cmake
+++ b/build_files/build_environment/cmake/versions.cmake
@@ -21,7 +21,7 @@ set(ZLIB_URI https://zlib.net/zlib-${ZLIB_VERSION}.tar.gz)
set(ZLIB_HASH 1c9f62f0778697a09d36121ead88e08e)
set(OPENAL_VERSION 1.18.2)
-set(OPENAL_URI http://kcat.strangesoft.net/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2)
+set(OPENAL_URI http://openal-soft.org/openal-releases/openal-soft-${OPENAL_VERSION}.tar.bz2)
set(OPENAL_HASH d4eeb0889812e2fdeaa1843523d76190)
set(PNG_VERSION 1.6.35)
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.c b/source/blender/editors/uvedit/uvedit_parametrizer.c
index 79e804725e5..352bfbf9a9e 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.c
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.c
@@ -34,6 +34,8 @@
#include "BLI_heap.h"
#include "BLI_boxpack_2d.h"
#include "BLI_convexhull_2d.h"
+#include "BLI_polyfill_2d.h"
+#include "BLI_polyfill_2d_beautify.h"
#include "uvedit_parametrizer.h"
@@ -219,6 +221,8 @@ enum PHandleState {
typedef struct PHandle {
enum PHandleState state;
MemArena *arena;
+ MemArena *polyfill_arena;
+ Heap *polyfill_heap;
PChart *construction_chart;
PHash *hash_verts;
@@ -4119,6 +4123,8 @@ ParamHandle *param_construct_begin(void)
handle->construction_chart = p_chart_new(handle);
handle->state = PHANDLE_STATE_ALLOCATED;
handle->arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 16), "param construct arena");
+ handle->polyfill_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "param polyfill arena");
+ handle->polyfill_heap = BLI_heap_new_ex(BLI_POLYFILL_ALLOC_NGON_RESERVE);
handle->aspx = 1.0f;
handle->aspy = 1.0f;
handle->do_aspect = false;
@@ -4162,82 +4168,71 @@ void param_delete(ParamHandle *handle)
}
BLI_memarena_free(phandle->arena);
+ BLI_memarena_free(phandle->polyfill_arena);
+ BLI_heap_free(phandle->polyfill_heap, NULL);
MEM_freeN(phandle);
}
static void p_add_ngon(ParamHandle *handle, ParamKey key, int nverts,
ParamKey *vkeys, float **co, float **uv,
- ParamBool *pin, ParamBool *select, const float normal[3])
+ ParamBool *pin, ParamBool *select)
{
- int *boundary = BLI_array_alloca(boundary, nverts);
-
- /* boundary vertex indexes */
- for (int i = 0; i < nverts; i++) {
- boundary[i] = i;
- }
-
- while (nverts > 2) {
- float minangle = FLT_MAX;
- float minshape = FLT_MAX;
- int i, mini = 0;
-
- /* find corner with smallest angle */
- for (i = 0; i < nverts; i++) {
- int v0 = boundary[(i + nverts - 1) % nverts];
- int v1 = boundary[i];
- int v2 = boundary[(i + 1) % nverts];
- float angle = p_vec_angle(co[v0], co[v1], co[v2]);
- float n[3];
-
- normal_tri_v3(n, co[v0], co[v1], co[v2]);
+ /* Allocate memory for polyfill. */
+ PHandle *phandle = (PHandle *)handle;
+ MemArena *arena = phandle->polyfill_arena;
+ Heap *heap = phandle->polyfill_heap;
+ unsigned int nfilltri = nverts - 2;
+ unsigned int (*tris)[3] = BLI_memarena_alloc(arena, sizeof(*tris) * (size_t)nfilltri);
+ float (*projverts)[2] = BLI_memarena_alloc(arena, sizeof(*projverts) * (size_t)nverts);
- if (normal && (dot_v3v3(n, normal) < 0.0f))
- angle = (float)(2.0 * M_PI) - angle;
+ /* Calc normal, flipped: to get a positive 2d cross product. */
+ float normal[3];
+ zero_v3(normal);
- float other_angle = p_vec_angle(co[v2], co[v0], co[v1]);
- float shape = fabsf((float)M_PI - angle - 2.0f * other_angle);
+ const float *co_curr, *co_prev = co[nverts-1];
+ for (int j = 0; j < nverts; j++) {
+ co_curr = co[j];
+ add_newell_cross_v3_v3v3(normal, co_prev, co_curr);
+ co_prev = co_curr;
+ }
+ if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
+ normal[2] = 1.0f;
+ }
- if (fabsf(angle - minangle) < 0.01f) {
- /* for nearly equal angles, try to get well shaped triangles */
- if (shape < minshape) {
- minangle = angle;
- minshape = shape;
- mini = i;
- }
- }
- else if (angle < minangle) {
- minangle = angle;
- minshape = shape;
- mini = i;
- }
- }
+ /* Project verts to 2d. */
+ float axis_mat[3][3];
+ axis_dominant_v3_to_m3_negate(axis_mat, normal);
+ for (int j = 0; j < nverts; j++) {
+ mul_v2_m3v3(projverts[j], axis_mat, co[j]);
+ }
- /* add triangle in corner */
- {
- int v0 = boundary[(mini + nverts - 1) % nverts];
- int v1 = boundary[mini];
- int v2 = boundary[(mini + 1) % nverts];
+ BLI_polyfill_calc_arena(projverts, nverts, 1, tris, arena);
- ParamKey tri_vkeys[3] = {vkeys[v0], vkeys[v1], vkeys[v2]};
- float *tri_co[3] = {co[v0], co[v1], co[v2]};
- float *tri_uv[3] = {uv[v0], uv[v1], uv[v2]};
- ParamBool tri_pin[3] = {pin[v0], pin[v1], pin[v2]};
- ParamBool tri_select[3] = {select[v0], select[v1], select[v2]};
+ /* Beautify helps avoid thin triangles that give numerical problems. */
+ BLI_polyfill_beautify(projverts, nverts, tris, arena, heap);
- param_face_add(handle, key, 3, tri_vkeys, tri_co, tri_uv, tri_pin, tri_select, NULL);
- }
+ /* Add triangles. */
+ for (int j = 0; j < nfilltri; j++) {
+ unsigned int *tri = tris[j];
+ unsigned int v0 = tri[0];
+ unsigned int v1 = tri[1];
+ unsigned int v2 = tri[2];
- /* remove corner */
- if (mini + 1 < nverts)
- memmove(boundary + mini, boundary + mini + 1, (nverts - mini - 1) * sizeof(int));
+ ParamKey tri_vkeys[3] = {vkeys[v0], vkeys[v1], vkeys[v2]};
+ float *tri_co[3] = {co[v0], co[v1], co[v2]};
+ float *tri_uv[3] = {uv[v0], uv[v1], uv[v2]};
+ ParamBool tri_pin[3] = {pin[v0], pin[v1], pin[v2]};
+ ParamBool tri_select[3] = {select[v0], select[v1], select[v2]};
- nverts--;
+ param_face_add(handle, key, 3, tri_vkeys, tri_co, tri_uv, tri_pin, tri_select);
}
+
+ BLI_memarena_clear(arena);
}
void param_face_add(ParamHandle *handle, ParamKey key, int nverts,
ParamKey *vkeys, float *co[4], float *uv[4],
- ParamBool *pin, ParamBool *select, float normal[3])
+ ParamBool *pin, ParamBool *select)
{
PHandle *phandle = (PHandle *)handle;
@@ -4247,7 +4242,7 @@ void param_face_add(ParamHandle *handle, ParamKey key, int nverts,
if (nverts > 4) {
/* ngon */
- p_add_ngon(handle, key, nverts, vkeys, co, uv, pin, select, normal);
+ p_add_ngon(handle, key, nverts, vkeys, co, uv, pin, select);
}
else if (nverts == 4) {
/* quad */
diff --git a/source/blender/editors/uvedit/uvedit_parametrizer.h b/source/blender/editors/uvedit/uvedit_parametrizer.h
index 2714bc33769..e42944f3da4 100644
--- a/source/blender/editors/uvedit/uvedit_parametrizer.h
+++ b/source/blender/editors/uvedit/uvedit_parametrizer.h
@@ -62,8 +62,7 @@ void param_face_add(ParamHandle *handle,
float *co[4],
float *uv[4],
ParamBool *pin,
- ParamBool *select,
- float face_normal[3]);
+ ParamBool *select);
void param_edge_set_seam(ParamHandle *handle,
ParamKey *vkeys);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index 538ca9afafa..b344bb42318 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -262,7 +262,7 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene,
select[i] = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
}
- param_face_add(handle, key, i, vkeys, co, uv, pin, select, efa->no);
+ param_face_add(handle, key, i, vkeys, co, uv, pin, select);
}
/* See: construct_param_handle_multi to handle multiple objects at once. */
@@ -571,7 +571,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, Object *ob, B
texface_from_original_index(origFace, origVertIndices[mloop[2].v], &uv[2], &pin[2], &select[2], scene, cd_loop_uv_offset);
texface_from_original_index(origFace, origVertIndices[mloop[3].v], &uv[3], &pin[3], &select[3], scene, cd_loop_uv_offset);
- param_face_add(handle, key, 4, vkeys, co, uv, pin, select, NULL);
+ param_face_add(handle, key, 4, vkeys, co, uv, pin, select);
}
/* these are calculated from original mesh too */