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/blenkernel/intern/mesh.c')
-rw-r--r--source/blender/blenkernel/intern/mesh.c203
1 files changed, 95 insertions, 108 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 71fd65d1f23..ba139c654d3 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -27,6 +27,7 @@
#include "DNA_key_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_defaults.h"
#include "BLI_utildefines.h"
#include "BLI_bitmap.h"
@@ -495,7 +496,6 @@ void BKE_mesh_clear_geometry(Mesh *mesh)
CustomData_free(&mesh->ldata, mesh->totloop);
CustomData_free(&mesh->pdata, mesh->totpoly);
- MEM_SAFE_FREE(mesh->bb);
MEM_SAFE_FREE(mesh->mselect);
MEM_SAFE_FREE(mesh->edit_mesh);
@@ -533,10 +533,7 @@ void BKE_mesh_init(Mesh *me)
{
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(me, id));
- me->size[0] = me->size[1] = me->size[2] = 1.0;
- me->smoothresh = DEG2RADF(30);
- me->texflag = ME_AUTOSPACE;
- me->remesh_voxel_size = 0.1f;
+ MEMCPY_STRUCT_AFTER(me, DNA_struct_default_get(Mesh), id);
CustomData_reset(&me->vdata);
CustomData_reset(&me->edata);
@@ -607,7 +604,6 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
me_dst->edit_mesh = NULL;
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
- me_dst->bb = MEM_dupallocN(me_dst->bb);
/* TODO Do we want to add flag to prevent this? */
if (me_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
@@ -661,20 +657,44 @@ Mesh *BKE_mesh_new_nomain(
return mesh;
}
-static Mesh *mesh_new_nomain_from_template_ex(const Mesh *me_src,
- int verts_len,
- int edges_len,
- int tessface_len,
- int loops_len,
- int polys_len,
- CustomData_MeshMasks mask)
+/* Copy user editable settings that we want to preserve through the modifier stack
+ * or operations where a mesh with new topology is created based on another mesh. */
+void BKE_mesh_copy_settings(Mesh *me_dst, const Mesh *me_src)
+{
+ /* Copy general settings. */
+ me_dst->editflag = me_src->editflag;
+ me_dst->flag = me_src->flag;
+ me_dst->smoothresh = me_src->smoothresh;
+ me_dst->remesh_voxel_size = me_src->remesh_voxel_size;
+ me_dst->remesh_voxel_adaptivity = me_src->remesh_voxel_adaptivity;
+ me_dst->remesh_mode = me_src->remesh_mode;
+
+ /* Copy texture space. */
+ me_dst->texflag = me_src->texflag;
+ copy_v3_v3(me_dst->loc, me_src->loc);
+ copy_v3_v3(me_dst->size, me_src->size);
+
+ /* Copy materials. */
+ if (me_dst->mat != NULL) {
+ MEM_freeN(me_dst->mat);
+ }
+ me_dst->mat = MEM_dupallocN(me_src->mat);
+ me_dst->totcol = me_src->totcol;
+}
+
+Mesh *BKE_mesh_new_nomain_from_template_ex(const Mesh *me_src,
+ int verts_len,
+ int edges_len,
+ int tessface_len,
+ int loops_len,
+ int polys_len,
+ CustomData_MeshMasks mask)
{
/* Only do tessface if we are creating tessfaces or copying from mesh with only tessfaces. */
const bool do_tessface = (tessface_len || ((me_src->totface != 0) && (me_src->totpoly == 0)));
Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL);
- me_dst->mat = MEM_dupallocN(me_src->mat);
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
me_dst->totvert = verts_len;
@@ -684,8 +704,7 @@ static Mesh *mesh_new_nomain_from_template_ex(const Mesh *me_src,
me_dst->totpoly = polys_len;
me_dst->cd_flag = me_src->cd_flag;
- me_dst->editflag = me_src->editflag;
- me_dst->texflag = me_src->texflag;
+ BKE_mesh_copy_settings(me_dst, me_src);
CustomData_copy(&me_src->vdata, &me_dst->vdata, mask.vmask, CD_CALLOC, verts_len);
CustomData_copy(&me_src->edata, &me_dst->edata, mask.emask, CD_CALLOC, edges_len);
@@ -713,7 +732,7 @@ Mesh *BKE_mesh_new_nomain_from_template(const Mesh *me_src,
int loops_len,
int polys_len)
{
- return mesh_new_nomain_from_template_ex(
+ return BKE_mesh_new_nomain_from_template_ex(
me_src, verts_len, edges_len, tessface_len, loops_len, polys_len, CD_MASK_EVERYTHING);
}
@@ -774,18 +793,24 @@ BMesh *BKE_mesh_to_bmesh(Mesh *me,
});
}
-Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm, const struct BMeshToMeshParams *params)
+Mesh *BKE_mesh_from_bmesh_nomain(BMesh *bm,
+ const struct BMeshToMeshParams *params,
+ const Mesh *me_settings)
{
BLI_assert(params->calc_object_remap == false);
Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL);
BM_mesh_bm_to_me(NULL, bm, mesh, params);
+ BKE_mesh_copy_settings(mesh, me_settings);
return mesh;
}
-Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks *cd_mask_extra)
+Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm,
+ const CustomData_MeshMasks *cd_mask_extra,
+ const Mesh *me_settings)
{
Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL);
BM_mesh_bm_to_me_for_eval(bm, mesh, cd_mask_extra);
+ BKE_mesh_copy_settings(mesh, me_settings);
return mesh;
}
@@ -794,9 +819,10 @@ Mesh *BKE_mesh_from_bmesh_for_eval_nomain(BMesh *bm, const CustomData_MeshMasks
*/
Mesh *BKE_mesh_from_editmesh_with_coords_thin_wrap(BMEditMesh *em,
const CustomData_MeshMasks *data_mask,
- float (*vertexCos)[3])
+ float (*vertexCos)[3],
+ const Mesh *me_settings)
{
- Mesh *me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, data_mask);
+ Mesh *me = BKE_mesh_from_bmesh_for_eval_nomain(em->bm, data_mask, me_settings);
/* Use editmesh directly where possible. */
me->runtime.is_original = true;
if (vertexCos) {
@@ -813,50 +839,49 @@ void BKE_mesh_make_local(Main *bmain, Mesh *me, const bool lib_local)
BKE_id_make_local_generic(bmain, &me->id, true, lib_local);
}
-void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3])
+BoundBox *BKE_mesh_boundbox_get(Object *ob)
{
- BoundBox *bb;
- float min[3], max[3];
- float mloc[3], msize[3];
-
- if (me->bb == NULL) {
- me->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
- }
- bb = me->bb;
+ /* This is Object-level data access,
+ * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
+ if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
+ Mesh *me = ob->data;
+ float min[3], max[3];
- if (!r_loc) {
- r_loc = mloc;
- }
- if (!r_size) {
- r_size = msize;
- }
+ INIT_MINMAX(min, max);
+ if (!BKE_mesh_minmax(me, min, max)) {
+ min[0] = min[1] = min[2] = -1.0f;
+ max[0] = max[1] = max[2] = 1.0f;
+ }
- INIT_MINMAX(min, max);
- if (!BKE_mesh_minmax(me, min, max)) {
- min[0] = min[1] = min[2] = -1.0f;
- max[0] = max[1] = max[2] = 1.0f;
+ if (ob->runtime.bb == NULL) {
+ ob->runtime.bb = MEM_mallocN(sizeof(*ob->runtime.bb), __func__);
+ }
+ BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
+ ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
}
- mid_v3_v3v3(r_loc, min, max);
-
- r_size[0] = (max[0] - min[0]) / 2.0f;
- r_size[1] = (max[1] - min[1]) / 2.0f;
- r_size[2] = (max[2] - min[2]) / 2.0f;
-
- BKE_boundbox_init_from_minmax(bb, min, max);
-
- bb->flag &= ~BOUNDBOX_DIRTY;
+ return ob->runtime.bb;
}
void BKE_mesh_texspace_calc(Mesh *me)
{
- float loc[3], size[3];
- int a;
+ if (me->texflag & ME_AUTOSPACE) {
+ float min[3], max[3];
- BKE_mesh_boundbox_calc(me, loc, size);
+ INIT_MINMAX(min, max);
+ if (!BKE_mesh_minmax(me, min, max)) {
+ min[0] = min[1] = min[2] = -1.0f;
+ max[0] = max[1] = max[2] = 1.0f;
+ }
- if (me->texflag & ME_AUTOSPACE) {
- for (a = 0; a < 3; a++) {
+ float loc[3], size[3];
+ mid_v3_v3v3(loc, min, max);
+
+ size[0] = (max[0] - min[0]) / 2.0f;
+ size[1] = (max[1] - min[1]) / 2.0f;
+ size[2] = (max[2] - min[2]) / 2.0f;
+
+ for (int a = 0; a < 3; a++) {
if (size[a] == 0.0f) {
size[a] = 1.0f;
}
@@ -870,59 +895,33 @@ void BKE_mesh_texspace_calc(Mesh *me)
copy_v3_v3(me->loc, loc);
copy_v3_v3(me->size, size);
- zero_v3(me->rot);
+
+ me->texflag |= ME_AUTOSPACE_EVALUATED;
}
}
-BoundBox *BKE_mesh_boundbox_get(Object *ob)
+void BKE_mesh_texspace_ensure(Mesh *me)
{
- /* This is Object-level data access,
- * DO NOT touch to Mesh's bb, would be totally thread-unsafe. */
- if (ob->runtime.bb == NULL || ob->runtime.bb->flag & BOUNDBOX_DIRTY) {
- Mesh *me = ob->data;
- float min[3], max[3];
-
- INIT_MINMAX(min, max);
- if (!BKE_mesh_minmax(me, min, max)) {
- min[0] = min[1] = min[2] = -1.0f;
- max[0] = max[1] = max[2] = 1.0f;
- }
-
- if (ob->runtime.bb == NULL) {
- ob->runtime.bb = MEM_mallocN(sizeof(*ob->runtime.bb), __func__);
- }
- BKE_boundbox_init_from_minmax(ob->runtime.bb, min, max);
- ob->runtime.bb->flag &= ~BOUNDBOX_DIRTY;
+ if ((me->texflag & ME_AUTOSPACE) && !(me->texflag & ME_AUTOSPACE_EVALUATED)) {
+ BKE_mesh_texspace_calc(me);
}
-
- return ob->runtime.bb;
}
-BoundBox *BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
+void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_size[3])
{
- if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
- BKE_mesh_texspace_calc(me);
- }
+ BKE_mesh_texspace_ensure(me);
if (r_loc) {
copy_v3_v3(r_loc, me->loc);
}
- if (r_rot) {
- copy_v3_v3(r_rot, me->rot);
- }
if (r_size) {
copy_v3_v3(r_size, me->size);
}
-
- return me->bb;
}
-void BKE_mesh_texspace_get_reference(
- Mesh *me, short **r_texflag, float **r_loc, float **r_rot, float **r_size)
+void BKE_mesh_texspace_get_reference(Mesh *me, short **r_texflag, float **r_loc, float **r_size)
{
- if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
- BKE_mesh_texspace_calc(me);
- }
+ BKE_mesh_texspace_ensure(me);
if (r_texflag != NULL) {
*r_texflag = &me->texflag;
@@ -930,9 +929,6 @@ void BKE_mesh_texspace_get_reference(
if (r_loc != NULL) {
*r_loc = me->loc;
}
- if (r_rot != NULL) {
- *r_rot = me->rot;
- }
if (r_size != NULL) {
*r_size = me->size;
}
@@ -940,14 +936,13 @@ void BKE_mesh_texspace_get_reference(
void BKE_mesh_texspace_copy_from_object(Mesh *me, Object *ob)
{
- float *texloc, *texrot, *texsize;
+ float *texloc, *texsize;
short *texflag;
- if (BKE_object_obdata_texspace_get(ob, &texflag, &texloc, &texsize, &texrot)) {
+ if (BKE_object_obdata_texspace_get(ob, &texflag, &texloc, &texsize)) {
me->texflag = *texflag;
copy_v3_v3(me->loc, texloc);
copy_v3_v3(me->size, texsize);
- copy_v3_v3(me->rot, texrot);
}
}
@@ -976,7 +971,7 @@ void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int
float loc[3], size[3];
int a;
- BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, NULL, size);
+ BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, size);
if (invert) {
for (a = 0; a < totvert; a++) {
@@ -1082,12 +1077,12 @@ void BKE_mesh_assign_object(Main *bmain, Object *ob, Mesh *me)
{
Mesh *old = NULL;
- multires_force_update(ob);
-
if (ob == NULL) {
return;
}
+ multires_force_sculpt_rebuild(ob);
+
if (ob->type == OB_MESH) {
old = ob->data;
if (old) {
@@ -1951,9 +1946,6 @@ void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
{
DEG_debug_print_eval(depsgraph, __func__, mesh->id.name, mesh);
BKE_mesh_texspace_calc(mesh);
- /* Clear autospace flag in evaluated mesh, so that texspace does not get recomputed when bbox is
- * (e.g. after modifiers, etc.) */
- mesh->texflag &= ~ME_AUTOSPACE;
/* We are here because something did change in the mesh. This means we can not trust the existing
* evaluated mesh, and we don't know what parts of the mesh did change. So we simply delete the
* evaluated mesh and let objects to re-create it with updated settings. */
@@ -1964,15 +1956,10 @@ void BKE_mesh_eval_geometry(Depsgraph *depsgraph, Mesh *mesh)
}
if (DEG_is_active(depsgraph)) {
Mesh *mesh_orig = (Mesh *)DEG_get_original_id(&mesh->id);
- BoundBox *bb = mesh->bb;
- if (bb != NULL) {
- if (mesh_orig->bb == NULL) {
- mesh_orig->bb = MEM_mallocN(sizeof(*mesh_orig->bb), __func__);
- }
- *mesh_orig->bb = *bb;
+ if (mesh->texflag & ME_AUTOSPACE_EVALUATED) {
+ mesh_orig->texflag |= ME_AUTOSPACE_EVALUATED;
copy_v3_v3(mesh_orig->loc, mesh->loc);
copy_v3_v3(mesh_orig->size, mesh->size);
- copy_v3_v3(mesh_orig->rot, mesh->rot);
}
}
}