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:
Diffstat (limited to 'source/blender/blenkernel/intern/mball.c')
-rw-r--r--source/blender/blenkernel/intern/mball.c82
1 files changed, 76 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index fe6f1bd4a97..d71c100ed87 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -35,6 +35,9 @@
#include "MEM_guardedalloc.h"
+/* Allow using deprecated functionality for .blend file I/O. */
+#define DNA_DEPRECATED_ALLOW
+
#include "DNA_defaults.h"
#include "DNA_material_types.h"
#include "DNA_meta_types.h"
@@ -50,6 +53,7 @@
#include "BKE_main.h"
+#include "BKE_anim_data.h"
#include "BKE_curve.h"
#include "BKE_displist.h"
#include "BKE_idtype.h"
@@ -62,6 +66,8 @@
#include "DEG_depsgraph.h"
+#include "BLO_read_write.h"
+
static void metaball_init_data(ID *id)
{
MetaBall *metaball = (MetaBall *)id;
@@ -110,6 +116,71 @@ static void metaball_foreach_id(ID *id, LibraryForeachIDData *data)
}
}
+static void metaball_blend_write(BlendWriter *writer, ID *id, const void *id_address)
+{
+ MetaBall *mb = (MetaBall *)id;
+ if (mb->id.us > 0 || BLO_write_is_undo(writer)) {
+ /* Clean up, important in undo case to reduce false detection of changed datablocks. */
+ BLI_listbase_clear(&mb->disp);
+ mb->editelems = NULL;
+ /* Must always be cleared (meta's don't have their own edit-data). */
+ mb->needs_flush_to_id = 0;
+ mb->lastelem = NULL;
+ mb->batch_cache = NULL;
+
+ /* write LibData */
+ BLO_write_id_struct(writer, MetaBall, id_address, &mb->id);
+ BKE_id_blend_write(writer, &mb->id);
+
+ /* direct data */
+ BLO_write_pointer_array(writer, mb->totcol, mb->mat);
+ if (mb->adt) {
+ BKE_animdata_blend_write(writer, mb->adt);
+ }
+
+ LISTBASE_FOREACH (MetaElem *, ml, &mb->elems) {
+ BLO_write_struct(writer, MetaElem, ml);
+ }
+ }
+}
+
+static void metaball_blend_read_data(BlendDataReader *reader, ID *id)
+{
+ MetaBall *mb = (MetaBall *)id;
+ BLO_read_data_address(reader, &mb->adt);
+ BKE_animdata_blend_read_data(reader, mb->adt);
+
+ BLO_read_pointer_array(reader, (void **)&mb->mat);
+
+ BLO_read_list(reader, &(mb->elems));
+
+ BLI_listbase_clear(&mb->disp);
+ mb->editelems = NULL;
+ /* Must always be cleared (meta's don't have their own edit-data). */
+ mb->needs_flush_to_id = 0;
+ /* mb->edit_elems.first= mb->edit_elems.last= NULL;*/
+ mb->lastelem = NULL;
+ mb->batch_cache = NULL;
+}
+
+static void metaball_blend_read_lib(BlendLibReader *reader, ID *id)
+{
+ MetaBall *mb = (MetaBall *)id;
+ for (int a = 0; a < mb->totcol; a++) {
+ BLO_read_id_address(reader, mb->id.lib, &mb->mat[a]);
+ }
+
+ BLO_read_id_address(reader, mb->id.lib, &mb->ipo); // XXX deprecated - old animation system
+}
+
+static void metaball_blend_read_expand(BlendExpander *expander, ID *id)
+{
+ MetaBall *mb = (MetaBall *)id;
+ for (int a = 0; a < mb->totcol; a++) {
+ BLO_expand(expander, mb->mat[a]);
+ }
+}
+
IDTypeInfo IDType_ID_MB = {
.id_code = ID_MB,
.id_filter = FILTER_ID_MB,
@@ -127,10 +198,10 @@ IDTypeInfo IDType_ID_MB = {
.foreach_id = metaball_foreach_id,
.foreach_cache = NULL,
- .blend_write = NULL,
- .blend_read_data = NULL,
- .blend_read_lib = NULL,
- .blend_read_expand = NULL,
+ .blend_write = metaball_blend_write,
+ .blend_read_data = metaball_blend_read_data,
+ .blend_read_lib = metaball_blend_read_lib,
+ .blend_read_expand = metaball_blend_read_expand,
};
/* Functions */
@@ -484,7 +555,6 @@ bool BKE_mball_minmax_ex(
LISTBASE_FOREACH (const MetaElem *, ml, &mb->elems) {
if ((ml->flag & flag) == flag) {
const float scale_mb = (ml->rad * 0.5f) * scale;
- int i;
if (obmat) {
mul_v3_m4v3(centroid, obmat, &ml->x);
@@ -494,7 +564,7 @@ bool BKE_mball_minmax_ex(
}
/* TODO, non circle shapes cubes etc, probably nobody notices - campbell */
- for (i = -1; i != 3; i += 2) {
+ for (int i = -1; i != 3; i += 2) {
copy_v3_v3(vec, centroid);
add_v3_fl(vec, scale_mb * i);
minmax_v3v3_v3(min, max, vec);