2011-12-30 21:11:40 +00:00
|
|
|
/*
|
2012-01-01 16:09:32 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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) 2011 by Nicholas Bishop.
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
2011-12-30 21:11:40 +00:00
|
|
|
|
|
|
|
/** \file blender/modifiers/intern/MOD_remesh.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2012-04-16 08:11:07 +00:00
|
|
|
#include "BLI_math_base.h"
|
2011-12-30 21:11:40 +00:00
|
|
|
#include "BLI_math_vector.h"
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_modifier_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2018-05-12 09:31:44 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2011-12-30 21:11:40 +00:00
|
|
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
#include "BKE_mesh.h"
|
2018-06-05 15:59:53 +02:00
|
|
|
#include "BKE_mesh_runtime.h"
|
2018-05-12 09:31:44 +02:00
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#ifdef WITH_MOD_REMESH
|
|
|
|
# include "dualcon.h"
|
|
|
|
#endif
|
2011-12-30 21:11:40 +00:00
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
RemeshModifierData *rmd = (RemeshModifierData *) md;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
|
|
|
rmd->scale = 0.9;
|
|
|
|
rmd->depth = 4;
|
|
|
|
rmd->hermite_num = 1;
|
|
|
|
rmd->flag = MOD_REMESH_FLOOD_FILL;
|
|
|
|
rmd->mode = MOD_REMESH_SHARP_FEATURES;
|
|
|
|
rmd->threshold = 1;
|
|
|
|
}
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#ifdef WITH_MOD_REMESH
|
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
2018-05-12 09:31:44 +02:00
|
|
|
memset(input, 0, sizeof(DualConInput));
|
|
|
|
|
|
|
|
input->co = (void *)mesh->mvert;
|
|
|
|
input->co_stride = sizeof(MVert);
|
|
|
|
input->totco = mesh->totvert;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
input->mloop = (void *)mesh->mloop;
|
|
|
|
input->loop_stride = sizeof(MLoop);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
BKE_mesh_runtime_looptri_ensure(mesh);
|
|
|
|
input->looptri = (void *)mesh->runtime.looptris.array;
|
|
|
|
input->tri_stride = sizeof(MLoopTri);
|
|
|
|
input->tottri = mesh->runtime.looptris.len;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
INIT_MINMAX(input->min, input->max);
|
|
|
|
BKE_mesh_minmax(mesh, input->min, input->max);
|
2011-12-30 21:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* simple structure to hold the output: a CDDM and two counters to
|
2012-03-09 18:28:30 +00:00
|
|
|
* keep track of the current elements */
|
2011-12-30 21:11:40 +00:00
|
|
|
typedef struct {
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh;
|
2011-12-30 21:11:40 +00:00
|
|
|
int curvert, curface;
|
|
|
|
} DualConOutput;
|
|
|
|
|
|
|
|
/* allocate and initialize a DualConOutput */
|
2011-12-31 03:34:44 +00:00
|
|
|
static void *dualcon_alloc_output(int totvert, int totquad)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
|
|
|
DualConOutput *output;
|
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (!(output = MEM_callocN(sizeof(DualConOutput),
|
2012-04-28 06:31:57 +00:00
|
|
|
"DualConOutput")))
|
|
|
|
{
|
2011-12-30 21:11:40 +00:00
|
|
|
return NULL;
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad);
|
2011-12-30 21:11:40 +00:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
static void dualcon_add_vert(void *output_v, const float co[3])
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
|
|
|
DualConOutput *output = output_v;
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh = output->mesh;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
assert(output->curvert < mesh->totvert);
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
copy_v3_v3(mesh->mvert[output->curvert].co, co);
|
2011-12-30 21:11:40 +00:00
|
|
|
output->curvert++;
|
|
|
|
}
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
static void dualcon_add_quad(void *output_v, const int vert_indices[4])
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
|
|
|
DualConOutput *output = output_v;
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh = output->mesh;
|
2012-02-07 01:20:49 +00:00
|
|
|
MLoop *mloop;
|
|
|
|
MPoly *cur_poly;
|
|
|
|
int i;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
assert(output->curface < mesh->totpoly);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
mloop = mesh->mloop;
|
|
|
|
cur_poly = &mesh->mpoly[output->curface];
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-02-07 01:20:49 +00:00
|
|
|
cur_poly->loopstart = output->curface * 4;
|
|
|
|
cur_poly->totloop = 4;
|
2012-03-24 06:24:53 +00:00
|
|
|
for (i = 0; i < 4; i++)
|
2012-02-07 01:20:49 +00:00
|
|
|
mloop[output->curface * 4 + i].v = vert_indices[i];
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-02-07 01:20:49 +00:00
|
|
|
output->curface++;
|
2011-12-30 21:11:40 +00:00
|
|
|
}
|
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
static Mesh *applyModifier(
|
2018-05-12 08:04:56 +02:00
|
|
|
ModifierData *md,
|
2018-05-12 08:21:07 +02:00
|
|
|
const ModifierEvalContext *UNUSED(ctx),
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh)
|
2011-12-30 21:11:40 +00:00
|
|
|
{
|
|
|
|
RemeshModifierData *rmd;
|
|
|
|
DualConOutput *output;
|
|
|
|
DualConInput input;
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *result;
|
2011-12-30 21:11:40 +00:00
|
|
|
DualConFlags flags = 0;
|
2012-01-01 16:09:32 +00:00
|
|
|
DualConMode mode = 0;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
rmd = (RemeshModifierData *)md;
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
init_dualcon_mesh(&input, mesh);
|
2011-12-30 21:11:40 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (rmd->flag & MOD_REMESH_FLOOD_FILL)
|
2011-12-30 21:11:40 +00:00
|
|
|
flags |= DUALCON_FLOOD_FILL;
|
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (rmd->mode) {
|
2012-05-06 13:38:33 +00:00
|
|
|
case MOD_REMESH_CENTROID:
|
|
|
|
mode = DUALCON_CENTROID;
|
|
|
|
break;
|
|
|
|
case MOD_REMESH_MASS_POINT:
|
|
|
|
mode = DUALCON_MASS_POINT;
|
|
|
|
break;
|
|
|
|
case MOD_REMESH_SHARP_FEATURES:
|
|
|
|
mode = DUALCON_SHARP_FEATURES;
|
|
|
|
break;
|
2011-12-30 21:11:40 +00:00
|
|
|
}
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
output = dualcon(&input,
|
2012-05-06 13:38:33 +00:00
|
|
|
dualcon_alloc_output,
|
|
|
|
dualcon_add_vert,
|
|
|
|
dualcon_add_quad,
|
|
|
|
flags,
|
|
|
|
mode,
|
|
|
|
rmd->threshold,
|
|
|
|
rmd->hermite_num,
|
|
|
|
rmd->scale,
|
|
|
|
rmd->depth);
|
2018-05-12 09:31:44 +02:00
|
|
|
result = output->mesh;
|
2011-12-30 21:11:40 +00:00
|
|
|
MEM_freeN(output);
|
|
|
|
|
2012-05-18 06:10:47 +00:00
|
|
|
if (rmd->flag & MOD_REMESH_SMOOTH_SHADING) {
|
2018-05-12 09:31:44 +02:00
|
|
|
MPoly *mpoly = result->mpoly;
|
|
|
|
int i, totpoly = result->totpoly;
|
2018-06-17 17:04:27 +02:00
|
|
|
|
2012-05-18 06:10:47 +00:00
|
|
|
/* Apply smooth shading to output faces */
|
|
|
|
for (i = 0; i < totpoly; i++) {
|
|
|
|
mpoly[i].flag |= ME_SMOOTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
BKE_mesh_calc_edges(result, true, false);
|
|
|
|
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
|
2011-12-30 21:11:40 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-12-31 03:34:44 +00:00
|
|
|
#else /* !WITH_MOD_REMESH */
|
|
|
|
|
2018-05-12 09:31:44 +02:00
|
|
|
static Mesh *applyModifier(
|
2018-05-12 08:21:07 +02:00
|
|
|
ModifierData *UNUSED(md),
|
|
|
|
const ModifierEvalContext *UNUSED(ctx),
|
2018-05-12 09:31:44 +02:00
|
|
|
Mesh *mesh)
|
2011-12-31 03:34:44 +00:00
|
|
|
{
|
2018-05-12 09:31:44 +02:00
|
|
|
return mesh;
|
2011-12-31 03:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !WITH_MOD_REMESH */
|
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
ModifierTypeInfo modifierType_Remesh = {
|
|
|
|
/* name */ "Remesh",
|
|
|
|
/* structName */ "RemeshModifierData",
|
|
|
|
/* structSize */ sizeof(RemeshModifierData),
|
|
|
|
/* type */ eModifierTypeType_Nonconstructive,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
2012-10-24 05:45:54 +00:00
|
|
|
eModifierTypeFlag_AcceptsCVs |
|
2012-05-06 13:38:33 +00:00
|
|
|
eModifierTypeFlag_SupportsEditmode,
|
2018-05-08 15:20:18 +02:00
|
|
|
|
2018-05-08 15:04:10 +02:00
|
|
|
/* copyData */ modifier_copyData_generic,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
|
|
|
/* deformVerts_DM */ NULL,
|
|
|
|
/* deformMatrices_DM */ NULL,
|
|
|
|
/* deformVertsEM_DM */ NULL,
|
|
|
|
/* deformMatricesEM_DM*/NULL,
|
2018-05-12 09:31:44 +02:00
|
|
|
/* applyModifier_DM */ NULL,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2018-05-12 09:31:44 +02:00
|
|
|
/* applyModifier */ applyModifier,
|
2018-04-18 15:45:54 +02:00
|
|
|
|
2011-12-30 21:11:40 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* 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 */ NULL,
|
2011-12-30 21:11:40 +00:00
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
|
|
|
/* foreachIDLink */ NULL,
|
|
|
|
};
|