Vulkan: Clearing Storage Buffers #105487

Merged
Jeroen Bakker merged 94 commits from Jeroen-Bakker/blender:vulkan-storage-buffer-clear into main 2023-03-17 13:48:50 +01:00
331 changed files with 2376 additions and 1617 deletions
Showing only changes of commit 43cdb89179 - Show all commits

View File

@ -893,6 +893,23 @@ static std::optional<BL::IntAttribute> find_material_index_attribute(BL::Mesh b_
return std::nullopt;
}
static std::optional<BL::BoolAttribute> find_sharp_face_attribute(BL::Mesh b_mesh)
{
for (BL::Attribute &b_attribute : b_mesh.attributes) {
if (b_attribute.domain() != BL::Attribute::domain_FACE) {
continue;
}
if (b_attribute.data_type() != BL::Attribute::data_type_BOOLEAN) {
continue;
}
if (b_attribute.name() != "sharp_face") {
continue;
}
return BL::BoolAttribute{b_attribute};
}
return std::nullopt;
}
static void create_mesh(Scene *scene,
Mesh *mesh,
BL::Mesh &b_mesh,
@ -983,16 +1000,22 @@ static void create_mesh(Scene *scene,
return 0;
};
std::optional<BL::BoolAttribute> sharp_faces = find_sharp_face_attribute(b_mesh);
auto get_face_sharp = [&](const int poly_index) -> bool {
if (sharp_faces) {
return sharp_faces->data[poly_index].value();
}
return false;
};
/* create faces */
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
if (!subdivision) {
for (BL::MeshLoopTriangle &t : b_mesh.loop_triangles) {
const int poly_index = t.polygon_index();
const MPoly &b_poly = polys[poly_index];
int3 vi = get_int3(t.vertices());
int shader = get_material_index(poly_index);
bool smooth = (b_poly.flag & ME_SMOOTH) || use_loop_normals;
bool smooth = !get_face_sharp(poly_index) || use_loop_normals;
if (use_loop_normals) {
BL::Array<float, 9> loop_normals = t.split_normals();
@ -1012,13 +1035,14 @@ static void create_mesh(Scene *scene,
else {
vector<int> vi;
const MPoly *polys = static_cast<const MPoly *>(b_mesh.polygons[0].ptr.data);
const MLoop *loops = static_cast<const MLoop *>(b_mesh.loops[0].ptr.data);
for (int i = 0; i < numfaces; i++) {
const MPoly &b_poly = polys[i];
int n = b_poly.totloop;
int shader = get_material_index(i);
bool smooth = (b_poly.flag & ME_SMOOTH) || use_loop_normals;
bool smooth = !get_face_sharp(i) || use_loop_normals;
vi.resize(n);
for (int i = 0; i < n; i++) {

View File

@ -81,7 +81,7 @@ class DeviceInfo {
bool has_gpu_queue; /* Device supports GPU queue. */
bool use_metalrt; /* Use MetalRT to accelerate ray queries (Metal only). */
KernelOptimizationLevel kernel_optimization_level; /* Optimization level applied to path tracing
kernels (Metal only). */
* kernels (Metal only). */
DenoiserTypeMask denoisers; /* Supported denoiser types. */
int cpu_threads;
vector<DeviceInfo> multi_devices;

View File

@ -278,7 +278,7 @@ int MetalDeviceQueue::num_concurrent_states(const size_t state_size) const
if (metal_device_->device_vendor == METAL_GPU_APPLE) {
result *= 4;
/* Increasing the state count doesn't notably benefit M1-family systems. */
/* Increasing the state count doesn't notably benefit M1-family systems. */
if (MetalInfo::get_apple_gpu_architecture(metal_device_->mtlDevice) != APPLE_M1) {
size_t system_ram = system_physical_ram();
size_t allocated_so_far = [metal_device_->mtlDevice currentAllocatedSize];

View File

@ -1437,6 +1437,9 @@ void OptiXDevice::build_bvh(BVH *bvh, Progress &progress, bool refit)
BVHOptiX *const blas = static_cast<BVHOptiX *>(ob->get_geometry()->bvh);
OptixTraversableHandle handle = blas->traversable_handle;
if (handle == 0) {
continue;
}
OptixInstance &instance = instances[num_instances++];
memset(&instance, 0, sizeof(instance));

View File

@ -1343,7 +1343,7 @@ void PathTrace::guiding_prepare_structures()
* per update to be limited, for reproducible results and reasonable training size.
*
* Idea: we could stochastically discard samples with a probability of 1/num_samples_per_update
* we can then update only after the num_samples_per_update iterations are rendered. */
* we can then update only after the num_samples_per_update iterations are rendered. */
render_scheduler_.set_limit_samples_per_update(4);
}
else {

View File

@ -94,7 +94,7 @@ class PathTrace {
void set_adaptive_sampling(const AdaptiveSampling &adaptive_sampling);
/* Set the parameters for guiding.
* Use to setup the guiding structures before each rendering iteration.*/
* Use to setup the guiding structures before each rendering iteration. */
void set_guiding_params(const GuidingParams &params, const bool reset);
/* Sets output driver for render buffer output. */
@ -119,7 +119,7 @@ class PathTrace {
*/
void cancel();
/* Copy an entire render buffer to/from the path trace. */
/* Copy an entire render buffer to/from the path trace. */
/* Copy happens via CPU side buffer: data will be copied from every device of the path trace, and
* the data will be copied to the device of the given render buffers. */
@ -294,7 +294,7 @@ class PathTrace {
* rendering iteration. */
unique_ptr<openpgl::cpp::SampleStorage> guiding_sample_data_storage_;
/* The number of already performed training iterations for the guiding field.*/
/* The number of already performed training iterations for the guiding field. */
int guiding_update_count = 0;
#endif

View File

@ -202,7 +202,7 @@ ccl_device float2 direction_to_mirrorball(float3 dir)
}
/* Single face of a equiangular cube map projection as described in
https://blog.google/products/google-ar-vr/bringing-pixels-front-and-center-vr-video/ */
* https://blog.google/products/google-ar-vr/bringing-pixels-front-and-center-vr-video/ */
ccl_device float3 equiangular_cubemap_face_to_direction(float u, float v)
{
u = (1.0f - u);

View File

@ -136,7 +136,7 @@ ccl_device_forceinline float3 microfacet_beckmann_sample_vndf(const float3 wi,
/* Find root in a monotonic interval using newton method, under given precision and maximal
* iterations. Falls back to bisection if newton step produces results outside of the valid
* interval.*/
* interval. */
const float precision = 1e-6f;
const int max_iter = 3;
int iter = 0;

View File

@ -53,7 +53,7 @@ ccl_device_forceinline void guiding_record_surface_segment(KernelGlobals kg,
#endif
}
/* Records the surface scattering event at the current vertex position of the segment.*/
/* Records the surface scattering event at the current vertex position of the segment. */
ccl_device_forceinline void guiding_record_surface_bounce(KernelGlobals kg,
IntegratorState state,
ccl_private const ShaderData *sd,
@ -134,7 +134,7 @@ ccl_device_forceinline void guiding_record_bssrdf_segment(KernelGlobals kg,
}
/* Records the transmission of the path at the point of entry while passing
* the surface boundary.*/
* the surface boundary. */
ccl_device_forceinline void guiding_record_bssrdf_weight(KernelGlobals kg,
IntegratorState state,
const Spectrum weight,
@ -161,7 +161,7 @@ ccl_device_forceinline void guiding_record_bssrdf_weight(KernelGlobals kg,
/* Records the direction at the point of entry the path takes when sampling the SSS contribution.
* If not terminated this function is usually followed by a call of
* guiding_record_volume_transmission to record the transmittance between the point of entry and
* the point of exit.*/
* the point of exit. */
ccl_device_forceinline void guiding_record_bssrdf_bounce(KernelGlobals kg,
IntegratorState state,
const float pdf,
@ -216,7 +216,7 @@ ccl_device_forceinline void guiding_record_volume_segment(KernelGlobals kg,
#endif
}
/* Records the volume scattering event at the current vertex position of the segment.*/
/* Records the volume scattering event at the current vertex position of the segment. */
ccl_device_forceinline void guiding_record_volume_bounce(KernelGlobals kg,
IntegratorState state,
ccl_private const ShaderData *sd,
@ -247,7 +247,7 @@ ccl_device_forceinline void guiding_record_volume_bounce(KernelGlobals kg,
}
/* Records the transmission (a.k.a. transmittance weight) between the current path segment
* and the next one, when the path is inside or passes a volume.*/
* and the next one, when the path is inside or passes a volume. */
ccl_device_forceinline void guiding_record_volume_transmission(KernelGlobals kg,
IntegratorState state,
const float3 transmittance_weight)
@ -330,7 +330,7 @@ ccl_device_forceinline void guiding_record_light_surface_segment(
/* Records/Adds a final path segment when the path leaves the scene and
* intersects with a background light (e.g., background color,
* distant light, or env map). The vertex for this segment is placed along
* the current ray far out the scene.*/
* the current ray far out the scene. */
ccl_device_forceinline void guiding_record_background(KernelGlobals kg,
IntegratorState state,
const Spectrum L,
@ -359,7 +359,7 @@ ccl_device_forceinline void guiding_record_background(KernelGlobals kg,
/* Records the scattered contribution of a next event estimation
* (i.e., a direct light estimate scattered at the current path vertex
* towards the previous vertex).*/
* towards the previous vertex). */
ccl_device_forceinline void guiding_record_direct_light(KernelGlobals kg,
IntegratorShadowState state)
{
@ -397,7 +397,7 @@ ccl_device_forceinline void guiding_record_continuation_probability(
/* Path guiding debug render passes. */
/* Write a set of path guiding related debug information (e.g., guiding probability at first
* bounce) into separate rendering passes.*/
* bounce) into separate rendering passes. */
ccl_device_forceinline void guiding_write_debug_passes(KernelGlobals kg,
IntegratorState state,
ccl_private const ShaderData *sd,

View File

@ -1019,7 +1019,7 @@ ccl_device VolumeIntegrateEvent volume_integrate(KernelGlobals kg,
const float step_size = volume_stack_step_size(kg, volume_read_lambda_pass);
# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 1
/* The current path throughput which is used later to calculate per-segment throughput.*/
/* The current path throughput which is used later to calculate per-segment throughput. */
const float3 initial_throughput = INTEGRATOR_STATE(state, path, throughput);
/* The path throughput used to calculate the throughput for direct light. */
float3 unlit_throughput = initial_throughput;
@ -1063,7 +1063,7 @@ ccl_device VolumeIntegrateEvent volume_integrate(KernelGlobals kg,
if (result.direct_sample_method == VOLUME_SAMPLE_DISTANCE) {
/* If the direct scatter event is generated using VOLUME_SAMPLE_DISTANCE the direct event
* will happen at the same position as the indirect event and the direct light contribution
* will contribute to the position of the next path segment.*/
* will contribute to the position of the next path segment. */
float3 transmittance_weight = spectrum_to_rgb(
safe_divide_color(result.indirect_throughput, initial_throughput));
guiding_record_volume_transmission(kg, state, transmittance_weight);
@ -1076,7 +1076,8 @@ ccl_device VolumeIntegrateEvent volume_integrate(KernelGlobals kg,
/* If the direct scatter event is generated using VOLUME_SAMPLE_EQUIANGULAR the direct
* event will happen at a separate position as the indirect event and the direct light
* contribution will contribute to the position of the current/previous path segment. The
* unlit_throughput has to be adjusted to include the scattering at the previous segment.*/
* unlit_throughput has to be adjusted to include the scattering at the previous segment.
*/
float3 scatterEval = one_float3();
if (state->guiding.path_segment) {
pgl_vec3f scatteringWeight = state->guiding.path_segment->scatteringWeight;

View File

@ -126,16 +126,16 @@ typedef struct IntegratorStateGPU {
/* Count number of kernels queued for specific shaders. */
ccl_global int *sort_key_counter[DEVICE_KERNEL_INTEGRATOR_NUM];
/* Index of shadow path which will be used by a next shadow path. */
/* Index of shadow path which will be used by a next shadow path. */
ccl_global int *next_shadow_path_index;
/* Index of main path which will be used by a next shadow catcher split. */
/* Index of main path which will be used by a next shadow catcher split. */
ccl_global int *next_main_path_index;
/* Partition/key offsets used when writing sorted active indices. */
ccl_global int *sort_partition_key_offsets;
/* Divisor used to partition active indices by locality when sorting by material. */
/* Divisor used to partition active indices by locality when sorting by material. */
uint sort_partition_divisor;
} IntegratorStateGPU;

View File

@ -38,7 +38,7 @@ ccl_device_inline void surface_shader_prepare_guiding(KernelGlobals kg,
const float surface_guiding_probability = kernel_data.integrator.surface_guiding_probability;
float rand_bsdf_guiding = path_state_rng_1D(kg, rng_state, PRNG_SURFACE_BSDF_GUIDING);
/* Compute proportion of diffuse BSDF and BSSRDFs .*/
/* Compute proportion of diffuse BSDF and BSSRDFs. */
float diffuse_sampling_fraction = 0.0f;
float bssrdf_sampling_fraction = 0.0f;
float bsdf_bssrdf_sampling_sum = 0.0f;

View File

@ -259,7 +259,7 @@ int LightTree::recursive_build(
bool should_split = false;
if (try_splitting) {
/* Find the best place to split the primitives into 2 nodes.
* If the best split cost is no better than making a leaf node, make a leaf instead.*/
* If the best split cost is no better than making a leaf node, make a leaf instead. */
float min_cost = min_split_saoh(
centroid_bounds, start, end, bbox, bcone, split_dim, split_bucket, num_left_prims, prims);
should_split = num_prims > max_lights_in_leaf_ || min_cost < energy_total;

View File

@ -351,7 +351,7 @@ class Scene : public NodeOwner {
/* Get maximum number of closures to be used in kernel. */
int get_max_closure_count();
/* Get size of a volume stack needed to render this scene. */
/* Get size of a volume stack needed to render this scene. */
int get_volume_stack_size() const;
template<typename T> void delete_node_impl(T *node)

View File

@ -507,7 +507,7 @@ void Session::do_delayed_reset()
params = delayed_reset_.session_params;
buffer_params_ = delayed_reset_.buffer_params;
/* Store parameters used for buffers access outside of scene graph. */
/* Store parameters used for buffers access outside of scene graph. */
buffer_params_.samples = params.samples;
buffer_params_.exposure = scene->film->get_exposure();
buffer_params_.use_approximate_shadow_catcher =

View File

@ -943,6 +943,11 @@ extern void GHOST_SetBacktraceHandler(GHOST_TBacktraceFn backtrace_fn);
*/
extern void GHOST_UseWindowFocus(bool use_focus);
/**
* Focus and raise windows on mouse hover.
*/
extern void GHOST_SetAutoFocus(bool auto_focus);
/**
* If window was opened using native pixel size, it returns scaling factor.
*/

View File

@ -332,6 +332,11 @@ class GHOST_ISystem {
*/
virtual void useWindowFocus(const bool use_focus) = 0;
/**
* Focus and raise windows on mouse hover.
*/
virtual void setAutoFocus(const bool auto_focus) = 0;
/**
* Get the Window under the cursor.
* \param x: The x-coordinate of the cursor.

View File

@ -918,6 +918,12 @@ void GHOST_UseWindowFocus(bool use_focus)
return system->useWindowFocus(use_focus);
}
void GHOST_SetAutoFocus(bool auto_focus)
{
GHOST_ISystem *system = GHOST_ISystem::getSystem();
system->setAutoFocus(auto_focus);
}
float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle)
{
GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;

View File

@ -401,13 +401,15 @@ static bool checkLayerSupport(vector<VkLayerProperties> &layers_available, const
static void enableLayer(vector<VkLayerProperties> &layers_available,
vector<const char *> &layers_enabled,
const char *layer_name)
const char *layer_name,
const bool debug)
{
if (checkLayerSupport(layers_available, layer_name)) {
layers_enabled.push_back(layer_name);
}
else {
fprintf(stderr, "Error: %s not supported.\n", layer_name);
else if (debug) {
fprintf(
stderr, "Warning: Layer requested, but not supported by the platform. [%s]\n", layer_name);
}
}
@ -862,7 +864,7 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
vector<const char *> layers_enabled;
if (m_debug) {
enableLayer(layers_available, layers_enabled, "VK_LAYER_KHRONOS_validation");
enableLayer(layers_available, layers_enabled, "VK_LAYER_KHRONOS_validation", m_debug);
}
vector<const char *> extensions_device;
@ -878,7 +880,7 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
}
extensions_device.push_back("VK_KHR_dedicated_allocation");
extensions_device.push_back("VK_KHR_get_memory_requirements2");
/* Enable MoltenVK required instance extensions.*/
/* Enable MoltenVK required instance extensions. */
#ifdef VK_MVK_MOLTENVK_EXTENSION_NAME
requireExtension(
extensions_available, extensions_enabled, "VK_KHR_get_physical_device_properties2");

View File

@ -23,6 +23,7 @@
GHOST_System::GHOST_System()
: m_nativePixel(false),
m_windowFocus(true),
m_autoFocus(true),
m_displayManager(nullptr),
m_timerManager(nullptr),
m_windowManager(nullptr),
@ -412,6 +413,11 @@ void GHOST_System::useWindowFocus(const bool use_focus)
m_windowFocus = use_focus;
}
void GHOST_System::setAutoFocus(const bool auto_focus)
{
m_autoFocus = auto_focus;
}
bool GHOST_System::supportsCursorWarp()
{
return true;

View File

@ -160,6 +160,12 @@ class GHOST_System : public GHOST_ISystem {
bool m_windowFocus;
/**
* Focus and raise windows on mouse hover.
*/
void setAutoFocus(const bool auto_focus);
bool m_autoFocus;
/**
* Get the Window under the cursor.
* \param x: The x-coordinate of the cursor.

View File

@ -1828,10 +1828,13 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, uint msg, WPARAM wParam,
if (!window->m_mousePresent) {
WINTAB_PRINTF("HWND %p mouse enter\n", window->getHWND());
TRACKMOUSEEVENT tme = {sizeof(tme)};
/* Request WM_MOUSELEAVE message when the cursor leaves the client area, and
* WM_MOUSEHOVER message after 50ms when in the client area. */
tme.dwFlags = TME_LEAVE | TME_HOVER;
tme.dwHoverTime = 50;
/* Request WM_MOUSELEAVE message when the cursor leaves the client area. */
tme.dwFlags = TME_LEAVE;
if (system->m_autoFocus) {
/* Request WM_MOUSEHOVER message after 100ms when in the client area. */
tme.dwFlags |= TME_HOVER;
tme.dwHoverTime = 100;
}
tme.hwndTrack = hwnd;
TrackMouseEvent(&tme);
window->m_mousePresent = true;

View File

@ -157,6 +157,7 @@ const UserDef U_default = {
.glalphaclip = 0.004,
.autokey_mode = (AUTOKEY_MODE_NORMAL & ~AUTOKEY_ON),
.autokey_flag = AUTOKEY_FLAG_XYZ2RGB,
.animation_flag = USER_ANIM_HIGH_QUALITY_DRAWING,
.text_render = 0,
.navigation_mode = VIEW_NAVIGATION_WALK,
.view_rotate_sensitivity_turntable = DEG2RAD(0.4),

View File

@ -604,7 +604,7 @@ class DATA_PT_mesh_attributes(MeshButtonsPanel, Panel):
colliding_names = []
for collection in (
# Built-in names.
{"shade_smooth": None, "crease": None},
{"crease": None},
mesh.attributes,
None if ob is None else ob.vertex_groups,
):

View File

@ -107,16 +107,9 @@ class GRAPH_MT_view(Menu):
layout.separator()
layout.prop(st, "show_markers")
layout.separator()
layout.prop(st, "use_beauty_drawing")
layout.separator()
layout.prop(st, "show_extrapolation")
layout.prop(st, "show_handles")
layout.prop(st, "use_only_selected_curves_handles")
layout.prop(st, "use_only_selected_keyframe_handles")
layout.prop(st, "show_seconds")

View File

@ -559,6 +559,8 @@ class USERPREF_PT_animation_fcurves(AnimationPanel, CenterAlignMixIn, Panel):
flow.prop(edit, "keyframe_new_handle_type", text="Default Handles")
flow.prop(edit, "use_insertkey_xyz_to_rgb", text="XYZ to RGB")
flow.prop(edit, "use_anim_channel_group_colors")
flow.prop(edit, "show_only_selected_curve_keyframes")
flow.prop(edit, "use_fcurve_high_quality_drawing")
# -----------------------------------------------------------------------------

View File

@ -60,7 +60,7 @@ static FT_Library ft_lib = NULL;
static FTC_Manager ftc_manager = NULL;
static FTC_CMapCache ftc_charmap_cache = NULL;
/* Lock for FreeType library, used around face creation and deletion. */
/* Lock for FreeType library, used around face creation and deletion. */
static ThreadMutex ft_lib_mutex;
/* May be set to #UI_widgetbase_draw_cache_flush. */
@ -1566,7 +1566,7 @@ FontBLF *blf_font_new_ex(const char *name,
}
}
/* Detect "Last resort" fonts. They have everything. Usually except last 5 bits. */
/* Detect "Last resort" fonts. They have everything. Usually except last 5 bits. */
if (font->unicode_ranges[0] == 0xffffffffU && font->unicode_ranges[1] == 0xffffffffU &&
font->unicode_ranges[2] == 0xffffffffU && font->unicode_ranges[3] >= 0x7FFFFFFU) {
font->flags |= BLF_LAST_RESORT;

View File

@ -300,7 +300,7 @@ typedef struct FontBLF {
/** Font size. */
float size;
/** Axes data for Adobe MM, TrueType GX, or OpenType variation fonts. */
/** Axes data for Adobe MM, TrueType GX, or OpenType variation fonts. */
FT_MM_Var *variations;
/** Character variation; 0=default, -1=min, +1=max. */

View File

@ -246,7 +246,7 @@ static const char32_t *blf_get_sample_text(FT_Face face)
return def;
}
/* Detect "Last resort" fonts. They have everything, except the last 5 bits. */
/* Detect "Last resort" fonts. They have everything, except the last 5 bits. */
if (os2_table->ulUnicodeRange1 == 0xffffffffU && os2_table->ulUnicodeRange2 == 0xffffffffU &&
os2_table->ulUnicodeRange3 == 0xffffffffU && os2_table->ulUnicodeRange4 >= 0x7FFFFFFU) {
return U"\xE000\xFFFF";

View File

@ -74,7 +74,7 @@ struct Scene;
/* keep in sync with MFace/MPoly types */
typedef struct DMFlagMat {
short mat_nr;
char flag;
bool sharp;
} DMFlagMat;
typedef enum DerivedMeshType {

View File

@ -25,7 +25,7 @@ extern "C" {
/* Blender file format version. */
#define BLENDER_FILE_VERSION BLENDER_VERSION
#define BLENDER_FILE_SUBVERSION 1
#define BLENDER_FILE_SUBVERSION 2
/* Minimum Blender version that supports reading file written with the current
* version. Older Blender versions will test this and show a warning if the file

View File

@ -83,8 +83,10 @@ typedef enum {
BKE_CB_EVT_RENDER_CANCEL,
BKE_CB_EVT_LOAD_PRE,
BKE_CB_EVT_LOAD_POST,
BKE_CB_EVT_LOAD_POST_FAIL,
BKE_CB_EVT_SAVE_PRE,
BKE_CB_EVT_SAVE_POST,
BKE_CB_EVT_SAVE_POST_FAIL,
BKE_CB_EVT_UNDO_PRE,
BKE_CB_EVT_UNDO_POST,
BKE_CB_EVT_REDO_PRE,
@ -123,6 +125,7 @@ void BKE_callback_exec_id_depsgraph(struct Main *bmain,
struct ID *id,
struct Depsgraph *depsgraph,
eCbEvent evt);
void BKE_callback_exec_string(struct Main *bmain, eCbEvent evt, const char *str);
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt);
void BKE_callback_remove(bCallbackFuncStore *funcstore, eCbEvent evt);

View File

@ -133,21 +133,26 @@ void BKE_curvemapping_table_RGBA(const struct CurveMapping *cumap, float **array
void BKE_curvemapping_get_range_minimums(const struct CurveMapping *curve_mapping,
float minimums[4]);
/** Get the reciprocal of the difference between the maximum and the minimum x value of each curve
/**
* Get the reciprocal of the difference between the maximum and the minimum x value of each curve
* map table. Evaluation parameters can be multiplied by this value to be normalized. If the
* difference is zero, 1^8 is returned. */
* difference is zero, 1^8 is returned.
*/
void BKE_curvemapping_compute_range_dividers(const struct CurveMapping *curve_mapping,
float dividers[4]);
/** Compute the slopes at the start and end points of each curve map. The slopes are multiplied by
/**
* Compute the slopes at the start and end points of each curve map. The slopes are multiplied by
* the range of the curve map to compensate for parameter normalization. If the slope is vertical,
* 1^8 is returned. */
* 1^8 is returned.
*/
void BKE_curvemapping_compute_slopes(const struct CurveMapping *curve_mapping,
float start_slopes[4],
float end_slopes[4]);
/** Check if the curve map at the index is identity, that is, does nothing. A curve map is said to
* be identity if:
/**
* Check if the curve map at the index is identity, that is, does nothing.
* A curve map is said to be identity if:
* - The curve mapping uses extrapolation.
* - Its range is 1.
* - The slope at its start point is 1.

View File

@ -259,7 +259,7 @@ extern IDTypeInfo IDType_ID_AC;
extern IDTypeInfo IDType_ID_NT;
extern IDTypeInfo IDType_ID_BR;
extern IDTypeInfo IDType_ID_PA;
extern IDTypeInfo IDType_ID_GD;
extern IDTypeInfo IDType_ID_GD_LEGACY;
extern IDTypeInfo IDType_ID_WM;
extern IDTypeInfo IDType_ID_MC;
extern IDTypeInfo IDType_ID_MSK;

View File

@ -139,11 +139,15 @@ enum {
/** Do not process ID pointers inside embedded IDs. Needed by depsgraph processing e.g. */
IDWALK_IGNORE_EMBEDDED_ID = (1 << 3),
/** Also process internal ID pointers like `ID.newid` or `ID.orig_id`.
* WARNING: Dangerous, use with caution. */
/**
* Also process internal ID pointers like `ID.newid` or `ID.orig_id`.
* WARNING: Dangerous, use with caution.
*/
IDWALK_DO_INTERNAL_RUNTIME_POINTERS = (1 << 9),
/** Also process the ID.lib pointer. It is an option because this pointer can usually be fully
ignored. */
/**
* Also process the ID.lib pointer. It is an option because this pointer can usually be fully
* ignored.
*/
IDWALK_DO_LIBRARY_POINTER = (1 << 10),
};

View File

@ -453,12 +453,15 @@ void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
*
* Used when defining an empty custom loop normals data layer,
* to keep same shading as with auto-smooth!
*
* \param sharp_faces: Optional array used to mark specific faces for sharp shading.
*/
void BKE_edges_sharp_from_angle_set(int numEdges,
const struct MLoop *mloops,
int numLoops,
const struct MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
int numPolys,
float split_angle,
bool *sharp_edges);
@ -574,6 +577,7 @@ void BKE_lnor_space_custom_normal_to_data(const MLoopNorSpace *lnor_space,
* (splitting edges).
*
* \param loop_to_poly_map: Optional pre-created map from loops to their polygon.
* \param sharp_faces: Optional array used to mark specific faces for sharp shading.
* \param sharp_edges: Optional array of sharp edge tags, used to split the evaluated normals on
* each side of the edge.
*/
@ -591,6 +595,7 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3],
bool use_split_normals,
float split_angle,
const bool *sharp_edges,
const bool *sharp_faces,
const int *loop_to_poly_map,
MLoopNorSpaceArray *r_lnors_spacearr,
short (*clnors_data)[2]);
@ -605,6 +610,7 @@ void BKE_mesh_normals_loop_custom_set(const float (*vert_positions)[3],
int numLoops,
const struct MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
int numPolys,
bool *sharp_edges,
short (*r_clnors_data)[2]);
@ -618,6 +624,7 @@ void BKE_mesh_normals_loop_custom_from_verts_set(const float (*vert_positions)[3
int numLoops,
const struct MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
int numPolys,
bool *sharp_edges,
short (*r_clnors_data)[2]);

View File

@ -96,6 +96,9 @@ void BKE_mesh_legacy_convert_loose_edges_to_flag(struct Mesh *mesh);
void BKE_mesh_legacy_attribute_flags_to_strings(struct Mesh *mesh);
void BKE_mesh_legacy_attribute_strings_to_flags(struct Mesh *mesh);
void BKE_mesh_legacy_sharp_faces_to_flags(struct Mesh *mesh);
void BKE_mesh_legacy_sharp_faces_from_flags(struct Mesh *mesh);
void BKE_mesh_legacy_sharp_edges_to_flags(struct Mesh *mesh);
void BKE_mesh_legacy_sharp_edges_from_flags(struct Mesh *mesh);

View File

@ -324,6 +324,7 @@ int *BKE_mesh_calc_smoothgroups(int totedge,
const struct MLoop *mloop,
int totloop,
const bool *sharp_edges,
const bool *sharp_faces,
int *r_totgroup,
bool use_bitflags);

View File

@ -48,6 +48,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
const struct MLoop *mloop,
const struct MLoopTri *looptri,
uint looptri_len,
const bool *sharp_faces,
struct CustomData *loopdata,
bool calc_active_tangent,

View File

@ -76,6 +76,7 @@ typedef struct ShrinkwrapTreeData {
const struct MPoly *polys;
const float (*vert_normals)[3];
const float (*poly_normals)[3];
const bool *sharp_faces;
const float (*clnors)[3];
ShrinkwrapBoundaryData *boundary;
} ShrinkwrapTreeData;

View File

@ -515,7 +515,7 @@ static void armature_deform_coords_impl(const Object *ob_arm,
dverts_len = lt->pntsu * lt->pntsv * lt->pntsw;
}
}
else if (ob_target->type == OB_GPENCIL) {
else if (ob_target->type == OB_GPENCIL_LEGACY) {
target_data_id = (const ID *)ob_target->data;
dverts = gps_target->dvert;
if (dverts) {

View File

@ -63,6 +63,9 @@ bool allow_procedural_attribute_access(StringRef attribute_name)
if (attribute_name.startswith(".hide")) {
return false;
}
if (attribute_name.startswith(".uv")) {
return false;
}
if (attribute_name.startswith("." UV_VERTSEL_NAME ".")) {
return false;
}

View File

@ -506,7 +506,7 @@ struct BlendFileData *BKE_blendfile_read(const char *filepath,
{
/* Don't print startup file loading. */
if (params->is_startup == false) {
printf("Read blend: %s\n", filepath);
printf("Read blend: \"%s\"\n", filepath);
}
BlendFileData *bfd = BLO_read_from_file(filepath, eBLOReadSkip(params->skip_flags), reports);
@ -518,7 +518,7 @@ struct BlendFileData *BKE_blendfile_read(const char *filepath,
handle_subversion_warning(bfd->main, reports);
}
else {
BKE_reports_prependf(reports->reports, "Loading '%s' failed: ", filepath);
BKE_reports_prependf(reports->reports, "Loading \"%s\" failed: ", filepath);
}
return bfd;
}
@ -768,7 +768,7 @@ bool BKE_blendfile_userdef_write_all(ReportList *reports)
bool ok_write;
BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE);
printf("Writing userprefs: '%s' ", filepath);
printf("Writing userprefs: \"%s\" ", filepath);
if (use_template_userpref) {
ok_write = BKE_blendfile_userdef_write_app_template(filepath, reports);
}
@ -795,7 +795,7 @@ bool BKE_blendfile_userdef_write_all(ReportList *reports)
/* Also save app-template prefs */
BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_USERPREF_FILE);
printf("Writing userprefs app-template: '%s' ", filepath);
printf("Writing userprefs app-template: \"%s\" ", filepath);
if (BKE_blendfile_userdef_write(filepath, reports) != 0) {
printf("ok\n");
}

View File

@ -69,6 +69,18 @@ void BKE_callback_exec_id_depsgraph(struct Main *bmain,
BKE_callback_exec(bmain, pointers, 2, evt);
}
void BKE_callback_exec_string(struct Main *bmain, eCbEvent evt, const char *str)
{
PointerRNA str_ptr;
PrimitiveStringRNA data = {NULL};
data.value = str;
RNA_pointer_create(NULL, &RNA_PrimitiveString, &data, &str_ptr);
PointerRNA *pointers[1] = {&str_ptr};
BKE_callback_exec(bmain, pointers, 1, evt);
}
void BKE_callback_add(bCallbackFuncStore *funcstore, eCbEvent evt)
{
ASSERT_CALLBACKS_INITIALIZED();

View File

@ -410,7 +410,7 @@ void BKE_curve_init(Curve *cu, const short curve_type)
}
cu->bevel_profile = nullptr;
/* Initialize the offset to 1.0, to compensate for it being set to -1.0
in the property getter. */
* in the property getter. */
cu->offset = 1.0f;
}

View File

@ -103,7 +103,6 @@ static void fill_mesh_topology(const int vert_offset,
MPoly &poly = polys[ring_poly_offset + i_profile];
poly.loopstart = ring_segment_loop_offset;
poly.totloop = 4;
poly.flag = ME_SMOOTH;
MLoop &loop_a = loops[ring_segment_loop_offset];
loop_a.v = ring_vert_offset + i_profile;
@ -674,6 +673,7 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
MutableSpan<MEdge> edges = mesh->edges_for_write();
MutableSpan<MPoly> polys = mesh->polys_for_write();
MutableSpan<MLoop> loops = mesh->loops_for_write();
MutableAttributeAccessor mesh_attributes = mesh->attributes_for_write();
foreach_curve_combination(curves_info, offsets, [&](const CombinationInfo &info) {
fill_mesh_topology(info.vert_range.start(),
@ -690,6 +690,23 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
polys);
});
if (fill_caps) {
/* TODO: This is used to keep the tests passing after refactoring mesh shade smooth flags. It
* can be removed if the tests are updated and the final shading results will be the same. */
SpanAttributeWriter<bool> sharp_faces = mesh_attributes.lookup_or_add_for_write_span<bool>(
"sharp_face", ATTR_DOMAIN_FACE);
foreach_curve_combination(curves_info, offsets, [&](const CombinationInfo &info) {
const bool has_caps = fill_caps && !info.main_cyclic && info.profile_cyclic;
if (has_caps) {
const int poly_num = info.main_segment_num * info.profile_segment_num;
const int cap_poly_offset = info.poly_range.start() + poly_num;
sharp_faces.span[cap_poly_offset] = true;
sharp_faces.span[cap_poly_offset + 1] = true;
}
});
sharp_faces.finish();
}
const Span<float3> main_positions = main.evaluated_positions();
const Span<float3> tangents = main.evaluated_tangents();
const Span<float3> normals = main.evaluated_normals();
@ -721,8 +738,6 @@ Mesh *curve_to_mesh_sweep(const CurvesGeometry &main,
positions.slice(info.vert_range));
});
MutableAttributeAccessor mesh_attributes = mesh->attributes_for_write();
SpanAttributeWriter<bool> sharp_edges;
write_sharp_bezier_edges(curves_info, offsets, mesh_attributes, sharp_edges);
if (fill_caps) {

View File

@ -382,6 +382,8 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
if (dirty_nors_dst || do_loop_nors_dst) {
const bool *sharp_edges = static_cast<const bool *>(
CustomData_get_layer_named(&me_dst->edata, CD_PROP_BOOL, "sharp_edge"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face"));
BKE_mesh_normals_loop_split(positions_dst,
BKE_mesh_vert_normals_ensure(me_dst),
num_verts_dst,
@ -396,6 +398,7 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
use_split_nors_dst,
split_angle_dst,
sharp_edges,
sharp_faces,
nullptr,
nullptr,
custom_nors_dst);
@ -451,6 +454,8 @@ static void data_transfer_dtdata_type_postprocess(Object * /*ob_src*/,
loops_dst.size(),
polys_dst.data(),
poly_nors_dst,
static_cast<const bool *>(CustomData_get_layer_named(
&me_dst->pdata, CD_PROP_BOOL, "sharp_face")),
polys_dst.size(),
sharp_edges.span.data(),
custom_nors_dst);
@ -1109,26 +1114,21 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
return true;
}
if (r_map && cddata_type == CD_FAKE_SHARP) {
const size_t elem_size = sizeof(*((MPoly *)nullptr));
const size_t data_size = sizeof(((MPoly *)nullptr)->flag);
const size_t data_offset = offsetof(MPoly, flag);
const uint64_t data_flag = ME_SMOOTH;
data_transfer_layersmapping_add_item(r_map,
cddata_type,
mix_mode,
mix_factor,
mix_weights,
me_src->polys().data(),
me_dst->polys_for_write().data(),
me_src->totpoly,
me_dst->totpoly,
elem_size,
data_size,
data_offset,
data_flag,
nullptr,
interp_data);
if (!CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face")) {
CustomData_add_layer_named(
&me_dst->pdata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me_dst->totpoly, "sharp_face");
}
data_transfer_layersmapping_add_item_cd(
r_map,
CD_PROP_BOOL,
mix_mode,
mix_factor,
mix_weights,
CustomData_get_layer_named(&me_src->pdata, CD_PROP_BOOL, "sharp_face"),
CustomData_get_layer_named_for_write(
&me_dst->pdata, CD_PROP_BOOL, "sharp_face", num_elem_dst),
interp,
interp_data);
return true;
}

View File

@ -440,7 +440,7 @@ bool BKE_object_supports_vertex_groups(const Object *ob)
return false;
}
return ELEM(GS(id->name), ID_ME, ID_LT, ID_GD);
return ELEM(GS(id->name), ID_ME, ID_LT, ID_GD_LEGACY);
}
const ListBase *BKE_id_defgroup_list_get(const ID *id)
@ -454,7 +454,7 @@ const ListBase *BKE_id_defgroup_list_get(const ID *id)
const Lattice *lt = (const Lattice *)id;
return &lt->vertex_group_names;
}
case ID_GD: {
case ID_GD_LEGACY: {
const bGPdata *gpd = (const bGPdata *)id;
return &gpd->vertex_group_names;
}
@ -477,7 +477,7 @@ static const int *object_defgroup_active_index_get_p(const Object *ob)
const Lattice *lattice = (const Lattice *)ob->data;
return &lattice->vertex_group_active_index;
}
case OB_GPENCIL: {
case OB_GPENCIL_LEGACY: {
const bGPdata *gpd = (const bGPdata *)ob->data;
return &gpd->vertex_group_active_index;
}

View File

@ -589,7 +589,7 @@ static bool get_fcurve_end_keyframes(const FCurve *fcu,
}
/* The binary search returns an index where a keyframe would be inserted,
so it needs to be clamped to ensure it is in range of the array. */
* so it needs to be clamped to ensure it is in range of the array. */
first_index = clamp_i(first_index, 0, fcu->totvert - 1);
last_index = clamp_i(last_index - 1, 0, fcu->totvert - 1);
}

View File

@ -23,7 +23,7 @@
#include "DNA_object_types.h"
#include "DNA_rigidbody_types.h"
#include "BKE_attribute.h"
#include "BKE_attribute.hh"
#include "BKE_effect.h"
#include "BKE_fluid.h"
#include "BKE_global.h"
@ -3213,16 +3213,8 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
float size[3];
float cell_size_scaled[3];
/* Assign material + flags to new mesh.
* If there are no faces in original mesh, keep materials and flags unchanged. */
MPoly mp_example = {0};
if (MPoly *polys = BKE_mesh_polys_for_write(orgmesh)) {
mp_example = *polys;
}
const int *orig_material_indices = BKE_mesh_material_indices(orgmesh);
const short mp_mat_nr = orig_material_indices ? orig_material_indices[0] : 0;
const char mp_flag = mp_example.flag;
int i;
int num_verts, num_faces;
@ -3251,6 +3243,10 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
blender::MutableSpan<MPoly> polys = me->polys_for_write();
blender::MutableSpan<MLoop> loops = me->loops_for_write();
const bool is_sharp = orgmesh->attributes().lookup_or_default<bool>(
"sharp_face", ATTR_DOMAIN_FACE, false)[0];
BKE_mesh_smooth_flag_set(me, !is_sharp);
/* Get size (dimension) but considering scaling. */
copy_v3_v3(cell_size_scaled, fds->cell_size);
mul_v3_v3(cell_size_scaled, ob->scale);
@ -3338,7 +3334,6 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
for (const int i : polys.index_range()) {
/* Initialize from existing face. */
material_indices[i] = mp_mat_nr;
polys[i].flag = mp_flag;
polys[i].loopstart = i * 3;
polys[i].totloop = 3;

View File

@ -913,16 +913,6 @@ static void tag_component_positions_changed(void *owner)
}
}
static bool get_shade_smooth(const MPoly &poly)
{
return poly.flag & ME_SMOOTH;
}
static void set_shade_smooth(MPoly &poly, bool value)
{
SET_FLAG_FROM_TEST(poly.flag, value, ME_SMOOTH);
}
static float get_crease(const float &crease)
{
return crease;
@ -1217,17 +1207,16 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
nullptr,
AttributeValidator{&material_index_clamp});
static BuiltinCustomDataLayerProvider shade_smooth(
"shade_smooth",
ATTR_DOMAIN_FACE,
CD_PROP_BOOL,
CD_MPOLY,
BuiltinAttributeProvider::NonCreatable,
BuiltinAttributeProvider::NonDeletable,
face_access,
make_derived_read_attribute<MPoly, bool, get_shade_smooth>,
make_derived_write_attribute<MPoly, bool, get_shade_smooth, set_shade_smooth>,
nullptr);
static BuiltinCustomDataLayerProvider sharp_face("sharp_face",
ATTR_DOMAIN_FACE,
CD_PROP_BOOL,
CD_PROP_BOOL,
BuiltinAttributeProvider::Creatable,
BuiltinAttributeProvider::Deletable,
face_access,
make_array_read_attribute<bool>,
make_array_write_attribute<bool>,
nullptr);
static BuiltinCustomDataLayerProvider sharp_edge("sharp_edge",
ATTR_DOMAIN_EDGE,
@ -1259,7 +1248,7 @@ static ComponentAttributeProviders create_attribute_providers_for_mesh()
static CustomDataAttributeProvider face_custom_data(ATTR_DOMAIN_FACE, face_access);
return ComponentAttributeProviders(
{&position, &id, &material_index, &shade_smooth, &sharp_edge, &crease},
{&position, &id, &material_index, &sharp_face, &sharp_edge, &crease},
{&corner_custom_data,
&vertex_groups,
&point_custom_data,

View File

@ -296,10 +296,10 @@ static void greasepencil_blend_read_expand(BlendExpander *expander, ID *id)
}
}
IDTypeInfo IDType_ID_GD = {
.id_code = ID_GD,
.id_filter = FILTER_ID_GD,
.main_listbase_index = INDEX_ID_GD,
IDTypeInfo IDType_ID_GD_LEGACY = {
.id_code = ID_GD_LEGACY,
.id_filter = FILTER_ID_GD_LEGACY,
.main_listbase_index = INDEX_ID_GD_LEGACY,
.struct_size = sizeof(bGPdata),
.name = "GPencil",
.name_plural = "grease_pencils",
@ -707,7 +707,7 @@ bGPdata *BKE_gpencil_data_addnew(Main *bmain, const char name[])
bGPdata *gpd;
/* allocate memory for a new block */
gpd = BKE_libblock_alloc(bmain, ID_GD, name, 0);
gpd = BKE_libblock_alloc(bmain, ID_GD_LEGACY, name, 0);
/* initial settings */
gpd->flag = (GP_DATA_DISPINFO | GP_DATA_EXPAND);
@ -1275,9 +1275,8 @@ bGPDframe *BKE_gpencil_layer_frame_get(bGPDlayer *gpl, int cframe, eGP_GetFrame_
gpl->actframe = gpf;
}
else if (addnew == GP_GETFRAME_ADD_COPY) {
/* The frame_addcopy function copies the active frame of gpl,
so we need to set the active frame before copying.
*/
/* The #BKE_gpencil_frame_addcopy function copies the active frame of gpl,
* so we need to set the active frame before copying. */
gpl->actframe = gpf;
gpl->actframe = BKE_gpencil_frame_addcopy(gpl, cframe);
}
@ -1306,9 +1305,8 @@ bGPDframe *BKE_gpencil_layer_frame_get(bGPDlayer *gpl, int cframe, eGP_GetFrame_
gpl->actframe = gpf;
}
else if (addnew == GP_GETFRAME_ADD_COPY) {
/* The frame_addcopy function copies the active frame of gpl;
so we need to set the active frame before copying.
*/
/* The #BKE_gpencil_frame_addcopy function copies the active frame of gpl;
* so we need to set the active frame before copying. */
gpl->actframe = gpf;
gpl->actframe = BKE_gpencil_frame_addcopy(gpl, cframe);
}
@ -2710,7 +2708,7 @@ void BKE_gpencil_layer_transform_matrix_get(const Depsgraph *depsgraph,
/* if not layer parented, try with object parented */
if (obparent_eval == NULL) {
if ((ob_eval != NULL) && (ob_eval->type == OB_GPENCIL)) {
if ((ob_eval != NULL) && (ob_eval->type == OB_GPENCIL_LEGACY)) {
copy_m4_m4(diff_mat, ob_eval->object_to_world);
mul_m4_m4m4(diff_mat, diff_mat, gpl->layer_mat);
return;
@ -2748,7 +2746,7 @@ void BKE_gpencil_layer_transform_matrix_get(const Depsgraph *depsgraph,
void BKE_gpencil_update_layer_transforms(const Depsgraph *depsgraph, Object *ob)
{
if (ob->type != OB_GPENCIL) {
if (ob->type != OB_GPENCIL_LEGACY) {
return;
}

View File

@ -468,7 +468,7 @@ void BKE_gpencil_convert_curve(Main *bmain,
const float scale_thickness,
const float sample)
{
if (ELEM(NULL, ob_gp, ob_cu) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == NULL)) {
if (ELEM(NULL, ob_gp, ob_cu) || (ob_gp->type != OB_GPENCIL_LEGACY) || (ob_gp->data == NULL)) {
return;
}

View File

@ -2703,7 +2703,8 @@ bool BKE_gpencil_convert_mesh(Main *bmain,
{
using namespace blender;
using namespace blender::bke;
if (ELEM(nullptr, ob_gp, ob_mesh) || (ob_gp->type != OB_GPENCIL) || (ob_gp->data == nullptr)) {
if (ELEM(nullptr, ob_gp, ob_mesh) || (ob_gp->type != OB_GPENCIL_LEGACY) ||
(ob_gp->data == nullptr)) {
return false;
}

View File

@ -81,7 +81,7 @@ static void id_type_init(void)
INIT_TYPE(ID_NT);
INIT_TYPE(ID_BR);
INIT_TYPE(ID_PA);
INIT_TYPE(ID_GD);
INIT_TYPE(ID_GD_LEGACY);
INIT_TYPE(ID_WM);
INIT_TYPE(ID_MC);
INIT_TYPE(ID_MSK);
@ -220,7 +220,7 @@ uint64_t BKE_idtype_idcode_to_idfilter(const short idcode)
CASE_IDFILTER(CA);
CASE_IDFILTER(CF);
CASE_IDFILTER(CU_LEGACY);
CASE_IDFILTER(GD);
CASE_IDFILTER(GD_LEGACY);
CASE_IDFILTER(GR);
CASE_IDFILTER(CV);
CASE_IDFILTER(IM);
@ -278,7 +278,7 @@ short BKE_idtype_idcode_from_idfilter(const uint64_t idfilter)
CASE_IDFILTER(CA);
CASE_IDFILTER(CF);
CASE_IDFILTER(CU_LEGACY);
CASE_IDFILTER(GD);
CASE_IDFILTER(GD_LEGACY);
CASE_IDFILTER(GR);
CASE_IDFILTER(CV);
CASE_IDFILTER(IM);
@ -334,7 +334,7 @@ int BKE_idtype_idcode_to_index(const short idcode)
CASE_IDINDEX(CA);
CASE_IDINDEX(CF);
CASE_IDINDEX(CU_LEGACY);
CASE_IDINDEX(GD);
CASE_IDINDEX(GD_LEGACY);
CASE_IDINDEX(GR);
CASE_IDINDEX(CV);
CASE_IDINDEX(IM);
@ -393,7 +393,7 @@ short BKE_idtype_idcode_from_index(const int index)
CASE_IDCODE(CA);
CASE_IDCODE(CF);
CASE_IDCODE(CU_LEGACY);
CASE_IDCODE(GD);
CASE_IDCODE(GD_LEGACY);
CASE_IDCODE(GR);
CASE_IDCODE(CV);
CASE_IDCODE(IM);

View File

@ -2281,6 +2281,8 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
&mesh->ldata, CD_CUSTOMLOOPNORMAL, loops.size())); /* May be nullptr. */
const bool *sharp_edges = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"));
BKE_mesh_normals_loop_split(positions,
vert_normals,
mesh->totvert,
@ -2295,6 +2297,7 @@ void BKE_keyblock_mesh_calc_normals(const KeyBlock *kb,
(mesh->flag & ME_AUTOSMOOTH) != 0,
mesh->smoothresh,
sharp_edges,
sharp_faces,
nullptr,
nullptr,
clnors);

View File

@ -839,7 +839,7 @@ bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
RNA_property_update(C, ptr, prop);
/* tag grease pencil data-block and disable onion */
if (GS(id->name) == ID_GD) {
if (GS(id->name) == ID_GD_LEGACY) {
DEG_id_tag_update(id, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
DEG_id_tag_update(newid, ID_RECALC_TRANSFORM | ID_RECALC_GEOMETRY);
bGPdata *gpd = (bGPdata *)newid;

View File

@ -396,7 +396,7 @@ uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner)
case ID_SCE:
return FILTER_ID_OB | FILTER_ID_WO | FILTER_ID_SCE | FILTER_ID_MC | FILTER_ID_MA |
FILTER_ID_GR | FILTER_ID_TXT | FILTER_ID_LS | FILTER_ID_MSK | FILTER_ID_SO |
FILTER_ID_GD | FILTER_ID_BR | FILTER_ID_PAL | FILTER_ID_IM | FILTER_ID_NT;
FILTER_ID_GD_LEGACY | FILTER_ID_BR | FILTER_ID_PAL | FILTER_ID_IM | FILTER_ID_NT;
case ID_OB:
/* Could be more specific, but simpler to just always say 'yes' here. */
return FILTER_ID_ALL;
@ -435,7 +435,7 @@ uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner)
case ID_PA:
return FILTER_ID_OB | FILTER_ID_GR | FILTER_ID_TE;
case ID_MC:
return FILTER_ID_GD | FILTER_ID_IM;
return FILTER_ID_GD_LEGACY | FILTER_ID_IM;
case ID_MSK:
/* WARNING! mask->parent.id, not typed. */
return FILTER_ID_MC;
@ -443,7 +443,7 @@ uint64_t BKE_library_id_can_use_filter_id(const ID *id_owner)
return FILTER_ID_TE | FILTER_ID_OB;
case ID_LP:
return FILTER_ID_IM;
case ID_GD:
case ID_GD_LEGACY:
return FILTER_ID_MA;
case ID_WS:
return FILTER_ID_SCE;

View File

@ -625,7 +625,7 @@ ListBase *which_libbase(Main *bmain, short type)
return &(bmain->particles);
case ID_WM:
return &(bmain->wm);
case ID_GD:
case ID_GD_LEGACY:
return &(bmain->gpencils);
case ID_MC:
return &(bmain->movieclips);
@ -669,7 +669,7 @@ int set_listbasepointers(Main *bmain, ListBase *lb[/*INDEX_ID_MAX*/])
lb[INDEX_ID_PAL] = &(bmain->palettes);
/* Referenced by nodes, objects, view, scene etc, before to free after. */
lb[INDEX_ID_GD] = &(bmain->gpencils);
lb[INDEX_ID_GD_LEGACY] = &(bmain->gpencils);
lb[INDEX_ID_NT] = &(bmain->nodetrees);
lb[INDEX_ID_IM] = &(bmain->images);

View File

@ -328,7 +328,7 @@ Material ***BKE_object_material_array_p(Object *ob)
MetaBall *mb = static_cast<MetaBall *>(ob->data);
return &(mb->mat);
}
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
return &(gpd->mat);
}
@ -361,7 +361,7 @@ short *BKE_object_material_len_p(Object *ob)
MetaBall *mb = static_cast<MetaBall *>(ob->data);
return &(mb->totcol);
}
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
bGPdata *gpd = static_cast<bGPdata *>(ob->data);
return &(gpd->totcol);
}
@ -392,7 +392,7 @@ Material ***BKE_id_material_array_p(ID *id)
return &(((Curve *)id)->mat);
case ID_MB:
return &(((MetaBall *)id)->mat);
case ID_GD:
case ID_GD_LEGACY:
return &(((bGPdata *)id)->mat);
case ID_CV:
return &(((Curves *)id)->mat);
@ -418,7 +418,7 @@ short *BKE_id_material_len_p(ID *id)
return &(((Curve *)id)->totcol);
case ID_MB:
return &(((MetaBall *)id)->totcol);
case ID_GD:
case ID_GD_LEGACY:
return &(((bGPdata *)id)->totcol);
case ID_CV:
return &(((Curves *)id)->totcol);
@ -480,7 +480,7 @@ bool BKE_object_material_slot_used(Object *object, short actcol)
case ID_MB:
/* Meta-elements don't support materials at the moment. */
return false;
case ID_GD:
case ID_GD_LEGACY:
return BKE_gpencil_material_index_used((bGPdata *)ob_data, actcol - 1);
default:
return false;
@ -1090,7 +1090,7 @@ void BKE_object_material_remap(Object *ob, const uint *remap)
else if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF, OB_FONT)) {
BKE_curve_material_remap(static_cast<Curve *>(ob->data), remap, ob->totcol);
}
else if (ob->type == OB_GPENCIL) {
else if (ob->type == OB_GPENCIL_LEGACY) {
BKE_gpencil_material_remap(static_cast<bGPdata *>(ob->data), remap, ob->totcol);
}
else {
@ -1347,7 +1347,7 @@ bool BKE_object_material_slot_remove(Main *bmain, Object *ob)
}
}
/* check indices from gpencil */
else if (ob->type == OB_GPENCIL) {
else if (ob->type == OB_GPENCIL_LEGACY) {
BKE_gpencil_material_index_reassign((bGPdata *)ob->data, ob->totcol, actcol - 1);
}

View File

@ -1480,7 +1480,6 @@ Mesh *BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob)
const int count = indices[2] != indices[3] ? 4 : 3;
polys[i].loopstart = loop_offset;
polys[i].totloop = count;
polys[i].flag = ME_SMOOTH;
mloop[loop_offset].v = uint32_t(indices[0]);
mloop[loop_offset + 1].v = uint32_t(indices[1]);

View File

@ -255,20 +255,24 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address
Set<std::string> names_to_skip;
if (!BLO_write_is_undo(writer)) {
/* When converting to the old mesh format, don't save redundant attributes. */
names_to_skip.add_multiple_new({".hide_vert",
names_to_skip.add_multiple_new({"position",
".hide_vert",
".hide_edge",
".hide_poly",
"position",
"material_index",
".uv_seam",
".select_vert",
".select_edge",
".select_poly"});
".select_poly",
"material_index",
"sharp_face",
"sharp_edge"});
mesh->mvert = BKE_mesh_legacy_convert_positions_to_verts(
mesh, temp_arrays_for_legacy_format, vert_layers);
BKE_mesh_legacy_convert_hide_layers_to_flags(mesh);
BKE_mesh_legacy_convert_selection_layers_to_flags(mesh);
BKE_mesh_legacy_convert_material_indices_to_mpoly(mesh);
BKE_mesh_legacy_sharp_faces_to_flags(mesh);
BKE_mesh_legacy_bevel_weight_from_layers(mesh);
BKE_mesh_legacy_edge_crease_from_layers(mesh);
BKE_mesh_legacy_sharp_edges_to_flags(mesh);
@ -1485,16 +1489,17 @@ void BKE_mesh_material_remap(Mesh *me, const uint *remap, uint remap_len)
void BKE_mesh_smooth_flag_set(Mesh *me, const bool use_smooth)
{
MutableSpan<MPoly> polys = me->polys_for_write();
using namespace blender;
using namespace blender::bke;
MutableAttributeAccessor attributes = me->attributes_for_write();
if (use_smooth) {
for (MPoly &poly : polys) {
poly.flag |= ME_SMOOTH;
}
attributes.remove("sharp_face");
}
else {
for (MPoly &poly : polys) {
poly.flag &= ~ME_SMOOTH;
}
SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_only_span<bool>(
"sharp_face", ATTR_DOMAIN_FACE);
sharp_faces.span.fill(true);
sharp_faces.finish();
}
}
@ -1842,7 +1847,8 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
&mesh->ldata, CD_CUSTOMLOOPNORMAL, mesh->totloop);
const bool *sharp_edges = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"));
const Span<float3> positions = mesh->vert_positions();
const Span<MEdge> edges = mesh->edges();
const Span<MPoly> polys = mesh->polys();
@ -1862,6 +1868,7 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
use_split_normals,
split_angle,
sharp_edges,
sharp_faces,
nullptr,
r_lnors_spacearr,
clnors);

View File

@ -391,15 +391,12 @@ static void copy_vert_attributes(Mesh *dest_mesh,
/* Similar to copy_vert_attributes but for poly attributes. */
static void copy_poly_attributes(Mesh *dest_mesh,
MPoly *poly,
const MPoly *orig_poly,
const Mesh *orig_me,
int poly_index,
int index_in_orig_me,
Span<short> material_remap,
MutableSpan<int> dst_material_indices)
{
poly->flag = orig_poly->flag;
CustomData *target_cd = &dest_mesh->pdata;
const CustomData *source_cd = &orig_me->pdata;
for (int source_layer_i = 0; source_layer_i < source_cd->totlayer; ++source_layer_i) {
@ -751,8 +748,6 @@ static Mesh *imesh_to_mesh(IMesh *im, MeshesToIMeshInfo &mim)
}
copy_poly_attributes(result,
poly,
orig_poly,
orig_me,
fi,
index_in_orig_me,

View File

@ -195,6 +195,9 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<int> material_indices = attributes.lookup_or_add_for_write_only_span<int>(
"material_index", ATTR_DOMAIN_FACE);
SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_span<bool>(
"sharp_face", ATTR_DOMAIN_FACE);
blender::float2 *mloopuv = static_cast<blender::float2 *>(CustomData_add_layer_named(
&mesh->ldata, CD_PROP_FLOAT2, CD_SET_DEFAULT, nullptr, mesh->totloop, DATA_("UVMap")));
@ -278,9 +281,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
}
}
if (is_smooth) {
polys[dst_poly].flag |= ME_SMOOTH;
}
sharp_faces.span[dst_poly] = !is_smooth;
dst_poly++;
dst_loop += 3;
index += 3;
@ -363,9 +364,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
}
}
if (is_smooth) {
polys[dst_poly].flag |= ME_SMOOTH;
}
sharp_faces.span[dst_poly] = !is_smooth;
dst_poly++;
dst_loop += 4;
@ -383,6 +382,7 @@ static Mesh *mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBase *dispba
}
material_indices.finish();
sharp_faces.finish();
return mesh;
}

View File

@ -447,6 +447,12 @@ static void convert_mfaces_to_mpolys(ID *id,
material_indices = static_cast<int *>(CustomData_add_layer_named(
pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, totpoly, "material_index"));
}
bool *sharp_faces = static_cast<bool *>(
CustomData_get_layer_named_for_write(pdata, CD_PROP_BOOL, "sharp_face", totpoly));
if (!sharp_faces) {
sharp_faces = static_cast<bool *>(CustomData_add_layer_named(
pdata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, totpoly, "sharp_face"));
}
numTex = CustomData_number_of_layers(fdata, CD_MTFACE);
numCol = CustomData_number_of_layers(fdata, CD_MCOL);
@ -491,7 +497,7 @@ static void convert_mfaces_to_mpolys(ID *id,
poly->totloop = mf->v4 ? 4 : 3;
material_indices[i] = mf->mat_nr;
poly->flag = mf->flag;
sharp_faces[i] = (mf->flag & ME_SMOOTH) == 0;
#define ML(v1, v2) \
{ \
@ -975,6 +981,8 @@ static int mesh_tessface_calc(Mesh &mesh,
mloop = (const MLoop *)CustomData_get_layer(ldata, CD_MLOOP);
const int *material_indices = static_cast<const int *>(
CustomData_get_layer_named(pdata, CD_PROP_INT32, "material_index"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(pdata, CD_PROP_BOOL, "sharp_face"));
/* Allocate the length of `totfaces`, avoid many small reallocation's,
* if all faces are triangles it will be correct, `quads == 2x` allocations. */
@ -1014,7 +1022,7 @@ static int mesh_tessface_calc(Mesh &mesh,
lidx[2] = l3; \
lidx[3] = 0; \
mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
mf->flag = poly->flag; \
mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
mf->edcode = 0; \
(void)0
@ -1037,7 +1045,7 @@ static int mesh_tessface_calc(Mesh &mesh,
lidx[2] = l3; \
lidx[3] = l4; \
mf->mat_nr = material_indices ? material_indices[poly_index] : 0; \
mf->flag = poly->flag; \
mf->flag = (sharp_faces && sharp_faces[poly_index]) ? 0 : ME_SMOOTH; \
mf->edcode = TESSFACE_IS_QUAD; \
(void)0
@ -1123,7 +1131,6 @@ static int mesh_tessface_calc(Mesh &mesh,
lidx[3] = 0;
mf->mat_nr = material_indices ? material_indices[poly_index] : 0;
mf->flag = poly->flag;
mf->edcode = 0;
mface_index++;
@ -1214,6 +1221,57 @@ void BKE_mesh_tessface_ensure(struct Mesh *mesh)
/** \} */
/* -------------------------------------------------------------------- */
/** \name Sharp Edge Conversion
* \{ */
void BKE_mesh_legacy_sharp_faces_to_flags(Mesh *mesh)
{
using namespace blender;
MutableSpan<MPoly> polys = mesh->polys_for_write();
if (const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"))) {
threading::parallel_for(polys.index_range(), 4096, [&](const IndexRange range) {
for (const int i : range) {
SET_FLAG_FROM_TEST(polys[i].flag_legacy, !sharp_faces[i], ME_SMOOTH);
}
});
}
else {
for (const int i : polys.index_range()) {
polys[i].flag_legacy |= ME_SMOOTH;
}
}
}
void BKE_mesh_legacy_sharp_faces_from_flags(Mesh *mesh)
{
using namespace blender;
using namespace blender::bke;
const Span<MPoly> polys = mesh->polys();
MutableAttributeAccessor attributes = mesh->attributes_for_write();
if (attributes.contains("sharp_face")) {
return;
}
if (std::any_of(polys.begin(), polys.end(), [](const MPoly &poly) {
return !(poly.flag_legacy & ME_SMOOTH);
})) {
SpanAttributeWriter<bool> sharp_faces = attributes.lookup_or_add_for_write_only_span<bool>(
"sharp_face", ATTR_DOMAIN_FACE);
threading::parallel_for(polys.index_range(), 4096, [&](const IndexRange range) {
for (const int i : range) {
sharp_faces.span[i] = !(polys[i].flag_legacy & ME_SMOOTH);
}
});
sharp_faces.finish();
}
else {
attributes.remove("sharp_face");
}
}
/** \} */
/* -------------------------------------------------------------------- */
/** \name Face Set Conversion
* \{ */
@ -1496,7 +1554,7 @@ void BKE_mesh_legacy_convert_hide_layers_to_flags(Mesh *mesh)
".hide_poly", ATTR_DOMAIN_FACE, false);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
SET_FLAG_FROM_TEST(polys[i].flag, hide_poly[i], ME_HIDE);
SET_FLAG_FROM_TEST(polys[i].flag_legacy, hide_poly[i], ME_HIDE);
}
});
}
@ -1539,13 +1597,14 @@ void BKE_mesh_legacy_convert_flags_to_hide_layers(Mesh *mesh)
}
const Span<MPoly> polys = mesh->polys();
if (std::any_of(
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.flag & ME_HIDE; })) {
if (std::any_of(polys.begin(), polys.end(), [](const MPoly &poly) {
return poly.flag_legacy & ME_HIDE;
})) {
SpanAttributeWriter<bool> hide_poly = attributes.lookup_or_add_for_write_only_span<bool>(
".hide_poly", ATTR_DOMAIN_FACE);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
hide_poly.span[i] = polys[i].flag & ME_HIDE;
hide_poly.span[i] = polys[i].flag_legacy & ME_HIDE;
}
});
hide_poly.finish();
@ -1814,7 +1873,7 @@ void BKE_mesh_legacy_convert_selection_layers_to_flags(Mesh *mesh)
".select_poly", ATTR_DOMAIN_FACE, false);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
SET_FLAG_FROM_TEST(polys[i].flag, select_poly[i], ME_FACE_SEL);
SET_FLAG_FROM_TEST(polys[i].flag_legacy, select_poly[i], ME_FACE_SEL);
}
});
}
@ -1858,13 +1917,14 @@ void BKE_mesh_legacy_convert_flags_to_selection_layers(Mesh *mesh)
}
const Span<MPoly> polys = mesh->polys();
if (std::any_of(
polys.begin(), polys.end(), [](const MPoly &poly) { return poly.flag & ME_FACE_SEL; })) {
if (std::any_of(polys.begin(), polys.end(), [](const MPoly &poly) {
return poly.flag_legacy & ME_FACE_SEL;
})) {
SpanAttributeWriter<bool> select_poly = attributes.lookup_or_add_for_write_only_span<bool>(
".select_poly", ATTR_DOMAIN_FACE);
threading::parallel_for(polys.index_range(), 4096, [&](IndexRange range) {
for (const int i : range) {
select_poly.span[i] = polys[i].flag & ME_FACE_SEL;
select_poly.span[i] = polys[i].flag_legacy & ME_FACE_SEL;
}
});
select_poly.finish();

View File

@ -845,11 +845,14 @@ int *BKE_mesh_calc_smoothgroups(const int totedge,
const MLoop *mloop,
const int totloop,
const bool *sharp_edges,
const bool *sharp_faces,
int *r_totgroup,
const bool use_bitflags)
{
int *poly_groups = nullptr;
auto poly_is_smooth = [&](const int i) { return !(sharp_faces && sharp_faces[i]); };
auto poly_is_island_boundary_smooth = [&](const int poly_index,
const int /*loop_index*/,
const int edge_index,
@ -857,13 +860,13 @@ int *BKE_mesh_calc_smoothgroups(const int totedge,
const MeshElemMap &edge_poly_map_elem) {
/* Edge is sharp if one of its polys is flat, or edge itself is sharp,
* or edge is not used by exactly two polygons. */
if ((polys[poly_index].flag & ME_SMOOTH) && !(sharp_edges && sharp_edges[edge_index]) &&
if ((poly_is_smooth(poly_index)) && !(sharp_edges && sharp_edges[edge_index]) &&
(edge_user_count == 2)) {
/* In that case, edge appears to be smooth, but we need to check its other poly too. */
const int other_poly_index = (poly_index == edge_poly_map_elem.indices[0]) ?
edge_poly_map_elem.indices[1] :
edge_poly_map_elem.indices[0];
return (polys[other_poly_index].flag & ME_SMOOTH) == 0;
return !poly_is_smooth(other_poly_index);
}
return true;
};

View File

@ -63,7 +63,7 @@ static void merge_uvs_for_vertex(const Span<int> loops_for_vert, Span<float2 *>
if (loops_for_vert.size() <= 1) {
return;
}
/* Manipulate a copy of the loop indices, de-duplicating UVs per layer. */
/* Manipulate a copy of the loop indices, de-duplicating UVs per layer. */
Vector<int, 32> loops_merge;
loops_merge.reserve(loops_for_vert.size());
for (float2 *mloopuv : mloopuv_layers) {

View File

@ -389,6 +389,8 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
const bool *sharp_edges = static_cast<const bool *>(
CustomData_get_layer_named(&result->edata, CD_PROP_BOOL, "sharp_edge"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&result->pdata, CD_PROP_BOOL, "sharp_face"));
BKE_mesh_normals_loop_split(BKE_mesh_vert_positions(result),
BKE_mesh_vert_normals_ensure(result),
result->totvert,
@ -403,6 +405,7 @@ Mesh *BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(MirrorModifierData *mmd,
true,
result->smoothresh,
sharp_edges,
sharp_faces,
nullptr,
&lnors_spacearr,
clnors);

View File

@ -786,6 +786,7 @@ static void mesh_edges_sharp_tag(const Span<MPoly> polys,
const Span<MLoop> loops,
const Span<int> loop_to_poly_map,
const Span<float3> poly_normals,
const Span<bool> sharp_faces,
const Span<bool> sharp_edges,
const bool check_angle,
const float split_angle,
@ -794,6 +795,9 @@ static void mesh_edges_sharp_tag(const Span<MPoly> polys,
{
using namespace blender;
const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f;
auto poly_is_smooth = [&](const int poly_i) {
return sharp_faces.is_empty() || !sharp_faces[poly_i];
};
for (const int poly_i : polys.index_range()) {
const MPoly &poly = polys[poly_i];
@ -808,7 +812,7 @@ static void mesh_edges_sharp_tag(const Span<MPoly> polys,
/* 'Empty' edge until now, set e2l[0] (and e2l[1] to INDEX_UNSET to tag it as unset). */
e2l[0] = loop_index;
/* We have to check this here too, else we might miss some flat faces!!! */
e2l[1] = (poly.flag & ME_SMOOTH) ? INDEX_UNSET : INDEX_INVALID;
e2l[1] = (poly_is_smooth(poly_i)) ? INDEX_UNSET : INDEX_INVALID;
}
else if (e2l[1] == INDEX_UNSET) {
const bool is_angle_sharp = (check_angle &&
@ -820,7 +824,7 @@ static void mesh_edges_sharp_tag(const Span<MPoly> polys,
* or both poly have opposed (flipped) normals, i.e. both loops on the same edge share the
* same vertex, or angle between both its polys' normals is above split_angle value.
*/
if (!(poly.flag & ME_SMOOTH) || (!sharp_edges.is_empty() && sharp_edges[edge_i]) ||
if (!poly_is_smooth(poly_i) || (!sharp_edges.is_empty() && sharp_edges[edge_i]) ||
vert_i == loops[e2l[0]].v || is_angle_sharp) {
/* NOTE: we are sure that loop != 0 here ;). */
e2l[1] = INDEX_INVALID;
@ -855,6 +859,7 @@ void BKE_edges_sharp_from_angle_set(const int numEdges,
const int numLoops,
const MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
const int numPolys,
const float split_angle,
bool *sharp_edges)
@ -877,6 +882,7 @@ void BKE_edges_sharp_from_angle_set(const int numEdges,
{mloops, numLoops},
loop_to_poly,
{reinterpret_cast<const float3 *>(poly_normals), numPolys},
Span<bool>(sharp_faces, sharp_faces ? numPolys : 0),
Span<bool>(sharp_edges, numEdges),
true,
split_angle,
@ -1442,6 +1448,7 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3],
const bool use_split_normals,
const float split_angle,
const bool *sharp_edges,
const bool *sharp_faces,
const int *loop_to_poly_map,
MLoopNorSpaceArray *r_lnors_spacearr,
short (*clnors_data)[2])
@ -1465,7 +1472,7 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3],
const MPoly &poly = polys[poly_index];
int ml_index = poly.loopstart;
const int ml_index_end = ml_index + poly.totloop;
const bool is_poly_flat = ((poly.flag & ME_SMOOTH) == 0);
const bool is_poly_flat = sharp_faces && sharp_faces[poly_index];
for (; ml_index < ml_index_end; ml_index++) {
if (is_poly_flat) {
@ -1555,6 +1562,7 @@ void BKE_mesh_normals_loop_split(const float (*vert_positions)[3],
loops,
loop_to_poly,
{reinterpret_cast<const float3 *>(poly_normals), numPolys},
Span<bool>(sharp_faces, sharp_faces ? numPolys : 0),
Span<bool>(sharp_edges, sharp_edges ? numEdges : 0),
check_angle,
split_angle,
@ -1605,6 +1613,7 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3],
const int numLoops,
const MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
const int numPolys,
MutableSpan<bool> sharp_edges,
short (*r_clnors_data)[2],
@ -1646,6 +1655,7 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3],
use_split_normals,
split_angle,
sharp_edges.data(),
sharp_faces,
loop_to_poly.data(),
&lnors_spacearr,
nullptr);
@ -1774,6 +1784,7 @@ static void mesh_normals_loop_custom_set(const float (*positions)[3],
use_split_normals,
split_angle,
sharp_edges.data(),
sharp_faces,
loop_to_poly.data(),
&lnors_spacearr,
nullptr);
@ -1848,6 +1859,7 @@ void BKE_mesh_normals_loop_custom_set(const float (*vert_positions)[3],
const int numLoops,
const MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
const int numPolys,
bool *sharp_edges,
short (*r_clnors_data)[2])
@ -1862,6 +1874,7 @@ void BKE_mesh_normals_loop_custom_set(const float (*vert_positions)[3],
numLoops,
polys,
poly_normals,
sharp_faces,
numPolys,
{sharp_edges, numEdges},
r_clnors_data,
@ -1878,6 +1891,7 @@ void BKE_mesh_normals_loop_custom_from_verts_set(const float (*vert_positions)[3
const int numLoops,
const MPoly *polys,
const float (*poly_normals)[3],
const bool *sharp_faces,
const int numPolys,
bool *sharp_edges,
short (*r_clnors_data)[2])
@ -1892,6 +1906,7 @@ void BKE_mesh_normals_loop_custom_from_verts_set(const float (*vert_positions)[3
numLoops,
polys,
poly_normals,
sharp_faces,
numPolys,
{sharp_edges, numEdges},
r_clnors_data,
@ -1921,7 +1936,8 @@ static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const
MutableAttributeAccessor attributes = mesh->attributes_for_write();
SpanAttributeWriter<bool> sharp_edges = attributes.lookup_or_add_for_write_span<bool>(
"sharp_edge", ATTR_DOMAIN_EDGE);
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, "sharp_face"));
mesh_normals_loop_custom_set(reinterpret_cast<const float(*)[3]>(positions.data()),
BKE_mesh_vert_normals_ensure(mesh),
positions.size(),
@ -1932,6 +1948,7 @@ static void mesh_set_custom_normals(Mesh *mesh, float (*r_custom_nors)[3], const
loops.size(),
polys.data(),
BKE_mesh_poly_normals_ensure(mesh),
sharp_faces,
polys.size(),
sharp_edges.span,
clnors,

View File

@ -1361,6 +1361,8 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
if (dirty_nors_dst || do_loop_nors_dst) {
const bool *sharp_edges = static_cast<const bool *>(
CustomData_get_layer_named(&mesh_dst->edata, CD_PROP_BOOL, "sharp_edge"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh_dst->pdata, CD_PROP_BOOL, "sharp_face"));
BKE_mesh_normals_loop_split(vert_positions_dst,
BKE_mesh_vert_normals_ensure(mesh_dst),
numverts_dst,
@ -1375,6 +1377,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode,
use_split_nors_dst,
split_angle_dst,
sharp_edges,
sharp_faces,
nullptr,
nullptr,
custom_nors_dst);

View File

@ -240,7 +240,7 @@ struct SGLSLMeshToTangent {
if (precomputedLoopNormals) {
return mikk::float3(precomputedLoopNormals[loop_index]);
}
if ((polys[lt->poly].flag & ME_SMOOTH) == 0) { /* flat */
if (sharp_faces && sharp_faces[lt->poly]) { /* flat */
if (precomputedFaceNormals) {
return mikk::float3(precomputedFaceNormals[lt->poly]);
}
@ -285,6 +285,7 @@ struct SGLSLMeshToTangent {
const float (*vert_normals)[3];
const float (*orco)[3];
float (*tangent)[4]; /* destination */
const bool *sharp_faces;
int numTessFaces;
#ifdef USE_LOOPTRI_DETECT_QUADS
@ -394,6 +395,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
const MLoop *mloop,
const MLoopTri *looptri,
const uint looptri_len,
const bool *sharp_faces,
CustomData *loopdata,
bool calc_active_tangent,
@ -498,6 +500,7 @@ void BKE_mesh_calc_loop_tangent_ex(const float (*vert_positions)[3],
mesh2tangent->polys = polys;
mesh2tangent->mloop = mloop;
mesh2tangent->looptri = looptri;
mesh2tangent->sharp_faces = sharp_faces;
/* NOTE: we assume we do have tessellated loop normals at this point
* (in case it is object-enabled), have to check this is valid. */
mesh2tangent->precomputedLoopNormals = loop_normals;
@ -583,6 +586,8 @@ void BKE_mesh_calc_loop_tangents(Mesh *me_eval,
me_eval->loops().data(),
looptris.data(),
uint(looptris.size()),
static_cast<const bool *>(
CustomData_get_layer_named(&me_eval->pdata, CD_PROP_BOOL, "sharp_face")),
&me_eval->ldata,
calc_active_tangent,
tangent_names,

View File

@ -735,7 +735,7 @@ ModifierData *BKE_modifiers_get_virtual_modifierlist(const Object *ob,
Object *BKE_modifiers_is_deformed_by_armature(Object *ob)
{
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
GpencilVirtualModifierData gpencilvirtualModifierData;
ArmatureGpencilModifierData *agmd = nullptr;
GpencilModifierData *gmd = BKE_gpencil_modifiers_get_virtual_modifierlist(

View File

@ -23,6 +23,11 @@ static const aal::RelationsInNode &get_relations_in_node(const bNode &node, Reso
{
if (node.is_group()) {
if (const bNodeTree *group = reinterpret_cast<const bNodeTree *>(node.id)) {
/* Undefined tree types have no relations. */
if (!ntreeIsRegistered(group)) {
return scope.construct<aal::RelationsInNode>();
}
BLI_assert(group->runtime->anonymous_attribute_relations);
return *group->runtime->anonymous_attribute_relations;
}

View File

@ -233,7 +233,7 @@ static void object_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const in
BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps);
BKE_constraints_copy_ex(&ob_dst->constraints, &ob_src->constraints, flag_subdata, true);
ob_dst->mode = ob_dst->type != OB_GPENCIL ? OB_MODE_OBJECT : ob_dst->mode;
ob_dst->mode = ob_dst->type != OB_GPENCIL_LEGACY ? OB_MODE_OBJECT : ob_dst->mode;
ob_dst->sculpt = nullptr;
if (ob_src->pd) {
@ -1489,7 +1489,7 @@ static ParticleSystem *object_copy_modifier_particle_system_ensure(Main *bmain,
bool BKE_object_copy_modifier(
Main *bmain, Scene *scene, Object *ob_dst, const Object *ob_src, ModifierData *md_src)
{
BLI_assert(ob_dst->type != OB_GPENCIL);
BLI_assert(ob_dst->type != OB_GPENCIL_LEGACY);
const ModifierTypeInfo *mti = BKE_modifier_get_info((ModifierType)md_src->type);
if (!object_modifier_type_copy_check((ModifierType)md_src->type)) {
@ -1587,7 +1587,7 @@ bool BKE_object_copy_modifier(
bool BKE_object_copy_gpencil_modifier(struct Object *ob_dst, GpencilModifierData *gmd_src)
{
BLI_assert(ob_dst->type == OB_GPENCIL);
BLI_assert(ob_dst->type == OB_GPENCIL_LEGACY);
GpencilModifierData *gmd_dst = BKE_gpencil_modifier_new(gmd_src->type);
BLI_strncpy(gmd_dst->name, gmd_src->name, sizeof(gmd_dst->name));
@ -1607,7 +1607,7 @@ bool BKE_object_modifier_stack_copy(Object *ob_dst,
const bool do_copy_all,
const int flag_subdata)
{
if ((ob_dst->type == OB_GPENCIL) != (ob_src->type == OB_GPENCIL)) {
if ((ob_dst->type == OB_GPENCIL_LEGACY) != (ob_src->type == OB_GPENCIL_LEGACY)) {
BLI_assert_msg(0,
"Trying to copy a modifier stack between a GPencil object and another type.");
return false;
@ -1904,7 +1904,7 @@ bool BKE_object_is_in_editmode(const Object *ob)
case OB_SURF:
case OB_CURVES_LEGACY:
return ((Curve *)ob->data)->editnurb != nullptr;
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
/* Grease Pencil object has no edit mode data. */
return GPENCIL_EDIT_MODE((bGPdata *)ob->data);
case OB_CURVES:
@ -2131,7 +2131,7 @@ static const char *get_obdata_defname(int type)
return DATA_("Volume");
case OB_EMPTY:
return DATA_("Empty");
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
return DATA_("GPencil");
case OB_LIGHTPROBE:
return DATA_("LightProbe");
@ -2156,7 +2156,7 @@ static void object_init(Object *ob, const short ob_type)
ob->upflag = OB_POSY;
}
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
ob->dtx |= OB_USE_GPENCIL_LIGHTS;
}
@ -2196,7 +2196,7 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
return BKE_speaker_add(bmain, name);
case OB_LIGHTPROBE:
return BKE_lightprobe_add(bmain, name);
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
return BKE_gpencil_data_addnew(bmain, name);
case OB_CURVES:
return BKE_curves_add(bmain, name);
@ -2230,8 +2230,8 @@ int BKE_object_obdata_to_type(const ID *id)
return OB_CAMERA;
case ID_LT:
return OB_LATTICE;
case ID_GD:
return OB_GPENCIL;
case ID_GD_LEGACY:
return OB_GPENCIL_LEGACY;
case ID_AR:
return OB_ARMATURE;
case ID_LP:
@ -2558,7 +2558,7 @@ Object *BKE_object_pose_armature_get_with_wpaint_check(Object *ob)
}
break;
}
case OB_GPENCIL: {
case OB_GPENCIL_LEGACY: {
if ((ob->mode & OB_MODE_WEIGHT_GPENCIL) == 0) {
return nullptr;
}
@ -2794,7 +2794,7 @@ Object *BKE_object_duplicate(Main *bmain, Object *ob, uint dupflag, uint duplica
id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
}
break;
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
if (dupflag & USER_DUP_GPENCIL) {
id_new = BKE_id_copy_for_duplicate(bmain, id_old, dupflag, copy_flags);
}
@ -3737,7 +3737,7 @@ const BoundBox *BKE_object_boundbox_get(Object *ob)
case OB_ARMATURE:
bb = BKE_armature_boundbox_get(ob);
break;
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
bb = BKE_gpencil_boundbox_get(ob);
break;
case OB_CURVES:
@ -3889,7 +3889,7 @@ void BKE_object_minmax(Object *ob, float r_min[3], float r_max[3], const bool us
changed = true;
break;
}
case OB_GPENCIL: {
case OB_GPENCIL_LEGACY: {
const BoundBox bb = *BKE_gpencil_boundbox_get(ob);
BKE_boundbox_minmax(&bb, ob->object_to_world, r_min, r_max);
changed = true;
@ -4090,7 +4090,7 @@ bool BKE_object_minmax_empty_drawtype(const struct Object *ob, float r_min[3], f
max[0] = radius + (ofs[0] * radius);
max[1] = radius + (ofs[1] * radius);
/* Since the image aspect can shrink the bounds towards the object origin,
* adjust the min/max to account for that. */
* adjust the min/max to account for that. */
for (int i = 0; i < 2; i++) {
CLAMP_MAX(min[i], 0.0f);
CLAMP_MIN(max[i], 0.0f);
@ -4190,7 +4190,7 @@ void BKE_object_foreach_display_point(Object *ob,
func_cb(co, user_data);
}
}
else if (ob->type == OB_GPENCIL) {
else if (ob->type == OB_GPENCIL_LEGACY) {
GPencilStrokePointIterData iter_data{};
iter_data.obmat = obmat;
iter_data.point_func_cb = func_cb;
@ -5118,7 +5118,7 @@ bool BKE_object_supports_material_slots(struct Object *ob)
OB_CURVES,
OB_POINTCLOUD,
OB_VOLUME,
OB_GPENCIL);
OB_GPENCIL_LEGACY);
}
/** \} */

View File

@ -366,7 +366,7 @@ static void object_defgroup_remove_edit_mode(Object *ob, bDeformGroup *dg)
void BKE_object_defgroup_remove(Object *ob, bDeformGroup *defgroup)
{
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
BKE_gpencil_vgroup_remove(ob, defgroup);
}
else {

View File

@ -181,7 +181,7 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o
case OB_LATTICE:
BKE_lattice_modifiers_calc(depsgraph, scene, ob);
break;
case OB_GPENCIL: {
case OB_GPENCIL_LEGACY: {
BKE_gpencil_prepare_eval_data(depsgraph, scene, ob);
BKE_gpencil_modifiers_calc(depsgraph, scene, ob);
BKE_gpencil_update_layer_transforms(depsgraph, ob);
@ -303,7 +303,7 @@ void BKE_object_batch_cache_dirty_tag(Object *ob)
}
break;
}
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
BKE_gpencil_batch_cache_dirty_tag((struct bGPdata *)ob->data);
break;
case OB_CURVES:

View File

@ -2803,8 +2803,7 @@ static void sculpt_attribute_update_refs(Object *ob)
{
SculptSession *ss = ob->sculpt;
/* run twice, in case sculpt_attr_update had to recreate a layer and
messed up the bmesh offsets. */
/* Run twice, in case sculpt_attr_update had to recreate a layer and messed up #BMesh offsets. */
for (int i = 0; i < 2; i++) {
for (int j = 0; j < SCULPT_MAX_ATTRIBUTES; j++) {
SculptAttribute *attr = ss->temp_attributes + j;

View File

@ -151,19 +151,27 @@ static void update_node_vb(PBVH *pbvh, PBVHNode *node)
// BB_expand(&node->vb, co);
//}
static bool face_materials_match(const PBVH *pbvh, const int a, const int b)
static bool face_materials_match(const PBVH *pbvh,
const bool *sharp_faces,
const int a,
const int b)
{
if (pbvh->material_indices) {
if (pbvh->material_indices[a] != pbvh->material_indices[b]) {
return false;
}
}
return (pbvh->polys[a].flag & ME_SMOOTH) == (pbvh->polys[b].flag & ME_SMOOTH);
if (sharp_faces) {
if (sharp_faces[a] != sharp_faces[b]) {
return false;
}
}
return true;
}
static bool grid_materials_match(const DMFlagMat *f1, const DMFlagMat *f2)
{
return ((f1->flag & ME_SMOOTH) == (f2->flag & ME_SMOOTH) && (f1->mat_nr == f2->mat_nr));
return (f1->sharp == f2->sharp) && (f1->mat_nr == f2->mat_nr);
}
/* Adapted from BLI_kdopbvh.c */
@ -229,7 +237,7 @@ static int partition_indices_grids(int *prim_indices,
}
/* Returns the index of the first element on the right of the partition */
static int partition_indices_material(PBVH *pbvh, int lo, int hi)
static int partition_indices_material(PBVH *pbvh, const bool *sharp_faces, int lo, int hi)
{
const MLoopTri *looptri = pbvh->looptri;
const DMFlagMat *flagmats = pbvh->grid_flag_mats;
@ -239,10 +247,10 @@ static int partition_indices_material(PBVH *pbvh, int lo, int hi)
for (;;) {
if (pbvh->looptri) {
const int first = looptri[pbvh->prim_indices[lo]].poly;
for (; face_materials_match(pbvh, first, looptri[indices[i]].poly); i++) {
for (; face_materials_match(pbvh, sharp_faces, first, looptri[indices[i]].poly); i++) {
/* pass */
}
for (; !face_materials_match(pbvh, first, looptri[indices[j]].poly); j--) {
for (; !face_materials_match(pbvh, sharp_faces, first, looptri[indices[j]].poly); j--) {
/* pass */
}
}
@ -450,7 +458,7 @@ static void build_leaf(PBVH *pbvh, int node_index, BBC *prim_bbc, int offset, in
/* Return zero if all primitives in the node can be drawn with the
* same material (including flat/smooth shading), non-zero otherwise */
static bool leaf_needs_material_split(PBVH *pbvh, int offset, int count)
static bool leaf_needs_material_split(PBVH *pbvh, const bool *sharp_faces, int offset, int count)
{
if (count <= 1) {
return false;
@ -460,7 +468,7 @@ static bool leaf_needs_material_split(PBVH *pbvh, int offset, int count)
const MLoopTri *first = &pbvh->looptri[pbvh->prim_indices[offset]];
for (int i = offset + count - 1; i > offset; i--) {
int prim = pbvh->prim_indices[i];
if (!face_materials_match(pbvh, first->poly, pbvh->looptri[prim].poly)) {
if (!face_materials_match(pbvh, sharp_faces, first->poly, pbvh->looptri[prim].poly)) {
return true;
}
}
@ -539,6 +547,7 @@ static void test_face_boundaries(PBVH *pbvh)
*/
static void build_sub(PBVH *pbvh,
const bool *sharp_faces,
int node_index,
BB *cb,
BBC *prim_bbc,
@ -557,7 +566,7 @@ static void build_sub(PBVH *pbvh,
/* Decide whether this is a leaf or not */
const bool below_leaf_limit = count <= pbvh->leaf_limit || depth >= STACK_FIXED_DEPTH - 1;
if (below_leaf_limit) {
if (!leaf_needs_material_split(pbvh, offset, count)) {
if (!leaf_needs_material_split(pbvh, sharp_faces, offset, count)) {
build_leaf(pbvh, node_index, prim_bbc, offset, count);
if (node_index == 0) {
@ -610,11 +619,12 @@ static void build_sub(PBVH *pbvh,
}
else {
/* Partition primitives by material */
end = partition_indices_material(pbvh, offset, offset + count - 1);
end = partition_indices_material(pbvh, sharp_faces, offset, offset + count - 1);
}
/* Build children */
build_sub(pbvh,
sharp_faces,
pbvh->nodes[node_index].children_offset,
nullptr,
prim_bbc,
@ -623,6 +633,7 @@ static void build_sub(PBVH *pbvh,
prim_scratch,
depth + 1);
build_sub(pbvh,
sharp_faces,
pbvh->nodes[node_index].children_offset + 1,
nullptr,
prim_bbc,
@ -636,7 +647,7 @@ static void build_sub(PBVH *pbvh,
}
}
static void pbvh_build(PBVH *pbvh, BB *cb, BBC *prim_bbc, int totprim)
static void pbvh_build(PBVH *pbvh, const bool *sharp_faces, BB *cb, BBC *prim_bbc, int totprim)
{
if (totprim != pbvh->totprim) {
pbvh->totprim = totprim;
@ -659,7 +670,7 @@ static void pbvh_build(PBVH *pbvh, BB *cb, BBC *prim_bbc, int totprim)
}
pbvh->totnode = 1;
build_sub(pbvh, 0, cb, prim_bbc, 0, totprim, nullptr, 0);
build_sub(pbvh, sharp_faces, 0, cb, prim_bbc, 0, totprim, nullptr, 0);
}
static void pbvh_draw_args_init(PBVH *pbvh, PBVH_GPU_Args *args, PBVHNode *node)
@ -881,7 +892,9 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
}
if (looptri_num) {
pbvh_build(pbvh, &cb, prim_bbc, looptri_num);
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
&mesh->pdata, CD_PROP_BOOL, "sharp_face");
pbvh_build(pbvh, sharp_faces, &cb, prim_bbc, looptri_num);
#ifdef TEST_PBVH_FACE_SPLIT
test_face_boundaries(pbvh);
@ -968,7 +981,9 @@ void BKE_pbvh_build_grids(PBVH *pbvh,
}
if (totgrid) {
pbvh_build(pbvh, &cb, prim_bbc, totgrid);
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
&me->pdata, CD_PROP_BOOL, "sharp_face");
pbvh_build(pbvh, sharp_faces, &cb, prim_bbc, totgrid);
#ifdef TEST_PBVH_FACE_SPLIT
test_face_boundaries(pbvh);

View File

@ -116,6 +116,8 @@ bool BKE_shrinkwrap_init_tree(
data->mesh = mesh;
data->polys = mesh->polys().data();
data->vert_normals = BKE_mesh_vert_normals_ensure(mesh);
data->sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_face"));
if (shrinkType == MOD_SHRINKWRAP_NEAREST_VERTEX) {
data->bvh = BKE_bvhtree_from_mesh_get(&data->treeData, mesh, BVHTREE_FROM_VERTS, 2);
@ -1175,7 +1177,7 @@ void BKE_shrinkwrap_compute_smooth_normal(const ShrinkwrapTreeData *tree,
const float(*vert_normals)[3] = tree->vert_normals;
/* Interpolate smooth normals if enabled. */
if ((tree->polys[tri->poly].flag & ME_SMOOTH) != 0) {
if (!(tree->sharp_faces && tree->sharp_faces[tri->poly])) {
const uint32_t vert_indices[3] = {treeData->loop[tri->tri[0]].v,
treeData->loop[tri->tri[1]].v,
treeData->loop[tri->tri[2]].v};

View File

@ -15,7 +15,7 @@
struct CCGMaterialFromMeshData {
const Mesh *mesh;
blender::Span<MPoly> polys;
const bool *sharp_faces;
const int *material_indices;
};
@ -24,9 +24,8 @@ static DMFlagMat subdiv_ccg_material_flags_eval(
{
CCGMaterialFromMeshData *data = (CCGMaterialFromMeshData *)material_flags_evaluator->user_data;
BLI_assert(coarse_face_index < data->mesh->totpoly);
const MPoly &poly = data->polys[coarse_face_index];
DMFlagMat material_flags;
material_flags.flag = poly.flag;
material_flags.sharp = data->sharp_faces && data->sharp_faces[coarse_face_index];
material_flags.mat_nr = data->material_indices ? data->material_indices[coarse_face_index] : 0;
return material_flags;
}
@ -45,7 +44,8 @@ void BKE_subdiv_ccg_material_flags_init_from_mesh(
data->mesh = mesh;
data->material_indices = (const int *)CustomData_get_layer_named(
&mesh->pdata, CD_PROP_INT32, "material_index");
data->polys = mesh->polys();
data->sharp_faces = (const bool *)CustomData_get_layer_named(
&mesh->pdata, CD_PROP_BOOL, "sharp_face");
material_flags_evaluator->eval_material_flags = subdiv_ccg_material_flags_eval;
material_flags_evaluator->free = subdiv_ccg_material_flags_free;
material_flags_evaluator->user_data = data;

View File

@ -1068,20 +1068,17 @@ static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *polys)
int gridSize = ccgSubSurf_getGridSize(ss);
/* int edgeSize = ccgSubSurf_getEdgeSize(ss); */ /* UNUSED */
int i = 0, k = 0;
DMFlagMat *faceFlags = ccgdm->faceFlags;
totface = ccgSubSurf_getNumFaces(ss);
for (index = 0; index < totface; index++) {
CCGFace *f = ccgdm->faceMap[index].face;
int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
char flag = (faceFlags) ? faceFlags[index].flag : char(ME_SMOOTH);
for (S = 0; S < numVerts; S++) {
for (y = 0; y < gridSize - 1; y++) {
for (x = 0; x < gridSize - 1; x++) {
polys[i].loopstart = k;
polys[i].totloop = 4;
polys[i].flag = flag;
k += 4;
i++;
@ -1541,9 +1538,11 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
gridSideEdges = gridSize - 1;
gridInternalEdges = (gridSideEdges - 1) * gridSideEdges * 2;
const MPoly *polys = static_cast<const MPoly *>(CustomData_get_layer(&dm->polyData, CD_MPOLY));
const int *material_indices = static_cast<const int *>(
CustomData_get_layer_named(&dm->polyData, CD_MPOLY, "material_index"));
const bool *sharp_faces = static_cast<const bool *>(
CustomData_get_layer_named(&dm->polyData, CD_PROP_BOOL, "sharp_face"));
const int *base_polyOrigIndex = static_cast<const int *>(
CustomData_get_layer(&dm->polyData, CD_ORIGINDEX));
@ -1569,7 +1568,7 @@ static void set_ccgdm_all_geometry(CCGDerivedMesh *ccgdm,
ccgdm->faceMap[index].startEdge = edgeNum;
ccgdm->faceMap[index].startFace = faceNum;
faceFlags->flag = polys ? polys[origIndex].flag : 0;
faceFlags->sharp = sharp_faces ? sharp_faces[origIndex] : false;
faceFlags->mat_nr = material_indices ? material_indices[origIndex] : 0;
faceFlags++;

View File

@ -180,6 +180,7 @@ Mesh *volume_to_mesh(const openvdb::GridBase &grid,
mesh->loops_for_write());
BKE_mesh_calc_edges(mesh, false, false);
BKE_mesh_smooth_flag_set(mesh, false);
return mesh;
}

View File

@ -586,7 +586,7 @@ static const AVCodec *get_av1_encoder(
}
else {
/* Is not a square num, set greater side based on longer side, or use a square if both
sides are equal. */
* sides are equal. */
int sqrt_p2 = power_of_2_min_i(threads_sqrt);
if (sqrt_p2 < 2) {
/* Ensure a default minimum. */

View File

@ -79,6 +79,9 @@ template<typename T> uint64_t vector_hash(const T &vec)
template<typename T, int Size> struct VecBase : public vec_struct_base<T, Size> {
BLI_STATIC_ASSERT(alignof(T) <= sizeof(T),
"VecBase is not compatible with aligned type for now.");
static constexpr int type_length = Size;
using base_type = T;
@ -176,16 +179,36 @@ template<typename T, int Size> struct VecBase : public vec_struct_base<T, Size>
/** Swizzling. */
template<BLI_ENABLE_IF_VEC(Size, >= 3)> VecBase<T, 2> xy() const
template<BLI_ENABLE_IF_VEC(Size, >= 2)> VecBase<T, 2> xy() const
{
return *reinterpret_cast<const VecBase<T, 2> *>(this);
}
template<BLI_ENABLE_IF_VEC(Size, >= 4)> VecBase<T, 3> xyz() const
template<BLI_ENABLE_IF_VEC(Size, >= 3)> VecBase<T, 2> yz() const
{
return *reinterpret_cast<const VecBase<T, 2> *>(&((*this)[1]));
}
template<BLI_ENABLE_IF_VEC(Size, >= 4)> VecBase<T, 2> zw() const
{
return *reinterpret_cast<const VecBase<T, 2> *>(&((*this)[2]));
}
template<BLI_ENABLE_IF_VEC(Size, >= 3)> VecBase<T, 3> xyz() const
{
return *reinterpret_cast<const VecBase<T, 3> *>(this);
}
template<BLI_ENABLE_IF_VEC(Size, >= 4)> VecBase<T, 3> yzw() const
{
return *reinterpret_cast<const VecBase<T, 3> *>(&((*this)[1]));
}
template<BLI_ENABLE_IF_VEC(Size, >= 4)> VecBase<T, 4> xyzw() const
{
return *reinterpret_cast<const VecBase<T, 4> *>(this);
}
#undef BLI_ENABLE_IF_VEC
/** Conversion from pointers (from C-style vectors). */

View File

@ -10,7 +10,7 @@
#ifdef __GNUC__
/* NOTE(@ideasman42): CLANG behaves slightly differently to GCC,
* these can be enabled but do so carefully as they can introduce build-errors. */
* these can be enabled but do so carefully as they can introduce build-errors. */
# if !defined(__clang__)
# pragma GCC diagnostic error "-Wsign-compare"
# pragma GCC diagnostic error "-Wconversion"

View File

@ -259,4 +259,25 @@ TEST(math_vec_types, DivideFloatByVectorSmall)
EXPECT_FLOAT_EQ(result.y, 1.0f);
}
TEST(math_vec_types, SwizzleReinterpret)
{
const float2 v01(0, 1);
const float2 v12(1, 2);
const float2 v23(2, 3);
const float3 v012(0, 1, 2);
const float3 v123(1, 2, 3);
const float4 v0123(0, 1, 2, 3);
/* Identity. */
EXPECT_EQ(v01.xy(), v01);
EXPECT_EQ(v012.xyz(), v012);
EXPECT_EQ(v0123.xyzw(), v0123);
/* Masking. */
EXPECT_EQ(v012.xy(), v01);
EXPECT_EQ(v0123.xyz(), v012);
/* Offset. */
EXPECT_EQ(v0123.yz(), v12);
EXPECT_EQ(v0123.zw(), v23);
EXPECT_EQ(v0123.yzw(), v123);
}
} // namespace blender::tests

View File

@ -2963,7 +2963,7 @@ static const char *dataname(short id_code)
return "Data from PAL";
case ID_PC:
return "Data from PCRV";
case ID_GD:
case ID_GD_LEGACY:
return "Data from GD";
case ID_WM:
return "Data from WM";

View File

@ -431,7 +431,7 @@ static void versions_gpencil_add_main(Main *bmain, ListBase *lb, ID *id, const c
BLI_addtail(lb, id);
id->us = 1;
id->flag = LIB_FAKEUSER;
*((short *)id->name) = ID_GD;
*((short *)id->name) = ID_GD_LEGACY;
BKE_id_new_name_validate(bmain, lb, id, name, false);
/* alphabetic insertion: is in BKE_id_new_name_validate */

View File

@ -4665,7 +4665,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Fix Grease Pencil VFX and modifiers. */
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
if (ob->type != OB_GPENCIL) {
if (ob->type != OB_GPENCIL_LEGACY) {
continue;
}

View File

@ -553,7 +553,7 @@ void do_versions_after_linking_290(FileData * /*fd*/, Main *bmain)
Scene *scene = static_cast<Scene *>(bmain->scenes.first);
if (scene != nullptr) {
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
if (ob->type != OB_GPENCIL) {
if (ob->type != OB_GPENCIL_LEGACY) {
continue;
}
bGPdata *gpd = static_cast<bGPdata *>(ob->data);

View File

@ -14,6 +14,7 @@
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
#include "BLI_multi_value_map.hh"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BLI_string_utils.h"
@ -385,7 +386,7 @@ static void assert_sorted_ids(Main *bmain)
static void move_vertex_group_names_to_object_data(Main *bmain)
{
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (ELEM(object->type, OB_MESH, OB_LATTICE, OB_GPENCIL)) {
if (ELEM(object->type, OB_MESH, OB_LATTICE, OB_GPENCIL_LEGACY)) {
ListBase *new_defbase = BKE_object_defgroup_list_mutable(object);
/* Choose the longest vertex group name list among all linked duplicates. */
@ -940,6 +941,139 @@ static void version_geometry_nodes_primitive_uv_maps(bNodeTree &ntree)
}
}
/**
* When extruding from loose edges, the extrude geometry node used to create flat faces due to the
* default of the old "shade_smooth" attribute. Since the "false" value has changed with the
* "sharp_face" attribute, add nodes to propagate the new attribute in its inverted "smooth" form.
*/
static void version_geometry_nodes_extrude_smooth_propagation(bNodeTree &ntree)
{
using namespace blender;
Vector<bNode *> new_nodes;
LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree.nodes) {
if (node->idname != StringRef("GeometryNodeExtrudeMesh")) {
continue;
}
if (static_cast<const NodeGeometryExtrudeMesh *>(node->storage)->mode !=
GEO_NODE_EXTRUDE_MESH_EDGES) {
continue;
}
bNodeSocket *geometry_in_socket = nodeFindSocket(node, SOCK_IN, "Mesh");
bNodeSocket *geometry_out_socket = nodeFindSocket(node, SOCK_OUT, "Mesh");
Map<bNodeSocket *, bNodeLink *> in_links_per_socket;
MultiValueMap<bNodeSocket *, bNodeLink *> out_links_per_socket;
LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) {
in_links_per_socket.add(link->tosock, link);
out_links_per_socket.add(link->fromsock, link);
}
bNodeLink *geometry_in_link = in_links_per_socket.lookup_default(geometry_in_socket, nullptr);
Span<bNodeLink *> geometry_out_links = out_links_per_socket.lookup(geometry_out_socket);
if (!geometry_in_link || geometry_out_links.is_empty()) {
continue;
}
const bool versioning_already_done = [&]() {
if (geometry_in_link->fromnode->idname != StringRef("GeometryNodeCaptureAttribute")) {
return false;
}
bNode *capture_node = geometry_in_link->fromnode;
const NodeGeometryAttributeCapture &capture_storage =
*static_cast<const NodeGeometryAttributeCapture *>(capture_node->storage);
if (capture_storage.data_type != CD_PROP_BOOL ||
capture_storage.domain != ATTR_DOMAIN_FACE) {
return false;
}
bNodeSocket *capture_in_socket = nodeFindSocket(capture_node, SOCK_IN, "Value_003");
bNodeLink *capture_in_link = in_links_per_socket.lookup_default(capture_in_socket, nullptr);
if (!capture_in_link) {
return false;
}
if (capture_in_link->fromnode->idname != StringRef("GeometryNodeInputShadeSmooth")) {
return false;
}
if (geometry_out_links.size() != 1) {
return false;
}
bNodeLink *geometry_out_link = geometry_out_links.first();
if (geometry_out_link->tonode->idname != StringRef("GeometryNodeSetShadeSmooth")) {
return false;
}
bNode *set_smooth_node = geometry_out_link->tonode;
bNodeSocket *smooth_in_socket = nodeFindSocket(set_smooth_node, SOCK_IN, "Shade Smooth");
bNodeLink *connecting_link = in_links_per_socket.lookup_default(smooth_in_socket, nullptr);
if (!connecting_link) {
return false;
}
if (connecting_link->fromnode != capture_node) {
return false;
}
return true;
}();
if (versioning_already_done) {
continue;
}
bNode *capture_node = nodeAddNode(nullptr, &ntree, "GeometryNodeCaptureAttribute");
capture_node->parent = node->parent;
capture_node->locx = node->locx - 25;
capture_node->locy = node->locy;
new_nodes.append(capture_node);
static_cast<NodeGeometryAttributeCapture *>(capture_node->storage)->data_type = CD_PROP_BOOL;
static_cast<NodeGeometryAttributeCapture *>(capture_node->storage)->domain = ATTR_DOMAIN_FACE;
bNode *is_smooth_node = nodeAddNode(nullptr, &ntree, "GeometryNodeInputShadeSmooth");
is_smooth_node->parent = node->parent;
is_smooth_node->locx = capture_node->locx - 25;
is_smooth_node->locy = capture_node->locy;
new_nodes.append(is_smooth_node);
nodeAddLink(&ntree,
is_smooth_node,
nodeFindSocket(is_smooth_node, SOCK_OUT, "Smooth"),
capture_node,
nodeFindSocket(capture_node, SOCK_IN, "Value_003"));
nodeAddLink(&ntree,
capture_node,
nodeFindSocket(capture_node, SOCK_OUT, "Geometry"),
capture_node,
geometry_in_socket);
geometry_in_link->tonode = capture_node;
geometry_in_link->tosock = nodeFindSocket(capture_node, SOCK_IN, "Geometry");
bNode *set_smooth_node = nodeAddNode(nullptr, &ntree, "GeometryNodeSetShadeSmooth");
set_smooth_node->parent = node->parent;
set_smooth_node->locx = node->locx + 25;
set_smooth_node->locy = node->locy;
new_nodes.append(set_smooth_node);
nodeAddLink(&ntree,
node,
geometry_out_socket,
set_smooth_node,
nodeFindSocket(set_smooth_node, SOCK_IN, "Geometry"));
bNodeSocket *smooth_geometry_out = nodeFindSocket(set_smooth_node, SOCK_OUT, "Geometry");
for (bNodeLink *link : geometry_out_links) {
link->fromnode = set_smooth_node;
link->fromsock = smooth_geometry_out;
}
nodeAddLink(&ntree,
capture_node,
nodeFindSocket(capture_node, SOCK_OUT, "Attribute_003"),
set_smooth_node,
nodeFindSocket(set_smooth_node, SOCK_IN, "Shade Smooth"));
}
/* Move nodes to the front so that they are drawn behind existing nodes. */
for (bNode *node : new_nodes) {
BLI_remlink(&ntree.nodes, node);
BLI_addhead(&ntree.nodes, node);
}
if (!new_nodes.is_empty()) {
nodeRebuildIDVector(&ntree);
}
}
void do_versions_after_linking_300(FileData * /*fd*/, Main *bmain)
{
if (MAIN_VERSION_ATLEAST(bmain, 300, 0) && !MAIN_VERSION_ATLEAST(bmain, 300, 1)) {
@ -1044,7 +1178,7 @@ void do_versions_after_linking_300(FileData * /*fd*/, Main *bmain)
if (!MAIN_VERSION_ATLEAST(bmain, 300, 33)) {
/* This was missing from #move_vertex_group_names_to_object_data. */
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (ELEM(object->type, OB_MESH, OB_LATTICE, OB_GPENCIL)) {
if (ELEM(object->type, OB_MESH, OB_LATTICE, OB_GPENCIL_LEGACY)) {
/* This uses the fact that the active vertex group index starts counting at 1. */
if (BKE_object_defgroup_active_index_get(object) == 0) {
BKE_object_defgroup_active_index_set(object, object->actdef);
@ -2347,7 +2481,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
}
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
if (md->type == eGpencilModifierType_Lineart) {
LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
@ -2542,7 +2676,7 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
if (!DNA_struct_elem_find(
fd->filesdna, "LineartGpencilModifierData", "bool", "use_crease_on_smooth")) {
LISTBASE_FOREACH (Object *, ob, &bmain->objects) {
if (ob->type == OB_GPENCIL) {
if (ob->type == OB_GPENCIL_LEGACY) {
LISTBASE_FOREACH (GpencilModifierData *, md, &ob->greasepencil_modifiers) {
if (md->type == eGpencilModifierType_Lineart) {
LineartGpencilModifierData *lmd = (LineartGpencilModifierData *)md;
@ -4047,5 +4181,10 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, Main *bmain)
}
}
/* Keep this block, even when empty. */
LISTBASE_FOREACH (bNodeTree *, ntree, &bmain->nodetrees) {
if (ntree->type == NTREE_GEOMETRY) {
version_geometry_nodes_extrude_smooth_propagation(*ntree);
}
}
}
}

View File

@ -31,6 +31,7 @@ static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh)
BKE_mesh_legacy_convert_flags_to_hide_layers(&mesh);
BKE_mesh_legacy_convert_uvs_to_generic(&mesh);
BKE_mesh_legacy_convert_mpoly_to_material_indices(&mesh);
BKE_mesh_legacy_sharp_faces_from_flags(&mesh);
BKE_mesh_legacy_bevel_weight_to_layers(&mesh);
BKE_mesh_legacy_sharp_edges_from_flags(&mesh);
BKE_mesh_legacy_face_set_to_generic(&mesh);

View File

@ -464,7 +464,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
Object *ob = static_cast<Object *>(
BLI_findstring(&bmain->objects, "Stroke", offsetof(ID, name) + 2));
if (ob && ob->type == OB_GPENCIL) {
if (ob && ob->type == OB_GPENCIL_LEGACY) {
ob->dtx |= OB_USE_GPENCIL_LIGHTS;
}
}
@ -550,7 +550,7 @@ void BLO_update_defaults_startup_blend(Main *bmain, const char *app_template)
if (app_template && STREQ(app_template, "2D_Animation")) {
LISTBASE_FOREACH (Object *, object, &bmain->objects) {
if (object->type == OB_GPENCIL) {
if (object->type == OB_GPENCIL_LEGACY) {
/* Set grease pencil object in drawing mode */
bGPdata *gpd = (bGPdata *)object->data;
object->mode = OB_MODE_PAINT_GPENCIL;

View File

@ -783,6 +783,10 @@ void blo_do_versions_userdef(UserDef *userdef)
}
}
if (!USER_VERSION_ATLEAST(306, 2)) {
userdef->animation_flag |= USER_ANIM_HIGH_QUALITY_DRAWING;
}
/**
* Versioning code until next subversion bump goes here.
*

View File

@ -113,18 +113,6 @@ using blender::Span;
using blender::StringRef;
using blender::Vector;
static char bm_face_flag_from_mflag(const char mflag)
{
return ((mflag & ME_SMOOTH) ? BM_ELEM_SMOOTH : 0);
}
static char bm_face_flag_to_mflag(const BMFace *f)
{
const char hflag = f->head.hflag;
return ((hflag & BM_ELEM_SMOOTH) ? ME_SMOOTH : 0);
}
bool BM_attribute_stored_in_bmesh_builtin(const StringRef name)
{
return ELEM(name,
@ -137,6 +125,7 @@ bool BM_attribute_stored_in_bmesh_builtin(const StringRef name)
".select_edge",
".select_poly",
"material_index",
"sharp_face",
"sharp_edge");
}
@ -426,6 +415,8 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
&me->pdata, CD_PROP_BOOL, ".hide_poly");
const int *material_indices = (const int *)CustomData_get_layer_named(
&me->pdata, CD_PROP_INT32, "material_index");
const bool *sharp_faces = (const bool *)CustomData_get_layer_named(
&me->pdata, CD_PROP_BOOL, "sharp_face");
const bool *sharp_edges = (const bool *)CustomData_get_layer_named(
&me->edata, CD_PROP_BOOL, "sharp_edge");
const bool *uv_seams = (const bool *)CustomData_get_layer_named(
@ -527,7 +518,9 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar
BM_elem_index_set(f, bm->totface - 1); /* set_ok */
/* Transfer flag. */
f->head.hflag = bm_face_flag_from_mflag(polys[i].flag);
if (!(sharp_faces && sharp_faces[i])) {
BM_elem_flag_enable(f, BM_ELEM_SMOOTH);
}
if (hide_poly && hide_poly[i]) {
BM_elem_flag_enable(f, BM_ELEM_HIDDEN);
}
@ -1252,6 +1245,7 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
bool need_hide_edge = false;
bool need_hide_poly = false;
bool need_material_index = false;
bool need_sharp_face = false;
bool need_sharp_edge = false;
bool need_uv_seam = false;
@ -1312,7 +1306,9 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
if (f->mat_nr != 0) {
need_material_index = true;
}
polys[i].flag = bm_face_flag_to_mflag(f);
if (!BM_elem_flag_test(f, BM_ELEM_SMOOTH)) {
need_sharp_face = true;
}
if (BM_elem_flag_test(f, BM_ELEM_HIDDEN)) {
need_hide_poly = true;
}
@ -1357,6 +1353,13 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh
return !BM_elem_flag_test(BM_edge_at_index(bm, i), BM_ELEM_SMOOTH);
});
}
if (need_sharp_face) {
BM_mesh_elem_table_ensure(bm, BM_FACE);
write_fn_to_attribute<bool>(
me->attributes_for_write(), "sharp_face", ATTR_DOMAIN_FACE, [&](const int i) {
return !BM_elem_flag_test(BM_face_at_index(bm, i), BM_ELEM_SMOOTH);
});
}
if (need_uv_seam) {
BM_mesh_elem_table_ensure(bm, BM_EDGE);
write_fn_to_attribute<bool>(
@ -1524,6 +1527,7 @@ static void bm_face_loop_table_build(BMesh &bm,
MutableSpan<const BMLoop *> loop_table,
bool &need_select_poly,
bool &need_hide_poly,
bool &need_sharp_face,
bool &need_material_index)
{
char hflag = 0;
@ -1535,6 +1539,7 @@ static void bm_face_loop_table_build(BMesh &bm,
BM_elem_index_set(face, face_i); /* set_inline */
face_table[face_i] = face;
hflag |= face->head.hflag;
need_sharp_face |= (face->head.hflag & BM_ELEM_SMOOTH) == 0;
need_material_index |= face->mat_nr != 0;
BMLoop *loop = BM_FACE_FIRST_LOOP(face);
@ -1622,6 +1627,7 @@ static void bm_to_mesh_faces(const BMesh &bm,
Mesh &mesh,
MutableSpan<bool> select_poly,
MutableSpan<bool> hide_poly,
MutableSpan<bool> sharp_faces,
MutableSpan<int> material_indices)
{
const Vector<BMeshToMeshLayerInfo> info = bm_to_mesh_copy_info_calc(bm.pdata, mesh.pdata);
@ -1632,7 +1638,6 @@ static void bm_to_mesh_faces(const BMesh &bm,
MPoly &dst_poly = dst_polys[face_i];
dst_poly.totloop = src_face.len;
dst_poly.loopstart = BM_elem_index_get(BM_FACE_FIRST_LOOP(&src_face));
dst_poly.flag = bm_face_flag_to_mflag(&src_face);
bmesh_block_copy_to_mesh_attributes(info, face_i, src_face.head.data);
}
if (!select_poly.is_empty()) {
@ -1650,6 +1655,11 @@ static void bm_to_mesh_faces(const BMesh &bm,
material_indices[face_i] = bm_faces[face_i]->mat_nr;
}
}
if (!sharp_faces.is_empty()) {
for (const int face_i : range) {
sharp_faces[face_i] = !BM_elem_flag_test(bm_faces[face_i], BM_ELEM_SMOOTH);
}
}
});
}
@ -1721,6 +1731,7 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
bool need_hide_poly = false;
bool need_material_index = false;
bool need_sharp_edge = false;
bool need_sharp_face = false;
bool need_uv_seams = false;
Array<const BMVert *> vert_table;
Array<const BMEdge *> edge_table;
@ -1740,8 +1751,13 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
[&]() {
face_table.reinitialize(bm->totface);
loop_table.reinitialize(bm->totloop);
bm_face_loop_table_build(
*bm, face_table, loop_table, need_select_poly, need_hide_poly, need_material_index);
bm_face_loop_table_build(*bm,
face_table,
loop_table,
need_select_poly,
need_hide_poly,
need_sharp_face,
need_material_index);
});
bm->elem_index_dirty &= ~(BM_VERT | BM_EDGE | BM_FACE | BM_LOOP);
@ -1756,6 +1772,7 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
bke::SpanAttributeWriter<bool> uv_seams;
bke::SpanAttributeWriter<bool> select_poly;
bke::SpanAttributeWriter<bool> hide_poly;
bke::SpanAttributeWriter<bool> sharp_face;
bke::SpanAttributeWriter<int> material_index;
if (need_select_vert) {
select_vert = attrs.lookup_or_add_for_write_only_span<bool>(".select_vert", ATTR_DOMAIN_POINT);
@ -1781,6 +1798,9 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
if (need_hide_poly) {
hide_poly = attrs.lookup_or_add_for_write_only_span<bool>(".hide_poly", ATTR_DOMAIN_FACE);
}
if (need_sharp_face) {
sharp_face = attrs.lookup_or_add_for_write_only_span<bool>("sharp_face", ATTR_DOMAIN_FACE);
}
if (need_material_index) {
material_index = attrs.lookup_or_add_for_write_only_span<int>("material_index",
ATTR_DOMAIN_FACE);
@ -1800,8 +1820,13 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
uv_seams.span);
},
[&]() {
bm_to_mesh_faces(
*bm, face_table, *me, select_poly.span, hide_poly.span, material_index.span);
bm_to_mesh_faces(*bm,
face_table,
*me,
select_poly.span,
hide_poly.span,
sharp_face.span,
material_index.span);
},
[&]() { bm_to_mesh_loops(*bm, loop_table, *me); });
@ -1813,5 +1838,6 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks *
uv_seams.finish();
select_poly.finish();
hide_poly.finish();
sharp_face.finish();
material_index.finish();
}

View File

@ -274,7 +274,7 @@ static BMOpDefine bmo_reverse_faces_def = {
* Flip Quad Tessellation
*
* Flip the tessellation direction of the selected quads.
*/
*/
static BMOpDefine bmo_flip_quad_tessellation_def = {
"flip_quad_tessellation",
/* slot_in */

View File

@ -30,7 +30,7 @@ namespace blender::compositor {
* - Distance between the center of the image and the pixel to be evaluated.
* - Distance between the center of the image and the outer-edge.
* - Distance between the center of the image and the inner-edge.
*
* With a simple compare it can be detected if the evaluated pixel is between the outer and inner
* edge.
*/

View File

@ -102,7 +102,7 @@ void GaussianAlphaBlurBaseOperation::update_memory_buffer_partial(MemoryBuffer *
const int coord_min = max_ii(coord - filtersize_, min_input_coord);
const int coord_max = min_ii(coord + filtersize_ + 1, max_input_coord);
/* *** This is the main part which is different to #GaussianBlurBaseOperation. *** */
/* *** This is the main part which is different to #GaussianBlurBaseOperation. *** */
/* Gauss. */
float alpha_accum = 0.0f;
float multiplier_accum = 0.0f;

View File

@ -155,7 +155,7 @@ struct PersistentOperationKey : public OperationKey {
component_name_storage_ = component_node->name;
name_storage_ = operation_node->name;
/* Assign fields used by the #OperationKey API. */
/* Assign fields used by the #OperationKey API. */
id = id_node->id_orig;
component_type = component_node->type;
component_name = component_name_storage_.c_str();

View File

@ -604,7 +604,7 @@ void DepsgraphNodeBuilder::build_id(ID *id)
case ID_MB:
case ID_CU_LEGACY:
case ID_LT:
case ID_GD:
case ID_GD_LEGACY:
case ID_CV:
case ID_PT:
case ID_VO:
@ -933,7 +933,7 @@ void DepsgraphNodeBuilder::build_object_data(Object *object)
case OB_SURF:
case OB_MBALL:
case OB_LATTICE:
case OB_GPENCIL:
case OB_GPENCIL_LEGACY:
case OB_CURVES:
case OB_POINTCLOUD:
case OB_VOLUME:
@ -1616,7 +1616,7 @@ void DepsgraphNodeBuilder::build_object_data_geometry_datablock(ID *obdata)
break;
}
case ID_GD: {
case ID_GD_LEGACY: {
/* GPencil evaluation operations. */
op_node = add_operation_node(obdata,
NodeType::GEOMETRY,

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