Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastián Barschkis <sebbas@sebbas.org>2019-12-16 17:50:14 +0300
committerSebastián Barschkis <sebbas@sebbas.org>2019-12-16 18:37:01 +0300
commitd27ccf990c2b957a10f4676e3153f907829a4b22 (patch)
tree48667db9d5f51e3c951cb1106566a53db21d9adf /source/blender/modifiers/intern
parent7b87d3d34ec5bbaf777bdc27abdb69600915fce1 (diff)
Mantaflow [Part 6]: Updates in /blender/source
A collection of smaller changes that are required in the /blender/source files. A lot of them are also due to variable renaming. Reviewed By: sergey Maniphest Tasks: T59995 Differential Revision: https://developer.blender.org/D3855
Diffstat (limited to 'source/blender/modifiers/intern')
-rw-r--r--source/blender/modifiers/intern/MOD_fluid.c (renamed from source/blender/modifiers/intern/MOD_smoke.c)113
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim.c150
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim_util.c588
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim_util.h39
-rw-r--r--source/blender/modifiers/intern/MOD_util.c3
5 files changed, 64 insertions, 829 deletions
diff --git a/source/blender/modifiers/intern/MOD_smoke.c b/source/blender/modifiers/intern/MOD_fluid.c
index 34275d91ee6..aba9e352162 100644
--- a/source/blender/modifiers/intern/MOD_smoke.c
+++ b/source/blender/modifiers/intern/MOD_fluid.c
@@ -30,7 +30,7 @@
#include "DNA_collection_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_smoke_types.h"
+#include "DNA_fluid_types.h"
#include "DNA_object_force_types.h"
#include "DNA_mesh_types.h"
@@ -38,7 +38,7 @@
#include "BKE_layer.h"
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "BKE_smoke.h"
+#include "BKE_fluid.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
@@ -49,45 +49,45 @@
static void initData(ModifierData *md)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
+ FluidModifierData *mmd = (FluidModifierData *)md;
- smd->domain = NULL;
- smd->flow = NULL;
- smd->coll = NULL;
- smd->type = 0;
- smd->time = -1;
+ mmd->domain = NULL;
+ mmd->flow = NULL;
+ mmd->effector = NULL;
+ mmd->type = 0;
+ mmd->time = -1;
}
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
{
- const SmokeModifierData *smd = (const SmokeModifierData *)md;
- SmokeModifierData *tsmd = (SmokeModifierData *)target;
+ const FluidModifierData *mmd = (const FluidModifierData *)md;
+ FluidModifierData *tmmd = (FluidModifierData *)target;
- smokeModifier_free(tsmd);
- smokeModifier_copy(smd, tsmd, flag);
+ fluidModifier_free(tmmd);
+ fluidModifier_copy(mmd, tmmd, flag);
}
static void freeData(ModifierData *md)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
+ FluidModifierData *mmd = (FluidModifierData *)md;
- smokeModifier_free(smd);
+ fluidModifier_free(mmd);
}
static void requiredDataMask(Object *UNUSED(ob),
ModifierData *md,
CustomData_MeshMasks *r_cddata_masks)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
+ FluidModifierData *mmd = (FluidModifierData *)md;
- if (smd && (smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow) {
- if (smd->flow->source == MOD_SMOKE_FLOW_SOURCE_MESH) {
+ if (mmd && (mmd->type & MOD_FLUID_TYPE_FLOW) && mmd->flow) {
+ if (mmd->flow->source == FLUID_FLOW_SOURCE_MESH) {
/* vertex groups */
- if (smd->flow->vgroup_density) {
+ if (mmd->flow->vgroup_density) {
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
}
/* uv layer */
- if (smd->flow->texture_type == MOD_SMOKE_FLOW_TEXTURE_MAP_UV) {
+ if (mmd->flow->texture_type == FLUID_FLOW_TEXTURE_MAP_UV) {
r_cddata_masks->fmask |= CD_MASK_MTFACE;
}
}
@@ -96,14 +96,17 @@ static void requiredDataMask(Object *UNUSED(ob),
static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *me)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
+ FluidModifierData *mmd = (FluidModifierData *)md;
+ Mesh *result = NULL;
if (ctx->flag & MOD_APPLY_ORCO) {
return me;
}
Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
- return smokeModifier_do(smd, ctx->depsgraph, scene, ctx->object, me);
+
+ result = fluidModifier_do(mmd, ctx->depsgraph, scene, ctx->object, me);
+ return result ? result : me;
}
static bool dependsOnTime(ModifierData *UNUSED(md))
@@ -113,68 +116,78 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
static bool is_flow_cb(Object *UNUSED(ob), ModifierData *md)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
- return (smd->type & MOD_SMOKE_TYPE_FLOW) && smd->flow;
+ FluidModifierData *mmd = (FluidModifierData *)md;
+ return (mmd->type & MOD_FLUID_TYPE_FLOW) && mmd->flow;
}
static bool is_coll_cb(Object *UNUSED(ob), ModifierData *md)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
- return (smd->type & MOD_SMOKE_TYPE_COLL) && smd->coll;
+ FluidModifierData *mmd = (FluidModifierData *)md;
+ return (mmd->type & MOD_FLUID_TYPE_EFFEC) && mmd->effector;
}
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
+ FluidModifierData *mmd = (FluidModifierData *)md;
- if (smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
+ if (mmd && (mmd->type & MOD_FLUID_TYPE_DOMAIN) && mmd->domain) {
DEG_add_collision_relations(ctx->node,
ctx->object,
- smd->domain->fluid_group,
- eModifierType_Smoke,
+ mmd->domain->fluid_group,
+ eModifierType_Fluid,
is_flow_cb,
- "Smoke Flow");
+ "Fluid Flow");
DEG_add_collision_relations(ctx->node,
ctx->object,
- smd->domain->coll_group,
- eModifierType_Smoke,
+ mmd->domain->effector_group,
+ eModifierType_Fluid,
is_coll_cb,
- "Smoke Coll");
+ "Fluid Effector");
DEG_add_forcefield_relations(ctx->node,
ctx->object,
- smd->domain->effector_weights,
+ mmd->domain->effector_weights,
true,
PFIELD_SMOKEFLOW,
- "Smoke Force Field");
+ "Fluid Force Field");
+
+ if (mmd->domain->guiding_parent != NULL) {
+ DEG_add_object_relation(
+ ctx->node, mmd->domain->guiding_parent, DEG_OB_COMP_TRANSFORM, "Fluid Guiding Object");
+ DEG_add_object_relation(
+ ctx->node, mmd->domain->guiding_parent, DEG_OB_COMP_GEOMETRY, "Fluid Guiding Object");
+ }
}
}
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
{
- SmokeModifierData *smd = (SmokeModifierData *)md;
+ FluidModifierData *mmd = (FluidModifierData *)md;
- if (smd->type == MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
- walk(userData, ob, (ID **)&smd->domain->coll_group, IDWALK_CB_NOP);
- walk(userData, ob, (ID **)&smd->domain->fluid_group, IDWALK_CB_NOP);
- walk(userData, ob, (ID **)&smd->domain->eff_group, IDWALK_CB_NOP);
+ if (mmd->type == MOD_FLUID_TYPE_DOMAIN && mmd->domain) {
+ walk(userData, ob, (ID **)&mmd->domain->effector_group, IDWALK_CB_NOP);
+ walk(userData, ob, (ID **)&mmd->domain->fluid_group, IDWALK_CB_NOP);
+ walk(userData, ob, (ID **)&mmd->domain->force_group, IDWALK_CB_NOP);
+
+ if (mmd->domain->guiding_parent) {
+ walk(userData, ob, (ID **)&mmd->domain->guiding_parent, IDWALK_CB_NOP);
+ }
- if (smd->domain->effector_weights) {
- walk(userData, ob, (ID **)&smd->domain->effector_weights->group, IDWALK_CB_NOP);
+ if (mmd->domain->effector_weights) {
+ walk(userData, ob, (ID **)&mmd->domain->effector_weights->group, IDWALK_CB_NOP);
}
}
- if (smd->type == MOD_SMOKE_TYPE_FLOW && smd->flow) {
- walk(userData, ob, (ID **)&smd->flow->noise_texture, IDWALK_CB_USER);
+ if (mmd->type == MOD_FLUID_TYPE_FLOW && mmd->flow) {
+ walk(userData, ob, (ID **)&mmd->flow->noise_texture, IDWALK_CB_USER);
}
}
-ModifierTypeInfo modifierType_Smoke = {
- /* name */ "Smoke",
- /* structName */ "SmokeModifierData",
- /* structSize */ sizeof(SmokeModifierData),
+ModifierTypeInfo modifierType_Fluid = {
+ /* name */ "Fluid",
+ /* structName */ "FluidModifierData",
+ /* structSize */ sizeof(FluidModifierData),
/* type */ eModifierTypeType_Constructive,
- /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_UsesPointCache |
- eModifierTypeFlag_Single,
+ /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_Single,
/* copyData */ copyData,
diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c
deleted file mode 100644
index 620b21f3e0c..00000000000
--- a/source/blender/modifiers/intern/MOD_fluidsim.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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.
- */
-
-/** \file
- * \ingroup modifiers
- */
-
-#include "BLI_utildefines.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_object_fluidsim_types.h"
-#include "DNA_object_types.h"
-
-#include "BKE_layer.h"
-#include "BKE_modifier.h"
-
-#include "DEG_depsgraph_build.h"
-
-#include "MOD_fluidsim_util.h"
-#include "MOD_modifiertypes.h"
-
-#include "MEM_guardedalloc.h"
-
-/* Fluidsim */
-static void initData(ModifierData *md)
-{
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
-
- fluidsim_init(fluidmd);
-}
-static void freeData(ModifierData *md)
-{
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
-
- fluidsim_free(fluidmd);
-}
-
-static void copyData(const ModifierData *md, ModifierData *target, const int UNUSED(flag))
-{
- const FluidsimModifierData *fluidmd = (const FluidsimModifierData *)md;
- FluidsimModifierData *tfluidmd = (FluidsimModifierData *)target;
-
- /* Free any FSS that was allocated in initData() */
- if (tfluidmd->fss) {
- MEM_SAFE_FREE(tfluidmd->fss->meshVelocities);
- MEM_freeN(tfluidmd->fss);
- }
-
- if (fluidmd->fss == NULL) {
- tfluidmd->fss = NULL;
- return;
- }
-
- tfluidmd->fss = MEM_dupallocN(fluidmd->fss);
- if (tfluidmd->fss->meshVelocities != NULL) {
- tfluidmd->fss->meshVelocities = MEM_dupallocN(tfluidmd->fss->meshVelocities);
- }
-}
-
-static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
-{
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
- Mesh *result = NULL;
-
- /* check for alloc failing */
- if (!fluidmd->fss) {
- initData(md);
-
- if (!fluidmd->fss) {
- return mesh;
- }
- }
-
- result = fluidsimModifier_do(fluidmd, ctx, mesh);
-
- return result ? result : mesh;
-}
-
-static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)md;
- if (fluidmd && fluidmd->fss) {
- if (fluidmd->fss->type == OB_FLUIDSIM_DOMAIN) {
- FOREACH_SCENE_OBJECT_BEGIN (ctx->scene, ob1) {
- if (ob1 != ctx->object) {
- FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(
- ob1, eModifierType_Fluidsim);
-
- /* Only put dependencies from NON-DOMAIN fluids in here. */
- if (fluidmdtmp && fluidmdtmp->fss && (fluidmdtmp->fss->type != OB_FLUIDSIM_DOMAIN)) {
- DEG_add_object_relation(ctx->node, ob1, DEG_OB_COMP_TRANSFORM, "Fluidsim Object");
- }
- }
- }
- FOREACH_SCENE_OBJECT_END;
- }
- }
-}
-
-static bool dependsOnTime(ModifierData *UNUSED(md))
-{
- return true;
-}
-
-ModifierTypeInfo modifierType_Fluidsim = {
- /* name */ "Fluidsim",
- /* structName */ "FluidsimModifierData",
- /* structSize */ sizeof(FluidsimModifierData),
- /* type */ eModifierTypeType_Nonconstructive,
-
- /* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_RequiresOriginalData |
- eModifierTypeFlag_Single,
-
- /* copyData */ copyData,
-
- /* deformVerts */ NULL,
- /* deformMatrices */ NULL,
- /* deformVertsEM */ NULL,
- /* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
-
- /* initData */ initData,
- /* requiredDataMask */ NULL,
- /* freeData */ freeData,
- /* isDisabled */ NULL,
- /* updateDepsgraph */ updateDepsgraph,
- /* dependsOnTime */ dependsOnTime,
- /* dependsOnNormals */ NULL,
- /* foreachObjectLink */ NULL,
- /* foreachIDLink */ NULL,
- /* foreachTexLink */ NULL,
- /* freeRuntimeData */ NULL,
-};
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.c b/source/blender/modifiers/intern/MOD_fluidsim_util.c
deleted file mode 100644
index 748bf4db4e2..00000000000
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.c
+++ /dev/null
@@ -1,588 +0,0 @@
-/*
- * 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.
- */
-
-/** \file
- * \ingroup modifiers
- */
-
-#include <stddef.h>
-#include <zlib.h>
-
-#include "BLI_utildefines.h"
-
-#ifdef WITH_MOD_FLUID
-# include "BLI_blenlib.h"
-# include "BLI_math.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_object_fluidsim_types.h"
-
-#include "BKE_fluidsim.h" /* ensure definitions here match */
-#include "BKE_mesh.h"
-#ifdef WITH_MOD_FLUID
-# include "BKE_global.h"
-# include "BKE_library.h"
-#endif
-
-#include "DEG_depsgraph.h"
-#include "DEG_depsgraph_query.h"
-
-#include "MOD_fluidsim_util.h"
-#include "MOD_modifiertypes.h"
-
-#include "MEM_guardedalloc.h"
-
-// headers for fluidsim bobj meshes
-#include "LBM_fluidsim.h"
-
-void fluidsim_init(FluidsimModifierData *fluidmd)
-{
-#ifdef WITH_MOD_FLUID
- if (fluidmd) {
- FluidsimSettings *fss = MEM_callocN(sizeof(FluidsimSettings), "fluidsimsettings");
-
- fluidmd->fss = fss;
-
- if (!fss) {
- return;
- }
-
- fss->fmd = fluidmd;
- fss->type = OB_FLUIDSIM_ENABLE;
- fss->threads = 0;
- fss->show_advancedoptions = 0;
-
- fss->resolutionxyz = 65;
- fss->previewresxyz = 45;
- fss->realsize = 0.5;
- fss->guiDisplayMode = OB_FSDOM_PREVIEW;
- fss->renderDisplayMode = OB_FSDOM_FINAL;
-
- fss->viscosityValue = 1.0;
- fss->viscosityExponent = 6;
-
- fss->grav[0] = 0.0;
- fss->grav[1] = 0.0;
- fss->grav[2] = -9.81;
-
- fss->animStart = 0.0;
- fss->animEnd = 4.0;
- fss->animRate = 1.0;
- fss->gstar = 0.005; // used as normgstar
- fss->maxRefine = -1;
- /* maxRefine is set according to resolutionxyz during bake */
-
- /* fluid/inflow settings
- * fss->iniVel --> automatically set to 0 */
-
- modifier_path_init(fss->surfdataPath, sizeof(fss->surfdataPath), OB_FLUIDSIM_SURF_DIR_DEFAULT);
-
- /* first init of bounding box */
- /* no bounding box needed */
-
- /* todo - reuse default init from elbeem! */
- fss->typeFlags = OB_FSBND_PARTSLIP | OB_FSSG_NOOBS;
- fss->domainNovecgen = 0;
- fss->volumeInitType = 1; /* volume */
- fss->partSlipValue = 0.2;
-
- fss->generateTracers = 0;
- fss->generateParticles = 0.0;
- fss->surfaceSmoothing = 1.0;
- fss->surfaceSubdivs = 0.0;
- fss->particleInfSize = 0.0;
- fss->particleInfAlpha = 0.0;
-
- /* init fluid control settings */
- fss->attractforceStrength = 0.2;
- fss->attractforceRadius = 0.75;
- fss->velocityforceStrength = 0.2;
- fss->velocityforceRadius = 0.75;
- fss->cpsTimeStart = fss->animStart;
- fss->cpsTimeEnd = fss->animEnd;
- fss->cpsQuality = 10.0; // 1.0 / 10.0 => means 0.1 width
-
- /*
- * BAD TODO: this is done in buttons_object.c in the moment
- * Mesh *mesh = ob->data;
- * // calculate bounding box
- * fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize);
- */
-
- fss->meshVelocities = NULL;
-
- fss->lastgoodframe = -1;
-
- fss->flag |= OB_FLUIDSIM_ACTIVE;
- }
-#else
- (void)fluidmd; /* unused */
-#endif
- return;
-}
-
-void fluidsim_free(FluidsimModifierData *fluidmd)
-{
- if (fluidmd && fluidmd->fss) {
- if (fluidmd->fss->meshVelocities) {
- MEM_freeN(fluidmd->fss->meshVelocities);
- }
- MEM_SAFE_FREE(fluidmd->fss);
- }
-
- return;
-}
-
-#ifdef WITH_MOD_FLUID
-/* read .bobj.gz file into a fluidsimMesh struct */
-static Mesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example)
-{
- int wri = 0, i;
- int gotBytes;
- gzFile gzf;
- int numverts = 0, numfaces = 0;
- Mesh *mesh = NULL;
- MPoly *mp;
- MLoop *ml;
- MVert *mv;
- short *normals, *no_s;
- float no[3];
-
- const short mp_mat_nr = mp_example->mat_nr;
- const char mp_flag = mp_example->flag;
-
- /* ------------------------------------------------
- * get numverts + numfaces first
- * ------------------------------------------------ */
- gzf = BLI_gzopen(filename, "rb");
- if (!gzf) {
- return NULL;
- }
-
- /* read numverts */
- gotBytes = gzread(gzf, &wri, sizeof(wri));
- numverts = wri;
-
- /* skip verts */
- gotBytes = gzseek(gzf, numverts * 3 * sizeof(float), SEEK_CUR) != -1;
-
- /* read number of normals */
- if (gotBytes) {
- gotBytes = gzread(gzf, &wri, sizeof(wri));
- }
-
- /* skip normals */
- gotBytes = gzseek(gzf, numverts * 3 * sizeof(float), SEEK_CUR) != -1;
-
- /* get no. of triangles */
- if (gotBytes) {
- gotBytes = gzread(gzf, &wri, sizeof(wri));
- }
- numfaces = wri;
-
- gzclose(gzf);
- /* ------------------------------------------------ */
-
- if (!numfaces || !numverts || !gotBytes) {
- return NULL;
- }
-
- gzf = BLI_gzopen(filename, "rb");
- if (!gzf) {
- return NULL;
- }
-
- mesh = BKE_mesh_new_nomain(numverts, 0, 0, numfaces * 3, numfaces);
-
- if (!mesh) {
- gzclose(gzf);
- return NULL;
- }
-
- /* read numverts */
- gotBytes = gzread(gzf, &wri, sizeof(wri));
-
- /* read vertex position from file */
- mv = mesh->mvert;
-
- for (i = 0; i < numverts; i++, mv++) {
- gotBytes = gzread(gzf, mv->co, sizeof(float) * 3);
- }
-
- /* should be the same as numverts */
- gotBytes = gzread(gzf, &wri, sizeof(wri));
- if (wri != numverts) {
- if (mesh) {
- BKE_id_free(NULL, mesh);
- }
- gzclose(gzf);
- return NULL;
- }
-
- normals = MEM_calloc_arrayN(numverts, 3 * sizeof(short), "fluid_tmp_normals");
- if (!normals) {
- if (mesh) {
- BKE_id_free(NULL, mesh);
- }
- gzclose(gzf);
- return NULL;
- }
-
- /* read normals from file (but don't save them yet) */
- for (i = numverts, no_s = normals; i > 0; i--, no_s += 3) {
- gotBytes = gzread(gzf, no, sizeof(float) * 3);
- normal_float_to_short_v3(no_s, no);
- }
-
- /* read no. of triangles */
- gotBytes = gzread(gzf, &wri, sizeof(wri));
-
- if (wri != numfaces) {
- printf("Fluidsim: error in reading data from file.\n");
- if (mesh) {
- BKE_id_free(NULL, mesh);
- }
- gzclose(gzf);
- MEM_freeN(normals);
- return NULL;
- }
-
- /* read triangles from file */
- mp = mesh->mpoly;
- ml = mesh->mloop;
- for (i = 0; i < numfaces; i++, mp++, ml += 3) {
- int face[3];
-
- gotBytes = gzread(gzf, face, sizeof(int) * 3);
-
- /* initialize from existing face */
- mp->mat_nr = mp_mat_nr;
- mp->flag = mp_flag;
-
- mp->loopstart = i * 3;
- mp->totloop = 3;
-
- ml[0].v = face[0];
- ml[1].v = face[1];
- ml[2].v = face[2];
- }
-
- gzclose(gzf);
-
- BKE_mesh_calc_edges(mesh, false, false);
- BKE_mesh_vert_normals_apply(mesh, (short(*)[3])normals);
- MEM_freeN(normals);
-
- // CDDM_calc_normals(result);
- return mesh;
-}
-
-void fluid_get_bb(MVert *mvert,
- int totvert,
- float obmat[4][4],
- /*RET*/ float start[3],
- /*RET*/ float size[3])
-{
- float bbsx = 0.0, bbsy = 0.0, bbsz = 0.0;
- float bbex = 1.0, bbey = 1.0, bbez = 1.0;
- int i;
- float vec[3];
-
- if (totvert == 0) {
- zero_v3(start);
- zero_v3(size);
- return;
- }
-
- copy_v3_v3(vec, mvert[0].co);
- mul_m4_v3(obmat, vec);
- bbsx = vec[0];
- bbsy = vec[1];
- bbsz = vec[2];
- bbex = vec[0];
- bbey = vec[1];
- bbez = vec[2];
-
- for (i = 1; i < totvert; i++) {
- copy_v3_v3(vec, mvert[i].co);
- mul_m4_v3(obmat, vec);
-
- if (vec[0] < bbsx) {
- bbsx = vec[0];
- }
- if (vec[1] < bbsy) {
- bbsy = vec[1];
- }
- if (vec[2] < bbsz) {
- bbsz = vec[2];
- }
- if (vec[0] > bbex) {
- bbex = vec[0];
- }
- if (vec[1] > bbey) {
- bbey = vec[1];
- }
- if (vec[2] > bbez) {
- bbez = vec[2];
- }
- }
-
- /* return values... */
- if (start) {
- start[0] = bbsx;
- start[1] = bbsy;
- start[2] = bbsz;
- }
- if (size) {
- size[0] = bbex - bbsx;
- size[1] = bbey - bbsy;
- size[2] = bbez - bbsz;
- }
-}
-
-//-------------------------------------------------------------------------------
-// old interface
-//-------------------------------------------------------------------------------
-
-void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value)
-{
- Mesh *mesh;
-
- value[0] = '\0';
-
- if (ob->type == OB_MESH) {
- /* use mesh bounding box and object scaling */
- mesh = ob->data;
-
- fluid_get_bb(mesh->mvert, mesh->totvert, ob->obmat, fss->bbStart, fss->bbSize);
- elbeemEstimateMemreq(
- fss->resolutionxyz, fss->bbSize[0], fss->bbSize[1], fss->bbSize[2], fss->maxRefine, value);
- }
-}
-
-/* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */
-static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, Mesh *mesh, char *filename)
-{
- int wri, i, j;
- float wrf;
- gzFile gzf;
- FluidsimSettings *fss = fluidmd->fss;
- int len = strlen(filename);
- int totvert = mesh->totvert;
- FluidVertexVelocity *velarray = NULL;
-
- /* mesh and vverts have to be valid from loading... */
-
- if (fss->meshVelocities) {
- MEM_freeN(fss->meshVelocities);
- }
-
- if (len < 7) {
- return;
- }
-
- if (fss->domainNovecgen > 0) {
- return;
- }
-
- fss->meshVelocities = MEM_calloc_arrayN(
- mesh->totvert, sizeof(FluidVertexVelocity), "Fluidsim_velocities");
- fss->totvert = totvert;
-
- velarray = fss->meshVelocities;
-
- /* .bobj.gz, correct filename
- * 87654321 */
- filename[len - 6] = 'v';
- filename[len - 5] = 'e';
- filename[len - 4] = 'l';
-
- gzf = BLI_gzopen(filename, "rb");
- if (!gzf) {
- MEM_freeN(fss->meshVelocities);
- fss->meshVelocities = NULL;
- return;
- }
-
- gzread(gzf, &wri, sizeof(wri));
- if (wri != totvert) {
- MEM_freeN(fss->meshVelocities);
- fss->meshVelocities = NULL;
- return;
- }
-
- for (i = 0; i < totvert; i++) {
- for (j = 0; j < 3; j++) {
- gzread(gzf, &wrf, sizeof(wrf));
- velarray[i].vel[j] = wrf;
- }
- }
-
- gzclose(gzf);
-}
-
-static Mesh *fluidsim_read_cache(
- Object *ob, Mesh *orgmesh, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
-{
- int curFrame = framenr /* - 1 */ /*scene->r.sfra*/; /* start with 0 at start frame */
- /* why start with 0 as start frame?? Animations + time are frozen for frame 0 anyway.
- * (See physics_fluid.c for that. - DG) */
- /* If we start with frame 0, we need to remap all animation channels, too,
- * because they will all be 1 frame late if using frame-1! - DG */
-
- char targetFile[FILE_MAX];
- FluidsimSettings *fss = fluidmd->fss;
- Mesh *newmesh = NULL;
- MPoly *mpoly;
- MPoly mp_example = {0};
-
- const int displaymode = useRenderParams ? fss->renderDisplayMode : fss->guiDisplayMode;
-
- switch (displaymode) {
- case OB_FSDOM_GEOM:
- /* just display original object */
- return NULL;
- case OB_FSDOM_PREVIEW:
- /* use preview mesh */
- BLI_join_dirfile(
- targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_PREVIEW_OBJ_FNAME);
- break;
- case OB_FSDOM_FINAL:
- /* use final mesh */
- BLI_join_dirfile(
- targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_OBJ_FNAME);
- break;
- default:
- BLI_assert(!"Wrong fluidsim display type");
- return NULL;
- }
-
- /* offset baked frame */
- curFrame += fss->frameOffset;
-
- BLI_path_abs(targetFile, modifier_path_relbase_from_global(ob));
- BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no
-
- /* assign material + flags to new mesh.
- * if there's no faces in original mesh, keep materials and flags unchanged */
- mpoly = orgmesh->mpoly;
- if (mpoly) {
- mp_example = *mpoly;
- }
- /* else leave NULL'd */
-
- newmesh = fluidsim_read_obj(targetFile, &mp_example);
-
- if (!newmesh) {
- /* switch, abort background rendering when fluidsim mesh is missing */
- const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp
-
- if (G.background == 1) {
- if (BLI_getenv(strEnvName2)) {
- int elevel = atoi(BLI_getenv(strEnvName2));
- if (elevel > 0) {
- printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n",
- strEnvName2,
- targetFile);
- exit(1);
- }
- }
- }
-
- /* display org. object upon failure which is in new mesh */
- return NULL;
- }
-
- BKE_mesh_copy_settings(newmesh, orgmesh);
-
- /* Fluid simulation has a texture space that based on the bounds of the fluid mesh.
- * This does not seem particularly useful, but it's backwards compatible. */
- BKE_mesh_texspace_calc(newmesh);
-
- /* load vertex velocities, if they exist...
- * TODO? use generate flag as loading flag as well?
- * warning, needs original .bobj.gz mesh loading filename */
- if (displaymode == OB_FSDOM_FINAL) {
- fluidsim_read_vel_cache(fluidmd, newmesh, targetFile);
- }
- else {
- if (fss->meshVelocities) {
- MEM_freeN(fss->meshVelocities);
- }
-
- fss->meshVelocities = NULL;
- }
-
- return newmesh;
-}
-#endif // WITH_MOD_FLUID
-
-Mesh *fluidsimModifier_do(FluidsimModifierData *fluidmd,
- const ModifierEvalContext *ctx,
- Mesh *mesh)
-{
-#ifdef WITH_MOD_FLUID
- Object *ob = ctx->object;
- Depsgraph *depsgraph = ctx->depsgraph;
- const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0;
- // const bool isFinalCalc = (ctx->flag & MOD_APPLY_USECACHE) != 0;
- Mesh *result = NULL;
- int framenr;
- FluidsimSettings *fss = NULL;
-
- framenr = (int)DEG_get_ctime(depsgraph);
-
- /* only handle fluidsim domains */
- if (fluidmd && fluidmd->fss && (fluidmd->fss->type != OB_FLUIDSIM_DOMAIN)) {
- return mesh;
- }
-
- /* sanity check */
- if (!fluidmd || !fluidmd->fss) {
- return mesh;
- }
-
- fss = fluidmd->fss;
-
- /* timescale not supported yet
- * clmd->sim_parms->timescale = timescale; */
-
- /* support reversing of baked fluid frames here */
- if ((fss->flag & OB_FLUIDSIM_REVERSE) && (fss->lastgoodframe >= 0)) {
- framenr = fss->lastgoodframe - framenr + 1;
- CLAMP(framenr, 1, fss->lastgoodframe);
- }
-
- /* try to read from cache */
- /* if the frame is there, fine, otherwise don't do anything */
- if ((result = fluidsim_read_cache(ob, mesh, fluidmd, framenr, useRenderParams))) {
- return result;
- }
-
- return mesh;
-#else
- /* unused */
- UNUSED_VARS(fluidmd, ctx, mesh);
- return NULL;
-#endif
-}
diff --git a/source/blender/modifiers/intern/MOD_fluidsim_util.h b/source/blender/modifiers/intern/MOD_fluidsim_util.h
deleted file mode 100644
index da70568353e..00000000000
--- a/source/blender/modifiers/intern/MOD_fluidsim_util.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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) Blender Foundation
- * All rights reserved.
- */
-
-/** \file
- * \ingroup modifiers
- */
-
-#ifndef __MOD_FLUIDSIM_UTIL_H__
-#define __MOD_FLUIDSIM_UTIL_H__
-
-struct FluidsimModifierData;
-struct Mesh;
-struct ModifierEvalContext;
-
-/* new fluid-modifier interface */
-void fluidsim_init(struct FluidsimModifierData *fluidmd);
-void fluidsim_free(struct FluidsimModifierData *fluidmd);
-
-struct Mesh *fluidsimModifier_do(struct FluidsimModifierData *fluidmd,
- const struct ModifierEvalContext *ctx,
- struct Mesh *me);
-
-#endif
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index 05bd8b5e01a..0b72c31ad7b 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -279,12 +279,11 @@ void modifier_type_init(ModifierTypeInfo *types[])
INIT_TYPE(ParticleInstance);
INIT_TYPE(Explode);
INIT_TYPE(Shrinkwrap);
- INIT_TYPE(Fluidsim);
INIT_TYPE(Mask);
INIT_TYPE(SimpleDeform);
INIT_TYPE(Multires);
INIT_TYPE(Surface);
- INIT_TYPE(Smoke);
+ INIT_TYPE(Fluid);
INIT_TYPE(ShapeKey);
INIT_TYPE(Solidify);
INIT_TYPE(Screw);