Cleanup: Split paint_canvas into BKE and ED.
The BKE part is needed for the 3d texture paiting brush to be part of blender kernel.
This commit is contained in:
parent
babd027fae
commit
24fea2bdc4
|
@ -42,6 +42,7 @@ struct Object;
|
|||
struct PBVH;
|
||||
struct Paint;
|
||||
struct PaintCurve;
|
||||
struct PaintModeSettings;
|
||||
struct Palette;
|
||||
struct PaletteColor;
|
||||
struct Scene;
|
||||
|
@ -725,6 +726,12 @@ enum {
|
|||
SCULPT_MASK_LAYER_CALC_LOOP = (1 << 1),
|
||||
};
|
||||
|
||||
/* paint_canvas.cc */
|
||||
struct Image *BKE_paint_canvas_image_get(const struct PaintModeSettings *settings,
|
||||
struct Object *ob);
|
||||
int BKE_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
|
||||
struct Object *ob);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -235,6 +235,7 @@ set(SRC
|
|||
intern/outliner_treehash.c
|
||||
intern/packedFile.c
|
||||
intern/paint.c
|
||||
intern/paint_canvas.cc
|
||||
intern/paint_toolslots.c
|
||||
intern/particle.c
|
||||
intern/particle_child.c
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#include "BLI_compiler_compat.h"
|
||||
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_paint.h"
|
||||
|
||||
namespace blender::bke::paint::canvas {
|
||||
static TexPaintSlot *get_active_slot(Object *ob)
|
||||
{
|
||||
Material *mat = BKE_object_material_get(ob, ob->actcol);
|
||||
if (mat == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (mat->texpaintslot == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (mat->paint_active_slot >= mat->tot_slots) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TexPaintSlot *slot = &mat->texpaintslot[mat->paint_active_slot];
|
||||
return slot;
|
||||
}
|
||||
|
||||
} // namespace blender::bke::paint::canvas
|
||||
|
||||
extern "C" {
|
||||
|
||||
using namespace blender::bke::paint::canvas;
|
||||
|
||||
Image *BKE_paint_canvas_image_get(const struct PaintModeSettings *settings, struct Object *ob)
|
||||
{
|
||||
switch (settings->canvas_source) {
|
||||
case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE:
|
||||
return nullptr;
|
||||
case PAINT_CANVAS_SOURCE_IMAGE:
|
||||
return settings->canvas_image;
|
||||
case PAINT_CANVAS_SOURCE_MATERIAL: {
|
||||
TexPaintSlot *slot = get_active_slot(ob);
|
||||
if (slot == nullptr) {
|
||||
break;
|
||||
}
|
||||
return slot->ima;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int BKE_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
|
||||
struct Object *ob)
|
||||
{
|
||||
switch (settings->canvas_source) {
|
||||
case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE:
|
||||
return -1;
|
||||
case PAINT_CANVAS_SOURCE_IMAGE: {
|
||||
/* Use active uv map of the object. */
|
||||
if (ob->type != OB_MESH) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const Mesh *mesh = static_cast<Mesh *>(ob->data);
|
||||
return CustomData_get_active_layer_index(&mesh->ldata, CD_MLOOPUV);
|
||||
}
|
||||
case PAINT_CANVAS_SOURCE_MATERIAL: {
|
||||
/* Use uv map of the canvas. */
|
||||
TexPaintSlot *slot = get_active_slot(ob);
|
||||
if (slot == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ob->type != OB_MESH) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (slot->uvname == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const Mesh *mesh = static_cast<Mesh *>(ob->data);
|
||||
return CustomData_get_named_layer_index(&mesh->ldata, CD_MLOOPUV, slot->uvname);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
|
@ -114,11 +114,6 @@ void ED_paintcurve_undo_push_end(struct bContext *C);
|
|||
void ED_paintcurve_undosys_type(struct UndoType *ut);
|
||||
|
||||
/* paint_canvas.cc */
|
||||
struct Image *ED_paint_canvas_image_get(const struct PaintModeSettings *settings,
|
||||
struct Object *ob);
|
||||
int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
|
||||
struct Object *ob);
|
||||
|
||||
/** Color type of an object can be overridden in sculpt/paint mode. */
|
||||
eV3DShadingColorType ED_paint_shading_color_override(struct bContext *C,
|
||||
const struct PaintModeSettings *settings,
|
||||
|
|
|
@ -2,20 +2,11 @@
|
|||
#include "BLI_compiler_compat.h"
|
||||
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_workspace_types.h"
|
||||
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_material.h"
|
||||
#include "BKE_paint.h"
|
||||
#include "BKE_pbvh.h"
|
||||
|
||||
#include "DEG_depsgraph.h"
|
||||
|
||||
#include "NOD_shader.h"
|
||||
|
||||
#include "WM_toolsystem.h"
|
||||
|
||||
|
@ -43,16 +34,15 @@ static TexPaintSlot *get_active_slot(Object *ob)
|
|||
|
||||
extern "C" {
|
||||
|
||||
using namespace blender;
|
||||
using namespace blender::ed::sculpt_paint::canvas;
|
||||
|
||||
/* Does the paint tool with the given idname uses a canvas. */
|
||||
static bool paint_tool_uses_canvas(StringRef idname)
|
||||
static bool paint_tool_uses_canvas(blender::StringRef idname)
|
||||
{
|
||||
return ELEM(idname, "builtin_brush.Paint", "builtin_brush.Smear", "builtin.color_filter");
|
||||
}
|
||||
|
||||
static bool paint_tool_shading_color_follows_last_used(StringRef idname)
|
||||
static bool paint_tool_shading_color_follows_last_used(blender::StringRef idname)
|
||||
{
|
||||
/* TODO(jbakker): complete this list. */
|
||||
return ELEM(idname, "builtin_brush.Mask");
|
||||
|
@ -147,59 +137,4 @@ eV3DShadingColorType ED_paint_shading_color_override(bContext *C,
|
|||
|
||||
return color_type;
|
||||
}
|
||||
|
||||
Image *ED_paint_canvas_image_get(const struct PaintModeSettings *settings, struct Object *ob)
|
||||
{
|
||||
switch (settings->canvas_source) {
|
||||
case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE:
|
||||
return nullptr;
|
||||
case PAINT_CANVAS_SOURCE_IMAGE:
|
||||
return settings->canvas_image;
|
||||
case PAINT_CANVAS_SOURCE_MATERIAL: {
|
||||
TexPaintSlot *slot = get_active_slot(ob);
|
||||
if (slot == nullptr) {
|
||||
break;
|
||||
}
|
||||
return slot->ima;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int ED_paint_canvas_uvmap_layer_index_get(const struct PaintModeSettings *settings,
|
||||
struct Object *ob)
|
||||
{
|
||||
switch (settings->canvas_source) {
|
||||
case PAINT_CANVAS_SOURCE_COLOR_ATTRIBUTE:
|
||||
return -1;
|
||||
case PAINT_CANVAS_SOURCE_IMAGE: {
|
||||
/* Use active uv map of the object. */
|
||||
if (ob->type != OB_MESH) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const Mesh *mesh = static_cast<Mesh *>(ob->data);
|
||||
return CustomData_get_active_layer_index(&mesh->ldata, CD_MLOOPUV);
|
||||
}
|
||||
case PAINT_CANVAS_SOURCE_MATERIAL: {
|
||||
/* Use uv map of the canvas. */
|
||||
TexPaintSlot *slot = get_active_slot(ob);
|
||||
if (slot == nullptr) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (ob->type != OB_MESH) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (slot->uvname == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
const Mesh *mesh = static_cast<Mesh *>(ob->data);
|
||||
return CustomData_get_named_layer_index(&mesh->ldata, CD_MLOOPUV, slot->uvname);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue