Cycles: new Microfacet-based Hair BSDF with elliptical cross-section support #105600

Merged
Weizhen Huang merged 114 commits from weizhen/blender:microfacet_hair into main 2023-08-18 12:46:20 +02:00
141 changed files with 5335 additions and 3434 deletions
Showing only changes of commit 05e7caed94 - Show all commits

View File

@ -210,7 +210,7 @@ ccl_device_forceinline float3 microfacet_sample_stretched(KernelGlobals kg,
/* 2. sample P22_{wi}(x_slope, y_slope, 1, 1) */
float slope_x, slope_y;
if constexpr (m_type == MicrofacetType::BECKMANN) {
if (m_type == MicrofacetType::BECKMANN) {
microfacet_beckmann_sample_slopes(
kg, costheta_, sintheta_, randu, randv, &slope_x, &slope_y, G1i);
}
@ -276,13 +276,14 @@ ccl_device_forceinline float bsdf_clearcoat_D(float alpha2, float cos_NH)
template<MicrofacetType m_type>
ccl_device_inline float bsdf_G1_from_sqr_alpha_tan_n(float sqr_alpha_tan_n)
{
if constexpr (m_type == MicrofacetType::GGX) {
if (m_type == MicrofacetType::GGX) {
return 2.0f / (1.0f + sqrtf(1.0f + sqr_alpha_tan_n));
}
/* m_type == MicrofacetType::BECKMANN */
const float a = inversesqrtf(sqr_alpha_tan_n);
return (a > 1.6f) ? 1.0f : ((2.181f * a + 3.535f) * a) / ((2.577f * a + 2.276f) * a + 1.0f);
else {
/* m_type == MicrofacetType::BECKMANN */
const float a = inversesqrtf(sqr_alpha_tan_n);
return (a > 1.6f) ? 1.0f : ((2.181f * a + 3.535f) * a) / ((2.577f * a + 2.276f) * a + 1.0f);
}
}
template<MicrofacetType m_type> ccl_device_inline float bsdf_G1(float alpha2, float cos_N)
@ -309,12 +310,13 @@ template<MicrofacetType m_type> ccl_device_inline float bsdf_D(float alpha2, flo
{
const float cos_NH2 = sqr(cos_NH);
if constexpr (m_type == MicrofacetType::BECKMANN) {
if (m_type == MicrofacetType::BECKMANN) {
return expf((1.0f - 1.0f / cos_NH2) / alpha2) / (M_PI_F * alpha2 * sqr(cos_NH2));
}
/* m_type == MicrofacetType::GGX */
return alpha2 / (M_PI_F * sqr(1.0f + (alpha2 - 1.0f) * cos_NH2));
else {
/* m_type == MicrofacetType::GGX */
return alpha2 / (M_PI_F * sqr(1.0f + (alpha2 - 1.0f) * cos_NH2));
}
}
template<MicrofacetType m_type>
@ -325,12 +327,13 @@ ccl_device_inline float bsdf_aniso_D(float alpha_x, float alpha_y, float3 H)
const float cos_NH2 = sqr(H.z);
const float alpha2 = alpha_x * alpha_y;
if constexpr (m_type == MicrofacetType::BECKMANN) {
if (m_type == MicrofacetType::BECKMANN) {
return expf(-(sqr(H.x) + sqr(H.y)) / cos_NH2) / (M_PI_F * alpha2 * sqr(cos_NH2));
}
/* m_type == MicrofacetType::GGX */
return M_1_PI_F / (alpha2 * sqr(len_squared(H)));
else {
/* m_type == MicrofacetType::GGX */
return M_1_PI_F / (alpha2 * sqr(len_squared(H)));
}
}
ccl_device_forceinline void bsdf_microfacet_fresnel_color(ccl_private const ShaderData *sd,

View File

@ -235,8 +235,6 @@ ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg,
light_sample_to_surface_shadow_ray(kg, sd, &ls, &ray);
}
const bool is_light = light_sample_is_light(&ls);
/* Branch off shadow kernel. */
IntegratorShadowState shadow_state = integrator_shadow_path_init(
kg, state, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SHADOW, false);

View File

@ -821,7 +821,6 @@ ccl_device_forceinline void integrate_volume_direct_light(
/* Create shadow ray. */
Ray ray ccl_optional_struct_init;
light_sample_to_volume_shadow_ray(kg, sd, &ls, P, &ray);
const bool is_light = light_sample_is_light(&ls);
/* Branch off shadow kernel. */
IntegratorShadowState shadow_state = integrator_shadow_path_init(

View File

@ -88,13 +88,6 @@ light_sample_shader_eval(KernelGlobals kg,
return eval;
}
/* Test if light sample is from a light or emission from geometry. */
ccl_device_inline bool light_sample_is_light(ccl_private const LightSample *ccl_restrict ls)
{
/* return if it's a lamp for shadow pass */
return (ls->prim == PRIM_NONE && ls->type != LIGHT_BACKGROUND);
}
/* Early path termination of shadow rays. */
ccl_device_inline bool light_sample_terminate(KernelGlobals kg,
ccl_private const LightSample *ccl_restrict ls,

View File

@ -464,12 +464,17 @@ void GHOST_NDOFManager::updateButton(int button_number, bool press, uint64_t tim
ndof_button_names[button]);
GHOST_IWindow *window = system_.getWindowManager()->getActiveWindow();
const GHOST_TKey key = ghost_map_keyboard_from_ndof_buttom(button);
if (key != GHOST_kKeyUnknown) {
sendKeyEvent(key, press, time, window);
}
else {
sendButtonEvent(button, press, time, window);
/* Delivery will fail, so don't bother sending.
* Do, however update the buttons internal depressed state. */
if (window != nullptr) {
const GHOST_TKey key = ghost_map_keyboard_from_ndof_buttom(button);
if (key != GHOST_kKeyUnknown) {
sendKeyEvent(key, press, time, window);
}
else {
sendButtonEvent(button, press, time, window);
}
}
int mask = 1 << button_number;
@ -547,9 +552,11 @@ bool GHOST_NDOFManager::sendMotionEvent()
GHOST_IWindow *window = system_.getWindowManager()->getActiveWindow();
/* Delivery will fail, so don't bother sending. */
if (window == nullptr) {
motion_state_ = GHOST_kNotStarted; /* Avoid large `dt` times when changing windows. */
return false; /* Delivery will fail, so don't bother sending. */
/* Avoid large `dt` times when changing windows. */
motion_state_ = GHOST_kNotStarted;
return false;
}
GHOST_EventNDOFMotion *event = new GHOST_EventNDOFMotion(motion_time_, window);

View File

@ -2586,8 +2586,6 @@ static void pointer_handle_enter(void *data,
GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface);
win->activate();
GWL_Seat *seat = static_cast<GWL_Seat *>(data);
seat->cursor_source_serial = serial;
seat->pointer.serial = serial;
@ -2627,8 +2625,6 @@ static void pointer_handle_leave(void *data,
static_cast<GWL_Seat *>(data)->pointer.wl_surface_window = nullptr;
if (wl_surface && ghost_wl_surface_own(wl_surface)) {
CLOG_INFO(LOG, 2, "leave");
GHOST_WindowWayland *win = ghost_wl_surface_user_data(wl_surface);
win->deactivate();
}
else {
CLOG_INFO(LOG, 2, "leave (skipped)");

View File

@ -55,6 +55,7 @@ _km_hierarchy = [
('Curve', 'EMPTY', 'WINDOW', [
_km_expand_from_toolsystem('VIEW_3D', 'EDIT_CURVE'),
]),
('Curves', 'EMPTY', 'WINDOW', []),
('Armature', 'EMPTY', 'WINDOW', [
_km_expand_from_toolsystem('VIEW_3D', 'EDIT_ARMATURE'),
]),

View File

@ -352,8 +352,7 @@ def load():
use_v3d_tab_menu=kc_prefs.use_v3d_tab_menu,
use_v3d_shade_ex_pie=kc_prefs.use_v3d_shade_ex_pie,
use_gizmo_drag=(is_select_left and kc_prefs.gizmo_action == 'DRAG'),
use_fallback_tool=True,
use_fallback_tool_rmb=(False if is_select_left else kc_prefs.rmb_action == 'FALLBACK_TOOL'),
use_fallback_tool=True if is_select_left else (kc_prefs.rmb_action == 'FALLBACK_TOOL'),
use_tweak_select_passthrough=(show_developer_ui and kc_prefs.use_tweak_select_passthrough),
use_tweak_tool_lmb_interaction=(
False if is_select_left else

View File

@ -11,7 +11,7 @@ __all__ = (
# - This script should run without Blender (no references to the `bpy` module for example).
# - All configuration must be passed into the `generate_keymaps` function (via `Params`).
# - Supporting some combinations of options is becoming increasingly complex,
# especially `Params.select_mouse` & `Params.use_fallback_tool_rmb`.
# especially `Params.select_mouse` & `Params.use_fallback_tool`.
# To ensure changes don't unintentionally break other configurations, see:
# `source/tools/utils/blender_keyconfig_export_permutations.py --help`
#
@ -52,8 +52,6 @@ class Params:
"use_gizmo_drag",
# Use the fallback tool instead of tweak for RMB select.
"use_fallback_tool",
# Only set for RMB select.
"use_fallback_tool_rmb",
# Use pie menu for tab by default (swap 'Tab/Ctrl-Tab').
"use_v3d_tab_menu",
# Use extended pie menu for shading.
@ -78,9 +76,9 @@ class Params:
# (derived from other settings).
#
# The fallback tool is activated on the same button as selection.
# Shorthand for: `(True if (select_mouse == 'LEFT') else self.use_fallback_tool_rmb)`
# Shorthand for: `(True if (select_mouse == 'LEFT') else self.use_fallback_tool)`
"use_fallback_tool_select_mouse",
# Shorthand for: `('CLICK' if self.use_fallback_tool_rmb else self.select_mouse_value)`.
# Shorthand for: `('CLICK' if self.use_fallback_tool and select_mouse == 'RIGHT' else self.select_mouse_value)`.
"select_mouse_value_fallback",
# Shorthand for: `{"type": params.select_mouse, "value": 'CLICK_DRAG'}`.
"select_tweak_event",
@ -110,7 +108,6 @@ class Params:
use_select_all_toggle=False,
use_gizmo_drag=True,
use_fallback_tool=False,
use_fallback_tool_rmb=False,
use_tweak_select_passthrough=False,
use_tweak_tool_lmb_interaction=False,
use_v3d_tab_menu=False,
@ -202,11 +199,12 @@ class Params:
self.use_tweak_select_passthrough = use_tweak_select_passthrough
self.use_fallback_tool = use_fallback_tool
self.use_fallback_tool_rmb = use_fallback_tool_rmb
# Convenience variables:
self.use_fallback_tool_select_mouse = True if (select_mouse == 'LEFT') else self.use_fallback_tool_rmb
self.select_mouse_value_fallback = 'CLICK' if self.use_fallback_tool_rmb else self.select_mouse_value
self.use_fallback_tool_select_mouse = True if (select_mouse == 'LEFT') else self.use_fallback_tool
self.select_mouse_value_fallback = (
'CLICK' if (self.use_fallback_tool and select_mouse == 'RIGHT') else self.select_mouse_value
)
self.select_tweak_event = {"type": self.select_mouse, "value": 'CLICK_DRAG'}
self.pie_value = 'CLICK_DRAG' if use_pie_click_drag else 'PRESS'
self.tool_tweak_event = {"type": self.tool_mouse, "value": 'CLICK_DRAG'}
@ -4720,7 +4718,7 @@ def _template_paint_radial_control(paint, rotation=False, secondary_rotation=Fal
def _template_view3d_select(*, type, value, legacy, select_passthrough, exclude_mod=None):
# NOTE: `exclude_mod` is needed since we don't want this tool to exclude Control-RMB actions when this is used
# as a tool key-map with RMB-select and `use_fallback_tool_rmb` is enabled. See T92467.
# as a tool key-map with RMB-select and `use_fallback_tool` is enabled with RMB select. See T92467.
props_vert_without_handles = ()
if select_passthrough:
@ -5615,6 +5613,14 @@ def km_curves(params):
{"items": items},
)
items.extend([
("curves.set_selection_domain", {"type": 'ONE', "value": 'PRESS'}, {"properties": [("domain", 'POINT')]}),
("curves.set_selection_domain", {"type": 'TWO', "value": 'PRESS'}, {"properties": [("domain", 'CURVE')]}),
("curves.disable_selection", {"type": 'ONE', "value": 'PRESS', "alt": True}, None),
("curves.disable_selection", {"type": 'TWO', "value": 'PRESS', "alt": True}, None),
*_template_items_select_actions(params, "curves.select_all"),
])
return keymap
@ -6493,11 +6499,12 @@ def km_image_editor_tool_uv_select(params, *, fallback):
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "uv.select", "uv.cursor_set", fallback=fallback)),
*([] if (not params.use_fallback_tool_rmb) else _template_uv_select(
type=params.select_mouse,
value=params.select_mouse_value,
select_passthrough=params.use_tweak_select_passthrough,
legacy=params.legacy,
*([] if (not (params.use_fallback_tool and params.select_mouse == 'RIGHTMOUSE')) else
_template_uv_select(
type=params.select_mouse,
value=params.select_mouse_value,
select_passthrough=params.use_tweak_select_passthrough,
legacy=params.legacy,
)),
]},
)
@ -6712,12 +6719,13 @@ def km_3d_view_tool_select(params, *, fallback):
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "view3d.select", "view3d.cursor3d", operator_props=operator_props, fallback=fallback)),
*([] if (not params.use_fallback_tool_rmb) else _template_view3d_select(
type=params.select_mouse,
value=params.select_mouse_value,
legacy=params.legacy,
select_passthrough=params.use_tweak_select_passthrough,
exclude_mod="ctrl",
*([] if (not (params.use_fallback_tool and params.select_mouse == 'RIGHTMOUSE')) else
_template_view3d_select(
type=params.select_mouse,
value=params.select_mouse_value,
legacy=params.legacy,
select_passthrough=params.use_tweak_select_passthrough,
exclude_mod="ctrl",
)),
]},
)
@ -7656,8 +7664,12 @@ def km_3d_view_tool_edit_gpencil_select(params, *, fallback):
{"items": [
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "gpencil.select", "view3d.cursor3d", fallback=fallback)),
*([] if (not params.use_fallback_tool_rmb) else _template_view3d_gpencil_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy)),
*([] if (not (params.use_fallback_tool and params.select_mouse == 'RIGHTMOUSE')) else
_template_view3d_gpencil_select(
type=params.select_mouse,
value=params.select_mouse_value,
legacy=params.legacy,
)),
]},
)
@ -7835,8 +7847,9 @@ def km_sequencer_editor_tool_generic_select(params, *, fallback):
*([] if (fallback and (params.select_mouse == 'RIGHTMOUSE')) else _template_items_tool_select(
params, "sequencer.select", "sequencer.cursor_set", cursor_prioritize=True, fallback=fallback)),
*([] if (not params.use_fallback_tool_rmb) else _template_sequencer_preview_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy)),
*([] if (not (params.use_fallback_tool and params.select_mouse == 'RIGHTMOUSE')) else
_template_sequencer_preview_select(
type=params.select_mouse, value=params.select_mouse_value, legacy=params.legacy)),
# Ignored for preview.
*_template_items_change_frame(params),
]},

View File

@ -101,6 +101,7 @@ class NODE_MT_geometry_node_GEO_CURVE_OPERATIONS(Menu):
node_add_menu.add_node_type(layout, "GeometryNodeDeformCurvesOnSurface")
node_add_menu.add_node_type(layout, "GeometryNodeFillCurve")
node_add_menu.add_node_type(layout, "GeometryNodeFilletCurve")
node_add_menu.add_node_type(layout, "GeometryNodeInterpolateCurves")
node_add_menu.add_node_type(layout, "GeometryNodeResampleCurve")
node_add_menu.add_node_type(layout, "GeometryNodeReverseCurve")
node_add_menu.add_node_type(layout, "GeometryNodeSampleCurve")

View File

@ -718,7 +718,7 @@ class VIEW3D_HT_header(Header):
if object_mode == 'PARTICLE_EDIT':
row = layout.row()
row.prop(tool_settings.particle_edit, "select_mode", text="", expand=True)
elif object_mode == 'SCULPT_CURVES' and obj.type == 'CURVES':
elif object_mode in {'EDIT', 'SCULPT_CURVES'} and obj.type == 'CURVES':
curves = obj.data
row = layout.row(align=True)
@ -2044,7 +2044,13 @@ class VIEW3D_MT_select_edit_curves(Menu):
bl_label = "Select"
def draw(self, _context):
pass
layout = self.layout
layout.operator("curves.select_all", text="All").action = 'SELECT'
layout.operator("curves.select_all", text="None").action = 'DESELECT'
layout.operator("curves.select_all", text="Invert").action = 'INVERT'
layout.operator("curves.select_random", text="Random")
layout.operator("curves.select_end", text="Endpoints")
class VIEW3D_MT_select_sculpt_curves(Menu):
@ -2057,7 +2063,7 @@ class VIEW3D_MT_select_sculpt_curves(Menu):
layout.operator("curves.select_all", text="None").action = 'DESELECT'
layout.operator("curves.select_all", text="Invert").action = 'INVERT'
layout.operator("sculpt_curves.select_random", text="Random")
layout.operator("sculpt_curves.select_end", text="Endpoints")
layout.operator("curves.select_end", text="Endpoints")
layout.operator("sculpt_curves.select_grow", text="Grow")
@ -5326,7 +5332,10 @@ class VIEW3D_MT_edit_curves(Menu):
bl_label = "Curves"
def draw(self, _context):
pass
layout = self.layout
layout.menu("VIEW3D_MT_transform")
layout.separator()
class VIEW3D_MT_object_mode_pie(Menu):

View File

@ -32,6 +32,9 @@ class IDPropertyDeleter {
}
};
/** \brief Allocate a new IDProperty of type IDP_BOOLEAN, set its name and value. */
std::unique_ptr<IDProperty, IDPropertyDeleter> create_bool(StringRefNull prop_name, bool value);
/** \brief Allocate a new IDProperty of type IDP_INT, set its name and value. */
std::unique_ptr<IDProperty, IDPropertyDeleter> create(StringRefNull prop_name, int32_t value);

