2007-12-26 09:39:15 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2020-05-09 17:14:35 +10:00
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-12-26 09:39:15 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2007 by Nicholas Bishop
|
|
|
|
* All rights reserved.
|
2018-06-01 18:19:39 +02:00
|
|
|
*/
|
2007-12-26 09:39:15 +00:00
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2009-12-09 13:37:19 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 13:05:18 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-11 11:48:58 +01:00
|
|
|
#include "BKE_subsurf.h"
|
2018-11-01 15:12:54 +01:00
|
|
|
#include "BLI_compiler_compat.h"
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
struct Depsgraph;
|
2009-01-06 18:59:03 +00:00
|
|
|
struct DerivedMesh;
|
2012-03-14 06:32:03 +00:00
|
|
|
struct MDisps;
|
|
|
|
struct Mesh;
|
|
|
|
struct ModifierData;
|
2009-01-06 18:59:03 +00:00
|
|
|
struct MultiresModifierData;
|
2007-12-26 09:39:15 +00:00
|
|
|
struct Object;
|
2010-11-04 16:00:28 +00:00
|
|
|
struct Scene;
|
2018-09-14 10:56:54 +02:00
|
|
|
struct SubdivCCG;
|
2007-12-26 09:39:15 +00:00
|
|
|
|
2015-07-30 14:43:58 +02:00
|
|
|
struct MLoop;
|
|
|
|
struct MLoopTri;
|
2019-01-28 21:08:24 +11:00
|
|
|
struct MPoly;
|
|
|
|
struct MVert;
|
2015-07-30 14:43:58 +02:00
|
|
|
|
Add mask support to CCGSubSurf and multires.
* Add new CCG function ccgSubSurf_setAllocMask(). Similar to to
ccgSubSurf_setCalcVertexNormals(), it sets whether the CCG elements
have a mask layer and what that layer's offset is. Unlike normals
however, it doesn't change any behavior during CCG calculation; it's
there only to give CCGKey information on the mask.
* Add a new flag to _getSubSurf(), CCG_ALLOC_MASK. If set, space for
an extra layer is allocated, but the number of CCG layers is not set
to include it. This is done because GridPaintMasks are absolute,
rather than being relative to the subdivided output (as MDisp
displacements are), so we skip subdividing paint masks here.
* Add a new flag to subsurf_make_derived_from_derived(),
SUBSURF_ALLOC_PAINT_MASK. This controls whether CCG_ALLOC_MASK is
set for _getSubSurf(). Related, masks are never loaded in during
ss_sync_from_derivedmesh(). After subdivision is finished, if the
alloc mask flag is set, the number of CCG layers is increase to 4
with ccgSubSurf_setNumLayers().
* Add a new flag to multires_make_from_derived(),
MULTIRES_ALLOC_PAINT_MASK. Not all multires functions need paint
mask data (e.g. multiresModifier_base_apply.) This flag is always
set in MOD_multires.c so that subdividing a mesh with a mask updates
properly even when not in sculpt mode.
* Update multiresModifier_disp_run() to apply, calculate, and add mask
elements. It's almost the same as the existing operations with xyz
coordinates, but treats masks as absolute rather than displacements
relative to subdivided values.
* Update multires_customdata_delete to free CD_GRID_PAINT_MASK in
addition to CD_MDISPS.
* Update multires_del_higher() to call the new function
multires_grid_paint_mask_downsample(), which allocates a
lower-resolution paint mask grid and copies values over from the
high-resolution grid.
2012-05-10 20:34:08 +00:00
|
|
|
/* Delete mesh mdisps and grid paint masks */
|
2012-03-19 05:13:41 +00:00
|
|
|
void multires_customdata_delete(struct Mesh *me);
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
void multires_set_tot_level(struct Object *ob, struct MultiresModifierData *mmd, int lvl);
|
2012-06-24 20:18:32 +00:00
|
|
|
|
2019-07-09 12:12:18 +02:00
|
|
|
void multires_mark_as_modified(struct Depsgraph *depsgraph,
|
|
|
|
struct Object *object,
|
|
|
|
enum MultiresModifiedFlags flags);
|
2007-12-26 09:39:15 +00:00
|
|
|
|
2020-02-28 12:05:48 +01:00
|
|
|
void multires_flush_sculpt_updates(struct Object *object);
|
|
|
|
void multires_force_sculpt_rebuild(struct Object *object);
|
|
|
|
void multires_force_external_reload(struct Object *object);
|
2007-12-26 09:39:15 +00:00
|
|
|
|
2012-03-12 22:52:20 +00:00
|
|
|
/* internal, only called in subsurf_ccg.c */
|
2018-06-18 11:21:33 +02:00
|
|
|
void multires_modifier_update_mdisps(struct DerivedMesh *dm, struct Scene *scene);
|
2012-03-14 06:32:03 +00:00
|
|
|
void multires_modifier_update_hidden(struct DerivedMesh *dm);
|
2012-03-12 22:52:20 +00:00
|
|
|
|
2010-09-09 00:14:51 +00:00
|
|
|
void multiresModifier_set_levels_from_disps(struct MultiresModifierData *mmd, struct Object *ob);
|
|
|
|
|
2012-05-10 20:32:09 +00:00
|
|
|
typedef enum {
|
|
|
|
MULTIRES_USE_LOCAL_MMD = 1,
|
|
|
|
MULTIRES_USE_RENDER_PARAMS = 2,
|
2014-06-12 13:49:46 +06:00
|
|
|
MULTIRES_ALLOC_PAINT_MASK = 4,
|
2019-01-15 23:57:49 +11:00
|
|
|
MULTIRES_IGNORE_SIMPLIFY = 8,
|
2012-05-10 20:32:09 +00:00
|
|
|
} MultiresFlags;
|
|
|
|
|
2018-04-05 18:20:27 +02:00
|
|
|
struct DerivedMesh *multires_make_derived_from_derived(struct DerivedMesh *dm,
|
|
|
|
struct MultiresModifierData *mmd,
|
2018-06-18 11:21:33 +02:00
|
|
|
struct Scene *scene,
|
2018-04-05 18:20:27 +02:00
|
|
|
struct Object *ob,
|
|
|
|
MultiresFlags flags);
|
2007-12-26 09:39:15 +00:00
|
|
|
|
2010-07-05 12:20:49 +00:00
|
|
|
struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene,
|
2012-05-11 08:05:47 +00:00
|
|
|
struct ModifierData *lastmd);
|
2013-03-19 23:17:44 +00:00
|
|
|
struct MultiresModifierData *get_multires_modifier(struct Scene *scene,
|
|
|
|
struct Object *ob,
|
|
|
|
bool use_first);
|
2018-08-21 15:40:23 +02:00
|
|
|
int multires_get_level(const struct Scene *scene,
|
|
|
|
const struct Object *ob,
|
|
|
|
const struct MultiresModifierData *mmd,
|
2018-08-14 12:17:10 +02:00
|
|
|
bool render,
|
|
|
|
bool ignore_simplify);
|
2020-03-17 15:55:59 +01:00
|
|
|
|
|
|
|
/* Creates mesh with multires modifier applied on current object's deform mesh. */
|
2018-11-02 13:59:04 +01:00
|
|
|
struct Mesh *BKE_multires_create_mesh(struct Depsgraph *depsgraph,
|
2020-03-17 14:20:14 +01:00
|
|
|
struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd);
|
2020-03-17 15:55:59 +01:00
|
|
|
|
2020-03-19 12:05:34 +11:00
|
|
|
/* Get coordinates of a deformed base mesh which is an input to the given multires modifier.
|
2020-03-17 15:55:59 +01:00
|
|
|
* NOTE: The modifiers will be re-evaluated. */
|
2020-03-17 17:34:04 +01:00
|
|
|
float (*BKE_multires_create_deformed_base_mesh_vert_coords(struct Depsgraph *depsgraph,
|
|
|
|
struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd,
|
|
|
|
int *r_num_deformed_verts))[3];
|
2020-03-17 15:55:59 +01:00
|
|
|
|
2018-06-18 11:21:33 +02:00
|
|
|
void multiresModifier_del_levels(struct MultiresModifierData *mmd,
|
|
|
|
struct Scene *scene,
|
|
|
|
struct Object *object,
|
|
|
|
int direction);
|
2020-03-03 12:35:51 +01:00
|
|
|
void multiresModifier_base_apply(struct Depsgraph *depsgraph,
|
|
|
|
struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd);
|
2020-04-30 16:47:23 +02:00
|
|
|
int multiresModifier_rebuild_subdiv(struct Depsgraph *depsgraph,
|
|
|
|
struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd,
|
|
|
|
int rebuild_limit,
|
|
|
|
bool switch_view_to_lower_level);
|
2020-03-03 12:35:51 +01:00
|
|
|
void multiresModifier_sync_levels_ex(struct Object *ob_dst,
|
2018-06-18 11:21:33 +02:00
|
|
|
struct MultiresModifierData *mmd_src,
|
|
|
|
struct MultiresModifierData *mmd_dst);
|
2009-01-06 18:59:03 +00:00
|
|
|
|
2009-12-09 13:37:19 +00:00
|
|
|
void multires_stitch_grids(struct Object *);
|
|
|
|
|
2018-04-06 12:07:27 +02:00
|
|
|
void multiresModifier_scale_disp(struct Depsgraph *depsgraph,
|
|
|
|
struct Scene *scene,
|
|
|
|
struct Object *ob);
|
|
|
|
void multiresModifier_prepare_join(struct Depsgraph *depsgraph,
|
|
|
|
struct Scene *scene,
|
|
|
|
struct Object *ob,
|
|
|
|
struct Object *to_ob);
|
2010-10-25 08:03:05 +00:00
|
|
|
|
2010-11-04 16:00:28 +00:00
|
|
|
int multires_mdisp_corners(struct MDisps *s);
|
|
|
|
|
|
|
|
/* update multires data after topology changing */
|
2012-04-16 11:03:42 +00:00
|
|
|
void multires_topology_changed(struct Mesh *me);
|
2010-11-04 16:00:28 +00:00
|
|
|
|
2020-03-13 16:13:32 +01:00
|
|
|
void multires_ensure_external_read(struct Mesh *mesh, int top_level);
|
|
|
|
void multiresModifier_ensure_external_read(struct Mesh *mesh,
|
|
|
|
const struct MultiresModifierData *mmd);
|
|
|
|
|
2011-01-02 16:43:28 +00:00
|
|
|
/**** interpolation stuff ****/
|
2011-02-12 10:18:21 +00:00
|
|
|
void old_mdisps_bilinear(float out[3], float (*disps)[3], const int st, float u, float v);
|
2015-07-30 14:43:58 +02:00
|
|
|
int mdisp_rot_face_to_crn(struct MVert *mvert,
|
|
|
|
struct MPoly *mpoly,
|
2020-09-04 20:59:13 +02:00
|
|
|
struct MLoop *mloop,
|
2015-07-30 14:43:58 +02:00
|
|
|
const struct MLoopTri *lt,
|
|
|
|
const int face_side,
|
|
|
|
const float u,
|
|
|
|
const float v,
|
|
|
|
float *x,
|
|
|
|
float *y);
|
2011-01-02 16:43:28 +00:00
|
|
|
|
2018-08-21 15:40:23 +02:00
|
|
|
/* Reshaping, define in multires_reshape.c */
|
|
|
|
|
2020-03-03 12:35:51 +01:00
|
|
|
bool multiresModifier_reshapeFromVertcos(struct Depsgraph *depsgraph,
|
|
|
|
struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd,
|
|
|
|
const float (*vert_coords)[3],
|
|
|
|
const int num_vert_coords);
|
2018-09-12 16:30:33 +02:00
|
|
|
bool multiresModifier_reshapeFromObject(struct Depsgraph *depsgraph,
|
2018-08-22 16:49:05 +02:00
|
|
|
struct MultiresModifierData *mmd,
|
|
|
|
struct Object *dst,
|
|
|
|
struct Object *src);
|
2018-08-21 15:40:23 +02:00
|
|
|
bool multiresModifier_reshapeFromDeformModifier(struct Depsgraph *depsgraph,
|
2018-08-22 15:45:19 +02:00
|
|
|
struct Object *ob,
|
2020-03-03 12:35:51 +01:00
|
|
|
struct MultiresModifierData *mmd,
|
|
|
|
struct ModifierData *deform_md);
|
2018-09-14 10:56:54 +02:00
|
|
|
bool multiresModifier_reshapeFromCCG(const int tot_level,
|
2018-09-24 16:59:27 +02:00
|
|
|
struct Mesh *coarse_mesh,
|
2018-09-14 10:56:54 +02:00
|
|
|
struct SubdivCCG *subdiv_ccg);
|
2018-08-21 15:40:23 +02:00
|
|
|
|
2020-03-03 12:35:51 +01:00
|
|
|
/* Subdivide multires displacement once. */
|
2020-04-30 15:15:19 +02:00
|
|
|
|
|
|
|
typedef enum eMultiresSubdivideModeType {
|
|
|
|
MULTIRES_SUBDIVIDE_CATMULL_CLARK,
|
|
|
|
MULTIRES_SUBDIVIDE_SIMPLE,
|
|
|
|
MULTIRES_SUBDIVIDE_LINEAR,
|
|
|
|
} eMultiresSubdivideModeType;
|
|
|
|
|
|
|
|
void multiresModifier_subdivide(struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd,
|
|
|
|
const eMultiresSubdivideModeType mode);
|
|
|
|
void multires_subdivide_create_tangent_displacement_linear_grids(struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd);
|
2020-03-03 12:35:51 +01:00
|
|
|
|
|
|
|
/* Subdivide displacement to the given level.
|
|
|
|
* If level is lower than the current top level nothing happens. */
|
|
|
|
void multiresModifier_subdivide_to_level(struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd,
|
2020-04-30 15:15:19 +02:00
|
|
|
const int top_level,
|
|
|
|
const eMultiresSubdivideModeType mode);
|
2020-03-03 12:35:51 +01:00
|
|
|
|
2018-08-21 15:40:23 +02:00
|
|
|
/* Subdivision integration, defined in multires_subdiv.c */
|
|
|
|
|
|
|
|
struct SubdivSettings;
|
|
|
|
struct SubdivToMeshSettings;
|
|
|
|
|
|
|
|
void BKE_multires_subdiv_settings_init(struct SubdivSettings *settings,
|
|
|
|
const struct MultiresModifierData *mmd);
|
|
|
|
|
2018-08-22 16:07:39 +02:00
|
|
|
/* TODO(sergey): Replace this set of boolean flags with bitmask. */
|
2018-08-21 15:40:23 +02:00
|
|
|
void BKE_multires_subdiv_mesh_settings_init(struct SubdivToMeshSettings *mesh_settings,
|
|
|
|
const struct Scene *scene,
|
|
|
|
const struct Object *object,
|
|
|
|
const struct MultiresModifierData *mmd,
|
2018-08-22 16:07:39 +02:00
|
|
|
const bool use_render_params,
|
2020-03-26 14:36:39 +01:00
|
|
|
const bool ignore_simplify,
|
|
|
|
const bool ignore_control_edges);
|
2018-08-21 15:40:23 +02:00
|
|
|
|
2018-11-01 15:12:54 +01:00
|
|
|
/* General helpers. */
|
|
|
|
|
|
|
|
/* For a given partial derivatives of a ptex face get tangent matrix for
|
|
|
|
* displacement.
|
2019-01-17 12:06:26 +01:00
|
|
|
*
|
|
|
|
* Corner needs to be known to properly "rotate" partial derivatives when the
|
|
|
|
* matrix is being constructed for quad. For non-quad the corner is to be set
|
|
|
|
* to 0. */
|
2018-11-01 15:12:54 +01:00
|
|
|
BLI_INLINE void BKE_multires_construct_tangent_matrix(float tangent_matrix[3][3],
|
|
|
|
const float dPdu[3],
|
|
|
|
const float dPdv[3],
|
|
|
|
const int corner);
|
|
|
|
|
2020-10-26 12:32:22 +01:00
|
|
|
/* Versioning. */
|
|
|
|
|
|
|
|
/* Convert displacement which is stored for simply-subdivided mesh to a Catmull-Clark
|
|
|
|
* subdivided mesh. */
|
|
|
|
void multires_do_versions_simple_to_catmull_clark(struct Object *object,
|
|
|
|
struct MultiresModifierData *mmd);
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-01 15:12:54 +01:00
|
|
|
#include "intern/multires_inline.h"
|