2011-02-18 13:05:18 +00:00
|
|
|
/*
|
2008-04-25 18:22:20 +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
|
|
|
|
* 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.
|
2008-04-25 18:22:20 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2008-04-25 18:22:20 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup bke
|
2011-02-18 13:05:18 +00:00
|
|
|
*/
|
|
|
|
|
2008-07-18 22:24:20 +00:00
|
|
|
/* Shrinkwrap stuff */
|
2008-08-07 15:18:47 +00:00
|
|
|
#include "BKE_bvhutils.h"
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
#include "BLI_bitmap.h"
|
2008-08-07 15:18:47 +00:00
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2008-08-12 20:43:10 +00:00
|
|
|
/*
|
|
|
|
* Shrinkwrap is composed by a set of functions and options that define the type of shrink.
|
|
|
|
*
|
|
|
|
* 3 modes are available:
|
2018-11-14 12:53:15 +11:00
|
|
|
* - Nearest vertex
|
|
|
|
* - Nearest surface
|
|
|
|
* - Normal projection
|
2008-08-12 20:43:10 +00:00
|
|
|
*
|
|
|
|
* ShrinkwrapCalcData encapsulates all needed data for shrinkwrap functions.
|
2012-03-18 07:38:51 +00:00
|
|
|
* (So that you don't have to pass an enormous amount of arguments to functions)
|
2008-08-12 20:43:10 +00:00
|
|
|
*/
|
|
|
|
|
2019-01-28 21:08:24 +11:00
|
|
|
struct BVHTree;
|
2009-04-20 15:06:46 +00:00
|
|
|
struct MDeformVert;
|
2019-01-28 21:08:24 +11:00
|
|
|
struct Mesh;
|
2018-05-09 12:51:03 +02:00
|
|
|
struct ModifierEvalContext;
|
2019-01-28 21:08:24 +11:00
|
|
|
struct Object;
|
2008-04-25 18:22:20 +00:00
|
|
|
struct ShrinkwrapModifierData;
|
2014-08-01 16:28:31 +02:00
|
|
|
struct SpaceTransform;
|
2008-04-25 18:22:20 +00:00
|
|
|
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
/* Information about boundary edges in the mesh. */
|
|
|
|
typedef struct ShrinkwrapBoundaryVertData {
|
|
|
|
/* Average direction of edges that meet here. */
|
|
|
|
float direction[3];
|
|
|
|
|
|
|
|
/* Closest vector to direction that is orthogonal to vertex normal. */
|
|
|
|
float normal_plane[3];
|
|
|
|
} ShrinkwrapBoundaryVertData;
|
|
|
|
|
|
|
|
typedef struct ShrinkwrapBoundaryData {
|
|
|
|
/* True if the edge belongs to exactly one face. */
|
|
|
|
const BLI_bitmap *edge_is_boundary;
|
|
|
|
/* True if the looptri has any boundary edges. */
|
|
|
|
const BLI_bitmap *looptri_has_boundary;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
/* Mapping from vertex index to boundary vertex index, or -1.
|
|
|
|
* Used for compact storage of data about boundary vertices. */
|
|
|
|
const int *vert_boundary_id;
|
|
|
|
unsigned int num_boundary_verts;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
/* Direction data about boundary vertices. */
|
|
|
|
const ShrinkwrapBoundaryVertData *boundary_verts;
|
|
|
|
} ShrinkwrapBoundaryData;
|
|
|
|
|
|
|
|
void BKE_shrinkwrap_discard_boundary_data(struct Mesh *mesh);
|
|
|
|
void BKE_shrinkwrap_compute_boundary_data(struct Mesh *mesh);
|
|
|
|
|
|
|
|
/* Information about a mesh and BVH tree. */
|
2018-10-03 19:09:43 +03:00
|
|
|
typedef struct ShrinkwrapTreeData {
|
|
|
|
Mesh *mesh;
|
2008-05-07 12:45:02 +00:00
|
|
|
|
2018-10-03 19:09:43 +03:00
|
|
|
BVHTree *bvh;
|
|
|
|
BVHTreeFromMesh treeData;
|
2008-04-30 17:55:26 +00:00
|
|
|
|
2018-12-05 20:24:05 +03:00
|
|
|
float (*pnors)[3];
|
2018-10-03 19:09:43 +03:00
|
|
|
float (*clnors)[3];
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
ShrinkwrapBoundaryData *boundary;
|
2018-10-03 19:09:43 +03:00
|
|
|
} ShrinkwrapTreeData;
|
2008-07-22 11:50:50 +00:00
|
|
|
|
2018-10-03 19:09:43 +03:00
|
|
|
/* Checks if the modifier needs target normals with these settings. */
|
|
|
|
bool BKE_shrinkwrap_needs_normals(int shrinkType, int shrinkMode);
|
2008-04-30 17:55:26 +00:00
|
|
|
|
2018-10-03 19:09:43 +03:00
|
|
|
/* Initializes the mesh data structure from the given mesh and settings. */
|
|
|
|
bool BKE_shrinkwrap_init_tree(struct ShrinkwrapTreeData *data,
|
|
|
|
Mesh *mesh,
|
|
|
|
int shrinkType,
|
|
|
|
int shrinkMode,
|
|
|
|
bool force_normals);
|
2008-11-03 23:17:36 +00:00
|
|
|
|
2018-10-03 19:09:43 +03:00
|
|
|
/* Frees the tree data if necessary. */
|
|
|
|
void BKE_shrinkwrap_free_tree(struct ShrinkwrapTreeData *data);
|
2008-04-30 17:55:26 +00:00
|
|
|
|
2018-10-03 19:09:43 +03:00
|
|
|
/* Implementation of the Shrinkwrap modifier */
|
2018-12-07 15:45:53 +01:00
|
|
|
void shrinkwrapModifier_deform(struct ShrinkwrapModifierData *smd,
|
|
|
|
const struct ModifierEvalContext *ctx,
|
|
|
|
struct Scene *scene,
|
|
|
|
struct Object *ob,
|
|
|
|
struct Mesh *mesh,
|
2018-11-26 20:43:35 +01:00
|
|
|
struct MDeformVert *dvert,
|
|
|
|
const int defgrp_index,
|
|
|
|
float (*vertexCos)[3],
|
|
|
|
int numVerts);
|
2008-08-12 20:43:10 +00:00
|
|
|
|
2019-09-10 15:18:51 +02:00
|
|
|
/* Used in editmesh_mask_extract.c to shrinkwrap the extracted mesh to the sculpt */
|
|
|
|
void BKE_shrinkwrap_mesh_nearest_surface_deform(struct bContext *C,
|
|
|
|
struct Object *ob_source,
|
|
|
|
struct Object *ob_target);
|
|
|
|
|
2019-09-26 16:28:56 +02:00
|
|
|
/* Used in object_remesh.c to preserve the details and volume in the voxel remesher */
|
|
|
|
void BKE_shrinkwrap_remesh_target_project(struct Mesh *src_me,
|
|
|
|
struct Mesh *target_me,
|
|
|
|
struct Object *ob_target);
|
|
|
|
|
2008-08-12 20:43:10 +00:00
|
|
|
/*
|
2019-04-27 12:07:07 +10:00
|
|
|
* This function casts a ray in the given BVHTree.
|
|
|
|
* but it takes into consideration the space_transform, that is:
|
2008-08-12 20:43:10 +00:00
|
|
|
*
|
2012-09-06 01:31:15 +00:00
|
|
|
* if transf was configured with "SPACE_TRANSFORM_SETUP( &transf, ob1, ob2 )"
|
2008-08-12 20:43:10 +00:00
|
|
|
* then the input (vert, dir, BVHTreeRayHit) must be defined in ob1 coordinates space
|
|
|
|
* and the BVHTree must be built in ob2 coordinate space.
|
|
|
|
*
|
2012-12-23 01:18:35 +00:00
|
|
|
* Thus it provides an easy way to cast the same ray across several trees
|
|
|
|
* (where each tree was built on its own coords space)
|
2008-08-12 20:43:10 +00:00
|
|
|
*/
|
2014-03-20 22:56:28 +11:00
|
|
|
bool BKE_shrinkwrap_project_normal(char options,
|
2018-05-04 07:39:07 -03:00
|
|
|
const float vert[3],
|
|
|
|
const float dir[3],
|
|
|
|
const float ray_radius,
|
2018-10-03 19:09:43 +03:00
|
|
|
const struct SpaceTransform *transf,
|
|
|
|
struct ShrinkwrapTreeData *tree,
|
|
|
|
BVHTreeRayHit *hit);
|
|
|
|
|
2019-04-27 12:07:07 +10:00
|
|
|
/* Maps the point to the nearest surface, either by simple nearest,
|
|
|
|
* or by target normal projection. */
|
Shrinkwrap: new mode that projects along the target normal.
The Nearest Surface Point shrink method, while fast, is neither
smooth nor continuous: as the source point moves, the projected
point can both stop and jump. This causes distortions in the
deformation of the shrinkwrap modifier, and the motion of an
animated object with a shrinkwrap constraint.
This patch implements a new mode, which, instead of using the simple
nearest point search, iteratively solves an equation for each triangle
to find a point which has its interpolated normal point to or from the
original vertex. Non-manifold boundary edges are treated as infinitely
thin cylinders that cast normals in all perpendicular directions.
Since this is useful for the constraint, and having multiple
objects with constraints targeting the same guide mesh is a quite
reasonable use case, rather than calculating the mesh boundary edge
data over and over again, it is precomputed and cached in the mesh.
Reviewers: mont29
Differential Revision: https://developer.blender.org/D3836
2018-11-06 21:04:53 +03:00
|
|
|
void BKE_shrinkwrap_find_nearest_surface(struct ShrinkwrapTreeData *tree,
|
|
|
|
struct BVHTreeNearest *nearest,
|
|
|
|
float co[3],
|
|
|
|
int type);
|
|
|
|
|
2018-10-03 19:09:43 +03:00
|
|
|
/* Computes a smooth normal of the target (if applicable) at the hit location. */
|
|
|
|
void BKE_shrinkwrap_compute_smooth_normal(const struct ShrinkwrapTreeData *tree,
|
|
|
|
const struct SpaceTransform *transform,
|
|
|
|
int looptri_idx,
|
|
|
|
const float hit_co[3],
|
|
|
|
const float hit_no[3],
|
|
|
|
float r_no[3]);
|
2008-08-12 20:43:10 +00:00
|
|
|
|
2018-07-07 18:39:45 +03:00
|
|
|
/* Apply the shrink to surface modes to the given original coordinates and nearest point. */
|
|
|
|
void BKE_shrinkwrap_snap_point_to_surface(const struct ShrinkwrapTreeData *tree,
|
2018-10-03 19:09:43 +03:00
|
|
|
const struct SpaceTransform *transform,
|
|
|
|
int mode,
|
|
|
|
int hit_idx,
|
|
|
|
const float hit_co[3],
|
|
|
|
const float hit_no[3],
|
|
|
|
float goal_dist,
|
2018-07-07 18:39:45 +03:00
|
|
|
const float point_co[3],
|
|
|
|
float r_point_co[3]);
|
|
|
|
|
2008-08-12 20:43:10 +00:00
|
|
|
/*
|
2020-03-11 21:39:56 +11:00
|
|
|
* NULL initializes to local data
|
2008-08-12 20:43:10 +00:00
|
|
|
*/
|
2012-05-12 20:39:39 +00:00
|
|
|
#define NULL_ShrinkwrapCalcData \
|
|
|
|
{ \
|
|
|
|
NULL, \
|
|
|
|
}
|
|
|
|
#define NULL_BVHTreeFromMesh \
|
|
|
|
{ \
|
|
|
|
NULL, \
|
|
|
|
}
|
|
|
|
#define NULL_BVHTreeRayHit \
|
|
|
|
{ \
|
|
|
|
NULL, \
|
|
|
|
}
|
|
|
|
#define NULL_BVHTreeNearest \
|
2019-04-17 06:17:24 +02:00
|
|
|
{ \
|
2012-05-12 20:39:39 +00:00
|
|
|
0, \
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-02 15:07:49 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|