Blender  V3.3
multires.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2007 by Nicholas Bishop. All rights reserved. */
3 
8 #include "MEM_guardedalloc.h"
9 
10 /* for reading old multires */
11 #define DNA_DEPRECATED_ALLOW
12 
13 #include "DNA_mesh_types.h"
14 #include "DNA_meshdata_types.h"
15 #include "DNA_object_types.h"
16 #include "DNA_scene_types.h"
17 
18 #include "BLI_bitmap.h"
19 #include "BLI_blenlib.h"
20 #include "BLI_math.h"
21 #include "BLI_task.h"
22 #include "BLI_utildefines.h"
23 
24 #include "BKE_ccg.h"
25 #include "BKE_cdderivedmesh.h"
26 #include "BKE_editmesh.h"
27 #include "BKE_mesh.h"
28 #include "BKE_mesh_mapping.h"
29 #include "BKE_mesh_runtime.h"
30 #include "BKE_modifier.h"
31 #include "BKE_multires.h"
32 #include "BKE_paint.h"
33 #include "BKE_pbvh.h"
34 #include "BKE_scene.h"
35 #include "BKE_subdiv_ccg.h"
36 #include "BKE_subsurf.h"
37 
38 #include "BKE_object.h"
39 
40 #include "CCGSubSurf.h"
41 
42 #include "DEG_depsgraph_query.h"
43 
44 #include "multires_reshape.h"
45 
46 #include <math.h>
47 #include <string.h>
48 
49 /* MULTIRES MODIFIER */
50 static const int multires_grid_tot[] = {
51  0, 4, 9, 25, 81, 289, 1089, 4225, 16641, 66049, 263169, 1050625, 4198401, 16785409};
52 static const int multires_side_tot[] = {
53  0, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513, 1025, 2049, 4097};
54 
55 /* See multiresModifier_disp_run for description of each operation */
56 typedef enum {
60 } DispOp;
61 
62 static void multiresModifier_disp_run(
63  DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, CCGElem **oldGridData, int totlvl);
64 
68 {
69  if (me->edit_mesh) {
70  BMEditMesh *em = me->edit_mesh;
71  /* CustomData_external_remove is used here only to mark layer
72  * as non-external for further free-ing, so zero element count
73  * looks safer than em->totface */
75 
76  if (CustomData_has_layer(&em->bm->ldata, CD_MDISPS)) {
77  BM_data_layer_free(em->bm, &em->bm->ldata, CD_MDISPS);
78  }
79 
82  }
83  }
84  else {
87 
89  }
90 }
91 
94  int lo_level,
95  int hi_level,
96 
97  /* assumed to be at hi_level (or null) */
98  const BLI_bitmap *prev_hidden)
99 {
100  BLI_bitmap *subd;
101  int hi_gridsize = BKE_ccg_gridsize(hi_level);
102  int lo_gridsize = BKE_ccg_gridsize(lo_level);
103  int yh, xh, xl, yl, xo, yo, hi_ndx;
104  int offset, factor;
105 
106  BLI_assert(lo_level <= hi_level);
107 
108  /* fast case */
109  if (lo_level == hi_level) {
110  return MEM_dupallocN(lo_hidden);
111  }
112 
113  subd = BLI_BITMAP_NEW(square_i(hi_gridsize), "MDisps.hidden upsample");
114 
115  factor = BKE_ccg_factor(lo_level, hi_level);
116  offset = 1 << (hi_level - lo_level - 1);
117 
118  /* low-res blocks */
119  for (yl = 0; yl < lo_gridsize; yl++) {
120  for (xl = 0; xl < lo_gridsize; xl++) {
121  int lo_val = BLI_BITMAP_TEST(lo_hidden, yl * lo_gridsize + xl);
122 
123  /* high-res blocks */
124  for (yo = -offset; yo <= offset; yo++) {
125  yh = yl * factor + yo;
126  if (yh < 0 || yh >= hi_gridsize) {
127  continue;
128  }
129 
130  for (xo = -offset; xo <= offset; xo++) {
131  xh = xl * factor + xo;
132  if (xh < 0 || xh >= hi_gridsize) {
133  continue;
134  }
135 
136  hi_ndx = yh * hi_gridsize + xh;
137 
138  if (prev_hidden) {
139  /* If prev_hidden is available, copy it to
140  * subd, except when the equivalent element in
141  * lo_hidden is different */
142  if (lo_val != prev_hidden[hi_ndx]) {
143  BLI_BITMAP_SET(subd, hi_ndx, lo_val);
144  }
145  else {
146  BLI_BITMAP_SET(subd, hi_ndx, prev_hidden[hi_ndx]);
147  }
148  }
149  else {
150  BLI_BITMAP_SET(subd, hi_ndx, lo_val);
151  }
152  }
153  }
154  }
155  }
156 
157  return subd;
158 }
159 
161  int old_level,
162  int new_level)
163 {
164  BLI_bitmap *new_hidden;
165  int new_gridsize = BKE_ccg_gridsize(new_level);
166  int old_gridsize = BKE_ccg_gridsize(old_level);
167  int x, y, factor, old_value;
168 
169  BLI_assert(new_level <= old_level);
170  factor = BKE_ccg_factor(new_level, old_level);
171  new_hidden = BLI_BITMAP_NEW(square_i(new_gridsize), "downsample hidden");
172 
173  for (y = 0; y < new_gridsize; y++) {
174  for (x = 0; x < new_gridsize; x++) {
175  old_value = BLI_BITMAP_TEST(old_hidden, factor * y * old_gridsize + x * factor);
176 
177  BLI_BITMAP_SET(new_hidden, y * new_gridsize + x, old_value);
178  }
179  }
180 
181  return new_hidden;
182 }
183 
184 static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm, Mesh *me, int level)
185 {
186  const MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
187  BLI_bitmap **grid_hidden = ccgdm->gridHidden;
188  int *gridOffset;
189  int i, j;
190 
191  gridOffset = ccgdm->dm.getGridOffset(&ccgdm->dm);
192 
193  for (i = 0; i < me->totpoly; i++) {
194  for (j = 0; j < me->mpoly[i].totloop; j++) {
195  int g = gridOffset[i] + j;
196  const MDisps *md = &mdisps[g];
197  BLI_bitmap *gh = md->hidden;
198 
199  if (gh) {
200  grid_hidden[g] = multires_mdisps_downsample_hidden(gh, md->level, level);
201  }
202  }
203  }
204 }
205 
206 /* subdivide mdisps.hidden if needed (assumes that md.level reflects
207  * the current level of md.hidden) */
208 static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level)
209 {
210  BLI_bitmap *subd;
211 
212  BLI_assert(md->hidden);
213 
214  /* nothing to do if already subdivided enough */
215  if (md->level >= new_level) {
216  return;
217  }
218 
219  subd = multires_mdisps_upsample_hidden(md->hidden, md->level, new_level, NULL);
220 
221  /* swap in the subdivided data */
222  MEM_freeN(md->hidden);
223  md->hidden = subd;
224 }
225 
227  Object *object,
229 {
230  Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
231  Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
232  Mesh *deformed_mesh = mesh_get_eval_deform(
233  depsgraph, scene_eval, object_eval, &CD_MASK_BAREMESH);
234  ModifierEvalContext modifier_ctx = {
235  .depsgraph = depsgraph,
236  .object = object_eval,
238  };
239 
241  Mesh *result = mti->modifyMesh(&mmd->modifier, &modifier_ctx, deformed_mesh);
242 
243  if (result == deformed_mesh) {
244  result = BKE_mesh_copy_for_eval(deformed_mesh, true);
245  }
246  return result;
247 }
248 
250  struct Object *object,
251  struct MultiresModifierData *mmd,
252  int *r_num_deformed_verts))[3]
253 {
254  Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
255  Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
256 
257  Object object_for_eval = *object_eval;
258  object_for_eval.data = object->data;
259  object_for_eval.sculpt = NULL;
260 
261  const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
262  ModifierEvalContext mesh_eval_context = {depsgraph, &object_for_eval, 0};
263  if (use_render) {
264  mesh_eval_context.flag |= MOD_APPLY_RENDER;
265  }
266  const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
267 
268  VirtualModifierData virtual_modifier_data;
269  ModifierData *first_md = BKE_modifiers_get_virtual_modifierlist(&object_for_eval,
270  &virtual_modifier_data);
271 
272  Mesh *base_mesh = object->data;
273 
274  int num_deformed_verts;
275  float(*deformed_verts)[3] = BKE_mesh_vert_coords_alloc(base_mesh, &num_deformed_verts);
276 
277  for (ModifierData *md = first_md; md != NULL; md = md->next) {
278  const ModifierTypeInfo *mti = BKE_modifier_get_info(md->type);
279 
280  if (md == &mmd->modifier) {
281  break;
282  }
283 
284  if (!BKE_modifier_is_enabled(scene_eval, md, required_mode)) {
285  continue;
286  }
287 
288  if (mti->type != eModifierTypeType_OnlyDeform) {
289  break;
290  }
291 
293  md, &mesh_eval_context, base_mesh, deformed_verts, num_deformed_verts);
294  }
295 
296  if (r_num_deformed_verts != NULL) {
297  *r_num_deformed_verts = num_deformed_verts;
298  }
299  return deformed_verts;
300 }
301 
303 {
304  ModifierData *md;
305 
306  for (md = lastmd; md; md = md->prev) {
307  if (md->type == eModifierType_Multires) {
309  return (MultiresModifierData *)md;
310  }
311  }
312  }
313 
314  return NULL;
315 }
316 
318 {
319  ModifierData *md;
320  MultiresModifierData *mmd = NULL, *firstmmd = NULL;
321 
322  /* find first active multires modifier */
323  for (md = ob->modifiers.first; md; md = md->next) {
324  if (md->type == eModifierType_Multires) {
325  if (!firstmmd) {
326  firstmmd = (MultiresModifierData *)md;
327  }
328 
330  mmd = (MultiresModifierData *)md;
331  break;
332  }
333  }
334  }
335 
336  if (!mmd && use_first) {
337  /* active multires have not been found
338  * try to use first one */
339  return firstmmd;
340  }
341 
342  return mmd;
343 }
344 
346  const Object *ob,
347  const MultiresModifierData *mmd,
348  bool render,
349  bool ignore_simplify)
350 {
351  if (render) {
352  return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->renderlvl, true) :
353  mmd->renderlvl;
354  }
355  if (ob->mode == OB_MODE_SCULPT) {
356  return mmd->sculptlvl;
357  }
358  if (ignore_simplify) {
359  return mmd->lvl;
360  }
361 
362  return (scene != NULL) ? get_render_subsurf_level(&scene->r, mmd->lvl, false) : mmd->lvl;
363 }
364 
366 {
367  mmd->totlvl = lvl;
368 
369  if (ob->mode != OB_MODE_SCULPT) {
370  mmd->lvl = CLAMPIS(MAX2(mmd->lvl, lvl), 0, mmd->totlvl);
371  }
372 
373  mmd->sculptlvl = CLAMPIS(MAX2(mmd->sculptlvl, lvl), 0, mmd->totlvl);
374  mmd->renderlvl = CLAMPIS(MAX2(mmd->renderlvl, lvl), 0, mmd->totlvl);
375 }
376 
378 {
379  if (flags & MULTIRES_COORDS_MODIFIED) {
380  subdiv_ccg->dirty.coords = true;
381  }
382  if (flags & MULTIRES_HIDDEN_MODIFIED) {
383  subdiv_ccg->dirty.hidden = true;
384  }
385 }
386 
388 {
389  if (object == NULL) {
390  return;
391  }
392  /* NOTE: CCG live inside of evaluated object.
393  *
394  * While this is a bit weird to tag the only one, this is how other areas were built
395  * historically: they are tagging multires for update and then rely on object re-evaluation to
396  * do an actual update.
397  *
398  * In a longer term maybe special dependency graph tag can help sanitizing this a bit. */
399  Object *object_eval = DEG_get_evaluated_object(depsgraph, object);
400  Mesh *mesh = object_eval->data;
401  SubdivCCG *subdiv_ccg = mesh->runtime.subdiv_ccg;
402  if (subdiv_ccg == NULL) {
403  return;
404  }
405  multires_ccg_mark_as_modified(subdiv_ccg, flags);
406 }
407 
409 {
410  if (object == NULL || object->sculpt == NULL || object->sculpt->pbvh == NULL) {
411  return;
412  }
413 
414  SculptSession *sculpt_session = object->sculpt;
415  if (BKE_pbvh_type(sculpt_session->pbvh) != PBVH_GRIDS || !sculpt_session->multires.active ||
416  sculpt_session->multires.modifier == NULL) {
417  return;
418  }
419 
420  SubdivCCG *subdiv_ccg = sculpt_session->subdiv_ccg;
421  if (subdiv_ccg == NULL) {
422  return;
423  }
424 
425  if (!subdiv_ccg->dirty.coords && !subdiv_ccg->dirty.hidden) {
426  return;
427  }
428 
429  Mesh *mesh = object->data;
431  sculpt_session->multires.modifier->totlvl, mesh, sculpt_session->subdiv_ccg);
432 
433  subdiv_ccg->dirty.coords = false;
434  subdiv_ccg->dirty.hidden = false;
435 }
436 
438 {
440 
441  if (object == NULL || object->sculpt == NULL) {
442  return;
443  }
444 
445  SculptSession *ss = object->sculpt;
446 
447  if (ss->pbvh != NULL) {
448  BKE_pbvh_free(ss->pbvh);
449  object->sculpt->pbvh = NULL;
450  }
451 
452  MEM_SAFE_FREE(ss->pmap);
453 
454  MEM_SAFE_FREE(ss->pmap_mem);
455 }
456 
458 {
459  Mesh *mesh = BKE_mesh_from_object(object);
460 
463 }
464 
465 /* reset the multires levels to match the number of mdisps */
467 {
468  Mesh *me = ob->data;
469  MDisps *mdisp, *md;
470  int i, j, totlvl = 0;
471 
472  mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS);
473 
474  for (i = 0; i < me->totpoly; i++) {
475  md = mdisp + me->mpoly[i].loopstart;
476 
477  for (j = 0; j < me->mpoly[i].totloop; j++, md++) {
478  if (md->totdisp == 0) {
479  continue;
480  }
481 
482  while (1) {
483  int side = (1 << (totlvl - 1)) + 1;
484  int lvl_totdisp = side * side;
485  if (md->totdisp == lvl_totdisp) {
486  break;
487  }
488  if (md->totdisp < lvl_totdisp) {
489  totlvl--;
490  }
491  else {
492  totlvl++;
493  }
494  }
495 
496  break;
497  }
498  }
499 
500  return totlvl;
501 }
502 
504 {
505  Mesh *me = ob->data;
506  MDisps *mdisp;
507 
508  if (me->edit_mesh) {
510  }
511  else {
512  mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS);
513  }
514 
515  if (mdisp) {
516  mmd->totlvl = get_levels_from_disps(ob);
517  mmd->lvl = MIN2(mmd->sculptlvl, mmd->totlvl);
518  mmd->sculptlvl = MIN2(mmd->sculptlvl, mmd->totlvl);
519  mmd->renderlvl = MIN2(mmd->renderlvl, mmd->totlvl);
520  }
521 }
522 
523 static void multires_set_tot_mdisps(Mesh *me, int lvl)
524 {
525  MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
526  int i;
527 
528  if (mdisps) {
529  for (i = 0; i < me->totloop; i++, mdisps++) {
530  mdisps->totdisp = multires_grid_tot[lvl];
531  mdisps->level = lvl;
532  }
533  }
534 }
535 
536 static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl)
537 {
538  int i;
539 
540  /* reallocate displacements to be filled in */
541  for (i = 0; i < totloop; i++) {
542  int totdisp = multires_grid_tot[lvl];
543  float(*disps)[3] = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps");
544 
545  if (mdisps[i].disps) {
546  MEM_freeN(mdisps[i].disps);
547  }
548 
549  if (mdisps[i].level && mdisps[i].hidden) {
550  multires_mdisps_subdivide_hidden(&mdisps[i], lvl);
551  }
552 
553  mdisps[i].disps = disps;
554  mdisps[i].totdisp = totdisp;
555  mdisps[i].level = lvl;
556  }
557 }
558 
559 static void multires_copy_grid(float (*gridA)[3], float (*gridB)[3], int sizeA, int sizeB)
560 {
561  int x, y, j, skip;
562 
563  if (sizeA > sizeB) {
564  skip = (sizeA - 1) / (sizeB - 1);
565 
566  for (j = 0, y = 0; y < sizeB; y++) {
567  for (x = 0; x < sizeB; x++, j++) {
568  copy_v3_v3(gridA[y * skip * sizeA + x * skip], gridB[j]);
569  }
570  }
571  }
572  else {
573  skip = (sizeB - 1) / (sizeA - 1);
574 
575  for (j = 0, y = 0; y < sizeA; y++) {
576  for (x = 0; x < sizeA; x++, j++) {
577  copy_v3_v3(gridA[j], gridB[y * skip * sizeB + x * skip]);
578  }
579  }
580  }
581 }
582 
583 static void multires_copy_dm_grid(CCGElem *gridA, CCGElem *gridB, CCGKey *keyA, CCGKey *keyB)
584 {
585  int x, y, j, skip;
586 
587  if (keyA->grid_size > keyB->grid_size) {
588  skip = (keyA->grid_size - 1) / (keyB->grid_size - 1);
589 
590  for (j = 0, y = 0; y < keyB->grid_size; y++) {
591  for (x = 0; x < keyB->grid_size; x++, j++) {
592  memcpy(CCG_elem_offset_co(keyA, gridA, y * skip * keyA->grid_size + x * skip),
593  CCG_elem_offset_co(keyB, gridB, j),
594  keyA->elem_size);
595  }
596  }
597  }
598  else {
599  skip = (keyB->grid_size - 1) / (keyA->grid_size - 1);
600 
601  for (j = 0, y = 0; y < keyA->grid_size; y++) {
602  for (x = 0; x < keyA->grid_size; x++, j++) {
603  memcpy(CCG_elem_offset_co(keyA, gridA, j),
604  CCG_elem_offset_co(keyB, gridB, y * skip * keyB->grid_size + x * skip),
605  keyA->elem_size);
606  }
607  }
608  }
609 }
610 
611 /* Reallocate gpm->data at a lower resolution and copy values over
612  * from the original high-resolution data */
614 {
615  if (level < gpm->level) {
616  int gridsize = BKE_ccg_gridsize(level);
617  float *data = MEM_calloc_arrayN(
618  square_i(gridsize), sizeof(float), "multires_grid_paint_mask_downsample");
619  int x, y;
620 
621  for (y = 0; y < gridsize; y++) {
622  for (x = 0; x < gridsize; x++) {
623  data[y * gridsize + x] = paint_grid_paint_mask(gpm, level, x, y);
624  }
625  }
626 
627  MEM_freeN(gpm->data);
628  gpm->data = data;
629  gpm->level = level;
630  }
631 }
632 
633 static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
634 {
635  Mesh *me = (Mesh *)ob->data;
636  int levels = mmd->totlvl - lvl;
637  MDisps *mdisps;
638  GridPaintMask *gpm;
639 
642  mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
644 
646 
647  if (mdisps && levels > 0) {
648  if (lvl > 0) {
649  /* MLoop *ml = me->mloop; */ /*UNUSED*/
650  int nsize = multires_side_tot[lvl];
651  int hsize = multires_side_tot[mmd->totlvl];
652  int i, j;
653 
654  for (i = 0; i < me->totpoly; i++) {
655  for (j = 0; j < me->mpoly[i].totloop; j++) {
656  int g = me->mpoly[i].loopstart + j;
657  MDisps *mdisp = &mdisps[g];
658  float(*disps)[3], (*ndisps)[3], (*hdisps)[3];
659  int totdisp = multires_grid_tot[lvl];
660 
661  disps = MEM_calloc_arrayN(totdisp, sizeof(float[3]), "multires disps");
662 
663  if (mdisp->disps != NULL) {
664  ndisps = disps;
665  hdisps = mdisp->disps;
666 
667  multires_copy_grid(ndisps, hdisps, nsize, hsize);
668  if (mdisp->hidden) {
669  BLI_bitmap *gh = multires_mdisps_downsample_hidden(mdisp->hidden, mdisp->level, lvl);
670  MEM_freeN(mdisp->hidden);
671  mdisp->hidden = gh;
672  }
673 
674  MEM_freeN(mdisp->disps);
675  }
676 
677  mdisp->disps = disps;
678  mdisp->totdisp = totdisp;
679  mdisp->level = lvl;
680 
681  if (gpm) {
683  }
684  }
685  }
686  }
687  else {
689  }
690  }
691 
692  multires_set_tot_level(ob, mmd, lvl);
693 }
694 
696  Scene *scene,
697  Object *ob,
698  int direction)
699 {
700  Mesh *me = BKE_mesh_from_object(ob);
701  int lvl = multires_get_level(scene, ob, mmd, false, true);
702  int levels = mmd->totlvl - lvl;
703  MDisps *mdisps;
704 
707  mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
708 
710 
711  if (mdisps && levels > 0 && direction == 1) {
712  multires_del_higher(mmd, ob, lvl);
713  }
714 
715  multires_set_tot_level(ob, mmd, lvl);
716 }
717 
719  Object *ob,
720  DerivedMesh *dm,
721  int lvl,
722  int totlvl,
723  bool alloc_paint_mask,
724  int flags)
725 {
726  MultiresModifierData mmd = {{NULL}};
727 
728  mmd.lvl = lvl;
729  mmd.sculptlvl = lvl;
730  mmd.renderlvl = lvl;
731  mmd.totlvl = totlvl;
732 
733  flags |= MULTIRES_USE_LOCAL_MMD;
734  if (alloc_paint_mask) {
735  flags |= MULTIRES_ALLOC_PAINT_MASK;
736  }
737 
738  return multires_make_derived_from_derived(dm, &mmd, scene, ob, flags);
739 }
740 
742  Object *ob,
743  DerivedMesh *dm,
744  int lvl,
745  bool is_simple,
746  bool is_optimal,
747  bool is_plain_uv,
748  bool alloc_paint_mask,
749  bool for_render,
750  SubsurfFlags flags)
751 {
752  SubsurfModifierData smd = {{NULL}};
753 
754  smd.levels = smd.renderLevels = lvl;
755  smd.quality = 3;
756  if (!is_plain_uv) {
758  }
759  else {
761  }
762  if (is_simple) {
764  }
765  if (is_optimal) {
767  }
768 
769  if (ob->mode & OB_MODE_EDIT) {
770  flags |= SUBSURF_IN_EDIT_MODE;
771  }
772  if (alloc_paint_mask) {
773  flags |= SUBSURF_ALLOC_PAINT_MASK;
774  }
775  if (for_render) {
776  flags |= SUBSURF_USE_RENDER_PARAMS;
777  }
778 
779  return subsurf_make_derived_from_derived(dm, &smd, scene, NULL, flags);
780 }
781 
782 static void grid_tangent(const CCGKey *key, int x, int y, int axis, CCGElem *grid, float t[3])
783 {
784  if (axis == 0) {
785  if (x == key->grid_size - 1) {
786  if (y == key->grid_size - 1) {
787  sub_v3_v3v3(
788  t, CCG_grid_elem_co(key, grid, x, y - 1), CCG_grid_elem_co(key, grid, x - 1, y - 1));
789  }
790  else {
791  sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, y), CCG_grid_elem_co(key, grid, x - 1, y));
792  }
793  }
794  else {
795  sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x + 1, y), CCG_grid_elem_co(key, grid, x, y));
796  }
797  }
798  else if (axis == 1) {
799  if (y == key->grid_size - 1) {
800  if (x == key->grid_size - 1) {
801  sub_v3_v3v3(
802  t, CCG_grid_elem_co(key, grid, x - 1, y), CCG_grid_elem_co(key, grid, x - 1, (y - 1)));
803  }
804  else {
805  sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, y), CCG_grid_elem_co(key, grid, x, (y - 1)));
806  }
807  }
808  else {
809  sub_v3_v3v3(t, CCG_grid_elem_co(key, grid, x, (y + 1)), CCG_grid_elem_co(key, grid, x, y));
810  }
811  }
812 }
813 
814 /* Construct 3x3 tangent-space matrix in 'mat' */
815 static void grid_tangent_matrix(float mat[3][3], const CCGKey *key, int x, int y, CCGElem *grid)
816 {
817  grid_tangent(key, x, y, 0, grid, mat[0]);
818  normalize_v3(mat[0]);
819 
820  grid_tangent(key, x, y, 1, grid, mat[1]);
821  normalize_v3(mat[1]);
822 
823  copy_v3_v3(mat[2], CCG_grid_elem_no(key, grid, x, y));
824 }
825 
826 typedef struct MultiresThreadedData {
836  float (*smat)[3];
838 
839 static void multires_disp_run_cb(void *__restrict userdata,
840  const int pidx,
841  const TaskParallelTLS *__restrict UNUSED(tls))
842 {
843  MultiresThreadedData *tdata = userdata;
844 
845  DispOp op = tdata->op;
846  CCGElem **gridData = tdata->gridData;
847  CCGElem **subGridData = tdata->subGridData;
848  CCGKey *key = tdata->key;
849  MPoly *mpoly = tdata->mpoly;
850  MDisps *mdisps = tdata->mdisps;
851  GridPaintMask *grid_paint_mask = tdata->grid_paint_mask;
852  int *gridOffset = tdata->gridOffset;
853  int gridSize = tdata->gridSize;
854  int dGridSize = tdata->dGridSize;
855  int dSkip = tdata->dSkip;
856 
857  const int numVerts = mpoly[pidx].totloop;
858  int S, x, y, gIndex = gridOffset[pidx];
859 
860  for (S = 0; S < numVerts; S++, gIndex++) {
861  GridPaintMask *gpm = grid_paint_mask ? &grid_paint_mask[gIndex] : NULL;
862  MDisps *mdisp = &mdisps[mpoly[pidx].loopstart + S];
863  CCGElem *grid = gridData[gIndex];
864  CCGElem *subgrid = subGridData[gIndex];
865  float(*dispgrid)[3] = NULL;
866 
867  dispgrid = mdisp->disps;
868 
869  /* if needed, reallocate multires paint mask */
870  if (gpm && gpm->level < key->level) {
871  gpm->level = key->level;
872  if (gpm->data) {
873  MEM_freeN(gpm->data);
874  }
875  gpm->data = MEM_calloc_arrayN(key->grid_area, sizeof(float), "gpm.data");
876  }
877 
878  for (y = 0; y < gridSize; y++) {
879  for (x = 0; x < gridSize; x++) {
880  float *co = CCG_grid_elem_co(key, grid, x, y);
881  float *sco = CCG_grid_elem_co(key, subgrid, x, y);
882  float *data = dispgrid[dGridSize * y * dSkip + x * dSkip];
883  float mat[3][3], disp[3], d[3], mask;
884 
885  /* construct tangent space matrix */
886  grid_tangent_matrix(mat, key, x, y, subgrid);
887 
888  switch (op) {
889  case APPLY_DISPLACEMENTS:
890  /* Convert displacement to object space
891  * and add to grid points */
892  mul_v3_m3v3(disp, mat, data);
893  add_v3_v3v3(co, sco, disp);
894  break;
895  case CALC_DISPLACEMENTS:
896  /* Calculate displacement between new and old
897  * grid points and convert to tangent space */
898  sub_v3_v3v3(disp, co, sco);
899  invert_m3(mat);
900  mul_v3_m3v3(data, mat, disp);
901  break;
902  case ADD_DISPLACEMENTS:
903  /* Convert subdivided displacements to tangent
904  * space and add to the original displacements */
905  invert_m3(mat);
906  mul_v3_m3v3(d, mat, co);
907  add_v3_v3(data, d);
908  break;
909  }
910 
911  if (gpm) {
912  switch (op) {
913  case APPLY_DISPLACEMENTS:
914  /* Copy mask from gpm to DM */
915  *CCG_grid_elem_mask(key, grid, x, y) = paint_grid_paint_mask(gpm, key->level, x, y);
916  break;
917  case CALC_DISPLACEMENTS:
918  /* Copy mask from DM to gpm */
919  mask = *CCG_grid_elem_mask(key, grid, x, y);
920  gpm->data[y * gridSize + x] = CLAMPIS(mask, 0, 1);
921  break;
922  case ADD_DISPLACEMENTS:
923  /* Add mask displacement to gpm */
924  gpm->data[y * gridSize + x] += *CCG_grid_elem_mask(key, grid, x, y);
925  break;
926  }
927  }
928  }
929  }
930  }
931 }
932 
933 /* XXX WARNING: subsurf elements from dm and oldGridData *must* be of the same format (size),
934  * because this code uses CCGKey's info from dm to access oldGridData's normals
935  * (through the call to grid_tangent_matrix())! */
937  DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, CCGElem **oldGridData, int totlvl)
938 {
939  CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
940  CCGElem **gridData, **subGridData;
941  CCGKey key;
942  MPoly *mpoly = me->mpoly;
943  MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
944  GridPaintMask *grid_paint_mask = NULL;
945  int *gridOffset;
946  int i, gridSize, dGridSize, dSkip;
947  int totloop, totpoly;
948 
949  /* this happens in the dm made by bmesh_mdisps_space_set */
950  if (dm2 && CustomData_has_layer(&dm2->loopData, CD_MDISPS)) {
951  mpoly = CustomData_get_layer(&dm2->polyData, CD_MPOLY);
952  mdisps = CustomData_get_layer(&dm2->loopData, CD_MDISPS);
953  totloop = dm2->numLoopData;
954  totpoly = dm2->numPolyData;
955  }
956  else {
957  totloop = me->totloop;
958  totpoly = me->totpoly;
959  }
960 
961  if (!mdisps) {
962  if (op == CALC_DISPLACEMENTS) {
964  }
965  else {
966  return;
967  }
968  }
969 
970  // numGrids = dm->getNumGrids(dm); /* UNUSED */
971  gridSize = dm->getGridSize(dm);
972  gridData = dm->getGridData(dm);
973  gridOffset = dm->getGridOffset(dm);
974  dm->getGridKey(dm, &key);
975  subGridData = (oldGridData) ? oldGridData : gridData;
976 
977  dGridSize = multires_side_tot[totlvl];
978  dSkip = (dGridSize - 1) / (gridSize - 1);
979 
980  /* multires paint masks */
981  if (key.has_mask) {
982  grid_paint_mask = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK);
983  }
984 
985  /* when adding new faces in edit mode, need to allocate disps */
986  for (i = 0; i < totloop; i++) {
987  if (mdisps[i].disps == NULL) {
988  multires_reallocate_mdisps(totloop, mdisps, totlvl);
989  break;
990  }
991  }
992 
993  TaskParallelSettings settings;
996 
998  .op = op,
999  .gridData = gridData,
1000  .subGridData = subGridData,
1001  .key = &key,
1002  .mpoly = mpoly,
1003  .mdisps = mdisps,
1004  .grid_paint_mask = grid_paint_mask,
1005  .gridOffset = gridOffset,
1006  .gridSize = gridSize,
1007  .dGridSize = dGridSize,
1008  .dSkip = dSkip,
1009  };
1010 
1011  BLI_task_parallel_range(0, totpoly, &data, multires_disp_run_cb, &settings);
1012 
1013  if (op == APPLY_DISPLACEMENTS) {
1014  ccgSubSurf_stitchFaces(ccgdm->ss, 0, NULL, 0);
1015  ccgSubSurf_updateNormals(ccgdm->ss, NULL, 0);
1016  }
1017 }
1018 
1020 {
1021  CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
1022  Object *ob;
1023  Mesh *me;
1024  const MDisps *mdisps;
1025  MultiresModifierData *mmd;
1026 
1027  ob = ccgdm->multires.ob;
1028  me = ccgdm->multires.ob->data;
1029  mmd = ccgdm->multires.mmd;
1030  multires_set_tot_mdisps(me, mmd->totlvl);
1032  mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
1033 
1034  if (mdisps) {
1035  int lvl = ccgdm->multires.lvl;
1036  int totlvl = ccgdm->multires.totlvl;
1037 
1038  if (lvl < totlvl) {
1039  DerivedMesh *lowdm, *cddm, *highdm;
1040  CCGElem **highGridData, **lowGridData, **subGridData, **gridData, *diffGrid;
1041  CCGKey highGridKey, lowGridKey;
1042  CCGSubSurf *ss;
1043  int i, j, numGrids, highGridSize, lowGridSize;
1044  const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK);
1045 
1046  /* Create subsurf DM from original mesh at high level. */
1047  /* TODO: use mesh_deform_eval when sculpting on deformed mesh. */
1048  cddm = CDDM_from_mesh(me);
1050 
1051  highdm = subsurf_dm_create_local(scene,
1052  ob,
1053  cddm,
1054  totlvl,
1055  false,
1056  0,
1058  has_mask,
1059  false,
1061  ss = ((CCGDerivedMesh *)highdm)->ss;
1062 
1063  /* create multires DM from original mesh and displacements */
1064  lowdm = multires_dm_create_local(
1065  scene, ob, cddm, lvl, totlvl, has_mask, MULTIRES_IGNORE_SIMPLIFY);
1066  cddm->release(cddm);
1067 
1068  /* gather grid data */
1069  numGrids = highdm->getNumGrids(highdm);
1070  highGridSize = highdm->getGridSize(highdm);
1071  highGridData = highdm->getGridData(highdm);
1072  highdm->getGridKey(highdm, &highGridKey);
1073  lowGridSize = lowdm->getGridSize(lowdm);
1074  lowGridData = lowdm->getGridData(lowdm);
1075  lowdm->getGridKey(lowdm, &lowGridKey);
1076  gridData = dm->getGridData(dm);
1077 
1078  BLI_assert(highGridKey.elem_size == lowGridKey.elem_size);
1079 
1080  subGridData = MEM_calloc_arrayN(numGrids, sizeof(CCGElem *), "subGridData*");
1081  diffGrid = MEM_calloc_arrayN(lowGridKey.elem_size, lowGridSize * lowGridSize, "diff");
1082 
1083  for (i = 0; i < numGrids; i++) {
1084  /* backup subsurf grids */
1085  subGridData[i] = MEM_calloc_arrayN(
1086  highGridKey.elem_size, highGridSize * highGridSize, "subGridData");
1087  memcpy(
1088  subGridData[i], highGridData[i], highGridKey.elem_size * highGridSize * highGridSize);
1089 
1090  /* write difference of subsurf and displaced low level into high subsurf */
1091  for (j = 0; j < lowGridSize * lowGridSize; j++) {
1092  sub_v4_v4v4(CCG_elem_offset_co(&lowGridKey, diffGrid, j),
1093  CCG_elem_offset_co(&lowGridKey, gridData[i], j),
1094  CCG_elem_offset_co(&lowGridKey, lowGridData[i], j));
1095  }
1096 
1097  multires_copy_dm_grid(highGridData[i], diffGrid, &highGridKey, &lowGridKey);
1098  }
1099 
1100  /* lower level dm no longer needed at this point */
1101  MEM_freeN(diffGrid);
1102  lowdm->release(lowdm);
1103 
1104  /* subsurf higher levels again with difference of coordinates */
1105  ccgSubSurf_updateFromFaces(ss, lvl, NULL, 0);
1106  ccgSubSurf_updateLevels(ss, lvl, NULL, 0);
1107 
1108  /* add to displacements */
1109  multiresModifier_disp_run(highdm, me, NULL, ADD_DISPLACEMENTS, subGridData, mmd->totlvl);
1110 
1111  /* free */
1112  highdm->release(highdm);
1113  for (i = 0; i < numGrids; i++) {
1114  MEM_freeN(subGridData[i]);
1115  }
1116  MEM_freeN(subGridData);
1117  }
1118  else {
1119  DerivedMesh *cddm, *subdm;
1120  const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK);
1121 
1122  /* TODO: use mesh_deform_eval when sculpting on deformed mesh. */
1123  cddm = CDDM_from_mesh(me);
1125 
1127  ob,
1128  cddm,
1129  mmd->totlvl,
1130  false,
1131  0,
1133  has_mask,
1134  false,
1136  cddm->release(cddm);
1137 
1139  dm, me, NULL, CALC_DISPLACEMENTS, subdm->getGridData(subdm), mmd->totlvl);
1140 
1141  subdm->release(subdm);
1142  }
1143  }
1144 }
1145 
1147 {
1148  CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
1149  BLI_bitmap **grid_hidden = ccgdm->gridHidden;
1150  Mesh *me = ccgdm->multires.ob->data;
1151  MDisps *mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
1152  int totlvl = ccgdm->multires.totlvl;
1153  int lvl = ccgdm->multires.lvl;
1154 
1155  if (mdisps) {
1156  int i;
1157 
1158  for (i = 0; i < me->totloop; i++) {
1159  MDisps *md = &mdisps[i];
1160  BLI_bitmap *gh = grid_hidden[i];
1161 
1162  if (!gh && md->hidden) {
1163  MEM_freeN(md->hidden);
1164  md->hidden = NULL;
1165  }
1166  else if (gh) {
1167  gh = multires_mdisps_upsample_hidden(gh, lvl, totlvl, md->hidden);
1168  if (md->hidden) {
1169  MEM_freeN(md->hidden);
1170  }
1171 
1172  md->hidden = gh;
1173  }
1174  }
1175  }
1176 }
1177 
1179 {
1180  if (ob == NULL) {
1181  return;
1182  }
1183  SculptSession *sculpt_session = ob->sculpt;
1184  if (sculpt_session == NULL) {
1185  return;
1186  }
1187  PBVH *pbvh = sculpt_session->pbvh;
1188  SubdivCCG *subdiv_ccg = sculpt_session->subdiv_ccg;
1189  if (pbvh == NULL || subdiv_ccg == NULL) {
1190  return;
1191  }
1193  /* NOTE: Currently CCG does not keep track of faces, making it impossible
1194  * to use BKE_pbvh_get_grid_updates().
1195  */
1196  CCGFace **faces;
1197  int num_faces;
1198  BKE_pbvh_get_grid_updates(pbvh, false, (void ***)&faces, &num_faces);
1199  if (num_faces) {
1200  BKE_subdiv_ccg_average_stitch_faces(subdiv_ccg, faces, num_faces);
1201  MEM_freeN(faces);
1202  }
1203 }
1204 
1207 {
1208  Mesh *me = ob->data;
1210  CCGDerivedMesh *ccgdm = NULL;
1211  CCGElem **gridData, **subGridData;
1212  CCGKey key;
1213  const bool render = (flags & MULTIRES_USE_RENDER_PARAMS) != 0;
1214  const bool ignore_simplify = (flags & MULTIRES_IGNORE_SIMPLIFY) != 0;
1215  int lvl = multires_get_level(scene, ob, mmd, render, ignore_simplify);
1216  int i, gridSize, numGrids;
1217 
1218  if (lvl == 0) {
1219  return dm;
1220  }
1221 
1222  const int subsurf_flags = ignore_simplify ? SUBSURF_IGNORE_SIMPLIFY : 0;
1223 
1225  ob,
1226  dm,
1227  lvl,
1228  false,
1231  flags & MULTIRES_ALLOC_PAINT_MASK,
1232  render,
1233  subsurf_flags);
1234 
1235  if (!(flags & MULTIRES_USE_LOCAL_MMD)) {
1236  ccgdm = (CCGDerivedMesh *)result;
1237 
1238  ccgdm->multires.ob = ob;
1239  ccgdm->multires.mmd = mmd;
1240  ccgdm->multires.local_mmd = 0;
1241  ccgdm->multires.lvl = lvl;
1242  ccgdm->multires.totlvl = mmd->totlvl;
1243  ccgdm->multires.modified_flags = 0;
1244  }
1245 
1246  numGrids = result->getNumGrids(result);
1247  gridSize = result->getGridSize(result);
1248  gridData = result->getGridData(result);
1249  result->getGridKey(result, &key);
1250 
1251  subGridData = MEM_malloc_arrayN(numGrids, sizeof(CCGElem *), "subGridData*");
1252 
1253  for (i = 0; i < numGrids; i++) {
1254  subGridData[i] = MEM_malloc_arrayN(key.elem_size, gridSize * gridSize, "subGridData");
1255  memcpy(subGridData[i], gridData[i], key.elem_size * gridSize * gridSize);
1256  }
1257 
1258  multires_set_tot_mdisps(me, mmd->totlvl);
1260 
1261  /* Run displacement. */
1262  multiresModifier_disp_run(result, ob->data, dm, APPLY_DISPLACEMENTS, subGridData, mmd->totlvl);
1263 
1264  /* copy hidden elements for this level */
1265  if (ccgdm) {
1266  multires_output_hidden_to_ccgdm(ccgdm, me, lvl);
1267  }
1268 
1269  for (i = 0; i < numGrids; i++) {
1270  MEM_freeN(subGridData[i]);
1271  }
1272  MEM_freeN(subGridData);
1273 
1274  return result;
1275 }
1276 
1277 void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float u, float v)
1278 {
1279  int x, y, x2, y2;
1280  const int st_max = st - 1;
1281  float urat, vrat, uopp;
1282  float d[4][3], d2[2][3];
1283 
1284  if (!disps || isnan(u) || isnan(v)) {
1285  return;
1286  }
1287 
1288  if (u < 0) {
1289  u = 0;
1290  }
1291  else if (u >= st) {
1292  u = st_max;
1293  }
1294  if (v < 0) {
1295  v = 0;
1296  }
1297  else if (v >= st) {
1298  v = st_max;
1299  }
1300 
1301  x = floor(u);
1302  y = floor(v);
1303  x2 = x + 1;
1304  y2 = y + 1;
1305 
1306  if (x2 >= st) {
1307  x2 = st_max;
1308  }
1309  if (y2 >= st) {
1310  y2 = st_max;
1311  }
1312 
1313  urat = u - x;
1314  vrat = v - y;
1315  uopp = 1 - urat;
1316 
1317  mul_v3_v3fl(d[0], disps[y * st + x], uopp);
1318  mul_v3_v3fl(d[1], disps[y * st + x2], urat);
1319  mul_v3_v3fl(d[2], disps[y2 * st + x], uopp);
1320  mul_v3_v3fl(d[3], disps[y2 * st + x2], urat);
1321 
1322  add_v3_v3v3(d2[0], d[0], d[1]);
1323  add_v3_v3v3(d2[1], d[2], d[3]);
1324  mul_v3_fl(d2[0], 1 - vrat);
1325  mul_v3_fl(d2[1], vrat);
1326 
1327  add_v3_v3v3(out, d2[0], d2[1]);
1328 }
1329 
1331  MultiresModifierData *mmd_src,
1332  MultiresModifierData *mmd_dst)
1333 {
1334  if (mmd_src->totlvl == mmd_dst->totlvl) {
1335  return;
1336  }
1337 
1338  if (mmd_src->totlvl > mmd_dst->totlvl) {
1340  ob_dst, mmd_dst, mmd_src->totlvl, MULTIRES_SUBDIVIDE_CATMULL_CLARK);
1341  }
1342  else {
1343  multires_del_higher(mmd_dst, ob_dst, mmd_src->totlvl);
1344  }
1345 }
1346 
1347 static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst)
1348 {
1349  MultiresModifierData *mmd_src = get_multires_modifier(scene, ob_src, true);
1350  MultiresModifierData *mmd_dst = get_multires_modifier(scene, ob_dst, true);
1351 
1352  if (!mmd_src) {
1353  /* object could have MDISP even when there is no multires modifier
1354  * this could lead to troubles due to i've got no idea how mdisp could be
1355  * up-sampled correct without modifier data.
1356  * just remove mdisps if no multires present (nazgul) */
1357 
1359  }
1360 
1361  if (mmd_src && mmd_dst) {
1362  multiresModifier_sync_levels_ex(ob_dst, mmd_src, mmd_dst);
1363  }
1364 }
1365 
1366 static void multires_apply_uniform_scale(Object *object, const float scale)
1367 {
1368  Mesh *mesh = (Mesh *)object->data;
1370  for (int i = 0; i < mesh->totloop; i++) {
1371  MDisps *grid = &mdisps[i];
1372  for (int j = 0; j < grid->totdisp; j++) {
1373  mul_v3_fl(grid->disps[j], scale);
1374  }
1375  }
1376 }
1377 
1379  Scene *scene,
1380  Object *object,
1381  const float smat[3][3])
1382 {
1383  const MultiresModifierData *mmd = get_multires_modifier(scene, object, true);
1384  if (mmd == NULL || mmd->totlvl == 0) {
1385  return;
1386  }
1387  /* Make sure layer present. */
1388  Mesh *mesh = (Mesh *)object->data;
1391  return;
1392  }
1393  if (is_uniform_scaled_m3(smat)) {
1394  const float scale = mat3_to_scale(smat);
1395  multires_apply_uniform_scale(object, scale);
1396  }
1397  else {
1398  /* TODO(sergey): This branch of code actually requires more work to
1399  * preserve all the details.
1400  */
1401  const float scale = mat3_to_scale(smat);
1402  multires_apply_uniform_scale(object, scale);
1403  }
1404 }
1405 
1407 {
1408  int lvl = 13;
1409 
1410  while (lvl > 0) {
1411  int side = (1 << (lvl - 1)) + 1;
1412  if ((s->totdisp % (side * side)) == 0) {
1413  return s->totdisp / (side * side);
1414  }
1415  lvl--;
1416  }
1417 
1418  return 0;
1419 }
1420 
1422 {
1423  float smat[3][3];
1424 
1425  /* object's scale matrix */
1426  BKE_object_scale_to_mat3(ob, smat);
1427 
1428  multires_apply_smat(depsgraph, scene, ob, smat);
1429 }
1430 
1432  Scene *scene,
1433  Object *ob,
1434  Object *to_ob)
1435 {
1436  float smat[3][3], tmat[3][3], mat[3][3];
1437  multires_sync_levels(scene, to_ob, ob);
1438 
1439  /* construct scale matrix for displacement */
1440  BKE_object_scale_to_mat3(to_ob, tmat);
1441  invert_m3(tmat);
1442  BKE_object_scale_to_mat3(ob, smat);
1443  mul_m3_m3m3(mat, smat, tmat);
1444 
1445  multires_apply_smat(depsgraph, scene, ob, mat);
1446 }
1447 
1449 {
1450  MDisps *mdisp = NULL, *cur = NULL;
1451  int i, grid = 0;
1452 
1454  mdisp = CustomData_get_layer(&me->ldata, CD_MDISPS);
1455 
1456  if (!mdisp) {
1457  return;
1458  }
1459 
1460  cur = mdisp;
1461  for (i = 0; i < me->totloop; i++, cur++) {
1462  if (cur->totdisp) {
1463  grid = mdisp->totdisp;
1464 
1465  break;
1466  }
1467  }
1468 
1469  for (i = 0; i < me->totloop; i++, mdisp++) {
1470  /* allocate memory for mdisp, the whole disp layer would be erased otherwise */
1471  if (!mdisp->totdisp || !mdisp->disps) {
1472  if (grid) {
1473  mdisp->totdisp = grid;
1474  mdisp->disps = MEM_calloc_arrayN(mdisp->totdisp, sizeof(float[3]), "mdisp topology");
1475  }
1476 
1477  continue;
1478  }
1479  }
1480 }
1481 
1482 void multires_ensure_external_read(struct Mesh *mesh, int top_level)
1483 {
1485  return;
1486  }
1487 
1489  if (mdisps == NULL) {
1491  }
1492 
1493  const int totloop = mesh->totloop;
1494 
1495  for (int i = 0; i < totloop; ++i) {
1496  if (mdisps[i].level != top_level) {
1497  MEM_SAFE_FREE(mdisps[i].disps);
1498  }
1499 
1500  /* NOTE: CustomData_external_read will take care of allocation of displacement vectors if
1501  * they are missing. */
1502 
1503  const int totdisp = multires_grid_tot[top_level];
1504  mdisps[i].totdisp = totdisp;
1505  mdisps[i].level = top_level;
1506  }
1507 
1509 }
1511 {
1513 }
1514 
1515 /***************** Multires interpolation stuff *****************/
1516 
1518  struct MPoly *mpoly,
1519  struct MLoop *UNUSED(mloop),
1520  const struct MLoopTri *UNUSED(lt),
1521  const int face_side,
1522  const float u,
1523  const float v,
1524  float *x,
1525  float *y)
1526 {
1527  const float offset = face_side * 0.5f - 0.5f;
1528  int S = 0;
1529 
1530  if (mpoly->totloop == 4) {
1531  if (u <= offset && v <= offset) {
1532  S = 0;
1533  }
1534  else if (u > offset && v <= offset) {
1535  S = 1;
1536  }
1537  else if (u > offset && v > offset) {
1538  S = 2;
1539  }
1540  else if (u <= offset && v >= offset) {
1541  S = 3;
1542  }
1543 
1544  if (S == 0) {
1545  *y = offset - u;
1546  *x = offset - v;
1547  }
1548  else if (S == 1) {
1549  *x = u - offset;
1550  *y = offset - v;
1551  }
1552  else if (S == 2) {
1553  *y = u - offset;
1554  *x = v - offset;
1555  }
1556  else if (S == 3) {
1557  *x = offset - u;
1558  *y = v - offset;
1559  }
1560  }
1561  else if (mpoly->totloop == 3) {
1562  int grid_size = offset;
1563  float w = (face_side - 1) - u - v;
1564  float W1, W2;
1565 
1566  if (u >= v && u >= w) {
1567  S = 0;
1568  W1 = w;
1569  W2 = v;
1570  }
1571  else if (v >= u && v >= w) {
1572  S = 1;
1573  W1 = u;
1574  W2 = w;
1575  }
1576  else {
1577  S = 2;
1578  W1 = v;
1579  W2 = u;
1580  }
1581 
1582  W1 /= (face_side - 1);
1583  W2 /= (face_side - 1);
1584 
1585  *x = (1 - (2 * W1) / (1 - W2)) * grid_size;
1586  *y = (1 - (2 * W2) / (1 - W1)) * grid_size;
1587  }
1588  else {
1589  /* the complicated ngon case: find the actual coordinate from
1590  * the barycentric coordinates and finally find the closest vertex
1591  * should work reliably for convex cases only but better than nothing */
1592 
1593 #if 0
1594  int minS, i;
1595  float mindist = FLT_MAX;
1596 
1597  for (i = 0; i < mpoly->totloop; i++) {
1598  float len = len_v3v3(NULL, mvert[mloop[mpoly->loopstart + i].v].co);
1599  if (len < mindist) {
1600  mindist = len;
1601  minS = i;
1602  }
1603  }
1604  S = minS;
1605 #endif
1606  /* temp not implemented yet and also not working properly in current master.
1607  * (was worked around by subdividing once) */
1608  S = 0;
1609  *x = 0;
1610  *y = 0;
1611  }
1612 
1613  return S;
1614 }
typedef float(TangentPoint)[2]
void DM_set_only_copy(DerivedMesh *dm, const struct CustomData_MeshMasks *mask)
BLI_INLINE float * CCG_grid_elem_co(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:114
BLI_INLINE float * CCG_grid_elem_no(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:119
struct CCGElem CCGElem
Definition: BKE_ccg.h:30
BLI_INLINE float * CCG_elem_offset_co(const CCGKey *key, CCGElem *elem, int offset)
Definition: BKE_ccg.h:129
BLI_INLINE float * CCG_grid_elem_mask(const CCGKey *key, CCGElem *elem, int x, int y)
Definition: BKE_ccg.h:124
struct DerivedMesh * CDDM_from_mesh(struct Mesh *mesh)
bool CustomData_free_layer_active(struct CustomData *data, int type, int totelem)
Definition: customdata.cc:2895
@ CD_DEFAULT
bool CustomData_has_layer(const struct CustomData *data, int type)
const CustomData_MeshMasks CD_MASK_BAREMESH
Definition: customdata.cc:2051
void CustomData_external_reload(struct CustomData *data, struct ID *id, eCustomDataMask mask, int totelem)
void * CustomData_get_layer(const struct CustomData *data, int type)
bool CustomData_external_test(struct CustomData *data, int type)
Definition: customdata.cc:4772
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
Definition: customdata.cc:2776
void CustomData_external_read(struct CustomData *data, struct ID *id, eCustomDataMask mask, int totelem)
Definition: customdata.cc:4547
void CustomData_external_remove(struct CustomData *data, struct ID *id, int type, int totelem)
Definition: customdata.cc:4748
struct Mesh * BKE_mesh_copy_for_eval(const struct Mesh *source, bool reference)
struct Mesh * BKE_mesh_from_object(struct Object *ob)
Definition: mesh.cc:1365
float(* BKE_mesh_vert_coords_alloc(const struct Mesh *mesh, int *r_vert_len))[3]
struct Mesh * mesh_get_eval_deform(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, const struct CustomData_MeshMasks *dataMask)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
bool BKE_modifier_is_enabled(const struct Scene *scene, struct ModifierData *md, int required_mode)
void BKE_modifier_deform_verts(ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *me, float(*vertexCos)[3], int numVerts)
struct ModifierData * BKE_modifiers_get_virtual_modifierlist(const struct Object *ob, struct VirtualModifierData *data)
@ eModifierTypeType_OnlyDeform
Definition: BKE_modifier.h:44
@ MOD_APPLY_USECACHE
Definition: BKE_modifier.h:118
@ MOD_APPLY_RENDER
Definition: BKE_modifier.h:115
@ MOD_APPLY_IGNORE_SIMPLIFY
Definition: BKE_modifier.h:123
bool multiresModifier_reshapeFromCCG(int tot_level, struct Mesh *coarse_mesh, struct SubdivCCG *subdiv_ccg)
MultiresFlags
Definition: BKE_multires.h:56
@ MULTIRES_USE_RENDER_PARAMS
Definition: BKE_multires.h:58
@ MULTIRES_ALLOC_PAINT_MASK
Definition: BKE_multires.h:59
@ MULTIRES_USE_LOCAL_MMD
Definition: BKE_multires.h:57
@ MULTIRES_IGNORE_SIMPLIFY
Definition: BKE_multires.h:60
@ MULTIRES_SUBDIVIDE_CATMULL_CLARK
Definition: BKE_multires.h:196
void multiresModifier_subdivide_to_level(struct Object *object, struct MultiresModifierData *mmd, int top_level, eMultiresSubdivideModeType mode)
General operations, lookup, etc. for blender objects.
void BKE_object_scale_to_mat3(struct Object *ob, float r_mat[3][3])
Definition: object.cc:2887
float paint_grid_paint_mask(const struct GridPaintMask *gpm, uint level, uint x, uint y)
A BVH for high poly meshes.
void BKE_pbvh_get_grid_updates(PBVH *pbvh, bool clear, void ***r_gridfaces, int *r_totface)
Definition: pbvh.c:1751
void BKE_pbvh_free(PBVH *pbvh)
Definition: pbvh.c:663
PBVHType BKE_pbvh_type(const PBVH *pbvh)
Definition: pbvh.c:1798
@ PBVH_GRIDS
Definition: BKE_pbvh.h:235
int get_render_subsurf_level(const struct RenderData *r, int lvl, bool for_render)
void BKE_subdiv_ccg_average_stitch_faces(SubdivCCG *subdiv_ccg, struct CCGFace **effected_faces, int num_effected_faces)
Definition: subdiv_ccg.c:1329
int BKE_ccg_gridsize(int level)
Definition: CCGSubSurf.c:23
MultiresModifiedFlags
Definition: BKE_subsurf.h:64
@ MULTIRES_HIDDEN_MODIFIED
Definition: BKE_subsurf.h:69
@ MULTIRES_COORDS_MODIFIED
Definition: BKE_subsurf.h:67
struct DerivedMesh * subsurf_make_derived_from_derived(struct DerivedMesh *dm, struct SubsurfModifierData *smd, const struct Scene *scene, float(*vertCos)[3], SubsurfFlags flags)
Definition: subsurf_ccg.c:1902
SubsurfFlags
Definition: BKE_subsurf.h:35
@ SUBSURF_IN_EDIT_MODE
Definition: BKE_subsurf.h:39
@ SUBSURF_ALLOC_PAINT_MASK
Definition: BKE_subsurf.h:40
@ SUBSURF_USE_RENDER_PARAMS
Definition: BKE_subsurf.h:36
@ SUBSURF_IGNORE_SIMPLIFY
Definition: BKE_subsurf.h:42
int BKE_ccg_factor(int low_level, int high_level)
Definition: CCGSubSurf.c:28
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_BITMAP_NEW(_num, _alloc_string)
Definition: BLI_bitmap.h:40
#define BLI_BITMAP_TEST(_bitmap, _index)
Definition: BLI_bitmap.h:64
#define BLI_BITMAP_SET(_bitmap, _index, _set)
Definition: BLI_bitmap.h:102
unsigned int BLI_bitmap
Definition: BLI_bitmap.h:16
MINLINE int square_i(int a)
bool is_uniform_scaled_m3(const float mat[3][3])
Definition: math_matrix.c:1843
float mat3_to_scale(const float M[3][3])
Definition: math_matrix.c:2176
bool invert_m3(float R[3][3])
Definition: math_matrix.c:1171
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:897
void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
Definition: math_matrix.c:388
MINLINE float len_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
MINLINE float normalize_v3(float r[3])
MINLINE void sub_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE void add_v3_v3v3(float r[3], const float a[3], const float b[3])
MINLINE void mul_v3_v3fl(float r[3], const float a[3], float f)
MINLINE void add_v3_v3(float r[3], const float a[3])
MINLINE void sub_v4_v4v4(float r[4], const float a[4], const float b[4])
void BLI_task_parallel_range(int start, int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
Definition: task_range.cc:94
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
Definition: BLI_task.h:293
#define CLAMPIS(a, b, c)
#define UNUSED(x)
#define MAX2(a, b)
#define MIN2(a, b)
CCGError ccgSubSurf_updateFromFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, int numEffectedF)
Definition: CCGSubSurf.c:928
CCGError ccgSubSurf_stitchFaces(CCGSubSurf *ss, int lvl, CCGFace **effectedF, int numEffectedF)
Definition: CCGSubSurf.c:1022
CCGError ccgSubSurf_updateNormals(CCGSubSurf *ss, CCGFace **effectedF, int numEffectedF)
#define CCG_TASK_LIMIT
Definition: CCGSubSurf.h:56
CCGError ccgSubSurf_updateLevels(CCGSubSurf *ss, int lvl, CCGFace **effectedF, int numEffectedF)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
@ DAG_EVAL_RENDER
Definition: DEG_depsgraph.h:46
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
struct Scene * DEG_get_evaluated_scene(const struct Depsgraph *graph)
@ CD_GRID_PAINT_MASK
#define CD_MASK_MDISPS
@ ME_SIMPLE_SUBSURF
@ eMultiresModifierFlag_ControlEdges
@ eModifierMode_Render
@ eModifierMode_Realtime
@ eModifierType_Multires
@ eSubsurfModifierFlag_ControlEdges
@ SUBSURF_UV_SMOOTH_NONE
@ SUBSURF_UV_SMOOTH_PRESERVE_BOUNDARIES
@ OB_MODE_EDIT
@ OB_MODE_SCULPT
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble x2
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
#define MEM_SAFE_FREE(v)
void BM_data_layer_free(BMesh *bm, CustomData *data, int type)
Definition: bmesh_interp.c:875
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
Scene scene
const Depsgraph * depsgraph
int len
Definition: draw_manager.c:108
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:34
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_dupallocN)(const void *vmemh)
Definition: mallocn.c:28
void *(* MEM_calloc_arrayN)(size_t len, size_t size, const char *str)
Definition: mallocn.c:32
ccl_device_inline float4 mask(const int4 &mask, const float4 &a)
Definition: math_float4.h:513
static char faces[256]
static void multires_copy_grid(float(*gridA)[3], float(*gridB)[3], int sizeA, int sizeB)
Definition: multires.c:559
void multires_modifier_update_mdisps(struct DerivedMesh *dm, Scene *scene)
Definition: multires.c:1019
void multires_force_external_reload(Object *object)
Definition: multires.c:457
static void multires_output_hidden_to_ccgdm(CCGDerivedMesh *ccgdm, Mesh *me, int level)
Definition: multires.c:184
static const int multires_grid_tot[]
Definition: multires.c:50
static void multires_grid_paint_mask_downsample(GridPaintMask *gpm, int level)
Definition: multires.c:613
DerivedMesh * multires_make_derived_from_derived(DerivedMesh *dm, MultiresModifierData *mmd, Scene *scene, Object *ob, MultiresFlags flags)
Definition: multires.c:1205
static void multires_sync_levels(Scene *scene, Object *ob_src, Object *ob_dst)
Definition: multires.c:1347
void multiresModifier_sync_levels_ex(Object *ob_dst, MultiresModifierData *mmd_src, MultiresModifierData *mmd_dst)
Definition: multires.c:1330
MultiresModifierData * find_multires_modifier_before(Scene *scene, ModifierData *lastmd)
Definition: multires.c:302
static void multiresModifier_disp_run(DerivedMesh *dm, Mesh *me, DerivedMesh *dm2, DispOp op, CCGElem **oldGridData, int totlvl)
Definition: multires.c:936
static void grid_tangent_matrix(float mat[3][3], const CCGKey *key, int x, int y, CCGElem *grid)
Definition: multires.c:815
static void multires_del_higher(MultiresModifierData *mmd, Object *ob, int lvl)
Definition: multires.c:633
void multiresModifier_del_levels(MultiresModifierData *mmd, Scene *scene, Object *ob, int direction)
Definition: multires.c:695
static void multires_ccg_mark_as_modified(SubdivCCG *subdiv_ccg, MultiresModifiedFlags flags)
Definition: multires.c:377
static DerivedMesh * multires_dm_create_local(Scene *scene, Object *ob, DerivedMesh *dm, int lvl, int totlvl, bool alloc_paint_mask, int flags)
Definition: multires.c:718
static void grid_tangent(const CCGKey *key, int x, int y, int axis, CCGElem *grid, float t[3])
Definition: multires.c:782
static void multires_apply_smat(struct Depsgraph *UNUSED(depsgraph), Scene *scene, Object *object, const float smat[3][3])
Definition: multires.c:1378
static void multires_mdisps_subdivide_hidden(MDisps *md, int new_level)
Definition: multires.c:208
static DerivedMesh * subsurf_dm_create_local(Scene *scene, Object *ob, DerivedMesh *dm, int lvl, bool is_simple, bool is_optimal, bool is_plain_uv, bool alloc_paint_mask, bool for_render, SubsurfFlags flags)
Definition: multires.c:741
void multires_flush_sculpt_updates(Object *object)
Definition: multires.c:408
MultiresModifierData * get_multires_modifier(Scene *scene, Object *ob, bool use_first)
Definition: multires.c:317
void old_mdisps_bilinear(float out[3], float(*disps)[3], const int st, float u, float v)
Definition: multires.c:1277
static const int multires_side_tot[]
Definition: multires.c:52
DispOp
Definition: multires.c:56
@ APPLY_DISPLACEMENTS
Definition: multires.c:57
@ CALC_DISPLACEMENTS
Definition: multires.c:58
@ ADD_DISPLACEMENTS
Definition: multires.c:59
static int get_levels_from_disps(Object *ob)
Definition: multires.c:466
struct MultiresThreadedData MultiresThreadedData
void multires_stitch_grids(Object *ob)
Definition: multires.c:1178
void multiresModifier_ensure_external_read(struct Mesh *mesh, const MultiresModifierData *mmd)
Definition: multires.c:1510
Mesh * BKE_multires_create_mesh(struct Depsgraph *depsgraph, Object *object, MultiresModifierData *mmd)
Definition: multires.c:226
static void multires_apply_uniform_scale(Object *object, const float scale)
Definition: multires.c:1366
static BLI_bitmap * multires_mdisps_upsample_hidden(BLI_bitmap *lo_hidden, int lo_level, int hi_level, const BLI_bitmap *prev_hidden)
Definition: multires.c:93
int mdisp_rot_face_to_crn(struct MVert *UNUSED(mvert), struct MPoly *mpoly, struct MLoop *UNUSED(mloop), const struct MLoopTri *UNUSED(lt), const int face_side, const float u, const float v, float *x, float *y)
Definition: multires.c:1517
void multires_mark_as_modified(Depsgraph *depsgraph, Object *object, MultiresModifiedFlags flags)
Definition: multires.c:387
static BLI_bitmap * multires_mdisps_downsample_hidden(const BLI_bitmap *old_hidden, int old_level, int new_level)
Definition: multires.c:160
void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *ob)
Definition: multires.c:503
void multires_ensure_external_read(struct Mesh *mesh, int top_level)
Definition: multires.c:1482
float(* BKE_multires_create_deformed_base_mesh_vert_coords(struct Depsgraph *depsgraph, struct Object *object, struct MultiresModifierData *mmd, int *r_num_deformed_verts))[3]
Definition: multires.c:249
void multires_topology_changed(Mesh *me)
Definition: multires.c:1448
void multiresModifier_scale_disp(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
Definition: multires.c:1421
static void multires_set_tot_mdisps(Mesh *me, int lvl)
Definition: multires.c:523
int multires_mdisp_corners(const MDisps *s)
Definition: multires.c:1406
void multires_force_sculpt_rebuild(Object *object)
Definition: multires.c:437
void multires_modifier_update_hidden(DerivedMesh *dm)
Definition: multires.c:1146
void multires_set_tot_level(Object *ob, MultiresModifierData *mmd, int lvl)
Definition: multires.c:365
static void multires_copy_dm_grid(CCGElem *gridA, CCGElem *gridB, CCGKey *keyA, CCGKey *keyB)
Definition: multires.c:583
static void multires_reallocate_mdisps(int totloop, MDisps *mdisps, int lvl)
Definition: multires.c:536
int multires_get_level(const Scene *scene, const Object *ob, const MultiresModifierData *mmd, bool render, bool ignore_simplify)
Definition: multires.c:345
void multires_customdata_delete(Mesh *me)
Definition: multires.c:67
void multiresModifier_prepare_join(struct Depsgraph *depsgraph, Scene *scene, Object *ob, Object *to_ob)
Definition: multires.c:1431
static void multires_disp_run_cb(void *__restrict userdata, const int pidx, const TaskParallelTLS *__restrict UNUSED(tls))
Definition: multires.c:839
T floor(const T &a)
bool isnan(double i)
Definition: numeric.h:451
static const pxr::TfToken st("st", pxr::TfToken::Immortal)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
struct BMesh * bm
Definition: BKE_editmesh.h:40
CustomData ldata
Definition: bmesh_class.h:337
struct CCGDerivedMesh::@74 multires
struct CCGSubSurf * ss
Definition: BKE_subsurf.h:77
struct MultiresModifierData * mmd
Definition: BKE_subsurf.h:116
MultiresModifiedFlags modified_flags
Definition: BKE_subsurf.h:123
unsigned int ** gridHidden
Definition: BKE_subsurf.h:111
DerivedMesh dm
Definition: BKE_subsurf.h:75
struct Object * ob
Definition: BKE_subsurf.h:122
Definition: BKE_ccg.h:32
int has_mask
Definition: BKE_ccg.h:55
int grid_size
Definition: BKE_ccg.h:40
int grid_area
Definition: BKE_ccg.h:42
int level
Definition: BKE_ccg.h:33
int elem_size
Definition: BKE_ccg.h:37
int(* getGridSize)(DerivedMesh *dm)
struct CCGElem **(* getGridData)(DerivedMesh *dm)
int(* getNumGrids)(DerivedMesh *dm)
CustomData polyData
void(* getGridKey)(DerivedMesh *dm, struct CCGKey *key)
CustomData loopData
void(* release)(DerivedMesh *dm)
int *(* getGridOffset)(DerivedMesh *dm)
unsigned int level
void * first
Definition: DNA_listBase.h:31
float(* disps)[3]
unsigned int * hidden
struct SubdivCCG * subdiv_ccg
struct BMEditMesh * edit_mesh
Mesh_Runtime runtime
int totpoly
int totloop
struct MPoly * mpoly
CustomData ldata
struct ModifierData * next
struct ModifierData * prev
struct Depsgraph * depsgraph
Definition: BKE_modifier.h:140
ModifierApplyFlag flag
Definition: BKE_modifier.h:142
ModifierTypeType type
Definition: BKE_modifier.h:160
struct Mesh *(* modifyMesh)(struct ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *mesh)
Definition: BKE_modifier.h:231
GridPaintMask * grid_paint_mask
Definition: multires.c:833
float(* smat)[3]
Definition: multires.c:836
CCGElem ** subGridData
Definition: multires.c:828
CCGElem ** gridData
Definition: multires.c:828
ListBase modifiers
struct SculptSession * sculpt
void * data
struct RenderData r
struct SubdivCCG * subdiv_ccg
Definition: BKE_paint.h:547
int * pmap_mem
Definition: BKE_paint.h:517
struct MeshElemMap * pmap
Definition: BKE_paint.h:516
struct SculptSession::@52 multires
struct MultiresModifierData * modifier
Definition: BKE_paint.h:490
struct PBVH * pbvh
Definition: BKE_paint.h:550
struct SubdivCCG::@69 dirty