2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52: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,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
* \ingroup modifiers
|
2011-12-29 04:04:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2019-02-25 11:56:24 +01:00
|
|
|
#include "BLI_math.h"
|
|
|
|
|
2018-04-25 12:21:07 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2010-08-04 04:01:27 +00:00
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-03 15:42:55 +02:00
|
|
|
#include "BKE_library.h"
|
2015-10-08 14:21:11 +02:00
|
|
|
#include "BKE_library_query.h"
|
2018-04-25 12:21:07 +02:00
|
|
|
#include "BKE_mesh.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
#include "BKE_deform.h"
|
2012-10-24 07:24:11 +00:00
|
|
|
|
2018-11-21 10:01:04 +11:00
|
|
|
#include "bmesh.h"
|
|
|
|
#include "bmesh_tools.h"
|
|
|
|
|
2011-12-29 04:04:27 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
|
|
|
|
#include "DEG_depsgraph_build.h"
|
2018-12-07 15:45:53 +01:00
|
|
|
#include "DEG_depsgraph_query.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2017-08-01 09:06:34 +10:00
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MirrorModifierData *mmd = (MirrorModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
mmd->flag |= (MOD_MIR_AXIS_X | MOD_MIR_VGROUP);
|
|
|
|
mmd->tolerance = 0.001;
|
|
|
|
mmd->mirror_ob = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-05 15:57:10 +02:00
|
|
|
static void foreachObjectLink(
|
|
|
|
ModifierData *md, Object *ob,
|
|
|
|
ObjectWalkFunc walk, void *userData)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
MirrorModifierData *mmd = (MirrorModifierData *) md;
|
2011-12-29 04:04:27 +00:00
|
|
|
|
2017-01-31 09:47:59 +01:00
|
|
|
walk(userData, ob, &mmd->mirror_ob, IDWALK_CB_NOP);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 12:54:06 +01:00
|
|
|
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
{
|
|
|
|
MirrorModifierData *mmd = (MirrorModifierData *)md;
|
|
|
|
if (mmd->mirror_ob != NULL) {
|
2018-02-22 12:54:06 +01:00
|
|
|
DEG_add_object_relation(ctx->node, mmd->mirror_ob, DEG_OB_COMP_TRANSFORM, "Mirror Modifier");
|
2019-02-12 12:01:17 +01:00
|
|
|
DEG_add_modifier_to_transform_relation(ctx->node, "Mirror Modifier");
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:01:04 +11:00
|
|
|
static Mesh *doBiscetOnMirrorPlane(
|
2018-05-12 08:04:56 +02:00
|
|
|
MirrorModifierData *mmd,
|
2018-05-12 08:21:07 +02:00
|
|
|
const Mesh *mesh,
|
2018-11-21 10:01:04 +11:00
|
|
|
int axis,
|
2019-01-09 11:36:00 +01:00
|
|
|
float plane_co[3],
|
|
|
|
float plane_no[3])
|
2018-11-21 10:01:04 +11:00
|
|
|
{
|
2018-11-21 10:27:19 +11:00
|
|
|
bool do_bisect_flip_axis = (
|
|
|
|
(axis == 0 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_X) ||
|
|
|
|
(axis == 1 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_Y) ||
|
|
|
|
(axis == 2 && mmd->flag & MOD_MIR_BISECT_FLIP_AXIS_Z));
|
2018-11-21 10:01:04 +11:00
|
|
|
|
2019-01-09 11:36:00 +01:00
|
|
|
const float bisect_distance = 0.001f;
|
2018-11-21 10:01:04 +11:00
|
|
|
|
|
|
|
Mesh *result;
|
|
|
|
BMesh *bm;
|
|
|
|
BMIter viter;
|
|
|
|
BMVert *v, *v_next;
|
|
|
|
|
|
|
|
bm = BKE_mesh_to_bmesh_ex(
|
2019-03-08 17:16:30 +11:00
|
|
|
mesh,
|
|
|
|
&(struct BMeshCreateParams){0},
|
|
|
|
&(struct BMeshFromMeshParams){
|
|
|
|
.calc_face_normal = true,
|
|
|
|
.cd_mask_extra = {.vmask = CD_MASK_ORIGINDEX, .emask = CD_MASK_ORIGINDEX, .pmask = CD_MASK_ORIGINDEX},
|
|
|
|
});
|
2018-11-21 10:01:04 +11:00
|
|
|
|
2019-01-09 11:36:00 +01:00
|
|
|
/* Define bisecting plane (aka mirror plane). */
|
2018-11-21 10:01:04 +11:00
|
|
|
float plane[4];
|
2019-01-09 11:36:00 +01:00
|
|
|
if (!do_bisect_flip_axis) {
|
|
|
|
/* That reversed condition is a tad weird, but for some reason that's how you keep
|
|
|
|
* the part of the mesh which is on the non-mirrored side when flip option is disabled,
|
|
|
|
* think that that is the expected behavior. */
|
|
|
|
negate_v3(plane_no);
|
2018-11-21 10:01:04 +11:00
|
|
|
}
|
|
|
|
plane_from_point_normal_v3(plane, plane_co, plane_no);
|
|
|
|
|
|
|
|
BM_mesh_bisect_plane(bm, plane, false, false, 0, 0, bisect_distance);
|
|
|
|
|
|
|
|
/* Plane definitions for vert killing. */
|
|
|
|
float plane_offset[4];
|
|
|
|
copy_v3_v3(plane_offset, plane);
|
|
|
|
plane_offset[3] = plane[3] - bisect_distance;
|
|
|
|
|
|
|
|
/* Delete verts across the mirror plane. */
|
|
|
|
BM_ITER_MESH_MUTABLE(v, v_next, &viter, bm, BM_VERTS_OF_MESH) {
|
|
|
|
if (plane_point_side_v3(plane_offset, v->co) > 0.0f) {
|
|
|
|
BM_vert_kill(bm, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, NULL);
|
2018-11-21 10:01:04 +11:00
|
|
|
BM_mesh_free(bm);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Mesh *doMirrorOnAxis(
|
|
|
|
MirrorModifierData *mmd,
|
2018-12-07 15:45:53 +01:00
|
|
|
const ModifierEvalContext *ctx,
|
2018-11-21 10:01:04 +11:00
|
|
|
Object *ob,
|
|
|
|
const Mesh *mesh,
|
|
|
|
int axis)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-01-03 13:57:31 +00:00
|
|
|
const float tolerance_sq = mmd->tolerance * mmd->tolerance;
|
2015-04-22 07:54:14 +02:00
|
|
|
const bool do_vtargetmap = (mmd->flag & MOD_MIR_NO_MERGE) == 0;
|
2013-05-27 20:11:12 +00:00
|
|
|
int tot_vtargetmap = 0; /* total merge vertices */
|
2012-01-03 13:57:31 +00:00
|
|
|
|
2018-11-21 10:01:04 +11:00
|
|
|
const bool do_bisect = (
|
|
|
|
(axis == 0 && mmd->flag & MOD_MIR_BISECT_AXIS_X) ||
|
|
|
|
(axis == 1 && mmd->flag & MOD_MIR_BISECT_AXIS_Y) ||
|
|
|
|
(axis == 2 && mmd->flag & MOD_MIR_BISECT_AXIS_Z));
|
|
|
|
|
2018-04-25 12:21:07 +02:00
|
|
|
Mesh *result;
|
2012-01-03 13:57:31 +00:00
|
|
|
MVert *mv, *mv_prev;
|
2012-11-21 10:53:15 +00:00
|
|
|
MEdge *me;
|
2011-02-27 07:49:36 +00:00
|
|
|
MLoop *ml;
|
|
|
|
MPoly *mp;
|
2011-05-13 13:17:30 +00:00
|
|
|
float mtx[4][4];
|
2019-01-09 11:36:00 +01:00
|
|
|
float plane_co[3], plane_no[3];
|
2013-03-23 17:11:03 +00:00
|
|
|
int i;
|
2011-12-29 09:15:06 +00:00
|
|
|
int a, totshape;
|
2012-05-02 16:17:04 +00:00
|
|
|
int *vtargetmap = NULL, *vtmap_a = NULL, *vtmap_b = NULL;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* mtx is the mirror transformation */
|
2011-09-16 04:14:46 +00:00
|
|
|
unit_m4(mtx);
|
2012-01-03 13:57:31 +00:00
|
|
|
mtx[axis][axis] = -1.0f;
|
2010-07-19 04:44:37 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
Object *mirror_ob = DEG_get_evaluated_object(ctx->depsgraph, mmd->mirror_ob);
|
|
|
|
if (mirror_ob != NULL) {
|
2011-09-16 04:14:46 +00:00
|
|
|
float tmp[4][4];
|
|
|
|
float itmp[4][4];
|
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* tmp is a transform from coords relative to the object's own origin,
|
|
|
|
* to coords relative to the mirror object origin */
|
2018-12-07 15:45:53 +01:00
|
|
|
invert_m4_m4(tmp, mirror_ob->obmat);
|
2013-05-26 18:36:25 +00:00
|
|
|
mul_m4_m4m4(tmp, tmp, ob->obmat);
|
2011-09-16 04:14:46 +00:00
|
|
|
|
2012-03-08 04:12:11 +00:00
|
|
|
/* itmp is the reverse transform back to origin-relative coordinates */
|
2011-09-16 04:14:46 +00:00
|
|
|
invert_m4_m4(itmp, tmp);
|
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* combine matrices to get a single matrix that translates coordinates into
|
|
|
|
* mirror-object-relative space, does the mirror, and translates back to
|
|
|
|
* origin-relative space */
|
2019-01-09 11:36:00 +01:00
|
|
|
mul_m4_series(mtx, itmp, mtx, tmp);
|
2012-01-03 13:57:31 +00:00
|
|
|
|
2019-01-09 11:36:00 +01:00
|
|
|
if (do_bisect) {
|
|
|
|
copy_v3_v3(plane_co, itmp[3]);
|
|
|
|
copy_v3_v3(plane_no, itmp[axis]);
|
|
|
|
}
|
|
|
|
}
|
2019-01-15 08:47:04 +11:00
|
|
|
else if (do_bisect) {
|
2019-01-09 11:36:00 +01:00
|
|
|
copy_v3_v3(plane_co, mtx[3]);
|
|
|
|
/* Need to negate here, since that axis is inverted (for mirror transform). */
|
|
|
|
negate_v3_v3(plane_no, mtx[axis]);
|
|
|
|
}
|
2018-11-21 10:01:04 +11:00
|
|
|
|
|
|
|
Mesh *mesh_bisect = NULL;
|
|
|
|
if (do_bisect) {
|
2019-01-09 11:36:00 +01:00
|
|
|
mesh_bisect = doBiscetOnMirrorPlane(mmd, mesh, axis, plane_co, plane_no);
|
2018-11-21 10:01:04 +11:00
|
|
|
mesh = mesh_bisect;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int maxVerts = mesh->totvert;
|
|
|
|
const int maxEdges = mesh->totedge;
|
|
|
|
const int maxLoops = mesh->totloop;
|
|
|
|
const int maxPolys = mesh->totpoly;
|
|
|
|
|
2018-05-08 17:06:30 +02:00
|
|
|
result = BKE_mesh_new_nomain_from_template(
|
|
|
|
mesh, maxVerts * 2, maxEdges * 2, 0, maxLoops * 2, maxPolys * 2);
|
2012-01-03 13:57:31 +00:00
|
|
|
|
2011-02-27 07:49:36 +00:00
|
|
|
/*copy customdata to original geometry*/
|
2018-04-25 12:21:07 +02:00
|
|
|
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, maxVerts);
|
|
|
|
CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, maxEdges);
|
|
|
|
CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, maxLoops);
|
|
|
|
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, maxPolys);
|
2012-01-03 13:57:31 +00:00
|
|
|
|
2018-09-03 16:49:08 +02:00
|
|
|
/* Subsurf for eg won't have mesh data in the custom data arrays.
|
2018-04-25 12:25:47 +02:00
|
|
|
* now add mvert/medge/mpoly layers. */
|
2018-04-25 12:21:07 +02:00
|
|
|
if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
|
|
|
|
memcpy(result->mvert, mesh->mvert, sizeof(*result->mvert) * mesh->totvert);
|
2012-01-03 13:57:31 +00:00
|
|
|
}
|
2018-04-25 12:21:07 +02:00
|
|
|
if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
|
|
|
|
memcpy(result->medge, mesh->medge, sizeof(*result->medge) * mesh->totedge);
|
2012-01-03 13:57:31 +00:00
|
|
|
}
|
2018-04-25 12:21:07 +02:00
|
|
|
if (!CustomData_has_layer(&mesh->pdata, CD_MPOLY)) {
|
|
|
|
memcpy(result->mloop, mesh->mloop, sizeof(*result->mloop) * mesh->totloop);
|
|
|
|
memcpy(result->mpoly, mesh->mpoly, sizeof(*result->mpoly) * mesh->totpoly);
|
2012-01-03 13:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy customdata to new geometry,
|
2012-03-18 07:38:51 +00:00
|
|
|
* copy from its self because this data may have been created in the checks above */
|
2018-04-25 12:21:07 +02:00
|
|
|
CustomData_copy_data(&result->vdata, &result->vdata, 0, maxVerts, maxVerts);
|
|
|
|
CustomData_copy_data(&result->edata, &result->edata, 0, maxEdges, maxEdges);
|
2012-01-03 13:57:31 +00:00
|
|
|
/* loops are copied later */
|
2018-04-25 12:21:07 +02:00
|
|
|
CustomData_copy_data(&result->pdata, &result->pdata, 0, maxPolys, maxPolys);
|
2011-12-29 09:15:06 +00:00
|
|
|
|
|
|
|
if (do_vtargetmap) {
|
|
|
|
/* second half is filled with -1 */
|
2018-01-14 22:14:20 +01:00
|
|
|
vtargetmap = MEM_malloc_arrayN(maxVerts, 2 * sizeof(int), "MOD_mirror tarmap");
|
2011-12-29 09:15:06 +00:00
|
|
|
|
|
|
|
vtmap_a = vtargetmap;
|
2012-01-03 13:57:31 +00:00
|
|
|
vtmap_b = vtargetmap + maxVerts;
|
2011-12-29 09:15:06 +00:00
|
|
|
}
|
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* mirror vertex coordinates */
|
2018-04-25 12:21:07 +02:00
|
|
|
mv_prev = result->mvert;
|
2012-01-03 13:57:31 +00:00
|
|
|
mv = mv_prev + maxVerts;
|
|
|
|
for (i = 0; i < maxVerts; i++, mv++, mv_prev++) {
|
2011-09-16 04:14:46 +00:00
|
|
|
mul_m4_v3(mtx, mv->co);
|
2011-12-29 09:15:06 +00:00
|
|
|
|
|
|
|
if (do_vtargetmap) {
|
|
|
|
/* compare location of the original and mirrored vertex, to see if they
|
|
|
|
* should be mapped for merging */
|
2012-01-03 14:02:51 +00:00
|
|
|
if (UNLIKELY(len_squared_v3v3(mv_prev->co, mv->co) < tolerance_sq)) {
|
|
|
|
*vtmap_a = maxVerts + i;
|
2013-05-27 20:11:12 +00:00
|
|
|
tot_vtargetmap++;
|
2013-12-18 11:14:24 +01:00
|
|
|
|
|
|
|
/* average location */
|
|
|
|
mid_v3_v3v3(mv->co, mv_prev->co, mv->co);
|
|
|
|
copy_v3_v3(mv_prev->co, mv->co);
|
2012-01-03 14:02:51 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*vtmap_a = -1;
|
|
|
|
}
|
|
|
|
|
2011-12-29 09:15:06 +00:00
|
|
|
*vtmap_b = -1; /* fill here to avoid 2x loops */
|
|
|
|
|
|
|
|
vtmap_a++;
|
|
|
|
vtmap_b++;
|
2011-09-16 04:14:46 +00:00
|
|
|
}
|
2011-02-27 07:49:36 +00:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* handle shape keys */
|
2018-04-25 12:21:07 +02:00
|
|
|
totshape = CustomData_number_of_layers(&result->vdata, CD_SHAPEKEY);
|
2012-01-03 13:57:31 +00:00
|
|
|
for (a = 0; a < totshape; a++) {
|
2018-04-25 12:21:07 +02:00
|
|
|
float (*cos)[3] = CustomData_get_layer_n(&result->vdata, CD_SHAPEKEY, a);
|
|
|
|
for (i = maxVerts; i < result->totvert; i++) {
|
2011-09-16 04:14:46 +00:00
|
|
|
mul_m4_v3(mtx, cos[i]);
|
2011-04-15 05:20:18 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-11-21 10:53:15 +00:00
|
|
|
/* adjust mirrored edge vertex indices */
|
2018-04-25 12:21:07 +02:00
|
|
|
me = result->medge + maxEdges;
|
2012-11-21 10:53:15 +00:00
|
|
|
for (i = 0; i < maxEdges; i++, me++) {
|
2012-01-03 13:57:31 +00:00
|
|
|
me->v1 += maxVerts;
|
|
|
|
me->v2 += maxVerts;
|
2011-02-27 07:49:36 +00:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* adjust mirrored poly loopstart indices, and reverse loop order (normals) */
|
2018-04-25 12:21:07 +02:00
|
|
|
mp = result->mpoly + maxPolys;
|
|
|
|
ml = result->mloop;
|
2012-01-03 13:57:31 +00:00
|
|
|
for (i = 0; i < maxPolys; i++, mp++) {
|
2011-03-31 00:06:19 +00:00
|
|
|
MLoop *ml2;
|
2013-03-23 17:11:03 +00:00
|
|
|
int j, e;
|
2012-01-03 13:57:31 +00:00
|
|
|
|
2012-05-02 16:17:04 +00:00
|
|
|
/* reverse the loop, but we keep the first vertex in the face the same,
|
|
|
|
* to ensure that quads are split the same way as on the other side */
|
2018-04-25 12:21:07 +02:00
|
|
|
CustomData_copy_data(&result->ldata, &result->ldata, mp->loopstart, mp->loopstart + maxLoops, 1);
|
|
|
|
|
2012-05-02 16:17:04 +00:00
|
|
|
for (j = 1; j < mp->totloop; j++)
|
2018-04-25 12:21:07 +02:00
|
|
|
CustomData_copy_data(&result->ldata, &result->ldata,
|
|
|
|
mp->loopstart + j,
|
|
|
|
mp->loopstart + maxLoops + mp->totloop - j,
|
|
|
|
1);
|
2012-01-03 13:57:31 +00:00
|
|
|
|
|
|
|
ml2 = ml + mp->loopstart + maxLoops;
|
2011-03-31 00:06:19 +00:00
|
|
|
e = ml2[0].e;
|
2012-05-03 21:35:04 +00:00
|
|
|
for (j = 0; j < mp->totloop - 1; j++) {
|
|
|
|
ml2[j].e = ml2[j + 1].e;
|
2011-03-31 00:06:19 +00:00
|
|
|
}
|
2012-05-03 21:35:04 +00:00
|
|
|
ml2[mp->totloop - 1].e = e;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
mp->loopstart += maxLoops;
|
2011-02-27 07:49:36 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* adjust mirrored loop vertex and edge indices */
|
2018-04-25 12:21:07 +02:00
|
|
|
ml = result->mloop + maxLoops;
|
2012-01-03 13:57:31 +00:00
|
|
|
for (i = 0; i < maxLoops; i++, ml++) {
|
|
|
|
ml->v += maxVerts;
|
|
|
|
ml->e += maxEdges;
|
2011-02-27 07:49:36 +00:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-12-29 07:29:44 +00:00
|
|
|
/* handle uvs,
|
|
|
|
* let tessface recalc handle updating the MTFace data */
|
2017-09-25 14:11:27 +10:00
|
|
|
if (mmd->flag & (MOD_MIR_MIRROR_U | MOD_MIR_MIRROR_V) || (is_zero_v2(mmd->uv_offset_copy) == false)) {
|
2013-03-23 17:11:03 +00:00
|
|
|
const bool do_mirr_u = (mmd->flag & MOD_MIR_MIRROR_U) != 0;
|
|
|
|
const bool do_mirr_v = (mmd->flag & MOD_MIR_MIRROR_V) != 0;
|
2011-12-29 07:29:44 +00:00
|
|
|
|
2018-04-25 12:21:07 +02:00
|
|
|
const int totuv = CustomData_number_of_layers(&result->ldata, CD_MLOOPUV);
|
2011-12-29 07:29:44 +00:00
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
for (a = 0; a < totuv; a++) {
|
2018-04-25 12:21:07 +02:00
|
|
|
MLoopUV *dmloopuv = CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, a);
|
2012-01-03 13:57:31 +00:00
|
|
|
int j = maxLoops;
|
2011-12-29 07:29:44 +00:00
|
|
|
dmloopuv += j; /* second set of loops only */
|
2012-05-15 15:02:02 +00:00
|
|
|
for (; j-- > 0; dmloopuv++) {
|
2017-03-30 12:39:51 +11:00
|
|
|
if (do_mirr_u) dmloopuv->uv[0] = 1.0f - dmloopuv->uv[0] + mmd->uv_offset[0];
|
|
|
|
if (do_mirr_v) dmloopuv->uv[1] = 1.0f - dmloopuv->uv[1] + mmd->uv_offset[1];
|
2017-09-25 14:11:27 +10:00
|
|
|
dmloopuv->uv[0] += mmd->uv_offset_copy[0];
|
|
|
|
dmloopuv->uv[1] += mmd->uv_offset_copy[1];
|
2011-12-29 07:29:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-03 13:57:31 +00:00
|
|
|
/* handle vgroup stuff */
|
2018-04-25 12:21:07 +02:00
|
|
|
if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&result->vdata, CD_MDEFORMVERT)) {
|
|
|
|
MDeformVert *dvert = (MDeformVert *) CustomData_get_layer(&result->vdata, CD_MDEFORMVERT) + maxVerts;
|
2012-05-06 13:38:33 +00:00
|
|
|
int *flip_map = NULL, flip_map_len = 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
flip_map = defgroup_flip_map(ob, &flip_map_len, false);
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-02-22 13:15:29 +00:00
|
|
|
if (flip_map) {
|
2012-03-19 21:09:16 +00:00
|
|
|
for (i = 0; i < maxVerts; dvert++, i++) {
|
|
|
|
/* merged vertices get both groups, others get flipped */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (do_vtargetmap && (vtargetmap[i] != -1))
|
2012-03-19 21:09:16 +00:00
|
|
|
defvert_flip_merged(dvert, flip_map, flip_map_len);
|
|
|
|
else
|
|
|
|
defvert_flip(dvert, flip_map, flip_map_len);
|
2012-02-22 13:15:29 +00:00
|
|
|
}
|
2012-01-24 00:26:12 +00:00
|
|
|
|
2012-02-22 13:15:29 +00:00
|
|
|
MEM_freeN(flip_map);
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2011-12-29 09:15:06 +00:00
|
|
|
|
|
|
|
if (do_vtargetmap) {
|
2012-01-24 00:26:12 +00:00
|
|
|
/* slow - so only call if one or more merge verts are found,
|
|
|
|
* users may leave this on and not realize there is nothing to merge - campbell */
|
2013-05-27 20:11:12 +00:00
|
|
|
if (tot_vtargetmap) {
|
2018-04-25 12:21:07 +02:00
|
|
|
result = BKE_mesh_merge_verts(result, vtargetmap, tot_vtargetmap, MESH_MERGE_VERTS_DUMP_IF_MAPPED);
|
2012-01-03 14:02:51 +00:00
|
|
|
}
|
2011-12-29 09:15:06 +00:00
|
|
|
MEM_freeN(vtargetmap);
|
|
|
|
}
|
|
|
|
|
2018-11-21 10:01:04 +11:00
|
|
|
if (mesh_bisect != NULL) {
|
|
|
|
BKE_id_free(NULL, mesh_bisect);
|
|
|
|
}
|
|
|
|
|
2012-01-03 09:37:57 +00:00
|
|
|
return result;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 08:21:07 +02:00
|
|
|
static Mesh *mirrorModifier__doMirror(
|
2018-12-07 15:45:53 +01:00
|
|
|
MirrorModifierData *mmd, const ModifierEvalContext *ctx,
|
2018-05-12 08:21:07 +02:00
|
|
|
Object *ob, Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-04-25 12:21:07 +02:00
|
|
|
Mesh *result = mesh;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* check which axes have been toggled and mirror accordingly */
|
2012-03-24 06:24:53 +00:00
|
|
|
if (mmd->flag & MOD_MIR_AXIS_X) {
|
2018-12-07 15:45:53 +01:00
|
|
|
result = doMirrorOnAxis(mmd, ctx, ob, result, 0);
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
if (mmd->flag & MOD_MIR_AXIS_Y) {
|
2018-04-25 12:21:07 +02:00
|
|
|
Mesh *tmp = result;
|
2018-12-07 15:45:53 +01:00
|
|
|
result = doMirrorOnAxis(mmd, ctx, ob, result, 1);
|
2018-04-25 12:21:07 +02:00
|
|
|
if (tmp != mesh) {
|
|
|
|
/* free intermediate results */
|
2018-05-03 15:42:55 +02:00
|
|
|
BKE_id_free(NULL, tmp);
|
2018-04-25 12:21:07 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
if (mmd->flag & MOD_MIR_AXIS_Z) {
|
2018-04-25 12:21:07 +02:00
|
|
|
Mesh *tmp = result;
|
2018-12-07 15:45:53 +01:00
|
|
|
result = doMirrorOnAxis(mmd, ctx, ob, result, 2);
|
2018-04-25 12:21:07 +02:00
|
|
|
if (tmp != mesh) {
|
|
|
|
/* free intermediate results */
|
2018-05-03 15:42:55 +02:00
|
|
|
BKE_id_free(NULL, tmp);
|
2018-04-25 12:21:07 +02:00
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-05-12 08:21:07 +02:00
|
|
|
static Mesh *applyModifier(
|
|
|
|
ModifierData *md, const ModifierEvalContext *ctx,
|
|
|
|
Mesh *mesh)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2018-04-25 12:21:07 +02:00
|
|
|
Mesh *result;
|
2012-05-06 13:38:33 +00:00
|
|
|
MirrorModifierData *mmd = (MirrorModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-12-07 15:45:53 +01:00
|
|
|
result = mirrorModifier__doMirror(mmd, ctx, ctx->object, mesh);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-04 10:05:57 +02:00
|
|
|
if (result != mesh) {
|
|
|
|
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
|
|
|
|
}
|
2010-04-11 22:12:30 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Mirror = {
|
|
|
|
/* name */ "Mirror",
|
|
|
|
/* structName */ "MirrorModifierData",
|
|
|
|
/* structSize */ sizeof(MirrorModifierData),
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_EnableInEditmode |
|
2013-06-02 22:40:45 +00:00
|
|
|
eModifierTypeFlag_AcceptsCVs |
|
|
|
|
/* this is only the case when 'MOD_MIR_VGROUP' is used */
|
|
|
|
eModifierTypeFlag_UsesPreview,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2018-04-25 12:21:07 +02:00
|
|
|
/* applyModifier */ applyModifier,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
/* initData */ initData,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* requiredDataMask */ NULL,
|
|
|
|
/* freeData */ NULL,
|
|
|
|
/* isDisabled */ NULL,
|
Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
2015-05-12 15:05:57 +05:00
|
|
|
/* updateDepsgraph */ updateDepsgraph,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* foreachObjectLink */ foreachObjectLink,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* foreachIDLink */ NULL,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ NULL,
|
2019-03-18 15:56:16 +01:00
|
|
|
/* freeRuntimeData */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|