Merge remote-tracking branch 'blender/main' into goo-engine-main

This commit is contained in:
2023-11-11 20:44:12 +00:00
327 changed files with 4600 additions and 2031 deletions
+16
View File
@@ -761,6 +761,18 @@ option(WITH_GTESTS "Enable GTest unit testing" OFF)
option(WITH_OPENGL_RENDER_TESTS "Enable OpenGL render related unit testing (Experimental)" OFF)
option(WITH_OPENGL_DRAW_TESTS "Enable OpenGL UI drawing related unit testing (Experimental)" OFF)
option(WITH_COMPOSITOR_REALTIME_TESTS "Enable regression testing for realtime compositor" OFF)
if(UNIX AND NOT (APPLE OR HAIKU))
option(WITH_UI_TESTS "\
Enable user-interface tests using a headless display server. \
Currently this depends on WITH_GHOST_WAYLAND and the weston compositor \
(Experimental)"
OFF
)
else()
# TODO: support running GUI tests on other platforms.
set(WITH_UI_TESTS OFF)
endif()
# NOTE: All callers of this must add `TEST_PYTHON_EXE_EXTRA_ARGS` before any other arguments.
set(TEST_PYTHON_EXE "" CACHE PATH "Python executable to run unit tests")
mark_as_advanced(TEST_PYTHON_EXE)
@@ -1156,6 +1168,10 @@ endif()
set_and_warn_incompatible(WITH_HEADLESS WITH_XR_OPENXR OFF)
set_and_warn_incompatible(WITH_GHOST_SDL WITH_XR_OPENXR OFF)
if(WITH_UI_TESTS)
set_and_warn_dependency(WITH_GHOST_WAYLAND WITH_UI_TESTS OFF)
endif()
if(WITH_BUILDINFO)
find_package(Git)
set_and_warn_library_found("Git" GIT_FOUND WITH_BUILDINFO)
@@ -168,6 +168,7 @@ if(UNIX AND NOT APPLE)
# Can be removed when the build-bot upgrades to v1.20.x or newer.
include(cmake/wayland.cmake)
include(cmake/wayland_libdecor.cmake)
include(cmake/wayland_weston.cmake)
endif()
include(cmake/shaderc_deps.cmake)
include(cmake/shaderc.cmake)
@@ -137,6 +137,7 @@ download_source(XR_OPENXR_SDK)
download_source(WL_PROTOCOLS)
download_source(WAYLAND)
download_source(WAYLAND_LIBDECOR)
download_source(WAYLAND_WESTON)
download_source(ISPC)
download_source(GMP)
download_source(POTRACE)
@@ -191,6 +191,14 @@ else()
harvest(wayland/bin wayland/bin "wayland-scanner")
harvest(wayland/include wayland/include "*.h")
harvest(wayland_libdecor/include wayland_libdecor/include "*.h")
# Only needed for running the WESTON compositor.
harvest(wayland/lib64 wayland/lib64 "*")
harvest(
wayland_weston/
wayland_weston/
"*"
)
else()
harvest(blosc/lib openvdb/lib "*.a")
harvest(xml2/lib opencollada/lib "*.a")
@@ -37,16 +37,14 @@ else()
PREFIX ${BUILD_DIR}/ssl
CONFIGURE_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/ssl/src/external_ssl/ && ${SSL_CONFIGURE_COMMAND} --prefix=${LIBDIR}/ssl
--openssldir=${LIBDIR}/ssl
# Without this: Python will use the build directories:
# To see these values in use, check the output of `ssl.get_default_verify_paths()`.
# This definition causes the following values to be set:
# - `capath='/etc/ssl/certs'`
# - `openssl_cafile='/etc/ssl/cert.pem'`
# - `openssl_capath='/etc/ssl/certs'`
# Note that the output from the command `openssl info -configdir` on the users system
# would be ideal but this is more involved.
# Without this: Python will use the build directories.
# using the system directory `/etc/ssl` might seem the obvious choice,
# there is no guarantee the version of SSL used with Blender is compatible with the systems,
# where changes to the SSL configuration format can cause SSL not to load (see #114452).
# So reference a directory known not to exist. Ideally Blender could distribute it's own SSL
# directory, but this isn't compatible with hard coded paths.
# See #111132 & https://github.com/openssl/openssl/issues/20185 for details.
-DOPENSSLDIR=\\"/etc/ssl\\"
-DOPENSSLDIR=\\"/dev/null\\"
no-shared
no-idea no-mdc2 no-rc5 no-zlib no-ssl3 enable-unit-test no-ssl3-method enable-rfc3779 enable-cms
--config=${CMAKE_CURRENT_SOURCE_DIR}/cmake/ssl.conf
@@ -574,6 +574,13 @@ set(WAYLAND_LIBDECOR_HASH 47b59eba76faa3787f0878bf8700e912)
set(WAYLAND_LIBDECOR_HASH_TYPE MD5)
set(WAYLAND_LIBDECOR_HOMEPAGE https://gitlab.freedesktop.org/libdecor/libdecor)
set(WAYLAND_WESTON_VERSION 12.0.92)
set(WAYLAND_WESTON_FILE weston-${WAYLAND_WESTON_VERSION}.tar.xz)
set(WAYLAND_WESTON_URI https://gitlab.freedesktop.org/wayland/weston/-/releases/${WAYLAND_WESTON_VERSION}/downloads/weston-${WAYLAND_WESTON_VERSION}.tar.xz)
set(WAYLAND_WESTON_HASH 44542b60bf9b9fe3add904af11bbad98)
set(WAYLAND_WESTON_HASH_TYPE MD5)
set(WAYLAND_WESTON_HOMEPAGE https://wayland.freedesktop.org)
set(ISPC_VERSION v1.17.0)
set(ISPC_URI https://github.com/ispc/ispc/archive/${ISPC_VERSION}.tar.gz)
set(ISPC_HASH 4f476a3109332a77fe839a9014c60ca9)
@@ -0,0 +1,65 @@
# SPDX-FileCopyrightText: 2023 Blender Authors
#
# SPDX-License-Identifier: GPL-2.0-or-later
set(WAYLAND_WESTON_CONFIGURE_ENV ${CONFIGURE_ENV})
set(WAYLAND_WESTON_PKG_ENV "PKG_CONFIG_PATH=\
${LIBDIR}/wayland/lib64/pkgconfig:\
${LIBDIR}/wayland-protocols/share/pkgconfig:\
$PKG_CONFIG_PATH"
)
ExternalProject_Add(external_wayland_weston
URL file://${PACKAGE_DIR}/${WAYLAND_WESTON_FILE}
URL_HASH ${WAYLAND_WESTON_HASH_TYPE}=${WAYLAND_WESTON_HASH}
DOWNLOAD_DIR ${DOWNLOAD_DIR}
PREFIX ${BUILD_DIR}/wayland_weston
# Notes:
# - Disable nearly everything as only a simple headless server is needed for testing.
# - Keep X11 and WAYLAND back-ends enabled so it's possible
# to run the instance inside existing X11/WAYLAND sessions (for debugging).
CONFIGURE_COMMAND ${WAYLAND_WESTON_CONFIGURE_ENV} &&
${CMAKE_COMMAND} -E env ${WAYLAND_WESTON_PKG_ENV}
${MESON} setup
${MESON_BUILD_TYPE}
--prefix ${LIBDIR}/wayland_weston
--libdir lib
-Dbackend-default=headless # For tests.
-Dbackend-drm-screencast-vaapi=false
-Dbackend-drm=false
-Dbackend-pipewire=false
-Dbackend-rdp=false
-Dbackend-vnc=false
-Dcolor-management-lcms=false
-Ddemo-clients=false
-Ddoc=false
-Dimage-jpeg=false
-Dimage-webp=false
-Dpipewire=false
-Dremoting=false
-Dscreenshare=false
-Dshell-fullscreen=false
-Dshell-ivi=false
-Dshell-kiosk=false
-Dsimple-clients=
-Dsystemd=false
-Dtest-junit-xml=false
-Dtools=
-Dwcap-decode=false
-Dxwayland=false
${BUILD_DIR}/wayland_weston/src/external_wayland_weston-build
${BUILD_DIR}/wayland_weston/src/external_wayland_weston
BUILD_COMMAND ninja
INSTALL_COMMAND ninja install
INSTALL_DIR ${LIBDIR}/wayland_weston
)
add_dependencies(
external_wayland_weston
external_wayland_protocols
external_wayland
# Needed for `MESON`.
external_python_site_packages
)
@@ -109,6 +109,20 @@ PACKAGES_FOR_LIBS=(
# Required by: `external_ssl` (build dependencies).
perl-IPC-Cmd
perl-Pod-Html
# Required by: `external_wayland_weston`
cairo-devel
libdrm-devel
pixman-devel
libffi-devel
libinput-devel
libevdev-devel
mesa-libEGL-devel
systemd-dev # for `libudev` (not so obvious!).
# Required by: `weston --headless` (run-time requirement for off screen rendering).
mesa-dri-drivers
mesa-libEGL
mesa-libGL
)
# Additional packages needed for building Blender.
@@ -1013,12 +1013,6 @@ class CyclesMaterialSettings(bpy.types.PropertyGroup):
default="AUTO",
)
use_transparent_shadow: BoolProperty(
name="Transparent Shadows",
description="Use transparent shadows for this material if it contains a Transparent BSDF, "
"disabling will render faster but not give accurate shadows",
default=True,
)
use_bump_map_correction: BoolProperty(
name="Bump Map Correction",
description="Apply corrections to solve shadow terminator artifacts caused by bump mapping",
+1 -1
View File
@@ -1966,7 +1966,7 @@ class CYCLES_MATERIAL_PT_settings_surface(CyclesButtonsPanel, Panel):
col = layout.column()
col.prop(cmat, "displacement_method", text="Displacement")
col.prop(cmat, "emission_sampling")
col.prop(cmat, "use_transparent_shadow")
col.prop(mat, "use_transparent_shadow")
col.prop(cmat, "use_bump_map_correction")
def draw(self, context):
+1 -1
View File
@@ -1550,7 +1550,7 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all)
/* settings */
PointerRNA cmat = RNA_pointer_get(&b_mat.ptr, "cycles");
shader->set_emission_sampling_method(get_emission_sampling(cmat));
shader->set_use_transparent_shadow(get_boolean(cmat, "use_transparent_shadow"));
shader->set_use_transparent_shadow(b_mat.use_transparent_shadow());
shader->set_use_bump_map_correction(get_boolean(cmat, "use_bump_map_correction"));
shader->set_heterogeneous_volume(!get_boolean(cmat, "homogeneous_volume"));
shader->set_volume_sampling_method(get_volume_sampling(cmat));
+3
View File
@@ -19,6 +19,9 @@ class BVHMetal : public BVH {
API_AVAILABLE(macos(11.0))
id<MTLAccelerationStructure> accel_struct = nil;
API_AVAILABLE(macos(11.0))
id<MTLAccelerationStructure> null_BLAS = nil;
API_AVAILABLE(macos(11.0))
vector<id<MTLAccelerationStructure>> blas_array;
+69 -15
View File
@@ -124,6 +124,10 @@ BVHMetal::~BVHMetal()
stats.mem_free(accel_struct.allocatedSize);
[accel_struct release];
}
if (null_BLAS) {
[null_BLAS release];
}
}
}
@@ -964,6 +968,60 @@ bool BVHMetal::build_TLAS(Progress &progress,
g_bvh_build_throttler.wait_for_all();
if (@available(macos 12.0, *)) {
/* Defined inside available check, for return type to be available. */
auto make_null_BLAS = [](id<MTLDevice> device,
id<MTLCommandQueue> queue) -> id<MTLAccelerationStructure> {
MTLResourceOptions storage_mode = MTLResourceStorageModeManaged;
if (device.hasUnifiedMemory) {
storage_mode = MTLResourceStorageModeShared;
}
id<MTLBuffer> nullBuf = [device newBufferWithLength:0 options:storage_mode];
/* Create an acceleration structure. */
MTLAccelerationStructureTriangleGeometryDescriptor *geomDesc =
[MTLAccelerationStructureTriangleGeometryDescriptor descriptor];
geomDesc.vertexBuffer = nullBuf;
geomDesc.vertexBufferOffset = 0;
geomDesc.vertexStride = sizeof(float3);
geomDesc.indexBuffer = nullBuf;
geomDesc.indexBufferOffset = 0;
geomDesc.indexType = MTLIndexTypeUInt32;
geomDesc.triangleCount = 0;
geomDesc.intersectionFunctionTableOffset = 0;
geomDesc.opaque = true;
geomDesc.allowDuplicateIntersectionFunctionInvocation = false;
MTLPrimitiveAccelerationStructureDescriptor *accelDesc =
[MTLPrimitiveAccelerationStructureDescriptor descriptor];
accelDesc.geometryDescriptors = @[ geomDesc ];
accelDesc.usage |= MTLAccelerationStructureUsageExtendedLimits;
MTLAccelerationStructureSizes accelSizes = [device
accelerationStructureSizesWithDescriptor:accelDesc];
id<MTLAccelerationStructure> accel_struct = [device
newAccelerationStructureWithSize:accelSizes.accelerationStructureSize];
id<MTLBuffer> scratchBuf = [device newBufferWithLength:accelSizes.buildScratchBufferSize
options:MTLResourceStorageModePrivate];
id<MTLBuffer> sizeBuf = [device newBufferWithLength:8 options:MTLResourceStorageModeShared];
id<MTLCommandBuffer> accelCommands = [queue commandBuffer];
id<MTLAccelerationStructureCommandEncoder> accelEnc =
[accelCommands accelerationStructureCommandEncoder];
[accelEnc buildAccelerationStructure:accel_struct
descriptor:accelDesc
scratchBuffer:scratchBuf
scratchBufferOffset:0];
[accelEnc endEncoding];
[accelCommands commit];
[accelCommands waitUntilCompleted];
/* free temp resources */
[scratchBuf release];
[nullBuf release];
[sizeBuf release];
return accel_struct;
};
uint32_t num_instances = 0;
uint32_t num_motion_transforms = 0;
@@ -1005,7 +1063,7 @@ bool BVHMetal::build_TLAS(Progress &progress,
int blas_index = (int)[all_blas count];
instance_mapping[blas] = blas_index;
if (@available(macos 12.0, *)) {
[all_blas addObject:blas->accel_struct];
[all_blas addObject:(blas ? blas->accel_struct : null_BLAS)];
}
return blas_index;
}
@@ -1052,22 +1110,18 @@ bool BVHMetal::build_TLAS(Progress &progress,
if (!blas || !blas->accel_struct) {
/* Place a degenerate instance, to ensure [[instance_id]] equals ob->get_device_index()
* in our intersection functions */
if (motion_blur) {
MTLAccelerationStructureMotionInstanceDescriptor *instances =
(MTLAccelerationStructureMotionInstanceDescriptor *)[instanceBuf contents];
MTLAccelerationStructureMotionInstanceDescriptor &desc = instances[instance_index++];
memset(&desc, 0x00, sizeof(desc));
blas = nullptr;
/* Workaround for issue in macOS <= 14.1: Insert degenerate BLAS instead of zero-filling
* the descriptor. */
if (!null_BLAS) {
null_BLAS = make_null_BLAS(device, queue);
}
else {
MTLAccelerationStructureUserIDInstanceDescriptor *instances =
(MTLAccelerationStructureUserIDInstanceDescriptor *)[instanceBuf contents];
MTLAccelerationStructureUserIDInstanceDescriptor &desc = instances[instance_index++];
memset(&desc, 0x00, sizeof(desc));
}
blas_array.push_back(nil);
continue;
blas_array.push_back(null_BLAS);
}
else {
blas_array.push_back(blas->accel_struct);
}
blas_array.push_back(blas->accel_struct);
uint32_t accel_struct_index = get_blas_index(blas);
@@ -343,6 +343,11 @@ string MetalDevice::preprocess_source(MetalPipelineType pso_type,
}
}
if (@available(macos 14.0, *)) {
/* Use Program Scope Global Built-ins, when available. */
global_defines += "#define __METAL_GLOBAL_BUILTINS__\n";
}
# ifdef WITH_CYCLES_DEBUG
global_defines += "#define __KERNEL_DEBUG__\n";
# endif
@@ -108,6 +108,31 @@ using namespace metal::raytracing;
/* Generate a struct containing the entry-point parameters and a "run"
* method which can access them implicitly via this-> */
#ifdef __METAL_GLOBAL_BUILTINS__
#define ccl_gpu_kernel_signature(name, ...) \
struct kernel_gpu_##name \
{ \
PARAMS_MAKER(__VA_ARGS__)(__VA_ARGS__) \
void run(thread MetalKernelContext& context, \
threadgroup atomic_int *threadgroup_array) ccl_global const; \
}; \
kernel void cycles_metal_##name(device const kernel_gpu_##name *params_struct, \
constant KernelParamsMetal &ccl_restrict _launch_params_metal, \
constant MetalAncillaries *_metal_ancillaries, \
threadgroup atomic_int *threadgroup_array[[ threadgroup(0) ]]) { \
MetalKernelContext context(_launch_params_metal, _metal_ancillaries); \
params_struct->run(context, threadgroup_array); \
} \
void kernel_gpu_##name::run(thread MetalKernelContext& context, \
threadgroup atomic_int *threadgroup_array) ccl_global const
#else
/* On macOS versions before 14.x, builtin constants (e.g. metal_global_id) must
* be accessed through attributed entrypoint parameters. */
#define ccl_gpu_kernel_signature(name, ...) \
struct kernel_gpu_##name \
{ \
@@ -149,6 +174,8 @@ void kernel_gpu_##name::run(thread MetalKernelContext& context, \
uint simd_group_index, \
uint num_simd_groups) ccl_global const
#endif /* __METAL_GLOBAL_BUILTINS__ */
#define ccl_gpu_kernel_postfix
#define ccl_gpu_kernel_call(x) context.x
#define ccl_gpu_kernel_within_bounds(i,n) true
@@ -365,3 +392,14 @@ constant constexpr array<sampler, SamplerCount> metal_samplers = {
sampler(address::clamp_to_zero, filter::linear),
sampler(address::mirrored_repeat, filter::linear),
};
#ifdef __METAL_GLOBAL_BUILTINS__
const uint metal_global_id [[thread_position_in_grid]];
const ushort metal_local_id [[thread_position_in_threadgroup]];
const ushort metal_local_size [[threads_per_threadgroup]];
const uint metal_grid_id [[threadgroup_position_in_grid]];
const uint simdgroup_size [[threads_per_simdgroup]];
const uint simd_lane_index [[thread_index_in_simdgroup]];
const uint simd_group_index [[simdgroup_index_in_threadgroup]];
const uint num_simd_groups [[simdgroups_per_threadgroup]];
#endif /* __METAL_GLOBAL_BUILTINS__ */
+7 -7
View File
@@ -726,7 +726,7 @@ static void gwl_primary_selection_discard_source(GWL_PrimarySelection *primary)
#ifdef WITH_INPUT_IME
struct GWL_SeatIME {
struct wl_surface *surface_window = nullptr;
wl_surface *surface_window = nullptr;
GHOST_TEventImeData event_ime_data = {
/*result_len*/ nullptr,
/*composite_len*/ nullptr,
@@ -806,7 +806,7 @@ struct GWL_Seat {
std::unordered_set<zwp_tablet_tool_v2 *> tablet_tools;
#ifdef WITH_INPUT_IME
struct zwp_text_input_v3 *text_input = nullptr;
zwp_text_input_v3 *text_input = nullptr;
#endif
} wp;
@@ -1063,7 +1063,7 @@ struct GWL_Display {
zwp_pointer_constraints_v1 *pointer_constraints = nullptr;
zwp_pointer_gestures_v1 *pointer_gestures = nullptr;
#ifdef WITH_INPUT_IME
struct zwp_text_input_manager_v3 *text_input_manager = nullptr;
zwp_text_input_manager_v3 *text_input_manager = nullptr;
#endif
} wp;
@@ -4566,7 +4566,7 @@ static CLG_LogRef LOG_WL_TEXT_INPUT = {"ghost.wl.handle.text_input"};
static void text_input_handle_enter(void *data,
zwp_text_input_v3 * /*zwp_text_input_v3*/,
struct wl_surface *surface)
wl_surface *surface)
{
if (!ghost_wl_surface_own(surface)) {
return;
@@ -4578,7 +4578,7 @@ static void text_input_handle_enter(void *data,
static void text_input_handle_leave(void *data,
zwp_text_input_v3 * /*zwp_text_input_v3*/,
struct wl_surface *surface)
wl_surface *surface)
{
/* Can be null when closing a window. */
if (!ghost_wl_surface_own_with_null_check(surface)) {
@@ -4747,7 +4747,7 @@ static void text_input_handle_done(void *data,
seat->ime.has_commit_string_callback = false;
}
static struct zwp_text_input_v3_listener text_input_listener = {
static zwp_text_input_v3_listener text_input_listener = {
/*enter*/ text_input_handle_enter,
/*leave*/ text_input_handle_leave,
/*preedit_string*/ text_input_handle_preedit_string,
@@ -5773,7 +5773,7 @@ static void gwl_registry_wp_text_input_manager_remove(GWL_Display *display,
void * /*user_data*/,
const bool /*on_exit*/)
{
struct zwp_text_input_manager_v3 **value_p = &display->wp.text_input_manager;
zwp_text_input_manager_v3 **value_p = &display->wp.text_input_manager;
zwp_text_input_manager_v3_destroy(*value_p);
*value_p = nullptr;
}
@@ -22,20 +22,28 @@
</p>
</description>
<url type="homepage">https://www.blender.org</url>
<url type="bugtracker">https://projects.blender.org/blender/blender/issues?q=&labels=296</url>
<url type="faq">https://www.blender.org/support/faq/</url>
<url type="help">https://www.blender.org/support/</url>
<url type="bugtracker">https://developer.blender.org</url>
<url type="donation">https://www.blender.org/foundation/donation-payment/</url>
<url type="donation">https://fund.blender.org/</url>
<url type="translate">https://wiki.blender.org/wiki/Process/Translate_Blender</url>
<url type="vcs-browser">https://projects.blender.org/blender/blender</url>
<url type="contribute">https://www.blender.org/get-involved/</url>
<screenshots>
<screenshot type="default">
<caption>Sculpt</caption>
<image>https://download.blender.org/demo/screenshots/blender_screenshot_1.jpg</image>
</screenshot>
<screenshot>
<caption>Model</caption>
<image>https://download.blender.org/demo/screenshots/blender_screenshot_2.jpg</image>
</screenshot>
<screenshot>
<caption>Animate</caption>
<image>https://download.blender.org/demo/screenshots/blender_screenshot_3.jpg</image>
</screenshot>
<screenshot>
<caption>Edit &amp; Grade</caption>
<image>https://download.blender.org/demo/screenshots/blender_screenshot_4.jpg</image>
</screenshot>
</screenshots>
@@ -377,5 +385,6 @@
</ul>
</description>
</release>
</releases>
</releases>
<content_rating type="oars-1.1" />
</component>
@@ -941,6 +941,14 @@ def dump_asset_messages(msgs, reports, settings):
# Parse the asset blend files
asset_files = {}
# Store assets according to this structure:
# {"basename": [
# {"name": "Name",
# "description": "Description",
# "sockets": [
# ("Name", "Description"),
# ]},
# ]}
bfiles = glob.glob(assets_dir + "/**/*.blend", recursive=True)
for bfile in bfiles:
@@ -953,11 +961,18 @@ def dump_asset_messages(msgs, reports, settings):
if asset.asset_data is None: # Not an asset
continue
assets = asset_files.setdefault(basename, [])
assets.append((asset.name, asset.asset_data.description))
asset_data = {"name": asset.name,
"description": asset.asset_data.description}
for interface in asset.interface.items_tree:
if interface.name == "Geometry": # Ignore common socket
continue
socket_data = asset_data.setdefault("sockets", [])
socket_data.append((interface.name, interface.description))
assets.append(asset_data)
for asset_file in sorted(asset_files):
for asset in sorted(asset_files[asset_file]):
name, description = asset
for asset in sorted(asset_files[asset_file], key=lambda a: a["name"]):
name, description = asset["name"], asset["description"]
msgsrc = "Asset name from file " + asset_file
process_msg(msgs, settings.DEFAULT_CONTEXT, name, msgsrc,
reports, None, settings)
@@ -965,6 +980,15 @@ def dump_asset_messages(msgs, reports, settings):
process_msg(msgs, settings.DEFAULT_CONTEXT, description, msgsrc,
reports, None, settings)
if "sockets" in asset:
for socket_name, socket_description in asset["sockets"]:
msgsrc = f"Socket name from node group {name}, file {asset_file}"
process_msg(msgs, settings.DEFAULT_CONTEXT, socket_name, msgsrc,
reports, None, settings)
msgsrc = f"Socket description from node group {name}, file {asset_file}"
process_msg(msgs, settings.DEFAULT_CONTEXT, socket_description, msgsrc,
reports, None, settings)
def dump_addon_bl_info(msgs, reports, module, settings):
for prop in ('name', 'location', 'description', 'warning'):
@@ -323,6 +323,21 @@ class NODE_MT_category_shader_vector(Menu):
node_add_menu.draw_assets_for_catalog(layout, self.bl_label)
class NODE_MT_category_goo_engine(Menu):
bl_idname = "NODE_MT_category_goo_engine"
bl_label = "Goo Engine"
def draw(self, _context):
layout = self.layout
node_add_menu.add_node_type(layout, "ShaderNodeShaderInfo")
node_add_menu.add_node_type(layout, "ShaderNodeScreenspaceInfo")
node_add_menu.add_node_type(layout, "ShaderNodeCurvature")
node_add_menu.add_node_type(layout, "ShaderNodeSetDepth")
node_add_menu.add_node_type(layout, "ShaderNodeSdfPrimitive")
node_add_menu.add_node_type(layout, "ShaderNodeSdfOp")
node_add_menu.add_node_type(layout, "ShaderNodeSdfVectorOp")
node_add_menu.add_node_type(layout, "ShaderNodeSdfNoise")
class NODE_MT_category_shader_script(Menu):
bl_idname = "NODE_MT_category_shader_script"
bl_label = "Script"
@@ -359,6 +374,7 @@ class NODE_MT_shader_node_add_all(Menu):
layout.menu("NODE_MT_category_shader_shader")
layout.menu("NODE_MT_category_shader_texture")
layout.menu("NODE_MT_category_shader_vector")
layout.menu("NODE_MT_category_goo_engine")
layout.separator()
layout.menu("NODE_MT_category_shader_script")
layout.separator()
@@ -377,6 +393,7 @@ classes = (
NODE_MT_category_shader_shader,
NODE_MT_category_shader_texture,
NODE_MT_category_shader_vector,
NODE_MT_category_goo_engine,
NODE_MT_category_shader_script,
NODE_MT_category_shader_group,
)
@@ -359,8 +359,8 @@ class BONE_PT_display(BoneButtonsPanel, Panel):
row.prop(bone_color.custom, "select", text="")
row.prop(bone_color.custom, "active", text="")
if (pchan := context.object.pose.bones[bone.name]) and context.bone:
col.prop(pchan, "hide_outliner", text="Hide in Outliner", toggle=False)
if (pchan := context.object.pose.bones[bone.name]) and context.bone:
col.prop(pchan, "hide_outliner", text="Hide in Outliner", toggle=False)
class BONE_PT_display_custom_shape(BoneButtonsPanel, Panel):
+3 -2
View File
@@ -301,8 +301,9 @@ class EEVEE_NEXT_MATERIAL_PT_settings_surface(MaterialButtonsPanel, Panel):
col.prop(mat, "use_backface_culling", text="Camera")
col.prop(mat, "use_backface_culling_shadow", text="Shadow")
# TODO(fclem): Displacement option
# TODO(fclem): Transparent shadow option
layout.prop(mat, "max_vertex_displacement", text="Max Displacement")
layout.prop(mat, "use_transparent_shadow")
col = layout.column()
col.prop(mat, "surface_render_method", text="Render Method")
@@ -390,6 +390,11 @@ class OBJECT_PT_visibility(ObjectButtonsPanel, Panel):
col.prop(ob, "hide_render", text="Renders", toggle=False, invert_checkbox=True)
if context.engine == 'BLENDER_EEVEE_NEXT':
if ob.type in {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT', 'CURVES', 'POINTCLOUD', 'VOLUME'}:
layout.separator()
col = layout.column(heading="Ray Visibility")
col.prop(ob, "visible_shadow", text="Shadow", toggle=False)
if ob.type in {'MESH', 'CURVE', 'SURFACE', 'META', 'FONT', 'CURVES', 'POINTCLOUD', 'VOLUME', 'LIGHT'}:
layout.separator()
col = layout.column(heading="Light Probes")
+2 -2
View File
@@ -111,8 +111,8 @@ class RENDER_PT_color_management_display_settings(RenderButtonsPanel, Panel):
# Only display HDR toggle for non-Filmic display transforms.
col = layout.column(align=True)
sub = col.row()
sub.active = (not view.view_transform.startswith("Filmic") and
not view.view_transform.startswith("AgX"))
sub.active = (not view.view_transform.startswith("Filmic") and not view.view_transform.startswith("AgX") and not
view.view_transform.startswith("False Color"))
sub.prop(view, "use_hdr_view")
+1 -1
View File
@@ -1077,7 +1077,7 @@ class USERPREF_PT_theme_text_style(ThemePanel, CenterAlignMixIn, Panel):
col = flow.column()
col.prop(font_style, "points")
col.prop(font_style, "character_weight", text="Weight")
col.prop(font_style, "character_weight", text="Weight", text_ctxt=i18n_contexts.id_text)
col = flow.column(align=True)
col.prop(font_style, "shadow_offset_x", text="Shadow Offset X")
@@ -1,62 +0,0 @@
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
# <pep8 compliant>
"""
Custom file version warning system, to avoid mistakes with regular blender builds and production files.
"""
import bpy
from bpy.types import Operator
from bpy.app.handlers import persistent
import os
script_name = ".version_warning.py"
script_content = """
import bpy
def draw_popup_warning(self, context):
self.layout.label(text=f"Warning: file edited in Goo Engine, data may be lost if used in standard Blender!")
if not bpy.app.version_string.endswith('Goo Engine'):
print("File loaded, not a Goo Engine build!")
bpy.context.window_manager.popup_menu(draw_popup_warning, title="Warning", icon='ERROR')
"""
@persistent
def save_handler(_):
if not bpy.context.preferences.filepaths.save_version_warning:
return
text = bpy.data.texts.get(script_name)
if not text:
text = bpy.data.texts.new(script_name)
text.use_module = True
text.clear()
text.write(script_content)
def register():
bpy.app.handlers.save_pre.append(save_handler)
def unregister():
bpy.app.handlers.save_pre.remove(save_handler)
if __name__ == "__main__":
register()
+33
View File
@@ -0,0 +1,33 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup animrig
*
* \brief Functions to work with Actions.
*/
#include "RNA_types.hh"
struct FCurve;
struct bAction;
namespace blender::animrig {
/**
* Get (or add relevant data to be able to do so) F-Curve from the given Action,
* for the given Animation Data block. This assumes that all the destinations are valid.
*/
FCurve *action_fcurve_ensure(Main *bmain,
bAction *act,
const char group[],
PointerRNA *ptr,
const char rna_path[],
int array_index);
/**
* Find the F-Curve from the given Action. This assumes that all the destinations are valid.
*/
FCurve *action_fcurve_find(bAction *act, const char rna_path[], int array_index);
} // namespace blender::animrig
+31
View File
@@ -0,0 +1,31 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup animrig
*
* \brief Functions to work with AnimData.
*/
struct bAnimContext;
struct AnimData;
struct FCurve;
namespace blender::animrig {
/**
* Delete the F-Curve from the given AnimData block (if possible),
* as appropriate according to animation context.
*/
void animdata_fcurve_delete(bAnimContext *ac, AnimData *adt, FCurve *fcu);
/**
* Unlink the action from animdata if it's empty.
*
* If the action has no F-Curves, unlink it from AnimData if it did not
* come from a NLA Strip being tweaked.
*/
bool animdata_remove_empty_action(AnimData *adt);
} // namespace blender::animrig
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+38 -21
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -8,34 +8,51 @@
* \brief Functions to modify FCurves.
*/
#include "RNA_types.hh"
#include "DNA_anim_types.h"
struct AnimData;
struct FCurve;
struct bAction;
namespace blender::animrig {
/**
* Get (or add relevant data to be able to do so) F-Curve from the given Action,
* for the given Animation Data block. This assumes that all the destinations are valid.
*/
FCurve *action_fcurve_ensure(Main *bmain,
bAction *act,
const char group[],
PointerRNA *ptr,
const char rna_path[],
int array_index);
/**
* Find the F-Curve from the given Action. This assumes that all the destinations are valid.
*/
FCurve *action_fcurve_find(bAction *act, const char rna_path[], int array_index);
/**
* \note The caller needs to run #BKE_nla_tweakedit_remap to get NLA relative frame.
* The caller should also check #BKE_fcurve_is_protected before keying.
*/
bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra);
/**
* \brief Lesser Key-framing API call.
*
* Use this when validation of necessary animation data isn't necessary as it already
* exists, and there is a #BezTriple that can be directly copied into the array.
*
* This function adds a given #BezTriple to an F-Curve. It will allocate
* memory for the array if needed, and will insert the #BezTriple into a
* suitable place in chronological order.
*
* \returns The index of the keyframe array into which the bezt has been added.
*
* \note Any recalculate of the F-Curve that needs to be done will need to be done by the caller.
*/
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag);
/**
* \brief Main Key-framing API call.
*
* Use this when validation of necessary animation data isn't necessary as it
* already exists. It will insert a keyframe using the current value being keyframed.
* Returns the index at which a keyframe was added (or -1 if failed).
*
* This function is a wrapper for #insert_bezt_fcurve(), and should be used when
* adding a new keyframe to a curve, when the keyframe doesn't exist anywhere else yet.
* It returns the index at which the keyframe was added.
*
* \returns The index of the keyframe array into which the bezt has been added.
*
* \param keyframe_type: The type of keyframe (#eBezTriple_KeyframeType).
* \param flag: Optional flags (#eInsertKeyFlags) for controlling how keys get added
* and/or whether updates get done.
*/
int insert_vert_fcurve(
FCurve *fcu, float x, float y, eBezTriple_KeyframeType keyframe_type, eInsertKeyFlags flag);
} // namespace blender::animrig
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+4
View File
@@ -20,7 +20,9 @@ set(INC_SYS
)
set(SRC
intern/action.cc
intern/anim_rna.cc
intern/animdata.cc
intern/bone_collections.cc
intern/bonecolor.cc
intern/fcurve.cc
@@ -28,6 +30,8 @@ set(SRC
intern/keyframing_auto.cc
intern/visualkey.cc
ANIM_action.hh
ANIM_animdata.hh
ANIM_armature_iter.hh
ANIM_bone_collections.h
ANIM_bone_collections.hh
+86
View File
@@ -0,0 +1,86 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup animrig
*/
#include "ANIM_action.hh"
#include "BKE_action.h"
#include "BKE_fcurve.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "DEG_depsgraph_build.hh"
#include "DNA_anim_types.h"
#include "RNA_prototypes.h"
namespace blender::animrig {
FCurve *action_fcurve_find(bAction *act, const char rna_path[], const int array_index)
{
if (ELEM(nullptr, act, rna_path)) {
return nullptr;
}
return BKE_fcurve_find(&act->curves, rna_path, array_index);
}
FCurve *action_fcurve_ensure(Main *bmain,
bAction *act,
const char group[],
PointerRNA *ptr,
const char rna_path[],
const int array_index)
{
if (ELEM(nullptr, act, rna_path)) {
return nullptr;
}
/* Try to find f-curve matching for this setting.
* - add if not found and allowed to add one
* TODO: add auto-grouping support? how this works will need to be resolved
*/
FCurve *fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
if (fcu != nullptr) {
return fcu;
}
fcu = BKE_fcurve_create();
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
fcu->auto_smoothing = U.auto_smoothing_new;
if (BLI_listbase_is_empty(&act->curves)) {
fcu->flag |= FCURVE_ACTIVE;
}
fcu->rna_path = BLI_strdup(rna_path);
fcu->array_index = array_index;
if (group) {
bActionGroup *agrp = BKE_action_group_find_name(act, group);
if (agrp == nullptr) {
agrp = action_groups_add_new(act, group);
/* Sync bone group colors if applicable. */
if (ptr && (ptr->type == &RNA_PoseBone)) {
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
action_group_colors_set_from_posebone(agrp, pchan);
}
}
action_groups_add_channel(act, agrp, fcu);
}
else {
BLI_addtail(&act->curves, fcu);
}
/* New f-curve was added, meaning it's possible that it affects
* dependency graph component which wasn't previously animated.
*/
DEG_relations_tag_update(bmain);
return fcu;
}
} // namespace blender::animrig
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+93
View File
@@ -0,0 +1,93 @@
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup animrig
*/
#include "ANIM_animdata.hh"
#include "BKE_action.h"
#include "BKE_fcurve.h"
#include "BKE_lib_id.h"
#include "BLI_listbase.h"
#include "DNA_anim_types.h"
#include "ED_anim_api.hh"
namespace blender::animrig {
/* -------------------------------------------------------------------- */
/** \name Public F-Curves API
* \{ */
void animdata_fcurve_delete(bAnimContext *ac, AnimData *adt, FCurve *fcu)
{
/* - If no AnimData, we've got nowhere to remove the F-Curve from
* (this doesn't guarantee that the F-Curve is in there, but at least we tried
* - If no F-Curve, there is nothing to remove
*/
if (ELEM(nullptr, adt, fcu)) {
return;
}
/* Remove from whatever list it came from
* - Action Group
* - Action
* - Drivers
* - TODO... some others?
*/
if ((ac) && (ac->datatype == ANIMCONT_DRIVERS)) {
BLI_remlink(&adt->drivers, fcu);
}
else if (adt->action) {
bAction *act = adt->action;
/* Remove from group or action, whichever one "owns" the F-Curve. */
if (fcu->grp) {
bActionGroup *agrp = fcu->grp;
/* Remove F-Curve from group+action. */
action_groups_remove_channel(act, fcu);
/* If group has no more channels, remove it too,
* otherwise can have many dangling groups #33541.
*/
if (BLI_listbase_is_empty(&agrp->channels)) {
BLI_freelinkN(&act->groups, agrp);
}
}
else {
BLI_remlink(&act->curves, fcu);
}
/* If action has no more F-Curves as a result of this, unlink it from
* AnimData if it did not come from a NLA Strip being tweaked.
*
* This is done so that we don't have dangling Object+Action entries in
* channel list that are empty, and linger around long after the data they
* are for has disappeared (and probably won't come back).
*/
animdata_remove_empty_action(adt);
}
BKE_fcurve_free(fcu);
}
bool animdata_remove_empty_action(AnimData *adt)
{
if (adt->action != nullptr) {
bAction *act = adt->action;
if (BLI_listbase_is_empty(&act->curves) && (adt->flag & ADT_NLA_EDIT_ON) == 0) {
id_us_min(&act->id);
adt->action = nullptr;
return true;
}
}
return false;
}
/** \} */
} // namespace blender::animrig
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+285 -88
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -6,104 +6,301 @@
* \ingroup animrig
*/
#include <cmath>
#include <string.h>
#include "ANIM_animdata.hh"
#include "ANIM_fcurve.hh"
#include "BKE_action.h"
#include "BKE_fcurve.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
#include "DEG_depsgraph_build.hh"
#include "DNA_anim_types.h"
#include "ED_anim_api.hh"
#include "RNA_prototypes.h"
#include "MEM_guardedalloc.h"
namespace blender::animrig {
FCurve *action_fcurve_find(bAction *act, const char rna_path[], const int array_index)
{
if (ELEM(nullptr, act, rna_path)) {
return nullptr;
}
return BKE_fcurve_find(&act->curves, rna_path, array_index);
}
FCurve *action_fcurve_ensure(Main *bmain,
bAction *act,
const char group[],
PointerRNA *ptr,
const char rna_path[],
const int array_index)
{
bActionGroup *agrp;
FCurve *fcu;
if (ELEM(nullptr, act, rna_path)) {
return nullptr;
}
/* try to find f-curve matching for this setting
* - add if not found and allowed to add one
* TODO: add auto-grouping support? how this works will need to be resolved
*/
fcu = BKE_fcurve_find(&act->curves, rna_path, array_index);
if (fcu == nullptr) {
fcu = BKE_fcurve_create();
fcu->flag = (FCURVE_VISIBLE | FCURVE_SELECTED);
fcu->auto_smoothing = U.auto_smoothing_new;
if (BLI_listbase_is_empty(&act->curves)) {
fcu->flag |= FCURVE_ACTIVE;
}
fcu->rna_path = BLI_strdup(rna_path);
fcu->array_index = array_index;
if (group) {
agrp = BKE_action_group_find_name(act, group);
if (agrp == nullptr) {
agrp = action_groups_add_new(act, group);
/* sync bone group colors if applicable */
if (ptr && (ptr->type == &RNA_PoseBone)) {
bPoseChannel *pchan = static_cast<bPoseChannel *>(ptr->data);
action_group_colors_set_from_posebone(agrp, pchan);
}
}
action_groups_add_channel(act, agrp, fcu);
}
else {
BLI_addtail(&act->curves, fcu);
}
/* New f-curve was added, meaning it's possible that it affects
* dependency graph component which wasn't previously animated.
*/
DEG_relations_tag_update(bmain);
}
return fcu;
}
bool delete_keyframe_fcurve(AnimData *adt, FCurve *fcu, float cfra)
{
bool found;
int i;
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
if (found) {
/* Delete the key at the index (will sanity check + do recalc afterwards). */
BKE_fcurve_delete_key(fcu, i);
BKE_fcurve_handles_recalc(fcu);
/* Empty curves get automatically deleted. */
if (BKE_fcurve_is_empty(fcu)) {
ANIM_fcurve_delete_from_animdata(nullptr, adt, fcu);
}
return true;
const int index = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, cfra, fcu->totvert, &found);
if (!found) {
return false;
}
return false;
/* Delete the key at the index (will sanity check + do recalc afterwards). */
BKE_fcurve_delete_key(fcu, index);
BKE_fcurve_handles_recalc(fcu);
/* Empty curves get automatically deleted. */
if (BKE_fcurve_is_empty(fcu)) {
animdata_fcurve_delete(nullptr, adt, fcu);
}
return true;
}
/* ************************************************** */
/* KEYFRAME INSERTION */
/* -------------- BezTriple Insertion -------------------- */
/* Change the Y position of a keyframe to match the input, adjusting handles. */
static void replace_bezt_keyframe_ypos(BezTriple *dst, const BezTriple *bezt)
{
/* Just change the values when replacing, so as to not overwrite handles. */
float dy = bezt->vec[1][1] - dst->vec[1][1];
/* Just apply delta value change to the handle values. */
dst->vec[0][1] += dy;
dst->vec[1][1] += dy;
dst->vec[2][1] += dy;
dst->f1 = bezt->f1;
dst->f2 = bezt->f2;
dst->f3 = bezt->f3;
/* TODO: perform some other operations? */
}
int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
{
int i = 0;
/* Are there already keyframes? */
if (fcu->bezt) {
bool replace;
i = BKE_fcurve_bezt_binarysearch_index(fcu->bezt, bezt->vec[1][0], fcu->totvert, &replace);
/* Replace an existing keyframe? */
if (replace) {
/* 'i' may in rare cases exceed arraylen. */
if ((i >= 0) && (i < fcu->totvert)) {
if (flag & INSERTKEY_OVERWRITE_FULL) {
fcu->bezt[i] = *bezt;
}
else {
replace_bezt_keyframe_ypos(&fcu->bezt[i], bezt);
}
if (flag & INSERTKEY_CYCLE_AWARE) {
/* If replacing an end point of a cyclic curve without offset,
* modify the other end too. */
if (ELEM(i, 0, fcu->totvert - 1) && BKE_fcurve_get_cycle_type(fcu) == FCU_CYCLE_PERFECT)
{
replace_bezt_keyframe_ypos(&fcu->bezt[i == 0 ? fcu->totvert - 1 : 0], bezt);
}
}
}
}
/* Keyframing modes allow not replacing the keyframe. */
else if ((flag & INSERTKEY_REPLACE) == 0) {
/* Insert new - if we're not restricted to replacing keyframes only. */
BezTriple *newb = static_cast<BezTriple *>(
MEM_callocN((fcu->totvert + 1) * sizeof(BezTriple), "beztriple"));
/* Add the beztriples that should occur before the beztriple to be pasted
* (originally in fcu). */
if (i > 0) {
memcpy(newb, fcu->bezt, i * sizeof(BezTriple));
}
/* Add beztriple to paste at index i. */
*(newb + i) = *bezt;
/* Add the beztriples that occur after the beztriple to be pasted (originally in fcu). */
if (i < fcu->totvert) {
memcpy(newb + i + 1, fcu->bezt + i, (fcu->totvert - i) * sizeof(BezTriple));
}
/* Replace (+ free) old with new, only if necessary to do so. */
MEM_freeN(fcu->bezt);
fcu->bezt = newb;
fcu->totvert++;
}
else {
return -1;
}
}
/* No keyframes yet, but can only add if...
* 1) keyframing modes say that keyframes can only be replaced, so adding new ones won't know
* 2) there are no samples on the curve
* NOTE: maybe we may want to allow this later when doing samples -> bezt conversions,
* but for now, having both is asking for trouble
*/
else if ((flag & INSERTKEY_REPLACE) == 0 && (fcu->fpt == nullptr)) {
/* Create new keyframes array. */
fcu->bezt = static_cast<BezTriple *>(MEM_callocN(sizeof(BezTriple), "beztriple"));
*(fcu->bezt) = *bezt;
fcu->totvert = 1;
}
/* Cannot add anything. */
else {
/* Return error code -1 to prevent any misunderstandings. */
return -1;
}
/* We need to return the index, so that some tools which do post-processing can
* detect where we added the BezTriple in the array.
*/
return i;
}
/**
* Update the FCurve to allow insertion of `bezt` without modifying the curve shape.
*
* Checks whether it is necessary to apply Bezier subdivision due to involvement of non-auto
* handles. If necessary, changes `bezt` handles from Auto to Aligned.
*
* \param bezt: key being inserted
* \param prev: keyframe before that key
* \param next: keyframe after that key
*/
static void subdivide_nonauto_handles(const FCurve *fcu,
BezTriple *bezt,
BezTriple *prev,
BezTriple *next)
{
if (prev->ipo != BEZT_IPO_BEZ || bezt->ipo != BEZT_IPO_BEZ) {
return;
}
/* Don't change Vector handles, or completely auto regions. */
const bool bezt_auto = BEZT_IS_AUTOH(bezt) || (bezt->h1 == HD_VECT && bezt->h2 == HD_VECT);
const bool prev_auto = BEZT_IS_AUTOH(prev) || (prev->h2 == HD_VECT);
const bool next_auto = BEZT_IS_AUTOH(next) || (next->h1 == HD_VECT);
if (bezt_auto && prev_auto && next_auto) {
return;
}
/* Subdivide the curve. */
float delta;
if (!BKE_fcurve_bezt_subdivide_handles(bezt, prev, next, &delta)) {
return;
}
/* Decide when to force auto to manual. */
if (!BEZT_IS_AUTOH(bezt)) {
return;
}
if ((prev_auto || next_auto) && fcu->auto_smoothing == FCURVE_SMOOTH_CONT_ACCEL) {
const float hx = bezt->vec[1][0] - bezt->vec[0][0];
const float dx = bezt->vec[1][0] - prev->vec[1][0];
/* This mode always uses 1/3 of key distance for handle x size. */
const bool auto_works_well = fabsf(hx - dx / 3.0f) < 0.001f;
if (auto_works_well) {
return;
}
}
/* Turn off auto mode. */
bezt->h1 = bezt->h2 = HD_ALIGN;
}
int insert_vert_fcurve(
FCurve *fcu, float x, float y, eBezTriple_KeyframeType keyframe_type, eInsertKeyFlags flag)
{
BezTriple beztr = {{{0}}};
uint oldTot = fcu->totvert;
int a;
/* Set all three points, for nicer start position.
* NOTE: +/- 1 on vec.x for left and right handles is so that 'free' handles work ok...
*/
beztr.vec[0][0] = x - 1.0f;
beztr.vec[0][1] = y;
beztr.vec[1][0] = x;
beztr.vec[1][1] = y;
beztr.vec[2][0] = x + 1.0f;
beztr.vec[2][1] = y;
beztr.f1 = beztr.f2 = beztr.f3 = SELECT;
/* Set default handle types and interpolation mode. */
if (flag & INSERTKEY_NO_USERPREF) {
/* For Py-API, we want scripts to have predictable behavior,
* hence the option to not depend on the userpref defaults.
*/
beztr.h1 = beztr.h2 = HD_AUTO_ANIM;
beztr.ipo = BEZT_IPO_BEZ;
}
else {
/* For UI usage - defaults should come from the user-preferences and/or tool-settings. */
beztr.h1 = beztr.h2 = U.keyhandles_new; /* Use default handle type here. */
/* Use default interpolation mode, with exceptions for int/discrete values. */
beztr.ipo = U.ipo_new;
}
/* Interpolation type used is constrained by the type of values the curve can take. */
if (fcu->flag & FCURVE_DISCRETE_VALUES) {
beztr.ipo = BEZT_IPO_CONST;
}
else if ((beztr.ipo == BEZT_IPO_BEZ) && (fcu->flag & FCURVE_INT_VALUES)) {
beztr.ipo = BEZT_IPO_LIN;
}
/* Set keyframe type value (supplied), which should come from the scene
* settings in most cases. */
BEZKEYTYPE(&beztr) = keyframe_type;
/* Set default values for "easing" interpolation mode settings.
* NOTE: Even if these modes aren't currently used, if users switch
* to these later, we want these to work in a sane way out of
* the box.
*/
/* "back" easing - This value used to be used when overshoot=0, but that
* introduced discontinuities in how the param worked. */
beztr.back = 1.70158f;
/* "elastic" easing - Values here were hand-optimized for a default duration of
* ~10 frames (typical mograph motion length) */
beztr.amplitude = 0.8f;
beztr.period = 4.1f;
/* Add temp beztriple to keyframes. */
a = insert_bezt_fcurve(fcu, &beztr, flag);
BKE_fcurve_active_keyframe_set(fcu, &fcu->bezt[a]);
/* If `a` is negative return to avoid segfaults. */
if (a < 0) {
return -1;
}
/* Set handle-type and interpolation. */
if ((fcu->totvert > 2) && (flag & INSERTKEY_REPLACE) == 0) {
BezTriple *bezt = (fcu->bezt + a);
/* Set interpolation from previous (if available),
* but only if we didn't just replace some keyframe:
* - Replacement is indicated by no-change in number of verts.
* - When replacing, the user may have specified some interpolation that should be kept.
*/
if (fcu->totvert > oldTot) {
if (a > 0) {
bezt->ipo = (bezt - 1)->ipo;
}
else if (a < fcu->totvert - 1) {
bezt->ipo = (bezt + 1)->ipo;
}
if (0 < a && a < (fcu->totvert - 1) && (flag & INSERTKEY_OVERWRITE_FULL) == 0) {
subdivide_nonauto_handles(fcu, bezt, bezt - 1, bezt + 1);
}
}
}
/* Don't recalculate handles if fast is set.
* - this is a hack to make importers faster
* - we may calculate twice (due to auto-handle needing to be calculated twice)
*/
if ((flag & INSERTKEY_FAST) == 0) {
BKE_fcurve_handles_recalc(fcu);
}
/* Return the index at which the keyframe was added. */
return a;
}
} // namespace blender::animrig
+4 -3
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -9,6 +9,8 @@
#include <cfloat>
#include <cmath>
#include "ANIM_action.hh"
#include "ANIM_animdata.hh"
#include "ANIM_fcurve.hh"
#include "ANIM_keyframing.hh"
#include "ANIM_rna.hh"
@@ -31,7 +33,6 @@
#include "DEG_depsgraph.hh"
#include "DEG_depsgraph_query.hh"
#include "DNA_anim_types.h"
#include "ED_anim_api.hh"
#include "ED_keyframing.hh"
#include "MEM_guardedalloc.h"
#include "RNA_access.hh"
@@ -936,7 +937,7 @@ int clear_keyframe(Main *bmain,
continue;
}
ANIM_fcurve_delete_from_animdata(nullptr, adt, fcu);
animdata_fcurve_delete(nullptr, adt, fcu);
key_count++;
}
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -3
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -23,8 +23,6 @@
#include "DNA_object_types.h"
#include "DNA_rigidbody_types.h"
#include "ED_keyframing.hh"
#include "RNA_access.hh"
#include "RNA_prototypes.h"
#include "RNA_types.hh"
+48 -39
View File
@@ -56,7 +56,7 @@
BatchBLF g_batch;
/* freetype2 handle ONLY for this file! */
/* `freetype2` handle ONLY for this file! */
static FT_Library ft_lib = nullptr;
static FTC_Manager ftc_manager = nullptr;
static FTC_CMapCache ftc_charmap_cache = nullptr;
@@ -163,8 +163,8 @@ static ft_pix blf_unscaled_F26Dot6_to_pixels(FontBLF *font, FT_Pos value)
/* Scale value by font size using integer-optimized multiplication. */
FT_Long scaled = FT_MulFix(value, font->ft_size->metrics.x_scale);
/* Copied from FreeType's FT_Get_Kerning (with FT_KERNING_DEFAULT), scaling down */
/* kerning distances at small PPEM values so that they don't become too big. */
/* Copied from FreeType's FT_Get_Kerning (with FT_KERNING_DEFAULT), scaling down. */
/* Kerning distances at small PPEM values so that they don't become too big. */
if (font->ft_size->metrics.x_ppem < 25) {
scaled = FT_MulDiv(scaled, font->ft_size->metrics.x_ppem, 25);
}
@@ -270,7 +270,7 @@ void blf_batch_draw_begin(FontBLF *font)
}
}
else {
/* flush cache */
/* Flush cache. */
blf_batch_draw();
g_batch.font = font;
g_batch.simple_shader = simple_shader;
@@ -332,7 +332,7 @@ void blf_batch_draw()
GPUTexture *texture = blf_batch_cache_texture_load();
GPU_vertbuf_data_len_set(g_batch.verts, g_batch.glyph_len);
GPU_vertbuf_use(g_batch.verts); /* send data */
GPU_vertbuf_use(g_batch.verts); /* Send data. */
GPU_batch_program_set_builtin(g_batch.batch, GPU_SHADER_TEXT);
GPU_batch_texture_bind(g_batch.batch, "glyph", texture);
@@ -342,7 +342,7 @@ void blf_batch_draw()
GPU_texture_unbind(texture);
/* restart to 1st vertex data pointers */
/* Restart to 1st vertex data pointers. */
GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step);
GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step);
GPU_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.offset_loc, &g_batch.offset_step);
@@ -442,15 +442,15 @@ static void blf_font_draw_ex(FontBLF *font,
ResultBLF *r_info,
const ft_pix pen_y)
{
if (str_len == 0) {
/* Early exit, don't do any immediate-mode GPU operations. */
return;
}
GlyphBLF *g = nullptr;
ft_pix pen_x = 0;
size_t i = 0;
if (str_len == 0) {
/* early output, don't do any IMM OpenGL. */
return;
}
blf_batch_draw_begin(font);
while ((i < str_len) && str[i]) {
@@ -458,7 +458,7 @@ static void blf_font_draw_ex(FontBLF *font,
if (UNLIKELY(g == nullptr)) {
continue;
}
/* do not return this loop if clipped, we want every character tested */
/* Do not return this loop if clipped, we want every character tested. */
blf_glyph_draw(font, gc, g, ft_pix_to_int_floor(pen_x), ft_pix_to_int_floor(pen_y));
pen_x += g->advance_x;
}
@@ -497,7 +497,7 @@ int blf_font_draw_mono(
if (UNLIKELY(g == nullptr)) {
continue;
}
/* do not return this loop if clipped, we want every character tested */
/* Do not return this loop if clipped, we want every character tested. */
blf_glyph_draw(font, gc, g, ft_pix_to_int_floor(pen_x), ft_pix_to_int_floor(pen_y));
const int col = UNLIKELY(g->c == '\t') ? (tab_columns - (columns % tab_columns)) :
@@ -641,10 +641,10 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
ft_pix pen_y_basis = ft_pix_from_int(font->pos[1]) + pen_y;
size_t i = 0;
/* buffer specific vars */
/* Buffer specific variables. */
FontBufInfoBLF *buf_info = &font->buf_info;
/* another buffer specific call for color conversion */
/* Another buffer specific call for color conversion. */
while ((i < str_len) && str[i]) {
g = blf_glyph_from_utf8_and_step(font, gc, g, str, str_len, &i, &pen_x);
@@ -687,7 +687,8 @@ static bool blf_font_width_to_strlen_glyph_process(FontBLF *font,
const int width_i)
{
if (UNLIKELY(g == nullptr)) {
return false; /* continue the calling loop. */
/* Continue the calling loop. */
return false;
}
if (g && pen_x && !(font->flags & BLF_MONOSPACED)) {
@@ -946,19 +947,19 @@ void blf_font_boundbox_foreach_glyph(FontBLF *font,
BLF_GlyphBoundsFn user_fn,
void *user_data)
{
GlyphBLF *g = nullptr;
ft_pix pen_x = 0;
size_t i = 0, i_curr;
if (str_len == 0 || str[0] == 0) {
/* early output. */
/* Early exit. */
return;
}
GlyphBLF *g = nullptr;
ft_pix pen_x = 0;
size_t i = 0;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
while ((i < str_len) && str[i]) {
i_curr = i;
const size_t i_curr = i;
g = blf_glyph_from_utf8_and_step(font, gc, g, str, str_len, &i, &pen_x);
if (UNLIKELY(g == nullptr)) {
@@ -1103,8 +1104,8 @@ static void blf_font_wrap_apply(FontBLF *font,
// printf("%s wrapping (%d, %d) `%s`:\n", __func__, str_len, strlen(str), str);
while ((i < str_len) && str[i]) {
/* wrap vars */
size_t i_curr = i;
/* Wrap variables. */
const size_t i_curr = i;
bool do_draw = false;
g = blf_glyph_from_utf8_and_step(font, gc, g_prev, str, str_len, &i, &pen_x);
@@ -1126,7 +1127,7 @@ static void blf_font_wrap_apply(FontBLF *font,
do_draw = true;
}
else if (UNLIKELY(((i < str_len) && str[i]) == 0)) {
/* need check here for trailing newline, else we draw it */
/* Need check here for trailing newline, else we draw it. */
wrap.last[0] = i + ((g->c != '\n') ? 1 : 0);
wrap.last[1] = i;
do_draw = true;
@@ -1142,8 +1143,13 @@ static void blf_font_wrap_apply(FontBLF *font,
}
if (UNLIKELY(do_draw)) {
// printf("(%03d..%03d) `%.*s`\n",
// wrap.start, wrap.last[0], (wrap.last[0] - wrap.start) - 1, &str[wrap.start]);
#if 0
printf("(%03d..%03d) `%.*s`\n",
wrap.start,
wrap.last[0],
(wrap.last[0] - wrap.start) - 1,
&str[wrap.start]);
#endif
callback(font, gc, &str[wrap.start], (wrap.last[0] - wrap.start) - 1, pen_y, userdata);
wrap.start = wrap.last[0];
@@ -1163,14 +1169,14 @@ static void blf_font_wrap_apply(FontBLF *font,
if (r_info) {
r_info->lines = lines;
/* width of last line only (with wrapped lines) */
/* Width of last line only (with wrapped lines). */
r_info->width = ft_pix_to_int(pen_x_next);
}
blf_glyph_cache_release(font);
}
/* blf_font_draw__wrap */
/** Utility for #blf_font_draw__wrap. */
static void blf_font_draw__wrap_cb(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
@@ -1185,7 +1191,7 @@ void blf_font_draw__wrap(FontBLF *font, const char *str, const size_t str_len, R
blf_font_wrap_apply(font, str, str_len, r_info, blf_font_draw__wrap_cb, nullptr);
}
/* blf_font_boundbox__wrap */
/** Utility for #blf_font_boundbox__wrap. */
static void blf_font_boundbox_wrap_cb(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
@@ -1210,7 +1216,7 @@ void blf_font_boundbox__wrap(
blf_font_wrap_apply(font, str, str_len, r_info, blf_font_boundbox_wrap_cb, box);
}
/* blf_font_draw_buffer__wrap */
/** Utility for #blf_font_draw_buffer__wrap. */
static void blf_font_draw_buffer__wrap_cb(FontBLF *font,
GlyphCacheBLF *gc,
const char *str,
@@ -1237,8 +1243,8 @@ void blf_font_draw_buffer__wrap(FontBLF *font,
static ft_pix blf_font_height_max_ft_pix(FontBLF *font)
{
blf_ensure_size(font);
/* Metrics.height is rounded to pixel. Force minimum of one pixel. */
return MAX2((ft_pix)font->ft_size->metrics.height, ft_pix_from_int(1));
/* #Metrics::height is rounded to pixel. Force minimum of one pixel. */
return std::max((ft_pix)font->ft_size->metrics.height, ft_pix_from_int(1));
}
int blf_font_height_max(FontBLF *font)
@@ -1249,8 +1255,8 @@ int blf_font_height_max(FontBLF *font)
static ft_pix blf_font_width_max_ft_pix(FontBLF *font)
{
blf_ensure_size(font);
/* Metrics.max_advance is rounded to pixel. Force minimum of one pixel. */
return MAX2((ft_pix)font->ft_size->metrics.max_advance, ft_pix_from_int(1));
/* #Metrics::max_advance is rounded to pixel. Force minimum of one pixel. */
return std::max((ft_pix)font->ft_size->metrics.max_advance, ft_pix_from_int(1));
}
int blf_font_width_max(FontBLF *font)
@@ -1299,7 +1305,7 @@ int blf_font_init()
nullptr,
&ftc_manager);
if (err == FT_Err_Ok) {
/* Create a charmap cache to speed up glyph index lookups. */
/* Create a character-map cache to speed up glyph index lookups. */
err = FTC_CMapCache_New(ftc_manager, &ftc_charmap_cache);
}
}
@@ -1342,7 +1348,8 @@ static void blf_font_fill(FontBLF *font)
font->m[i] = 0;
}
/* annoying bright color so we can see where to add BLF_color calls */
/* Use an easily identifiable bright color (yellow)
* so its clear when #BLF_color calls are missing. */
font->color[0] = 255;
font->color[1] = 255;
font->color[2] = 0;
@@ -1377,8 +1384,10 @@ static void blf_font_fill(FontBLF *font)
font->buf_info.col_init[3] = 0;
}
/* Note that the data the following function creates is not yet used.
* But do not remove it as it will be used in the near future - Harley */
/**
* NOTE(@Harley): that the data the following function creates is not yet used.
* But do not remove it as it will be used in the near future.
*/
static void blf_font_metrics(FT_Face face, FontMetrics *metrics)
{
/* Members with non-zero defaults. */
+3 -3
View File
@@ -1134,11 +1134,11 @@ static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font,
/* Style targets are on the settings_font. */
float weight_target = float(settings_font->char_weight);
if (settings_font->flags & BLF_BOLD) {
weight_target = MIN2(weight_target + 300.0f, 900.0f);
weight_target = std::min(weight_target + 300.0f, 900.0f);
}
float slant_target = settings_font->char_slant;
if (settings_font->flags & BLF_ITALIC) {
slant_target = MIN2(slant_target + 8.0f, 15.0f);
slant_target = std::min(slant_target + 8.0f, 15.0f);
}
float width_target = settings_font->char_width;
float spacing_target = settings_font->char_spacing;
@@ -1281,7 +1281,7 @@ static void blf_glyph_calc_rect_test(rcti *rect, GlyphBLF *g, const int x, const
* width used by BLF_width. This allows that the text slightly
* overlaps the clipping border to achieve better alignment. */
rect->xmin = x + g->pos[0] + 1;
rect->xmax = x + MIN2(ft_pix_to_int(g->advance_x), g->dims[0]);
rect->xmax = x + std::min(ft_pix_to_int(g->advance_x), g->dims[0]);
rect->ymin = y;
rect->ymax = rect->ymin - g->dims[1];
}
+2 -2
View File
@@ -365,7 +365,7 @@ bool BLF_thumb_preview(const char *filename, uchar *buf, int w, int h, int /*cha
int height = ft_pix_to_int((ft_pix)face->size->metrics.ascender -
(ft_pix)face->size->metrics.descender);
width = MAX2(width, height);
width = std::max(width, height);
/* Fill up to 96% horizontally or vertically. */
float font_size = MIN3(float(w),
@@ -410,7 +410,7 @@ bool BLF_thumb_preview(const char *filename, uchar *buf, int w, int h, int /*cha
if (dest_col >= 0 && dest_col < w) {
uchar *source = &face->glyph->bitmap.buffer[y * int(face->glyph->bitmap.width) + x];
uchar *dest = &buf[dest_row * w * 4 + (dest_col * 4 + 3)];
*dest = uchar(MIN2((uint(*dest) + uint(*source)), 255u));
*dest = uchar(std::min((uint(*dest) + uint(*source)), 255u));
}
}
}
@@ -29,7 +29,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 4
#define BLENDER_FILE_SUBVERSION 5
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and cancel loading the file, showing a warning to
@@ -8,8 +8,11 @@
#include "DNA_node_types.h"
#include "BLI_array.hh"
#include "BLI_bit_group_vector.hh"
#include "BLI_resource_scope.hh"
#include "BLI_vector.hh"
#include "BLI_vector_set.hh"
#include "NOD_node_declaration.hh"
+1 -1
View File
@@ -1197,7 +1197,7 @@ static void nlaeval_snapshot_init(NlaEvalSnapshot *snapshot,
NlaEvalSnapshot *base)
{
snapshot->base = base;
snapshot->size = MAX2(16, nlaeval->num_channels);
snapshot->size = std::max(16, nlaeval->num_channels);
snapshot->channels = static_cast<NlaEvalChannelSnapshot **>(
MEM_callocN(sizeof(*snapshot->channels) * snapshot->size, "NlaEvalSnapshot::channels"));
}
@@ -270,8 +270,8 @@ void BKE_id_attribute_calc_unique_name(ID *id, const char *name, char *outname)
const int name_maxncpy = CustomData_name_maxncpy_calc(name);
/* Set default name if none specified.
* NOTE: We only call IFACE_() if needed to avoid locale lookup overhead. */
BLI_strncpy_utf8(outname, (name && name[0]) ? name : IFACE_("Attribute"), name_maxncpy);
* NOTE: We only call DATA_() if needed to avoid locale lookup overhead. */
BLI_strncpy_utf8(outname, (name && name[0]) ? name : DATA_("Attribute"), name_maxncpy);
const char *defname = ""; /* Dummy argument, never used as `name` is never zero length. */
BLI_uniquename_cb(unique_name_cb, &data, defname, '.', outname, name_maxncpy);
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+4 -4
View File
@@ -275,7 +275,7 @@ static bool rule_avoid_collision(BoidRule *rule,
mul_v3_fl(bbd->wanted_co, (1.0f - t) * val->personal_space * pa->size);
bbd->wanted_speed = sqrtf(t) * len_v3(pa->prev_state.vel);
bbd->wanted_speed = MAX2(bbd->wanted_speed, val->min_speed);
bbd->wanted_speed = std::max(bbd->wanted_speed, val->min_speed);
return true;
}
@@ -1321,7 +1321,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
new_speed = MAX2(bbd->wanted_speed, old_speed - val.max_acc);
}
else {
new_speed = MIN2(bbd->wanted_speed, old_speed + val.max_acc);
new_speed = std::min(bbd->wanted_speed, old_speed + val.max_acc);
}
/* combine direction and speed */
@@ -1333,7 +1333,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
float len2 = dot_v2v2(new_vel, new_vel);
float root;
len2 = MAX2(len2, val.min_speed * val.min_speed);
len2 = std::max(len2, val.min_speed * val.min_speed);
root = sasqrt(new_speed * new_speed - len2);
new_vel[2] = new_vel[2] < 0.0f ? -root : root;
@@ -1367,7 +1367,7 @@ void boid_body(BoidBrainData *bbd, ParticleData *pa)
if (ELEM(bpa->data.mode, eBoidMode_OnLand, eBoidMode_Climbing)) {
float length = normalize_v3(force);
length = MAX2(0.0f, length - boids->land_stick_force);
length = std::max(0.0f, length - boids->land_stick_force);
mul_v3_fl(force, length);
}
@@ -757,7 +757,7 @@ static int cloth_collision_response_static(ClothModifierData *clmd,
}
if ((magrelVel < 0.1f * d * time_multiplier) && (d > ALMOST_ZERO)) {
repulse = MIN2(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
repulse = std::min(d / time_multiplier, 0.1f * d * time_multiplier - magrelVel);
/* Stay on the safe side and clamp repulse. */
if (impulse > ALMOST_ZERO) {
@@ -2427,7 +2427,7 @@ void CustomData_ensure_data_is_mutable(CustomDataLayer *layer, const int totelem
ensure_layer_data_is_mutable(*layer, totelem);
}
void CustomData_ensure_layers_are_mutable(struct CustomData *data, int totelem)
void CustomData_ensure_layers_are_mutable(CustomData *data, int totelem)
{
for (const int i : IndexRange(data->totlayer)) {
ensure_layer_data_is_mutable(data->layers[i], totelem);
@@ -7,6 +7,8 @@
#include "BKE_fcurve.h"
#include "ANIM_fcurve.hh"
#include "ED_keyframing.hh"
#include "DNA_anim_types.h"
@@ -14,6 +16,7 @@
#include "BLI_math_vector_types.hh"
namespace blender::bke::tests {
using namespace blender::animrig;
/* Epsilon for floating point comparisons. */
static const float EPSILON = 1e-7f;
+11 -10
View File
@@ -450,7 +450,7 @@ static void manta_set_domain_from_mesh(FluidDomainSettings *fds,
fds->base_res[1] = max_ii(int(size[1] * scale + 0.5f), 4);
fds->base_res[2] = max_ii(int(size[2] * scale + 0.5f), 4);
}
else if (size[1] >= MAX2(size[0], size[2])) {
else if (size[1] >= std::max(size[0], size[2])) {
scale = res / size[1];
fds->scale = size[1] / fabsf(ob->scale[1]);
fds->base_res[0] = max_ii(int(size[0] * scale + 0.5f), 4);
@@ -736,8 +736,8 @@ static void bb_combineMaps(FluidObjectBB *output,
for (i = 0; i < 3; i++) {
if (bb1.valid) {
output->min[i] = MIN2(bb1.min[i], bb2->min[i]);
output->max[i] = MAX2(bb1.max[i], bb2->max[i]);
output->min[i] = std::min(bb1.min[i], bb2->min[i]);
output->max[i] = std::max(bb1.max[i], bb2->max[i]);
}
else {
output->min[i] = bb2->min[i];
@@ -783,14 +783,15 @@ static void bb_combineMaps(FluidObjectBB *output,
x - bb2->min[0], bb2->res[0], y - bb2->min[1], bb2->res[1], z - bb2->min[2]);
/* Values. */
output->numobjs[index_out] = MAX2(bb2->numobjs[index_in], output->numobjs[index_out]);
output->numobjs[index_out] = std::max(bb2->numobjs[index_in],
output->numobjs[index_out]);
if (output->influence && bb2->influence) {
if (additive) {
output->influence[index_out] += bb2->influence[index_in] * sample_size;
}
else {
output->influence[index_out] = MAX2(bb2->influence[index_in],
output->influence[index_out]);
output->influence[index_out] = std::max(bb2->influence[index_in],
output->influence[index_out]);
}
}
output->distances[index_out] = MIN2(bb2->distances[index_in],
@@ -2481,7 +2482,7 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *ffs,
/* Set emission value for smoke inflow.
* Ensure that emission value is "maximized". */
if (emission_in) {
emission_in[index] = MAX2(emission_value, emission_in[index]);
emission_in[index] = std::max(emission_value, emission_in[index]);
}
/* Set inflow for smoke from here on. */
@@ -2502,13 +2503,13 @@ BLI_INLINE void apply_inflow_fields(FluidFlowSettings *ffs,
if (density && density_in) {
if (ffs->type != FLUID_FLOW_TYPE_FIRE && dens_flow > density[index]) {
/* Use MAX2 to preserve values from other emitters at this cell. */
density_in[index] = MAX2(dens_flow, density_in[index]);
density_in[index] = std::max(dens_flow, density_in[index]);
}
}
if (fuel && fuel_in) {
if (ffs->type != FLUID_FLOW_TYPE_SMOKE && fuel_flow && fuel_flow > fuel[index]) {
/* Use MAX2 to preserve values from other emitters at this cell. */
fuel_in[index] = MAX2(fuel_flow, fuel_in[index]);
fuel_in[index] = std::max(fuel_flow, fuel_in[index]);
}
}
}
@@ -4414,7 +4415,7 @@ float BKE_fluid_get_velocity_at(Object *ob, float position[3], float velocity[3]
if (manta_smoke_has_fuel(fds->fluid)) {
fuel = BLI_voxel_sample_trilinear(manta_smoke_get_fuel(fds->fluid), fds->res, pos);
}
return MAX2(density, fuel);
return std::max(density, fuel);
}
return -1.0f;
}
@@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm> /* For `min/max`. */
#include <cfloat>
#include <cmath>
#include <cstddef>
@@ -1327,7 +1328,7 @@ uint evaluate_fmodifiers_storage_size_per_modifier(ListBase *modifiers)
continue;
}
max_size = MAX2(max_size, fmi->storage_size);
max_size = std::max(max_size, fmi->storage_size);
}
return max_size;
@@ -1717,7 +1717,7 @@ float BKE_gpencil_stroke_segment_length(const bGPDstroke *gps,
}
int index = MAX2(start_index, 0) + 1;
int last_index = MIN2(end_index, gps->totpoints - 1) + 1;
int last_index = std::min(end_index, gps->totpoints - 1) + 1;
float *last_pt = &gps->points[index - 1].x;
float total_length = 0.0f;
@@ -3560,8 +3560,8 @@ void BKE_gpencil_stroke_join(bGPDstroke *gps_a,
if (smooth) {
const int sample_points = 8;
/* Get the segment to smooth using n points on each side of the join. */
int start = MAX2(0, totpoints_a - sample_points);
int end = MIN2(gps_a->totpoints - 1, start + (sample_points * 2));
int start = std::max(0, totpoints_a - sample_points);
int end = std::min(gps_a->totpoints - 1, start + (sample_points * 2));
const int len = (end - start);
float step = 1.0f / ((len / 2) + 1);
@@ -1939,7 +1939,7 @@ static std::string unique_node_name(const GreasePencil &grease_pencil,
{
using namespace blender;
char unique_name[MAX_NAME];
BLI_strncpy(unique_name, name.c_str(), MAX_NAME);
STRNCPY(unique_name, name.c_str());
VectorSet<StringRefNull> names = get_node_names(grease_pencil);
unique_node_name_ex(names, default_name, unique_name);
return unique_name;
@@ -8,6 +8,7 @@
* Functions for evaluating the mask beziers into points for the outline and feather.
*/
#include <algorithm> /* For `min/max`. */
#include <cstddef>
#include <cstring>
@@ -57,7 +58,7 @@ uint BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
len = a + b + c;
cur_resol = len / max_segment;
resol = MAX2(resol, cur_resol);
resol = std::max(resol, cur_resol);
if (resol >= MASK_RESOL_MAX) {
break;
@@ -50,6 +50,8 @@
* - Campbell
*/
#include <algorithm> /* For `min/max`. */
#include "CLG_log.h"
#include "MEM_guardedalloc.h"
@@ -630,7 +632,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
const uint resol_a = BKE_mask_spline_resolution(spline, width, height) / 4;
const uint resol_b = BKE_mask_spline_feather_resolution(spline, width, height) / 4;
const uint resol = CLAMPIS(MAX2(resol_a, resol_b), 4, 512);
const uint resol = CLAMPIS(std::max(resol_a, resol_b), 4, 512);
diff_points = BKE_mask_spline_differentiate_with_resolution(spline, resol, &tot_diff_point);
@@ -23,6 +23,7 @@
#include "BLI_array_utils.hh"
#include "BLI_bit_vector.hh"
#include "BLI_linklist.h"
#include "BLI_math_base.hh"
#include "BLI_math_vector.hh"
#include "BLI_memarena.h"
#include "BLI_span.hh"
@@ -243,7 +244,7 @@ static void accumulate_face_normal_to_vert(const Span<float3> positions,
}
/* Calculate angle between the two face edges incident on this vertex. */
const float fac = saacos(-dot_v3v3(edvec_prev, edvec_next));
const float fac = math::safe_acos_approx(-dot_v3v3(edvec_prev, edvec_next));
const float vnor_add[3] = {face_normal[0] * fac, face_normal[1] * fac, face_normal[2] * fac};
float *vnor = vert_normals[face_verts[i_curr]];
@@ -535,7 +536,7 @@ static CornerNormalSpace lnor_space_define(const float lnor[3],
if (!edge_vectors.is_empty()) {
float alpha = 0.0f;
for (const float3 &vec : edge_vectors) {
alpha += saacosf(dot_v3v3(vec, lnor));
alpha += math::safe_acos_approx(dot_v3v3(vec, lnor));
}
/* This piece of code shall only be called for more than one loop. */
/* NOTE: In theory, this could be `count > 2`,
@@ -546,8 +547,8 @@ static CornerNormalSpace lnor_space_define(const float lnor[3],
lnor_space.ref_alpha = alpha / float(edge_vectors.size());
}
else {
lnor_space.ref_alpha = (saacosf(dot_v3v3(vec_ref, lnor)) +
saacosf(dot_v3v3(vec_other, lnor))) /
lnor_space.ref_alpha = (math::safe_acos_approx(dot_v3v3(vec_ref, lnor)) +
math::safe_acos_approx(dot_v3v3(vec_other, lnor))) /
2.0f;
}
@@ -567,7 +568,7 @@ static CornerNormalSpace lnor_space_define(const float lnor[3],
/* Beta is angle between ref_vec and other_vec, around lnor. */
dtp = dot_v3v3(lnor_space.vec_ref, vec_other);
if (LIKELY(dtp < LNOR_SPACE_TRIGO_THRESHOLD)) {
const float beta = saacos(dtp);
const float beta = math::safe_acos_approx(dtp);
lnor_space.ref_beta = (dot_v3v3(lnor_space.vec_ortho, vec_other) < 0.0f) ? pi2 - beta : beta;
}
else {
@@ -698,7 +699,7 @@ short2 lnor_space_custom_normal_to_data(const CornerNormalSpace &lnor_space,
float vec[3], cos_beta;
float alpha;
alpha = saacosf(cos_alpha);
alpha = math::safe_acos_approx(cos_alpha);
if (alpha > lnor_space.ref_alpha) {
/* Note we could stick to [0, pi] range here,
* but makes decoding more complex, not worth it. */
@@ -716,7 +717,7 @@ short2 lnor_space_custom_normal_to_data(const CornerNormalSpace &lnor_space,
cos_beta = dot_v3v3(lnor_space.vec_ref, vec);
if (cos_beta < LNOR_SPACE_TRIGO_THRESHOLD) {
float beta = saacosf(cos_beta);
float beta = math::safe_acos_approx(cos_beta);
if (dot_v3v3(lnor_space.vec_ortho, vec) < 0.0f) {
beta = pi2 - beta;
}
@@ -1097,7 +1098,8 @@ static void split_loop_nor_fan_do(LoopSplitTaskDataCommon *common_data,
/* Code similar to accumulate_vertex_normals_poly_v3. */
/* Calculate angle between the two face edges incident on this vertex. */
lnor += face_normals[loop_to_face[mlfan_curr_index]] * saacos(math::dot(vec_curr, vec_prev));
lnor += face_normals[loop_to_face[mlfan_curr_index]] *
math::safe_acos_approx(math::dot(vec_curr, vec_prev));
processed_corners.append(mlfan_vert_index);
+3 -3
View File
@@ -532,9 +532,9 @@ void multiresModifier_set_levels_from_disps(MultiresModifierData *mmd, Object *o
if (mdisp) {
mmd->totlvl = get_levels_from_disps(ob);
mmd->lvl = MIN2(mmd->sculptlvl, mmd->totlvl);
mmd->sculptlvl = MIN2(mmd->sculptlvl, mmd->totlvl);
mmd->renderlvl = MIN2(mmd->renderlvl, mmd->totlvl);
mmd->lvl = std::min(mmd->sculptlvl, mmd->totlvl);
mmd->sculptlvl = std::min(mmd->sculptlvl, mmd->totlvl);
mmd->renderlvl = std::min(mmd->renderlvl, mmd->totlvl);
}
}
+7 -7
View File
@@ -492,12 +492,12 @@ static ParticleCacheKey **psys_alloc_path_cache_buffers(ListBase *bufs, int tot,
ParticleCacheKey **cache;
int i, totkey, totbufkey;
tot = MAX2(tot, 1);
tot = std::max(tot, 1);
totkey = 0;
cache = static_cast<ParticleCacheKey **>(MEM_callocN(tot * sizeof(void *), "PathCacheArray"));
while (totkey < tot) {
totbufkey = MIN2(tot - totkey, PATH_CACHE_BUF_SIZE);
totbufkey = std::min(tot - totkey, PATH_CACHE_BUF_SIZE);
buf = static_cast<LinkData *>(MEM_callocN(sizeof(LinkData), "PathCacheLinkData"));
buf->data = MEM_callocN(sizeof(ParticleCacheKey) * totbufkey * totkeys, "ParticleCacheKey");
@@ -1309,8 +1309,8 @@ static void init_particle_interpolation(Object *ob,
pind->dietime = pa ? pa->dietime : (pind->cache->endframe + 1);
if (get_pointcache_times_for_particle(pind->cache, pa - psys->particles, &start, &dietime)) {
pind->birthtime = MAX2(pind->birthtime, start);
pind->dietime = MIN2(pind->dietime, dietime);
pind->birthtime = std::max(pind->birthtime, start);
pind->dietime = std::min(pind->dietime, dietime);
}
}
else {
@@ -3352,7 +3352,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
if (part->draw & PART_ABS_PATH_TIME) {
birthtime = MAX2(pind.birthtime, part->path_start);
dietime = MIN2(pind.dietime, part->path_end);
dietime = std::min(pind.dietime, part->path_end);
}
else {
float tb = pind.birthtime;
@@ -3674,7 +3674,7 @@ void psys_cache_edit_paths(Depsgraph *depsgraph,
return;
}
segments = MAX2(segments, 4);
segments = std::max(segments, 4);
if (!cache || edit->totpoint != edit->totcached) {
/* Clear out old and create new empty path cache. */
@@ -4934,7 +4934,7 @@ bool psys_get_particle_state(ParticleSimulationData *sim,
}
}
cfra = MIN2(cfra, pa->dietime);
cfra = std::min(cfra, pa->dietime);
}
if (sim->psys->flag & PSYS_KEYED) {
@@ -526,7 +526,7 @@ void do_kink(ParticleKey *state,
sub_v3_v3v3(par_vec, state->co, state_co);
length = normalize_v3(par_vec);
mul_v3_fl(par_vec, MIN2(length, amplitude / 2.0f));
mul_v3_fl(par_vec, std::min(length, amplitude / 2.0f));
add_v3_v3v3(state_co, par_co, y_vec);
add_v3_v3(state_co, z_vec);
@@ -128,11 +128,11 @@ static void distribute_grid(Mesh *mesh, ParticleSystem *psys)
/* float errors grrr. */
size[(axis + 1) % 3] = MIN2(size[(axis + 1) % 3], res);
size[(axis + 2) % 3] = MIN2(size[(axis + 2) % 3], res);
size[(axis + 2) % 3] = std::min(size[(axis + 2) % 3], res);
size[0] = MAX2(size[0], 1);
size[1] = MAX2(size[1], 1);
size[2] = MAX2(size[2], 1);
size[0] = std::max(size[0], 1);
size[1] = std::max(size[1], 1);
size[2] = std::max(size[2], 1);
/* no full offset for flat/thin objects */
min[0] += d < delta[0] ? d / 2.0f : delta[0] / 2.0f;
@@ -1132,7 +1132,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
(sim->psys->pointcache->mem_cache.first))
{
float dietime = psys_get_dietime_from_cache(sim->psys->pointcache, p);
pa->dietime = MIN2(pa->dietime, dietime);
pa->dietime = std::min(pa->dietime, dietime);
}
if (pa->time > cfra) {
@@ -3003,7 +3003,7 @@ static int collision_response(ParticleSimulationData *sim,
/* Convert to angular velocity. */
cross_v3_v3v3(ave, vr_tan, pce->nor);
mul_v3_fl(ave, 1.0f / MAX2(pa->size, 0.001f));
mul_v3_fl(ave, 1.0f / std::max(pa->size, 0.001f));
/* only friction will cause change in linear & angular velocity */
interp_v3_v3v3(pa->state.ave, pa->state.ave, ave, frict);
@@ -4688,8 +4688,8 @@ void psys_changed_type(Object *ob, ParticleSystem *psys)
else {
free_hair(ob, psys, 1);
CLAMP(part->path_start, 0.0f, MAX2(100.0f, part->end + part->lifetime));
CLAMP(part->path_end, 0.0f, MAX2(100.0f, part->end + part->lifetime));
CLAMP(part->path_start, 0.0f, std::max(100.0f, part->end + part->lifetime));
CLAMP(part->path_end, 0.0f, std::max(100.0f, part->end + part->lifetime));
}
psys_reset(psys, PSYS_RESET_ALL);
+10 -10
View File
@@ -410,8 +410,8 @@ static void ptcache_particle_interpolate(int index,
}
cfra = MIN2(cfra, pa->dietime);
cfra1 = MIN2(cfra1, pa->dietime);
cfra2 = MIN2(cfra2, pa->dietime);
cfra1 = std::min(cfra1, pa->dietime);
cfra2 = std::min(cfra2, pa->dietime);
if (cfra1 == cfra2) {
return;
@@ -2372,7 +2372,7 @@ int BKE_ptcache_read(PTCacheID *pid, float cfra, bool no_extrapolate_old)
pid->cache->flag &= ~PTCACHE_FRAMES_SKIPPED;
}
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, MAX2(cfrai, pid->cache->last_exact));
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_AFTER, std::max(cfrai, pid->cache->last_exact));
}
return ret;
@@ -2653,7 +2653,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, uint cfra)
if (strstr(de->d_name, ext)) { /* Do we have the right extension? */
if (STREQLEN(filepath, de->d_name, len)) { /* Do we have the right prefix. */
if (mode == PTCACHE_CLEAR_ALL) {
pid->cache->last_exact = MIN2(pid->cache->startframe, 0);
pid->cache->last_exact = std::min(pid->cache->startframe, 0);
BLI_path_join(path_full, sizeof(path_full), path, de->d_name);
BLI_delete(path_full, false, false);
}
@@ -2688,7 +2688,7 @@ void BKE_ptcache_id_clear(PTCacheID *pid, int mode, uint cfra)
if (mode == PTCACHE_CLEAR_ALL) {
/* We want startframe if the cache starts before zero. */
pid->cache->last_exact = MIN2(pid->cache->startframe, 0);
pid->cache->last_exact = std::min(pid->cache->startframe, 0);
for (; pm; pm = pm->next) {
ptcache_mem_clear(pm);
}
@@ -2803,7 +2803,7 @@ void BKE_ptcache_id_time(
time = BKE_scene_ctime_get(scene);
nexttime = BKE_scene_frame_to_ctime(scene, scene->r.cfra + 1);
*timescale = MAX2(nexttime - time, 0.0f);
*timescale = std::max(nexttime - time, 0.0f);
}
if (startframe && endframe) {
@@ -3219,7 +3219,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
BKE_ptcache_id_clear(pid, PTCACHE_CLEAR_ALL, 0);
}
startframe = MAX2(cache->last_exact, cache->startframe);
startframe = std::max(cache->last_exact, cache->startframe);
if (bake) {
endframe = cache->endframe;
@@ -3603,8 +3603,8 @@ void BKE_ptcache_load_external(PTCacheID *pid)
if (frame != -1) {
if (frame) {
start = MIN2(start, frame);
end = MAX2(end, frame);
start = std::min(start, frame);
end = std::max(end, frame);
}
else {
info = 1;
@@ -3774,7 +3774,7 @@ void BKE_ptcache_invalidate(PointCache *cache)
if (cache) {
cache->flag &= ~PTCACHE_SIMULATION_VALID;
cache->simframe = 0;
cache->last_exact = MIN2(cache->startframe, 0);
cache->last_exact = std::min(cache->startframe, 0);
}
}
@@ -501,7 +501,7 @@ static rbCollisionShape *rigidbody_validate_sim_shape_helper(RigidBodyWorld *rbw
if (ELEM(rbo->shape, RB_SHAPE_CAPSULE, RB_SHAPE_CYLINDER, RB_SHAPE_CONE)) {
/* take radius as largest x/y dimension, and height as z-dimension */
radius = MAX2(size[0], size[1]);
radius = std::max(size[0], size[1]);
height = size[2];
}
else if (rbo->shape == RB_SHAPE_SPHERE) {
@@ -97,7 +97,7 @@ static bool is_subdivision_evaluation_possible_on_gpu()
return false;
}
if (!(GPU_compute_shader_support())) {
if (!GPU_compute_shader_support()) {
return false;
}
@@ -94,7 +94,7 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int numLaye
int normalOffset = 0;
/* (subdivLevels == 0) is not allowed */
subdivLevels = MAX2(subdivLevels, 1);
subdivLevels = std::max(subdivLevels, 1);
if (prevSS) {
int oldUseAging;
+2 -2
View File
@@ -2113,7 +2113,7 @@ static bool txt_select_unprefix(Text *text, const char *remove, const bool requi
if (text->curl == text->sell) {
if (changed) {
text->selc = MAX2(text->selc - indentlen, 0);
text->selc = std::max(text->selc - indentlen, 0);
}
break;
}
@@ -2123,7 +2123,7 @@ static bool txt_select_unprefix(Text *text, const char *remove, const bool requi
}
if (unindented_first) {
text->curc = MAX2(text->curc - indentlen, 0);
text->curc = std::max(text->curc - indentlen, 0);
}
while (num > 0) {
+5 -4
View File
@@ -6,6 +6,7 @@
* \ingroup bke
*/
#include <algorithm> /* For `min/max`. */
#include <cctype>
#include <cstdio>
#include <cstdlib>
@@ -1673,17 +1674,17 @@ static const bUnitDef *get_preferred_display_unit_if_used(int type, PreferredUni
if (units.length == USER_UNIT_ADAPTIVE) {
return nullptr;
}
return usys->units + MIN2(units.length, max_offset);
return usys->units + std::min(units.length, max_offset);
case B_UNIT_MASS:
if (units.mass == USER_UNIT_ADAPTIVE) {
return nullptr;
}
return usys->units + MIN2(units.mass, max_offset);
return usys->units + std::min(units.mass, max_offset);
case B_UNIT_TIME:
if (units.time == USER_UNIT_ADAPTIVE) {
return nullptr;
}
return usys->units + MIN2(units.time, max_offset);
return usys->units + std::min(units.time, max_offset);
case B_UNIT_ROTATION:
if (units.rotation == 0) {
return usys->units + 0;
@@ -1696,7 +1697,7 @@ static const bUnitDef *get_preferred_display_unit_if_used(int type, PreferredUni
if (units.temperature == USER_UNIT_ADAPTIVE) {
return nullptr;
}
return usys->units + MIN2(units.temperature, max_offset);
return usys->units + std::min(units.temperature, max_offset);
default:
break;
}
+18
View File
@@ -192,6 +192,24 @@ template<typename T> inline T safe_acos(const T &a)
return math::acos((a));
}
/* Faster/approximate version of acosf. Max error 4.51803e-5 (0.00258 degrees).*/
inline float safe_acos_approx(float x)
{
const float f = fabsf(x);
/* clamp and crush denormals. */
const float m = (f < 1.0f) ? 1.0f - (1.0f - f) : 1.0f;
/* Based on http://www.pouet.net/topic.php?which=9132&page=2
* 85% accurate (ULP 0)
* Examined 2130706434 values of acos:
* 15.2000597 avg ULP diff, 4492 max ULP, 4.51803e-05 max error // without "denormal crush"
* Examined 2130706434 values of acos:
* 15.2007108 avg ULP diff, 4492 max ULP, 4.51803e-05 max error // with "denormal crush"
*/
const float a = sqrtf(1.0f - m) *
(1.5707963267f + m * (-0.213300989f + m * (0.077980478f + m * -0.02164095f)));
return x < 0 ? (float)M_PI - a : a;
}
template<typename T> inline T asin(const T &a)
{
return std::asin(a);
+2 -8
View File
@@ -788,14 +788,8 @@ bool isect_ray_line_v3(const float ray_origin[3],
/* Point in polygon. */
bool isect_point_poly_v2(const float pt[2],
const float verts[][2],
unsigned int nr,
bool use_holes);
bool isect_point_poly_v2_int(const int pt[2],
const int verts[][2],
unsigned int nr,
bool use_holes);
bool isect_point_poly_v2(const float pt[2], const float verts[][2], unsigned int nr);
bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], unsigned int nr);
/**
* Point in quad - only convex quads.
+1 -1
View File
@@ -101,7 +101,7 @@ set(SRC
intern/math_color.c
intern/math_color_blend_inline.c
intern/math_color_inline.c
intern/math_geom.c
intern/math_geom.cc
intern/math_geom_inline.c
intern/math_interp.c
intern/math_matrix.c
+23 -23
View File
@@ -48,7 +48,7 @@
* Ordering function for sorting lists of files/directories. Returns -1 if
* entry1 belongs before entry2, 0 if they are equal, 1 if they should be swapped.
*/
static int direntry_cmp(struct direntry *entry1, struct direntry *entry2)
static int direntry_cmp(direntry *entry1, direntry *entry2)
{
/* type is equal to stat.st_mode */
@@ -101,14 +101,14 @@ static int direntry_cmp(struct direntry *entry1, struct direntry *entry2)
}
struct BuildDirCtx {
struct direntry *files; /* array[files_num] */
direntry *files; /* array[files_num] */
int files_num;
};
/**
* Scans the directory named *dirname and appends entries for its contents to files.
*/
static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
static void bli_builddir(BuildDirCtx *dir_ctx, const char *dirname)
{
DIR *dir = opendir(dirname);
if (UNLIKELY(dir == nullptr)) {
@@ -121,7 +121,7 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
ListBase dirbase = {nullptr, nullptr};
int newnum = 0;
const struct dirent *fname;
const dirent *fname;
bool has_current = false, has_parent = false;
char dirname_with_slash[FILE_MAXDIR + 1];
@@ -136,7 +136,7 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
}
while ((fname = readdir(dir)) != nullptr) {
struct dirlink *const dlink = (struct dirlink *)malloc(sizeof(dirlink));
dirlink *const dlink = (dirlink *)malloc(sizeof(dirlink));
if (dlink != nullptr) {
dlink->name = BLI_strdup(fname->d_name);
if (FILENAME_IS_PARENT(dlink->name)) {
@@ -155,7 +155,7 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
STRNCPY(pardir, dirname);
if (BLI_path_parent_dir(pardir) && (BLI_access(pardir, R_OK) == 0)) {
struct dirlink *const dlink = (struct dirlink *)malloc(sizeof(dirlink));
dirlink *const dlink = (dirlink *)malloc(sizeof(dirlink));
if (dlink != nullptr) {
dlink->name = BLI_strdup(FILENAME_PARENT);
BLI_addhead(&dirbase, dlink);
@@ -164,7 +164,7 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
}
}
if (!has_current) {
struct dirlink *const dlink = (struct dirlink *)malloc(sizeof(dirlink));
dirlink *const dlink = (dirlink *)malloc(sizeof(dirlink));
if (dlink != nullptr) {
dlink->name = BLI_strdup(FILENAME_CURRENT);
BLI_addhead(&dirbase, dlink);
@@ -186,7 +186,7 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
}
if (dir_ctx->files == nullptr) {
dir_ctx->files = (struct direntry *)MEM_mallocN(newnum * sizeof(direntry), __func__);
dir_ctx->files = (direntry *)MEM_mallocN(newnum * sizeof(direntry), __func__);
}
if (UNLIKELY(dir_ctx->files == nullptr)) {
@@ -194,8 +194,8 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
dir_ctx->files_num = 0;
}
else {
struct dirlink *dlink = (dirlink *)dirbase.first;
struct direntry *file = &dir_ctx->files[dir_ctx->files_num];
dirlink *dlink = (dirlink *)dirbase.first;
direntry *file = &dir_ctx->files[dir_ctx->files_num];
while (dlink) {
memset(file, 0, sizeof(direntry));
@@ -226,9 +226,9 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname)
closedir(dir);
}
uint BLI_filelist_dir_contents(const char *dirname, struct direntry **r_filelist)
uint BLI_filelist_dir_contents(const char *dirname, direntry **r_filelist)
{
struct BuildDirCtx dir_ctx;
BuildDirCtx dir_ctx;
dir_ctx.files_num = 0;
dir_ctx.files = nullptr;
@@ -322,7 +322,7 @@ void BLI_filelist_entry_owner_to_string(const struct stat *st,
UNUSED_VARS(st);
BLI_strncpy(r_owner, "unknown", FILELIST_DIRENTRY_OWNER_LEN);
#else
struct passwd *pwuser = getpwuid(st->st_uid);
passwd *pwuser = getpwuid(st->st_uid);
if (pwuser) {
BLI_strncpy(r_owner, pwuser->pw_name, sizeof(*r_owner) * FILELIST_DIRENTRY_OWNER_LEN);
@@ -348,8 +348,8 @@ void BLI_filelist_entry_datetime_to_string(const struct stat *st,
if (r_is_today || r_is_yesterday) {
/* `localtime()` has only one buffer so need to get data out before called again. */
const time_t ts_now = time(NULL);
struct tm *today = localtime(&ts_now);
const time_t ts_now = time(nullptr);
tm *today = localtime(&ts_now);
today_year = today->tm_year;
today_yday = today->tm_yday;
@@ -368,7 +368,7 @@ void BLI_filelist_entry_datetime_to_string(const struct stat *st,
}
const time_t ts_mtime = ts;
const struct tm *tm = localtime(st ? &st->st_mtime : &ts_mtime);
const tm *tm = localtime(st ? &st->st_mtime : &ts_mtime);
const time_t zero = 0;
/* Prevent impossible dates in windows. */
@@ -395,7 +395,7 @@ void BLI_filelist_entry_datetime_to_string(const struct stat *st,
}
}
void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *src)
void BLI_filelist_entry_duplicate(direntry *dst, const direntry *src)
{
*dst = *src;
if (dst->relname) {
@@ -406,8 +406,8 @@ void BLI_filelist_entry_duplicate(struct direntry *dst, const struct direntry *s
}
}
void BLI_filelist_duplicate(struct direntry **dest_filelist,
struct direntry *const src_filelist,
void BLI_filelist_duplicate(direntry **dest_filelist,
direntry *const src_filelist,
const uint nrentries)
{
uint i;
@@ -415,13 +415,13 @@ void BLI_filelist_duplicate(struct direntry **dest_filelist,
*dest_filelist = static_cast<direntry *>(
MEM_mallocN(sizeof(**dest_filelist) * size_t(nrentries), __func__));
for (i = 0; i < nrentries; i++) {
struct direntry *const src = &src_filelist[i];
struct direntry *dst = &(*dest_filelist)[i];
direntry *const src = &src_filelist[i];
direntry *dst = &(*dest_filelist)[i];
BLI_filelist_entry_duplicate(dst, src);
}
}
void BLI_filelist_entry_free(struct direntry *entry)
void BLI_filelist_entry_free(direntry *entry)
{
if (entry->relname) {
MEM_freeN((void *)entry->relname);
@@ -431,7 +431,7 @@ void BLI_filelist_entry_free(struct direntry *entry)
}
}
void BLI_filelist_free(struct direntry *filelist, const uint nrentries)
void BLI_filelist_free(direntry *filelist, const uint nrentries)
{
uint i;
for (i = 0; i < nrentries; i++) {
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+6 -6
View File
@@ -862,9 +862,9 @@ static int recursive_operation(const char *startfrom,
RecursiveOp_Callback callback_dir_post)
{
struct stat st;
char *from = NULL, *to = nullptr;
char *from_path = NULL, *to_path = nullptr;
struct dirent **dirlist = nullptr;
char *from = nullptr, *to = nullptr;
char *from_path = nullptr, *to_path = nullptr;
dirent **dirlist = nullptr;
size_t from_alloc_len = -1, to_alloc_len = -1;
int i, n = 0, ret = 0;
@@ -916,7 +916,7 @@ static int recursive_operation(const char *startfrom,
}
for (i = 0; i < n; i++) {
const struct dirent *const dirent = dirlist[i];
const dirent *const dirent = dirlist[i];
if (FILENAME_IS_CURRPAR(dirent->d_name)) {
continue;
@@ -1062,8 +1062,8 @@ static int delete_soft(const char *file, const char **error_message)
char *xdg_current_desktop = getenv("XDG_CURRENT_DESKTOP");
char *xdg_session_desktop = getenv("XDG_SESSION_DESKTOP");
if ((xdg_current_desktop != NULL && STREQ(xdg_current_desktop, "KDE")) ||
(xdg_session_desktop != NULL && STREQ(xdg_session_desktop, "KDE")))
if ((xdg_current_desktop != nullptr && STREQ(xdg_current_desktop, "KDE")) ||
(xdg_session_desktop != nullptr && STREQ(xdg_session_desktop, "KDE")))
{
args[0] = "kioclient5";
args[1] = "move";
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+1 -1
View File
@@ -48,7 +48,7 @@ bool BLI_lasso_is_point_inside(const int mcoords[][2],
}
const int pt[2] = {sx, sy};
return isect_point_poly_v2_int(pt, mcoords, mcoords_len, true);
return isect_point_poly_v2_int(pt, mcoords, mcoords_len);
}
bool BLI_lasso_is_edge_inside(const int mcoords[][2],
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -6,11 +6,11 @@
* \ingroup bli
*/
#include "BLI_array.hh"
#include "BLI_math_base.h"
#include "BLI_math_base.hh"
#include "BLI_math_geom.h"
#include "MEM_guardedalloc.h"
#include "BLI_math_bits.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
@@ -654,7 +654,7 @@ void aabb_get_near_far_from_plane(const float plane_no[3],
/** \name dist_squared_to_ray_to_aabb and helpers
* \{ */
void dist_squared_ray_to_aabb_v3_precalc(struct DistRayAABB_Precalc *neasrest_precalc,
void dist_squared_ray_to_aabb_v3_precalc(DistRayAABB_Precalc *neasrest_precalc,
const float ray_origin[3],
const float ray_direction[3])
{
@@ -668,7 +668,7 @@ void dist_squared_ray_to_aabb_v3_precalc(struct DistRayAABB_Precalc *neasrest_pr
}
}
float dist_squared_ray_to_aabb_v3(const struct DistRayAABB_Precalc *data,
float dist_squared_ray_to_aabb_v3(const DistRayAABB_Precalc *data,
const float bb_min[3],
const float bb_max[3],
float r_point[3],
@@ -764,7 +764,7 @@ float dist_squared_ray_to_aabb_v3_simple(const float ray_origin[3],
float r_point[3],
float *r_depth)
{
struct DistRayAABB_Precalc data;
DistRayAABB_Precalc data;
dist_squared_ray_to_aabb_v3_precalc(&data, ray_origin, ray_direction);
return dist_squared_ray_to_aabb_v3(&data, bb_min, bb_max, r_point, r_depth);
}
@@ -775,7 +775,7 @@ float dist_squared_ray_to_aabb_v3_simple(const float ray_origin[3],
/** \name dist_squared_to_projected_aabb and helpers
* \{ */
void dist_squared_to_projected_aabb_precalc(struct DistProjectedAABBPrecalc *precalc,
void dist_squared_to_projected_aabb_precalc(DistProjectedAABBPrecalc *precalc,
const float projmat[4][4],
const float winsize[2],
const float mval[2])
@@ -827,7 +827,7 @@ void dist_squared_to_projected_aabb_precalc(struct DistProjectedAABBPrecalc *pre
}
}
float dist_squared_to_projected_aabb(struct DistProjectedAABBPrecalc *data,
float dist_squared_to_projected_aabb(DistProjectedAABBPrecalc *data,
const float bbmin[3],
const float bbmax[3],
bool r_axis_closest[3])
@@ -963,7 +963,7 @@ float dist_squared_to_projected_aabb_simple(const float projmat[4][4],
const float bbmin[3],
const float bbmax[3])
{
struct DistProjectedAABBPrecalc data;
DistProjectedAABBPrecalc data;
dist_squared_to_projected_aabb_precalc(&data, projmat, winsize, mval);
bool dummy[3] = {true, true, true};
@@ -1071,14 +1071,14 @@ int isect_seg_seg_v2_int(const int v1[2], const int v2[2], const int v3[2], cons
{
float div, lambda, mu;
div = (float)((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]));
div = float((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]));
if (div == 0.0f) {
return ISECT_LINE_LINE_COLINEAR;
}
lambda = (float)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
lambda = float((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
mu = (float)((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
mu = float((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
if (lambda >= 0.0f && lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) {
@@ -1121,9 +1121,9 @@ int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], co
return ISECT_LINE_LINE_COLINEAR;
}
lambda = ((float)(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
lambda = (float(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div;
mu = ((float)(v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
mu = (float(v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div;
if (lambda >= 0.0f && lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) {
if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) {
@@ -1360,16 +1360,14 @@ int isect_line_sphere_v3(const float l1[3],
float r_p1[3],
float r_p2[3])
{
/* adapted for use in blender by Campbell Barton - 2011
/* Adapted for use in blender by Campbell Barton, 2011.
*
* atelier iebele abel - 2001
* <atelier@iebele.nl>
* http://www.iebele.nl
* `Atelier Iebele Abel <atelier@iebele.nl>` - 2001.
*
* sphere_line_intersection function adapted from:
* http://astronomy.swin.edu.au/pbourke/geometry/sphereline
* Paul Bourke <pbourke@swin.edu.au>
*/
* `Paul Bourke <pbourke@swin.edu.au>`. */
const float ldir[3] = {
l2[0] - l1[0],
@@ -1463,10 +1461,7 @@ int isect_line_sphere_v2(const float l1[2],
return -1;
}
bool isect_point_poly_v2(const float pt[2],
const float verts[][2],
const uint nr,
const bool UNUSED(use_holes))
bool isect_point_poly_v2(const float pt[2], const float verts[][2], const uint nr)
{
/* Keep in sync with #isect_point_poly_v2_int. */
@@ -1483,10 +1478,7 @@ bool isect_point_poly_v2(const float pt[2],
}
return isect;
}
bool isect_point_poly_v2_int(const int pt[2],
const int verts[][2],
const uint nr,
const bool UNUSED(use_holes))
bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const uint nr)
{
/* Keep in sync with #isect_point_poly_v2. */
@@ -1790,7 +1782,7 @@ bool isect_ray_tri_epsilon_v3(const float ray_origin[3],
return true;
}
void isect_ray_tri_watertight_v3_precalc(struct IsectRayPrecalc *isect_precalc,
void isect_ray_tri_watertight_v3_precalc(IsectRayPrecalc *isect_precalc,
const float ray_direction[3])
{
float inv_dir_z;
@@ -1818,7 +1810,7 @@ void isect_ray_tri_watertight_v3_precalc(struct IsectRayPrecalc *isect_precalc,
}
bool isect_ray_tri_watertight_v3(const float ray_origin[3],
const struct IsectRayPrecalc *isect_precalc,
const IsectRayPrecalc *isect_precalc,
const float v0[3],
const float v1[3],
const float v2[3],
@@ -1868,7 +1860,7 @@ bool isect_ray_tri_watertight_v3(const float ray_origin[3],
/* Calculate scaled z-coordinates of vertices and use them to calculate
* the hit distance.
*/
const int sign_det = (float_as_int(det) & (int)0x80000000);
const int sign_det = (float_as_int(det) & int(0x80000000));
const float t = (u * a_kz + v * b_kz + w * c_kz) * sz;
const float sign_t = xor_fl(t, sign_det);
if ((sign_t < 0.0f)
@@ -1901,7 +1893,7 @@ bool isect_ray_tri_watertight_v3_simple(const float ray_origin[3],
float *r_lambda,
float r_uv[2])
{
struct IsectRayPrecalc isect_precalc;
IsectRayPrecalc isect_precalc;
isect_ray_tri_watertight_v3_precalc(&isect_precalc, ray_direction);
return isect_ray_tri_watertight_v3(ray_origin, &isect_precalc, v0, v1, v2, r_lambda, r_uv);
}
@@ -2259,9 +2251,9 @@ bool isect_tri_tri_v3_ex(const float tri_a[3][3],
sub_v3db_v3fl_v3fl(bc, tri_a[2], tri_a[1]);
cross_v3_v3v3_db(plane_a, ba, bc);
plane_a[3] = -dot_v3db_v3fl(plane_a, tri_a[1]);
side[1][0] = (float)(dot_v3db_v3fl(plane_a, tri_b[0]) + plane_a[3]);
side[1][1] = (float)(dot_v3db_v3fl(plane_a, tri_b[1]) + plane_a[3]);
side[1][2] = (float)(dot_v3db_v3fl(plane_a, tri_b[2]) + plane_a[3]);
side[1][0] = float(dot_v3db_v3fl(plane_a, tri_b[0]) + plane_a[3]);
side[1][1] = float(dot_v3db_v3fl(plane_a, tri_b[1]) + plane_a[3]);
side[1][2] = float(dot_v3db_v3fl(plane_a, tri_b[2]) + plane_a[3]);
if (!side[1][0] && !side[1][1] && !side[1][2]) {
/* Coplanar case is not supported. */
@@ -2280,9 +2272,9 @@ bool isect_tri_tri_v3_ex(const float tri_a[3][3],
sub_v3db_v3fl_v3fl(bc, tri_b[2], tri_b[1]);
cross_v3_v3v3_db(plane_b, ba, bc);
plane_b[3] = -dot_v3db_v3fl(plane_b, tri_b[1]);
side[0][0] = (float)(dot_v3db_v3fl(plane_b, tri_a[0]) + plane_b[3]);
side[0][1] = (float)(dot_v3db_v3fl(plane_b, tri_a[1]) + plane_b[3]);
side[0][2] = (float)(dot_v3db_v3fl(plane_b, tri_a[2]) + plane_b[3]);
side[0][0] = float(dot_v3db_v3fl(plane_b, tri_a[0]) + plane_b[3]);
side[0][1] = float(dot_v3db_v3fl(plane_b, tri_a[1]) + plane_b[3]);
side[0][2] = float(dot_v3db_v3fl(plane_b, tri_a[2]) + plane_b[3]);
if ((side[0][0] && side[0][1] && side[0][2]) && (side[0][0] < 0.0f) == (side[0][1] < 0.0f) &&
(side[0][0] < 0.0f) == (side[0][2] < 0.0f))
@@ -2332,13 +2324,13 @@ bool isect_tri_tri_v3_ex(const float tri_a[3][3],
SWAP(int, tri_i[0], tri_i[2]);
}
range[i].min = (float)(dot_b + offset0);
range[i].max = (float)(dot_b + offset1);
range[i].min = float(dot_b + offset0);
range[i].max = float(dot_b + offset1);
interp_v3_v3v3(range[i].loc[0], tri[tri_i[1]], tri[tri_i[0]], fac0);
interp_v3_v3v3(range[i].loc[1], tri[tri_i[1]], tri[tri_i[2]], fac1);
}
else {
range[i].min = range[i].max = (float)dot_b;
range[i].min = range[i].max = float(dot_b);
copy_v3_v3(range[i].loc[0], tri[tri_i[1]]);
copy_v3_v3(range[i].loc[1], tri[tri_i[1]]);
}
@@ -3028,12 +3020,12 @@ bool isect_ray_ray_epsilon_v3(const float ray_origin_a[3],
sub_v3_v3v3(t, ray_origin_b, ray_origin_a);
sub_v3_v3v3(c, n, t);
if (r_lambda_a != NULL) {
if (r_lambda_a != nullptr) {
cross_v3_v3v3(cray, c, ray_direction_b);
*r_lambda_a = dot_v3v3(cray, n) / nlen;
}
if (r_lambda_b != NULL) {
if (r_lambda_b != nullptr) {
cross_v3_v3v3(cray, c, ray_direction_a);
*r_lambda_b = dot_v3v3(cray, n) / nlen;
}
@@ -3066,7 +3058,7 @@ bool isect_aabb_aabb_v3(const float min1[3],
min2[1] < max1[1] && min2[2] < max1[2]);
}
void isect_ray_aabb_v3_precalc(struct IsectRayAABB_Precalc *data,
void isect_ray_aabb_v3_precalc(IsectRayAABB_Precalc *data,
const float ray_origin[3],
const float ray_direction[3])
{
@@ -3081,7 +3073,7 @@ void isect_ray_aabb_v3_precalc(struct IsectRayAABB_Precalc *data,
data->sign[2] = data->ray_inv_dir[2] < 0.0f;
}
bool isect_ray_aabb_v3(const struct IsectRayAABB_Precalc *data,
bool isect_ray_aabb_v3(const IsectRayAABB_Precalc *data,
const float bb_min[3],
const float bb_max[3],
float *tmin_out)
@@ -3142,17 +3134,17 @@ bool isect_ray_aabb_v3_simple(const float orig[3],
{
double t[6];
float hit_dist[2];
const double invdirx = (dir[0] > 1e-35f || dir[0] < -1e-35f) ? 1.0 / (double)dir[0] : DBL_MAX;
const double invdiry = (dir[1] > 1e-35f || dir[1] < -1e-35f) ? 1.0 / (double)dir[1] : DBL_MAX;
const double invdirz = (dir[2] > 1e-35f || dir[2] < -1e-35f) ? 1.0 / (double)dir[2] : DBL_MAX;
t[0] = (double)(bb_min[0] - orig[0]) * invdirx;
t[1] = (double)(bb_max[0] - orig[0]) * invdirx;
t[2] = (double)(bb_min[1] - orig[1]) * invdiry;
t[3] = (double)(bb_max[1] - orig[1]) * invdiry;
t[4] = (double)(bb_min[2] - orig[2]) * invdirz;
t[5] = (double)(bb_max[2] - orig[2]) * invdirz;
hit_dist[0] = (float)fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5]));
hit_dist[1] = (float)fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5]));
const double invdirx = (dir[0] > 1e-35f || dir[0] < -1e-35f) ? 1.0 / double(dir[0]) : DBL_MAX;
const double invdiry = (dir[1] > 1e-35f || dir[1] < -1e-35f) ? 1.0 / double(dir[1]) : DBL_MAX;
const double invdirz = (dir[2] > 1e-35f || dir[2] < -1e-35f) ? 1.0 / double(dir[2]) : DBL_MAX;
t[0] = double(bb_min[0] - orig[0]) * invdirx;
t[1] = double(bb_max[0] - orig[0]) * invdirx;
t[2] = double(bb_min[1] - orig[1]) * invdiry;
t[3] = double(bb_max[1] - orig[1]) * invdiry;
t[4] = double(bb_min[2] - orig[2]) * invdirz;
t[5] = double(bb_max[2] - orig[2]) * invdirz;
hit_dist[0] = float(fmax(fmax(fmin(t[0], t[1]), fmin(t[2], t[3])), fmin(t[4], t[5])));
hit_dist[1] = float(fmin(fmin(fmax(t[0], t[1]), fmax(t[2], t[3])), fmax(t[4], t[5])));
if ((hit_dist[1] < 0.0f) || (hit_dist[0] > hit_dist[1])) {
return false;
}
@@ -3323,17 +3315,17 @@ int isect_point_tri_v2_int(
{
float v1[2], v2[2], v3[2], p[2];
v1[0] = (float)x1;
v1[1] = (float)y1;
v1[0] = float(x1);
v1[1] = float(y1);
v2[0] = (float)x1;
v2[1] = (float)y2;
v2[0] = float(x1);
v2[1] = float(y2);
v3[0] = (float)x2;
v3[1] = (float)y1;
v3[0] = float(x2);
v3[1] = float(y1);
p[0] = (float)a;
p[1] = (float)b;
p[0] = float(a);
p[1] = float(b);
return isect_point_tri_v2(p, v1, v2, v3);
}
@@ -3953,11 +3945,11 @@ int interp_sparse_array(float *array, const int list_size, const float skipval)
float valid_last = skipval;
int valid_ofs = 0;
float *array_up = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up");
float *array_down = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up");
blender::Array<float> array_up(list_size);
blender::Array<float> array_down(list_size);
int *ofs_tot_up = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tup");
int *ofs_tot_down = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tdown");
blender::Array<int> ofs_tot_up(list_size);
blender::Array<int> ofs_tot_down(list_size);
for (i = 0; i < list_size; i++) {
if (array[i] == skipval) {
@@ -3988,9 +3980,9 @@ int interp_sparse_array(float *array, const int list_size, const float skipval)
for (i = 0; i < list_size; i++) {
if (array[i] == skipval) {
if (array_up[i] != skipval && array_down[i] != skipval) {
array[i] = ((array_up[i] * (float)ofs_tot_down[i]) +
(array_down[i] * (float)ofs_tot_up[i])) /
(float)(ofs_tot_down[i] + ofs_tot_up[i]);
array[i] = ((array_up[i] * float(ofs_tot_down[i])) +
(array_down[i] * float(ofs_tot_up[i]))) /
float(ofs_tot_down[i] + ofs_tot_up[i]);
}
else if (array_up[i] != skipval) {
array[i] = array_up[i];
@@ -4001,12 +3993,6 @@ int interp_sparse_array(float *array, const int list_size, const float skipval)
}
}
MEM_freeN(array_up);
MEM_freeN(array_down);
MEM_freeN(ofs_tot_up);
MEM_freeN(ofs_tot_down);
return 1;
}
@@ -4041,8 +4027,7 @@ struct Double2_Len {
/* Mean value weights - smooth interpolation weights for polygons with
* more than 3 vertices */
static float mean_value_half_tan_v3(const struct Float3_Len *d_curr,
const struct Float3_Len *d_next)
static float mean_value_half_tan_v3(const Float3_Len *d_curr, const Float3_Len *d_next)
{
float cross[3];
cross_v3_v3v3(cross, d_curr->dir, d_next->dir);
@@ -4068,8 +4053,7 @@ static float mean_value_half_tan_v3(const struct Float3_Len *d_curr,
* do not indicate a point "inside" the polygon.
* To resolve this, doubles are used.
*/
static double mean_value_half_tan_v2_db(const struct Double2_Len *d_curr,
const struct Double2_Len *d_next)
static double mean_value_half_tan_v2_db(const Double2_Len *d_curr, const Double2_Len *d_next)
{
/* Different from the 3d version but still correct. */
const double area = cross_v2v2_db(d_curr->dir, d_next->dir);
@@ -4106,7 +4090,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[
float totweight = 0.0f;
int i_curr, i_next;
char ix_flag = 0;
struct Float3_Len d_curr, d_next;
Float3_Len d_curr, d_next;
/* loop over 'i_next' */
i_curr = n - 1;
@@ -4149,7 +4133,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[
}
if (ix_flag) {
memset(w, 0, sizeof(*w) * (size_t)n);
memset(w, 0, sizeof(*w) * size_t(n));
if (ix_flag & IS_POINT_IX) {
w[i_curr] = 1.0f;
@@ -4191,7 +4175,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
float totweight = 0.0f;
int i_curr, i_next;
char ix_flag = 0;
struct Double2_Len d_curr, d_next;
Double2_Len d_curr, d_next;
/* loop over 'i_next' */
i_curr = n - 1;
@@ -4222,7 +4206,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
d_curr = d_next;
DIR_V2_SET(&d_next, v_next, co);
ht = mean_value_half_tan_v2_db(&d_curr, &d_next);
w[i_curr] = (d_curr.len == 0.0) ? 0.0f : (float)((ht_prev + ht) / d_curr.len);
w[i_curr] = (d_curr.len == 0.0) ? 0.0f : float((ht_prev + ht) / d_curr.len);
totweight += w[i_curr];
/* step */
@@ -4234,7 +4218,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[
}
if (ix_flag) {
memset(w, 0, sizeof(*w) * (size_t)n);
memset(w, 0, sizeof(*w) * size_t(n));
if (ix_flag & IS_POINT_IX) {
w[i_curr] = 1.0f;
@@ -4312,8 +4296,8 @@ void resolve_tri_uv_v2(
if (IS_ZERO(det) == 0) {
const double x[2] = {st[0] - st2[0], st[1] - st2[1]};
r_uv[0] = (float)((d * x[0] - b * x[1]) / det);
r_uv[1] = (float)(((-c) * x[0] + a * x[1]) / det);
r_uv[0] = float((d * x[0] - b * x[1]) / det);
r_uv[1] = float(((-c) * x[0] + a * x[1]) / det);
}
else {
zero_v2(r_uv);
@@ -4342,8 +4326,8 @@ void resolve_tri_uv_v3(
if (IS_ZERO(det) == 0) {
float w;
w = (float)((d00 * d21 - d01 * d20) / det);
r_uv[1] = (float)((d11 * d20 - d01 * d21) / det);
w = float((d00 * d21 - d01 * d20) / det);
r_uv[1] = float((d11 * d20 - d01 * d21) / det);
r_uv[0] = 1.0f - r_uv[1] - w;
}
else {
@@ -4358,7 +4342,7 @@ void resolve_quad_uv_v2(float r_uv[2],
const float st2[2],
const float st3[2])
{
resolve_quad_uv_v2_deriv(r_uv, NULL, st, st0, st1, st2, st3);
resolve_quad_uv_v2_deriv(r_uv, nullptr, st, st0, st1, st2, st3);
}
void resolve_quad_uv_v2_deriv(float r_uv[2],
@@ -4379,10 +4363,9 @@ void resolve_quad_uv_v2_deriv(float r_uv[2],
const double a = (st0[0] - st[0]) * (st0[1] - st3[1]) - (st0[1] - st[1]) * (st0[0] - st3[0]);
/* B = ( (p0 - p) X (p1 - p2) + (p1 - p) X (p0 - p3) ) / 2 */
const double b = 0.5 * (double)(((st0[0] - st[0]) * (st1[1] - st2[1]) -
(st0[1] - st[1]) * (st1[0] - st2[0])) +
((st1[0] - st[0]) * (st0[1] - st3[1]) -
(st1[1] - st[1]) * (st0[0] - st3[0])));
const double b =
0.5 * double(((st0[0] - st[0]) * (st1[1] - st2[1]) - (st0[1] - st[1]) * (st1[0] - st2[0])) +
((st1[0] - st[0]) * (st0[1] - st3[1]) - (st1[1] - st[1]) * (st0[0] - st3[0])));
/* C = (p1-p) X (p1-p2) */
const double fC = (st1[0] - st[0]) * (st1[1] - st2[1]) - (st1[1] - st[1]) * (st1[0] - st2[0]);
@@ -4394,7 +4377,7 @@ void resolve_quad_uv_v2_deriv(float r_uv[2],
if (IS_ZERO(denom) != 0) {
const double fDen = a - fC;
if (IS_ZERO(fDen) == 0) {
r_uv[0] = (float)(a / fDen);
r_uv[0] = float(a / fDen);
}
}
else {
@@ -4402,7 +4385,7 @@ void resolve_quad_uv_v2_deriv(float r_uv[2],
const double desc = sqrt(desc_sq < 0.0 ? 0.0 : desc_sq);
const double s = signed_area > 0 ? (-1.0) : 1.0;
r_uv[0] = (float)(((a - b) + s * desc) / denom);
r_uv[0] = float(((a - b) + s * desc) / denom);
}
/* find UV such that
@@ -4419,9 +4402,8 @@ void resolve_quad_uv_v2_deriv(float r_uv[2],
}
if (IS_ZERO(denom) == 0) {
r_uv[1] = (float)((double)((1.0f - r_uv[0]) * (st0[i] - st[i]) +
r_uv[0] * (st1[i] - st[i])) /
denom);
r_uv[1] = float(double((1.0f - r_uv[0]) * (st0[i] - st[i]) + r_uv[0] * (st1[i] - st[i])) /
denom);
}
}
@@ -4443,10 +4425,10 @@ void resolve_quad_uv_v2_deriv(float r_uv[2],
if (!IS_ZERO(denom)) {
double inv_denom = 1.0 / denom;
r_deriv[0][0] = (float)((double)-t[1] * inv_denom);
r_deriv[0][1] = (float)((double)t[0] * inv_denom);
r_deriv[1][0] = (float)((double)s[1] * inv_denom);
r_deriv[1][1] = (float)((double)-s[0] * inv_denom);
r_deriv[0][0] = float(double(-t[1]) * inv_denom);
r_deriv[0][1] = float(double(t[0]) * inv_denom);
r_deriv[1][0] = float(double(s[1]) * inv_denom);
r_deriv[1][1] = float(double(-s[0]) * inv_denom);
}
}
}
@@ -4467,10 +4449,9 @@ float resolve_quad_u_v2(const float st[2],
const double a = (st0[0] - st[0]) * (st0[1] - st3[1]) - (st0[1] - st[1]) * (st0[0] - st3[0]);
/* B = ( (p0 - p) X (p1 - p2) + (p1 - p) X (p0 - p3) ) / 2 */
const double b = 0.5 * (double)(((st0[0] - st[0]) * (st1[1] - st2[1]) -
(st0[1] - st[1]) * (st1[0] - st2[0])) +
((st1[0] - st[0]) * (st0[1] - st3[1]) -
(st1[1] - st[1]) * (st0[0] - st3[0])));
const double b =
0.5 * double(((st0[0] - st[0]) * (st1[1] - st2[1]) - (st0[1] - st[1]) * (st1[0] - st2[0])) +
((st1[0] - st[0]) * (st0[1] - st3[1]) - (st1[1] - st[1]) * (st0[0] - st3[0])));
/* C = (p1-p) X (p1-p2) */
const double fC = (st1[0] - st[0]) * (st1[1] - st2[1]) - (st1[1] - st[1]) * (st1[0] - st2[0]);
@@ -4479,7 +4460,7 @@ float resolve_quad_u_v2(const float st[2],
if (IS_ZERO(denom) != 0) {
const double fDen = a - fC;
if (IS_ZERO(fDen) == 0) {
return (float)(a / fDen);
return float(a / fDen);
}
return 0.0f;
@@ -4489,7 +4470,7 @@ float resolve_quad_u_v2(const float st[2],
const double desc = sqrt(desc_sq < 0.0 ? 0.0 : desc_sq);
const double s = signed_area > 0 ? (-1.0) : 1.0;
return (float)(((a - b) + s * desc) / denom);
return float(((a - b) + s * desc) / denom);
}
#undef IS_ZERO
@@ -4745,14 +4726,14 @@ void projmat_from_subregion(const float projmat[4][4],
const int y_max,
float r_projmat[4][4])
{
float rect_width = (float)(x_max - x_min);
float rect_height = (float)(y_max - y_min);
float rect_width = float(x_max - x_min);
float rect_height = float(y_max - y_min);
float x_sca = (float)win_size[0] / rect_width;
float y_sca = (float)win_size[1] / rect_height;
float x_sca = float(win_size[0]) / rect_width;
float y_sca = float(win_size[1]) / rect_height;
float x_fac = (float)((x_min + x_max) - win_size[0]) / rect_width;
float y_fac = (float)((y_min + y_max) - win_size[1]) / rect_height;
float x_fac = float((x_min + x_max) - win_size[0]) / rect_width;
float y_fac = float((y_min + y_max) - win_size[1]) / rect_height;
copy_m4_m4(r_projmat, projmat);
r_projmat[0][0] *= x_sca;
@@ -4959,7 +4940,7 @@ bool map_to_tube(float *r_u, float *r_v, const float x, const float y, const flo
}
else {
/* The "Regular" case, just compute the coordinate. */
*r_u = snap_coordinate(atan2f(x, -y) / (float)(2.0f * M_PI));
*r_u = snap_coordinate(atan2f(x, -y) / float(2.0f * M_PI));
}
*r_v = (z + 1.0f) / 2.0f;
return regular;
@@ -4976,9 +4957,9 @@ bool map_to_sphere(float *r_u, float *r_v, const float x, const float y, const f
}
else {
/* The "Regular" case, just compute the coordinate. */
*r_u = snap_coordinate(atan2f(x, -y) / (float)(2.0f * M_PI));
*r_u = snap_coordinate(atan2f(x, -y) / float(2.0f * M_PI));
}
*r_v = snap_coordinate(atan2f(len_xy, -z) / (float)M_PI);
*r_v = snap_coordinate(atan2f(len_xy, -z) / float(M_PI));
return regular;
}
@@ -5035,7 +5016,7 @@ void accumulate_vertex_normals_tri_v3(float n1[3],
for (i = 0; i < nverts; i++) {
const float *cur_edge = vdiffs[i];
const float fac = saacos(-dot_v3v3(cur_edge, prev_edge));
const float fac = blender::math::safe_acos_approx(-dot_v3v3(cur_edge, prev_edge));
/* accumulate */
madd_v3_v3fl(vn[i], f_no, fac);
@@ -5055,7 +5036,7 @@ void accumulate_vertex_normals_v3(float n1[3],
const float co4[3])
{
float vdiffs[4][3];
const int nverts = (n4 != NULL && co4 != NULL) ? 4 : 3;
const int nverts = (n4 != nullptr && co4 != nullptr) ? 4 : 3;
/* compute normalized edge vectors */
sub_v3_v3v3(vdiffs[0], co2, co1);
@@ -5082,7 +5063,7 @@ void accumulate_vertex_normals_v3(float n1[3],
for (i = 0; i < nverts; i++) {
const float *cur_edge = vdiffs[i];
const float fac = saacos(-dot_v3v3(cur_edge, prev_edge));
const float fac = blender::math::safe_acos_approx(-dot_v3v3(cur_edge, prev_edge));
/* accumulate */
madd_v3_v3fl(vn[i], f_no, fac);
@@ -5114,7 +5095,7 @@ void accumulate_vertex_normals_poly_v3(float **vertnos,
/* calculate angle between the two poly edges incident on
* this vertex */
const float fac = saacos(-dot_v3v3(cur_edge, prev_edge));
const float fac = blender::math::safe_acos_approx(-dot_v3v3(cur_edge, prev_edge));
/* accumulate */
madd_v3_v3fl(vertnos[i], polyno, fac);
@@ -5226,7 +5207,7 @@ void vcloud_estimate_transform_v3(const int list_size,
}
}
if (!weight || !rweight) {
accu_weight = accu_rweight = (float)list_size;
accu_weight = accu_rweight = float(list_size);
}
mul_v3_fl(accu_com, 1.0f / accu_weight);
@@ -5740,8 +5721,8 @@ float form_factor_quad(const float p[3],
dot3 = dot_v3v3(n, g2);
dot4 = dot_v3v3(n, g3);
result = (a1 * dot1 + a2 * dot2 + a3 * dot3 + a4 * dot4) * 0.5f / (float)M_PI;
result = MAX2(result, 0.0f);
result = (a1 * dot1 + a2 * dot2 + a3 * dot3 + a4 * dot4) * 0.5f / float(M_PI);
result = std::max(result, 0.0f);
return result;
}
+9 -8
View File
@@ -7,6 +7,7 @@
* Various string, file, list operations.
*/
#include <algorithm> /* For `min/max`. */
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -76,7 +77,7 @@ int BLI_path_sequence_decode(const char *path,
const char *const lslash = BLI_path_slash_rfind(path);
const char *const extension = BLI_path_extension_or_end(lslash ? lslash : path);
const uint lslash_len = lslash != nullptr ? int(lslash - path) : 0;
const uint name_end = (uint)(extension - path);
const uint name_end = uint(extension - path);
for (i = name_end - 1; i >= int(lslash_len); i--) {
if (isdigit(path[i])) {
@@ -108,7 +109,7 @@ int BLI_path_sequence_decode(const char *path,
if (r_digits_len) {
*r_digits_len = nume - nums + 1;
}
return (int)ret;
return int(ret);
}
}
@@ -135,7 +136,7 @@ void BLI_path_sequence_encode(char *path,
{
BLI_string_debug_size(path, path_maxncpy);
BLI_snprintf(path, path_maxncpy, "%s%.*d%s", head, numlen, MAX2(0, pic), tail);
BLI_snprintf(path, path_maxncpy, "%s%.*d%s", head, numlen, std::max(0, pic), tail);
}
/**
@@ -963,7 +964,7 @@ bool BLI_path_frame(char *path, size_t path_maxncpy, int frame, int digits)
if (path_frame_chars_find_range(path, &ch_sta, &ch_end)) {
char frame_str[FILENAME_FRAME_CHARS_MAX + 1]; /* One for null. */
const int ch_span = MIN2(ch_end - ch_sta, FILENAME_FRAME_CHARS_MAX);
const int ch_span = std::min(ch_end - ch_sta, FILENAME_FRAME_CHARS_MAX);
SNPRINTF(frame_str, "%.*d", ch_span, frame);
BLI_string_replace_range(path, path_maxncpy, ch_sta, ch_end, frame_str);
return true;
@@ -983,7 +984,7 @@ bool BLI_path_frame_range(char *path, size_t path_maxncpy, int sta, int end, int
if (path_frame_chars_find_range(path, &ch_sta, &ch_end)) {
char frame_str[(FILENAME_FRAME_CHARS_MAX * 2) + 1 + 1]; /* One for null, one for the '-' */
const int ch_span = MIN2(ch_end - ch_sta, FILENAME_FRAME_CHARS_MAX);
const int ch_span = std::min(ch_end - ch_sta, FILENAME_FRAME_CHARS_MAX);
SNPRINTF(frame_str, "%.*d-%.*d", ch_span, sta, ch_span, end);
BLI_string_replace_range(path, path_maxncpy, ch_sta, ch_end, frame_str);
return true;
@@ -1166,7 +1167,7 @@ bool BLI_path_abs(char path[FILE_MAX], const char *basepath)
if (lslash) {
/* Length up to and including last `/`. */
const int baselen = (int)(lslash - base) + 1;
const int baselen = int(lslash - base) + 1;
/* Use path for temp storage here, we copy back over it right away. */
BLI_strncpy(path, tmp + 2, FILE_MAX); /* Strip `//` prefix. */
@@ -1581,7 +1582,7 @@ void BLI_path_split_dir_file(const char *filepath,
const char *basename = BLI_path_basename(filepath);
if (basename != filepath) {
const size_t dir_size = (basename - filepath) + 1;
BLI_strncpy(dir, filepath, MIN2(dir_maxncpy, dir_size));
BLI_strncpy(dir, filepath, std::min(dir_maxncpy, dir_size));
}
else {
dir[0] = '\0';
@@ -1595,7 +1596,7 @@ void BLI_path_split_dir_part(const char *filepath, char *dir, const size_t dir_m
const char *basename = BLI_path_basename(filepath);
if (basename != filepath) {
const size_t dir_size = (basename - filepath) + 1;
BLI_strncpy(dir, filepath, MIN2(dir_maxncpy, dir_size));
BLI_strncpy(dir, filepath, std::min(dir_maxncpy, dir_size));
}
else {
dir[0] = '\0';
+2 -2
View File
@@ -172,7 +172,7 @@ double BLI_dir_free_space(const char *dir)
}
# endif
return ((double(disk.f_bsize)) * (double(disk.f_bfree)));
return double(disk.f_bsize) * double(disk.f_bfree);
#endif
}
@@ -563,7 +563,7 @@ LinkNode *BLI_file_read_as_lines(const char *filepath)
}
BLI_fseek(fp, 0, SEEK_END);
size = (size_t)BLI_ftell(fp);
size = size_t(BLI_ftell(fp));
BLI_fseek(fp, 0, SEEK_SET);
if (UNLIKELY(size == size_t(-1))) {
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+21 -21
View File
@@ -319,7 +319,7 @@ BLI_INLINE char *str_utf8_copy_max_bytes_impl(char *dst, const char *src, size_t
/* Cast to `uint8_t` is a no-op, quiets array subscript of type `char` warning.
* No need to check `src` points to a nil byte as this will return from the switch statement. */
size_t utf8_size;
while ((utf8_size = (size_t)utf8_char_compute_skip(*src)) < dst_maxncpy) {
while ((utf8_size = size_t(utf8_char_compute_skip(*src))) < dst_maxncpy) {
dst_maxncpy -= utf8_size;
/* Prefer more compact block. */
/* NOLINTBEGIN: bugprone-assignment-in-if-condition */
@@ -356,7 +356,7 @@ size_t BLI_strncpy_utf8_rlen(char *__restrict dst, const char *__restrict src, s
char *r_dst = dst;
dst = str_utf8_copy_max_bytes_impl(dst, src, dst_maxncpy);
return (size_t)(dst - r_dst);
return size_t(dst - r_dst);
}
/* -------------------------------------------------------------------- */
@@ -371,7 +371,7 @@ size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst,
size_t len = 0;
while (*src && len < dst_maxncpy) {
len += BLI_str_utf8_from_unicode((uint)*src++, dst + len, dst_maxncpy - len);
len += BLI_str_utf8_from_unicode(uint(*src++), dst + len, dst_maxncpy - len);
}
dst[len] = '\0';
/* Return the correct length when part of the final byte did not fit into the string. */
@@ -386,7 +386,7 @@ size_t BLI_wstrlen_utf8(const wchar_t *src)
size_t len = 0;
while (*src) {
len += BLI_str_utf8_from_unicode_len((uint)*src++);
len += BLI_str_utf8_from_unicode_len(uint(*src++));
}
return len;
@@ -401,7 +401,7 @@ size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes)
strc += BLI_str_utf8_size_safe(strc);
}
*r_len_bytes = (size_t)(strc - strc_orig);
*r_len_bytes = size_t(strc - strc_orig);
return len;
}
@@ -418,7 +418,7 @@ size_t BLI_strnlen_utf8_ex(const char *strc, const size_t strc_maxlen, size_t *r
const char *strc_end = strc + strc_maxlen;
while (true) {
size_t step = (size_t)BLI_str_utf8_size_safe(strc);
size_t step = size_t(BLI_str_utf8_size_safe(strc));
if (!*strc || strc + step > strc_end) {
break;
}
@@ -426,7 +426,7 @@ size_t BLI_strnlen_utf8_ex(const char *strc, const size_t strc_maxlen, size_t *r
len++;
}
*r_len_bytes = (size_t)(strc - strc_orig);
*r_len_bytes = size_t(strc - strc_orig);
return len;
}
@@ -762,7 +762,7 @@ uint BLI_str_utf8_as_unicode_step_or_error(const char *__restrict p,
const size_t p_len,
size_t *__restrict index)
{
const uchar c = (uchar) * (p += *index);
const uchar c = uchar(*(p += *index));
BLI_assert(*index < p_len);
BLI_assert(c != '\0');
@@ -788,7 +788,7 @@ uint BLI_str_utf8_as_unicode_step_safe(const char *__restrict p,
{
uint result = BLI_str_utf8_as_unicode_step_or_error(p, p_len, index);
if (UNLIKELY(result == BLI_UTF8_ERR)) {
result = (uint)p[*index];
result = uint(p[*index]);
*index += 1;
}
BLI_assert(*index <= p_len);
@@ -854,10 +854,10 @@ size_t BLI_str_utf8_from_unicode(uint c, char *dst, const size_t dst_maxncpy)
}
for (uint i = len - 1; i > 0; i--) {
dst[i] = (char)((c & 0x3f) | 0x80);
dst[i] = char((c & 0x3f) | 0x80);
c >>= 6;
}
dst[0] = (char)(c | first);
dst[0] = char(c | first);
return len;
}
@@ -883,7 +883,7 @@ size_t BLI_str_utf8_as_utf32(char32_t *__restrict dst_w,
else {
*dst_w = '?';
const char *src_c_next = BLI_str_find_next_char_utf8(src_c + index, src_c_end);
index = (size_t)(src_c_next - src_c);
index = size_t(src_c_next - src_c);
}
dst_w++;
len++;
@@ -903,7 +903,7 @@ size_t BLI_str_utf32_as_utf8(char *__restrict dst,
size_t len = 0;
while (*src && len < dst_maxncpy) {
len += BLI_str_utf8_from_unicode((uint)*src++, dst + len, dst_maxncpy - len);
len += BLI_str_utf8_from_unicode(uint(*src++), dst + len, dst_maxncpy - len);
}
dst[len] = '\0';
/* Return the correct length when part of the final byte did not fit into the string. */
@@ -919,7 +919,7 @@ size_t BLI_str_utf32_as_utf8_len_ex(const char32_t *src, const size_t src_maxlen
const char32_t *src_end = src + src_maxlen;
while ((src < src_end) && *src) {
len += BLI_str_utf8_from_unicode_len((uint)*src++);
len += BLI_str_utf8_from_unicode_len(uint(*src++));
}
return len;
@@ -930,7 +930,7 @@ size_t BLI_str_utf32_as_utf8_len(const char32_t *src)
size_t len = 0;
while (*src) {
len += BLI_str_utf8_from_unicode_len((uint)*src++);
len += BLI_str_utf8_from_unicode_len(uint(*src++));
}
return len;
@@ -987,7 +987,7 @@ size_t BLI_str_partition_ex_utf8(const char *str,
const char **r_suf,
const bool from_right)
{
const size_t str_len = end ? (size_t)(end - str) : strlen(str);
const size_t str_len = end ? size_t(end - str) : strlen(str);
if (end == nullptr) {
end = str + str_len;
}
@@ -1003,7 +1003,7 @@ size_t BLI_str_partition_ex_utf8(const char *str,
str + index))
{
size_t index_ofs = 0;
const uint c = BLI_str_utf8_as_unicode_step_or_error(sep, (size_t)(end - sep), &index_ofs);
const uint c = BLI_str_utf8_as_unicode_step_or_error(sep, size_t(end - sep), &index_ofs);
if (UNLIKELY(c == BLI_UTF8_ERR)) {
break;
}
@@ -1014,7 +1014,7 @@ size_t BLI_str_partition_ex_utf8(const char *str,
/* `suf` is already correct in case from_right is true. */
*r_sep = sep;
*r_suf = from_right ? suf : (char *)(str + index);
return (size_t)(sep - str);
return size_t(sep - str);
}
}
@@ -1063,7 +1063,7 @@ int BLI_str_utf8_offset_from_index(const char *str, const size_t str_len, const
UNUSED_VARS(code);
index++;
}
return (int)offset;
return int(offset);
}
int BLI_str_utf8_offset_to_column(const char *str, const size_t str_len, const int offset_target)
@@ -1092,7 +1092,7 @@ int BLI_str_utf8_offset_from_column(const char *str, const size_t str_len, const
}
offset = offset_next;
}
return (int)offset;
return int(offset);
}
int BLI_str_utf8_offset_to_column_with_tabs(const char *str,
@@ -1129,7 +1129,7 @@ int BLI_str_utf8_offset_from_column_with_tabs(const char *str,
}
offset = offset_next;
}
return (int)offset;
return int(offset);
}
/** \} */
@@ -114,11 +114,11 @@ bool BLI_string_replace_table_exact(char *string,
size_t BLI_string_replace_range(
char *string, size_t string_maxncpy, int src_beg, int src_end, const char *dst)
{
int string_len = (int)strlen(string);
int string_len = int(strlen(string));
BLI_assert(src_beg <= src_end);
BLI_assert(src_end <= string_len);
const int src_len = src_end - src_beg;
int dst_len = (int)strlen(dst);
int dst_len = int(strlen(dst));
if (src_len < dst_len) {
/* Grow, first handle special cases. */
@@ -140,13 +140,13 @@ size_t BLI_string_replace_range(
}
/* Grow. */
memmove(string + (src_end + ofs), string + src_end, (size_t)(string_len - src_end) + 1);
memmove(string + (src_end + ofs), string + src_end, size_t(string_len - src_end) + 1);
string_len += ofs;
}
else if (src_len > dst_len) {
/* Shrink. */
const int ofs = src_len - dst_len;
memmove(string + (src_end - ofs), string + src_end, (size_t)(string_len - src_end) + 1);
memmove(string + (src_end - ofs), string + src_end, size_t(string_len - src_end) + 1);
string_len -= ofs;
}
else { /* Simple case, no resizing. */
@@ -157,7 +157,7 @@ size_t BLI_string_replace_range(
memcpy(string + src_beg, dst, size_t(dst_len));
}
BLI_assert(string[string_len] == '\0');
return (size_t)string_len;
return size_t(string_len);
}
/** \} */
@@ -178,7 +178,7 @@ size_t BLI_string_split_name_number(const char *name,
while (a--) {
if (name[a] == delim) {
r_name_left[a] = '\0'; /* truncate left part here */
*r_number = (int)atol(name + a + 1);
*r_number = int(atol(name + a + 1));
/* casting down to an int, can overflow for large numbers */
if (*r_number < 0) {
*r_number = 0;
@@ -562,7 +562,7 @@ size_t BLI_string_join_array(char *result,
}
}
*c = '\0';
return (size_t)(c - result);
return size_t(c - result);
}
size_t BLI_string_join_array_by_sep_char(
@@ -589,7 +589,7 @@ size_t BLI_string_join_array_by_sep_char(
}
}
*c = '\0';
return (size_t)(c - result);
return size_t(c - result);
}
char *BLI_string_join_arrayN(const char *strings[], uint strings_num)
+1 -1
View File
@@ -105,7 +105,7 @@ void BLI_task_parallel_range(const int start,
/* Multithreading. */
if (settings->use_threading && BLI_task_scheduler_num_threads() > 1) {
RangeTask task(func, userdata, settings);
const size_t grainsize = MAX2(settings->min_iter_per_thread, 1);
const size_t grainsize = std::max(settings->min_iter_per_thread, 1);
const tbb::blocked_range<int> range(start, stop, grainsize);
blender::lazy_threading::send_hint();
+1 -1
View File
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
@@ -1,4 +1,4 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
+2 -2
View File
@@ -702,7 +702,7 @@ static BHeadN *get_bhead(FileData *fd)
else {
/* MIN2 is only to quiet '-Warray-bounds' compiler warning. */
BLI_assert(sizeof(bhead) == sizeof(bhead4));
memcpy(&bhead, &bhead4, MIN2(sizeof(bhead), sizeof(bhead4)));
memcpy(&bhead, &bhead4, std::min(sizeof(bhead), sizeof(bhead4)));
}
}
else {
@@ -725,7 +725,7 @@ static BHeadN *get_bhead(FileData *fd)
else {
/* MIN2 is only to quiet `-Warray-bounds` compiler warning. */
BLI_assert(sizeof(bhead) == sizeof(bhead8));
memcpy(&bhead, &bhead8, MIN2(sizeof(bhead), sizeof(bhead8)));
memcpy(&bhead, &bhead8, std::min(sizeof(bhead), sizeof(bhead8)));
}
}
else {
@@ -961,7 +961,7 @@ void blo_do_versions_250(FileData *fd, Library * /*lib*/, Main *bmain)
key->refkey)
{
data = static_cast<const float *>(key->refkey->data);
tot = MIN2(me->totvert, key->refkey->totelem);
tot = std::min(me->totvert, key->refkey->totelem);
MVert *verts = (MVert *)CustomData_get_layer_for_write(
&me->vert_data, CD_MVERT, me->totvert);
for (a = 0; a < tot; a++, data += 3) {
@@ -976,7 +976,7 @@ void blo_do_versions_250(FileData *fd, Library * /*lib*/, Main *bmain)
key->refkey)
{
data = static_cast<const float *>(key->refkey->data);
tot = MIN2(lt->pntsu * lt->pntsv * lt->pntsw, key->refkey->totelem);
tot = std::min(lt->pntsu * lt->pntsv * lt->pntsw, key->refkey->totelem);
for (a = 0; a < tot; a++, data += 3) {
copy_v3_v3(lt->def[a].vec, data);
@@ -2557,7 +2557,7 @@ void blo_do_versions_260(FileData *fd, Library * /*lib*/, Main *bmain)
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 268, 1)) {
LISTBASE_FOREACH (Brush *, brush, &bmain->brushes) {
brush->spacing = MAX2(1, brush->spacing);
brush->spacing = std::max(1, brush->spacing);
}
}
@@ -122,12 +122,12 @@ static void version_idproperty_move_data_int(IDPropertyUIDataInt *ui_data,
IDProperty *soft_min = IDP_GetPropertyFromGroup(prop_ui_data, "soft_min");
if (soft_min != nullptr) {
ui_data->soft_min = IDP_coerce_to_int_or_zero(soft_min);
ui_data->soft_min = MIN2(ui_data->soft_min, ui_data->min);
ui_data->soft_min = std::min(ui_data->soft_min, ui_data->min);
}
IDProperty *soft_max = IDP_GetPropertyFromGroup(prop_ui_data, "soft_max");
if (soft_max != nullptr) {
ui_data->soft_max = IDP_coerce_to_int_or_zero(soft_max);
ui_data->soft_max = MAX2(ui_data->soft_max, ui_data->max);
ui_data->soft_max = std::max(ui_data->soft_max, ui_data->max);
}
IDProperty *step = IDP_GetPropertyFromGroup(prop_ui_data, "step");
if (step != nullptr) {
@@ -163,12 +163,12 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data,
IDProperty *soft_min = IDP_GetPropertyFromGroup(prop_ui_data, "soft_min");
if (soft_min != nullptr) {
ui_data->soft_min = IDP_coerce_to_double_or_zero(soft_min);
ui_data->soft_min = MAX2(ui_data->soft_min, ui_data->min);
ui_data->soft_min = std::max(ui_data->soft_min, ui_data->min);
}
IDProperty *soft_max = IDP_GetPropertyFromGroup(prop_ui_data, "soft_max");
if (soft_max != nullptr) {
ui_data->soft_max = IDP_coerce_to_double_or_zero(soft_max);
ui_data->soft_max = MIN2(ui_data->soft_max, ui_data->max);
ui_data->soft_max = std::min(ui_data->soft_max, ui_data->max);
}
IDProperty *step = IDP_GetPropertyFromGroup(prop_ui_data, "step");
if (step != nullptr) {
@@ -47,11 +47,13 @@
#include "BKE_animsys.h"
#include "BKE_armature.h"
#include "BKE_attribute.h"
#include "BKE_collection.h"
#include "BKE_curve.h"
#include "BKE_effect.h"
#include "BKE_grease_pencil.hh"
#include "BKE_idprop.hh"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mesh_legacy_convert.hh"
#include "BKE_node.hh"
#include "BKE_node_runtime.hh"
@@ -298,6 +300,30 @@ static void version_principled_bsdf_update_animdata(ID *owner_id, bNodeTree *ntr
}
}
static void versioning_eevee_shadow_settings(Object *object)
{
/** EEVEE no longer uses the Material::blend_shadow property.
* Instead, it uses Object::visibility_flag for disabling shadow casting
*/
short *material_len = BKE_object_material_len_p(object);
if (!material_len) {
return;
}
using namespace blender;
bool hide_shadows = *material_len > 0;
for (int i : IndexRange(*material_len)) {
Material *material = BKE_object_material_get(object, i + 1);
if (!material || material->blend_shadow != MA_BS_NONE) {
hide_shadows = false;
}
}
/* Enable the hide_shadow flag only if there's not any shadow casting material. */
SET_FLAG_FROM_TEST(object->visibility_flag, hide_shadows, OB_HIDE_SHADOW);
}
void do_versions_after_linking_400(FileData *fd, Main *bmain)
{
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 400, 9)) {
@@ -382,6 +408,16 @@ void do_versions_after_linking_400(FileData *fd, Main *bmain)
BKE_mesh_legacy_face_map_to_generic(bmain);
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 401, 5)) {
Scene *scene = static_cast<Scene *>(bmain->scenes.first);
bool is_cycles = scene && STREQ(scene->r.engine, RE_engine_id_CYCLES);
if (!is_cycles) {
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
versioning_eevee_shadow_settings(object);
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
@@ -1783,6 +1819,29 @@ void blo_do_versions_400(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
if (!MAIN_VERSION_FILE_ATLEAST(bmain, 401, 5)) {
/* Unify Material::blend_shadow and Cycles.use_transparent_shadows into the
* Material::blend_flag. */
Scene *scene = static_cast<Scene *>(bmain->scenes.first);
bool is_cycles = scene && STREQ(scene->r.engine, RE_engine_id_CYCLES);
if (is_cycles) {
LISTBASE_FOREACH (Material *, material, &bmain->materials) {
bool transparent_shadows = true;
if (IDProperty *cmat = version_cycles_properties_from_ID(&material->id)) {
transparent_shadows = version_cycles_property_boolean(
cmat, "use_transparent_shadow", true);
}
SET_FLAG_FROM_TEST(material->blend_flag, transparent_shadows, MA_BL_TRANSPARENT_SHADOW);
}
}
else {
LISTBASE_FOREACH (Material *, material, &bmain->materials) {
bool transparent_shadow = material->blend_shadow != MA_BS_SOLID;
SET_FLAG_FROM_TEST(material->blend_flag, transparent_shadow, MA_BL_TRANSPARENT_SHADOW);
}
}
}
/**
* Versioning code until next subversion bump goes here.
*
@@ -547,8 +547,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
blo_update_defaults_scene(bmain, scene);
if (app_template &&
(STREQ(app_template, "Video_Editing") || STREQ(app_template, "2D_Animation"))) {
if (app_template && STR_ELEM(app_template, "Video_Editing", "2D_Animation")) {
/* Filmic is too slow, use standard until it is optimized. */
STRNCPY(scene->view_settings.view_transform, "Standard");
STRNCPY(scene->view_settings.look, "None");
@@ -2259,7 +2259,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
/* convert settings from old particle system */
/* general settings */
part->totpart = MIN2(paf->totpart, 100000);
part->totpart = std::min(paf->totpart, 100000);
part->sta = paf->sta;
part->end = paf->end;
part->lifetime = paf->lifetime;
@@ -2503,8 +2503,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *bmain)
* use it for the number of divisions per segment
*/
if (nu->pntsv > 1) {
nu->resolu = MAX2(1, int((float(nu->resolu) / float(nu->pntsu)) + 0.5f));
nu->resolv = MAX2(1, int((float(nu->resolv) / float(nu->pntsv)) + 0.5f));
nu->resolu = std::max(1, int((float(nu->resolu) / float(nu->pntsu)) + 0.5f));
nu->resolv = std::max(1, int((float(nu->resolv) / float(nu->pntsv)) + 0.5f));
}
}
}

Some files were not shown because too many files have changed in this diff Show More