Blender  V3.3
Classes | Typedefs | Functions
object_bake_api.c File Reference
#include "MEM_guardedalloc.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BKE_attribute.h"
#include "BKE_callbacks.h"
#include "BKE_context.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_image_format.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_modifier.h"
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_query.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_object.h"
#include "ED_screen.h"
#include "ED_uvedit.h"
#include "object_intern.h"

Go to the source code of this file.

Classes

struct  BakeAPIRender
 

Typedefs

typedef struct BakeAPIRender BakeAPIRender
 

Functions

static void bake_set_props (wmOperator *op, Scene *scene)
 
static void bake_progress_update (void *bjv, float progress)
 
static int bake_modal (bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
 
static int bake_break (void *UNUSED(rjv))
 
static void bake_update_image (ScrArea *area, Image *image)
 
static bool write_internal_bake_pixels (Image *image, const int image_tile_number, BakePixel pixel_array[], float *buffer, const int width, const int height, const int margin, const char margin_type, const bool is_clear, const bool is_noncolor, Mesh const *mesh_eval, char const *uv_layer, const float uv_offset[2])
 
static void bake_targets_refresh (BakeTargets *targets)
 
static bool write_external_bake_pixels (const char *filepath, BakePixel pixel_array[], float *buffer, const int width, const int height, const int margin, const int margin_type, ImageFormatData const *im_format, const bool is_noncolor, Mesh const *mesh_eval, char const *uv_layer, const float uv_offset[2])
 
static bool is_noncolor_pass (eScenePassType pass_type)
 
static bool bake_object_check (ViewLayer *view_layer, Object *ob, const eBakeTarget target, ReportList *reports)
 
static bool bake_pass_filter_check (eScenePassType pass_type, const int pass_filter, ReportList *reports)
 
static bool bake_objects_check (Main *bmain, ViewLayer *view_layer, Object *ob, ListBase *selected_objects, ReportList *reports, const bool is_selected_to_active, const eBakeTarget target)
 
static void bake_targets_clear (Main *bmain, const bool is_tangent)
 
static Meshbake_mesh_new_from_object (Depsgraph *depsgraph, Object *object, const bool preserve_origindex)
 
static bool bake_targets_init_image_textures (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, ReportList *reports)
 
static bool bake_targets_init_internal (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, ReportList *reports)
 
static bool bake_targets_output_internal (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, BakePixel *pixel_array, ReportList *reports, Mesh *mesh_eval)
 
static bool bake_targets_init_external (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, ReportList *reports)
 
static bool bake_targets_output_external (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, Object *ob_eval, Mesh *mesh_eval, BakePixel *pixel_array, ReportList *reports)
 
static bool bake_targets_init_vertex_colors (Main *bmain, BakeTargets *targets, Object *ob, ReportList *reports)
 
static int find_original_loop (const Mesh *me_orig, const int *vert_origindex, const int *poly_origindex, const int poly_eval, const int vert_eval)
 
static void bake_targets_populate_pixels_color_attributes (BakeTargets *targets, Object *ob, Mesh *me_eval, BakePixel *pixel_array)
 
static void bake_result_add_to_rgba (float rgba[4], const float *result, const int channels_num)
 
static void convert_float_color_to_byte_color (const MPropCol *float_colors, const int num, const bool is_noncolor, MLoopCol *byte_colors)
 
static bool bake_targets_output_vertex_colors (BakeTargets *targets, Object *ob)
 
static bool bake_targets_init (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, Object *ob_eval, ReportList *reports)
 
static void bake_targets_populate_pixels (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, Mesh *me_eval, BakePixel *pixel_array)
 
static bool bake_targets_output (const BakeAPIRender *bkr, BakeTargets *targets, Object *ob, Object *ob_eval, Mesh *me_eval, BakePixel *pixel_array, ReportList *reports)
 
static void bake_targets_free (BakeTargets *targets)
 
static int bake (const BakeAPIRender *bkr, Object *ob_low, const ListBase *selected_objects, ReportList *reports)
 
static void bake_init_api_data (wmOperator *op, bContext *C, BakeAPIRender *bkr)
 
static int bake_exec (bContext *C, wmOperator *op)
 
static void bake_startjob (void *bkv, short *UNUSED(stop), short *do_update, float *progress)
 
static void bake_job_complete (void *bkv)
 
static void bake_job_canceled (void *bkv)
 
static void bake_freejob (void *bkv)
 
static int bake_invoke (bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
 
void OBJECT_OT_bake (wmOperatorType *ot)
 

Typedef Documentation

◆ BakeAPIRender

typedef struct BakeAPIRender BakeAPIRender

Function Documentation

◆ bake()

static int bake ( const BakeAPIRender bkr,
Object ob_low,
const ListBase selected_objects,
ReportList reports 
)
static

Definition at line 1322 of file object_bake_api.c.

References bake_mesh_new_from_object(), bake_targets_free(), bake_targets_init(), bake_targets_output(), bake_targets_populate_pixels(), bake_targets_refresh(), BASE_ENABLED_RENDER, Object::base_flag, BASE_VISIBLE_DEPSGRAPH, BKE_id_free(), BKE_mesh_new_from_object(), BKE_modifier_free(), BKE_modifiers_findby_type(), BKE_object_eval_reset(), BKE_object_handle_data_update(), BKE_report(), BKE_reportf(), BKE_scene_graph_update_tagged(), BLI_assert, BLI_findstring(), BLI_remlink(), BakeAPIRender::cage_extrusion, CD_MLOOPUV, BakeTargets::channels_num, copy_m4_m4(), BakeAPIRender::custom_cage, CustomData_get_named_layer(), DAG_EVAL_RENDER, Object::data, PointerRNA::data, DEG_get_evaluated_object(), DEG_graph_build_from_view_layer(), DEG_graph_free(), DEG_graph_new(), depsgraph, eModifierMode_Render, eModifierType_EdgeSplit, eModifierType_Multires, ListBase::first, MultiresModifierData::flags, Mesh::id, Object::id, if(), invert_m4_m4(), BakeAPIRender::is_cage, BakeHighPolyData::is_flip_object, is_negative_m4(), BakeAPIRender::is_selected_to_active, Mesh::ldata, BakeAPIRender::main, BakeAPIRender::max_ray_distance, BakeHighPolyData::me, MEM_callocN, MEM_freeN, MEM_mallocN, ModifierData::mode, Object::modifiers, ID::name, ModifierData::next, CollectionPointerLink::next, BakeAPIRender::normal_space, BakeAPIRender::normal_swizzle, NULL, BakeHighPolyData::ob, BakeHighPolyData::ob_eval, OB_HIDE_RENDER, OB_MESH, Main::objects, Object::obmat, BakeHighPolyData::obmat, OPERATOR_CANCELLED, OPERATOR_FINISHED, BakeAPIRender::pass_filter, BakeAPIRender::pass_type, BakeTargets::pixels_num, CollectionPointerLink::ptr, R_BAKE_POSX, R_BAKE_POSY, R_BAKE_POSZ, R_BAKE_SPACE_OBJECT, R_BAKE_SPACE_TANGENT, R_BAKE_SPACE_WORLD, R_BAKE_TARGET_VERTEX_COLORS, RE_bake_engine(), RE_bake_engine_set_engine_parameters(), RE_bake_has_engine(), RE_bake_normal_world_to_object(), RE_bake_normal_world_to_tangent(), RE_bake_normal_world_to_world(), RE_bake_pixels_populate_from_objects(), BakeAPIRender::render, BakeTargets::result, RPT_ERROR, SCE_PASS_NORMAL, scene, BakeAPIRender::scene, SUBSURF_UV_SMOOTH_NONE, BakeAPIRender::target, Mesh::totloop, Mesh::totpoly, ModifierData::type, Object::type, BakeAPIRender::uv_layer, MultiresModifierData::uv_smooth, BakeAPIRender::view_layer, and Object::visibility_flag.

Referenced by bake_exec(), bake_set_props(), bake_startjob(), bake_targets_output_external(), and BKE_ptcache_bake().

◆ bake_break()

static int bake_break ( void UNUSEDrjv)
static

for exec() when there is no render job NOTE: this won't check for the escape key being pressed, but doing so isn't thread-safe.

Definition at line 153 of file object_bake_api.c.

References G.

Referenced by bake_exec(), and bake_invoke().

◆ bake_exec()

static int bake_exec ( bContext C,
wmOperator op 
)
static

◆ bake_freejob()

static void bake_freejob ( void bkv)
static

Definition at line 1902 of file object_bake_api.c.

References BLI_freelistN(), G, MEM_freeN, and BakeAPIRender::selected_objects.

Referenced by bake_invoke().

◆ bake_init_api_data()

static void bake_init_api_data ( wmOperator op,
bContext C,
BakeAPIRender bkr 
)
static

◆ bake_invoke()

static int bake_invoke ( bContext C,
wmOperator op,
const wmEvent UNUSEDevent 
)
static

◆ bake_job_canceled()

static void bake_job_canceled ( void bkv)
static

◆ bake_job_complete()

static void bake_job_complete ( void bkv)
static

◆ bake_mesh_new_from_object()

static Mesh* bake_mesh_new_from_object ( Depsgraph depsgraph,
Object object,
const bool  preserve_origindex 
)
static

Definition at line 663 of file object_bake_api.c.

References BKE_mesh_new_from_object(), BKE_mesh_split_faces(), depsgraph, Mesh::flag, and ME_AUTOSMOOTH.

Referenced by bake().

◆ bake_modal()

static int bake_modal ( bContext C,
wmOperator UNUSEDop,
const wmEvent event 
)
static

◆ bake_object_check()

static bool bake_object_check ( ViewLayer view_layer,
Object ob,
const eBakeTarget  target,
ReportList reports 
)
static

◆ bake_objects_check()

static bool bake_objects_check ( Main bmain,
ViewLayer view_layer,
Object ob,
ListBase selected_objects,
ReportList reports,
const bool  is_selected_to_active,
const eBakeTarget  target 
)
static

◆ bake_pass_filter_check()

static bool bake_pass_filter_check ( eScenePassType  pass_type,
const int  pass_filter,
ReportList reports 
)
static

◆ bake_progress_update()

static void bake_progress_update ( void bjv,
float  progress 
)
static

Definition at line 119 of file object_bake_api.c.

References BakeAPIRender::do_update, and BakeAPIRender::progress.

Referenced by bake_invoke().

◆ bake_result_add_to_rgba()

static void bake_result_add_to_rgba ( float  rgba[4],
const float result,
const int  channels_num 
)
static

Definition at line 1082 of file object_bake_api.c.

References add_v3_v3(), add_v4_v4(), result, and usdtokens::rgba().

Referenced by bake_targets_output_vertex_colors().

◆ bake_set_props()

static void bake_set_props ( wmOperator op,
Scene scene 
)
static

◆ bake_startjob()

static void bake_startjob ( void bkv,
short *  UNUSEDstop,
short *  do_update,
float progress 
)
static

◆ bake_targets_clear()

static void bake_targets_clear ( Main bmain,
const bool  is_tangent 
)
static

Definition at line 652 of file object_bake_api.c.

References ListBase::first, image(), Main::images, LIB_TAG_DOIT, and RE_bake_ibuf_clear().

Referenced by bake_exec(), and bake_startjob().

◆ bake_targets_free()

static void bake_targets_free ( BakeTargets targets)
static

◆ bake_targets_init()

static bool bake_targets_init ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
Object ob_eval,
ReportList reports 
)
static

◆ bake_targets_init_external()

static bool bake_targets_init_external ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
ReportList reports 
)
static

