Fluidsim: ported from DerivedMesh to Mesh
Also removed a bunch of unnecessary #include statements from fluidsim.c.
This commit is contained in:
parent
99a6d616e8
commit
f4ce6d02cd
|
@ -530,10 +530,6 @@ DerivedMesh *getEditDerivedBMesh(
|
|||
struct BMEditMesh *em, struct Object *ob, CustomDataMask data_mask,
|
||||
float (*vertexCos)[3]);
|
||||
|
||||
DerivedMesh *mesh_create_derived_index_render(
|
||||
struct Depsgraph *depsgraph, struct Scene *scene,
|
||||
struct Object *ob, CustomDataMask dataMask, int index);
|
||||
|
||||
/* same as above but wont use render settings */
|
||||
DerivedMesh *mesh_create_derived(struct Mesh *me, float (*vertCos)[3]);
|
||||
DerivedMesh *mesh_create_derived_view(
|
||||
|
|
|
@ -85,6 +85,15 @@ struct Mesh *mesh_get_eval_deform(
|
|||
struct Depsgraph *depsgraph, struct Scene *scene,
|
||||
struct Object *ob, CustomDataMask dataMask);
|
||||
|
||||
#ifdef USE_DERIVEDMESH
|
||||
struct DerivedMesh *mesh_create_derived_index_render(
|
||||
struct Depsgraph *depsgraph, struct Scene *scene,
|
||||
struct Object *ob, CustomDataMask dataMask, int index);
|
||||
#endif
|
||||
struct Mesh *mesh_create_eval_final_index_render(
|
||||
struct Depsgraph *depsgraph, struct Scene *scene,
|
||||
struct Object *ob, CustomDataMask dataMask, int index);
|
||||
|
||||
void BKE_mesh_runtime_eval_to_meshkey(struct Mesh *me_deformed, struct Mesh *me, struct KeyBlock *kb);
|
||||
|
||||
/* Temporary? A function to give a colorband to derivedmesh for vertexcolor ranges */
|
||||
|
|
|
@ -3156,6 +3156,8 @@ DerivedMesh *mesh_create_derived_render(struct Depsgraph *depsgraph, Scene *scen
|
|||
return final;
|
||||
}
|
||||
|
||||
#ifdef USE_DERIVEDMESH
|
||||
/* Deprecated, use `mesh_create_eval_final_index_render` instead. */
|
||||
DerivedMesh *mesh_create_derived_index_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask, int index)
|
||||
{
|
||||
DerivedMesh *final;
|
||||
|
@ -3166,6 +3168,19 @@ DerivedMesh *mesh_create_derived_index_render(struct Depsgraph *depsgraph, Scene
|
|||
|
||||
return final;
|
||||
}
|
||||
#endif
|
||||
struct Mesh *mesh_create_eval_final_index_render(
|
||||
struct Depsgraph *depsgraph, struct Scene *scene,
|
||||
struct Object *ob, CustomDataMask dataMask, int index)
|
||||
{
|
||||
Mesh *final;
|
||||
|
||||
mesh_calc_modifiers(
|
||||
depsgraph, scene, ob, NULL, 1, false, dataMask, index, false, false, false,
|
||||
NULL, &final);
|
||||
|
||||
return final;
|
||||
}
|
||||
|
||||
DerivedMesh *mesh_create_derived_view(
|
||||
struct Depsgraph *depsgraph, Scene *scene,
|
||||
|
|
|
@ -30,36 +30,21 @@
|
|||
*/
|
||||
|
||||
|
||||
// headers for fluidsim bobj meshes
|
||||
#include <stdlib.h>
|
||||
#include <zlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_object_fluidsim_types.h"
|
||||
#include "DNA_object_force_types.h" // for pointcache
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_particle_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BLI_math.h"
|
||||
#include "BLI_blenlib.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_DerivedMesh.h"
|
||||
#include "BKE_fluidsim.h"
|
||||
#include "BKE_modifier.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_library.h"
|
||||
#include "BKE_mesh_runtime.h"
|
||||
|
||||
/* ************************* fluidsim bobj file handling **************************** */
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
// file handling
|
||||
//-------------------------------------------------------------------------------
|
||||
|
@ -69,7 +54,7 @@ void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Obj
|
|||
int *numTriangles, int **triangles,
|
||||
int useGlobalCoords, int modifierIndex)
|
||||
{
|
||||
DerivedMesh *dm;
|
||||
Mesh *mesh;
|
||||
const MVert *mvert;
|
||||
const MLoop *mloop;
|
||||
const MLoopTri *looptri, *lt;
|
||||
|
@ -77,13 +62,13 @@ void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Obj
|
|||
float *verts;
|
||||
int *tris;
|
||||
|
||||
dm = mesh_create_derived_index_render(depsgraph, scene, ob, CD_MASK_BAREMESH, modifierIndex);
|
||||
mesh = mesh_create_eval_final_index_render(depsgraph, scene, ob, CD_MASK_BAREMESH, modifierIndex);
|
||||
|
||||
mvert = dm->getVertArray(dm);
|
||||
mloop = dm->getLoopArray(dm);
|
||||
looptri = dm->getLoopTriArray(dm);
|
||||
mvert_num = dm->getNumVerts(dm);
|
||||
looptri_num = dm->getNumLoopTri(dm);
|
||||
mvert = mesh->mvert;
|
||||
mloop = mesh->mloop;
|
||||
looptri = BKE_mesh_runtime_looptri_ensure(mesh);
|
||||
mvert_num = mesh->totvert;
|
||||
looptri_num = mesh->runtime.looptris.len;
|
||||
|
||||
*numVertices = mvert_num;
|
||||
verts = MEM_mallocN(mvert_num * sizeof(float[3]), "elbeemmesh_vertices");
|
||||
|
@ -102,5 +87,5 @@ void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Obj
|
|||
}
|
||||
*triangles = tris;
|
||||
|
||||
dm->release(dm);
|
||||
BKE_id_free(NULL, mesh);
|
||||
}
|
||||
|
|
|
@ -33,14 +33,13 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_object_fluidsim_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_layer.h"
|
||||
#include "BKE_modifier.h"
|
||||
|
||||
|
@ -80,25 +79,25 @@ static void copyData(const ModifierData *md, ModifierData *target, const int UNU
|
|||
|
||||
|
||||
|
||||
static DerivedMesh *applyModifier(
|
||||
static Mesh *applyModifier(
|
||||
ModifierData *md, const ModifierEvalContext *ctx,
|
||||
DerivedMesh *dm)
|
||||
Mesh *mesh)
|
||||
{
|
||||
FluidsimModifierData *fluidmd = (FluidsimModifierData *) md;
|
||||
DerivedMesh *result = NULL;
|
||||
Mesh *result = NULL;
|
||||
|
||||
/* check for alloc failing */
|
||||
if (!fluidmd->fss) {
|
||||
initData(md);
|
||||
|
||||
if (!fluidmd->fss) {
|
||||
return dm;
|
||||
return mesh;
|
||||
}
|
||||
}
|
||||
|
||||
result = fluidsimModifier_do(fluidmd, ctx, dm);
|
||||
result = fluidsimModifier_do(fluidmd, ctx, mesh);
|
||||
|
||||
return result ? result : dm;
|
||||
return result ? result : mesh;
|
||||
}
|
||||
|
||||
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
|
||||
|
@ -145,14 +144,14 @@ ModifierTypeInfo modifierType_Fluidsim = {
|
|||
/* deformMatrices_DM */ NULL,
|
||||
/* deformVertsEM_DM */ NULL,
|
||||
/* deformMatricesEM_DM*/NULL,
|
||||
/* applyModifier_DM */ applyModifier,
|
||||
/* applyModifier_DM */ NULL,
|
||||
/* applyModifierEM_DM */NULL,
|
||||
|
||||
/* deformVerts */ NULL,
|
||||
/* deformMatrices */ NULL,
|
||||
/* deformVertsEM */ NULL,
|
||||
/* deformMatricesEM */ NULL,
|
||||
/* applyModifier */ NULL,
|
||||
/* applyModifier */ applyModifier,
|
||||
/* applyModifierEM */ NULL,
|
||||
|
||||
/* initData */ initData,
|
||||
|
|
|
@ -47,8 +47,8 @@
|
|||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BKE_fluidsim.h" /* ensure definitions here match */
|
||||
#include "BKE_cdderivedmesh.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_mesh.h"
|
||||
#ifdef WITH_MOD_FLUID
|
||||
# include "BKE_global.h"
|
||||
#endif
|
||||
|
@ -165,13 +165,13 @@ void fluidsim_free(FluidsimModifierData *fluidmd)
|
|||
|
||||
#ifdef WITH_MOD_FLUID
|
||||
/* read .bobj.gz file into a fluidsimDerivedMesh struct */
|
||||
static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_example)
|
||||
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;
|
||||
DerivedMesh *dm = NULL;
|
||||
Mesh *mesh = NULL;
|
||||
MPoly *mp;
|
||||
MLoop *ml;
|
||||
MVert *mv;
|
||||
|
@ -220,9 +220,9 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
|
|||
return NULL;
|
||||
}
|
||||
|
||||
dm = CDDM_new(numverts, 0, 0, numfaces * 3, numfaces);
|
||||
mesh = BKE_mesh_new_nomain(numverts, 0, 0, numfaces * 3, numfaces);
|
||||
|
||||
if (!dm) {
|
||||
if (!mesh) {
|
||||
gzclose(gzf);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
|
|||
gotBytes = gzread(gzf, &wri, sizeof(wri));
|
||||
|
||||
/* read vertex position from file */
|
||||
mv = CDDM_get_verts(dm);
|
||||
mv = mesh->mvert;
|
||||
|
||||
for (i = 0; i < numverts; i++, mv++)
|
||||
gotBytes = gzread(gzf, mv->co, sizeof(float) * 3);
|
||||
|
@ -239,16 +239,16 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
|
|||
/* should be the same as numverts */
|
||||
gotBytes = gzread(gzf, &wri, sizeof(wri));
|
||||
if (wri != numverts) {
|
||||
if (dm)
|
||||
dm->release(dm);
|
||||
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 (dm)
|
||||
dm->release(dm);
|
||||
if (mesh)
|
||||
BKE_id_free(NULL, mesh);
|
||||
gzclose(gzf);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -264,16 +264,16 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
|
|||
|
||||
if (wri != numfaces) {
|
||||
printf("Fluidsim: error in reading data from file.\n");
|
||||
if (dm)
|
||||
dm->release(dm);
|
||||
if (mesh)
|
||||
BKE_id_free(NULL, mesh);
|
||||
gzclose(gzf);
|
||||
MEM_freeN(normals);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read triangles from file */
|
||||
mp = CDDM_get_polys(dm);
|
||||
ml = CDDM_get_loops(dm);
|
||||
mp = mesh->mpoly;
|
||||
ml = mesh->mloop;
|
||||
for (i = 0; i < numfaces; i++, mp++, ml += 3) {
|
||||
int face[3];
|
||||
|
||||
|
@ -294,13 +294,12 @@ static DerivedMesh *fluidsim_read_obj(const char *filename, const MPoly *mp_exam
|
|||
|
||||
gzclose(gzf);
|
||||
|
||||
CDDM_calc_edges(dm);
|
||||
|
||||
CDDM_apply_vert_normals(dm, (short (*)[3])normals);
|
||||
BKE_mesh_calc_edges(mesh, false, false);
|
||||
BKE_mesh_apply_vert_normals(mesh, (short (*)[3])normals);
|
||||
MEM_freeN(normals);
|
||||
|
||||
// CDDM_calc_normals(result);
|
||||
return dm;
|
||||
return mesh;
|
||||
}
|
||||
|
||||
|
||||
|
@ -370,14 +369,14 @@ void fluid_estimate_memory(Object *ob, FluidsimSettings *fss, char *value)
|
|||
|
||||
|
||||
/* read zipped fluidsim velocities into the co's of the fluidsimsettings normals struct */
|
||||
static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *dm, char *filename)
|
||||
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 = dm->getNumVerts(dm);
|
||||
int totvert = mesh->totvert;
|
||||
FluidVertexVelocity *velarray = NULL;
|
||||
|
||||
/* mesh and vverts have to be valid from loading... */
|
||||
|
@ -391,7 +390,7 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *
|
|||
|
||||
if (fss->domainNovecgen > 0) return;
|
||||
|
||||
fss->meshVelocities = MEM_calloc_arrayN(dm->getNumVerts(dm), sizeof(FluidVertexVelocity), "Fluidsim_velocities");
|
||||
fss->meshVelocities = MEM_calloc_arrayN(mesh->totvert, sizeof(FluidVertexVelocity), "Fluidsim_velocities");
|
||||
fss->totvert = totvert;
|
||||
|
||||
velarray = fss->meshVelocities;
|
||||
|
@ -426,8 +425,8 @@ static void fluidsim_read_vel_cache(FluidsimModifierData *fluidmd, DerivedMesh *
|
|||
gzclose(gzf);
|
||||
}
|
||||
|
||||
static DerivedMesh *fluidsim_read_cache(
|
||||
Object *ob, DerivedMesh *orgdm,
|
||||
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 */
|
||||
|
@ -436,7 +435,7 @@ static DerivedMesh *fluidsim_read_cache(
|
|||
|
||||
char targetFile[FILE_MAX];
|
||||
FluidsimSettings *fss = fluidmd->fss;
|
||||
DerivedMesh *dm = NULL;
|
||||
Mesh *newmesh = NULL;
|
||||
MPoly *mpoly;
|
||||
MPoly mp_example = {0};
|
||||
|
||||
|
@ -467,15 +466,15 @@ static DerivedMesh *fluidsim_read_cache(
|
|||
|
||||
/* assign material + flags to new dm
|
||||
* if there's no faces in original dm, keep materials and flags unchanged */
|
||||
mpoly = orgdm->getPolyArray(orgdm);
|
||||
mpoly = orgmesh->mpoly;
|
||||
if (mpoly) {
|
||||
mp_example = *mpoly;
|
||||
}
|
||||
/* else leave NULL'd */
|
||||
|
||||
dm = fluidsim_read_obj(targetFile, &mp_example);
|
||||
newmesh = fluidsim_read_obj(targetFile, &mp_example);
|
||||
|
||||
if (!dm) {
|
||||
if (!newmesh) {
|
||||
/* switch, abort background rendering when fluidsim mesh is missing */
|
||||
const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp
|
||||
|
||||
|
@ -498,7 +497,7 @@ static DerivedMesh *fluidsim_read_cache(
|
|||
* 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, dm, targetFile);
|
||||
fluidsim_read_vel_cache(fluidmd, newmesh, targetFile);
|
||||
}
|
||||
else {
|
||||
if (fss->meshVelocities)
|
||||
|
@ -507,21 +506,21 @@ static DerivedMesh *fluidsim_read_cache(
|
|||
fss->meshVelocities = NULL;
|
||||
}
|
||||
|
||||
return dm;
|
||||
return newmesh;
|
||||
}
|
||||
#endif // WITH_MOD_FLUID
|
||||
|
||||
DerivedMesh *fluidsimModifier_do(
|
||||
Mesh *fluidsimModifier_do(
|
||||
FluidsimModifierData *fluidmd,
|
||||
const ModifierEvalContext *ctx,
|
||||
DerivedMesh *dm)
|
||||
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;
|
||||
DerivedMesh *result = NULL;
|
||||
Mesh *result = NULL;
|
||||
int framenr;
|
||||
FluidsimSettings *fss = NULL;
|
||||
|
||||
|
@ -529,11 +528,11 @@ DerivedMesh *fluidsimModifier_do(
|
|||
|
||||
/* only handle fluidsim domains */
|
||||
if (fluidmd && fluidmd->fss && (fluidmd->fss->type != OB_FLUIDSIM_DOMAIN))
|
||||
return dm;
|
||||
return mesh;
|
||||
|
||||
/* sanity check */
|
||||
if (!fluidmd || !fluidmd->fss)
|
||||
return dm;
|
||||
return mesh;
|
||||
|
||||
fss = fluidmd->fss;
|
||||
|
||||
|
@ -548,10 +547,10 @@ DerivedMesh *fluidsimModifier_do(
|
|||
|
||||
/* try to read from cache */
|
||||
/* if the frame is there, fine, otherwise don't do anything */
|
||||
if ((result = fluidsim_read_cache(ob, dm, fluidmd, framenr, useRenderParams)))
|
||||
if ((result = fluidsim_read_cache(ob, mesh, fluidmd, framenr, useRenderParams)))
|
||||
return result;
|
||||
|
||||
return dm;
|
||||
return mesh;
|
||||
#else
|
||||
/* unused */
|
||||
(void)fluidmd;
|
||||
|
|
|
@ -36,16 +36,16 @@
|
|||
struct Object;
|
||||
struct Scene;
|
||||
struct FluidsimModifierData;
|
||||
struct DerivedMesh;
|
||||
struct Mesh;
|
||||
struct ModifierEvalContext;
|
||||
|
||||
/* new fluid-modifier interface */
|
||||
void fluidsim_init(struct FluidsimModifierData *fluidmd);
|
||||
void fluidsim_free(struct FluidsimModifierData *fluidmd);
|
||||
|
||||
struct DerivedMesh *fluidsimModifier_do(
|
||||
struct Mesh *fluidsimModifier_do(
|
||||
struct FluidsimModifierData *fluidmd,
|
||||
const struct ModifierEvalContext *ctx,
|
||||
struct DerivedMesh *dm);
|
||||
struct Mesh *dm);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue