Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2020-03-17 16:41:48 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2020-03-18 13:23:05 +0300
commitb0a1cf2c9ae696b07f7a236bc855a5ab4a493dcb (patch)
tree92295af11db5e984da42bfac7ca60190b8549a3f /source/blender/blenloader
parent8dcfd392e4e62f193b666304425bc5ae635ecffe (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/blenloader')
-rw-r--r--source/blender/blenloader/intern/readblenentry.c6
-rw-r--r--source/blender/blenloader/intern/readfile.c211
-rw-r--r--source/blender/blenloader/intern/readfile.h3
-rw-r--r--source/blender/blenloader/intern/writefile.c104
4 files changed, 323 insertions, 1 deletions
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 085e500f7e5..c12df2bc87d 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -402,6 +402,9 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
/* make lookups of existing sound data in old main */
blo_make_sound_pointer_map(fd, oldmain);
+ /* make lookups of existing volume data in old main */
+ blo_make_volume_pointer_map(fd, oldmain);
+
/* removed packed data from this trick - it's internal data that needs saves */
bfd = blo_read_file_internal(fd, filename);
@@ -418,6 +421,9 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
/* ensures relinked sounds are not freed */
blo_end_sound_pointer_map(fd, oldmain);
+ /* ensures relinked volumes are not freed */
+ blo_end_volume_pointer_map(fd, oldmain);
+
/* Still in-use libraries have already been moved from oldmain to new mainlist,
* but oldmain itself shall *never* be 'transferred' to new mainlist! */
BLI_assert(old_mainlist.first == oldmain);
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f1f274f97d5..7e4d676954a 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -58,6 +58,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_shader_fx_types.h"
+#include "DNA_hair_types.h"
#include "DNA_ipo_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
@@ -74,6 +75,7 @@
#include "DNA_object_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_particle_types.h"
+#include "DNA_pointcloud_types.h"
#include "DNA_curveprofile_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
@@ -88,6 +90,7 @@
#include "DNA_sound_types.h"
#include "DNA_space_types.h"
#include "DNA_vfont_types.h"
+#include "DNA_volume_types.h"
#include "DNA_workspace_types.h"
#include "DNA_world_types.h"
#include "DNA_movieclip_types.h"
@@ -118,6 +121,7 @@
#include "BKE_fluid.h"
#include "BKE_global.h" // for G
#include "BKE_gpencil_modifier.h"
+#include "BKE_hair.h"
#include "BKE_idcode.h"
#include "BKE_idprop.h"
#include "BKE_layer.h"
@@ -136,13 +140,14 @@
#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
-#include "BKE_curveprofile.h"
+#include "BKE_pointcloud.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
#include "BKE_shader_fx.h"
#include "BKE_sound.h"
+#include "BKE_volume.h"
#include "BKE_workspace.h"
#include "DRW_engine.h"
@@ -1595,6 +1600,9 @@ void blo_filedata_free(FileData *fd)
if (fd->soundmap) {
oldnewmap_free(fd->soundmap);
}
+ if (fd->volumemap) {
+ oldnewmap_free(fd->volumemap);
+ }
if (fd->packedmap) {
oldnewmap_free(fd->packedmap);
}
@@ -1806,6 +1814,15 @@ static void *newsoundadr(FileData *fd, const void *adr)
return NULL;
}
+/* used to restore volume data after undo */
+static void *newvolumeadr(FileData *fd, const void *adr)
+{
+ if (fd->volumemap && adr) {
+ return oldnewmap_lookup_and_inc(fd->volumemap, adr, true);
+ }
+ return NULL;
+}
+
/* used to restore packed data after undo */
static void *newpackedadr(FileData *fd, const void *adr)
{
@@ -2112,6 +2129,37 @@ void blo_end_sound_pointer_map(FileData *fd, Main *oldmain)
}
}
+void blo_make_volume_pointer_map(FileData *fd, Main *oldmain)
+{
+ fd->volumemap = oldnewmap_new();
+
+ Volume *volume = oldmain->volumes.first;
+ for (; volume; volume = volume->id.next) {
+ if (volume->runtime.grids) {
+ oldnewmap_insert(fd->volumemap, volume->runtime.grids, volume->runtime.grids, 0);
+ }
+ }
+}
+
+/* set old main volume caches to zero if it has been restored */
+/* this works because freeing old main only happens after this call */
+void blo_end_volume_pointer_map(FileData *fd, Main *oldmain)
+{
+ OldNew *entry = fd->volumemap->entries;
+ Volume *volume = oldmain->volumes.first;
+ int i;
+
+ /* used entries were restored, so we put them to zero */
+ for (i = 0; i < fd->volumemap->nentries; i++, entry++) {
+ if (entry->nr > 0)
+ entry->newp = NULL;
+ }
+
+ for (; volume; volume = volume->id.next) {
+ volume->runtime.grids = newvolumeadr(fd, volume->runtime.grids);
+ }
+}
+
/* XXX disabled this feature - packed files also belong in temp saves and quit.blend,
* to make restore work. */
@@ -2126,6 +2174,7 @@ void blo_make_packed_pointer_map(FileData *fd, Main *oldmain)
Image *ima;
VFont *vfont;
bSound *sound;
+ Volume *volume;
Library *lib;
fd->packedmap = oldnewmap_new();
@@ -2156,6 +2205,12 @@ void blo_make_packed_pointer_map(FileData *fd, Main *oldmain)
}
}
+ for (volume = oldmain->volumes.first; volume; volume = volume->id.next) {
+ if (volume->packedfile) {
+ insert_packedmap(fd, volume->packedfile);
+ }
+ }
+
for (lib = oldmain->libraries.first; lib; lib = lib->id.next) {
if (lib->packedfile) {
insert_packedmap(fd, lib->packedfile);
@@ -2170,6 +2225,7 @@ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain)
Image *ima;
VFont *vfont;
bSound *sound;
+ Volume *volume;
Library *lib;
OldNew *entry = fd->packedmap->entries;
int i;
@@ -2202,6 +2258,10 @@ void blo_end_packed_pointer_map(FileData *fd, Main *oldmain)
for (lib = oldmain->libraries.first; lib; lib = lib->id.next) {
lib->packedfile = newpackedadr(fd, lib->packedfile);
}
+
+ for (volume = oldmain->volumes.first; volume; volume = volume->id.next) {
+ volume->packedfile = newpackedadr(fd, volume->packedfile);
+ }
}
/* undo file support: add all library pointers in lookup */
@@ -8962,6 +9022,89 @@ static void direct_link_linestyle(FileData *fd, FreestyleLineStyle *linestyle)
/** \} */
/* -------------------------------------------------------------------- */
+/** \name Read ID: Hair
+ * \{ */
+
+static void lib_link_hair(FileData *fd, Main *UNUSED(main), Hair *hair)
+{
+ for (int a = 0; a < hair->totcol; a++) {
+ hair->mat[a] = newlibadr(fd, hair->id.lib, hair->mat[a]);
+ }
+}
+
+static void direct_link_hair(FileData *fd, Hair *hair)
+{
+ hair->adt = newdataadr(fd, hair->adt);
+ direct_link_animdata(fd, hair->adt);
+
+ /* Geometry */
+ direct_link_customdata(fd, &hair->pdata, hair->totpoint);
+ direct_link_customdata(fd, &hair->cdata, hair->totcurve);
+ BKE_hair_update_customdata_pointers(hair);
+
+ /* Materials */
+ hair->mat = newdataadr(fd, hair->mat);
+ test_pointer_array(fd, (void **)&hair->mat);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Read ID: Point Cloud
+ * \{ */
+
+static void lib_link_pointcloud(FileData *fd, Main *UNUSED(main), PointCloud *pointcloud)
+{
+ for (int a = 0; a < pointcloud->totcol; a++) {
+ pointcloud->mat[a] = newlibadr(fd, pointcloud->id.lib, pointcloud->mat[a]);
+ }
+}
+
+static void direct_link_pointcloud(FileData *fd, PointCloud *pointcloud)
+{
+ pointcloud->adt = newdataadr(fd, pointcloud->adt);
+ direct_link_animdata(fd, pointcloud->adt);
+
+ /* Geometry */
+ direct_link_customdata(fd, &pointcloud->pdata, pointcloud->totpoint);
+ BKE_pointcloud_update_customdata_pointers(pointcloud);
+
+ /* Materials */
+ pointcloud->mat = newdataadr(fd, pointcloud->mat);
+ test_pointer_array(fd, (void **)&pointcloud->mat);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Read ID: Volume
+ * \{ */
+
+static void lib_link_volume(FileData *fd, Main *UNUSED(main), Volume *volume)
+{
+ for (int a = 0; a < volume->totcol; a++) {
+ volume->mat[a] = newlibadr(fd, volume->id.lib, volume->mat[a]);
+ }
+}
+
+static void direct_link_volume(FileData *fd, Volume *volume)
+{
+ volume->adt = newdataadr(fd, volume->adt);
+ direct_link_animdata(fd, volume->adt);
+
+ volume->packedfile = direct_link_packedfile(fd, volume->packedfile);
+ volume->runtime.grids = (fd->volumemap) ? newvolumeadr(fd, volume->runtime.grids) : NULL;
+ volume->runtime.frame = 0;
+ BKE_volume_init_grids(volume);
+
+ /* materials */
+ volume->mat = newdataadr(fd, volume->mat);
+ test_pointer_array(fd, (void **)&volume->mat);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
/** \name Read Library Data Block
* \{ */
@@ -9073,6 +9216,12 @@ static const char *dataname(short id_code)
return "Data from CF";
case ID_WS:
return "Data from WS";
+ case ID_HA:
+ return "Data from HA";
+ case ID_PT:
+ return "Data from PT";
+ case ID_VO:
+ return "Data from VO";
}
return "Data from Lib Block";
}
@@ -9498,6 +9647,15 @@ static BHead *read_libblock(FileData *fd,
case ID_WS:
direct_link_workspace(fd, (WorkSpace *)id, main);
break;
+ case ID_HA:
+ direct_link_hair(fd, (Hair *)id);
+ break;
+ case ID_PT:
+ direct_link_pointcloud(fd, (PointCloud *)id);
+ break;
+ case ID_VO:
+ direct_link_volume(fd, (Volume *)id);
+ break;
}
oldnewmap_free_unused(fd->datamap);
@@ -9825,6 +9983,15 @@ static void lib_link_all(FileData *fd, Main *bmain)
case ID_VF:
lib_link_vfont(fd, bmain, (VFont *)id);
break;
+ case ID_HA:
+ lib_link_hair(fd, bmain, (Hair *)id);
+ break;
+ case ID_PT:
+ lib_link_pointcloud(fd, bmain, (PointCloud *)id);
+ break;
+ case ID_VO:
+ lib_link_volume(fd, bmain, (Volume *)id);
+ break;
case ID_MA:
lib_link_material(fd, bmain, (Material *)id);
break;
@@ -11236,6 +11403,39 @@ static void expand_workspace(FileData *fd, Main *mainvar, WorkSpace *workspace)
}
}
+static void expand_hair(FileData *fd, Main *mainvar, Hair *hair)
+{
+ for (int a = 0; a < hair->totcol; a++) {
+ expand_doit(fd, mainvar, hair->mat[a]);
+ }
+
+ if (hair->adt) {
+ expand_animdata(fd, mainvar, hair->adt);
+ }
+}
+
+static void expand_pointcloud(FileData *fd, Main *mainvar, PointCloud *pointcloud)
+{
+ for (int a = 0; a < pointcloud->totcol; a++) {
+ expand_doit(fd, mainvar, pointcloud->mat[a]);
+ }
+
+ if (pointcloud->adt) {
+ expand_animdata(fd, mainvar, pointcloud->adt);
+ }
+}
+
+static void expand_volume(FileData *fd, Main *mainvar, Volume *volume)
+{
+ for (int a = 0; a < volume->totcol; a++) {
+ expand_doit(fd, mainvar, volume->mat[a]);
+ }
+
+ if (volume->adt) {
+ expand_animdata(fd, mainvar, volume->adt);
+ }
+}
+
/**
* Set the callback func used over all ID data found by \a BLO_expand_main func.
*
@@ -11356,6 +11556,15 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_WS:
expand_workspace(fd, mainvar, (WorkSpace *)id);
break;
+ case ID_HA:
+ expand_hair(fd, mainvar, (Hair *)id);
+ break;
+ case ID_PT:
+ expand_pointcloud(fd, mainvar, (PointCloud *)id);
+ break;
+ case ID_VO:
+ expand_volume(fd, mainvar, (Volume *)id);
+ break;
default:
break;
}
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 4965845d167..fce6a1d8ff7 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -124,6 +124,7 @@ typedef struct FileData {
struct OldNewMap *movieclipmap;
struct OldNewMap *scenemap;
struct OldNewMap *soundmap;
+ struct OldNewMap *volumemap;
struct OldNewMap *packedmap;
struct BHeadSort *bheadmap;
@@ -164,6 +165,8 @@ void blo_make_movieclip_pointer_map(FileData *fd, struct Main *oldmain);
void blo_end_movieclip_pointer_map(FileData *fd, struct Main *oldmain);
void blo_make_sound_pointer_map(FileData *fd, struct Main *oldmain);
void blo_end_sound_pointer_map(FileData *fd, struct Main *oldmain);
+void blo_make_volume_pointer_map(FileData *fd, struct Main *oldmain);
+void blo_end_volume_pointer_map(FileData *fd, struct Main *oldmain);
void blo_make_packed_pointer_map(FileData *fd, struct Main *oldmain);
void blo_end_packed_pointer_map(FileData *fd, struct Main *oldmain);
void blo_add_library_pointer_map(ListBase *old_mainlist, FileData *fd);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 837134c0156..c948949c06e 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -106,6 +106,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_gpencil_modifier_types.h"
#include "DNA_shader_fx_types.h"
+#include "DNA_hair_types.h"
#include "DNA_fileglobal_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
@@ -121,6 +122,7 @@
#include "DNA_object_force_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_particle_types.h"
+#include "DNA_pointcloud_types.h"
#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
@@ -134,6 +136,7 @@
#include "DNA_text_types.h"
#include "DNA_view3d_types.h"
#include "DNA_vfont_types.h"
+#include "DNA_volume_types.h"
#include "DNA_world_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_workspace_types.h"
@@ -3712,6 +3715,98 @@ static void write_workspace(WriteData *wd, WorkSpace *workspace)
}
}
+static void write_hair(WriteData *wd, Hair *hair)
+{
+ if (hair->id.us > 0 || wd->use_memfile) {
+ /* Write a copy of the hair with possibly reduced number of data layers.
+ * Don't edit the original since other threads might be reading it. */
+ Hair *old_hair = hair;
+ Hair copy_hair = *hair;
+ hair = &copy_hair;
+
+ CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
+ CustomDataLayer *clayers = NULL, clayers_buff[CD_TEMP_CHUNK_SIZE];
+ CustomData_file_write_prepare(&hair->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
+ CustomData_file_write_prepare(&hair->cdata, &clayers, clayers_buff, ARRAY_SIZE(clayers_buff));
+
+ /* Write LibData */
+ writestruct_at_address(wd, ID_HA, Hair, 1, old_hair, hair);
+ write_iddata(wd, &hair->id);
+
+ /* Direct data */
+ write_customdata(wd, &hair->id, hair->totpoint, &hair->pdata, players, CD_MASK_ALL);
+ write_customdata(wd, &hair->id, hair->totcurve, &hair->cdata, clayers, CD_MASK_ALL);
+ writedata(wd, DATA, sizeof(void *) * hair->totcol, hair->mat);
+ if (hair->adt) {
+ write_animdata(wd, hair->adt);
+ }
+
+ /* Remove temporary data. */
+ if (players && players != players_buff) {
+ MEM_freeN(players);
+ }
+ if (clayers && clayers != clayers_buff) {
+ MEM_freeN(clayers);
+ }
+
+ /* restore pointer */
+ hair = old_hair;
+ }
+}
+
+static void write_pointcloud(WriteData *wd, PointCloud *pointcloud)
+{
+ if (pointcloud->id.us > 0 || wd->use_memfile) {
+ /* Write a copy of the pointcloud with possibly reduced number of data layers.
+ * Don't edit the original since other threads might be reading it. */
+ PointCloud *old_pointcloud = pointcloud;
+ PointCloud copy_pointcloud = *pointcloud;
+ pointcloud = &copy_pointcloud;
+
+ CustomDataLayer *players = NULL, players_buff[CD_TEMP_CHUNK_SIZE];
+ CustomData_file_write_prepare(
+ &pointcloud->pdata, &players, players_buff, ARRAY_SIZE(players_buff));
+
+ /* Write LibData */
+ writestruct_at_address(wd, ID_PT, PointCloud, 1, old_pointcloud, pointcloud);
+ write_iddata(wd, &pointcloud->id);
+
+ /* Direct data */
+ write_customdata(
+ wd, &pointcloud->id, pointcloud->totpoint, &pointcloud->pdata, players, CD_MASK_ALL);
+ writedata(wd, DATA, sizeof(void *) * pointcloud->totcol, pointcloud->mat);
+ if (pointcloud->adt) {
+ write_animdata(wd, pointcloud->adt);
+ }
+
+ /* Remove temporary data. */
+ if (players && players != players_buff) {
+ MEM_freeN(players);
+ }
+ }
+}
+
+static void write_volume(WriteData *wd, Volume *volume)
+{
+ if (volume->id.us > 0 || wd->use_memfile) {
+ /* write LibData */
+ writestruct(wd, ID_VO, Volume, 1, volume);
+ write_iddata(wd, &volume->id);
+
+ /* direct data */
+ writedata(wd, DATA, sizeof(void *) * volume->totcol, volume->mat);
+ if (volume->adt) {
+ write_animdata(wd, volume->adt);
+ }
+
+ if (volume->packedfile) {
+ PackedFile *pf = volume->packedfile;
+ writestruct(wd, DATA, PackedFile, 1, pf);
+ writedata(wd, DATA, pf->size, pf->data);
+ }
+ }
+}
+
/* Keep it last of write_foodata functions. */
static void write_libraries(WriteData *wd, Main *main)
{
@@ -4017,6 +4112,15 @@ static bool write_file_handle(Main *mainvar,
case ID_CF:
write_cachefile(wd, (CacheFile *)id);
break;
+ case ID_HA:
+ write_hair(wd, (Hair *)id);
+ break;
+ case ID_PT:
+ write_pointcloud(wd, (PointCloud *)id);
+ break;
+ case ID_VO:
+ write_volume(wd, (Volume *)id);
+ break;
case ID_LI:
/* Do nothing, handled below - and should never be reached. */
BLI_assert(0);