Commit: 281db895f33a3481d1a5b7689cb2e5c914613261 Author: Geraldine Chua Date: Tue Jul 10 15:56:23 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB281db895f33a3481d1a5b7689cb2e5c914613261
Simple OpenVDB import GUI. =================================================================== M release/scripts/startup/bl_ui/space_info.py M source/blender/blenkernel/BKE_pointcache.h M source/blender/blenkernel/intern/pointcache.c M source/blender/editors/io/CMakeLists.txt A source/blender/editors/io/io_openvdb.c A source/blender/editors/io/io_openvdb.h M source/blender/editors/io/io_ops.c M source/blender/editors/space_file/filelist.c M source/blender/editors/space_file/filesel.c M source/blender/makesdna/DNA_space_types.h M source/blender/windowmanager/intern/wm_operator_props.c =================================================================== diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py index 180e48af386..64477d56e55 100644 --- a/release/scripts/startup/bl_ui/space_info.py +++ b/release/scripts/startup/bl_ui/space_info.py @@ -173,6 +173,8 @@ class INFO_MT_file_import(Menu): self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)") if bpy.app.build_options.alembic: self.layout.operator("wm.alembic_import", text="Alembic (.abc)") + if bpy.app.build_options.openvdb: + self.layout.operator("wm.openvdb_import", text="OpenVDB (.vdb)") class INFO_MT_file_export(Menu): diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index cc60df1b2d6..8873b70f992 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -125,6 +125,7 @@ typedef struct PTCacheFile { enum { PTCACHE_FILE_PTCACHE = 0, PTCACHE_FILE_OPENVDB = 1, + PTCACHE_FILE_OPENVDB_EXTERN = 2, }; typedef struct PTCacheID { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 3d1cdba1cdd..a8b63e131a2 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1156,6 +1156,96 @@ static int ptcache_smoke_openvdb_read(struct OpenVDBReader *reader, void *smoke_ return 1; } + +static int ptcache_smoke_openvdb_extern_read(struct OpenVDBReader *reader, void *smoke_v) +{ + SmokeModifierData *smd = (SmokeModifierData *)smoke_v; + + if (!smd) { + return 0; + } + + SmokeDomainSettings *sds = smd->domain; + + int fluid_fields = smoke_get_data_flags(sds); + int cache_fields = 0; + bool reallocate = false; + int res[3], res_min[3], res_max[3]; + + if (!OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_DENSITY) && + !OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_FLAME)) + { + return 0; + } + + if (!OpenVDBReader_get_detailed_bounds(reader, res_min, res_max, res, + sds->p0, sds->p1, sds->cell_size)) + { + modifier_setError((ModifierData *)smd, "Imported OpenVDB grids have different transformations"); + } + + sds->res_min[0] = sds->res_min[1] = sds->res_min[2] = 0; + VECSUB(sds->res_max, res_max, res_min); + sub_v3_v3v3(sds->global_size, sds->p1, sds->p0); + + if (sds->res[0] != res[0] || sds->res[1] != res[1] || sds->res[2] != res[2]) + { + reallocate = true; + VECCOPY(sds->res, res); + } + + /* check if active fields have changed */ + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_HEAT) || + OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_TEMPERATURE)) { + cache_fields |= SM_ACTIVE_HEAT; + } + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_FLAME)) { + cache_fields |= SM_ACTIVE_FIRE; + } + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_COLOR)) { + cache_fields |= SM_ACTIVE_COLORS; + } + + reallocate = (reallocate || ((fluid_fields == cache_fields) && (sds->active_fields == cache_fields))); + + /* reallocate fluid if needed */ + if (reallocate) { + sds->active_fields = cache_fields; + sds->maxres = MAX3(sds->base_res[0], sds->base_res[1], sds->base_res[2]); + sds->dx = 1.0f / sds->maxres; + smoke_reallocate_fluid(sds, sds->dx, sds->res, 1); + sds->total_cells = sds->res[0] * sds->res[1] * sds->res[2]; + } + + if (sds->fluid) { + float dt, dx, *dens, *react, *fuel, *flame, *heat, *heatold, *vx, *vy, *vz, *r, *g, *b; + unsigned char *obstacles; + + smoke_export(sds->fluid, &dt, &dx, &dens, &react, &flame, &fuel, &heat, + &heatold, &vx, &vy, &vz, &r, &g, &b, &obstacles); + + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_DENSITY)) { + OpenVDB_import_grid_fl(reader, vdb_grid_name(VDB_SMOKE_DENSITY), &dens, sds->res); + } + if(OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_HEAT)) { + OpenVDB_import_grid_fl(reader, vdb_grid_name(VDB_SMOKE_HEAT), &heat, sds->res); + } + else if(OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_TEMPERATURE)) { + OpenVDB_import_grid_fl(reader, vdb_grid_name(VDB_SMOKE_TEMPERATURE), &heat, sds->res); + } + if (cache_fields & SM_ACTIVE_FIRE) { + OpenVDB_import_grid_fl(reader, vdb_grid_name(VDB_SMOKE_FLAME), &flame, sds->res); + } + if (cache_fields & SM_ACTIVE_COLORS) { + OpenVDB_import_grid_vec(reader, vdb_grid_name(VDB_SMOKE_COLOR), &r, &g, &b, sds->res); + } + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_VELOCITY)) { + OpenVDB_import_grid_vec(reader, vdb_grid_name(VDB_SMOKE_VELOCITY), &vx, &vy, &vz, sds->res); + } + } + + return 1; +} #endif #else // WITH_SMOKE @@ -1177,6 +1267,12 @@ static int ptcache_smoke_openvdb_read(struct OpenVDBReader *reader, void *smoke_ UNUSED_VARS(reader, smoke_v); return 0; } + +static int ptcache_smoke_openvdb_extern_read(struct OpenVDBReader *reader, void *smoke_v) +{ + UNUSED_VARS(reader, smoke_v); + return 0; +} #endif static int ptcache_dynamicpaint_totpoint(void *sd, int UNUSED(cfra)) @@ -1544,7 +1640,7 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo pid->write_stream = ptcache_smoke_write; pid->write_openvdb_stream = ptcache_smoke_openvdb_write; - pid->read_openvdb_stream = ptcache_smoke_openvdb_read; + pid->read_openvdb_stream = (sds->cache_file_format == PTCACHE_FILE_OPENVDB_EXTERN ? ptcache_smoke_openvdb_extern_read : ptcache_smoke_openvdb_read); pid->write_extra_data = NULL; pid->read_extra_data = NULL; @@ -1868,6 +1964,19 @@ static int ptcache_filename(PTCacheID *pid, char *filename, int cfra, short do_p return len; /* make sure the above string is always 16 chars */ } +static void openvdb_filepath(PTCacheID *pid, char *filepath) +{ + SmokeModifierData *smd = (SmokeModifierData *)pid->calldata; + + BLI_strncpy(filepath, smd->domain->openvdb_filepath, 1024); + + if (BLI_path_is_rel(filepath)) { + Library *lib = (pid->ob) ? pid->ob->id.lib : NULL; + const char *blendfilename = (lib && (pid->cache->flag & PTCACHE_IGNORE_LIBPATH) == 0) ? lib->filepath: G.main->name; + BLI_path_abs(filepath, blendfilename); + } +} + /* youll need to close yourself after! */ static PTCacheFile *ptcache_file_open(PTCacheID *pid, int mode, int cfra) { @@ -2525,6 +2634,30 @@ static int ptcache_read_openvdb_stream(PTCacheID *pid, int cfra) #endif } +static int ptcache_read_openvdb_extern_stream(PTCacheID *pid) +{ +#if defined(WITH_OPENVDB) && defined(WITH_SMOKE) + char filepath[FILE_MAX * 2]; + + openvdb_filepath(pid, filepath); + + if (!BLI_exists(filepath)) { + return 0; + } + + struct OpenVDBReader *reader = OpenVDBReader_create(); + OpenVDBReader_open(reader, filepath); + + int result = pid->read_openvdb_stream(reader, pid->calldata); + + OpenVDBReader_free(reader); + return result; +#else + UNUSED_VARS(pid); + return 0; +#endif +} + static int ptcache_read(PTCacheID *pid, int cfra) { PTCacheMem *pm = NULL; @@ -2639,6 +2772,10 @@ int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old) int cfrai = (int)floor(cfra), cfra1=0, cfra2=0; int ret = 0; + if (pid->file_type == PTCACHE_FILE_OPENVDB_EXTERN && pid->read_openvdb_stream) { + return ptcache_read_openvdb_extern_stream(pid); + } + /* nothing to read to */ if (pid->totpoint(pid->calldata, cfrai) == 0) return 0; @@ -3097,6 +3234,14 @@ int BKE_ptcache_id_exist(PTCacheID *pid, int cfra) if (!pid->cache) return 0; + if (pid->file_type == PTCACHE_FILE_OPENVDB_EXTERN) { + char filename[MAX_PTCACHE_PATH]; + + openvdb_filepath(pid, filename); + + return BLI_exists(filename); + } + if (cfra<pid->cache->startframe || cfra > pid->cache->endframe) return 0; diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt index b3bbce939a5..2a6f1a27564 100644 --- a/source/blender/editors/io/CMakeLists.txt +++ b/source/blender/editors/io/CMakeLists.txt @@ -30,6 +30,7 @@ set(INC ../../collada ../../alembic ../../../../intern/guardedalloc + ../../../../intern/openvdb ) set(INC_SYS @@ -40,11 +41,13 @@ set(SRC io_alembic.c io_cache.c io_collada.c + io_openvdb.c io_ops.c io_alembic.h io_cache.h io_collada.h + io_openvdb.h io_ops.h ) @@ -60,6 +63,10 @@ if(WITH_ALEMBIC) endif() endif() +if(WITH_OPENVDB) + add_definitions(-DWITH_OPENVDB) +endif() + if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() diff --git a/source/blender/editors/io/io_openvdb.c b/source/blender/editors/io/io_openvdb.c new file mode 100644 index 00000000000..16beac0e195 --- /dev/null +++ b/source/blender/editors/io/io_openvdb.c @@ -0,0 +1,86 @@ + +#include "DNA_object_types.h" +#include "DNA_smoke_types.h" +#include "DNA_space_types.h" + +#include "BKE_context.h" +#include "BKE_global.h" +#include "BKE_main.h" +#include "BKE_modifier.h" +#include "BKE_object.h" +#include "BKE_pointcache.h" +#include "BKE_report.h" +#include "BKE_smoke.h" + +#include "BLI_fileops.h" +#include "BLI_listbase.h" +#include "BLI_path_util.h" +#include "BLI_string.h" + +#include "RNA_access.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "io_openvdb.h" +#include "openvdb_capi.h" + +static void wm_openvdb_import_draw(bContext *UNUSED(C), wmOperator *op) +{ + PointerRNA ptr; + + RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr); +} + +static int wm_openvdb_import_exec(bContext *C, wmOperator *op) +{ + if (!RNA_struct_property_is_set(op->ptr, "filepath")) { + BKE_report(op->reports, RPT_ERROR, "No filename given"); + return OPERATOR_CANCELLED; + } + + char filepath[FILE_MAX]; + char filename[64]; + + RNA_string_get(op->ptr, "filepath", filepath); + BLI_split_file_part(filepath, filename, 64); + + Main *bmain = CTX_data_main(C); + Scene *scene = CTX_data_scene(C); + Object *ob = BKE_object_add(bmain, scene, OB_MESH, filename); + + BLI_path_abs(filepath, ID_BLEND_PATH(G.main, (ID *)ob)); + if (!BLI_exists(filepath)) { + return OPERATOR_CANCELLED; + } + + ModifierData *md = modifier_new(eModifierType_Smoke); + BLI_addtail(&ob->modifiers, md); + + SmokeModifierData *smd = (SmokeModifierData *)md; + smd->type = MOD_SMOKE_TYPE_DOMAIN; + smokeModifier_createType(smd); + + smd->domain->flags |= MOD_SMOKE_OPENVDB_EXTERN; + smd->domain @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs