diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2020-03-17 16:41:48 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2020-03-18 13:23:05 +0300 |
commit | b0a1cf2c9ae696b07f7a236bc855a5ab4a493dcb (patch) | |
tree | 92295af11db5e984da42bfac7ca60190b8549a3f /source/blender/editors/object/object_volume.c | |
parent | 8dcfd392e4e62f193b666304425bc5ae635ecffe (diff) |
Objects: add Volume object type, and prototypes for Hair and PointCloud
Only the volume object is exposed in the user interface. It is based on OpenVDB
internally. Drawing and rendering code will follow in another commit.
https://wiki.blender.org/wiki/Source/Objects/Volume
https://wiki.blender.org/wiki/Reference/Release_Notes/2.83/Volumes
Hair and PointCloud object types are hidden behind a WITH_NEW_OBJECT_TYPES
build option. These are unfinished, and included only to make it easier to
cooperate on development in the future and avoid tricky merges.
https://wiki.blender.org/wiki/Source/Objects/New_Object_Types
Ref T73201, T68981
Differential Revision: https://developer.blender.org/D6945
Diffstat (limited to 'source/blender/editors/object/object_volume.c')
-rw-r--r-- | source/blender/editors/object/object_volume.c | 193 |
1 files changed, 193 insertions, 0 deletions
diff --git a/source/blender/editors/object/object_volume.c b/source/blender/editors/object/object_volume.c new file mode 100644 index 00000000000..64482a0bcf6 --- /dev/null +++ b/source/blender/editors/object/object_volume.c @@ -0,0 +1,193 @@ +/* + * 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) 2008 Blender Foundation. + * All rights reserved. + */ + +/** \file + * \ingroup edobj + */ + +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "BLI_fileops.h" +#include "BLI_listbase.h" +#include "BLI_math_base.h" +#include "BLI_path_util.h" +#include "BLI_string.h" + +#include "DNA_object_types.h" +#include "DNA_volume_types.h" + +#include "RNA_access.h" +#include "RNA_define.h" + +#include "BKE_context.h" +#include "BKE_lib_id.h" +#include "BKE_main.h" +#include "BKE_report.h" +#include "BKE_volume.h" + +#include "WM_types.h" +#include "WM_api.h" + +#include "ED_image.h" +#include "ED_object.h" +#include "ED_screen.h" + +#include "object_intern.h" + +/* Volume Add */ + +static Object *object_volume_add(bContext *C, wmOperator *op, const char *name) +{ + ushort local_view_bits; + float loc[3], rot[3]; + + if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, NULL, &local_view_bits, NULL)) { + return false; + } + return ED_object_add_type(C, OB_VOLUME, name, loc, rot, false, local_view_bits); +} + +static int object_volume_add_exec(bContext *C, wmOperator *op) +{ + return (object_volume_add(C, op, NULL) != NULL) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; +} + +void OBJECT_OT_volume_add(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Add Volume"; + ot->description = "Add a volume object to the scene"; + ot->idname = "OBJECT_OT_volume_add"; + + /* api callbacks */ + ot->exec = object_volume_add_exec; + ot->poll = ED_operator_objectmode; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + ED_object_add_generic_props(ot, false); +} + +/* Volume Import */ + +static int volume_import_exec(bContext *C, wmOperator *op) +{ + Main *bmain = CTX_data_main(C); + const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path"); + bool imported = false; + + ListBase ranges = ED_image_filesel_detect_sequences(bmain, op, false); + for (ImageFrameRange *range = ranges.first; range; range = range->next) { + char filename[FILE_MAX]; + BLI_split_file_part(range->filepath, filename, sizeof(filename)); + BLI_path_extension_replace(filename, sizeof(filename), ""); + + Object *object = object_volume_add(C, op, filename); + Volume *volume = (Volume *)object->data; + + STRNCPY(volume->filepath, range->filepath); + if (is_relative_path) { + BLI_path_rel(volume->filepath, BKE_main_blendfile_path(bmain)); + } + + volume->is_sequence = (range->length > 1); + volume->frame_duration = (volume->is_sequence) ? range->length : 0; + volume->frame_start = 1; + volume->frame_offset = (volume->is_sequence) ? range->offset - 1 : 0; + + if (!BKE_volume_load(volume, bmain)) { + BKE_reportf(op->reports, + RPT_WARNING, + "Volume \"%s\" failed to load: %s", + filename, + BKE_volume_grids_error_msg(volume)); + BKE_id_delete(bmain, &object->id); + BKE_id_delete(bmain, &volume->id); + continue; + } + else if (BKE_volume_is_points_only(volume)) { + BKE_reportf(op->reports, + RPT_WARNING, + "Volume \"%s\" contains points, only voxel grids are supported", + filename); + BKE_id_delete(bmain, &object->id); + BKE_id_delete(bmain, &volume->id); + continue; + } + + if (BKE_volume_is_y_up(volume)) { + object->rot[0] += M_PI_2; + } + + imported = true; + } + BLI_freelistN(&ranges); + + return (imported) ? OPERATOR_FINISHED : OPERATOR_CANCELLED; +} + +static int volume_import_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) +{ + if (RNA_struct_property_is_set(op->ptr, "filepath")) { + return volume_import_exec(C, op); + } + + RNA_string_set(op->ptr, "filepath", U.textudir); + WM_event_add_fileselect(C, op); + + return OPERATOR_RUNNING_MODAL; +} + +/* called by other space types too */ +void OBJECT_OT_volume_import(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Import OpenVDB Volume"; + ot->description = "Import OpenVDB volume file"; + ot->idname = "OBJECT_OT_volume_import"; + + /* api callbacks */ + ot->exec = volume_import_exec; + ot->invoke = volume_import_invoke; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + /* properties */ + WM_operator_properties_filesel(ot, + FILE_TYPE_FOLDER | FILE_TYPE_VOLUME, + FILE_SPECIAL, + FILE_OPENFILE, + WM_FILESEL_FILEPATH | WM_FILESEL_DIRECTORY | WM_FILESEL_FILES | + WM_FILESEL_RELPATH, + FILE_DEFAULTDISPLAY, + FILE_SORT_ALPHA); + + RNA_def_boolean( + ot->srna, + "use_sequence_detection", + true, + "Detect Sequences", + "Automatically detect animated sequences in selected volume files (based on file names)"); + + ED_object_add_generic_props(ot, false); +} |