Refactor: move Paint .blend I/O to blenkernel
Ref T76372.
This commit is contained in:
parent
e810a16d75
commit
9ad2965921
Notes:
blender-bot
2023-02-14 06:21:59 +01:00
Referenced by issue #76372, Blenloader Decentralization
|
@ -66,6 +66,8 @@ struct ViewLayer;
|
|||
struct bContext;
|
||||
struct bToolRef;
|
||||
struct tPaletteColorHSV;
|
||||
struct BlendWriter;
|
||||
struct BlendDataReader;
|
||||
|
||||
enum eOverlayFlags;
|
||||
|
||||
|
@ -217,6 +219,12 @@ void BKE_paint_toolslots_brush_update(struct Paint *paint);
|
|||
void BKE_paint_toolslots_brush_validate(struct Main *bmain, struct Paint *paint);
|
||||
struct Brush *BKE_paint_toolslots_brush_get(struct Paint *paint, int slot_index);
|
||||
|
||||
/* .blend I/O */
|
||||
void BKE_paint_blend_write(struct BlendWriter *writer, struct Paint *paint);
|
||||
void BKE_paint_blend_read_data(struct BlendDataReader *reader,
|
||||
const struct Scene *scene,
|
||||
struct Paint *paint);
|
||||
|
||||
#define SCULPT_FACE_SET_NONE 0
|
||||
|
||||
/* Used for both vertex color and weight paint */
|
||||
|
|
|
@ -1176,6 +1176,40 @@ void BKE_paint_stroke_get_average(Scene *scene, Object *ob, float stroke[3])
|
|||
}
|
||||
}
|
||||
|
||||
void BKE_paint_blend_write(BlendWriter *writer, Paint *p)
|
||||
{
|
||||
if (p->cavity_curve) {
|
||||
BKE_curvemapping_blend_write(writer, p->cavity_curve);
|
||||
}
|
||||
BLO_write_struct_array(writer, PaintToolSlot, p->tool_slots_len, p->tool_slots);
|
||||
}
|
||||
|
||||
void BKE_paint_blend_read_data(BlendDataReader *reader, const Scene *scene, Paint *p)
|
||||
{
|
||||
if (p->num_input_samples < 1) {
|
||||
p->num_input_samples = 1;
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &p->cavity_curve);
|
||||
if (p->cavity_curve) {
|
||||
BKE_curvemapping_blend_read(reader, p->cavity_curve);
|
||||
}
|
||||
else {
|
||||
BKE_paint_cavity_curve_preset(p, CURVE_PRESET_LINE);
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &p->tool_slots);
|
||||
|
||||
/* Workaround for invalid data written in older versions. */
|
||||
const size_t expected_size = sizeof(PaintToolSlot) * p->tool_slots_len;
|
||||
if (p->tool_slots && MEM_allocN_len(p->tool_slots) < expected_size) {
|
||||
MEM_freeN(p->tool_slots);
|
||||
p->tool_slots = MEM_callocN(expected_size, "PaintToolSlot");
|
||||
}
|
||||
|
||||
BKE_paint_runtime_init(scene->toolsettings, p);
|
||||
}
|
||||
|
||||
/* returns non-zero if any of the face's vertices
|
||||
* are hidden, zero otherwise */
|
||||
bool paint_is_face_hidden(const MLoopTri *lt, const MVert *mvert, const MLoop *mloop)
|
||||
|
|
|
@ -4181,39 +4181,13 @@ static void link_recurs_seq(BlendDataReader *reader, ListBase *lb)
|
|||
}
|
||||
}
|
||||
|
||||
static void direct_link_paint(BlendDataReader *reader, const Scene *scene, Paint *p)
|
||||
{
|
||||
if (p->num_input_samples < 1) {
|
||||
p->num_input_samples = 1;
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &p->cavity_curve);
|
||||
if (p->cavity_curve) {
|
||||
BKE_curvemapping_blend_read(reader, p->cavity_curve);
|
||||
}
|
||||
else {
|
||||
BKE_paint_cavity_curve_preset(p, CURVE_PRESET_LINE);
|
||||
}
|
||||
|
||||
BLO_read_data_address(reader, &p->tool_slots);
|
||||
|
||||
/* Workaround for invalid data written in older versions. */
|
||||
const size_t expected_size = sizeof(PaintToolSlot) * p->tool_slots_len;
|
||||
if (p->tool_slots && MEM_allocN_len(p->tool_slots) < expected_size) {
|
||||
MEM_freeN(p->tool_slots);
|
||||
p->tool_slots = MEM_callocN(expected_size, "PaintToolSlot");
|
||||
}
|
||||
|
||||
BKE_paint_runtime_init(scene->toolsettings, p);
|
||||
}
|
||||
|
||||
static void direct_link_paint_helper(BlendDataReader *reader, const Scene *scene, Paint **paint)
|
||||
{
|
||||
/* TODO. is this needed */
|
||||
BLO_read_data_address(reader, paint);
|
||||
|
||||
if (*paint) {
|
||||
direct_link_paint(reader, scene, *paint);
|
||||
BKE_paint_blend_read_data(reader, scene, *paint);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4280,7 +4254,7 @@ static void direct_link_scene(BlendDataReader *reader, Scene *sce)
|
|||
direct_link_paint_helper(reader, sce, (Paint **)&sce->toolsettings->gp_sculptpaint);
|
||||
direct_link_paint_helper(reader, sce, (Paint **)&sce->toolsettings->gp_weightpaint);
|
||||
|
||||
direct_link_paint(reader, sce, &sce->toolsettings->imapaint.paint);
|
||||
BKE_paint_blend_read_data(reader, sce, &sce->toolsettings->imapaint.paint);
|
||||
|
||||
sce->toolsettings->particle.paintcursor = NULL;
|
||||
sce->toolsettings->particle.scene = NULL;
|
||||
|
|
|
@ -153,6 +153,7 @@
|
|||
#include "BKE_node.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_packedFile.h"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_pointcache.h"
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_screen.h"
|
||||
|
@ -1323,10 +1324,7 @@ static void write_view_settings(BlendWriter *writer, ColorManagedViewSettings *v
|
|||
|
||||
static void write_paint(BlendWriter *writer, Paint *p)
|
||||
{
|
||||
if (p->cavity_curve) {
|
||||
BKE_curvemapping_blend_write(writer, p->cavity_curve);
|
||||
}
|
||||
BLO_write_struct_array(writer, PaintToolSlot, p->tool_slots_len, p->tool_slots);
|
||||
BKE_paint_blend_write(writer, p);
|
||||
}
|
||||
|
||||
static void write_layer_collections(BlendWriter *writer, ListBase *lb)
|
||||
|
|
Loading…
Reference in New Issue