Blender V5.3
blenkernel/intern/volume.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <optional>
10
11#include "MEM_guardedalloc.h"
12
13#include "DNA_material_types.h"
14#include "DNA_object_types.h"
15#include "DNA_scene_types.h"
16#include "DNA_volume_types.h"
17
18#include "BLI_bounds.hh"
19#include "BLI_fileops.hh"
20#include "BLI_index_range.hh"
21#include "BLI_math_base_c.hh"
24#include "BLI_path_utils.hh"
25#include "BLI_string.hh"
26#include "BLI_string_ref.hh"
27#include "BLI_utildefines.hh"
28
29#include "BKE_anim_data.hh"
31#include "BKE_bpath.hh"
32#include "BKE_geometry_set.hh"
33#include "BKE_global.hh"
34#include "BKE_idtype.hh"
35#include "BKE_lib_id.hh"
36#include "BKE_lib_query.hh"
37#include "BKE_lib_remap.hh"
38#include "BKE_library.hh"
39#include "BKE_main.hh"
40#include "BKE_modifier.hh"
41#include "BKE_object.hh"
42#include "BKE_object_types.hh"
43#include "BKE_packedFile.hh"
44#include "BKE_report.hh"
45#include "BKE_scene.hh"
46#include "BKE_volume.hh"
47#include "BKE_volume_grid.hh"
49#include "BKE_volume_openvdb.hh"
50
51#include "BLT_translation.hh"
52
54
55#include "BLO_read_write.hh"
56
57#include "CLG_log.h"
58
59#ifdef WITH_OPENVDB
60# include <list>
61
62# include <openvdb/openvdb.h>
63# include <openvdb/points/PointDataGrid.h>
64# include <openvdb/tools/GridTransformer.h>
65#endif
66
67namespace blender {
68
69#define VOLUME_FRAME_NONE INT_MAX
70
71using bke::GVolumeGrid;
72
73#ifdef WITH_OPENVDB
74static CLG_LogRef LOG = {"geom.volume"};
75
76/* Volume Grid Vector
77 *
78 * List of grids contained in a volume datablock. This is runtime-only data,
79 * the actual grids are always saved in a VDB file. */
80
81struct VolumeGridVector : public std::list<GVolumeGrid> {
82 VolumeGridVector() : metadata(new openvdb::MetaMap())
83 {
84 filepath[0] = '\0';
85 }
86
87 VolumeGridVector(const VolumeGridVector &other)
88 : std::list<GVolumeGrid>(other), error_msg(other.error_msg), metadata(other.metadata)
89 {
90 memcpy(filepath, other.filepath, sizeof(filepath));
91 }
92
93 bool is_loaded() const
94 {
95 return filepath[0] != '\0';
96 }
97
98 void clear_all()
99 {
100 std::list<GVolumeGrid>::clear();
101 filepath[0] = '\0';
102 error_msg.clear();
103 metadata.reset();
104 }
105
106 /* Mutex for file loading of grids list. `const` write access to the fields after this must be
107 * protected by locking with this mutex. */
108 mutable Mutex mutex;
109 /* Absolute file path that grids have been loaded from. */
110 char filepath[FILE_MAX];
111 /* File loading error message. */
112 std::string error_msg;
113 /* File Metadata. */
114 openvdb::MetaMap::Ptr metadata;
115};
116#endif
117
118/* Module */
119
121{
122#ifdef WITH_OPENVDB
123 openvdb::initialize();
124#endif
125}
126
127/* Volume datablock */
128
129static void volume_init_data(ID *id)
130{
131 Volume *volume = id_cast<Volume *>(id);
132
133 INIT_DEFAULT_STRUCT_AFTER(volume, id);
134
135 volume->runtime = MEM_new<bke::VolumeRuntime>(__func__);
136
137 BKE_volume_init_grids(volume);
138
139 STRNCPY(volume->velocity_grid, "velocity");
140}
141
142static void volume_copy_data(Main * /*bmain*/,
143 std::optional<Library *> /*owner_library*/,
144 ID *id_dst,
145 const ID *id_src,
146 const int /*flag*/)
147{
148 Volume *volume_dst = id_cast<Volume *>(id_dst);
149 const Volume *volume_src = id_cast<const Volume *>(id_src);
150 volume_dst->runtime = MEM_new<bke::VolumeRuntime>(__func__);
151
152 if (volume_src->packedfile) {
153 volume_dst->packedfile = BKE_packedfile_duplicate(volume_src->packedfile);
154 }
155
156 volume_dst->mat = MEM_dupalloc(volume_src->mat);
157#ifdef WITH_OPENVDB
158 if (volume_src->runtime->grids) {
159 const VolumeGridVector &grids_src = *(volume_src->runtime->grids);
160 volume_dst->runtime->grids = MEM_new<VolumeGridVector>(__func__, grids_src);
161 }
162#endif
163
164 volume_dst->runtime->frame = volume_src->runtime->frame;
165 STRNCPY(volume_dst->runtime->velocity_x_grid, volume_src->runtime->velocity_x_grid);
166 STRNCPY(volume_dst->runtime->velocity_y_grid, volume_src->runtime->velocity_y_grid);
167 STRNCPY(volume_dst->runtime->velocity_z_grid, volume_src->runtime->velocity_z_grid);
168
169 if (volume_src->runtime->bake_materials) {
170 volume_dst->runtime->bake_materials = std::make_unique<bke::bake::BakeMaterialsList>(
171 *volume_src->runtime->bake_materials);
172 }
173
174 volume_dst->batch_cache = nullptr;
175}
176
177static void volume_free_data(ID *id)
178{
179 Volume *volume = id_cast<Volume *>(id);
180 BKE_animdata_free(&volume->id, false);
182 MEM_SAFE_DELETE(volume->mat);
183 if (volume->packedfile) {
185 volume->packedfile = nullptr;
186 }
187#ifdef WITH_OPENVDB
188 MEM_delete(volume->runtime->grids);
189 volume->runtime->grids = nullptr;
190 /* Deleting the volume might have made some grids completely unused, so they can be freed. */
191 bke::volume_grid::file_cache::unload_unused();
192#endif
193 MEM_delete(volume->runtime);
194}
195
197{
198 Volume *volume = id_cast<Volume *>(id);
199 for (int i = 0; i < volume->totcol; i++) {
201 }
202}
203
204static void volume_foreach_cache(ID *id,
205 IDTypeForeachCacheFunctionCallback function_callback,
206 void *user_data)
207{
208 Volume *volume = id_cast<Volume *>(id);
209 IDCacheKey key = {
210 /*id_session_uid*/ id->session_uid,
211 /*identifier*/ 1,
212 };
213
214 function_callback(id, &key, reinterpret_cast<void **>(&volume->runtime->grids), 0, user_data);
215}
216
217static void volume_foreach_path(ID *id, BPathForeachPathData *bpath_data)
218{
219 Volume *volume = reinterpret_cast<Volume *>(id);
220
221 if (volume->packedfile != nullptr &&
222 (bpath_data->flag & BKE_BPATH_FOREACH_PATH_SKIP_PACKED) != 0)
223 {
224 return;
225 }
226
227 if (volume->is_sequence && (bpath_data->flag & BKE_BPATH_FOREACH_PATH_EXPAND_SEQUENCES) != 0 &&
228 volume->filepath[0] != '\0')
229 {
230 char abs_filepath[FILE_MAX];
231 STRNCPY(abs_filepath, volume->filepath);
232 if (bpath_data->absolute_base_path) {
233 BLI_path_abs(abs_filepath, bpath_data->absolute_base_path);
234 }
235 else {
236 BLI_path_abs(abs_filepath, ID_BLEND_PATH(bpath_data->bmain, &volume->id));
237 }
238
239 bpath_data->is_expanded = true;
240 BKE_bpath_sequence_filepaths_foreach(abs_filepath, [&](StringRef frame_filepath) {
241 char frame_path[FILE_MAX];
242 frame_filepath.copy_utf8_truncated(frame_path);
243 BKE_bpath_foreach_path_readonly_process(bpath_data, frame_path);
244 });
245 bpath_data->is_expanded = false;
246 return;
247 }
248
249 BKE_bpath_foreach_path_fixed_process(bpath_data, volume->filepath, sizeof(volume->filepath));
250}
251
252static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_address)
253{
254 Volume *volume = id_cast<Volume *>(id);
255 const bool is_undo = writer->is_undo();
256
257 /* Do not store packed files in case this is a library override ID. */
258 if (ID_IS_OVERRIDE_LIBRARY(volume) && !is_undo) {
259 volume->packedfile = nullptr;
260 }
261
262 /* write LibData */
263 writer->write_id_struct(id_address, volume);
264 BKE_id_blend_write(writer, &volume->id);
265
266 /* direct data */
267 writer->write_pointer_array(volume->totcol, volume->mat);
268
269 BKE_packedfile_blend_write(writer, volume->packedfile);
270}
271
273{
274 Volume *volume = id_cast<Volume *>(id);
275 volume->runtime = MEM_new<bke::VolumeRuntime>(__func__);
276
277 BKE_packedfile_blend_read(reader, &volume->packedfile, volume->filepath);
278 volume->runtime->frame = 0;
279
280 /* materials */
281 BLO_read_pointer_array_and_validate_size(reader, &volume->mat, &volume->totcol);
282}
283
285{
286 Volume *volume = reinterpret_cast<Volume *>(id);
287
288 /* Needs to be done *after* cache pointers are restored (call to
289 * `foreach_cache`/`blo_cache_storage_entry_restore_in_new`), easier for now to do it in
290 * lib_link... */
291 BKE_volume_init_grids(volume);
292}
293
295 .id_code = Volume::id_type,
296 .id_filter = FILTER_ID_VO,
297 .dependencies_id_types = FILTER_ID_MA,
298 .main_listbase_index = INDEX_ID_VO,
299 .struct_size = sizeof(Volume),
300 .name = "Volume",
301 .name_plural = N_("volumes"),
302 .translation_context = BLT_I18NCONTEXT_ID_VOLUME,
304 .asset_type_info = nullptr,
305
306 .init_data = volume_init_data,
307 .copy_data = volume_copy_data,
308 .free_data = volume_free_data,
309 .make_local = nullptr,
310 .foreach_id = volume_foreach_id,
311 .foreach_cache = volume_foreach_cache,
312 .foreach_path = volume_foreach_path,
313 .foreach_working_space_color = nullptr,
314 .foreach_asset_weak_reference = nullptr,
315 .owner_pointer_get = nullptr,
316
317 .blend_write = volume_blend_write,
318 .blend_read_data = volume_blend_read_data,
319 .blend_read_after_liblink = volume_blend_read_after_liblink,
320
321 .blend_read_undo_preserve = nullptr,
322
323 .lib_override_apply_post = nullptr,
324};
325
327{
328#ifdef WITH_OPENVDB
329 if (volume->runtime->grids == nullptr) {
330 volume->runtime->grids = MEM_new<VolumeGridVector>(__func__);
331 }
332#else
333 UNUSED_VARS(volume);
334#endif
335}
336
337Volume *BKE_volume_add(Main *bmain, const char *name)
338{
339 Volume *volume = BKE_id_new<Volume>(bmain, name);
340
341 return volume;
342}
343
344/* Sequence */
345
346static int volume_sequence_frame(const Depsgraph *depsgraph, const Volume *volume)
347{
348 if (!volume->is_sequence) {
349 return 0;
350 }
351
352 int path_frame, path_digits;
353 if (!(volume->is_sequence && BLI_path_frame_get(volume->filepath, &path_frame, &path_digits))) {
354 return 0;
355 }
356
357 const int scene_frame = DEG_get_ctime(depsgraph);
359 const int frame_duration = volume->frame_duration;
360 const int frame_start = volume->frame_start;
361 const int frame_offset = volume->frame_offset;
362
363 if (frame_duration == 0) {
364 return VOLUME_FRAME_NONE;
365 }
366
367 int frame = scene_frame - frame_start + 1;
368
369 switch (mode) {
371 if (frame < 1 || frame > frame_duration) {
372 return VOLUME_FRAME_NONE;
373 }
374 break;
375 }
377 frame = clamp_i(frame, 1, frame_duration);
378 break;
379 }
381 frame = frame % frame_duration;
382 if (frame < 0) {
383 frame += frame_duration;
384 }
385 if (frame == 0) {
386 frame = frame_duration;
387 }
388 break;
389 }
391 const int pingpong_duration = frame_duration * 2 - 2;
392 frame = frame % pingpong_duration;
393 if (frame < 0) {
394 frame += pingpong_duration;
395 }
396 if (frame == 0) {
397 frame = pingpong_duration;
398 }
399 if (frame > frame_duration) {
400 frame = frame_duration * 2 - frame;
401 }
402 break;
403 }
404 }
405
406 /* Important to apply after, else we can't loop on e.g. frames 100 - 110. */
407 frame += frame_offset;
408
409 return frame;
410}
411
412#ifdef WITH_OPENVDB
413static void volume_filepath_get(const Main *bmain, const Volume *volume, char r_filepath[FILE_MAX])
414{
415 BLI_strncpy(r_filepath, volume->filepath, FILE_MAX);
416 BLI_path_abs(r_filepath, ID_BLEND_PATH(bmain, &volume->id));
417
418 int path_frame, path_digits;
419 if (volume->is_sequence && BLI_path_frame_get(r_filepath, &path_frame, &path_digits)) {
420 char ext[32];
421 BLI_path_frame_strip(r_filepath, ext, sizeof(ext));
422 BLI_path_frame(r_filepath, FILE_MAX, volume->runtime->frame, path_digits);
423 BLI_path_extension_ensure(r_filepath, FILE_MAX, ext);
424 }
425}
426#endif
427
428/* File Load */
429
430bool BKE_volume_is_loaded(const Volume *volume)
431{
432#ifdef WITH_OPENVDB
433 /* Test if there is a file to load, or if already loaded. */
434 return (volume->filepath[0] == '\0' || volume->runtime->grids->is_loaded());
435#else
436 UNUSED_VARS(volume);
437 return true;
438#endif
439}
440
441bool BKE_volume_set_velocity_grid_by_name(Volume *volume, const StringRef ref_base_name)
442{
443 const std::string base_name = ref_base_name;
444
445 if (BKE_volume_grid_find(volume, base_name)) {
446 STRNCPY(volume->velocity_grid, base_name.c_str());
447 volume->runtime->velocity_x_grid[0] = '\0';
448 volume->runtime->velocity_y_grid[0] = '\0';
449 volume->runtime->velocity_z_grid[0] = '\0';
450 return true;
451 }
452
453 /* It could be that the velocity grid is split in multiple grids, try with known postfixes. */
454 const StringRefNull postfixes[][3] = {{"x", "y", "z"}, {".x", ".y", ".z"}, {"_x", "_y", "_z"}};
455
456 for (const StringRefNull *postfix : postfixes) {
457 bool found = true;
458 for (int i = 0; i < 3; i++) {
459 std::string post_fixed_name = ref_base_name + postfix[i];
460 if (!BKE_volume_grid_find(volume, post_fixed_name)) {
461 found = false;
462 break;
463 }
464 }
465
466 if (!found) {
467 continue;
468 }
469
470 /* Save the base name as well. */
471 STRNCPY(volume->velocity_grid, base_name.c_str());
472 STRNCPY(volume->runtime->velocity_x_grid, (ref_base_name + postfix[0]).c_str());
473 STRNCPY(volume->runtime->velocity_y_grid, (ref_base_name + postfix[1]).c_str());
474 STRNCPY(volume->runtime->velocity_z_grid, (ref_base_name + postfix[2]).c_str());
475 return true;
476 }
477
478 /* Reset to avoid potential issues. */
479 volume->velocity_grid[0] = '\0';
480 volume->runtime->velocity_x_grid[0] = '\0';
481 volume->runtime->velocity_y_grid[0] = '\0';
482 volume->runtime->velocity_z_grid[0] = '\0';
483 return false;
484}
485
486bool BKE_volume_load(const Volume *volume, const Main *bmain)
487{
488#ifdef WITH_OPENVDB
489 const VolumeGridVector &const_grids = *volume->runtime->grids;
490
491 if (volume->runtime->frame == VOLUME_FRAME_NONE) {
492 /* Skip loading this frame, outside of sequence range. */
493 return true;
494 }
495
496 if (BKE_volume_is_loaded(volume)) {
497 return const_grids.error_msg.empty();
498 }
499
500 /* Double-checked lock. */
501 std::lock_guard lock(const_grids.mutex);
502 if (BKE_volume_is_loaded(volume)) {
503 return const_grids.error_msg.empty();
504 }
505
506 /* Guarded by the lock, we can continue to access the grid vector,
507 * adding error messages or a new grid, etc. */
508 VolumeGridVector &grids = const_cast<VolumeGridVector &>(const_grids);
509
510 /* Get absolute file path at current frame. */
511 const char *volume_name = volume->id.name + 2;
512 char filepath[FILE_MAX];
513 volume_filepath_get(bmain, volume, filepath);
514
515 CLOG_INFO(&LOG, "Volume %s: load %s", volume_name, filepath);
516
517 /* Test if file exists. */
518 if (!BLI_exists(filepath)) {
519 grids.error_msg = BLI_path_basename(filepath) + std::string(" not found");
520 CLOG_INFO(&LOG, "Volume %s: %s", volume_name, grids.error_msg.c_str());
521 return false;
522 }
523
524 bke::volume_grid::file_cache::GridsFromFile grids_from_file =
525 bke::volume_grid::file_cache::get_all_grids_from_file(filepath, 0);
526
527 if (!grids_from_file.error_message.empty()) {
528 grids.error_msg = grids_from_file.error_message;
529 CLOG_INFO(&LOG, "Volume %s: %s", volume_name, grids.error_msg.c_str());
530 return false;
531 }
532
533 grids.metadata = std::move(grids_from_file.file_meta_data);
534 for (GVolumeGrid &volume_grid : grids_from_file.grids) {
535 grids.emplace_back(std::move(volume_grid));
536 }
537
538 /* Try to detect the velocity grid. */
539 const char *common_velocity_names[] = {"velocity", "vel", "v"};
540 for (const char *common_velocity_name : common_velocity_names) {
541 if (BKE_volume_set_velocity_grid_by_name(const_cast<Volume *>(volume), common_velocity_name)) {
542 break;
543 }
544 }
545
546 STRNCPY(grids.filepath, filepath);
547
548 return grids.error_msg.empty();
549#else
550 UNUSED_VARS(bmain, volume);
551 return true;
552#endif
553}
554
556{
557#ifdef WITH_OPENVDB
558 VolumeGridVector &grids = *volume->runtime->grids;
559 if (grids.filepath[0] != '\0') {
560 const char *volume_name = volume->id.name + 2;
561 CLOG_INFO(&LOG, "Volume %s: unload", volume_name);
562 grids.clear_all();
563 }
564#else
565 UNUSED_VARS(volume);
566#endif
567}
568
569/* File Save */
570
571bool BKE_volume_save(const Volume *volume,
572 const Main *bmain,
573 ReportList *reports,
574 const char *filepath)
575{
576#ifdef WITH_OPENVDB
577 if (!BKE_volume_load(volume, bmain)) {
578 BKE_reportf(reports, RPT_ERROR, "Could not load volume for writing");
579 return false;
580 }
581
582 VolumeGridVector &grids = *volume->runtime->grids;
583 openvdb::GridCPtrVec vdb_grids;
584
585 /* Tree users need to be kept alive for as long as the grids may be accessed. */
587
588 for (const GVolumeGrid &grid : grids) {
589 tree_tokens.append_as();
590 vdb_grids.push_back(grid->grid_ptr(tree_tokens.last()));
591 }
592
593 try {
594 openvdb::io::File file(filepath);
595 file.write(vdb_grids, *grids.metadata);
596 file.close();
597 }
598 catch (const openvdb::IoError &e) {
599 BKE_reportf(reports, RPT_ERROR, "Could not write volume: %s", e.what());
600 return false;
601 }
602 catch (...) {
603 BKE_reportf(reports, RPT_ERROR, "Could not write volume: Unknown error writing VDB file");
604 return false;
605 }
606
607 return true;
608#else
609 UNUSED_VARS(volume, bmain, reports, filepath);
610 return false;
611#endif
612}
613
614void BKE_volume_count_memory(const Volume &volume, MemoryCounter &memory)
615{
616#ifdef WITH_OPENVDB
617 if (const VolumeGridVector *grids = volume.runtime->grids) {
618 for (const GVolumeGrid &grid : *grids) {
619 grid->count_memory(memory);
620 }
621 }
622#else
623 UNUSED_VARS(volume, memory);
624#endif
625}
626
627std::optional<Bounds<float3>> BKE_volume_min_max(const Volume *volume)
628{
629#ifdef WITH_OPENVDB
630 /* TODO: if we know the volume is going to be displayed, it may be good to
631 * load it as part of dependency graph evaluation for better threading. We
632 * could also share the bounding box computation in the global volume cache. */
633 if (BKE_volume_load(const_cast<Volume *>(volume), G.main)) {
634 std::optional<Bounds<float3>> result;
635 for (const int i : IndexRange(BKE_volume_num_grids(volume))) {
636 const bke::VolumeGridData *volume_grid = BKE_volume_grid_get(volume, i);
637 bke::VolumeTreeAccessToken tree_token;
638 result = bounds::merge(result, BKE_volume_grid_bounds(volume_grid->grid_ptr(tree_token)));
639 }
640 return result;
641 }
642#else
643 UNUSED_VARS(volume);
644#endif
645 return std::nullopt;
646}
647
648bool BKE_volume_is_y_up(const Volume *volume)
649{
650 /* Simple heuristic for common files to open the right way up. */
651#ifdef WITH_OPENVDB
652 VolumeGridVector &grids = *volume->runtime->grids;
653 if (grids.metadata) {
654 openvdb::StringMetadata::ConstPtr creator =
655 grids.metadata->getMetadata<openvdb::StringMetadata>("creator");
656 if (!creator) {
657 creator = grids.metadata->getMetadata<openvdb::StringMetadata>("Creator");
658 }
659 return (creator && creator->str().starts_with("Houdini"));
660 }
661#else
662 UNUSED_VARS(volume);
663#endif
664
665 return false;
666}
667
669{
670 int num_grids = BKE_volume_num_grids(volume);
671 if (num_grids == 0) {
672 return false;
673 }
674
675 for (int i = 0; i < num_grids; i++) {
676 const bke::VolumeGridData *grid = BKE_volume_grid_get(volume, i);
678 return false;
679 }
680 }
681
682 return true;
683}
684
685/* Dependency Graph */
686
687static void volume_update_simplify_level(Main *bmain, Volume *volume, const Depsgraph *depsgraph)
688{
689#ifdef WITH_OPENVDB
690 const int simplify_level = BKE_volume_simplify_level(depsgraph);
691
692 /* Replace grids with the new simplify level variants from the cache. */
693 if (BKE_volume_load(volume, bmain)) {
694 VolumeGridVector &grids = *volume->runtime->grids;
695 std::list<GVolumeGrid> new_grids;
696 for (const GVolumeGrid &old_grid : grids) {
697 GVolumeGrid simple_grid = bke::volume_grid::file_cache::get_grid_from_file(
698 grids.filepath, old_grid->name(), simplify_level);
699 BLI_assert(simple_grid);
700 new_grids.push_back(std::move(simple_grid));
701 }
702 grids.swap(new_grids);
703 }
704#else
705 UNUSED_VARS(bmain, volume, depsgraph);
706#endif
707}
708
709static void volume_evaluate_modifiers(Depsgraph *depsgraph,
710 Scene *scene,
711 Object *object,
712 bke::GeometrySet &geometry_set)
713{
714 /* Modifier evaluation modes. */
715 const bool use_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
716 const int required_mode = use_render ? eModifierMode_Render : eModifierMode_Realtime;
717 ModifierApplyFlag apply_flag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE;
718 const ModifierEvalContext mectx = {depsgraph, object, apply_flag};
719
721
722 /* Get effective list of modifiers to execute. Some effects like shape keys
723 * are added as virtual modifiers before the user created modifiers. */
724 VirtualModifierData virtual_modifier_data;
725 ModifierData *md = BKE_modifiers_get_virtual_modifierlist(object, &virtual_modifier_data);
726
727 /* Evaluate modifiers. */
728 for (; md; md = md->next) {
730
731 if (!BKE_modifier_is_enabled(scene, md, required_mode)) {
732 continue;
733 }
734
735 bke::ScopedModifierTimer modifier_timer{*md};
736
737 if (mti->modify_geometry_set) {
738 mti->modify_geometry_set(md, &mectx, &geometry_set);
739 }
740 }
741}
742
743void BKE_volume_eval_geometry(Depsgraph *depsgraph, Volume *volume)
744{
745 Main *bmain = DEG_get_bmain(depsgraph);
746
747 /* TODO: can we avoid modifier re-evaluation when frame did not change? */
748 int frame = volume_sequence_frame(depsgraph, volume);
749 if (frame != volume->runtime->frame) {
750 BKE_volume_unload(volume);
751 volume->runtime->frame = frame;
752 }
753
754 volume_update_simplify_level(bmain, volume, depsgraph);
755
756 /* Flush back to original. */
757 if (DEG_is_active(depsgraph)) {
758 Volume *volume_orig = DEG_get_original(volume);
759 if (volume_orig->runtime->frame != volume->runtime->frame) {
760 BKE_volume_unload(volume_orig);
761 volume_orig->runtime->frame = volume->runtime->frame;
762 }
763 }
764}
765
767{
768 if (!geometry_set.has<bke::VolumeComponent>()) {
769 return nullptr;
770 }
771 auto &volume_component = geometry_set.get_component_for_write<bke::VolumeComponent>();
772 Volume *volume = volume_component.release();
773 if (volume != nullptr) {
774 /* Add back, but only as read-only non-owning component. */
775 volume_component.replace(volume, bke::GeometryOwnershipType::ReadOnly);
776 }
777 else {
778 /* The component was empty, we can remove it. */
779 geometry_set.remove<bke::VolumeComponent>();
780 }
781 return volume;
782}
783
784void BKE_volume_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
785{
786 /* Free any evaluated data and restore original data. */
788
789 /* Evaluate modifiers. */
790 Volume *volume = id_cast<Volume *>(object->data);
791 bke::GeometrySet geometry_set;
793 volume_evaluate_modifiers(depsgraph, scene, object, geometry_set);
794
795 Volume *volume_eval = take_volume_ownership_from_geometry_set(geometry_set);
796
797 /* If the geometry set did not contain a volume, we still create an empty one. */
798 if (volume_eval == nullptr) {
799 volume_eval = BKE_volume_new_for_eval(volume);
800 }
801
802 /* Assign evaluated object. */
803 const bool eval_is_owned = (volume != volume_eval);
804 BKE_object_eval_assign_data(object, &volume_eval->id, eval_is_owned);
805 object->runtime->geometry_set_eval = new bke::GeometrySet(std::move(geometry_set));
806}
807
808void BKE_volume_grids_backup_restore(Volume *volume, VolumeGridVector *grids, const char *filepath)
809{
810#ifdef WITH_OPENVDB
811 /* Restore grids after datablock was re-copied from original by depsgraph,
812 * we don't want to load them again if possible. */
814 BLI_assert(volume->runtime->grids != nullptr && grids != nullptr);
815
816 if (!grids->is_loaded()) {
817 /* No grids loaded in evaluated datablock, nothing lost by discarding. */
818 MEM_delete(grids);
819 }
820 else if (!STREQ(volume->filepath, filepath)) {
821 /* Filepath changed, discard grids from evaluated datablock. */
822 MEM_delete(grids);
823 }
824 else {
825 /* Keep grids from evaluated datablock. We might still unload them a little
826 * later in BKE_volume_eval_geometry if the frame changes. */
827 MEM_delete(volume->runtime->grids);
828 volume->runtime->grids = grids;
829 }
830#else
831 UNUSED_VARS(volume, grids, filepath);
832#endif
833}
834
835/* Draw Cache */
836
837void (*BKE_volume_batch_cache_dirty_tag_cb)(Volume *volume, int mode) = nullptr;
838void (*BKE_volume_batch_cache_free_cb)(Volume *volume) = nullptr;
839
841{
842 if (volume->batch_cache) {
844 }
845}
846
848{
849 if (volume->batch_cache) {
851 }
852}
853
854/* Grids */
855
856int BKE_volume_num_grids(const Volume *volume)
857{
858#ifdef WITH_OPENVDB
859 return volume->runtime->grids->size();
860#else
861 UNUSED_VARS(volume);
862 return 0;
863#endif
864}
865
866const char *BKE_volume_grids_error_msg(const Volume *volume)
867{
868#ifdef WITH_OPENVDB
869 return volume->runtime->grids->error_msg.c_str();
870#else
871 UNUSED_VARS(volume);
872 return "";
873#endif
874}
875
876const char *BKE_volume_grids_frame_filepath(const Volume *volume)
877{
878#ifdef WITH_OPENVDB
879 return volume->runtime->grids->filepath;
880#else
881 UNUSED_VARS(volume);
882 return "";
883#endif
884}
885
886const bke::VolumeGridData *BKE_volume_grid_get(const Volume *volume, int grid_index)
887{
888#ifdef WITH_OPENVDB
889 const VolumeGridVector &grids = *volume->runtime->grids;
890 for (const GVolumeGrid &grid : grids) {
891 if (grid_index-- == 0) {
892 return &grid.get();
893 }
894 }
895 return nullptr;
896#else
897 UNUSED_VARS(volume, grid_index);
898 return nullptr;
899#endif
900}
901
902bke::VolumeGridData *BKE_volume_grid_get_for_write(Volume *volume, int grid_index)
903{
904#ifdef WITH_OPENVDB
905 VolumeGridVector &grids = *volume->runtime->grids;
906 for (GVolumeGrid &grid_ptr : grids) {
907 if (grid_index-- == 0) {
908 return &grid_ptr.get_for_write();
909 }
910 }
911 return nullptr;
912#else
913 UNUSED_VARS(volume, grid_index);
914 return nullptr;
915#endif
916}
917
918const bke::VolumeGridData *BKE_volume_grid_active_get_for_read(const Volume *volume)
919{
920 const int num_grids = BKE_volume_num_grids(volume);
921 if (num_grids == 0) {
922 return nullptr;
923 }
924
925 const int index = clamp_i(volume->active_grid, 0, num_grids - 1);
926 return BKE_volume_grid_get(volume, index);
927}
928
929const bke::VolumeGridData *BKE_volume_grid_find(const Volume *volume, const StringRef name)
930{
931 int num_grids = BKE_volume_num_grids(volume);
932 for (int i = 0; i < num_grids; i++) {
933 const bke::VolumeGridData *grid = BKE_volume_grid_get(volume, i);
934 if (bke::volume_grid::get_name(*grid) == name) {
935 return grid;
936 }
937 }
938
939 return nullptr;
940}
941
942bke::VolumeGridData *BKE_volume_grid_find_for_write(Volume *volume, const StringRef name)
943{
944 int num_grids = BKE_volume_num_grids(volume);
945 for (int i = 0; i < num_grids; i++) {
946 const bke::VolumeGridData *grid = BKE_volume_grid_get(volume, i);
947 if (bke::volume_grid::get_name(*grid) == name) {
948 return BKE_volume_grid_get_for_write(volume, i);
949 }
950 }
951
952 return nullptr;
953}
954
955/* Grid Tree and Voxels */
956
957/* Volume Editing */
958
960{
961 Volume *volume_dst = BKE_id_new_nomain<Volume>(nullptr);
962
963 STRNCPY(volume_dst->id.name, volume_src->id.name);
964 volume_dst->mat = MEM_dupalloc(volume_src->mat);
965 volume_dst->totcol = volume_src->totcol;
966 volume_dst->render = volume_src->render;
967 volume_dst->display = volume_src->display;
968
969 return volume_dst;
970}
971
973{
974 return reinterpret_cast<Volume *>(
975 BKE_id_copy_ex(nullptr, &volume_src->id, nullptr, LIB_ID_COPY_LOCALIZE));
976}
977
978#ifdef WITH_OPENVDB
979struct CreateGridOp {
980 template<typename GridType> typename openvdb::GridBase::Ptr operator()()
981 {
982 if constexpr (std::is_same_v<GridType, openvdb::points::PointDataGrid>) {
983 return {};
984 }
985 else {
986 return GridType::create();
987 }
988 }
989};
990#endif
991
992#ifdef WITH_OPENVDB
993bke::VolumeGridData *BKE_volume_grid_add_vdb(Volume &volume,
994 const StringRef name,
995 openvdb::GridBase::Ptr vdb_grid)
996{
997 VolumeGridVector &grids = *volume.runtime->grids;
998 BLI_assert(BKE_volume_grid_find(&volume, name) == nullptr);
1000
1001 vdb_grid->setName(name);
1002 grids.emplace_back(GVolumeGrid(std::move(vdb_grid)));
1003 return &grids.back().get_for_write();
1004}
1005
1006void BKE_volume_metadata_set(Volume &volume, openvdb::MetaMap::Ptr metadata)
1007{
1008 volume.runtime->grids->metadata = metadata;
1009}
1010#endif
1011
1012void BKE_volume_grid_remove(Volume *volume, const bke::VolumeGridData *grid)
1013{
1014#ifdef WITH_OPENVDB
1015 VolumeGridVector &grids = *volume->runtime->grids;
1016 for (VolumeGridVector::iterator it = grids.begin(); it != grids.end(); it++) {
1017 if (&it->get() == grid) {
1018 grids.erase(it);
1019 break;
1020 }
1021 }
1022#else
1023 UNUSED_VARS(volume, grid);
1024#endif
1025}
1026
1027void BKE_volume_grid_add(Volume *volume, const bke::VolumeGridData &grid)
1028{
1029#ifdef WITH_OPENVDB
1030 VolumeGridVector &grids = *volume->runtime->grids;
1031 grids.push_back(GVolumeGrid(&grid));
1032#else
1033 UNUSED_VARS(volume, grid);
1034#endif
1035}
1036
1038{
1039#ifdef WITH_OPENVDB
1040 /* Limit taken from openvdb/math/Maps.h. */
1041 return std::abs(determinant) >= 3.0 * openvdb::math::Tolerance<double>::value();
1042#else
1044 return true;
1045#endif
1046}
1047
1049{
1050 return BKE_volume_grid_determinant_valid(voxel_size[0] * voxel_size[1] * voxel_size[2]);
1051}
1052
1057
1058int BKE_volume_simplify_level(const Depsgraph *depsgraph)
1059{
1060 if (DEG_get_mode(depsgraph) != DAG_EVAL_RENDER) {
1061 const Scene *scene = DEG_get_input_scene(depsgraph);
1062 if (scene->r.mode & R_SIMPLIFY) {
1063 const float simplify = scene->r.simplify_volumes;
1064 if (simplify == 0.0f) {
1065 /* log2 is not defined at 0.0f, so just use some high simplify level. */
1066 return 16;
1067 }
1068 return ceilf(-log2(simplify));
1069 }
1070 }
1071 return 0;
1072}
1073
1074float BKE_volume_simplify_factor(const Depsgraph *depsgraph)
1075{
1076 if (DEG_get_mode(depsgraph) != DAG_EVAL_RENDER) {
1077 const Scene *scene = DEG_get_input_scene(depsgraph);
1078 if (scene->r.mode & R_SIMPLIFY) {
1079 return scene->r.simplify_volumes;
1080 }
1081 }
1082 return 1.0f;
1083}
1084
1085/* OpenVDB Grid Access */
1086
1087#ifdef WITH_OPENVDB
1088
1089std::optional<Bounds<float3>> BKE_volume_grid_bounds(openvdb::GridBase::ConstPtr grid)
1090{
1091 /* TODO: we can get this from grid metadata in some cases? */
1092 openvdb::CoordBBox coordbbox;
1093 if (!grid->baseTree().evalLeafBoundingBox(coordbbox)) {
1094 return std::nullopt;
1095 }
1096
1097 openvdb::BBoxd index_bbox = {
1098 openvdb::BBoxd(coordbbox.min().asVec3d(), coordbbox.max().asVec3d())};
1099 /* Add half voxel padding that is expected by volume rendering code. */
1100 index_bbox.expand(0.5);
1101
1102 const openvdb::BBoxd bbox = grid->transform().indexToWorld(index_bbox);
1103 return Bounds<float3>{float3(bbox.min().asPointer()), float3(bbox.max().asPointer())};
1104}
1105
1106openvdb::GridBase::ConstPtr BKE_volume_grid_shallow_transform(openvdb::GridBase::ConstPtr grid,
1107 const float4x4 &transform)
1108{
1109 openvdb::math::Transform::Ptr grid_transform = grid->transform().copy();
1110 grid_transform->postMult(openvdb::Mat4d((float *)transform.ptr()));
1111
1112 /* Create a transformed grid. The underlying tree is shared. */
1113 return grid->copyGridReplacingTransform(grid_transform);
1114}
1115
1116float4x4 BKE_volume_transform_to_blender(const openvdb::math::Transform &transform)
1117{
1118 /* Perspective not supported for now, getAffineMap() will leave out the
1119 * perspective part of the transform. */
1120 const openvdb::math::Mat4f matrix = transform.baseMap()->getAffineMap()->getMat4();
1121 /* Blender column-major and OpenVDB right-multiplication conventions match. */
1123 for (int col = 0; col < 4; col++) {
1124 for (int row = 0; row < 4; row++) {
1125 result[col][row] = matrix(col, row);
1126 }
1127 }
1128 return result;
1129}
1130
1131openvdb::math::Transform BKE_volume_transform_to_openvdb(const float4x4 &transform)
1132{
1133 openvdb::math::Mat4f matrix_openvdb;
1134 for (int col = 0; col < 4; col++) {
1135 for (int row = 0; row < 4; row++) {
1136 matrix_openvdb(col, row) = transform[col][row];
1137 }
1138 }
1139 return openvdb::math::Transform(std::make_shared<openvdb::math::AffineMap>(matrix_openvdb));
1140}
1141
1142/* Changing the resolution of a grid. */
1143
1149template<typename GridType>
1150static typename GridType::Ptr create_grid_with_changed_resolution(const GridType &old_grid,
1151 const float resolution_factor)
1152{
1153 BLI_assert(resolution_factor > 0.0f);
1154
1155 openvdb::Mat4R xform;
1156 xform.setToScale(openvdb::Vec3d(resolution_factor));
1157 openvdb::tools::GridTransformer transformer{xform};
1158
1159 typename GridType::Ptr new_grid = old_grid.copyWithNewTree();
1160 transformer.transformGrid<openvdb::tools::BoxSampler>(old_grid, *new_grid);
1161 new_grid->transform() = old_grid.transform();
1162 new_grid->transform().preScale(1.0f / resolution_factor);
1163 new_grid->transform().postTranslate(-new_grid->voxelSize() / 2.0f);
1164 return new_grid;
1165}
1166
1167struct CreateGridWithChangedResolutionOp {
1168 const openvdb::GridBase &grid;
1169 const float resolution_factor;
1170
1171 template<typename GridType> typename openvdb::GridBase::Ptr operator()()
1172 {
1173 return create_grid_with_changed_resolution(static_cast<const GridType &>(grid),
1174 resolution_factor);
1175 }
1176};
1177
1178openvdb::GridBase::Ptr BKE_volume_grid_create_with_changed_resolution(
1179 const VolumeGridType grid_type,
1180 const openvdb::GridBase &old_grid,
1181 const float resolution_factor)
1182{
1183 CreateGridWithChangedResolutionOp op{old_grid, resolution_factor};
1184 return BKE_volume_grid_type_operation(grid_type, op);
1185}
1186#endif
1187
1188} // namespace blender
#define BKE_LIB_FOREACHID_PROCESS_IDSUPER(data_, id_super_, cb_flag_)
General operations, lookup, etc. for blender objects.
Volume data-block.
File and directory operations.
#define FILE_MAX
#define BLT_I18NCONTEXT_ID_VOLUME
#define CLOG_INFO(clg_ref,...)
Definition CLG_log.h:190
#define FILTER_ID_MA
Definition DNA_ID.h:1210
#define ID_BLEND_PATH(_bmain, _id)
Definition DNA_ID.h:688
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:736
#define FILTER_ID_VO
Definition DNA_ID.h:1232
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
volatile int lock
#define UNUSED_VARS(...)
#define INIT_DEFAULT_STRUCT_AFTER(struct_dst, member)
#define STREQ(a, b)
#define VOLUME_FRAME_NONE
SIMD_FORCE_INLINE btVector3 operator()(const btVector3 &x) const
Return the transform of the vector.
Definition btTransform.h:90
constexpr IndexRange()=default
const T & last(const int64_t n=0) const
void append_as(ForwardValue &&...value)
void copy_utf8_truncated(char *dst, int64_t dst_size) const
Definition string_ref.cc:28
b[1] b &&[1] b &&[1] b &&[1] b &&[1] b[3] b &&[1] b[3] float determinant(MatBase< C, R >) RET
#define log2
#define LOG(level)
Definition log.h:97
std::string get_name(const VolumeGridData &grid)
VolumeGridType get_type(const VolumeGridData &grid)
bool is_loaded(const VolumeGridData &grid)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
Definition BLI_bounds.hh:27
T determinant(const MatBase< T, Size, Size > &mat)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_packedfile_blend_write(BlendWriter *writer, const PackedFile *pf)
bke::VolumeGridData * BKE_volume_grid_find_for_write(Volume *volume, StringRef name)
char * STRNCPY(char(&dst)[N], const char *src)
bke::VolumeGridData * BKE_volume_grid_get_for_write(Volume *volume, int grid_index)
void BKE_volume_batch_cache_dirty_tag(Volume *volume, int mode)
PackedFile * BKE_packedfile_duplicate(const PackedFile *pf_src)
std::optional< Bounds< float3 > > BKE_volume_min_max(const Volume *volume)
int BKE_volume_num_grids(const Volume *volume)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void BKE_volume_batch_cache_free(Volume *volume)
static void volume_copy_data(Main *, std::optional< Library * >, ID *id_dst, const ID *id_src, const int)
bool BKE_volume_set_velocity_grid_by_name(Volume *volume, StringRef base_name)
bool DEG_is_active(const Depsgraph *depsgraph)
Definition depsgraph.cc:324
void BLO_read_pointer_array_and_validate_size(BlendDataReader *reader, T **ptr_p, SizeT *array_size)
void BKE_volume_count_memory(const Volume &volume, MemoryCounter &memory)
Volume * BKE_volume_add(Main *bmain, const char *name)
const bke::VolumeGridData * BKE_volume_grid_find(const Volume *volume, StringRef name)
void BKE_volume_data_update(Depsgraph *depsgraph, Scene *scene, Object *object)
static void volume_foreach_path(ID *id, BPathForeachPathData *bpath_data)
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
void BKE_object_eval_assign_data(Object *object, ID *data, bool is_owned)
Definition object.cc:1786
bool BKE_volume_grid_transform_valid(const float4x4 &transform)
void(*)(ID *id, const IDCacheKey *cache_key, void **cache_p, uint flags, void *user_data) IDTypeForeachCacheFunctionCallback
const bke::VolumeGridData * BKE_volume_grid_get(const Volume *volume, int grid_index)
bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits) ATTR_NONNULL(1)
void BKE_packedfile_free(PackedFile *pf)
int BKE_volume_simplify_level(const Depsgraph *depsgraph)
Volume * BKE_volume_new_for_eval(const Volume *volume_src)
MatBase< float, 4, 4 > float4x4
bool BLI_path_frame_get(const char *path, int *r_frame, int *r_digits_len) ATTR_NONNULL(1
void BKE_id_blend_write(BlendWriter *writer, ID *id)
Definition lib_id.cc:2890
static void volume_blend_read_after_liblink(BlendLibReader *, ID *id)
@ LIB_ID_COPY_LOCALIZE
@ VOLUME_SEQUENCE_EXTEND
@ VOLUME_SEQUENCE_PING_PONG
@ VOLUME_SEQUENCE_REPEAT
bool BKE_volume_is_y_up(const Volume *volume)
Global G
Definition blender.cc:57
const char * BKE_volume_grids_error_msg(const Volume *volume)
bool BKE_volume_is_loaded(const Volume *volume)
void void void const char * BLI_path_basename(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
bool BLI_path_extension_ensure(char *path, size_t path_maxncpy, const char *ext) ATTR_NONNULL(1
static void volume_evaluate_modifiers(Depsgraph *depsgraph, Scene *scene, Object *object, bke::GeometrySet &geometry_set)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
static void volume_foreach_cache(ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data)
void BKE_object_free_derived_caches(Object *ob)
Definition object.cc:1810
Volume * BKE_volume_copy_for_eval(const Volume *volume_src)
Main * DEG_get_bmain(const Depsgraph *graph)
BMesh const char void * data
void(*) BKE_volume_batch_cache_free_cb(Volume *volume)
void BKE_animdata_free(ID *id, bool do_id_user)
Definition anim_data.cc:174
@ MOD_APPLY_USECACHE
const char * BKE_volume_grids_frame_filepath(const Volume *volume)
void(*) BKE_volume_batch_cache_dirty_tag_cb(Volume *volume, int mode)
ModifierData * BKE_modifiers_get_virtual_modifierlist(const Object *ob, VirtualModifierData *data)
static void volume_foreach_id(ID *id, LibraryForeachIDData *data)
void BKE_volume_unload(Volume *volume)
static void volume_blend_write(BlendWriter *writer, ID *id, const void *id_address)
bool BKE_volume_is_points_only(const Volume *volume)
bool BKE_volume_save(const Volume *volume, const Main *bmain, ReportList *reports, const char *filepath)
void BKE_volume_grids_backup_restore(Volume *volume, VolumeGridVector *grids, const char *filepath)
bool BKE_volume_load(const Volume *volume, const Main *bmain)
float BKE_volume_simplify_factor(const Depsgraph *depsgraph)
void BKE_modifiers_clear_errors(Object *ob)
void BKE_volume_grid_add(Volume *volume, const bke::VolumeGridData &grid)
const bke::VolumeGridData * BKE_volume_grid_active_get_for_read(const Volume *volume)
void BKE_volume_init_grids(Volume *volume)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
void BKE_bpath_foreach_path_readonly_process(BPathForeachPathData *bpath_data, const char *path)
Definition bpath.cc:161
void BKE_volume_grid_remove(Volume *volume, const bke::VolumeGridData *grid)
void BKE_volume_eval_geometry(Depsgraph *depsgraph, Volume *volume)
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1617
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
Definition BKE_bpath.hh:49
@ BKE_BPATH_FOREACH_PATH_EXPAND_SEQUENCES
Definition BKE_bpath.hh:92
void BKE_bpath_sequence_filepaths_foreach(const char *abs_filepath, blender::FunctionRef< void(blender::StringRef frame_filepath)> callback)
static int volume_sequence_frame(const Depsgraph *depsgraph, const Volume *volume)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
T * DEG_get_original(T *id)
bool BKE_bpath_foreach_path_fixed_process(BPathForeachPathData *bpath_data, char *path, size_t path_maxncpy)
Definition bpath.cc:130
static Volume * take_volume_ownership_from_geometry_set(bke::GeometrySet &geometry_set)
@ INDEX_ID_VO
Definition DNA_ID.h:1332
std::mutex Mutex
Definition BLI_mutex.hh:51
Scene * DEG_get_input_scene(const Depsgraph *graph)
bool BKE_volume_grid_determinant_valid(double determinant)
static void volume_init_data(ID *id)
@ ID_TAG_COPIED_ON_EVAL
Definition DNA_ID.h:1000
static CLG_LogRef LOG
Definition logging.cpp:12
static void volume_update_simplify_level(Main *bmain, Volume *volume, const Depsgraph *depsgraph)
void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p, StringRefNull filepath)
bool void BLI_path_frame_strip(char *path, char *r_ext, size_t ext_maxncpy) ATTR_NONNULL(1
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
static void volume_free_data(ID *id)
VecBase< float, 3 > float3
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
MINLINE int clamp_i(int value, int min, int max)
float DEG_get_ctime(const Depsgraph *graph)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
void * BKE_id_new(Main *bmain, short type, const char *name)
Definition lib_id.cc:1612
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
static void volume_blend_read_data(BlendDataReader *reader, ID *id)
bool BKE_volume_voxel_size_valid(const float3 &voxel_size)
@ IDTYPE_FLAGS_APPEND_IS_REUSABLE
Definition BKE_idtype.hh:50
#define ceilf
void write_pointer_array(int64_t num, const void *data)
void write_id_struct(const void *id_address, const T *id, BlendStructWriterTypedFn< T > fn=nullptr)
bool is_undo() const
char name[258]
Definition DNA_ID.h:433
struct ModifierData * next
void(*) modify_geometry_set(ModifierData *md, const ModifierEvalContext *ctx, bke::GeometrySet *geometry_set)
struct RenderData r
draw::VolumeBatchCache * batch_cache
VolumeSequenceMode sequence_mode
bke::VolumeRuntime * runtime
struct PackedFile * packedfile
VolumeRender render
struct Material ** mat
VolumeDisplay display
void replace_volume(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
bool has(const GeometryComponent::Type component_type) const
void remove(const GeometryComponent::Type component_type)
std::unique_ptr< bake::BakeMaterialsList > bake_materials
VolumeGridVector * grids
#define N_(msgid)