Files
test/source/blender/blenkernel/intern/packedFile.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1008 lines
27 KiB
C++
Raw Normal View History

/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
2002-10-12 11:37:38 +00:00
/** \file
* \ingroup bke
2011-02-27 20:40:57 +00:00
*/
#include <algorithm>
#include <cstdio>
2002-10-12 11:37:38 +00:00
#include <fcntl.h>
#include <sys/stat.h>
2018-06-17 17:05:51 +02:00
#ifndef WIN32
2002-10-12 11:37:38 +00:00
# include <unistd.h>
#else
# include <io.h>
#endif
#include "MEM_guardedalloc.h"
#include <cstring>
2002-10-12 11:37:38 +00:00
Fix: Broken "File -> External Data -> Pack Linked Libraries" The operator refused to pack libraries with absolute paths (wasnt the case in its original implementation 16411da41e40, but was added in 129fb516f431 -- for the reason of preventing "bad things happen on unpacking" without an explanation of what these exactly are). It did so by cancelling as soon as **one** library with ab absolute path was found. Now with the introduction of essential assets, we have those absolute path linkages more or less "by default" as soon as e.g. a brush is used, so the operator is more or less unusable now. NOTE: these absolute essential asset library paths seem to be converted to relative on save? Upon reload, these are then gone... (might be another hint for an alternative fix, see below) By "bad things happen on unpacking" I would assume the scenario of folders being created in unwanted locations (e.g. when moving from one OS to another), but the same thing is also true for packing **files** instead of libraries (there, absolute paths are allowed, and unpacking in original locations can equally fail or create folder structures that are "unexpected"). NOTE: for files though we have the choice of unpacking to a relative folder (which wouldnt really be possible since libraries can be nested and we would have to correct paths all over the place). NOTE: the chance of creating "unwanted" folder structures with relative paths might be slimmer, but if you have a lot of "upwards" parent folders, relative can easily "break" as well. Possible ways to resolve this: ### [1] skip libraries identified as essentials assets (still cancel on all other absolute paths) Can check a library path to be contained in `EssentialsAssetLibrary` `essentials_directory_path`. This would be the safest imo since it is a no-behavior change. ### [2] lift the limitation of absolute paths alltogether Like mentioned above, things could break with "relative" almost as easily as with "absolute", there might even be scenarios where "absolute" is wanted. It is a more behavior-changing fix that we might explore more after 4.4 is out. ### [3] skip absolute libraries (but continue with non-absolute libraries) This does change behavior as well (it does not cancel as soon as **one** library with ab absolute path was found anymore, but the worst case scenario is that you end up with an "incomplete" file if you really mixed absolute and realtive lib linking). This PR implements [1] for now, [2] or [3] can follow for 4.5. Fixes #134665 Pull Request: https://projects.blender.org/blender/blender/pulls/134839
2025-02-28 17:14:14 +01:00
#include "AS_essentials_library.hh"
#include "DNA_ID.h"
#include "DNA_image_types.h"
#include "DNA_modifier_types.h"
#include "DNA_packedFile_types.h"
2002-10-12 11:37:38 +00:00
#include "DNA_sound_types.h"
#include "DNA_vfont_types.h"
#include "DNA_volume_types.h"
2002-10-12 11:37:38 +00:00
#include "BLI_listbase.h"
#include "BLI_path_utils.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
2002-10-12 11:37:38 +00:00
#include "BKE_bake_geometry_nodes_modifier.hh"
#include "BKE_bake_geometry_nodes_modifier_pack.hh"
#include "BKE_image.hh"
#include "BKE_image_format.hh"
#include "BKE_library.hh"
#include "BKE_main.hh"
#include "BKE_packedFile.hh"
#include "BKE_report.hh"
#include "BKE_sound.h"
#include "BKE_vfont.hh"
#include "BKE_volume.hh"
2002-10-12 11:37:38 +00:00
#include "DEG_depsgraph.hh"
2024-01-18 22:50:23 +02:00
#include "IMB_imbuf.hh"
#include "BLO_read_write.hh"
#include "CLG_log.h"
static CLG_LogRef LOG = {"bke.packedfile"};
using namespace blender;
int BKE_packedfile_seek(PackedFile *pf, int offset, int whence)
2002-10-12 11:37:38 +00:00
{
int oldseek = -1, seek = 0;
2002-10-12 11:37:38 +00:00
if (pf) {
oldseek = pf->seek;
switch (whence) {
2012-05-06 17:22:54 +00:00
case SEEK_CUR:
seek = oldseek + offset;
break;
case SEEK_END:
seek = pf->size + offset;
break;
case SEEK_SET:
seek = offset;
break;
default:
oldseek = -1;
break;
2002-10-12 11:37:38 +00:00
}
if (seek < 0) {
seek = 0;
}
else if (seek > pf->size) {
2002-10-12 11:37:38 +00:00
seek = pf->size;
}
pf->seek = seek;
}
return oldseek;
2002-10-12 11:37:38 +00:00
}
2018-06-17 17:05:51 +02:00
void BKE_packedfile_rewind(PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
BKE_packedfile_seek(pf, 0, SEEK_SET);
2002-10-12 11:37:38 +00:00
}
int BKE_packedfile_read(PackedFile *pf, void *data, int size)
2018-06-17 17:05:51 +02:00
{
if ((pf != nullptr) && (size >= 0) && (data != nullptr)) {
2002-10-12 11:37:38 +00:00
if (size + pf->seek > pf->size) {
size = pf->size - pf->seek;
}
2002-10-12 11:37:38 +00:00
if (size > 0) {
memcpy(data, ((const char *)pf->data) + pf->seek, size);
}
else {
2002-10-12 11:37:38 +00:00
size = 0;
}
2002-10-12 11:37:38 +00:00
pf->seek += size;
}
else {
2002-10-12 11:37:38 +00:00
size = -1;
}
return size;
2002-10-12 11:37:38 +00:00
}
PackedFileCount BKE_packedfile_count_all(Main *bmain)
2002-10-12 11:37:38 +00:00
{
Image *ima;
VFont *vf;
bSound *sound;
Volume *volume;
PackedFileCount count;
2018-06-17 17:05:51 +02:00
2012-07-07 22:51:57 +00:00
/* let's check if there are packed files... */
for (ima = static_cast<Image *>(bmain->images.first); ima;
ima = static_cast<Image *>(ima->id.next))
{
if (BKE_image_has_packedfile(ima) && !ID_IS_LINKED(ima)) {
count.individual_files++;
}
}
2002-10-12 11:37:38 +00:00
for (vf = static_cast<VFont *>(bmain->fonts.first); vf; vf = static_cast<VFont *>(vf->id.next)) {
if (vf->packedfile && !ID_IS_LINKED(vf)) {
count.individual_files++;
}
}
2002-10-12 11:37:38 +00:00
for (sound = static_cast<bSound *>(bmain->sounds.first); sound;
sound = static_cast<bSound *>(sound->id.next))
{
if (sound->packedfile && !ID_IS_LINKED(sound)) {
count.individual_files++;
}
}
2002-10-12 11:37:38 +00:00
for (volume = static_cast<Volume *>(bmain->volumes.first); volume;
volume = static_cast<Volume *>(volume->id.next))
{
if (volume->packedfile && !ID_IS_LINKED(volume)) {
count.individual_files++;
}
}
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (ID_IS_LINKED(object)) {
continue;
}
LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
if (md->type == eModifierType_Nodes) {
NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
for (const NodesModifierBake &bake : blender::Span{nmd->bakes, nmd->bakes_num}) {
if (bake.packed) {
count.bakes++;
}
}
}
}
}
return count;
2002-10-12 11:37:38 +00:00
}
void BKE_packedfile_free(PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
if (pf) {
BLI_assert(pf->data != nullptr);
BLI_assert(pf->sharing_info != nullptr);
pf->sharing_info->remove_user_and_delete_if_last();
2002-10-12 11:37:38 +00:00
MEM_freeN(pf);
}
else {
printf("%s: Trying to free a nullptr pointer\n", __func__);
}
2002-10-12 11:37:38 +00:00
}
PackedFile *BKE_packedfile_duplicate(const PackedFile *pf_src)
{
BLI_assert(pf_src != nullptr);
BLI_assert(pf_src->data != nullptr);
PackedFile *pf_dst;
pf_dst = static_cast<PackedFile *>(MEM_dupallocN(pf_src));
pf_dst->sharing_info->add_user();
return pf_dst;
}
PackedFile *BKE_packedfile_new_from_memory(const void *mem,
int memlen,
const blender::ImplicitSharingInfo *sharing_info)
2002-10-12 11:37:38 +00:00
{
BLI_assert(mem != nullptr);
if (!sharing_info) {
/* Assume we are the only owner of that memory currently. */
sharing_info = blender::implicit_sharing::info_for_mem_free(const_cast<void *>(mem));
}
PackedFile *pf = MEM_callocN<PackedFile>("PackedFile");
2002-10-12 11:37:38 +00:00
pf->data = mem;
pf->size = memlen;
pf->sharing_info = sharing_info;
2018-06-17 17:05:51 +02:00
2002-10-12 11:37:38 +00:00
return pf;
}
PackedFile *BKE_packedfile_new(ReportList *reports, const char *filepath_rel, const char *basepath)
2002-10-12 11:37:38 +00:00
{
char filepath[FILE_MAX];
/* render result has no filepath and can be ignored
* any other files with no name can be ignored too */
if (filepath_rel[0] == '\0') {
return nullptr;
}
// XXX waitcursor(1);
2012-07-07 22:51:57 +00:00
/* convert relative filenames to absolute filenames */
2023-05-09 12:50:37 +10:00
STRNCPY(filepath, filepath_rel);
BLI_path_abs(filepath, basepath);
2012-07-07 22:51:57 +00:00
/* open the file
* and create a PackedFile structure */
const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) {
BKE_reportf(reports, RPT_ERROR, "Unable to pack file, source path '%s' not found", filepath);
return nullptr;
}
PackedFile *pf = nullptr;
const size_t file_size = BLI_file_descriptor_size(file);
if (file_size == size_t(-1)) {
BKE_reportf(reports, RPT_ERROR, "Unable to access the size of, source path '%s'", filepath);
}
else if (file_size > INT_MAX) {
BKE_reportf(reports, RPT_ERROR, "Unable to pack files over 2gb, source path '%s'", filepath);
}
else {
/* #MEM_mallocN complains about `MEM_mallocN(0, "...")`,
* a single allocation is harmless and doesn't cause any complications. */
void *data = MEM_mallocN(std::max(file_size, size_t(1)), "packFile");
if (BLI_read(file, data, file_size) == file_size) {
pf = BKE_packedfile_new_from_memory(data, file_size);
2002-10-12 11:37:38 +00:00
}
else {
MEM_freeN(data);
}
2002-10-12 11:37:38 +00:00
}
close(file);
// XXX waitcursor(0);
return pf;
2002-10-12 11:37:38 +00:00
}
void BKE_packedfile_pack_all(Main *bmain, ReportList *reports, bool verbose)
2002-10-12 11:37:38 +00:00
{
Image *ima;
VFont *vfont;
bSound *sound;
Volume *volume;
int tot = 0;
for (ima = static_cast<Image *>(bmain->images.first); ima;
ima = static_cast<Image *>(ima->id.next))
{
if (BKE_image_has_packedfile(ima) == false && ID_IS_EDITABLE(ima)) {
if (ELEM(ima->source, IMA_SRC_FILE, IMA_SRC_TILED)) {
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
BKE_image_packfiles(reports, ima, ID_BLEND_PATH(bmain, &ima->id));
tot++;
}
else if (ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE) && verbose) {
BKE_reportf(reports,
RPT_WARNING,
"Image '%s' skipped, packing movies or image sequences not supported",
ima->id.name + 2);
}
}
}
for (vfont = static_cast<VFont *>(bmain->fonts.first); vfont;
vfont = static_cast<VFont *>(vfont->id.next))
{
if (vfont->packedfile == nullptr && ID_IS_EDITABLE(vfont) &&
BKE_vfont_is_builtin(vfont) == false)
{
vfont->packedfile = BKE_packedfile_new(
reports, vfont->filepath, BKE_main_blendfile_path(bmain));
tot++;
}
}
for (sound = static_cast<bSound *>(bmain->sounds.first); sound;
sound = static_cast<bSound *>(sound->id.next))
{
if (sound->packedfile == nullptr && ID_IS_EDITABLE(sound)) {
sound->packedfile = BKE_packedfile_new(
reports, sound->filepath, BKE_main_blendfile_path(bmain));
tot++;
}
}
for (volume = static_cast<Volume *>(bmain->volumes.first); volume;
volume = static_cast<Volume *>(volume->id.next))
{
if (volume->packedfile == nullptr && ID_IS_EDITABLE(volume)) {
volume->packedfile = BKE_packedfile_new(
reports, volume->filepath, BKE_main_blendfile_path(bmain));
tot++;
}
}
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (ID_IS_LINKED(object)) {
continue;
}
LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
if (md->type == eModifierType_Nodes) {
NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
for (NodesModifierBake &bake : blender::MutableSpan{nmd->bakes, nmd->bakes_num}) {
blender::bke::bake::pack_geometry_nodes_bake(*bmain, reports, *object, *nmd, bake);
}
}
}
}
if (tot > 0) {
BKE_reportf(reports, RPT_INFO, "Packed %d file(s)", tot);
}
else if (verbose) {
BKE_report(reports, RPT_INFO, "No new files have been packed");
}
2002-10-12 11:37:38 +00:00
}
int BKE_packedfile_write_to_file(ReportList *reports,
const char *ref_file_name,
const char *filepath_rel,
PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
int file, number;
2002-10-12 11:37:38 +00:00
int ret_value = RET_OK;
bool remove_tmp = false;
char filepath[FILE_MAX];
char filepath_temp[FILE_MAX];
// void *data;
2023-05-09 12:50:37 +10:00
STRNCPY(filepath, filepath_rel);
BLI_path_abs(filepath, ref_file_name);
if (BLI_exists(filepath)) {
2002-10-12 11:37:38 +00:00
for (number = 1; number <= 999; number++) {
2023-05-09 12:50:37 +10:00
SNPRINTF(filepath_temp, "%s.%03d_", filepath, number);
if (!BLI_exists(filepath_temp)) {
if (BLI_copy(filepath, filepath_temp) == RET_OK) {
remove_tmp = true;
2002-10-12 11:37:38 +00:00
}
break;
}
2002-10-12 11:37:38 +00:00
}
}
BLI_file_ensure_parent_dir_exists(filepath);
file = BLI_open(filepath, O_BINARY + O_WRONLY + O_CREAT + O_TRUNC, 0666);
if (file == -1) {
BKE_reportf(reports, RPT_ERROR, "Error creating file '%s'", filepath);
ret_value = RET_ERROR;
}
else {
2002-10-12 11:37:38 +00:00
if (write(file, pf->data, pf->size) != pf->size) {
BKE_reportf(reports, RPT_ERROR, "Error writing file '%s'", filepath);
2002-10-12 11:37:38 +00:00
ret_value = RET_ERROR;
}
else {
BKE_reportf(reports, RPT_INFO, "Saved packed file to: %s", filepath);
}
2002-10-12 11:37:38 +00:00
close(file);
}
2002-10-12 11:37:38 +00:00
if (remove_tmp) {
if (ret_value == RET_ERROR) {
if (BLI_rename_overwrite(filepath_temp, filepath) != 0) {
BKE_reportf(reports,
RPT_ERROR,
"Error restoring temp file (check files '%s' '%s')",
filepath_temp,
filepath);
2002-10-12 11:37:38 +00:00
}
}
else {
if (BLI_delete(filepath_temp, false, false) != 0) {
BKE_reportf(reports, RPT_ERROR, "Error deleting '%s' (ignored)", filepath_temp);
2002-10-12 11:37:38 +00:00
}
}
}
return ret_value;
2002-10-12 11:37:38 +00:00
}
enum ePF_FileCompare BKE_packedfile_compare_to_file(const char *ref_file_name,
const char *filepath_rel,
2024-04-03 10:22:05 +11:00
const PackedFile *pf)
2002-10-12 11:37:38 +00:00
{
BLI_stat_t st;
enum ePF_FileCompare ret_val;
2002-10-12 11:37:38 +00:00
char buf[4096];
char filepath[FILE_MAX];
2023-05-09 12:50:37 +10:00
STRNCPY(filepath, filepath_rel);
BLI_path_abs(filepath, ref_file_name);
if (BLI_stat(filepath, &st) == -1) {
ret_val = PF_CMP_NOFILE;
}
else if (st.st_size != pf->size) {
ret_val = PF_CMP_DIFFERS;
}
else {
2012-07-07 22:51:57 +00:00
/* we'll have to compare the two... */
const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
if (file == -1) {
ret_val = PF_CMP_NOFILE;
}
else {
ret_val = PF_CMP_EQUAL;
for (int i = 0; i < pf->size; i += sizeof(buf)) {
int len = pf->size - i;
len = std::min<ulong>(len, sizeof(buf));
if (BLI_read(file, buf, len) != len) {
2012-07-07 22:51:57 +00:00
/* read error ... */
ret_val = PF_CMP_DIFFERS;
2002-10-12 11:37:38 +00:00
break;
}
if (memcmp(buf, ((const char *)pf->data) + i, len) != 0) {
ret_val = PF_CMP_DIFFERS;
break;
2002-10-12 11:37:38 +00:00
}
}
close(file);
2002-10-12 11:37:38 +00:00
}
}
return ret_val;
2002-10-12 11:37:38 +00:00
}
char *BKE_packedfile_unpack_to_file(ReportList *reports,
const char *ref_file_name,
const char *abs_name,
const char *local_name,
PackedFile *pf,
enum ePF_FileStatus how)
2002-10-12 11:37:38 +00:00
{
char *newname = nullptr;
const char *temp = nullptr;
if (pf != nullptr) {
2002-10-12 11:37:38 +00:00
switch (how) {
case PF_KEEP:
break;
case PF_REMOVE:
2012-05-06 17:22:54 +00:00
temp = abs_name;
break;
2002-10-12 11:37:38 +00:00
case PF_USE_LOCAL: {
char temp_abs[FILE_MAX];
2023-05-09 12:50:37 +10:00
STRNCPY(temp_abs, local_name);
BLI_path_abs(temp_abs, ref_file_name);
2012-07-07 22:51:57 +00:00
/* if file exists use it */
if (BLI_exists(temp_abs)) {
2002-10-12 11:37:38 +00:00
temp = local_name;
break;
}
/* else create it */
ATTR_FALLTHROUGH;
}
2002-10-12 11:37:38 +00:00
case PF_WRITE_LOCAL:
if (BKE_packedfile_write_to_file(reports, ref_file_name, local_name, pf) == RET_OK) {
2002-10-12 11:37:38 +00:00
temp = local_name;
}
break;
case PF_USE_ORIGINAL: {
char temp_abs[FILE_MAX];
2023-05-09 12:50:37 +10:00
STRNCPY(temp_abs, abs_name);
BLI_path_abs(temp_abs, ref_file_name);
2012-07-07 22:51:57 +00:00
/* if file exists use it */
if (BLI_exists(temp_abs)) {
BKE_reportf(reports, RPT_INFO, "Use existing file (instead of packed): %s", abs_name);
2002-10-12 11:37:38 +00:00
temp = abs_name;
break;
}
/* else create it */
ATTR_FALLTHROUGH;
}
2002-10-12 11:37:38 +00:00
case PF_WRITE_ORIGINAL:
if (BKE_packedfile_write_to_file(reports, ref_file_name, abs_name, pf) == RET_OK) {
2002-10-12 11:37:38 +00:00
temp = abs_name;
}
break;
default:
printf("%s: unknown return_value %d\n", __func__, how);
2002-10-12 11:37:38 +00:00
break;
}
2002-10-12 11:37:38 +00:00
if (temp) {
2012-05-06 17:22:54 +00:00
newname = BLI_strdup(temp);
2002-10-12 11:37:38 +00:00
}
}
return newname;
2002-10-12 11:37:38 +00:00
}
static void unpack_generate_paths(const char *filepath,
ID *id,
char *r_abspath,
size_t abspath_maxncpy,
char *r_relpath,
size_t relpath_maxncpy)
{
const short id_type = GS(id->name);
char temp_filename[FILE_MAX];
char temp_dirname[FILE_MAXDIR];
BLI_path_split_dir_file(
filepath, temp_dirname, sizeof(temp_dirname), temp_filename, sizeof(temp_filename));
if (temp_filename[0] == '\0') {
/* NOTE: we generally do not have any real way to re-create extension out of data. */
2023-05-09 12:50:37 +10:00
const size_t len = STRNCPY_RLEN(temp_filename, id->name + 2);
printf("%s\n", temp_filename);
/* For images ensure that the temporary filename contains tile number information as well as
* a file extension based on the file magic. */
if (id_type == ID_IM) {
Image *ima = (Image *)id;
ImagePackedFile *imapf = static_cast<ImagePackedFile *>(ima->packedfiles.last);
if (imapf != nullptr && imapf->packedfile != nullptr) {
const PackedFile *pf = imapf->packedfile;
enum eImbFileType ftype = eImbFileType(
IMB_test_image_type_from_memory((const uchar *)pf->data, pf->size));
if (ima->source == IMA_SRC_TILED) {
char tile_number[6];
2023-05-09 12:50:37 +10:00
SNPRINTF(tile_number, ".%d", imapf->tile_number);
BLI_strncpy(temp_filename + len, tile_number, sizeof(temp_filename) - len);
}
if (ftype != IMB_FTYPE_NONE) {
const int imtype = BKE_ftype_to_imtype(ftype, nullptr);
BKE_image_path_ext_from_imtype_ensure(temp_filename, sizeof(temp_filename), imtype);
}
}
}
BLI_path_make_safe_filename(temp_filename);
printf("%s\n", temp_filename);
}
if (temp_dirname[0] == '\0') {
/* Fallback to relative dir. */
2023-05-09 12:50:37 +10:00
STRNCPY(temp_dirname, "//");
}
{
const char *dir_name = nullptr;
switch (id_type) {
case ID_VF:
dir_name = "fonts";
break;
case ID_SO:
dir_name = "sounds";
break;
case ID_IM:
dir_name = "textures";
break;
case ID_VO:
dir_name = "volumes";
break;
default:
break;
}
if (dir_name) {
BLI_path_join(r_relpath, relpath_maxncpy, "//", dir_name, temp_filename);
}
}
{
size_t len = BLI_strncpy_rlen(r_abspath, temp_dirname, abspath_maxncpy);
BLI_strncpy(r_abspath + len, temp_filename, abspath_maxncpy - len);
}
}
2002-10-12 11:37:38 +00:00
char *BKE_packedfile_unpack(Main *bmain,
ReportList *reports,
ID *id,
const char *orig_file_path,
PackedFile *pf,
enum ePF_FileStatus how)
{
char localname[FILE_MAX], absname[FILE_MAX];
char *new_name = nullptr;
if (id != nullptr) {
unpack_generate_paths(
orig_file_path, id, absname, sizeof(absname), localname, sizeof(localname));
new_name = BKE_packedfile_unpack_to_file(
reports, BKE_main_blendfile_path(bmain), absname, localname, pf, how);
}
return new_name;
}
int BKE_packedfile_unpack_vfont(Main *bmain,
ReportList *reports,
VFont *vfont,
enum ePF_FileStatus how)
2002-10-12 11:37:38 +00:00
{
int ret_value = RET_ERROR;
if (vfont) {
char *new_file_path = BKE_packedfile_unpack(
bmain, reports, (ID *)vfont, vfont->filepath, vfont->packedfile, how);
if (new_file_path != nullptr) {
2002-10-12 11:37:38 +00:00
ret_value = RET_OK;
BKE_packedfile_free(vfont->packedfile);
vfont->packedfile = nullptr;
2023-05-09 12:50:37 +10:00
STRNCPY(vfont->filepath, new_file_path);
MEM_freeN(new_file_path);
2002-10-12 11:37:38 +00:00
}
}
return ret_value;
2002-10-12 11:37:38 +00:00
}
int BKE_packedfile_unpack_sound(Main *bmain,
ReportList *reports,
bSound *sound,
enum ePF_FileStatus how)
2002-10-12 11:37:38 +00:00
{
int ret_value = RET_ERROR;
if (sound != nullptr) {
char *new_file_path = BKE_packedfile_unpack(
bmain, reports, (ID *)sound, sound->filepath, sound->packedfile, how);
if (new_file_path != nullptr) {
2023-05-09 12:50:37 +10:00
STRNCPY(sound->filepath, new_file_path);
MEM_freeN(new_file_path);
2002-10-12 11:37:38 +00:00
BKE_packedfile_free(sound->packedfile);
sound->packedfile = nullptr;
BKE_sound_load(bmain, sound);
2002-10-12 11:37:38 +00:00
ret_value = RET_OK;
}
}
2018-06-17 17:05:51 +02:00
return ret_value;
2002-10-12 11:37:38 +00:00
}
int BKE_packedfile_unpack_image(Main *bmain,
ReportList *reports,
Image *ima,
enum ePF_FileStatus how)
2002-10-12 11:37:38 +00:00
{
int ret_value = RET_ERROR;
if (ima != nullptr) {
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
while (ima->packedfiles.last) {
ImagePackedFile *imapf = static_cast<ImagePackedFile *>(ima->packedfiles.last);
char *new_file_path = BKE_packedfile_unpack(
bmain, reports, (ID *)ima, imapf->filepath, imapf->packedfile, how);
if (new_file_path != nullptr) {
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
ImageView *iv;
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
ret_value = ret_value == RET_ERROR ? RET_ERROR : RET_OK;
BKE_packedfile_free(imapf->packedfile);
imapf->packedfile = nullptr;
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
/* update the new corresponding view filepath */
iv = static_cast<ImageView *>(
BLI_findstring(&ima->views, imapf->filepath, offsetof(ImageView, filepath)));
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
if (iv) {
2023-05-09 12:50:37 +10:00
STRNCPY(iv->filepath, new_file_path);
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
}
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
/* keep the new name in the image for non-pack specific reasons */
if (how != PF_REMOVE) {
2023-05-09 12:50:37 +10:00
STRNCPY(ima->filepath, new_file_path);
if (ima->source == IMA_SRC_TILED) {
/* Ensure that the Image filepath is kept in a tokenized format. */
BKE_image_ensure_tile_token(ima->filepath, sizeof(ima->filepath));
}
}
MEM_freeN(new_file_path);
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
}
else {
ret_value = RET_ERROR;
}
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
BLI_remlink(&ima->packedfiles, imapf);
MEM_freeN(imapf);
2002-10-12 11:37:38 +00:00
}
}
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
if (ret_value == RET_OK) {
BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_RELOAD);
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
}
return ret_value;
2002-10-12 11:37:38 +00:00
}
int BKE_packedfile_unpack_volume(Main *bmain,
ReportList *reports,
Volume *volume,
enum ePF_FileStatus how)
{
int ret_value = RET_ERROR;
if (volume != nullptr) {
char *new_file_path = BKE_packedfile_unpack(
bmain, reports, (ID *)volume, volume->filepath, volume->packedfile, how);
if (new_file_path != nullptr) {
2023-05-09 12:50:37 +10:00
STRNCPY(volume->filepath, new_file_path);
MEM_freeN(new_file_path);
BKE_packedfile_free(volume->packedfile);
volume->packedfile = nullptr;
BKE_volume_unload(volume);
ret_value = RET_OK;
}
}
return ret_value;
}
int BKE_packedfile_unpack_all_libraries(Main *bmain, ReportList *reports)
{
Library *lib;
char *newname;
int ret_value = RET_ERROR;
2018-06-17 17:05:51 +02:00
for (lib = static_cast<Library *>(bmain->libraries.first); lib;
lib = static_cast<Library *>(lib->id.next))
{
if (lib->packedfile && lib->filepath[0]) {
2018-06-17 17:05:51 +02:00
newname = BKE_packedfile_unpack_to_file(reports,
BKE_main_blendfile_path(bmain),
lib->runtime->filepath_abs,
lib->runtime->filepath_abs,
lib->packedfile,
PF_WRITE_ORIGINAL);
if (newname != nullptr) {
ret_value = RET_OK;
2018-06-17 17:05:51 +02:00
printf("Unpacked .blend library: %s\n", newname);
2018-06-17 17:05:51 +02:00
BKE_packedfile_free(lib->packedfile);
lib->packedfile = nullptr;
MEM_freeN(newname);
}
}
}
2018-06-17 17:05:51 +02:00
return ret_value;
}
void BKE_packedfile_pack_all_libraries(Main *bmain, ReportList *reports)
{
Library *lib;
2018-06-17 17:05:51 +02:00
Fix: Broken "File -> External Data -> Pack Linked Libraries" The operator refused to pack libraries with absolute paths (wasnt the case in its original implementation 16411da41e40, but was added in 129fb516f431 -- for the reason of preventing "bad things happen on unpacking" without an explanation of what these exactly are). It did so by cancelling as soon as **one** library with ab absolute path was found. Now with the introduction of essential assets, we have those absolute path linkages more or less "by default" as soon as e.g. a brush is used, so the operator is more or less unusable now. NOTE: these absolute essential asset library paths seem to be converted to relative on save? Upon reload, these are then gone... (might be another hint for an alternative fix, see below) By "bad things happen on unpacking" I would assume the scenario of folders being created in unwanted locations (e.g. when moving from one OS to another), but the same thing is also true for packing **files** instead of libraries (there, absolute paths are allowed, and unpacking in original locations can equally fail or create folder structures that are "unexpected"). NOTE: for files though we have the choice of unpacking to a relative folder (which wouldnt really be possible since libraries can be nested and we would have to correct paths all over the place). NOTE: the chance of creating "unwanted" folder structures with relative paths might be slimmer, but if you have a lot of "upwards" parent folders, relative can easily "break" as well. Possible ways to resolve this: ### [1] skip libraries identified as essentials assets (still cancel on all other absolute paths) Can check a library path to be contained in `EssentialsAssetLibrary` `essentials_directory_path`. This would be the safest imo since it is a no-behavior change. ### [2] lift the limitation of absolute paths alltogether Like mentioned above, things could break with "relative" almost as easily as with "absolute", there might even be scenarios where "absolute" is wanted. It is a more behavior-changing fix that we might explore more after 4.4 is out. ### [3] skip absolute libraries (but continue with non-absolute libraries) This does change behavior as well (it does not cancel as soon as **one** library with ab absolute path was found anymore, but the worst case scenario is that you end up with an "incomplete" file if you really mixed absolute and realtive lib linking). This PR implements [1] for now, [2] or [3] can follow for 4.5. Fixes #134665 Pull Request: https://projects.blender.org/blender/blender/pulls/134839
2025-02-28 17:14:14 +01:00
/* Only allow libraries with relative paths (to avoid issues when unpacking, a limitation that we
* might want to lift since the "relativeness" does not really ensure sanity significantly more).
*/
for (lib = static_cast<Library *>(bmain->libraries.first); lib;
lib = static_cast<Library *>(lib->id.next))
{
Fix: Broken "File -> External Data -> Pack Linked Libraries" The operator refused to pack libraries with absolute paths (wasnt the case in its original implementation 16411da41e40, but was added in 129fb516f431 -- for the reason of preventing "bad things happen on unpacking" without an explanation of what these exactly are). It did so by cancelling as soon as **one** library with ab absolute path was found. Now with the introduction of essential assets, we have those absolute path linkages more or less "by default" as soon as e.g. a brush is used, so the operator is more or less unusable now. NOTE: these absolute essential asset library paths seem to be converted to relative on save? Upon reload, these are then gone... (might be another hint for an alternative fix, see below) By "bad things happen on unpacking" I would assume the scenario of folders being created in unwanted locations (e.g. when moving from one OS to another), but the same thing is also true for packing **files** instead of libraries (there, absolute paths are allowed, and unpacking in original locations can equally fail or create folder structures that are "unexpected"). NOTE: for files though we have the choice of unpacking to a relative folder (which wouldnt really be possible since libraries can be nested and we would have to correct paths all over the place). NOTE: the chance of creating "unwanted" folder structures with relative paths might be slimmer, but if you have a lot of "upwards" parent folders, relative can easily "break" as well. Possible ways to resolve this: ### [1] skip libraries identified as essentials assets (still cancel on all other absolute paths) Can check a library path to be contained in `EssentialsAssetLibrary` `essentials_directory_path`. This would be the safest imo since it is a no-behavior change. ### [2] lift the limitation of absolute paths alltogether Like mentioned above, things could break with "relative" almost as easily as with "absolute", there might even be scenarios where "absolute" is wanted. It is a more behavior-changing fix that we might explore more after 4.4 is out. ### [3] skip absolute libraries (but continue with non-absolute libraries) This does change behavior as well (it does not cancel as soon as **one** library with ab absolute path was found anymore, but the worst case scenario is that you end up with an "incomplete" file if you really mixed absolute and realtive lib linking). This PR implements [1] for now, [2] or [3] can follow for 4.5. Fixes #134665 Pull Request: https://projects.blender.org/blender/blender/pulls/134839
2025-02-28 17:14:14 +01:00
/* Exception to the above: essential assets have an absolute path and should not prevent to
* operator from continuing. */
if (BLI_path_contains(blender::asset_system::essentials_directory_path().c_str(),
lib->filepath))
{
continue;
}
if (!BLI_path_is_rel(lib->filepath)) {
break;
}
}
2018-06-17 17:05:51 +02:00
if (lib) {
BKE_reportf(reports, RPT_ERROR, "Cannot pack absolute file: '%s'", lib->filepath);
return;
}
2018-06-17 17:05:51 +02:00
for (lib = static_cast<Library *>(bmain->libraries.first); lib;
lib = static_cast<Library *>(lib->id.next))
{
Fix: Broken "File -> External Data -> Pack Linked Libraries" The operator refused to pack libraries with absolute paths (wasnt the case in its original implementation 16411da41e40, but was added in 129fb516f431 -- for the reason of preventing "bad things happen on unpacking" without an explanation of what these exactly are). It did so by cancelling as soon as **one** library with ab absolute path was found. Now with the introduction of essential assets, we have those absolute path linkages more or less "by default" as soon as e.g. a brush is used, so the operator is more or less unusable now. NOTE: these absolute essential asset library paths seem to be converted to relative on save? Upon reload, these are then gone... (might be another hint for an alternative fix, see below) By "bad things happen on unpacking" I would assume the scenario of folders being created in unwanted locations (e.g. when moving from one OS to another), but the same thing is also true for packing **files** instead of libraries (there, absolute paths are allowed, and unpacking in original locations can equally fail or create folder structures that are "unexpected"). NOTE: for files though we have the choice of unpacking to a relative folder (which wouldnt really be possible since libraries can be nested and we would have to correct paths all over the place). NOTE: the chance of creating "unwanted" folder structures with relative paths might be slimmer, but if you have a lot of "upwards" parent folders, relative can easily "break" as well. Possible ways to resolve this: ### [1] skip libraries identified as essentials assets (still cancel on all other absolute paths) Can check a library path to be contained in `EssentialsAssetLibrary` `essentials_directory_path`. This would be the safest imo since it is a no-behavior change. ### [2] lift the limitation of absolute paths alltogether Like mentioned above, things could break with "relative" almost as easily as with "absolute", there might even be scenarios where "absolute" is wanted. It is a more behavior-changing fix that we might explore more after 4.4 is out. ### [3] skip absolute libraries (but continue with non-absolute libraries) This does change behavior as well (it does not cancel as soon as **one** library with ab absolute path was found anymore, but the worst case scenario is that you end up with an "incomplete" file if you really mixed absolute and realtive lib linking). This PR implements [1] for now, [2] or [3] can follow for 4.5. Fixes #134665 Pull Request: https://projects.blender.org/blender/blender/pulls/134839
2025-02-28 17:14:14 +01:00
/* Do not really pack essential assets though (see above). */
if (BLI_path_contains(blender::asset_system::essentials_directory_path().c_str(),
lib->filepath))
{
continue;
}
if (lib->packedfile == nullptr) {
lib->packedfile = BKE_packedfile_new(reports, lib->filepath, BKE_main_blendfile_path(bmain));
}
}
}
void BKE_packedfile_unpack_all(Main *bmain, ReportList *reports, enum ePF_FileStatus how)
2002-10-12 11:37:38 +00:00
{
Image *ima;
VFont *vf;
bSound *sound;
Volume *volume;
2002-10-12 11:37:38 +00:00
for (ima = static_cast<Image *>(bmain->images.first); ima;
ima = static_cast<Image *>(ima->id.next))
{
if (BKE_image_has_packedfile(ima) && !ID_IS_LINKED(ima)) {
BKE_packedfile_unpack_image(bmain, reports, ima, how);
}
}
for (vf = static_cast<VFont *>(bmain->fonts.first); vf; vf = static_cast<VFont *>(vf->id.next)) {
if (vf->packedfile && !ID_IS_LINKED(vf)) {
BKE_packedfile_unpack_vfont(bmain, reports, vf, how);
}
}
for (sound = static_cast<bSound *>(bmain->sounds.first); sound;
sound = static_cast<bSound *>(sound->id.next))
{
if (sound->packedfile && !ID_IS_LINKED(sound)) {
BKE_packedfile_unpack_sound(bmain, reports, sound, how);
}
}
for (volume = static_cast<Volume *>(bmain->volumes.first); volume;
volume = static_cast<Volume *>(volume->id.next))
{
if (volume->packedfile && !ID_IS_LINKED(volume)) {
BKE_packedfile_unpack_volume(bmain, reports, volume, how);
}
}
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (ID_IS_LINKED(object)) {
continue;
}
LISTBASE_FOREACH (ModifierData *, md, &object->modifiers) {
if (md->type == eModifierType_Nodes) {
NodesModifierData *nmd = reinterpret_cast<NodesModifierData *>(md);
for (NodesModifierBake &bake : blender::MutableSpan{nmd->bakes, nmd->bakes_num}) {
blender::bke::bake::unpack_geometry_nodes_bake(
*bmain, reports, *object, *nmd, bake, how);
}
}
}
}
2002-10-12 11:37:38 +00:00
}
bool BKE_packedfile_id_check(const ID *id)
{
switch (GS(id->name)) {
case ID_IM: {
const Image *ima = (const Image *)id;
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
return BKE_image_has_packedfile(ima);
}
case ID_VF: {
const VFont *vf = (const VFont *)id;
return vf->packedfile != nullptr;
}
case ID_SO: {
const bSound *snd = (const bSound *)id;
return snd->packedfile != nullptr;
}
case ID_VO: {
const Volume *volume = (const Volume *)id;
return volume->packedfile != nullptr;
}
case ID_LI: {
const Library *li = (const Library *)id;
return li->packedfile != nullptr;
}
default:
break;
}
2013-03-09 05:35:49 +00:00
return false;
}
void BKE_packedfile_id_unpack(Main *bmain, ID *id, ReportList *reports, enum ePF_FileStatus how)
{
/* Only unpack when datablock is editable. */
if (!ID_IS_EDITABLE(id)) {
return;
}
switch (GS(id->name)) {
case ID_IM: {
Image *ima = (Image *)id;
Multi-View and Stereo 3D Official Documentation: http://www.blender.org/manual/render/workflows/multiview.html Implemented Features ==================== Builtin Stereo Camera * Convergence Mode * Interocular Distance * Convergence Distance * Pivot Mode Viewport * Cameras * Plane * Volume Compositor * View Switch Node * Image Node Multi-View OpenEXR support Sequencer * Image/Movie Strips 'Use Multiview' UV/Image Editor * Option to see Multi-View images in Stereo-3D or its individual images * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images I/O * Save/Open Multi-View (OpenEXR, Stereo3D, individual views) images Scene Render Views * Ability to have an arbitrary number of views in the scene Missing Bits ============ First rule of Multi-View bug report: If something is not working as it should *when Views is off* this is a severe bug, do mention this in the report. Second rule is, if something works *when Views is off* but doesn't (or crashes) when *Views is on*, this is a important bug. Do mention this in the report. Everything else is likely small todos, and may wait until we are sure none of the above is happening. Apart from that there are those known issues: * Compositor Image Node poorly working for Multi-View OpenEXR (this was working prefectly before the 'Use Multi-View' functionality) * Selecting camera from Multi-View when looking from camera is problematic * Animation Playback (ctrl+F11) doesn't support stereo formats * Wrong filepath when trying to play back animated scene * Viewport Rendering doesn't support Multi-View * Overscan Rendering * Fullscreen display modes need to warn the user * Object copy should be aware of views suffix Acknowledgments =============== * Francesco Siddi for the help with the original feature specs and design * Brecht Van Lommel for the original review of the code and design early on * Blender Foundation for the Development Fund to support the project wrap up Final patch reviewers: * Antony Riakiotakis (psy-fi) * Campbell Barton (ideasman42) * Julian Eisel (Severin) * Sergey Sharybin (nazgul) * Thomas Dinged (dingto) Code contributors of the original branch in github: * Alexey Akishin * Gabriel Caraballo
2015-04-06 10:40:12 -03:00
if (BKE_image_has_packedfile(ima)) {
BKE_packedfile_unpack_image(bmain, reports, ima, how);
}
break;
}
case ID_VF: {
VFont *vf = (VFont *)id;
if (vf->packedfile) {
BKE_packedfile_unpack_vfont(bmain, reports, vf, how);
}
break;
}
case ID_SO: {
bSound *snd = (bSound *)id;
if (snd->packedfile) {
BKE_packedfile_unpack_sound(bmain, reports, snd, how);
}
break;
}
case ID_VO: {
Volume *volume = (Volume *)id;
if (volume->packedfile) {
BKE_packedfile_unpack_volume(bmain, reports, volume, how);
}
break;
}
case ID_LI: {
Library *li = (Library *)id;
BKE_reportf(reports, RPT_ERROR, "Cannot unpack individual Library file, '%s'", li->filepath);
break;
}
default:
break;
}
}
2024-04-03 10:22:05 +11:00
void BKE_packedfile_blend_write(BlendWriter *writer, const PackedFile *pf)
{
if (pf == nullptr) {
return;
}
BLO_write_struct(writer, PackedFile, pf);
BLO_write_shared(writer, pf->data, pf->size, pf->sharing_info, [&]() {
BLO_write_raw(writer, pf->size, pf->data);
});
}
void BKE_packedfile_blend_read(BlendDataReader *reader, PackedFile **pf_p, StringRefNull filepath)
{
BLO_read_struct(reader, PackedFile, pf_p);
PackedFile *pf = *pf_p;
if (pf == nullptr) {
return;
}
/* NOTE: there is no way to handle endianness switch here. */
pf->sharing_info = BLO_read_shared(reader, &pf->data, [&]() {
BLO_read_data_address(reader, &pf->data);
2024-08-20 14:25:52 +10:00
/* Do not create an implicit sharing if read data pointer is `nullptr`. */
return pf->data ? blender::implicit_sharing::info_for_mem_free(const_cast<void *>(pf->data)) :
nullptr;
});
if (pf->data == nullptr) {
2024-08-23 10:02:36 +10:00
/* We cannot allow a #PackedFile with a nullptr data field,
* the whole code assumes this is not possible. See #70315. */
CLOG_WARN(&LOG,
"%s: nullptr packedfile data (source: '%s'), cleaning up...",
__func__,
filepath.c_str());
BLI_assert(pf->sharing_info == nullptr);
MEM_SAFE_FREE(*pf_p);
}
}