This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/modifiers/intern/MOD_remesh.c

243 lines
5.9 KiB
C
Raw Normal View History

/*
* ***** 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 *****
*/
/** \file blender/modifiers/intern/MOD_remesh.c
* \ingroup modifiers
*/
#include "MEM_guardedalloc.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "MOD_modifiertypes.h"
#include "BKE_mesh.h"
#include "BKE_mesh_runtime.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#ifdef WITH_MOD_REMESH
# include "dualcon.h"
#endif
static void initData(ModifierData *md)
{
2012-05-06 13:38:33 +00:00
RemeshModifierData *rmd = (RemeshModifierData *) md;
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;
}
#ifdef WITH_MOD_REMESH
static void init_dualcon_mesh(DualConInput *input, Mesh *mesh)
{
memset(input, 0, sizeof(DualConInput));
input->co = (void *)mesh->mvert;
input->co_stride = sizeof(MVert);
input->totco = mesh->totvert;
input->mloop = (void *)mesh->mloop;
input->loop_stride = sizeof(MLoop);
BKE_mesh_runtime_looptri_ensure(mesh);
input->looptri = (void *)mesh->runtime.looptris.array;
input->tri_stride = sizeof(MLoopTri);
input->tottri = mesh->runtime.looptris.len;
INIT_MINMAX(input->min, input->max);
BKE_mesh_minmax(mesh, input->min, input->max);
}
/* 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 */
typedef struct {
Mesh *mesh;
int curvert, curface;
} DualConOutput;
/* allocate and initialize a DualConOutput */
static void *dualcon_alloc_output(int totvert, int totquad)
{
DualConOutput *output;
if (!(output = MEM_callocN(sizeof(DualConOutput),
"DualConOutput")))
{
return NULL;
}
2018-06-17 17:04:27 +02:00
output->mesh = BKE_mesh_new_nomain(totvert, 0, 0, 4 * totquad, totquad);
return output;
}
static void dualcon_add_vert(void *output_v, const float co[3])
{
DualConOutput *output = output_v;
Mesh *mesh = output->mesh;
2018-06-17 17:04:27 +02:00
assert(output->curvert < mesh->totvert);
2018-06-17 17:04:27 +02:00
copy_v3_v3(mesh->mvert[output->curvert].co, co);
output->curvert++;
}
static void dualcon_add_quad(void *output_v, const int vert_indices[4])
{
DualConOutput *output = output_v;
Mesh *mesh = output->mesh;
MLoop *mloop;
MPoly *cur_poly;
int i;
2018-06-17 17:04:27 +02:00
assert(output->curface < mesh->totpoly);
mloop = mesh->mloop;
cur_poly = &mesh->mpoly[output->curface];
2018-06-17 17:04:27 +02:00
cur_poly->loopstart = output->curface * 4;
cur_poly->totloop = 4;
for (i = 0; i < 4; i++)
mloop[output->curface * 4 + i].v = vert_indices[i];
2018-06-17 17:04:27 +02:00
output->curface++;
}
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),
Mesh *mesh)
{
RemeshModifierData *rmd;
DualConOutput *output;
DualConInput input;
Mesh *result;
DualConFlags flags = 0;
DualConMode mode = 0;
2012-05-06 13:38:33 +00:00
rmd = (RemeshModifierData *)md;
init_dualcon_mesh(&input, mesh);
if (rmd->flag & MOD_REMESH_FLOOD_FILL)
flags |= DUALCON_FLOOD_FILL;
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;
}
2018-06-17 17:04:27 +02: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);
result = output->mesh;
MEM_freeN(output);
if (rmd->flag & MOD_REMESH_SMOOTH_SHADING) {
MPoly *mpoly = result->mpoly;
int i, totpoly = result->totpoly;
2018-06-17 17:04:27 +02:00
/* Apply smooth shading to output faces */
for (i = 0; i < totpoly; i++) {
mpoly[i].flag |= ME_SMOOTH;
}
}
BKE_mesh_calc_edges(result, true, false);
result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
return result;
}
#else /* !WITH_MOD_REMESH */
static Mesh *applyModifier(
2018-05-12 08:21:07 +02:00
ModifierData *UNUSED(md),
const ModifierEvalContext *UNUSED(ctx),
Mesh *mesh)
{
return mesh;
}
#endif /* !WITH_MOD_REMESH */
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
/* copyData */ modifier_copyData_generic,
/* deformVerts_DM */ NULL,
/* deformMatrices_DM */ NULL,
/* deformVertsEM_DM */ NULL,
/* deformMatricesEM_DM*/NULL,
/* applyModifier_DM */ NULL,
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* 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,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
/* foreachObjectLink */ NULL,
/* foreachIDLink */ NULL,
};