◆ bake_targets_init_image_textures()

static bool bake_targets_init_image_textures ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
ReportList reports 
)
static

◆ bake_targets_init_internal()

static bool bake_targets_init_internal ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
ReportList reports 
)
static

◆ bake_targets_init_vertex_colors()

static bool bake_targets_init_vertex_colors ( Main bmain,
BakeTargets targets,
Object ob,
ReportList reports 
)
static

◆ bake_targets_output()

static bool bake_targets_output ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
Object ob_eval,
Mesh me_eval,
BakePixel pixel_array,
ReportList reports 
)
static

◆ bake_targets_output_external()

static bool bake_targets_output_external ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
Object ob_eval,
Mesh mesh_eval,
BakePixel pixel_array,
ReportList reports 
)
static

◆ bake_targets_output_internal()

static bool bake_targets_output_internal ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
BakePixel pixel_array,
ReportList reports,
Mesh mesh_eval 
)
static

◆ bake_targets_output_vertex_colors()

static bool bake_targets_output_vertex_colors ( BakeTargets targets,
Object ob 
)
static

◆ bake_targets_populate_pixels()

static void bake_targets_populate_pixels ( const BakeAPIRender bkr,
BakeTargets targets,
Object ob,
Mesh me_eval,
BakePixel pixel_array 
)
static

