Commit: fb4fcd6e0137ef2785b8ceae203921ec359b1263
Author: Martin Felke
Date:   Thu Feb 22 13:02:34 2018 +0100
Branches: fracture_modifier
https://developer.blender.org/rBfb4fcd6e0137ef2785b8ceae203921ec359b1263

Merge remote-tracking branch 'refs/remotes/origin/blender-v2.79a-release' into 
fracture_modifier

Conflicts:
        source/blender/modifiers/intern/MOD_boolean.c

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



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

diff --cc intern/cycles/blender/blender_mesh.cpp
index 98bed494597,8938a12ce1d..b8c8ee4d8ed
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@@ -1123,10 -1075,8 +1123,10 @@@ Mesh *BlenderSync::sync_mesh(BL::Object
                                b_ob.cache_release();
                        }
  
 +                      sync_mesh_precalculated_motion(b_mesh, b_scene, scene, 
mesh);
 +
                        /* free derived mesh */
-                       b_data.meshes.remove(b_mesh, false);
+                       b_data.meshes.remove(b_mesh, false, true, false);
                }
        }
        mesh->geometry_flags = requested_geometry_flags;
diff --cc source/blender/alembic/intern/abc_customdata.cc
index b9d68416bb9,8b526616053..826ec4515ff
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@@ -239,10 -239,11 +239,12 @@@ static void read_uvs(const CDStreamConf
  
        for (int i = 0; i < config.totpoly; ++i) {
                MPoly &poly = mpolys[i];
+               unsigned int rev_loop_offset = poly.loopstart + poly.totloop - 
1;
  
                for (int f = 0; f < poly.totloop; ++f) {
 +                      rev_loop_index = poly.loopstart + poly.totloop - f - 1;
                        loop_index = poly.loopstart + f;
+                       rev_loop_index = rev_loop_offset - f;
                        uv_index = (*indices)[loop_index];
                        const Imath::V2f &uv = (*uvs)[uv_index];
  
diff --cc source/blender/blenkernel/intern/fracture_util.c
index f0d6e58ecc7,00000000000..cc5b761bc59
mode 100644,000000..100644
--- a/source/blender/blenkernel/intern/fracture_util.c
+++ b/source/blender/blenkernel/intern/fracture_util.c
@@@ -1,949 -1,0 +1,949 @@@
 +/*
 + * ***** 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) Blender Foundation
 + * All rights reserved.
 + *
 + * The Original Code is: all of this file.
 + *
 + * Contributor(s): Martin Felke
 + *
 + * ***** END GPL LICENSE BLOCK *****
 + */
 +
 +/** \file blender/blenkernel/intern/fracture_util.c
 + *  \ingroup blenkernel
 + *  \brief CSG operations
 + */
 +
 +#include "BKE_cdderivedmesh.h"
 +#include "BKE_deform.h"
 +#include "BKE_editmesh.h"
 +#include "BKE_fracture.h"
 +#include "BKE_fracture_util.h"
 +#include "BKE_material.h"
 +#include "BKE_modifier.h"
 +#include "BKE_object.h"
 +
 +#include "BLI_alloca.h"
 +#include "BLI_boxpack2d.h"
 +#include "BLI_convexhull2d.h"
 +#include "BLI_ghash.h"
 +#include "BLI_math.h"
 +#include "BLI_rand.h"
 +#include "BLI_sys_types.h"
 +#include "BLI_kdtree.h"
 +
 +#include "DNA_fracture_types.h"
 +#include "DNA_meshdata_types.h"
 +#include "DNA_material_types.h"
 +#include "DNA_modifier_types.h"
 +
 +#include "MEM_guardedalloc.h"
 +
 +#include "bmesh.h"
 +#include "bmesh_tools.h"
 +#include "../../modifiers/intern/MOD_boolean_util.h"
 +
 +/*prototypes*/
 +void uv_bbox(float uv[][2], int num_uv, float minv[2], float maxv[2]);
 +void uv_translate(float uv[][2], int num_uv, float trans[2]);
 +void uv_scale(float uv[][2], int num_uv, float scale);
 +void uv_transform(float uv[][2], int num_uv, float mat[2][2]);
 +void unwrap_shard_dm(DerivedMesh *dm, char uv_layer[], bool do_boxpack);
 +
 +/* UV Helpers */
 +void uv_bbox(float uv[][2], int num_uv, float minv[2], float maxv[2])
 +{
 +      int v;
 +      INIT_MINMAX2(minv, maxv);
 +
 +      for (v = 0; v < num_uv; v++) {
 +              minmax_v2v2_v2(minv, maxv, uv[v]);
 +      }
 +}
 +
 +void uv_translate(float uv[][2], int num_uv, float trans[2])
 +{
 +      int v;
 +      for (v = 0; v < num_uv; v++) {
 +              uv[v][0] += trans[0];
 +              uv[v][1] += trans[1];
 +      }
 +}
 +
 +void uv_scale(float uv[][2], int num_uv, float scale)
 +{
 +      int v;
 +      for (v = 0; v < num_uv; v++) {
 +              uv[v][0] *= scale;
 +              uv[v][1] *= scale;
 +      }
 +}
 +
 +void uv_transform(float uv[][2], int num_uv, float mat[2][2])
 +{
 +      int v;
 +      for (v = 0; v < num_uv; v++) {
 +              mul_m2v2(mat, uv[v]);
 +      }
 +}
 +
 +static void do_clean_uv(DerivedMesh *dm, char uv_layer[64])
 +{
 +      MLoopUV* mluv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, 
uv_layer);
 +      int i, totpoly = dm->getNumPolys(dm);
 +      MPoly *mp, *mpoly = dm->getPolyArray(dm);
 +
 +      if (mluv)
 +      {
 +              for (i = 0, mp = mpoly; i < totpoly; i++, mp++)
 +              {
 +                      if (mp->mat_nr != 1)
 +                      {       //clean up (set uv coords to zero) all except 
inner faces (material based)
 +                              int j;
 +                              for (j = mp->loopstart; j < mp->loopstart + 
mp->totloop; j++)
 +                              {
 +                                      mluv[j].uv[0] = 0.0f;
 +                                      mluv[j].uv[1] = 0.0f;
 +                              }
 +                      }
 +              }
 +      }
 +}
 +
 +static void do_unwrap(MPoly *mp, MVert *mvert, MLoop* mloop, int i, MLoopUV 
**mluv, BoxPack **boxpack)
 +{
 +      MLoop *ml;
 +      int j = 0;
 +      float (*verts)[3] = MEM_mallocN(sizeof(float[3]) * mp->totloop, 
"unwrap_shard_dm verts");
 +      float nor[3];
 +      float mat[3][3];
 +      float (*uv)[2] = MEM_mallocN(sizeof(float[2]) * mp->totloop, 
"unwrap_shard_dm_uv");
 +      BoxPack *box;
 +      float uvbbox[2][2];
 +      float angle;
 +
 +      /* uv unwrap cells, so inner faces get a uv map */
 +      for (j = 0; j < mp->totloop; j++) {
 +              ml = mloop + mp->loopstart + j;
 +              copy_v3_v3(verts[j], (mvert + ml->v)->co);
 +      }
 +
 +      normal_poly_v3(nor, (const float (*)[3])verts, mp->totloop);
 +      normalize_v3(nor);
 +      axis_dominant_v3_to_m3(mat, nor);
 +
 +      for (j = 0; j < mp->totloop; j++) {
 +              mul_v2_m3v3(uv[j], mat, verts[j]);
 +      }
 +
 +      /* rotate uvs for better packing */
 +      angle = BLI_convexhull_aabb_fit_points_2d((const float (*)[2])uv, 
mp->totloop);
 +
 +      if (angle != 0.0f) {
 +              float matt[2][2];
 +              angle_to_mat2(matt, angle);
 +              uv_transform((float (*)[2])uv, mp->totloop, matt);
 +      }
 +
 +      /* prepare box packing... one poly is a box */
 +      box = (*boxpack) + i;
 +      uv_bbox((float (*)[2])uv, mp->totloop, uvbbox[0], uvbbox[1]);
 +
 +      uvbbox[0][0] = -uvbbox[0][0];
 +      uvbbox[0][1] = -uvbbox[0][1];
 +
 +      uv_translate((float (*)[2])uv, mp->totloop, uvbbox[0]);
 +
 +      box->w = uvbbox[1][0] + uvbbox[0][0];
 +      box->h = uvbbox[1][1] + uvbbox[0][1];
 +      box->index = i;
 +
 +      /* copy coords back */
 +      for (j = 0; j < mp->totloop; j++) {
 +              copy_v2_v2((*mluv)[j + mp->loopstart].uv, uv[j]);
 +              (*mluv)[j + mp->loopstart].flag = 0;
 +      }
 +
 +      MEM_freeN(uv);
 +      MEM_freeN(verts);
 +}
 +
 +void unwrap_shard_dm(DerivedMesh *dm, char uv_layer[64], bool do_boxpack)
 +{
 +      MVert *mvert;
 +      MLoop *mloop;
 +      MPoly *mpoly, *mp;
 +      int totpoly, i = 0;
 +      MLoopUV *mluv = MEM_callocN(sizeof(MLoopUV) * dm->numLoopData, "mluv");
 +      BoxPack *boxpack = MEM_mallocN(sizeof(BoxPack) * dm->numPolyData, 
"boxpack");
 +      float scale, tot_width, tot_height;
 +
 +      /* set inner material on child shard */
 +      mvert = dm->getVertArray(dm);
 +      mpoly = dm->getPolyArray(dm);
 +      mloop = dm->getLoopArray(dm);
 +      totpoly = dm->getNumPolys(dm);
 +      for (i = 0, mp = mpoly; i < totpoly; i++, mp++) {
 +              do_unwrap(mp, mvert, mloop, i, &mluv, &boxpack);
 +      }
 +
 +      if (do_boxpack)
 +      {
 +              /* do box packing and match uvs according to it */
 +              BLI_box_pack_2d(boxpack, totpoly, &tot_width, &tot_height);
 +
 +              if (tot_height > tot_width)
 +                      scale = 1.0f / tot_height;
 +              else
 +                      scale = 1.0f / tot_width;
 +
 +              for (i = 0, mp = mpoly; i < totpoly; i++, mp++) {
 +                      float trans[2];
 +                      BoxPack *box;
 +                      int j;
 +
 +                      box = boxpack + i;
 +                      trans[0] = box->x;
 +                      trans[1] = box->y;
 +
 +                      for (j = 0; j < mp->totloop; j++)
 +                      {
 +                              uv_translate((float (*)[2])mluv[j + 
mp->loopstart].uv, 1, trans);
 +                              uv_scale((float (*)[2])mluv[j + 
mp->loopstart].uv, 1, scale);
 +                      }
 +              }
 +      }
 +
 +      MEM_freeN(boxpack);
 +
 +      CustomData_add_layer_named(&dm->loopData, CD_MLOOPUV, CD_ASSIGN, mluv, 
dm->numLoopData, uv_layer);
 +      CustomData_add_layer_named(&dm->polyData, CD_MTEXPOLY, CD_CALLOC, NULL, 
totpoly, uv_layer);
 +}
 +
 +static bool check_non_manifold(DerivedMesh* dm)
 +{
 +      BMesh *bm;
 +      BMVert* v;
 +      BMIter iter;
 +      BMEdge *e;
 +
 +      /*check for watertightness*/
 +      bm = BM_mesh_create(&bm_mesh_allocsize_default, &((struct 
BMeshCreateParams){.use_toolflags = true,}));
 +      DM_to_bmesh_ex(dm, bm, true);
 +
 +      if (bm->totface < 4) {
 +              BM_mesh_free(bm);
 +              printf("Empty mesh...\n");
 +              return true;
 +      }
 +
 +      BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
 +              if (!BM_vert_is_manifold(v)) {
 +                      BM_mesh_free(bm);
 +                      printf("Mesh not watertight...\n");
 +                      return true;
 +              }
 +      }
 +
 +      BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
 +              if (BM_edge_is_wire(e) ||
 +                      BM_edge_is_boundary(e) ||
 +                      (BM_edge_is_manifold(e) && !BM_edge_is_contiguous(e)) ||
 +                      BM_edge_face_count(e) > 2)
 +              {
 +                      /* check we never select perfect edge (in test above) */
 +                      BLI_assert(!(BM_edge_is_manifold(e) && 
BM_edge_is_contiguous(e)));
 +                      BM_mesh_free(bm);
 +                      printf("Mesh not watertight...\n");
 +                      return true;
 +              }
 +      }
 +
 +      BM_mesh_free(bm);
 +      return false;
 +}
 +
 +static int DM_mesh_minmax(DerivedMesh *dm, float r_min[3], float r_max[3])
 +{
 +      MVert *v;
 +      int i = 0;
 +      for (i = 0; i < dm->numVertData; i++) {
 +              v = CDDM_get_vert(dm, i);
 +              minmax_v3v3_v3(r_min, r_max, v->co);
 +      }
 +
 +      return (dm->numVertData != 0);
 +}
 +
 +static bool compare_dm_size(DerivedMesh *dmOld, DerivedMesh *dmNew)
 +{
 +      float min[3], max[3];
 +      float size[3];
 +      float v1, v2;
 +
 +      INIT_MINMAX(min, max);
 +      DM_mesh_minmax(dmOld, min, max);
 +      sub_v3_v3v3(size, max, min);
 +
 +      v1 = size[0] * size[1] * size[2];
 +
 +      INIT_MINMAX(min, max);
 +      DM_mesh_minmax(dmNew, min, max);
 +      sub_v3_v3v3(size, max, min);
 +
 +      v2 = size[0] * size[1] * size[2];
 +
 +      if (v2 > (v1 + 0.000001))
 +      {
 +              printf("Size mismatch !\n");
 +      }
 +
 +      return v2 <= (v1 + 0.000001);
 +}
 +
 +static bool do_other_output(DerivedMesh** other_dm, Shard** other, 
DerivedMesh** output_dm, DerivedMesh** left_dm, float m

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to