View File

@ -156,7 +156,7 @@ void old_mdisps_bilinear(float out[3], float (*disps)[3], int st, float u, float
int mdisp_rot_face_to_crn(
struct MPoly *mpoly, int face_side, float u, float v, float *x, float *y);
/* Reshaping, define in multires_reshape.c */
/* Reshaping, define in multires_reshape.cc */
bool multiresModifier_reshapeFromVertcos(struct Depsgraph *depsgraph,
struct Object *object,
@ -204,7 +204,7 @@ void multiresModifier_subdivide_to_level(struct Object *object,
int top_level,
eMultiresSubdivideModeType mode);
/* Subdivision integration, defined in multires_subdiv.c */
/* Subdivision integration, defined in multires_subdiv.cc */
struct SubdivSettings;
struct SubdivToMeshSettings;

View File

@ -1535,6 +1535,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, i
#define GEO_NODE_IMAGE_INFO 1189
#define GEO_NODE_BLUR_ATTRIBUTE 1190
#define GEO_NODE_IMAGE 1191
#define GEO_NODE_INTERPOLATE_CURVES 1192
/** \} */

View File

@ -93,6 +93,7 @@ typedef enum eUndoPushReturn {
UNDO_PUSH_RET_SUCCESS = (1 << 0),
UNDO_PUSH_RET_OVERRIDE_CHANGED = (1 << 1),
} eUndoPushReturn;
ENUM_OPERATORS(eUndoPushReturn, UNDO_PUSH_RET_OVERRIDE_CHANGED)
typedef void (*UndoTypeForEachIDRefFn)(void *user_data, struct UndoRefID *id_ref);
@ -137,7 +138,7 @@ typedef struct UndoType {
/**
* The size of the undo struct 'inherited' from #UndoStep for that specific type. Used for
* generic allocation in BKE's `undo_system.c`. */
* generic allocation in BKE's `undo_system.cc`. */
size_t step_size;
} UndoType;

View File

@ -114,7 +114,9 @@ int BKE_volume_grid_channels(const struct VolumeGrid *grid);
* Transformation from index space to object space.
*/
void BKE_volume_grid_transform_matrix(const struct VolumeGrid *grid, float mat[4][4]);
void BKE_volume_grid_transform_matrix_set(struct VolumeGrid *volume_grid, const float mat[4][4]);
void BKE_volume_grid_transform_matrix_set(const struct Volume *volume,
struct VolumeGrid *volume_grid,
const float mat[4][4]);
/* Volume Editing
*

View File

@ -78,9 +78,9 @@ set(SRC
intern/autoexec.c
intern/blender.c
intern/blender_copybuffer.c
intern/blender_undo.c
intern/blender_undo.cc
intern/blender_user_menu.c
intern/blendfile.c
intern/blendfile.cc
intern/blendfile_link_append.c
intern/boids.c
intern/bpath.c
@ -89,7 +89,7 @@ set(SRC
intern/cachefile.c
intern/callbacks.c
intern/camera.c
intern/cdderivedmesh.c
intern/cdderivedmesh.cc
intern/cloth.cc
intern/collection.c
intern/collision.c
@ -119,9 +119,9 @@ set(SRC
intern/customdata.cc
intern/customdata_file.c
intern/data_transfer.cc
intern/deform.c
intern/deform.cc
intern/displist.cc
intern/dynamicpaint.c
intern/dynamicpaint.cc
intern/editlattice.c
intern/editmesh.cc
intern/editmesh_bvh.c
@ -131,7 +131,7 @@ set(SRC
intern/fcurve.c
intern/fcurve_cache.c
intern/fcurve_driver.c
intern/fluid.c
intern/fluid.cc
intern/fmodifier.c
intern/freestyle.c
intern/geometry_component_curves.cc
@ -216,16 +216,16 @@ set(SRC
intern/modifier.cc
intern/movieclip.c
intern/multires.cc
intern/multires_reshape.c
intern/multires_reshape_apply_base.c
intern/multires_reshape_ccg.c
intern/multires_reshape_smooth.c
intern/multires_reshape_subdivide.c
intern/multires_reshape_util.c
intern/multires_reshape_vertcos.c
intern/multires_subdiv.c
intern/multires_unsubdivide.c
intern/multires_versioning.c
intern/multires_reshape.cc
intern/multires_reshape_apply_base.cc
intern/multires_reshape_ccg.cc
intern/multires_reshape_smooth.cc
intern/multires_reshape_subdivide.cc
intern/multires_reshape_util.cc
intern/multires_reshape_vertcos.cc
intern/multires_subdiv.cc
intern/multires_unsubdivide.cc
intern/multires_versioning.cc
intern/nla.c
intern/node.cc
intern/node_runtime.cc
@ -296,7 +296,7 @@ set(SRC
intern/tracking_stabilize.c
intern/tracking_util.c
intern/type_conversions.cc
intern/undo_system.c
intern/undo_system.cc
intern/unit.c
intern/vfont.c
intern/vfontdata_freetype.c

View File

@ -63,10 +63,10 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
G.fileflags |= G_FILE_NO_UI;
if (UNDO_DISK) {
const struct BlendFileReadParams params = {0};
BlendFileReadReport bf_reports = {.reports = NULL};
const BlendFileReadParams params{};
BlendFileReadReport bf_reports{};
struct BlendFileData *bfd = BKE_blendfile_read(mfu->filepath, &params, &bf_reports);
if (bfd != NULL) {
if (bfd != nullptr) {
BKE_blendfile_read_setup(C, bfd, &params, &bf_reports);
success = true;
}
@ -77,10 +77,11 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
if (!use_old_bmain_data) {
params.skip_flags |= BLO_READ_SKIP_UNDO_OLD_MAIN;
}
BlendFileReadReport blend_file_read_report{};
struct BlendFileData *bfd = BKE_blendfile_read_from_memfile(
bmain, &mfu->memfile, &params, NULL);
if (bfd != NULL) {
BKE_blendfile_read_setup(C, bfd, &params, &(BlendFileReadReport){NULL});
bmain, &mfu->memfile, &params, nullptr);
if (bfd != nullptr) {
BKE_blendfile_read_setup(C, bfd, &params, &blend_file_read_report);
success = true;
}
}
@ -100,7 +101,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
{
MemFileUndoData *mfu = MEM_callocN(sizeof(MemFileUndoData), __func__);
MemFileUndoData *mfu = MEM_cnew<MemFileUndoData>(__func__);
/* Include recovery information since undo-data is written out as #BLENDER_QUIT_FILE. */
const int fileflags = G.fileflags | G_FILE_RECOVER_WRITE;
@ -118,13 +119,14 @@ MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
BLI_snprintf(numstr, sizeof(numstr), "%d.blend", counter);
BLI_path_join(filepath, sizeof(filepath), BKE_tempdir_session(), numstr);
const BlendFileWriteParams blend_file_write_params{};
/* success = */ /* UNUSED */ BLO_write_file(
bmain, filepath, fileflags, &(const struct BlendFileWriteParams){0}, NULL);
bmain, filepath, fileflags, &blend_file_write_params, nullptr);
BLI_strncpy(mfu->filepath, filepath, sizeof(mfu->filepath));
}
else {
MemFile *prevfile = (mfu_prev) ? &(mfu_prev->memfile) : NULL;
MemFile *prevfile = (mfu_prev) ? &(mfu_prev->memfile) : nullptr;
if (prevfile) {
BLO_memfile_clear_future(prevfile);
}

View File

@ -83,7 +83,7 @@ static bool blendfile_or_libraries_versions_atleast(Main *bmain,
return true;
}
static bool foreach_path_clean_cb(BPathForeachPathData *UNUSED(bpath_data),
static bool foreach_path_clean_cb(BPathForeachPathData * /*bpath_data*/,
char *path_dst,
const char *path_src)
{
@ -95,12 +95,13 @@ static bool foreach_path_clean_cb(BPathForeachPathData *UNUSED(bpath_data),
/* make sure path names are correct for OS */
static void clean_paths(Main *bmain)
{
BKE_bpath_foreach_path_main(&(BPathForeachPathData){
.bmain = bmain,
.callback_function = foreach_path_clean_cb,
.flag = BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE,
.user_data = NULL,
});
BPathForeachPathData foreach_path_data{};
foreach_path_data.bmain = bmain;
foreach_path_data.callback_function = foreach_path_clean_cb;
foreach_path_data.flag = BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE;
foreach_path_data.user_data = nullptr;
BKE_bpath_foreach_path_main(&foreach_path_data);
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
BLI_path_slash_native(scene->r.pic);
@ -110,7 +111,7 @@ static void clean_paths(Main *bmain)
static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
{
wmWindow *win;
for (win = wm->windows.first; win; win = win->next) {
for (win = static_cast<wmWindow *>(wm->windows.first); win; win = win->next) {
if (win->scene == scene) {
return true;
}
@ -123,7 +124,7 @@ static void setup_app_userdef(BlendFileData *bfd)
if (bfd->user) {
/* only here free userdef themes... */
BKE_blender_userdef_data_set_and_free(bfd->user);
bfd->user = NULL;
bfd->user = nullptr;
/* Security issue: any blend file could include a USER block.
*
@ -151,7 +152,7 @@ static void setup_app_data(bContext *C,
BlendFileReadReport *reports)
{
Main *bmain = G_MAIN;
Scene *curscene = NULL;
Scene *curscene = nullptr;
const bool recover = (G.fileflags & G_FILE_RECOVER_READ) != 0;
const bool is_startup = params->is_startup;
enum {
@ -161,12 +162,12 @@ static void setup_app_data(bContext *C,
} mode;
if (params->undo_direction != STEP_INVALID) {
BLI_assert(bfd->curscene != NULL);
BLI_assert(bfd->curscene != nullptr);
mode = LOAD_UNDO;
}
/* may happen with library files - UNDO file should never have NULL curscene (but may have a
* NULL curscreen)... */
else if (ELEM(NULL, bfd->curscreen, bfd->curscene)) {
/* may happen with library files - UNDO file should never have nullptr curscene (but may have a
* nullptr curscreen)... */
else if (ELEM(nullptr, bfd->curscreen, bfd->curscene)) {
BKE_report(reports->reports, RPT_WARNING, "Library file, loading empty scene");
mode = LOAD_UI_OFF;
}
@ -205,7 +206,7 @@ static void setup_app_data(bContext *C,
* see: T43424
*/
wmWindow *win;
bScreen *curscreen = NULL;
bScreen *curscreen = nullptr;
ViewLayer *cur_view_layer;
bool track_undo_scene;
@ -213,10 +214,10 @@ static void setup_app_data(bContext *C,
SWAP(ListBase, bmain->wm, bfd->main->wm);
SWAP(ListBase, bmain->workspaces, bfd->main->workspaces);
SWAP(ListBase, bmain->screens, bfd->main->screens);
if (bmain->name_map != NULL) {
if (bmain->name_map != nullptr) {
BKE_main_namemap_destroy(&bmain->name_map);
}
if (bfd->main->name_map != NULL) {
if (bfd->main->name_map != nullptr) {
BKE_main_namemap_destroy(&bfd->main->name_map);
}
@ -250,14 +251,14 @@ static void setup_app_data(bContext *C,
track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
if (curscene == NULL) {
curscene = bfd->main->scenes.first;
if (curscene == nullptr) {
curscene = static_cast<Scene *>(bfd->main->scenes.first);
}
/* empty file, we add a scene to make Blender work */
if (curscene == NULL) {
if (curscene == nullptr) {
curscene = BKE_scene_add(bfd->main, "Empty");
}
if (cur_view_layer == NULL) {
if (cur_view_layer == nullptr) {
/* fallback to scene layer */
cur_view_layer = BKE_view_layer_default_view(curscene);
}
@ -267,7 +268,7 @@ static void setup_app_data(bContext *C,
* replace it with 'curscene' if its needed */
}
/* and we enforce curscene to be in current screen */
else if (win) { /* The window may be NULL in background-mode. */
else if (win) { /* The window may be nullptr in background-mode. */
win->scene = curscene;
}
@ -278,7 +279,7 @@ static void setup_app_data(bContext *C,
}
if (track_undo_scene) {
wmWindowManager *wm = bfd->main->wm.first;
wmWindowManager *wm = static_cast<wmWindowManager *>(bfd->main->wm.first);
if (wm_scene_is_visible(wm, bfd->curscene) == false) {
curscene = bfd->curscene;
win->scene = curscene;
@ -296,7 +297,7 @@ static void setup_app_data(bContext *C,
BKE_blender_globals_main_replace(bfd->main);
bmain = G_MAIN;
bfd->main = NULL;
bfd->main = nullptr;
CTX_data_main_set(C, bmain);
@ -306,12 +307,12 @@ static void setup_app_data(bContext *C,
CTX_data_scene_set(C, curscene);
}
else {
CTX_wm_manager_set(C, bmain->wm.first);
CTX_wm_manager_set(C, static_cast<wmWindowManager *>(bmain->wm.first));
CTX_wm_screen_set(C, bfd->curscreen);
CTX_data_scene_set(C, bfd->curscene);
CTX_wm_area_set(C, NULL);
CTX_wm_region_set(C, NULL);
CTX_wm_menu_set(C, NULL);
CTX_wm_area_set(C, nullptr);
CTX_wm_region_set(C, nullptr);
CTX_wm_menu_set(C, nullptr);
curscene = bfd->curscene;
}
@ -320,7 +321,7 @@ static void setup_app_data(bContext *C,
G.fileflags = (G.fileflags & fileflags_keep) | (bfd->fileflags & ~fileflags_keep);
/* this can happen when active scene was lib-linked, and doesn't exist anymore */
if (CTX_data_scene(C) == NULL) {
if (CTX_data_scene(C) == nullptr) {
wmWindow *win = CTX_wm_window(C);
/* in case we don't even have a local scene, add one */
@ -328,7 +329,7 @@ static void setup_app_data(bContext *C,
BKE_scene_add(bmain, "Empty");
}
CTX_data_scene_set(C, bmain->scenes.first);
CTX_data_scene_set(C, static_cast<Scene *>(bmain->scenes.first));
win->scene = CTX_data_scene(C);
curscene = CTX_data_scene(C);
}
@ -384,7 +385,7 @@ static void setup_app_data(bContext *C,
/* baseflags, groups, make depsgraph, etc */
/* first handle case if other windows have different scenes visible */
if (mode == LOAD_UI) {
wmWindowManager *wm = bmain->wm.first;
wmWindowManager *wm = static_cast<wmWindowManager *>(bmain->wm.first);
if (wm) {
LISTBASE_FOREACH (wmWindow *, win, &wm->windows) {
@ -435,7 +436,7 @@ static void setup_app_data(bContext *C,
reports->duration.lib_overrides_resync;
/* We need to rebuild some of the deleted override rules (for UI feedback purpose). */
BKE_lib_override_library_main_operations_create(bmain, true, NULL);
BKE_lib_override_library_main_operations_create(bmain, true, nullptr);
}
}
@ -487,7 +488,7 @@ void BKE_blendfile_read_setup(bContext *C,
const struct BlendFileReadParams *params,
BlendFileReadReport *reports)
{
BKE_blendfile_read_setup_ex(C, bfd, params, reports, false, NULL);
BKE_blendfile_read_setup_ex(C, bfd, params, reports, false, nullptr);
}
struct BlendFileData *BKE_blendfile_read(const char *filepath,
@ -499,7 +500,7 @@ struct BlendFileData *BKE_blendfile_read(const char *filepath,
printf("Read blend: %s\n", filepath);
}
BlendFileData *bfd = BLO_read_from_file(filepath, params->skip_flags, reports);
BlendFileData *bfd = BLO_read_from_file(filepath, eBLOReadSkip(params->skip_flags), reports);
if (bfd) {
handle_subversion_warning(bfd->main, reports);
}
@ -514,7 +515,8 @@ struct BlendFileData *BKE_blendfile_read_from_memory(const void *filebuf,
const struct BlendFileReadParams *params,
ReportList *reports)
{
BlendFileData *bfd = BLO_read_from_memory(filebuf, filelength, params->skip_flags, reports);
BlendFileData *bfd = BLO_read_from_memory(
filebuf, filelength, eBLOReadSkip(params->skip_flags), reports);
if (bfd) {
/* Pass. */
}
@ -595,11 +597,13 @@ void BKE_blendfile_read_make_empty(bContext *C)
UserDef *BKE_blendfile_userdef_read(const char *filepath, ReportList *reports)
{
BlendFileData *bfd;
UserDef *userdef = NULL;
UserDef *userdef = nullptr;
bfd = BLO_read_from_file(filepath,
BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF,
&(struct BlendFileReadReport){.reports = reports});
BlendFileReadReport blend_file_read_reports{};
blend_file_read_reports.reports = reports;
bfd = BLO_read_from_file(
filepath, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, &blend_file_read_reports);
if (bfd) {
if (bfd->user) {
userdef = bfd->user;
@ -616,7 +620,7 @@ UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf,
ReportList *reports)
{
BlendFileData *bfd;
UserDef *userdef = NULL;
UserDef *userdef = nullptr;
bfd = BLO_read_from_memory(
filebuf, filelength, BLO_READ_SKIP_ALL & ~BLO_READ_SKIP_USERDEF, reports);
@ -636,8 +640,8 @@ UserDef *BKE_blendfile_userdef_read_from_memory(const void *filebuf,
UserDef *BKE_blendfile_userdef_from_defaults(void)
{
UserDef *userdef = MEM_mallocN(sizeof(*userdef), __func__);
memcpy(userdef, &U_default, sizeof(*userdef));
UserDef *userdef = static_cast<UserDef *>(MEM_callocN(sizeof(UserDef), __func__));
*userdef = blender::dna::shallow_copy(U_default);
/* Add-ons. */
{
@ -663,7 +667,7 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
/* Theme. */
{
bTheme *btheme = MEM_mallocN(sizeof(*btheme), __func__);
bTheme *btheme = static_cast<bTheme *>(MEM_mallocN(sizeof(*btheme), __func__));
memcpy(btheme, &U_theme_default, sizeof(*btheme));
BLI_addtail(&userdef->themes, btheme);
@ -696,16 +700,13 @@ UserDef *BKE_blendfile_userdef_from_defaults(void)
bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
{
Main *mainb = MEM_callocN(sizeof(Main), "empty main");
Main *mainb = MEM_cnew<Main>("empty main");
bool ok = false;
if (BLO_write_file(mainb,
filepath,
0,
&(const struct BlendFileWriteParams){
.use_userdef = true,
},
reports)) {
BlendFileWriteParams params{};
params.use_userdef = true;
if (BLO_write_file(mainb, filepath, 0, &params, reports)) {
ok = true;
}
@ -721,9 +722,9 @@ bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *
* falling back to the defaults.
* If the preferences exists but file reading fails - the file can be assumed corrupt
* so overwriting the file is OK. */
UserDef *userdef_default = BLI_exists(filepath) ? BKE_blendfile_userdef_read(filepath, NULL) :
NULL;
if (userdef_default == NULL) {
UserDef *userdef_default = BLI_exists(filepath) ? BKE_blendfile_userdef_read(filepath, nullptr) :
nullptr;
if (userdef_default == nullptr) {
userdef_default = BKE_blendfile_userdef_from_defaults();
}
@ -742,7 +743,7 @@ bool BKE_blendfile_userdef_write_all(ReportList *reports)
bool ok = true;
const bool use_template_userpref = BKE_appdir_app_template_has_userpref(U.app_template);
if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, NULL))) {
if ((cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, nullptr))) {
bool ok_write;
BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE);
@ -806,18 +807,19 @@ WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepat
ReportList *reports)
{
BlendFileData *bfd;
WorkspaceConfigFileData *workspace_config = NULL;
WorkspaceConfigFileData *workspace_config = nullptr;
if (filepath) {
bfd = BLO_read_from_file(
filepath, BLO_READ_SKIP_USERDEF, &(struct BlendFileReadReport){.reports = reports});
BlendFileReadReport blend_file_read_reports{};
blend_file_read_reports.reports = reports;
bfd = BLO_read_from_file(filepath, BLO_READ_SKIP_USERDEF, &blend_file_read_reports);
}
else {
bfd = BLO_read_from_memory(filebuf, filelength, BLO_READ_SKIP_USERDEF, reports);
}
if (bfd) {
workspace_config = MEM_callocN(sizeof(*workspace_config), __func__);
workspace_config = MEM_cnew<WorkspaceConfigFileData>(__func__);
workspace_config->main = bfd->main;
/* Only 2.80+ files have actual workspaces, don't try to use screens
@ -839,7 +841,8 @@ bool BKE_blendfile_workspace_config_write(Main *bmain, const char *filepath, Rep
BKE_blendfile_write_partial_begin(bmain);
for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
for (WorkSpace *workspace = static_cast<WorkSpace *>(bmain->workspaces.first); workspace;
workspace = static_cast<WorkSpace *>(workspace->id.next)) {
BKE_blendfile_write_partial_tag_ID(&workspace->id, true);
}
@ -880,10 +883,10 @@ void BKE_blendfile_write_partial_tag_ID(ID *id, bool set)
}
}
static void blendfile_write_partial_cb(void *UNUSED(handle), Main *UNUSED(bmain), void *vid)
static void blendfile_write_partial_cb(void * /*handle*/, Main * /*bmain*/, void *vid)
{
if (vid) {
ID *id = vid;
ID *id = static_cast<ID *>(vid);
/* only tag for need-expand if not done, prevents eternal loops */
if ((id->tag & LIB_TAG_DOIT) == 0) {
id->tag |= LIB_TAG_NEED_EXPAND | LIB_TAG_DOIT;
@ -901,11 +904,11 @@ bool BKE_blendfile_write_partial(Main *bmain_src,
const int remap_mode,
ReportList *reports)
{
Main *bmain_dst = MEM_callocN(sizeof(Main), "copybuffer");
Main *bmain_dst = MEM_cnew<Main>("copybuffer");
ListBase *lbarray_dst[INDEX_ID_MAX], *lbarray_src[INDEX_ID_MAX];
int a, retval;
void *path_list_backup = NULL;
void *path_list_backup = nullptr;
const eBPathForeachFlag path_list_flag = (BKE_BPATH_FOREACH_PATH_SKIP_LINKED |
BKE_BPATH_FOREACH_PATH_SKIP_MULTIFILE);
@ -914,7 +917,7 @@ bool BKE_blendfile_write_partial(Main *bmain_src,
STRNCPY(bmain_dst->filepath, bmain_src->filepath);
BLO_main_expander(blendfile_write_partial_cb);
BLO_expand_main(NULL, bmain_src);
BLO_expand_main(nullptr, bmain_src);
/* move over all tagged blocks */
set_listbasepointers(bmain_src, lbarray_src);
@ -923,8 +926,8 @@ bool BKE_blendfile_write_partial(Main *bmain_src,
ID *id, *nextid;
ListBase *lb_dst = lbarray_dst[a], *lb_src = lbarray_src[a];
for (id = lb_src->first; id; id = nextid) {
nextid = id->next;
for (id = static_cast<ID *>(lb_src->first); id; id = nextid) {
nextid = static_cast<ID *>(id->next);
if (id->tag & LIB_TAG_DOIT) {
BLI_remlink(lb_src, id);
BLI_addtail(lb_dst, id);
@ -946,13 +949,9 @@ bool BKE_blendfile_write_partial(Main *bmain_src,
}
/* save the buffer */
retval = BLO_write_file(bmain_dst,
filepath,
write_flags,
&(const struct BlendFileWriteParams){
.remap_mode = remap_mode,
},
reports);
BlendFileWriteParams blend_file_write_params{};