◆ bake_targets_populate_pixels_color_attributes()

static void bake_targets_populate_pixels_color_attributes ( BakeTargets targets,
Object ob,
Mesh me_eval,
BakePixel pixel_array 
)
static

◆ bake_targets_refresh()

static void bake_targets_refresh ( BakeTargets targets)
static

◆ bake_update_image()

static void bake_update_image ( ScrArea area,
Image image 
)
static

◆ convert_float_color_to_byte_color()

static void convert_float_color_to_byte_color ( const MPropCol float_colors,
const int  num,
const bool  is_noncolor,
MLoopCol byte_colors 
)
static

◆ find_original_loop()

static int find_original_loop ( const Mesh me_orig,
const int *  vert_origindex,
const int *  poly_origindex,
const int  poly_eval,
const int  vert_eval 
)
static

◆ is_noncolor_pass()

static bool is_noncolor_pass ( eScenePassType  pass_type)
static

◆ OBJECT_OT_bake()

void OBJECT_OT_bake ( wmOperatorType ot)

◆ write_external_bake_pixels()

static bool write_external_bake_pixels ( const char *  filepath,
BakePixel  pixel_array[],
float buffer,
const int  width,
const int  height,
const int  margin,
const int  margin_type,
ImageFormatData const *  im_format,
const bool  is_noncolor,
Mesh const *  mesh_eval,
char const *  uv_layer,
const float  uv_offset[2] 
)
static

◆ write_internal_bake_pixels()

static bool write_internal_bake_pixels ( Image image,
const int  image_tile_number,
BakePixel  pixel_array[],
float buffer,
const int  width,
const int  height,
const int  margin,
const char  margin_type,
const bool  is_clear,
const bool  is_noncolor,
Mesh const *  mesh_eval,
char const *  uv_layer,
const float  uv_offset[2] 
)
static