Cleanup: Return Vector for View Layer objects and bases retrieval

This simplifies code using these functions because of RAII,
range based for loops, and the lack of output arguments.
Also pass object pointer array as a span in more cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/117482
This commit is contained in:
Hans Goudey 2024-01-24 18:18:14 +01:00 committed by Hans Goudey
parent d02d6ec4e5
commit 9ab356fe6e
79 changed files with 1657 additions and 2750 deletions

View File

@ -8,6 +8,8 @@
* \ingroup bke
*/
#include "BLI_vector.hh"
#include "BKE_collection.h"
#include "DNA_layer_types.h"
@ -478,8 +480,8 @@ struct ObjectsInViewLayerParams {
void *filter_userdata;
};
struct Object **BKE_view_layer_array_selected_objects_params(
ViewLayer *view_layer, const View3D *v3d, uint *r_len, const ObjectsInViewLayerParams *params);
blender::Vector<Object *> BKE_view_layer_array_selected_objects_params(
ViewLayer *view_layer, const View3D *v3d, const ObjectsInViewLayerParams *params);
/**
* Use this in rare cases we need to detect a pair of objects (active, selected).
@ -500,46 +502,38 @@ struct ObjectsInModeParams {
void *filter_userdata;
};
Base **BKE_view_layer_array_from_bases_in_mode_params(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len,
const ObjectsInModeParams *params);
blender::Vector<Base *> BKE_view_layer_array_from_bases_in_mode_params(
const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
const ObjectsInModeParams *params);
Object **BKE_view_layer_array_from_objects_in_mode_params(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *len,
const ObjectsInModeParams *params);
blender::Vector<Object *> BKE_view_layer_array_from_objects_in_mode_params(
const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
const ObjectsInModeParams *params);
bool BKE_view_layer_filter_edit_mesh_has_uvs(const Object *ob, void *user_data);
bool BKE_view_layer_filter_edit_mesh_has_edges(const Object *ob, void *user_data);
/* Utility functions that wrap common arguments (add more as needed). */
Object **BKE_view_layer_array_from_objects_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len);
Base **BKE_view_layer_array_from_bases_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len);
Object **BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len);
blender::Vector<Object *> BKE_view_layer_array_from_objects_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d);
blender::Vector<Base *> BKE_view_layer_array_from_bases_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d);
blender::Vector<Object *> BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d);
Base **BKE_view_layer_array_from_bases_in_edit_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len);
Object **BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len);
Object **BKE_view_layer_array_from_objects_in_mode_unique_data(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d, uint *r_len, eObjectMode mode);
blender::Vector<Base *> BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d);
blender::Vector<Object *> BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d);
blender::Vector<Object *> BKE_view_layer_array_from_objects_in_mode_unique_data(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d, eObjectMode mode);
Object *BKE_view_layer_active_object_get(const ViewLayer *view_layer);
Object *BKE_view_layer_edit_object_get(const ViewLayer *view_layer);

View File

@ -1,8 +1,11 @@
/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BLI_span.hh"
/** \file
* \ingroup bke
*/
@ -18,7 +21,7 @@ struct Scene;
MetaBall *BKE_mball_add(Main *bmain, const char *name);
bool BKE_mball_is_any_selected(const MetaBall *mb);
bool BKE_mball_is_any_selected_multi(Base **bases, int bases_len);
bool BKE_mball_is_any_selected_multi(blender::Span<Base *> bases);
bool BKE_mball_is_any_unselected(const MetaBall *mb);
/**
@ -82,13 +85,13 @@ MetaElem *BKE_mball_element_add(MetaBall *mb, int type);
/* *** Select functions *** */
int BKE_mball_select_count(const MetaBall *mb);
int BKE_mball_select_count_multi(Base **bases, int bases_len);
int BKE_mball_select_count_multi(blender::Span<Base *> bases);
bool BKE_mball_select_all(MetaBall *mb);
bool BKE_mball_select_all_multi_ex(Base **bases, int bases_len);
bool BKE_mball_select_all_multi_ex(blender::Span<Base *> bases);
bool BKE_mball_deselect_all(MetaBall *mb);
bool BKE_mball_deselect_all_multi_ex(Base **bases, int bases_len);
bool BKE_mball_deselect_all_multi_ex(blender::Span<Base *> bases);
bool BKE_mball_select_swap(MetaBall *mb);
bool BKE_mball_select_swap_multi_ex(Base **bases, int bases_len);
bool BKE_mball_select_swap_multi_ex(blender::Span<Base *> bases);
/* **** Depsgraph evaluation **** */

View File

@ -15,6 +15,7 @@
#include "BLI_compiler_attrs.h"
#include "BLI_math_vector_types.hh"
#include "BLI_sys_types.h"
#include "BLI_vector.hh"
#include "DNA_object_enums.h"
#include "DNA_userdef_enums.h"
@ -292,33 +293,27 @@ Object *BKE_object_pose_armature_get_visible(Object *ob,
/**
* Access pose array with special check to get pose object when in weight paint mode.
*/
Object **BKE_object_pose_array_get_ex(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
unsigned int *r_objects_len,
bool unique);
Object **BKE_object_pose_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
unsigned int *r_objects_len);
Object **BKE_object_pose_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
unsigned int *r_objects_len);
blender::Vector<Object *> BKE_object_pose_array_get_ex(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
bool unique);
blender::Vector<Object *> BKE_object_pose_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d);
blender::Vector<Object *> BKE_object_pose_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d);
Base **BKE_object_pose_base_array_get_ex(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
unsigned int *r_bases_len,
bool unique);
Base **BKE_object_pose_base_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
unsigned int *r_bases_len);
Base **BKE_object_pose_base_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
unsigned int *r_bases_len);
blender::Vector<Base *> BKE_object_pose_base_array_get_ex(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
bool unique);
blender::Vector<Base *> BKE_object_pose_base_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d);
blender::Vector<Base *> BKE_object_pose_base_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d);
void BKE_object_get_parent_matrix(Object *ob, Object *par, float r_parentmat[4][4]);

View File

@ -27,10 +27,10 @@
/** \name Selected Object Array
* \{ */
Object **BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer,
const View3D *v3d,
uint *r_len,
const ObjectsInViewLayerParams *params)
using blender::Vector;
Vector<Object *> BKE_view_layer_array_selected_objects_params(
ViewLayer *view_layer, const View3D *v3d, const ObjectsInViewLayerParams *params)
{
if (params->no_dup_data) {
FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
@ -42,8 +42,7 @@ Object **BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer,
FOREACH_SELECTED_OBJECT_END;
}
Object **object_array = nullptr;
BLI_array_declare(object_array);
Vector<Object *> objects;
FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob_iter) {
if (params->filter_fn) {
@ -64,19 +63,11 @@ Object **BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer,
}
}
BLI_array_append(object_array, ob_iter);
objects.append(ob_iter);
}
FOREACH_SELECTED_OBJECT_END;
if (object_array != nullptr) {
BLI_array_trim(object_array);
}
else {
/* We always need a valid allocation (prevent crash on free). */
object_array = static_cast<Object **>(MEM_mallocN(0, __func__));
}
*r_len = BLI_array_len(object_array);
return object_array;
return objects;
}
/** \} */
@ -85,11 +76,10 @@ Object **BKE_view_layer_array_selected_objects_params(ViewLayer *view_layer,
/** \name Objects in Mode Array
* \{ */
Base **BKE_view_layer_array_from_bases_in_mode_params(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len,
const ObjectsInModeParams *params)
Vector<Base *> BKE_view_layer_array_from_bases_in_mode_params(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
const ObjectsInModeParams *params)
{
if (params->no_dup_data) {
FOREACH_BASE_IN_MODE_BEGIN (scene, view_layer, v3d, -1, params->object_mode, base_iter) {
@ -101,8 +91,7 @@ Base **BKE_view_layer_array_from_bases_in_mode_params(const Scene *scene,
FOREACH_BASE_IN_MODE_END;
}
Base **base_array = nullptr;
BLI_array_declare(base_array);
Vector<Base *> bases;
FOREACH_BASE_IN_MODE_BEGIN (scene, view_layer, v3d, -1, params->object_mode, base_iter) {
if (params->filter_fn) {
@ -121,101 +110,84 @@ Base **BKE_view_layer_array_from_bases_in_mode_params(const Scene *scene,
}
}
}
BLI_array_append(base_array, base_iter);
bases.append(base_iter);
}
FOREACH_BASE_IN_MODE_END;
/* We always need a valid allocation (prevent crash on free). */
if (base_array != nullptr) {
BLI_array_trim(base_array);
}
else {
base_array = static_cast<Base **>(MEM_mallocN(0, __func__));
}
*r_len = BLI_array_len(base_array);
return base_array;
return bases;
}
Object **BKE_view_layer_array_from_objects_in_mode_params(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len,
const ObjectsInModeParams *params)
Vector<Object *> BKE_view_layer_array_from_objects_in_mode_params(
const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
const ObjectsInModeParams *params)
{
Base **base_array = BKE_view_layer_array_from_bases_in_mode_params(
scene, view_layer, v3d, r_len, params);
if (base_array != nullptr) {
for (uint i = 0; i < *r_len; i++) {
((Object **)base_array)[i] = base_array[i]->object;
}
}
return (Object **)base_array;
const Vector<Base *> bases = BKE_view_layer_array_from_bases_in_mode_params(
scene, view_layer, v3d, params);
Vector<Object *> objects(bases.size());
std::transform(
bases.begin(), bases.end(), objects.begin(), [](Base *base) { return base->object; });
return objects;
}
Object **BKE_view_layer_array_from_objects_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, r_len, &params);
}
Base **BKE_view_layer_array_from_bases_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
return BKE_view_layer_array_from_bases_in_mode_params(scene, view_layer, v3d, r_len, &params);
}
Object **BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
params.no_dup_data = true;
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, r_len, &params);
}
Base **BKE_view_layer_array_from_bases_in_edit_mode_unique_data(const Scene *scene,
Vector<Object *> BKE_view_layer_array_from_objects_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len)
const View3D *v3d)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, &params);
}
Vector<Base *> BKE_view_layer_array_from_bases_in_edit_mode(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
return BKE_view_layer_array_from_bases_in_mode_params(scene, view_layer, v3d, &params);
}
Vector<Object *> BKE_view_layer_array_from_objects_in_edit_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
params.no_dup_data = true;
return BKE_view_layer_array_from_bases_in_mode_params(scene, view_layer, v3d, r_len, &params);
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, &params);
}
Object **BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len)
Vector<Base *> BKE_view_layer_array_from_bases_in_edit_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
params.no_dup_data = true;
return BKE_view_layer_array_from_bases_in_mode_params(scene, view_layer, v3d, &params);
}
Vector<Object *> BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
{
ObjectsInModeParams params = {0};
params.object_mode = OB_MODE_EDIT;
params.no_dup_data = true;
params.filter_fn = BKE_view_layer_filter_edit_mesh_has_uvs;
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, r_len, &params);
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, &params);
}
Object **BKE_view_layer_array_from_objects_in_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
uint *r_len,
const eObjectMode mode)
Vector<Object *> BKE_view_layer_array_from_objects_in_mode_unique_data(const Scene *scene,
ViewLayer *view_layer,
const View3D *v3d,
const eObjectMode mode)
{
ObjectsInModeParams params = {0};
params.object_mode = mode;
params.no_dup_data = true;
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, r_len, &params);
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, &params);
}
ListBase *BKE_view_layer_object_bases_get(ViewLayer *view_layer)

View File

@ -60,6 +60,8 @@
#include "BLO_read_write.hh"
using blender::Span;
static void metaball_init_data(ID *id)
{
MetaBall *metaball = (MetaBall *)id;
@ -280,10 +282,10 @@ bool BKE_mball_is_any_selected(const MetaBall *mb)
return false;
}
bool BKE_mball_is_any_selected_multi(Base **bases, int bases_len)
bool BKE_mball_is_any_selected_multi(const Span<Base *> bases)
{
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
if (BKE_mball_is_any_selected(mb)) {
return true;
@ -540,11 +542,11 @@ int BKE_mball_select_count(const MetaBall *mb)
return sel;
}
int BKE_mball_select_count_multi(Base **bases, int bases_len)
int BKE_mball_select_count_multi(const Span<Base *> bases)
{
int sel = 0;
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
const Object *obedit = bases[ob_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
const MetaBall *mb = (MetaBall *)obedit->data;
sel += BKE_mball_select_count(mb);
}
@ -563,11 +565,11 @@ bool BKE_mball_select_all(MetaBall *mb)
return changed;
}
bool BKE_mball_select_all_multi_ex(Base **bases, int bases_len)
bool BKE_mball_select_all_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
Object *obedit = bases[ob_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = static_cast<MetaBall *>(obedit->data);
changed_multi |= BKE_mball_select_all(mb);
}
@ -586,11 +588,11 @@ bool BKE_mball_deselect_all(MetaBall *mb)
return changed;
}
bool BKE_mball_deselect_all_multi_ex(Base **bases, int bases_len)
bool BKE_mball_deselect_all_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
Object *obedit = bases[ob_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = static_cast<MetaBall *>(obedit->data);
changed_multi |= BKE_mball_deselect_all(mb);
DEG_id_tag_update(&mb->id, ID_RECALC_SELECT);
@ -608,11 +610,11 @@ bool BKE_mball_select_swap(MetaBall *mb)
return changed;
}
bool BKE_mball_select_swap_multi_ex(Base **bases, int bases_len)
bool BKE_mball_select_swap_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint ob_index = 0; ob_index < bases_len; ob_index++) {
Object *obedit = bases[ob_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
changed_multi |= BKE_mball_select_swap(mb);
}

View File

@ -153,6 +153,7 @@ using blender::Bounds;
using blender::float3;
using blender::MutableSpan;
using blender::Span;
using blender::Vector;
static CLG_LogRef LOG = {"bke.object"};
@ -2443,55 +2444,47 @@ Object *BKE_object_pose_armature_get_visible(Object *ob,
return nullptr;
}
Object **BKE_object_pose_array_get_ex(
const Scene *scene, ViewLayer *view_layer, View3D *v3d, uint *r_objects_len, bool unique)
Vector<Object *> BKE_object_pose_array_get_ex(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
bool unique)
{
BKE_view_layer_synced_ensure(scene, view_layer);
Object *ob_active = BKE_view_layer_active_object_get(view_layer);
Object *ob_pose = BKE_object_pose_armature_get(ob_active);
Object **objects = nullptr;
if (ob_pose == ob_active) {
ObjectsInModeParams ob_params{};
ob_params.object_mode = OB_MODE_POSE;
ob_params.no_dup_data = unique;
objects = BKE_view_layer_array_from_objects_in_mode_params(
scene, view_layer, v3d, r_objects_len, &ob_params);
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, &ob_params);
}
else if (ob_pose != nullptr) {
*r_objects_len = 1;
objects = (Object **)MEM_mallocN(sizeof(*objects), __func__);
objects[0] = ob_pose;
if (ob_pose != nullptr) {
return {ob_pose};
}
else {
*r_objects_len = 0;
objects = (Object **)MEM_mallocN(0, __func__);
}
return objects;
return {};
}
Object **BKE_object_pose_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
uint *r_objects_len)
Vector<Object *> BKE_object_pose_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d)
{
return BKE_object_pose_array_get_ex(scene, view_layer, v3d, r_objects_len, true);
return BKE_object_pose_array_get_ex(scene, view_layer, v3d, true);
}
Object **BKE_object_pose_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
uint *r_objects_len)
Vector<Object *> BKE_object_pose_array_get(const Scene *scene, ViewLayer *view_layer, View3D *v3d)
{
return BKE_object_pose_array_get_ex(scene, view_layer, v3d, r_objects_len, false);
return BKE_object_pose_array_get_ex(scene, view_layer, v3d, false);
}
Base **BKE_object_pose_base_array_get_ex(
const Scene *scene, ViewLayer *view_layer, View3D *v3d, uint *r_bases_len, bool unique)
blender::Vector<Base *> BKE_object_pose_base_array_get_ex(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
bool unique)
{
BKE_view_layer_synced_ensure(scene, view_layer);
Base *base_active = BKE_view_layer_active_base_get(view_layer);
Object *ob_pose = base_active ? BKE_object_pose_armature_get(base_active->object) : nullptr;
Base *base_pose = nullptr;
Base **bases = nullptr;
if (base_active) {
if (ob_pose == base_active->object) {
@ -2507,33 +2500,25 @@ Base **BKE_object_pose_base_array_get_ex(
ob_params.object_mode = OB_MODE_POSE;
ob_params.no_dup_data = unique;
bases = BKE_view_layer_array_from_bases_in_mode_params(
scene, view_layer, v3d, r_bases_len, &ob_params);
return BKE_view_layer_array_from_bases_in_mode_params(scene, view_layer, v3d, &ob_params);
}
else if (base_pose != nullptr) {
*r_bases_len = 1;
bases = (Base **)MEM_mallocN(sizeof(*bases), __func__);
bases[0] = base_pose;
if (base_pose != nullptr) {
return {base_pose};
}
else {
*r_bases_len = 0;
bases = (Base **)MEM_mallocN(0, __func__);
}
return bases;
return {};
}
Base **BKE_object_pose_base_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
uint *r_bases_len)
Vector<Base *> BKE_object_pose_base_array_get_unique(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d)
{
return BKE_object_pose_base_array_get_ex(scene, view_layer, v3d, r_bases_len, true);
return BKE_object_pose_base_array_get_ex(scene, view_layer, v3d, true);
}
Base **BKE_object_pose_base_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d,
uint *r_bases_len)
Vector<Base *> BKE_object_pose_base_array_get(const Scene *scene,
ViewLayer *view_layer,
View3D *v3d)
{
return BKE_object_pose_base_array_get_ex(scene, view_layer, v3d, r_bases_len, false);
return BKE_object_pose_base_array_get_ex(scene, view_layer, v3d, false);
}
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)

View File

@ -127,6 +127,5 @@ uint DRW_select_buffer_find_nearest_to_point(Depsgraph *depsgraph,
uint id_max,
uint *dist);
void DRW_select_buffer_context_create(Depsgraph *depsgraph,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
short select_mode);

View File

@ -36,6 +36,8 @@
#include "overlay_private.hh"
using blender::Vector;
/* Forward declarations. */
static void overlay_edit_uv_cache_populate(OVERLAY_Data *vedata, Object *ob);
@ -422,15 +424,13 @@ void OVERLAY_edit_uv_cache_init(OVERLAY_Data *vedata)
if ((pd->edit_uv.do_uv_overlay || pd->edit_uv.do_uv_shadow_overlay) &&
draw_ctx->obact->type == OB_MESH)
{
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_mode_unique_data(
draw_ctx->scene, draw_ctx->view_layer, nullptr, &objects_len, draw_ctx->object_mode);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *object_eval = DEG_get_evaluated_object(draw_ctx->depsgraph, objects[ob_index]);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_mode_unique_data(
draw_ctx->scene, draw_ctx->view_layer, nullptr, draw_ctx->object_mode);
for (Object *object : objects) {
Object *object_eval = DEG_get_evaluated_object(draw_ctx->depsgraph, object);
DRW_mesh_batch_cache_validate(object_eval, (Mesh *)object_eval->data);
overlay_edit_uv_cache_populate(vedata, object_eval);
}
MEM_freeN(objects);
}
}

View File

@ -473,18 +473,17 @@ uint DRW_select_buffer_context_offset_for_object_elem(Depsgraph *depsgraph,
* \{ */
void DRW_select_buffer_context_create(Depsgraph *depsgraph,
Base **bases,
const uint bases_len,
const blender::Span<Base *> bases,
short select_mode)
{
SELECTID_Context *select_ctx = DRW_select_engine_context_get();
select_ctx->objects.reinitialize(bases_len);
select_ctx->index_offsets.reinitialize(bases_len);
select_ctx->objects.reinitialize(bases.size());
select_ctx->index_offsets.reinitialize(bases.size());
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obj = bases[base_index]->object;
select_ctx->objects[base_index] = DEG_get_evaluated_object(depsgraph, obj);
for (const int i : bases.index_range()) {
Object *obj = bases[i]->object;
select_ctx->objects[i] = DEG_get_evaluated_object(depsgraph, obj);
}
select_ctx->select_mode = select_mode;

View File

@ -53,6 +53,8 @@
#include "armature_intern.hh"
using blender::Vector;
/* *************** Adding stuff in editmode *************** */
EditBone *ED_armature_ebone_add(bArmature *arm, const char *name)
@ -978,15 +980,13 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
EditBone *ebone_iter;
/* The beginning of the duplicated bones in the edbo list */
EditBone *ebone_first_dupe = nullptr;
Object *ob = objects[ob_index];
bArmature *arm = static_cast<bArmature *>(ob->data);
ED_armature_edit_sync_selection(arm->edbo); /* XXX why is this needed? */
@ -1099,7 +1099,6 @@ static int armature_duplicate_selected_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
DEG_id_tag_update(&ob->id, ID_RECALC_SELECT);
}
MEM_freeN(objects);
ED_outliner_select_sync_from_edit_bone_tag(C);
@ -1158,15 +1157,13 @@ static int armature_symmetrize_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
EditBone *ebone_iter;
/* The beginning of the duplicated mirrored bones in the edbo list */
EditBone *ebone_first_dupe = nullptr;
Object *obedit = objects[ob_index];
bArmature *arm = static_cast<bArmature *>(obedit->data);
ED_armature_edit_sync_selection(arm->edbo); /* XXX why is this needed? */
@ -1378,7 +1375,6 @@ static int armature_symmetrize_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
DEG_id_tag_update(&obedit->id, ID_RECALC_SELECT);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1425,9 +1421,8 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
const bool forked = RNA_boolean_get(op->ptr, "forked");
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
enum ExtrudePoint {
SKIP_EXTRUDE,
@ -1435,8 +1430,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
ROOT_EXTRUDE,
};
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool forked_iter = forked;
@ -1602,7 +1596,6 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
DEG_id_tag_update(&ob->id, ID_RECALC_SELECT);
}
MEM_freeN(objects);
if (!changed_multi) {
return OPERATOR_CANCELLED;

View File

@ -49,6 +49,8 @@
#include "armature_intern.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Object Tools Public API
* \{ */
@ -261,7 +263,6 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob_active = CTX_data_edit_object(C);
int ret = OPERATOR_FINISHED;
eCalcRollTypes type = eCalcRollTypes(RNA_enum_get(op->ptr, "type"));
const bool axis_only = RNA_boolean_get(op->ptr, "axis_only");
@ -270,11 +271,9 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
(type >= CALC_ROLL_TAN_NEG_X) ? true :
false);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -372,8 +371,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
RegionView3D *rv3d = CTX_wm_region_view3d(C);
if (rv3d == nullptr) {
BKE_report(op->reports, RPT_ERROR, "No region view3d available");
ret = OPERATOR_CANCELLED;
goto cleanup;
return OPERATOR_CANCELLED;
}
copy_v3_v3(vec, rv3d->viewinv[2]);
@ -385,8 +383,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
ebone = (EditBone *)arm_active->act_edbone;
if (ebone == nullptr) {
BKE_report(op->reports, RPT_ERROR, "No active bone set");
ret = OPERATOR_CANCELLED;
goto cleanup;
return OPERATOR_CANCELLED;
}
ED_armature_ebone_to_mat3(ebone, mat);
@ -439,9 +436,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
}
}
cleanup:
MEM_freeN(objects);
return ret;
return OPERATOR_FINISHED;
}
void ARMATURE_OT_calculate_roll(wmOperatorType *ot)
@ -475,11 +470,9 @@ static int armature_roll_clear_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
const float roll = RNA_float_get(op->ptr, "roll");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -509,7 +502,6 @@ static int armature_roll_clear_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&arm->id, ID_RECALC_SELECT);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -893,12 +885,10 @@ static int armature_switch_direction_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
ListBase chains = {nullptr, nullptr};
@ -987,7 +977,6 @@ static int armature_switch_direction_exec(bContext *C, wmOperator * /*op*/)
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
DEG_id_tag_update(&arm->id, ID_RECALC_SELECT);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1166,11 +1155,9 @@ static int armature_split_exec(bContext *C, wmOperator * /*op*/)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
LISTBASE_FOREACH (EditBone *, bone, arm->edbo) {
@ -1187,7 +1174,6 @@ static int armature_split_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(&arm->id, ID_RECALC_SELECT);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1235,11 +1221,9 @@ static int armature_delete_selected_exec(bContext *C, wmOperator * /*op*/)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
bArmature *arm = static_cast<bArmature *>(obedit->data);
bool changed = false;
@ -1270,7 +1254,6 @@ static int armature_delete_selected_exec(bContext *C, wmOperator * /*op*/)
ED_outliner_select_sync_from_edit_bone_tag(C);
}
}
MEM_freeN(objects);
if (!changed_multi) {
return OPERATOR_CANCELLED;
@ -1312,11 +1295,9 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/)
EditBone *ebone, *ebone_next;
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
bArmature *arm = static_cast<bArmature *>(obedit->data);
bool changed = false;
@ -1449,7 +1430,6 @@ static int armature_dissolve_selected_exec(bContext *C, wmOperator * /*op*/)
ED_outliner_select_sync_from_edit_bone_tag(C);
}
}
MEM_freeN(objects);
if (!changed_multi) {
return OPERATOR_CANCELLED;
@ -1490,11 +1470,9 @@ static int armature_hide_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
bArmature *arm = static_cast<bArmature *>(obedit->data);
bool changed = false;
@ -1517,7 +1495,6 @@ static int armature_hide_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
DEG_id_tag_update(&arm->id, ID_RECALC_SELECT);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1551,11 +1528,9 @@ static int armature_reveal_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
const bool select = RNA_boolean_get(op->ptr, "select");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
bArmature *arm = static_cast<bArmature *>(obedit->data);
bool changed = false;
@ -1579,7 +1554,6 @@ static int armature_reveal_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&arm->id, ID_RECALC_SELECT);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -267,22 +267,19 @@ EditBone *ED_armature_pick_ebone(bContext *C, const int xy[2], bool findunsel, B
bPoseChannel *ED_armature_pick_pchan(bContext *C, const int xy[2], bool findunsel, Base **r_base);
Bone *ED_armature_pick_bone(bContext *C, const int xy[2], bool findunsel, Base **r_base);
EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases,
uint bases_len,
EditBone *ED_armature_pick_ebone_from_selectbuffer(blender::Span<Base *> bases,
const GPUSelectResult *hit_results,
int hits,
bool findunsel,
bool do_nearest,
Base **r_base);
bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases,
uint bases_len,
bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(blender::Span<Base *> bases,
const GPUSelectResult *hit_results,
int hits,
bool findunsel,
bool do_nearest,
Base **r_base);
Bone *ED_armature_pick_bone_from_selectbuffer(Base **bases,
uint bases_len,
Bone *ED_armature_pick_bone_from_selectbuffer(blender::Span<Base *> bases,
const GPUSelectResult *hit_results,
int hits,
bool findunsel,

View File

@ -53,6 +53,8 @@
#include "armature_intern.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Unique Bone Name Utility (Edit Mode)
* \{ */
@ -437,11 +439,9 @@ static int armature_flip_names_exec(bContext *C, wmOperator *op)
const bool do_strip_numbers = RNA_boolean_get(op->ptr, "do_strip_numbers");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
/* Paranoia check. */
@ -484,7 +484,6 @@ static int armature_flip_names_exec(bContext *C, wmOperator *op)
/* update animation channels */
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN, ob->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -526,11 +525,9 @@ static int armature_autoside_names_exec(bContext *C, wmOperator *op)
const short axis = RNA_enum_get(op->ptr, "type");
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -575,7 +572,6 @@ static int armature_autoside_names_exec(bContext *C, wmOperator *op)
/* NOTE: notifier might evolve. */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -56,6 +56,8 @@
#include "armature_intern.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Edit Armature Join
*
@ -682,12 +684,10 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
/* set wait cursor in case this takes a while */
WM_cursor_wait(true);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base_old = bases[base_index];
for (Base *base_old : bases) {
Object *ob_old = base_old->object;
{
@ -762,7 +762,6 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
/* NOTE: notifier might evolve. */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob_old);
}
MEM_freeN(bases);
/* Recalculate/redraw + cleanup */
WM_cursor_wait(false);
@ -1056,11 +1055,9 @@ static int armature_parent_clear_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1080,8 +1077,6 @@ static int armature_parent_clear_exec(bContext *C, wmOperator *op)
/* NOTE: notifier might evolve. */
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -49,6 +49,9 @@
#include "armature_intern.hh"
using blender::Span;
using blender::Vector;
/* utility macros for storing a temp int in the bone (selection flag) */
#define EBONE_PREV_FLAG_GET(ebone) ((void)0, (ebone)->temp.i)
#define EBONE_PREV_FLAG_SET(ebone, val) ((ebone)->temp.i = val)
@ -57,8 +60,7 @@
/** \name Select Buffer Queries for PoseMode & EditMode
* \{ */
Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_armature_base_and_ebone_from_select_buffer(const Span<Base *> bases,
const uint select_id,
EditBone **r_ebone)
{
@ -66,9 +68,9 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
Base *base = nullptr;
EditBone *ebone = nullptr;
/* TODO(@ideasman42): optimize, eg: sort & binary search. */
for (uint base_index = 0; base_index < bases_len; base_index++) {
if (bases[base_index]->object->runtime->select_id == hit_object) {
base = bases[base_index];
for (Base *base_iter : bases) {
if (base_iter->object->runtime->select_id == hit_object) {
base = base_iter;
break;
}
}
@ -81,8 +83,7 @@ Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
return base;
}
Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
uint objects_len,
Object *ED_armature_object_and_ebone_from_select_buffer(const Span<Object *> objects,
const uint select_id,
EditBone **r_ebone)
{
@ -90,9 +91,9 @@ Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
Object *ob = nullptr;
EditBone *ebone = nullptr;
/* TODO(@ideasman42): optimize, eg: sort & binary search. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
if (objects[ob_index]->runtime->select_id == hit_object) {
ob = objects[ob_index];
for (Object *object_iter : objects) {
if (object_iter->runtime->select_id == hit_object) {
ob = object_iter;
break;
}
}
@ -105,8 +106,7 @@ Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
return ob;
}
Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_armature_base_and_pchan_from_select_buffer(const Span<Base *> bases,
const uint select_id,
bPoseChannel **r_pchan)
{
@ -114,9 +114,9 @@ Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
Base *base = nullptr;
bPoseChannel *pchan = nullptr;
/* TODO(@ideasman42): optimize, eg: sort & binary search. */
for (uint base_index = 0; base_index < bases_len; base_index++) {
if (bases[base_index]->object->runtime->select_id == hit_object) {
base = bases[base_index];
for (Base *base_iter : bases) {
if (base_iter->object->runtime->select_id == hit_object) {
base = base_iter;
break;
}
}
@ -131,13 +131,12 @@ Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
return base;
}
Base *ED_armature_base_and_bone_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_armature_base_and_bone_from_select_buffer(const Span<Base *> bases,
const uint select_id,
Bone **r_bone)
{
bPoseChannel *pchan = nullptr;
Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, bases_len, select_id, &pchan);
Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, select_id, &pchan);
*r_bone = pchan ? pchan->bone : nullptr;
return base;
}
@ -155,14 +154,12 @@ Base *ED_armature_base_and_bone_from_select_buffer(Base **bases,
/* See if there are any selected bones in this buffer */
/* only bones from base are checked on */
static void *ed_armature_pick_bone_from_selectbuffer_impl(
const bool is_editmode,
Base **bases,
uint bases_len,
const blender::Span<GPUSelectResult> hit_results,
bool findunsel,
bool do_nearest,
Base **r_base)
static void *ed_armature_pick_bone_from_selectbuffer_impl(const bool is_editmode,
const Span<Base *> bases,
const Span<GPUSelectResult> hit_results,
bool findunsel,
bool do_nearest,
Base **r_base)
{
bPoseChannel *pchan;
EditBone *ebone;
@ -181,7 +178,7 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(
hit_id &= ~BONESEL_ANY;
/* Determine what the current bone is */
if (is_editmode == false) {
base = ED_armature_base_and_pchan_from_select_buffer(bases, bases_len, hit_id, &pchan);
base = ED_armature_base_and_pchan_from_select_buffer(bases, hit_id, &pchan);
if (pchan != nullptr) {
if (findunsel) {
sel = (pchan->bone->flag & BONE_SELECTED);
@ -198,7 +195,7 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(
}
}
else {
base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hit_id, &ebone);
base = ED_armature_base_and_ebone_from_select_buffer(bases, hit_id, &ebone);
if (findunsel) {
sel = (ebone->flag & BONE_SELECTED);
}
@ -257,8 +254,7 @@ static void *ed_armature_pick_bone_from_selectbuffer_impl(
return firstSel;
}
EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases,
uint bases_len,
EditBone *ED_armature_pick_ebone_from_selectbuffer(const Span<Base *> bases,
const GPUSelectResult *hit_results,
const int hits,
bool findunsel,
@ -267,11 +263,10 @@ EditBone *ED_armature_pick_ebone_from_selectbuffer(Base **bases,
{
const bool is_editmode = true;
return static_cast<EditBone *>(ed_armature_pick_bone_from_selectbuffer_impl(
is_editmode, bases, bases_len, {hit_results, hits}, findunsel, do_nearest, r_base));
is_editmode, bases, {hit_results, hits}, findunsel, do_nearest, r_base));
}
bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases,
uint bases_len,
bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(const Span<Base *> bases,
const GPUSelectResult *hit_results,
const int hits,
bool findunsel,
@ -280,11 +275,10 @@ bPoseChannel *ED_armature_pick_pchan_from_selectbuffer(Base **bases,
{
const bool is_editmode = false;
return static_cast<bPoseChannel *>(ed_armature_pick_bone_from_selectbuffer_impl(
is_editmode, bases, bases_len, {hit_results, hits}, findunsel, do_nearest, r_base));
is_editmode, bases, {hit_results, hits}, findunsel, do_nearest, r_base));
}
Bone *ED_armature_pick_bone_from_selectbuffer(Base **bases,
uint bases_len,
Bone *ED_armature_pick_bone_from_selectbuffer(const Span<Base *> bases,
const GPUSelectResult *hit_results,
const int hits,
bool findunsel,
@ -292,7 +286,7 @@ Bone *ED_armature_pick_bone_from_selectbuffer(Base **bases,
Base **r_base)
{
bPoseChannel *pchan = ED_armature_pick_pchan_from_selectbuffer(
bases, bases_len, hit_results, hits, findunsel, do_nearest, r_base);
bases, hit_results, hits, findunsel, do_nearest, r_base);
return pchan ? pchan->bone : nullptr;
}
@ -334,27 +328,17 @@ static void *ed_armature_pick_bone_impl(
*r_base = nullptr;
if (hits > 0) {
uint bases_len = 0;
Base **bases;
Vector<Base *> bases;
if (vc.obedit != nullptr) {
bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bases = BKE_view_layer_array_from_bases_in_edit_mode(vc.scene, vc.view_layer, vc.v3d);
}
else {
bases = BKE_object_pose_base_array_get(vc.scene, vc.view_layer, vc.v3d, &bases_len);
bases = BKE_object_pose_base_array_get(vc.scene, vc.view_layer, vc.v3d);
}
void *bone = ed_armature_pick_bone_from_selectbuffer_impl(
is_editmode,
bases,
bases_len,
buffer.storage.as_span().take_front(hits),
findunsel,
true,
r_base);
MEM_freeN(bases);
is_editmode, bases, buffer.storage.as_span().take_front(hits), findunsel, true, r_base);
return bone;
}
@ -509,11 +493,9 @@ static int armature_select_linked_exec(bContext *C, wmOperator *op)
bool changed_multi = false;
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool found = false;
@ -535,7 +517,6 @@ static int armature_select_linked_exec(bContext *C, wmOperator *op)
}
}
}
MEM_freeN(objects);
if (changed_multi) {
ED_outliner_select_sync_from_edit_bone_tag(C);
@ -729,16 +710,15 @@ static EditBone *get_nearest_editbonepoint(
cache_end:
view3d_opengl_select_cache_end();
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d);
/* See if there are any selected bones in this group */
if (hits > 0) {
if (hits == 1) {
result_bias.hitresult = buffer.storage[0].id;
result_bias.base = ED_armature_base_and_ebone_from_select_buffer(
bases, bases_len, result_bias.hitresult, &result_bias.ebone);
bases, result_bias.hitresult, &result_bias.ebone);
}
else {
int bias_max = INT_MIN;
@ -779,7 +759,7 @@ cache_end:
Base *base = nullptr;
EditBone *ebone;
base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hitresult, &ebone);
base = ED_armature_base_and_ebone_from_select_buffer(bases, hitresult, &ebone);
/* If this fails, selection code is setting the selection ID's incorrectly. */
BLI_assert(base && ebone);
@ -873,13 +853,11 @@ cache_end:
if (result->hitresult & BONESEL_BONE) {
*r_selmask |= BONE_SELECTED;
}
MEM_freeN(bases);
return result->ebone;
}
}
*r_selmask = 0;
*r_base = nullptr;
MEM_freeN(bases);
return nullptr;
}
@ -922,21 +900,21 @@ bool ED_armature_edit_deselect_all_visible(Object *obedit)
return changed;
}
bool ED_armature_edit_deselect_all_multi_ex(Base **bases, uint bases_len)
bool ED_armature_edit_deselect_all_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
changed_multi |= ED_armature_edit_deselect_all(obedit);
}
return changed_multi;
}
bool ED_armature_edit_deselect_all_visible_multi_ex(Base **bases, uint bases_len)
bool ED_armature_edit_deselect_all_visible_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
changed_multi |= ED_armature_edit_deselect_all_visible(obedit);
}
return changed_multi;
@ -946,12 +924,9 @@ bool ED_armature_edit_deselect_all_visible_multi(bContext *C)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bool changed_multi = ED_armature_edit_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
return ED_armature_edit_deselect_all_multi_ex(bases);
}
/** \} */
@ -984,11 +959,9 @@ bool ED_armature_edit_select_pick_bone(
}
else if (found || params->deselect_all) {
/* Deselect everything. */
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, v3d, &bases_len);
ED_armature_edit_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, v3d);
ED_armature_edit_deselect_all_multi_ex(bases);
changed = true;
}
}
@ -1507,16 +1480,13 @@ static int armature_de_select_more_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
armature_select_more_less(ob, true);
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
MEM_freeN(objects);
ED_outliner_select_sync_from_edit_bone_tag(C);
return OPERATOR_FINISHED;
@ -1547,16 +1517,13 @@ static int armature_de_select_less_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
armature_select_more_less(ob, false);
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
MEM_freeN(objects);
ED_outliner_select_sync_from_edit_bone_tag(C);
return OPERATOR_FINISHED;
@ -1630,11 +1597,9 @@ static void select_similar_length(bContext *C, const float thresh)
const float len_min = len / (1.0f + (thresh - FLT_EPSILON));
const float len_max = len * (1.0f + (thresh + FLT_EPSILON));
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1653,7 +1618,6 @@ static void select_similar_length(bContext *C, const float thresh)
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
}
static void bone_direction_worldspace_get(Object *ob, EditBone *ebone, float *r_dir)
@ -1679,11 +1643,9 @@ static void select_similar_direction(bContext *C, const float thresh)
float dir_act[3];
bone_direction_worldspace_get(ob_act, ebone_act, dir_act);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1705,7 +1667,6 @@ static void select_similar_direction(bContext *C, const float thresh)
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
}
static void select_similar_bone_collection(bContext *C)
@ -1720,11 +1681,9 @@ static void select_similar_bone_collection(bContext *C)
collection_names.add(bcoll_ref->bcoll->name);
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1749,7 +1708,6 @@ static void select_similar_bone_collection(bContext *C)
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
}
static void select_similar_bone_color(bContext *C)
{
@ -1759,11 +1717,9 @@ static void select_similar_bone_color(bContext *C)
const blender::animrig::BoneColor &active_bone_color = ebone_act->color.wrap();
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1786,7 +1742,6 @@ static void select_similar_bone_color(bContext *C)
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
}
static void select_similar_prefix(bContext *C)
@ -1804,11 +1759,9 @@ static void select_similar_prefix(bContext *C)
return;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1829,7 +1782,6 @@ static void select_similar_prefix(bContext *C)
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
}
static void select_similar_suffix(bContext *C)
@ -1847,11 +1799,9 @@ static void select_similar_suffix(bContext *C)
return;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bool changed = false;
@ -1872,7 +1822,6 @@ static void select_similar_suffix(bContext *C)
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
}
/** Use for matching any pose channel data. */
@ -2179,11 +2128,9 @@ static int armature_select_mirror_exec(bContext *C, wmOperator *op)
const bool active_only = RNA_boolean_get(op->ptr, "only_active");
const bool extend = RNA_boolean_get(op->ptr, "extend");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
EditBone *ebone_mirror_act = nullptr;
@ -2229,7 +2176,6 @@ static int armature_select_mirror_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
DEG_id_tag_update(&ob->id, ID_RECALC_COPY_ON_WRITE);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -64,6 +64,8 @@
# include "BLI_time_utildefines.h"
#endif
using blender::Vector;
Object *ED_pose_object_from_context(bContext *C)
{
/* NOTE: matches logic with #ED_operator_posemode_context(). */
@ -693,16 +695,13 @@ static int pose_hide_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_object_pose_array_get_unique(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_object_pose_array_get_unique(scene, view_layer, CTX_wm_view3d(C));
bool changed_multi = false;
const int hide_select = !RNA_boolean_get(op->ptr, "unselected");
void *hide_select_p = POINTER_FROM_INT(hide_select);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
bArmature *arm = static_cast<bArmature *>(ob_iter->data);
bool changed = bone_looper(ob_iter,
@ -715,7 +714,6 @@ static int pose_hide_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -762,15 +760,12 @@ static int pose_reveal_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_object_pose_array_get_unique(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_object_pose_array_get_unique(scene, view_layer, CTX_wm_view3d(C));
bool changed_multi = false;
const bool select = RNA_boolean_get(op->ptr, "select");
void *select_p = POINTER_FROM_INT(select);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
bArmature *arm = static_cast<bArmature *>(ob_iter->data);
bool changed = bone_looper(
@ -781,7 +776,6 @@ static int pose_reveal_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -51,6 +51,9 @@
#include "armature_intern.hh"
using blender::Span;
using blender::Vector;
/* utility macros for storing a temp int in the bone (selection flag) */
#define PBONE_PREV_FLAG_GET(pchan) ((void)0, POINTER_AS_INT((pchan)->temp))
#define PBONE_PREV_FLAG_SET(pchan, val) ((pchan)->temp = POINTER_FROM_INT(val))
@ -273,7 +276,7 @@ bool ED_armature_pose_select_pick_with_buffer(const Scene *scene,
/* Callers happen to already get the active base */
Base *base_dummy = nullptr;
nearBone = ED_armature_pick_bone_from_selectbuffer(
&base, 1, hit_results, hits, true, do_nearest, &base_dummy);
{base}, hit_results, hits, true, do_nearest, &base_dummy);
return ED_armature_pose_select_pick_bone(scene, view_layer, v3d, ob, nearBone, params);
}
@ -377,10 +380,10 @@ static bool ed_pose_is_any_selected(Object *ob, bool ignore_visibility)
return false;
}
static bool ed_pose_is_any_selected_multi(Base **bases, uint bases_len, bool ignore_visibility)
static bool ed_pose_is_any_selected_multi(const Span<Base *> bases, bool ignore_visibility)
{
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *ob_iter = bases[base_index]->object;
for (Base *base : bases) {
Object *ob_iter = base->object;
if (ed_pose_is_any_selected(ob_iter, ignore_visibility)) {
return true;
}
@ -388,20 +391,18 @@ static bool ed_pose_is_any_selected_multi(Base **bases, uint bases_len, bool ign
return false;
}
bool ED_pose_deselect_all_multi_ex(Base **bases,
uint bases_len,
bool ED_pose_deselect_all_multi_ex(const Span<Base *> bases,
int select_mode,
const bool ignore_visibility)
{
if (select_mode == SEL_TOGGLE) {
select_mode = ed_pose_is_any_selected_multi(bases, bases_len, ignore_visibility) ?
SEL_DESELECT :
SEL_SELECT;
select_mode = ed_pose_is_any_selected_multi(bases, ignore_visibility) ? SEL_DESELECT :
SEL_SELECT;
}
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *ob_iter = bases[base_index]->object;
for (Base *base : bases) {
Object *ob_iter = base->object;
if (ED_pose_deselect_all(ob_iter, select_mode, ignore_visibility)) {
ED_pose_bone_select_tag_update(ob_iter);
changed_multi = true;
@ -414,14 +415,9 @@ bool ED_pose_deselect_all_multi(bContext *C, int select_mode, const bool ignore_
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_object_pose_base_array_get_unique(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bool changed_multi = ED_pose_deselect_all_multi_ex(
bases, bases_len, select_mode, ignore_visibility);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_object_pose_base_array_get_unique(vc.scene, vc.view_layer, vc.v3d);
return ED_pose_deselect_all_multi_ex(bases, select_mode, ignore_visibility);
}
/* ***************** Selections ********************** */
@ -1004,11 +1000,9 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex
CTX_DATA_END;
}
uint objects_len = 0;
Object **objects = BKE_object_pose_array_get_unique(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_object_pose_array_get_unique(scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *ob = BKE_object_pose_armature_get(objects[ob_index]);
bArmature *arm = static_cast<bArmature *>((ob) ? ob->data : nullptr);
bPose *pose = (ob) ? ob->pose : nullptr;
@ -1047,7 +1041,6 @@ static bool pose_select_same_keyingset(bContext *C, ReportList *reports, bool ex
changed_multi = true;
}
}
MEM_freeN(objects);
return changed_multi;
}
@ -1146,12 +1139,8 @@ static int pose_select_mirror_exec(bContext *C, wmOperator *op)
const bool active_only = RNA_boolean_get(op->ptr, "only_active");
const bool extend = RNA_boolean_get(op->ptr, "extend");
uint objects_len = 0;
Object **objects = BKE_object_pose_array_get_unique(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_object_pose_array_get_unique(scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
bPoseChannel *pchan_mirror_act = nullptr;
@ -1201,7 +1190,6 @@ static int pose_select_mirror_exec(bContext *C, wmOperator *op)
/* Need to tag armature for cow updates, or else selection doesn't update. */
DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
}
MEM_freeN(objects);
ED_outliner_select_sync_from_pose_bone_tag(C);

View File

@ -30,6 +30,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_array.hh"
#include "BLI_blenlib.h"
#include "BLI_dlrbTree.h"
#include "BLI_math_rotation.h"
@ -84,6 +85,8 @@
#include "BLF_api.h"
using blender::Vector;
/* Pixel distance from 0% to 100%. */
#define SLIDE_PIXEL_DISTANCE (300 * U.pixelsize)
#define OVERSHOOT_RANGE_DELTA 0.2f
@ -123,6 +126,16 @@ enum ePoseSlide_Channels {
PS_TFM_PROPS, /* Custom Properties */
};
struct tPoseSlideObject {
/** Active object that Pose Info comes from. */
Object *ob;
/** `prev_frame`, but in local action time (for F-Curve look-ups to work). */
float prev_frame;
/** `next_frame`, but in local action time (for F-Curve look-ups to work). */
float next_frame;
bool valid;
};
/** Temporary data shared between these operators. */
struct tPoseSlideOp {
/** current scene */
@ -132,7 +145,6 @@ struct tPoseSlideOp {
/** Region we're operating in (needed for modal()). */
ARegion *region;
/** len of the PoseSlideObject array. */
uint objects_len;
/** links between posechannels and f-curves for all the pose objects. */
ListBase pfLinks;
@ -165,17 +177,7 @@ struct tPoseSlideOp {
/** Numeric input. */
NumInput num;
struct tPoseSlideObject *ob_data_array;
};
struct tPoseSlideObject {
/** Active object that Pose Info comes from. */
Object *ob;
/** `prev_frame`, but in local action time (for F-Curve look-ups to work). */
float prev_frame;
/** `next_frame`, but in local action time (for F-Curve look-ups to work). */
float next_frame;
bool valid;
blender::Array<tPoseSlideObject> ob_data_array;
};
/** Property enum for #ePoseSlide_Channels. */
@ -207,11 +209,8 @@ static const EnumPropertyItem prop_axis_lock_types[] = {
/** Operator custom-data initialization. */
static int pose_slide_init(bContext *C, wmOperator *op, ePoseSlide_Modes mode)
{
tPoseSlideOp *pso;
/* Init slide-op data. */
pso = static_cast<tPoseSlideOp *>(
op->customdata = MEM_callocN(sizeof(tPoseSlideOp), "tPoseSlideOp"));
tPoseSlideOp *pso = MEM_new<tPoseSlideOp>(__func__);
op->customdata = pso;
/* Get info from context. */
pso->scene = CTX_data_scene(C);
@ -236,15 +235,11 @@ static int pose_slide_init(bContext *C, wmOperator *op, ePoseSlide_Modes mode)
* and set the relevant transform flags. */
poseAnim_mapping_get(C, &pso->pfLinks);
Object **objects = BKE_view_layer_array_from_objects_in_mode_unique_data(CTX_data_scene(C),
CTX_data_view_layer(C),
CTX_wm_view3d(C),
&pso->objects_len,
OB_MODE_POSE);
pso->ob_data_array = static_cast<tPoseSlideObject *>(
MEM_callocN(pso->objects_len * sizeof(tPoseSlideObject), "pose slide objects data"));
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_mode_unique_data(
CTX_data_scene(C), CTX_data_view_layer(C), CTX_wm_view3d(C), OB_MODE_POSE);
pso->ob_data_array.reinitialize(objects.size());
for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
Object *ob_iter = poseAnim_object_get(objects[ob_index]);
@ -267,7 +262,6 @@ static int pose_slide_init(bContext *C, wmOperator *op, ePoseSlide_Modes mode)
ob_data->ob->pose->flag |= POSE_LOCKED;
ob_data->ob->pose->flag &= ~POSE_DO_UNLOCK;
}
MEM_freeN(objects);
/* Do basic initialize of RB-BST used for finding keyframes, but leave the filling of it up
* to the caller of this (usually only invoke() will do it, to make things more efficient). */
@ -303,12 +297,8 @@ static void pose_slide_exit(bContext *C, wmOperator *op)
/* Free RB-BST for keyframes (if it contained data). */
ED_keylist_free(pso->keylist);
if (pso->ob_data_array != nullptr) {
MEM_freeN(pso->ob_data_array);
}
/* Free data itself. */
MEM_freeN(pso);
MEM_delete(pso);
/* Cleanup. */
op->customdata = nullptr;
@ -322,10 +312,9 @@ static void pose_slide_exit(bContext *C, wmOperator *op)
static void pose_slide_refresh(bContext *C, tPoseSlideOp *pso)
{
/* Wrapper around the generic version, allowing us to add some custom stuff later still. */
for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
if (ob_data->valid) {
poseAnim_mapping_refresh(C, pso->scene, ob_data->ob);
for (tPoseSlideObject &ob_data : pso->ob_data_array) {
if (ob_data.valid) {
poseAnim_mapping_refresh(C, pso->scene, ob_data.ob);
}
}
}
@ -339,13 +328,12 @@ static bool pose_frame_range_from_object_get(tPoseSlideOp *pso,
float *prev_frame,
float *next_frame)
{
for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
Object *ob_iter = ob_data->ob;
for (tPoseSlideObject &ob_data : pso->ob_data_array) {
Object *ob_iter = ob_data.ob;
if (ob_iter == ob) {
*prev_frame = ob_data->prev_frame;
*next_frame = ob_data->next_frame;
*prev_frame = ob_data.prev_frame;
*next_frame = ob_data.next_frame;
return true;
}
}
@ -821,18 +809,16 @@ static void pose_slide_apply(bContext *C, tPoseSlideOp *pso)
pso->prev_frame--;
pso->next_frame++;
for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
if (!ob_data->valid) {
for (tPoseSlideObject &ob_data : pso->ob_data_array) {
if (!ob_data.valid) {
continue;
}
/* Apply NLA mapping corrections so the frame look-ups work. */
ob_data->prev_frame = BKE_nla_tweakedit_remap(
ob_data->ob->adt, pso->prev_frame, NLATIME_CONVERT_UNMAP);
ob_data->next_frame = BKE_nla_tweakedit_remap(
ob_data->ob->adt, pso->next_frame, NLATIME_CONVERT_UNMAP);
ob_data.prev_frame = BKE_nla_tweakedit_remap(
ob_data.ob->adt, pso->prev_frame, NLATIME_CONVERT_UNMAP);
ob_data.next_frame = BKE_nla_tweakedit_remap(
ob_data.ob->adt, pso->next_frame, NLATIME_CONVERT_UNMAP);
}
}
@ -1059,13 +1045,12 @@ static int pose_slide_invoke_common(bContext *C, wmOperator *op, const wmEvent *
}
/* Apply NLA mapping corrections so the frame look-ups work. */
for (uint ob_index = 0; ob_index < pso->objects_len; ob_index++) {
tPoseSlideObject *ob_data = &pso->ob_data_array[ob_index];
if (ob_data->valid) {
ob_data->prev_frame = BKE_nla_tweakedit_remap(
ob_data->ob->adt, pso->prev_frame, NLATIME_CONVERT_UNMAP);
ob_data->next_frame = BKE_nla_tweakedit_remap(
ob_data->ob->adt, pso->next_frame, NLATIME_CONVERT_UNMAP);
for (tPoseSlideObject &ob_data : pso->ob_data_array) {
if (ob_data.valid) {
ob_data.prev_frame = BKE_nla_tweakedit_remap(
ob_data.ob->adt, pso->prev_frame, NLATIME_CONVERT_UNMAP);
ob_data.next_frame = BKE_nla_tweakedit_remap(
ob_data.ob->adt, pso->next_frame, NLATIME_CONVERT_UNMAP);
}
}

View File

@ -67,6 +67,8 @@ extern "C" {
#include "RNA_define.hh"
#include "RNA_enum_types.hh"
using blender::Vector;
void selectend_nurb(Object *obedit, enum eEndPoint_Types selfirst, bool doswap, bool selstatus);
static void adduplicateflagNurb(
Object *obedit, View3D *v3d, ListBase *newnurb, const uint8_t flag, const bool split);
@ -1354,11 +1356,9 @@ static int separate_exec(bContext *C, wmOperator *op)
WM_cursor_wait(true);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &bases_len);
for (uint b_index = 0; b_index < bases_len; b_index++) {
Base *oldbase = bases[b_index];
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Base *oldbase : bases) {
Base *newbase;
Object *oldob, *newob;
Curve *oldcu, *newcu;
@ -1418,10 +1418,9 @@ static int separate_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, newob);
status.changed++;
}
MEM_freeN(bases);
WM_cursor_wait(false);
if (status.unselected == bases_len) {
if (status.unselected == bases.size()) {
BKE_report(op->reports, RPT_ERROR, "No point was selected");
return OPERATOR_CANCELLED;
}
@ -1488,11 +1487,9 @@ static int curve_split_exec(bContext *C, wmOperator *op)
bool changed = false;
int count_failed = 0;
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -1523,7 +1520,6 @@ static int curve_split_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
if (changed == false) {
if (count_failed != 0) {
@ -2577,11 +2573,9 @@ static int switch_direction_exec(bContext *C, wmOperator * /*op*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -2608,7 +2602,6 @@ static int switch_direction_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2637,12 +2630,10 @@ static int set_goal_weight_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ListBase *editnurb = object_editcurve_get(obedit);
BezTriple *bezt;
BPoint *bp;
@ -2670,8 +2661,6 @@ static int set_goal_weight_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2704,14 +2693,12 @@ static int set_radius_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int totobjects = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (ED_object_edit_report_if_shape_key_is_locked(obedit, op->reports)) {
continue;
@ -2746,8 +2733,6 @@ static int set_radius_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -2825,14 +2810,12 @@ static int smooth_exec(bContext *C, wmOperator *op)
const float factor = 1.0f / 6.0f;
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int totobjects = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (ED_object_edit_report_if_shape_key_is_locked(obedit, op->reports)) {
continue;
@ -2915,8 +2898,6 @@ static int smooth_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -3131,12 +3112,10 @@ static int curve_smooth_weight_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ListBase *editnurb = object_editcurve_get(obedit);
curve_smooth_value(editnurb, offsetof(BezTriple, weight), offsetof(BPoint, weight));
@ -3145,8 +3124,6 @@ static int curve_smooth_weight_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3175,14 +3152,13 @@ static int curve_smooth_radius_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int totobjects = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (ED_object_edit_report_if_shape_key_is_locked(obedit, op->reports)) {
continue;
@ -3198,8 +3174,6 @@ static int curve_smooth_radius_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -3228,14 +3202,12 @@ static int curve_smooth_tilt_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int totobjects = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (ED_object_edit_report_if_shape_key_is_locked(obedit, op->reports)) {
continue;
@ -3251,8 +3223,6 @@ static int curve_smooth_tilt_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -3285,11 +3255,9 @@ static int hide_exec(bContext *C, wmOperator *op)
const bool invert = RNA_boolean_get(op->ptr, "unselected");
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!(invert || ED_curve_select_check(v3d, cu->editnurb))) {
@ -3352,7 +3320,6 @@ static int hide_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
BKE_curve_nurb_vert_active_validate(static_cast<Curve *>(obedit->data));
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3388,11 +3355,9 @@ static int reveal_exec(bContext *C, wmOperator *op)
const bool select = RNA_boolean_get(op->ptr, "select");
bool changed_multi = false;
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
ListBase *editnurb = object_editcurve_get(obedit);
BPoint *bp;
BezTriple *bezt;
@ -3434,7 +3399,6 @@ static int reveal_exec(bContext *C, wmOperator *op)
changed_multi = true;
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -3866,11 +3830,9 @@ static int subdivide_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -3886,7 +3848,6 @@ static int subdivide_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, cu);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3923,13 +3884,11 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int ret_value = OPERATOR_CANCELLED;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Main *bmain = CTX_data_main(C);
View3D *v3d = CTX_wm_view3d(C);
ListBase *editnurb = object_editcurve_get(obedit);
@ -3971,8 +3930,6 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
return ret_value;
}
@ -4023,11 +3980,9 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
const eNurbHandleTest_Mode handle_mode = hide_handles ? NURB_HANDLE_TEST_KNOT_ONLY :
NURB_HANDLE_TEST_KNOT_OR_EACH;
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -4040,7 +3995,6 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4087,14 +4041,12 @@ static int curve_normals_make_consistent_exec(bContext *C, wmOperator *op)
const bool calc_length = RNA_boolean_get(op->ptr, "calc_length");
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int totobjects = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -4113,7 +4065,6 @@ static int curve_normals_make_consistent_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -4544,11 +4495,9 @@ static int make_segment_exec(bContext *C, wmOperator *op)
int error_generic;
} status = {0};
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -4779,9 +4728,8 @@ static int make_segment_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
if (status.unselected == objects_len) {
if (status.unselected == objects.size()) {
BKE_report(op->reports, RPT_ERROR, "No points were selected");
return OPERATOR_CANCELLED;
}
@ -4869,19 +4817,14 @@ bool ED_curve_editnurb_select_pick(bContext *C,
}
else if (found || params->deselect_all) {
/* Deselect everything. */
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
for (Object *ob_iter : objects) {
ED_curve_deselect_all(((Curve *)ob_iter->data)->editnurb);
DEG_id_tag_update(static_cast<ID *>(ob_iter->data),
ID_RECALC_SELECT | ID_RECALC_COPY_ON_WRITE);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data);
}
MEM_freeN(objects);
changed = true;
}
}
@ -5158,11 +5101,9 @@ static int spin_exec(bContext *C, wmOperator *op)
unit_m4(viewmat);
}
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = (Curve *)obedit->data;
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -5185,7 +5126,6 @@ static int spin_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
if (changed == false) {
if (count_failed != 0) {
@ -5807,11 +5747,9 @@ static int curve_extrude_exec(bContext *C, wmOperator * /*op*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
EditNurb *editnurb = cu->editnurb;
bool changed = false;
@ -5836,7 +5774,6 @@ static int curve_extrude_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -5950,11 +5887,9 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
bool changed_multi = false;
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -5968,7 +5903,6 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -6042,11 +5976,9 @@ static int duplicate_exec(bContext *C, wmOperator *op)
bool changed = false;
int count_failed = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -6066,7 +5998,6 @@ static int duplicate_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&cu->id, ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, &cu->id);
}
MEM_freeN(objects);
if (changed == false) {
if (count_failed != 0) {
@ -6548,13 +6479,11 @@ static int curve_delete_exec(bContext *C, wmOperator *op)
eCurveElem_Types type = eCurveElem_Types(RNA_enum_get(op->ptr, "type"));
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
bool changed_multi = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = (Curve *)obedit->data;
bool changed = false;
@ -6585,7 +6514,6 @@ static int curve_delete_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
}
MEM_freeN(objects);
if (changed_multi) {
return OPERATOR_FINISHED;
@ -6728,11 +6656,9 @@ static int curve_dissolve_exec(bContext *C, wmOperator * /*op*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = (Curve *)obedit->data;
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -6774,7 +6700,6 @@ static int curve_dissolve_exec(bContext *C, wmOperator * /*op*/)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -6822,11 +6747,9 @@ static int curve_decimate_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = (Curve *)obedit->data;
bool all_supported = true;
bool changed = false;
@ -6869,8 +6792,6 @@ static int curve_decimate_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_WARNING, "Only bezier curves are supported");
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -6904,13 +6825,11 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
int clear = STREQ(op->idname, "CURVE_OT_shade_flat");
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int ret_value = OPERATOR_CANCELLED;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ListBase *editnurb = object_editcurve_get(obedit);
if (obedit->type != OB_CURVES_LEGACY) {
@ -6933,8 +6852,6 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
ret_value = OPERATOR_FINISHED;
}
MEM_freeN(objects);
return ret_value;
}
@ -7100,14 +7017,12 @@ static int clear_tilt_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
int totobjects = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -7151,7 +7066,6 @@ static int clear_tilt_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
MEM_freeN(objects);
return totobjects ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -26,6 +26,8 @@
#include "curve_intern.h"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Cursor Picking API
* \{ */
@ -109,11 +111,9 @@ bool ED_curve_pick_vert_ex(ViewContext *vc,
data.mval_fl[0] = vc->mval[0];
data.mval_fl[1] = vc->mval[1];
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d, &bases_len);
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base = bases[base_index];
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d);
for (Base *base : bases) {
data.is_changed = false;
ED_view3d_viewcontext_init_object(vc, base->object);
@ -124,7 +124,6 @@ bool ED_curve_pick_vert_ex(ViewContext *vc,
*r_base = base;
}
}
MEM_freeN(bases);
*r_nurb = data.nurb;
*r_bezt = data.bezt;

View File

@ -41,6 +41,9 @@
#include "DEG_depsgraph.hh"
using blender::Span;
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Utilities
* \{ */
@ -241,11 +244,11 @@ bool ED_curve_deselect_all(EditNurb *editnurb)
return changed;
}
bool ED_curve_deselect_all_multi_ex(Base **bases, int bases_len)
bool ED_curve_deselect_all_multi_ex(Span<Base *> bases)
{
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
Curve *cu = static_cast<Curve *>(obedit->data);
changed_multi |= ED_curve_deselect_all(cu->editnurb);
DEG_id_tag_update(&cu->id, ID_RECALC_SELECT);
@ -257,12 +260,9 @@ bool ED_curve_deselect_all_multi(bContext *C)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bool changed_multi = ED_curve_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
return ED_curve_deselect_all_multi_ex(bases);
}
bool ED_curve_select_swap(EditNurb *editnurb, bool hide_handles)
@ -491,18 +491,15 @@ static int de_select_first_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
selectend_nurb(obedit, FIRST, true, false);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
BKE_curve_nurb_vert_active_validate(static_cast<Curve *>(obedit->data));
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -525,19 +522,16 @@ static int de_select_last_exec(bContext *C, wmOperator * /*op*/)
{
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
selectend_nurb(obedit, LAST, true, false);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
BKE_curve_nurb_vert_active_validate(static_cast<Curve *>(obedit->data));
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -569,13 +563,11 @@ static int de_select_all_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (ED_curve_select_check(v3d, cu->editnurb)) {
@ -585,8 +577,7 @@ static int de_select_all_exec(bContext *C, wmOperator *op)
}
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
bool changed = false;
@ -610,7 +601,6 @@ static int de_select_all_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -644,11 +634,9 @@ static int select_linked_exec(bContext *C, wmOperator * /*op*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
EditNurb *editnurb = cu->editnurb;
ListBase *nurbs = &editnurb->nurbs;
@ -665,7 +653,6 @@ static int select_linked_exec(bContext *C, wmOperator * /*op*/)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -844,12 +831,10 @@ static int select_next_exec(bContext *C, wmOperator * /*op*/)
{
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ListBase *editnurb = object_editcurve_get(obedit);
select_adjacent_cp(editnurb, 1, false, SELECT);
@ -857,7 +842,6 @@ static int select_next_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -886,12 +870,10 @@ static int select_previous_exec(bContext *C, wmOperator * /*op*/)
{
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ListBase *editnurb = object_editcurve_get(obedit);
select_adjacent_cp(editnurb, -1, false, SELECT);
@ -899,7 +881,6 @@ static int select_previous_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1003,16 +984,13 @@ static int curve_select_more_exec(bContext *C, wmOperator * /*op*/)
{
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
curve_select_more(obedit);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1223,16 +1201,13 @@ static int curve_select_less_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
curve_select_less(obedit);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1265,11 +1240,10 @@ static int curve_select_random_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
ListBase *editnurb = object_editcurve_get(obedit);
int seed_iter = seed;
@ -1348,7 +1322,6 @@ static int curve_select_random_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1453,11 +1426,9 @@ static int select_nth_exec(bContext *C, wmOperator *op)
CheckerIntervalParams op_params;
WM_operator_properties_checker_interval_from_op(op, &op_params);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
if (!ED_curve_select_check(v3d, cu->editnurb)) {
@ -1471,7 +1442,6 @@ static int select_nth_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_freeN(objects);
if (!changed) {
if (obact->type == OB_SURF) {
@ -1747,19 +1717,16 @@ static int curve_select_similar_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
int tot_nurbs_selected_all = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
tot_nurbs_selected_all += ED_curve_select_count(v3d, cu->editnurb);
}
if (tot_nurbs_selected_all == 0) {
BKE_report(op->reports, RPT_ERROR, "No control point selected");
MEM_freeN(objects);
return OPERATOR_CANCELLED;
}
@ -1778,8 +1745,7 @@ static int curve_select_similar_exec(bContext *C, wmOperator *op)
}
/* Get type of selected control points. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
EditNurb *editnurb = cu->editnurb;
@ -1811,8 +1777,7 @@ static int curve_select_similar_exec(bContext *C, wmOperator *op)
}
/* Select control points with desired type. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Curve *cu = static_cast<Curve *>(obedit->data);
EditNurb *editnurb = cu->editnurb;
bool changed = false;
@ -1840,8 +1805,6 @@ static int curve_select_similar_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
if (tree_1d != nullptr) {
BLI_kdtree_1d_free(tree_1d);
}

View File

@ -37,6 +37,8 @@
#include "curve_intern.h"
using blender::Vector;
/** We only need this locally. */
static CLG_LogRef LOG = {"ed.undo.curve"};

View File

@ -8,9 +8,8 @@
#pragma once
#include <stdbool.h>
#include "BLI_listbase.h"
#include "BLI_span.hh"
struct Base;
struct Bone;
@ -134,29 +133,25 @@ int ED_armature_join_objects_exec(bContext *C, wmOperator *op);
/* `armature_select.cc` */
Base *ED_armature_base_and_ebone_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_armature_base_and_ebone_from_select_buffer(blender::Span<Base *> bases,
unsigned int select_id,
EditBone **r_ebone);
Object *ED_armature_object_and_ebone_from_select_buffer(Object **objects,
uint objects_len,
Object *ED_armature_object_and_ebone_from_select_buffer(blender::Span<Object *> objects,
unsigned int select_id,
EditBone **r_ebone);
Base *ED_armature_base_and_pchan_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_armature_base_and_pchan_from_select_buffer(blender::Span<Base *> bases,
unsigned int select_id,
bPoseChannel **r_pchan);
/**
* For callers that don't need the pose channel.
*/
Base *ED_armature_base_and_bone_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_armature_base_and_bone_from_select_buffer(blender::Span<Base *> bases,
unsigned int select_id,
Bone **r_bone);
bool ED_armature_edit_deselect_all(Object *obedit);
bool ED_armature_edit_deselect_all_visible(Object *obedit);
bool ED_armature_edit_deselect_all_multi_ex(Base **bases, uint bases_len);
bool ED_armature_edit_deselect_all_visible_multi_ex(Base **bases, uint bases_len);
bool ED_armature_edit_deselect_all_multi_ex(blender::Span<Base *> bases);
bool ED_armature_edit_deselect_all_visible_multi_ex(blender::Span<Base *> bases);
bool ED_armature_edit_deselect_all_visible_multi(bContext *C);
/**
* \return True when pick finds an element or the selection changed.
@ -315,8 +310,7 @@ bool ED_armature_pose_select_pick_with_buffer(const Scene *scene,
void ED_armature_pose_select_in_wpaint_mode(const Scene *scene,
ViewLayer *view_layer,
Base *base_select);
bool ED_pose_deselect_all_multi_ex(Base **bases,
uint bases_len,
bool ED_pose_deselect_all_multi_ex(blender::Span<Base *> bases,
int select_mode,
bool ignore_visibility);
bool ED_pose_deselect_all_multi(bContext *C, int select_mode, bool ignore_visibility);

View File

@ -74,7 +74,7 @@ int ED_curve_join_objects_exec(bContext *C, wmOperator *op);
bool ED_curve_select_check(const View3D *v3d, const EditNurb *editnurb);
bool ED_curve_deselect_all(EditNurb *editnurb);
bool ED_curve_deselect_all_multi_ex(Base **bases, int bases_len);
bool ED_curve_deselect_all_multi_ex(blender::Span<Base *> bases);
bool ED_curve_deselect_all_multi(bContext *C);
bool ED_curve_select_all(EditNurb *editnurb);
bool ED_curve_select_swap(EditNurb *editnurb, bool hide_handles);

View File

@ -31,7 +31,6 @@ bool ED_lattice_flags_set(Object *obedit, int flag);
*/
bool ED_lattice_select_pick(bContext *C, const int mval[2], const SelectPick_Params *params);
bool ED_lattice_deselect_all_multi_ex(Base **bases, uint bases_len);
bool ED_lattice_deselect_all_multi(bContext *C);
/* `editlattice_undo.cc` */

View File

@ -8,6 +8,8 @@
#pragma once
#include "BLI_span.hh"
struct Base;
struct MetaElem;
struct Object;
@ -26,8 +28,7 @@ void ED_keymap_metaball(wmKeyConfig *keyconf);
MetaElem *ED_mball_add_primitive(
bContext *C, Object *obedit, bool obedit_is_new, float mat[4][4], float dia, int type);
Base *ED_mball_base_and_elem_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_mball_base_and_elem_from_select_buffer(blender::Span<Base *> bases,
const uint select_id,
MetaElem **r_ml);
@ -37,8 +38,6 @@ Base *ED_mball_base_and_elem_from_select_buffer(Base **bases,
* \return True when pick finds an element or the selection changed.
*/
bool ED_mball_select_pick(bContext *C, const int mval[2], const SelectPick_Params *params);
bool ED_mball_deselect_all_multi_ex(Base **bases, uint bases_len);
bool ED_mball_deselect_all_multi(bContext *C);
/**

View File

@ -213,8 +213,7 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
float *dist_px_manhattan_p,
bool use_select_bias,
bool use_cycle,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
uint *r_base_index);
BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *dist_px_manhattan_p);
@ -224,8 +223,7 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
bool use_select_bias,
bool use_cycle,
BMEdge **r_eed_zbuf,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
uint *r_base_index);
BMEdge *EDBM_edge_find_nearest(ViewContext *vc, float *dist_px_manhattan_p);
@ -243,22 +241,19 @@ BMFace *EDBM_face_find_nearest_ex(ViewContext *vc,
bool use_select_bias,
bool use_cycle,
BMFace **r_efa_zbuf,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
uint *r_base_index);
BMFace *EDBM_face_find_nearest(ViewContext *vc, float *dist_px_manhattan_p);
bool EDBM_unified_findnearest(ViewContext *vc,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
int *r_base_index,
BMVert **r_eve,
BMEdge **r_eed,
BMFace **r_efa);
bool EDBM_unified_findnearest_from_raycast(ViewContext *vc,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
bool use_boundary_vertices,
bool use_boundary_edges,
int *r_base_index_vert,
@ -320,11 +315,10 @@ void EDBM_select_swap(BMEditMesh *em); /* exported for UV */
bool EDBM_select_interior_faces(BMEditMesh *em);
ViewContext em_setup_viewcontext(bContext *C); /* rename? */
bool EDBM_mesh_deselect_all_multi_ex(Base **bases, uint bases_len);
bool EDBM_mesh_deselect_all_multi_ex(blender::Span<Base *> bases);
bool EDBM_mesh_deselect_all_multi(bContext *C);
bool EDBM_selectmode_disable_multi_ex(Scene *scene,
Base **bases,
uint bases_len,
blender::Span<Base *> bases,
short selectmode_disable,
short selectmode_fallback);
bool EDBM_selectmode_disable_multi(bContext *C,
@ -653,8 +647,8 @@ MDeformVert *ED_mesh_active_dvert_get_em(Object *ob, BMVert **r_eve);
MDeformVert *ED_mesh_active_dvert_get_ob(Object *ob, int *r_index);
MDeformVert *ED_mesh_active_dvert_get_only(Object *ob);
void EDBM_mesh_stats_multi(Object **objects, uint objects_len, int totelem[3], int totelem_sel[3]);
void EDBM_mesh_elem_index_ensure_multi(Object **objects, uint objects_len, char htype);
void EDBM_mesh_stats_multi(blender::Span<Object *> objects, int totelem[3], int totelem_sel[3]);
void EDBM_mesh_elem_index_ensure_multi(blender::Span<Object *> objects, char htype);
#define ED_MESH_PICK_DEFAULT_VERT_DIST 25
#define ED_MESH_PICK_DEFAULT_FACE_DIST 1

View File

@ -12,6 +12,7 @@
#include "BLI_compiler_attrs.h"
#include "BLI_string_ref.hh"
#include "BLI_vector.hh"
#include "DNA_object_enums.h"
#include "DNA_userdef_enums.h"
@ -60,10 +61,8 @@ void ED_collection_hide_menu_draw(const bContext *C, uiLayout *layout);
* the callers \a filter_fn needs to check of they are editable
* (assuming they need to be modified).
*/
Object **ED_object_array_in_mode_or_selected(bContext *C,
bool (*filter_fn)(const Object *ob, void *user_data),
void *filter_user_data,
uint *r_objects_len);
blender::Vector<Object *> ED_object_array_in_mode_or_selected(
bContext *C, bool (*filter_fn)(const Object *ob, void *user_data), void *filter_user_data);
/* `object_shapekey.cc` */

View File

@ -47,15 +47,18 @@ void ED_uvedit_foreach_uv(const Scene *scene,
const bool selected,
blender::FunctionRef<void(float[2])> user_fn);
void ED_uvedit_foreach_uv_multi(const Scene *scene,
Object **objects_edit,
uint objects_len,
blender::Span<Object *> objects_edit,
const bool skip_invisible,
const bool skip_nonselected,
blender::FunctionRef<void(float[2])> user_fn);
bool ED_uvedit_minmax_multi(
const Scene *scene, Object **objects_edit, uint objects_len, float r_min[2], float r_max[2]);
bool ED_uvedit_center_multi(
const Scene *scene, Object **objects_edit, uint objects_len, float r_cent[2], char mode);
bool ED_uvedit_minmax_multi(const Scene *scene,
blender::Span<Object *> objects_edit,
float r_min[2],
float r_max[2]);
bool ED_uvedit_center_multi(const Scene *scene,
blender::Span<Object *> objects_edit,
float r_cent[2],
char mode);
bool ED_uvedit_center_from_pivot_ex(SpaceImage *sima,
Scene *scene,
@ -219,8 +222,7 @@ void uvedit_select_flush(const Scene *scene, BMEditMesh *em);
bool ED_uvedit_nearest_uv_multi(const View2D *v2d,
const Scene *scene,
Object **objects,
uint objects_len,
blender::Span<Object *> objects,
const float mval_fl[2],
const bool ignore_selected,
float *dist_sq,
@ -262,7 +264,7 @@ void ED_uvedit_live_unwrap_begin(Scene *scene, Object *obedit);
void ED_uvedit_live_unwrap_re_solve();
void ED_uvedit_live_unwrap_end(short cancel);
void ED_uvedit_live_unwrap(const Scene *scene, Object **objects, int objects_len);
void ED_uvedit_live_unwrap(const Scene *scene, blender::Span<Object *> objects);
void ED_uvedit_add_simple_uvs(Main *bmain, const Scene *scene, Object *ob);
/* `uvedit_draw.cc` */

View File

@ -44,6 +44,9 @@
#include "lattice_intern.h"
using blender::Span;
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Utility Functions
* \{ */
@ -60,12 +63,11 @@ static void bpoint_select_set(BPoint *bp, bool select)
}
}
bool ED_lattice_deselect_all_multi_ex(Base **bases, const uint bases_len)
static bool lattice_deselect_all_multi(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base_iter = bases[base_index];
Object *ob_iter = base_iter->object;
for (Base *base : bases) {
Object *ob_iter = base->object;
changed_multi |= ED_lattice_flags_set(ob_iter, 0);
DEG_id_tag_update(static_cast<ID *>(ob_iter->data), ID_RECALC_SELECT);
}
@ -76,12 +78,9 @@ bool ED_lattice_deselect_all_multi(bContext *C)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bool changed_multi = ED_lattice_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
return lattice_deselect_all_multi(bases);
}
/** \} */
@ -98,10 +97,9 @@ static int lattice_select_random_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
int seed_iter = seed;
@ -137,7 +135,6 @@ static int lattice_select_random_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -208,12 +205,10 @@ static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
for (int axis = 0; axis < 3; axis++) {
@ -226,7 +221,6 @@ static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -275,13 +269,11 @@ static int lattice_select_more_less(bContext *C, const bool select)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
bool changed = false;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
BPoint *bp;
const int tot = lt->pntsu * lt->pntsv * lt->pntsw;
@ -319,7 +311,6 @@ static int lattice_select_more_less(bContext *C, const bool select)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -404,14 +395,12 @@ static int lattice_select_all_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
int action = RNA_enum_get(op->ptr, "action");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Lattice *lt = static_cast<Lattice *>(obedit->data);
if (BKE_lattice_is_any_selected(lt->editlatt->latt)) {
action = SEL_DESELECT;
@ -421,8 +410,7 @@ static int lattice_select_all_exec(bContext *C, wmOperator *op)
}
bool changed_multi = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
Lattice *lt;
BPoint *bp;
int a;
@ -456,7 +444,6 @@ static int lattice_select_all_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_freeN(objects);
if (changed_multi) {
return OPERATOR_FINISHED;
@ -491,14 +478,12 @@ static int lattice_select_ungrouped_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
const bool is_extend = RNA_boolean_get(op->ptr, "extend");
bool changed = false;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
MDeformVert *dv;
BPoint *bp;
@ -527,7 +512,6 @@ static int lattice_select_ungrouped_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
if (!changed) {
BKE_report(op->reports, RPT_ERROR, "No weights/vertex groups on object(s)");
@ -596,11 +580,9 @@ static BPoint *findnearestLattvert(ViewContext *vc, bool select, Base **r_base)
data.mval_fl[0] = vc->mval[0];
data.mval_fl[1] = vc->mval[1];
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d, &bases_len);
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base = bases[base_index];
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d);
for (Base *base : bases) {
data.is_changed = false;
ED_view3d_viewcontext_init_object(vc, base->object);
@ -612,7 +594,6 @@ static BPoint *findnearestLattvert(ViewContext *vc, bool select, Base **r_base)
*r_base = base;
}
}
MEM_freeN(bases);
return data.bp;
}
@ -636,17 +617,14 @@ bool ED_lattice_select_pick(bContext *C, const int mval[2], const SelectPick_Par
}
else if (found || params->deselect_all) {
/* Deselect everything. */
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
for (Object *ob : objects) {
if (ED_lattice_flags_set(ob, 0)) {
DEG_id_tag_update(static_cast<ID *>(ob->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
}
}
MEM_freeN(objects);
changed = true;
}
}

View File

@ -33,6 +33,8 @@
#include "lattice_intern.h"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Make Regular Operator
* \{ */
@ -57,11 +59,9 @@ static int make_regular_exec(bContext *C, wmOperator *op)
const bool is_editmode = CTX_data_edit_object(C) != nullptr;
if (is_editmode) {
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
Lattice *lt = static_cast<Lattice *>(ob->data);
if (lt->editlatt->latt == nullptr) {
@ -77,7 +77,6 @@ static int make_regular_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
}
MEM_freeN(objects);
}
else {
FOREACH_SELECTED_OBJECT_BEGIN (view_layer, v3d, ob) {
@ -204,14 +203,12 @@ static int lattice_flip_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
bool changed = false;
const eLattice_FlipAxes axis = eLattice_FlipAxes(RNA_enum_get(op->ptr, "axis"));
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Lattice *lt;
int numU, numV, numW;
@ -332,7 +329,6 @@ static int lattice_flip_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
changed = true;
}
MEM_freeN(objects);
return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -46,6 +46,8 @@
#include "mesh_intern.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Delete Operator
* \{ */
@ -149,9 +151,8 @@ static int mesh_set_attribute_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
Mesh *mesh = ED_mesh_context(C);
CustomDataLayer *active_attribute = BKE_id_attributes_active_get(&mesh->id);
@ -166,8 +167,7 @@ static int mesh_set_attribute_exec(bContext *C, wmOperator *op)
const bke::DataTypeConversions &conversions = bke::get_implicit_type_conversions();
bool changed = false;
for (const int i : IndexRange(objects_len)) {
Object *object = objects[i];
for (Object *object : objects) {
Mesh *mesh = static_cast<Mesh *>(object->data);
BMEditMesh *em = BKE_editmesh_from_object(object);
BMesh *bm = em->bm;
@ -216,8 +216,6 @@ static int mesh_set_attribute_exec(bContext *C, wmOperator *op)
EDBM_update(mesh, &update);
}
MEM_freeN(objects);
return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -45,6 +45,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
#define MVAL_PIXEL_MARGIN 5.0f
#define PROFILE_HARD_MIN 0.0f
@ -80,8 +82,7 @@ struct BevelData {
float max_obj_scale;
bool is_modal;
BevelObjectStore *ob_store;
uint ob_store_len;
Vector<BevelObjectStore> ob_store;
/* modal only */
int launch_event;
@ -231,32 +232,24 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
RNA_float_set(op->ptr, "offset_pct", 0.0f);
}
op->customdata = MEM_mallocN(sizeof(BevelData), "beveldata_mesh_operator");
op->customdata = MEM_new<BevelData>(__func__);
BevelData *opdata = static_cast<BevelData *>(op->customdata);
uint objects_used_len = 0;
opdata->max_obj_scale = FLT_MIN;
/* Put the Curve Profile from the toolsettings into the opdata struct */
opdata->custom_profile = ts->custom_bevel_profile_preset;
{
uint ob_store_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &ob_store_len);
opdata->ob_store = static_cast<BevelObjectStore *>(
MEM_malloc_arrayN(ob_store_len, sizeof(*opdata->ob_store), __func__));
for (uint ob_index = 0; ob_index < ob_store_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (Object *obedit : objects) {
float scale = mat4_to_scale(obedit->object_to_world);
opdata->max_obj_scale = max_ff(opdata->max_obj_scale, scale);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totvertsel > 0) {
opdata->ob_store[objects_used_len].ob = obedit;
objects_used_len++;
opdata->ob_store.append(BevelObjectStore{obedit, {}});
}
}
MEM_freeN(objects);
opdata->ob_store_len = objects_used_len;
}
opdata->is_modal = is_modal;
@ -288,10 +281,10 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
if (is_modal) {
ARegion *region = CTX_wm_region(C);
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
Object *obedit = opdata->ob_store[ob_index].ob;
for (BevelObjectStore &ob_store : opdata->ob_store) {
Object *obedit = ob_store.ob;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
opdata->ob_store[ob_index].mesh_backup = EDBM_redo_state_store(em);
ob_store.mesh_backup = EDBM_redo_state_store(em);
}
opdata->draw_handle_pixel = ED_region_draw_cb_activate(
region->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
@ -325,13 +318,13 @@ static bool edbm_bevel_calc(wmOperator *op)
const float spread = RNA_float_get(op->ptr, "spread");
const int vmesh_method = RNA_enum_get(op->ptr, "vmesh_method");
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
Object *obedit = opdata->ob_store[ob_index].ob;
for (BevelObjectStore &ob_store : opdata->ob_store) {
Object *obedit = ob_store.ob;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
/* revert to original mesh */
if (opdata->is_modal) {
EDBM_redo_state_restore(&opdata->ob_store[ob_index].mesh_backup, em, false);
EDBM_redo_state_restore(&ob_store.mesh_backup, em, false);
}
const int material = std::clamp(material_init, -1, obedit->totcol - 1);
@ -398,9 +391,8 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
ED_area_status_text(area, nullptr);
}
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
Object *obedit = opdata->ob_store[ob_index].ob;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
for (BevelObjectStore &ob_store : opdata->ob_store) {
BMEditMesh *em = BKE_editmesh_from_object(ob_store.ob);
/* Without this, faces surrounded by selected edges/verts will be unselected. */
if ((em->selectmode & SCE_SELECT_FACE) == 0) {
EDBM_selectmode_flush(em);
@ -409,14 +401,13 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
if (opdata->is_modal) {
ARegion *region = CTX_wm_region(C);
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup);
for (BevelObjectStore &ob_store : opdata->ob_store) {
EDBM_redo_state_free(&ob_store.mesh_backup);
}
ED_region_draw_cb_exit(region->type, opdata->draw_handle_pixel);
G.moving = 0;
}
MEM_SAFE_FREE(opdata->ob_store);
MEM_SAFE_FREE(op->customdata);
MEM_delete(opdata);
op->customdata = nullptr;
}
@ -424,10 +415,10 @@ static void edbm_bevel_cancel(bContext *C, wmOperator *op)
{
BevelData *opdata = static_cast<BevelData *>(op->customdata);
if (opdata->is_modal) {
for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
Object *obedit = opdata->ob_store[ob_index].ob;
for (BevelObjectStore &ob_store : opdata->ob_store) {
Object *obedit = ob_store.ob;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
EDBM_redo_state_restore_and_free(&opdata->ob_store[ob_index].mesh_backup, em, true);
EDBM_redo_state_restore_and_free(&ob_store.mesh_backup, em, true);
EDBMUpdate_Params params{};
params.calc_looptris = false;

View File

@ -45,6 +45,8 @@
# include "ED_undo.hh"
#endif
using blender::Vector;
static int mesh_bisect_exec(bContext *C, wmOperator *op);
/* -------------------------------------------------------------------- */
@ -117,11 +119,9 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return mesh_bisect_exec(C, op);
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totedgesel != 0) {
@ -131,7 +131,6 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if (valid_objects == 0) {
BKE_report(op->reports, RPT_ERROR, "Selected edges/faces required");
MEM_freeN(objects);
return OPERATOR_CANCELLED;
}
@ -154,12 +153,12 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
opdata = static_cast<BisectData *>(MEM_mallocN(sizeof(BisectData), "inset_operator_data"));
gesture->user_data.data = opdata;
opdata->backup_len = objects_len;
opdata->backup_len = objects.size();
opdata->backup = static_cast<BisectData::BisectDataBackup *>(
MEM_callocN(sizeof(*opdata->backup) * objects_len, __func__));
MEM_callocN(sizeof(*opdata->backup) * objects.size(), __func__));
/* Store the mesh backups. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@ -175,7 +174,6 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* Initialize modal callout. */
ED_workspace_status_text(C, RPT_("LMB: Click and drag to draw cut line"));
}
MEM_freeN(objects);
return ret;
}
@ -292,11 +290,10 @@ static int mesh_bisect_exec(bContext *C, wmOperator *op)
/* End Modal */
/* -------------------------------------------------------------------- */
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
CTX_data_scene(C), CTX_data_view_layer(C), CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
CTX_data_scene(C), CTX_data_view_layer(C), CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -394,7 +391,6 @@ static int mesh_bisect_exec(bContext *C, wmOperator *op)
ret = OPERATOR_FINISHED;
}
}
MEM_freeN(objects);
return ret;
}

View File

@ -34,6 +34,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Extrude Internal Utilities
* \{ */
@ -287,14 +289,12 @@ static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (Object *obedit : objects) {
float offset_local[3], tmat[3][3];
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
copy_m3_m4(tmat, obedit->object_to_world);
@ -314,8 +314,6 @@ static int edbm_extrude_repeat_exec(bContext *C, wmOperator *op)
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -432,12 +430,10 @@ static int edbm_extrude_region_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totvertsel == 0) {
continue;
@ -454,7 +450,6 @@ static int edbm_extrude_region_exec(bContext *C, wmOperator *op)
params.is_destructive = true;
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -491,12 +486,10 @@ static int edbm_extrude_context_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totvertsel == 0) {
continue;
@ -512,7 +505,6 @@ static int edbm_extrude_context_exec(bContext *C, wmOperator *op)
params.is_destructive = true;
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -545,12 +537,10 @@ static int edbm_extrude_verts_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totvertsel == 0) {
continue;
@ -564,7 +554,6 @@ static int edbm_extrude_verts_exec(bContext *C, wmOperator *op)
params.is_destructive = true;
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -598,12 +587,10 @@ static int edbm_extrude_edges_exec(bContext *C, wmOperator *op)
const bool use_normal_flip = RNA_boolean_get(op->ptr, "use_normal_flip");
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totedgesel == 0) {
continue;
@ -617,7 +604,6 @@ static int edbm_extrude_edges_exec(bContext *C, wmOperator *op)
params.is_destructive = true;
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -651,12 +637,10 @@ static int edbm_extrude_faces_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totfacesel == 0) {
continue;
@ -670,7 +654,6 @@ static int edbm_extrude_faces_exec(bContext *C, wmOperator *op)
params.is_destructive = true;
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -720,11 +703,9 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
zero_v3(center);
verts_len = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
for (Object *obedit : objects) {
ED_view3d_viewcontext_init_object(&vc, obedit);
const int local_verts_len = vc.em->bm->totvertsel;
@ -754,8 +735,7 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
}
/* Then we process the meshes. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ED_view3d_viewcontext_init_object(&vc, obedit);
if (verts_len != 0) {
@ -912,7 +892,6 @@ static int edbm_dupli_extrude_cursor_invoke(bContext *C, wmOperator *op, const w
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
/* Support dragging to move after extrude, see: #114282. */
const int retval = OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;

View File

@ -30,6 +30,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Screw Operator
* \{ */
@ -51,14 +53,12 @@ static int edbm_screw_exec(bContext *C, wmOperator *op)
RNA_float_get_array(op->ptr, "center", cent);
RNA_float_get_array(op->ptr, "axis", axis);
uint objects_len = 0;
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -150,12 +150,11 @@ static int edbm_screw_exec(bContext *C, wmOperator *op)
params.is_destructive = true;
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
if (failed_axis_len == objects_len - objects_empty_len) {
if (failed_axis_len == objects.size() - objects_empty_len) {
BKE_report(op->reports, RPT_ERROR, "Invalid/unset axis");
}
else if (failed_verts_len == objects_len - objects_empty_len) {
else if (failed_verts_len == objects.size() - objects_empty_len) {
BKE_report(op->reports, RPT_ERROR, "You have to select a string of connected vertices too");
}

View File

@ -30,6 +30,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
#define USE_GIZMO
/* -------------------------------------------------------------------- */
@ -57,12 +59,10 @@ static int edbm_spin_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
BMOperator spinop;
@ -103,8 +103,6 @@ static int edbm_spin_exec(bContext *C, wmOperator *op)
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -40,6 +40,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
struct InsetObjectStore {
/** Must have a valid edit-mesh. */
Object *ob;
@ -133,12 +135,11 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
opdata->max_obj_scale = FLT_MIN;
{
uint ob_store_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &ob_store_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
opdata->ob_store = static_cast<InsetObjectStore *>(
MEM_malloc_arrayN(ob_store_len, sizeof(*opdata->ob_store), __func__));
for (uint ob_index = 0; ob_index < ob_store_len; ob_index++) {
MEM_malloc_arrayN(objects.size(), sizeof(*opdata->ob_store), __func__));
for (uint ob_index = 0; ob_index < objects.size(); ob_index++) {
Object *obedit = objects[ob_index];
float scale = mat4_to_scale(obedit->object_to_world);
opdata->max_obj_scale = max_ff(opdata->max_obj_scale, scale);
@ -148,7 +149,6 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
objects_used_len++;
}
}
MEM_freeN(objects);
opdata->ob_store_len = objects_used_len;
}

View File

@ -45,6 +45,8 @@
/* detect isolated holes and fill them */
#define USE_NET_ISLAND_CONNECT
using blender::Vector;
/**
* Compare selected with itself.
*/
@ -184,12 +186,10 @@ static int edbm_intersect_exec(bContext *C, wmOperator *op)
}
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
uint isect_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totfacesel == 0) {
@ -237,9 +237,8 @@ static int edbm_intersect_exec(bContext *C, wmOperator *op)
isect_len++;
}
}
MEM_freeN(objects);
if (isect_len == objects_len) {
if (isect_len == objects.size()) {
BKE_report(op->reports, RPT_WARNING, "No intersections found");
}
return OPERATOR_FINISHED;
@ -355,12 +354,10 @@ static int edbm_intersect_boolean_exec(bContext *C, wmOperator *op)
test_fn = use_swap ? bm_face_isect_pair_swap : bm_face_isect_pair;
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
uint isect_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totfacesel == 0) {
@ -401,9 +398,8 @@ static int edbm_intersect_boolean_exec(bContext *C, wmOperator *op)
isect_len++;
}
}
MEM_freeN(objects);
if (isect_len == objects_len) {
if (isect_len == objects.size()) {
BKE_report(op->reports, RPT_WARNING, "No intersections found");
}
return OPERATOR_FINISHED;
@ -828,11 +824,9 @@ static int edbm_face_split_by_edges_exec(bContext *C, wmOperator * /*op*/)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -1086,7 +1080,6 @@ static int edbm_face_split_by_edges_exec(bContext *C, wmOperator * /*op*/)
BLI_stack_free(edges_loose);
#endif /* USE_NET_ISLAND_CONNECT */
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -223,9 +223,7 @@ struct KnifeTool_OpData {
Scene *scene;
/* Used for swapping current object when in multi-object edit mode. */
Object **objects;
uint objects_len;
bool objects_free;
Vector<Object *> objects;
/** Array `objects_len` length of additional per-object data. */
KnifeObjectInfo *objects_info;
@ -1246,9 +1244,8 @@ static void knife_bvh_init(KnifeTool_OpData *kcd)
bool test_fn_ret = false;
/* Calculate tottri. */
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
for (Object *ob : kcd->objects) {
ob_tottri = 0;
ob = kcd->objects[ob_index];
em = BKE_editmesh_from_object(ob);
for (int i = 0; i < em->tottri; i++) {
@ -1277,7 +1274,7 @@ static void knife_bvh_init(KnifeTool_OpData *kcd)
* Compacting bvh tree indices may be possible.
* Don't forget to update #knife_bvh_intersect_plane! */
tottri = 0;
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
for (const int ob_index : kcd->objects.index_range()) {
ob = kcd->objects[ob_index];
em = BKE_editmesh_from_object(ob);
looptris = em->looptris;
@ -1334,7 +1331,7 @@ static void knife_bvh_raycast_cb(void *userdata,
tottri = 0;
uint ob_index = 0;
for (; ob_index < kcd->objects_len; ob_index++) {
for (; ob_index < kcd->objects.size(); ob_index++) {
index -= tottri;
ob = kcd->objects[ob_index];
em = BKE_editmesh_from_object(ob);
@ -2642,7 +2639,7 @@ static void calc_ortho_extent(KnifeTool_OpData *kcd)
float ws[3];
INIT_MINMAX(min, max);
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
for (uint ob_index = 0; ob_index < kcd->objects.size(); ob_index++) {
ob = kcd->objects[ob_index];
em = BKE_editmesh_from_object(ob);
@ -2914,7 +2911,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
for (i = 0, result = results; i < tot; i++, result++) {
uint ob_index = 0;
for (ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
for (ob_index = 0; ob_index < kcd->objects.size(); ob_index++) {
ob = kcd->objects[ob_index];
em = BKE_editmesh_from_object(ob);
if (*result >= 0 && *result < em->tottri) {
@ -4080,21 +4077,18 @@ static void knifetool_init(ViewContext *vc,
kcd->region = vc->region;
if (objects) {
kcd->objects = objects;
kcd->objects_len = objects_len;
kcd->objects_free = false;
kcd->objects = Vector<Object *>(objects, objects + objects_len);
}
else {
kcd->objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d, &kcd->objects_len);
kcd->objects_free = true;
vc->scene, vc->view_layer, vc->v3d);
}
Object *ob;
BMEditMesh *em;
kcd->objects_info = static_cast<KnifeObjectInfo *>(
MEM_callocN(sizeof(*kcd->objects_info) * kcd->objects_len, "knife cagecos"));
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
MEM_callocN(sizeof(*kcd->objects_info) * kcd->objects.size(), "knife cagecos"));
for (uint ob_index = 0; ob_index < kcd->objects.size(); ob_index++) {
ob = kcd->objects[ob_index];
em = BKE_editmesh_from_object(ob);
knifetool_init_obinfo(kcd, ob, ob_index, use_tri_indices);
@ -4200,7 +4194,7 @@ static void knifetool_exit_ex(KnifeTool_OpData *kcd)
ED_region_tag_redraw(kcd->region);
/* Knife BVH cleanup. */
for (int i = 0; i < kcd->objects_len; i++) {
for (int i = 0; i < kcd->objects.size(); i++) {
knifetool_free_obinfo(kcd, i);
}
MEM_freeN((void *)kcd->objects_info);
@ -4211,13 +4205,8 @@ static void knifetool_exit_ex(KnifeTool_OpData *kcd)
MEM_freeN(kcd->linehits);
}
/* Free object bases. */
if (kcd->objects_free) {
MEM_freeN(kcd->objects);
}
/* Destroy kcd itself. */
MEM_freeN(kcd);
MEM_delete(kcd);
}
static void knifetool_exit(wmOperator *op)
@ -4310,12 +4299,10 @@ static void knifetool_finish_ex(KnifeTool_OpData *kcd)
/* Separate pre/post passes are needed because `em->looptris` recalculation from the 'post' pass
* causes triangle indices in #KnifeTool_OpData.bvh to get out of sync.
* So perform all the cuts before doing any mesh recalculation, see: #101721. */
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
Object *ob = kcd->objects[ob_index];
for (Object *ob : kcd->objects) {
knifetool_finish_single_pre(kcd, ob);
}
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
Object *ob = kcd->objects[ob_index];
for (Object *ob : kcd->objects) {
knifetool_finish_single_post(kcd, ob);
}
}
@ -4778,14 +4765,11 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
const float angle_snapping_increment = RAD2DEGF(
RNA_float_get(op->ptr, "angle_snapping_increment"));
KnifeTool_OpData *kcd;
ViewContext vc = em_setup_viewcontext(C);
/* alloc new customdata */
kcd = static_cast<KnifeTool_OpData *>(
op->customdata = MEM_callocN(sizeof(KnifeTool_OpData), __func__));
KnifeTool_OpData *kcd = MEM_new<KnifeTool_OpData>(__func__);
op->customdata = kcd;
knifetool_init(&vc,
kcd,
nullptr,
@ -4799,13 +4783,9 @@ static int knifetool_invoke(bContext *C, wmOperator *op, const wmEvent *event)
true);
if (only_select) {
Object *obedit;
BMEditMesh *em;
bool faces_selected = false;
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
obedit = kcd->objects[ob_index];
em = BKE_editmesh_from_object(obedit);
for (Object *obedit : kcd->objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totfacesel != 0) {
faces_selected = true;
}
@ -5009,8 +4989,7 @@ void EDBM_mesh_knife(ViewContext *vc,
/* Finish. */
{
/* See #knifetool_finish_ex for why multiple passes are needed. */
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
Object *ob = kcd->objects[ob_index];
for (Object *ob : kcd->objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
if (use_tag) {
@ -5020,8 +4999,7 @@ void EDBM_mesh_knife(ViewContext *vc,
knifetool_finish_single_pre(kcd, ob);
}
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
Object *ob = kcd->objects[ob_index];
for (Object *ob : kcd->objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
/* Tag faces inside! */
@ -5118,10 +5096,9 @@ void EDBM_mesh_knife(ViewContext *vc,
}
}
for (uint ob_index = 0; ob_index < kcd->objects_len; ob_index++) {
for (Object *ob : kcd->objects) {
/* Defer freeing data until the BVH tree is finished with, see: #point_is_visible and
* the doc-string for #knifetool_finish_single_post. */
Object *ob = kcd->objects[ob_index];
knifetool_finish_single_post(kcd, ob);
}

View File

@ -41,6 +41,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
static LinkNode *knifeproject_poly_from_object(const bContext *C, Object *ob, LinkNode *polys)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
@ -126,14 +128,12 @@ static int knifeproject_exec(bContext *C, wmOperator *op)
ViewContext vc = em_setup_viewcontext(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
EDBM_mesh_knife(&vc, objects, objects_len, polys, true, cut_through);
EDBM_mesh_knife(&vc, objects.data(), objects.size(), polys, true, cut_through);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
ED_view3d_viewcontext_init_object(&vc, obedit);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@ -146,7 +146,6 @@ static int knifeproject_exec(bContext *C, wmOperator *op)
BM_mesh_select_mode_flush(em->bm);
}
MEM_freeN(objects);
BLI_linklist_freeN(polys);

View File

@ -44,6 +44,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
#define SUBD_SMOOTH_MAX 4.0f
#define SUBD_CUTS_MAX 500
@ -65,8 +67,7 @@ struct RingSelOpData {
Depsgraph *depsgraph;
Base **bases;
uint bases_len;
Vector<Base *> bases;
MeshCoordsCache *geom_cache;
@ -99,8 +100,8 @@ static void edgering_select(RingSelOpData *lcd)
}
if (!lcd->extend) {
for (uint base_index = 0; base_index < lcd->bases_len; base_index++) {
Object *ob_iter = lcd->bases[base_index]->object;
for (Base *base : lcd->bases) {
Object *ob_iter = base->object;
BMEditMesh *em = BKE_editmesh_from_object(ob_iter);
EDBM_flag_disable_all(em, BM_ELEM_SELECT);
DEG_id_tag_update(static_cast<ID *>(ob_iter->data), ID_RECALC_SELECT);
@ -255,7 +256,7 @@ static void ringsel_exit(bContext * /*C*/, wmOperator *op)
EDBM_preselect_edgering_destroy(lcd->presel_edgering);
for (uint i = 0; i < lcd->bases_len; i++) {
for (const int i : lcd->bases.index_range()) {
MeshCoordsCache *gcache = &lcd->geom_cache[i];
if (gcache->is_alloc) {
MEM_freeN((void *)gcache->coords);
@ -263,25 +264,20 @@ static void ringsel_exit(bContext * /*C*/, wmOperator *op)
}
MEM_freeN(lcd->geom_cache);
MEM_freeN(lcd->bases);
ED_region_tag_redraw(lcd->region);
/* free the custom data */
MEM_freeN(lcd);
MEM_delete(lcd);
op->customdata = nullptr;
}
/* called when modal loop selection gets set up... */
static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
{
RingSelOpData *lcd;
Scene *scene = CTX_data_scene(C);
/* alloc new customdata */
lcd = static_cast<RingSelOpData *>(
op->customdata = MEM_callocN(sizeof(RingSelOpData), "ringsel Modal Op Data"));
RingSelOpData *lcd = MEM_new<RingSelOpData>(__func__);
op->customdata = lcd;
lcd->vc = em_setup_viewcontext(C);
lcd->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
@ -355,7 +351,6 @@ static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines)
false,
nullptr,
lcd->bases,
lcd->bases_len,
&base_index);
if (eed_test) {
@ -391,13 +386,12 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, CTX_wm_view3d(C), &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, CTX_wm_view3d(C));
if (is_interactive) {
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *ob_iter = bases[base_index]->object;
for (Base *base : bases) {
Object *ob_iter = base->object;
if (BKE_modifiers_is_deformed_by_lattice(ob_iter) ||
BKE_modifiers_is_deformed_by_armature(ob_iter))
{
@ -415,7 +409,7 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
/* for re-execution, check edge index is in range before we setup ringsel */
bool ok = true;
if (is_interactive == false) {
if (exec_data.base_index >= bases_len) {
if (exec_data.base_index >= bases.size()) {
ok = false;
}
else {
@ -428,7 +422,6 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
}
if (!ok || !ringsel_init(C, op, true)) {
MEM_freeN(bases);
return OPERATOR_CANCELLED;
}
@ -440,10 +433,9 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
RingSelOpData *lcd = static_cast<RingSelOpData *>(op->customdata);
lcd->bases = bases;
lcd->bases_len = bases_len;
lcd->bases = std::move(bases);
lcd->geom_cache = static_cast<MeshCoordsCache *>(
MEM_callocN(sizeof(*lcd->geom_cache) * bases_len, __func__));
MEM_callocN(sizeof(*lcd->geom_cache) * lcd->bases.size(), __func__));
if (is_interactive) {
copy_v2_v2_int(lcd->vc.mval, event->mval);
@ -451,7 +443,7 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
}
else {
Object *ob_iter = bases[exec_data.base_index]->object;
Object *ob_iter = lcd->bases[exec_data.base_index]->object;
ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
BMEdge *e;

View File

@ -46,6 +46,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Path Select Struct & Properties
* \{ */
@ -499,7 +501,7 @@ static void mouse_mesh_shortest_path_edge(
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
if (op_params->edge_mode == EDGE_MODE_TAG_SEAM) {
ED_uvedit_live_unwrap(scene, &obedit, 1);
ED_uvedit_live_unwrap(scene, {obedit});
}
}
@ -724,15 +726,13 @@ static int edbm_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmE
{
int base_index = -1;
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
if (EDBM_unified_findnearest(&vc, bases, bases_len, &base_index, &eve, &eed, &efa)) {
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d);
if (EDBM_unified_findnearest(&vc, bases, &base_index, &eve, &eed, &efa)) {
basact = bases[base_index];
ED_view3d_viewcontext_init_object(&vc, basact->object);
em = vc.em;
}
MEM_freeN(bases);
}
/* If nothing is selected, let's select the picked vertex/edge/face. */
@ -854,11 +854,9 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
bool found_valid_elements = false;
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
BMIter iter;
@ -938,7 +936,6 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
found_valid_elements = true;
}
}
MEM_freeN(objects);
if (!found_valid_elements) {
BKE_report(

View File

@ -45,6 +45,8 @@
#include "DEG_depsgraph.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Local Utilities
* \{ */
@ -64,11 +66,9 @@ static void edbm_flag_disable_all_multi(const Scene *scene,
View3D *v3d,
const char hflag)
{
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (Object *ob_iter : objects) {
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
BMesh *bm_iter = em_iter->bm;
if (bm_iter->totvertsel) {
@ -76,7 +76,6 @@ static void edbm_flag_disable_all_multi(const Scene *scene,
DEG_id_tag_update(static_cast<ID *>(ob_iter->data), ID_RECALC_SELECT);
}
}
MEM_freeN(objects);
}
/** When accessed as a tool, get the active edge from the pre-selection gizmo. */

View File

@ -1025,9 +1025,8 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
const bool do_fill = RNA_boolean_get(op->ptr, "use_fill");
bool no_vertex_selected = true;
@ -1035,8 +1034,7 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool error_disconnected_vertices = true;
bool error_rip_failed = true;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -1110,8 +1108,6 @@ static int edbm_rip_invoke(bContext *C, wmOperator *op, const wmEvent *event)
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
MEM_freeN(objects);
if (no_vertex_selected) {
/* Ignore it. */
return OPERATOR_CANCELLED;

View File

@ -33,6 +33,7 @@
#include "mesh_intern.hh" /* own include */
using blender::float2;
using blender::Vector;
/* uses total number of selected edges around a vertex to choose how to extend */
#define USE_TRICKY_EXTEND
@ -43,12 +44,10 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
RegionView3D *rv3d = CTX_wm_region_view3d(C);
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -218,8 +217,6 @@ static int edbm_rip_edge_invoke(bContext *C, wmOperator * /*op*/, const wmEvent
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -69,6 +69,9 @@
/* use bmesh operator flags for a few operators */
#define BMO_ELE_TAG 1
using blender::Span;
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Select Mirror
* \{ */
@ -172,7 +175,9 @@ void EDBM_select_mirrored(BMEditMesh *em,
/** \name Back-Buffer OpenGL Selection
* \{ */
static BMElem *edbm_select_id_bm_elem_get(Base **bases, const uint sel_id, uint *r_base_index)
static BMElem *edbm_select_id_bm_elem_get(const Span<Base *> bases,
const uint sel_id,
uint *r_base_index)
{
uint elem_id;
char elem_type = 0;
@ -268,8 +273,7 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
float *dist_px_manhattan_p,
const bool use_select_bias,
bool use_cycle,
Base **bases,
uint bases_len,
const Span<Base *> bases,
uint *r_base_index)
{
uint base_index = 0;
@ -282,7 +286,7 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
/* No after-queue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */
{
DRW_select_buffer_context_create(vc->depsgraph, bases, bases_len, SCE_SELECT_VERTEX);
DRW_select_buffer_context_create(vc->depsgraph, bases, SCE_SELECT_VERTEX);
index = DRW_select_buffer_find_nearest_to_point(
vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px_manhattan_test);
@ -325,7 +329,7 @@ BMVert *EDBM_vert_find_nearest_ex(ViewContext *vc,
data.use_select_bias = use_select_bias;
data.use_cycle = use_cycle;
for (; base_index < bases_len; base_index++) {
for (; base_index < bases.size(); base_index++) {
Base *base_iter = bases[base_index];
ED_view3d_viewcontext_init_object(vc, base_iter->object);
if (use_cycle && prev_select.bm == vc->em->bm &&
@ -371,7 +375,7 @@ BMVert *EDBM_vert_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
{
BKE_view_layer_synced_ensure(vc->scene, vc->view_layer);
Base *base = BKE_view_layer_base_find(vc->view_layer, vc->obact);
return EDBM_vert_find_nearest_ex(vc, dist_px_manhattan_p, false, false, &base, 1, nullptr);
return EDBM_vert_find_nearest_ex(vc, dist_px_manhattan_p, false, false, {base}, nullptr);
}
/* find the distance to the edge we already have */
@ -499,8 +503,7 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
const bool use_select_bias,
bool use_cycle,
BMEdge **r_eed_zbuf,
Base **bases,
uint bases_len,
const Span<Base *> bases,
uint *r_base_index)
{
uint base_index = 0;
@ -513,7 +516,7 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
/* No after-queue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */
{
DRW_select_buffer_context_create(vc->depsgraph, bases, bases_len, SCE_SELECT_EDGE);
DRW_select_buffer_context_create(vc->depsgraph, bases, SCE_SELECT_EDGE);
index = DRW_select_buffer_find_nearest_to_point(
vc->depsgraph, vc->region, vc->v3d, vc->mval, 1, UINT_MAX, &dist_px_manhattan_test);
@ -580,7 +583,7 @@ BMEdge *EDBM_edge_find_nearest_ex(ViewContext *vc,
data.use_select_bias = use_select_bias;
data.use_cycle = use_cycle;
for (; base_index < bases_len; base_index++) {
for (; base_index < bases.size(); base_index++) {
Base *base_iter = bases[base_index];
ED_view3d_viewcontext_init_object(vc, base_iter->object);
if (use_cycle && prev_select.bm == vc->em->bm &&
@ -632,7 +635,7 @@ BMEdge *EDBM_edge_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
BKE_view_layer_synced_ensure(vc->scene, vc->view_layer);
Base *base = BKE_view_layer_base_find(vc->view_layer, vc->obact);
return EDBM_edge_find_nearest_ex(
vc, dist_px_manhattan_p, nullptr, false, false, nullptr, &base, 1, nullptr);
vc, dist_px_manhattan_p, nullptr, false, false, nullptr, {base}, nullptr);
}
/* find the distance to the face we already have */
@ -715,8 +718,7 @@ BMFace *EDBM_face_find_nearest_ex(ViewContext *vc,
const bool use_select_bias,
bool use_cycle,
BMFace **r_efa_zbuf,
Base **bases,
uint bases_len,
const Span<Base *> bases,
uint *r_base_index)
{
uint base_index = 0;
@ -733,7 +735,7 @@ BMFace *EDBM_face_find_nearest_ex(ViewContext *vc,
ED_view3d_backbuf_sample_size_clamp(vc->region, *dist_px_manhattan_p));
}
DRW_select_buffer_context_create(vc->depsgraph, bases, bases_len, SCE_SELECT_FACE);
DRW_select_buffer_context_create(vc->depsgraph, bases, SCE_SELECT_FACE);
if (dist_px_manhattan_test == 0) {
index = DRW_select_buffer_sample_point(vc->depsgraph, vc->region, vc->v3d, vc->mval);
@ -803,7 +805,7 @@ BMFace *EDBM_face_find_nearest_ex(ViewContext *vc,
data.use_select_bias = use_select_bias;
data.use_cycle = use_cycle;
for (; base_index < bases_len; base_index++) {
for (; base_index < bases.size(); base_index++) {
Base *base_iter = bases[base_index];
ED_view3d_viewcontext_init_object(vc, base_iter->object);
if (use_cycle && prev_select.bm == vc->em->bm &&
@ -854,7 +856,7 @@ BMFace *EDBM_face_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
BKE_view_layer_synced_ensure(vc->scene, vc->view_layer);
Base *base = BKE_view_layer_base_find(vc->view_layer, vc->obact);
return EDBM_face_find_nearest_ex(
vc, dist_px_manhattan_p, nullptr, false, false, false, nullptr, &base, 1, nullptr);
vc, dist_px_manhattan_p, nullptr, false, false, false, nullptr, {base}, nullptr);
}
#undef FIND_NEAR_SELECT_BIAS
@ -866,8 +868,7 @@ BMFace *EDBM_face_find_nearest(ViewContext *vc, float *dist_px_manhattan_p)
* return 1 if found one
*/
static bool unified_findnearest(ViewContext *vc,
Base **bases,
const uint bases_len,
const Span<Base *> bases,
int *r_base_index,
BMVert **r_eve,
BMEdge **r_eed,
@ -907,7 +908,7 @@ static bool unified_findnearest(ViewContext *vc,
uint base_index = 0;
BMFace *efa_zbuf = nullptr;
BMFace *efa_test = EDBM_face_find_nearest_ex(
vc, &dist, dist_center_p, true, true, use_cycle, &efa_zbuf, bases, bases_len, &base_index);
vc, &dist, dist_center_p, true, true, use_cycle, &efa_zbuf, bases, &base_index);
if (efa_test && dist_center_p) {
dist = min_ff(dist_margin, dist_center);
@ -929,7 +930,7 @@ static bool unified_findnearest(ViewContext *vc,
uint base_index = 0;
BMEdge *eed_zbuf = nullptr;
BMEdge *eed_test = EDBM_edge_find_nearest_ex(
vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf, bases, bases_len, &base_index);
vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf, bases, &base_index);
if (eed_test && dist_center_p) {
dist = min_ff(dist_margin, dist_center);
@ -946,8 +947,7 @@ static bool unified_findnearest(ViewContext *vc,
if ((dist > 0.0f) && (em->selectmode & SCE_SELECT_VERTEX)) {
uint base_index = 0;
BMVert *eve_test = EDBM_vert_find_nearest_ex(
vc, &dist, true, use_cycle, bases, bases_len, &base_index);
BMVert *eve_test = EDBM_vert_find_nearest_ex(vc, &dist, true, use_cycle, bases, &base_index);
if (eve_test) {
hit.v.base_index = base_index;
@ -1001,14 +1001,13 @@ static bool unified_findnearest(ViewContext *vc,
#undef FAKE_SELECT_MODE_END
bool EDBM_unified_findnearest(ViewContext *vc,
Base **bases,
const uint bases_len,
const Span<Base *> bases,
int *r_base_index,
BMVert **r_eve,
BMEdge **r_eed,
BMFace **r_efa)
{
return unified_findnearest(vc, bases, bases_len, r_base_index, r_eve, r_eed, r_efa);
return unified_findnearest(vc, bases, r_base_index, r_eve, r_eed, r_efa);
}
/** \} */
@ -1021,8 +1020,7 @@ bool EDBM_unified_findnearest(ViewContext *vc,
* \{ */
bool EDBM_unified_findnearest_from_raycast(ViewContext *vc,
Base **bases,
const uint bases_len,
const Span<Base *> bases,
bool use_boundary_vertices,
bool use_boundary_edges,
int *r_base_index_vert,
@ -1069,7 +1067,7 @@ bool EDBM_unified_findnearest_from_raycast(ViewContext *vc,
const bool use_edge = (r_eed != nullptr);
const bool use_face = (r_efa != nullptr);
for (uint base_index = 0; base_index < bases_len; base_index++) {
for (const int base_index : bases.index_range()) {
Base *base_iter = bases[base_index];
Object *obedit = base_iter->object;
@ -1541,11 +1539,9 @@ static int edbm_loop_multiselect_exec(bContext *C, wmOperator *op)
const bool is_ring = RNA_boolean_get(op->ptr, "ring");
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totedgesel == 0) {
@ -1600,7 +1596,6 @@ static int edbm_loop_multiselect_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1707,13 +1702,12 @@ static bool mouse_mesh_loop(
const short selectmode = em_original->selectmode;
em_original->selectmode = SCE_SELECT_EDGE;
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d);
{
int base_index = -1;
if (EDBM_unified_findnearest(&vc, bases, bases_len, &base_index, &eve, &eed, &efa)) {
if (EDBM_unified_findnearest(&vc, bases, &base_index, &eve, &eed, &efa)) {
basact = bases[base_index];
ED_view3d_viewcontext_init_object(&vc, basact->object);
em = vc.em;
@ -1726,7 +1720,6 @@ static bool mouse_mesh_loop(
em_original->selectmode = selectmode;
if (em == nullptr || eed == nullptr) {
MEM_freeN(bases);
return false;
}
@ -1749,8 +1742,7 @@ static bool mouse_mesh_loop(
}
if (select_clear) {
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base_iter = bases[base_index];
for (Base *base_iter : bases) {
Object *ob_iter = base_iter->object;
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
@ -1849,8 +1841,6 @@ static bool mouse_mesh_loop(
}
}
MEM_freeN(bases);
DEG_id_tag_update(static_cast<ID *>(vc.obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
@ -1939,14 +1929,12 @@ static int edbm_select_all_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
int action = RNA_enum_get(op->ptr, "action");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel) {
action = SEL_DESELECT;
@ -1955,8 +1943,7 @@ static int edbm_select_all_exec(bContext *C, wmOperator *op)
}
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
switch (action) {
case SEL_SELECT:
@ -1974,8 +1961,6 @@ static int edbm_select_all_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2006,12 +1991,10 @@ static int edbm_faces_select_interior_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (!EDBM_select_interior_faces(em)) {
@ -2021,7 +2004,6 @@ static int edbm_faces_select_interior_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2062,12 +2044,11 @@ bool EDBM_select_pick(bContext *C, const int mval[2], const SelectPick_Params *p
vc.mval[0] = mval[0];
vc.mval[1] = mval[1];
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d);
bool changed = false;
bool found = unified_findnearest(&vc, bases, bases_len, &base_index_active, &eve, &eed, &efa);
bool found = unified_findnearest(&vc, bases, &base_index_active, &eve, &eed, &efa);
if (params->sel_op == SEL_OP_SET) {
BMElem *ele = efa ? (BMElem *)efa : (eed ? (BMElem *)eed : (BMElem *)eve);
@ -2076,8 +2057,7 @@ bool EDBM_select_pick(bContext *C, const int mval[2], const SelectPick_Params *p
}
else if (found || params->deselect_all) {
/* Deselect everything. */
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base_iter = bases[base_index];
for (Base *base_iter : bases) {
Object *ob_iter = base_iter->object;
EDBM_flag_disable_all(BKE_editmesh_from_object(ob_iter), BM_ELEM_SELECT);
DEG_id_tag_update(static_cast<ID *>(ob_iter->data), ID_RECALC_SELECT);
@ -2241,8 +2221,6 @@ bool EDBM_select_pick(bContext *C, const int mval[2], const SelectPick_Params *p
changed = true;
}
MEM_freeN(bases);
return changed;
}
@ -2503,12 +2481,10 @@ bool EDBM_selectmode_toggle_multi(bContext *C,
break;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
if (em_iter != em) {
em_iter->selectmode = em->selectmode;
@ -2516,15 +2492,13 @@ bool EDBM_selectmode_toggle_multi(bContext *C,
}
if (only_update) {
MEM_freeN(objects);
return false;
}
if (use_extend == 0 || em->selectmode == 0) {
if (use_expand) {
const short selmode_max = highest_order_bit_s(ts->selectmode);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
EDBM_selectmode_convert(em_iter, selmode_max, selectmode_new);
}
@ -2558,8 +2532,7 @@ bool EDBM_selectmode_toggle_multi(bContext *C,
if (ret == true) {
ts->selectmode = em->selectmode;
em = nullptr;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
em_iter->selectmode = ts->selectmode;
EDBM_selectmode_set(em_iter);
@ -2571,7 +2544,6 @@ bool EDBM_selectmode_toggle_multi(bContext *C,
DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
}
MEM_freeN(objects);
return ret;
}
@ -2600,12 +2572,10 @@ bool EDBM_selectmode_set_multi(bContext *C, const short selectmode)
changed = true;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
if (em_iter->selectmode != ts->selectmode) {
em_iter->selectmode = ts->selectmode;
@ -2616,7 +2586,6 @@ bool EDBM_selectmode_set_multi(bContext *C, const short selectmode)
changed = true;
}
}
MEM_freeN(objects);
if (changed) {
WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, nullptr);
@ -2716,11 +2685,10 @@ void EDBM_select_swap(BMEditMesh *em) /* exported for UV */
}
}
bool EDBM_mesh_deselect_all_multi_ex(Base **bases, const uint bases_len)
bool EDBM_mesh_deselect_all_multi_ex(const Span<Base *> bases)
{
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base_iter = bases[base_index];
for (Base *base_iter : bases) {
Object *ob_iter = base_iter->object;
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
@ -2739,23 +2707,18 @@ bool EDBM_mesh_deselect_all_multi(bContext *C)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bool changed_multi = EDBM_mesh_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
return EDBM_mesh_deselect_all_multi_ex(bases);
}
bool EDBM_selectmode_disable_multi_ex(Scene *scene,
Base **bases,
const uint bases_len,
const Span<Base *> bases,
const short selectmode_disable,
const short selectmode_fallback)
{
bool changed_multi = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Base *base_iter = bases[base_index];
for (Base *base_iter : bases) {
Object *ob_iter = base_iter->object;
BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
@ -2773,13 +2736,9 @@ bool EDBM_selectmode_disable_multi(bContext *C,
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
Scene *scene = CTX_data_scene(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, nullptr, &bases_len);
bool changed_multi = EDBM_selectmode_disable_multi_ex(
scene, bases, bases_len, selectmode_disable, selectmode_fallback);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, nullptr);
return EDBM_selectmode_disable_multi_ex(scene, bases, selectmode_disable, selectmode_fallback);
}
/** \} */
@ -3264,12 +3223,10 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op)
const int delimit_init = RNA_enum_get(op->ptr, "delimit");
#endif
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -3455,8 +3412,6 @@ static int edbm_select_linked_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3631,21 +3586,19 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE
/* setup view context for argument to callbacks */
ViewContext vc = em_setup_viewcontext(C);
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d);
{
bool has_edges = false;
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *ob_iter = bases[base_index]->object;
for (Base *base : bases) {
Object *ob_iter = base->object;
ED_view3d_viewcontext_init_object(&vc, ob_iter);
if (vc.em->bm->totedge) {
has_edges = true;
}
}
if (has_edges == false) {
MEM_freeN(bases);
return OPERATOR_CANCELLED;
}
}
@ -3656,9 +3609,8 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE
/* return warning! */
{
int base_index = -1;
const bool ok = unified_findnearest(&vc, bases, bases_len, &base_index, &eve, &eed, &efa);
const bool ok = unified_findnearest(&vc, bases, &base_index, &eve, &eed, &efa);
if (!ok) {
MEM_freeN(bases);
return OPERATOR_CANCELLED;
}
basact = bases[base_index];
@ -3693,7 +3645,6 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE
DEG_id_tag_update(static_cast<ID *>(basact->object->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, basact->object->data);
MEM_freeN(bases);
return OPERATOR_FINISHED;
}
@ -3777,15 +3728,13 @@ static int edbm_select_face_by_sides_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
const bool extend = RNA_boolean_get(op->ptr, "extend");
const int numverts = RNA_int_get(op->ptr, "number");
const int type = RNA_enum_get(op->ptr, "type");
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter;
@ -3827,7 +3776,6 @@ static int edbm_select_face_by_sides_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3871,12 +3819,10 @@ static int edbm_select_loose_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
const bool extend = RNA_boolean_get(op->ptr, "extend");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
BMIter iter;
@ -3927,8 +3873,6 @@ static int edbm_select_loose_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3967,12 +3911,10 @@ static int edbm_select_mirror_exec(bContext *C, wmOperator *op)
const int select_mode = em_active->bm->selectmode;
int tot_mirr = 0, tot_fail = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totvertsel == 0) {
@ -4002,7 +3944,6 @@ static int edbm_select_mirror_exec(bContext *C, wmOperator *op)
tot_fail += tot_fail_iter;
tot_mirr += tot_mirr_iter;
}
MEM_freeN(objects);
if (tot_mirr || tot_fail) {
ED_mesh_report_mirror_ex(op, tot_mirr, tot_fail, select_mode);
@ -4042,11 +3983,9 @@ static int edbm_select_more_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
const bool use_face_step = RNA_boolean_get(op->ptr, "use_face_step");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -4059,7 +3998,6 @@ static int edbm_select_more_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4093,11 +4031,9 @@ static int edbm_select_less_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
const bool use_face_step = RNA_boolean_get(op->ptr, "use_face_step");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -4110,7 +4046,6 @@ static int edbm_select_less_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4336,12 +4271,10 @@ static int edbm_select_nth_exec(bContext *C, wmOperator *op)
WM_operator_properties_checker_interval_from_op(op, &op_params);
bool found_active_elt = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if ((em->bm->totvertsel == 0) && (em->bm->totedgesel == 0) && (em->bm->totfacesel == 0)) {
@ -4357,7 +4290,6 @@ static int edbm_select_nth_exec(bContext *C, wmOperator *op)
EDBM_update(static_cast<Mesh *>(obedit->data), &params);
}
}
MEM_freeN(objects);
if (!found_active_elt) {
BKE_report(op->reports, RPT_ERROR, "Mesh object(s) have no active vertex/edge/face");
@ -4411,12 +4343,10 @@ static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMIter iter;
BMEdge *e;
@ -4443,7 +4373,6 @@ static int edbm_select_sharp_edges_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4488,13 +4417,11 @@ static int edbm_select_linked_flat_faces_exec(bContext *C, wmOperator *op)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
const float angle_limit_cos = cosf(RNA_float_get(op->ptr, "sharpness"));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -4546,7 +4473,6 @@ static int edbm_select_linked_flat_faces_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4598,12 +4524,10 @@ static int edbm_select_non_manifold_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMVert *v;
BMEdge *e;
@ -4619,7 +4543,6 @@ static int edbm_select_non_manifold_exec(bContext *C, wmOperator *op)
if (em->selectmode == SCE_SELECT_FACE) {
BKE_report(op->reports, RPT_ERROR, "Does not work in face selection mode");
MEM_freeN(objects);
return OPERATOR_CANCELLED;
}
@ -4654,7 +4577,6 @@ static int edbm_select_non_manifold_exec(bContext *C, wmOperator *op)
EDBM_selectmode_flush(em);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4705,10 +4627,9 @@ static int edbm_select_random_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMIter iter;
@ -4784,7 +4705,6 @@ static int edbm_select_random_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4839,12 +4759,10 @@ static int edbm_select_ungrouped_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const int cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
@ -4882,7 +4800,6 @@ static int edbm_select_ungrouped_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4963,11 +4880,9 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op)
value -= limit;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit_iter = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit_iter : objects) {
BMEditMesh *em_iter = BKE_editmesh_from_object(obedit_iter);
BMesh *bm = em_iter->bm;
@ -5012,7 +4927,6 @@ static int edbm_select_axis_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit_iter->data), ID_RECALC_SELECT);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -5065,11 +4979,9 @@ static int edbm_region_to_loop_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totfacesel == 0) {
@ -5118,7 +5030,6 @@ static int edbm_region_to_loop_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(&obedit->id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -5296,11 +5207,9 @@ static int edbm_loop_to_region_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (em->bm->totedgesel == 0) {
@ -5331,7 +5240,6 @@ static int edbm_loop_to_region_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -5402,11 +5310,9 @@ static int edbm_select_by_attribute_exec(bContext *C, wmOperator * /*op*/)
using namespace blender;
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Mesh *mesh = static_cast<Mesh *>(obedit->data);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -5447,7 +5353,6 @@ static int edbm_select_by_attribute_exec(bContext *C, wmOperator * /*op*/)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -40,6 +40,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Select Similar (Vert/Edge/Face) Operator - common
* \{ */
@ -157,19 +159,16 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
const int compare = RNA_enum_get(op->ptr, "compare");
int tot_faces_selected_all = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
tot_faces_selected_all += em->bm->totfacesel;
}
if (tot_faces_selected_all == 0) {
BKE_report(op->reports, RPT_ERROR, "No face selected");
MEM_freeN(objects);
return OPERATOR_CANCELLED;
}
@ -197,8 +196,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
}
int tree_index = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
Material ***material_array = nullptr;
@ -309,8 +307,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
BLI_kdtree_4d_balance(tree_4d);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
bool changed = false;
@ -471,8 +468,7 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
face_select_all:
BLI_assert(ELEM(type, SIMFACE_SMOOTH, SIMFACE_FREESTYLE));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
@ -493,7 +489,6 @@ static int similar_face_select_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
BLI_kdtree_1d_free(tree_1d);
BLI_kdtree_3d_free(tree_3d);
BLI_kdtree_4d_free(tree_4d);
@ -571,19 +566,16 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
const int compare = RNA_enum_get(op->ptr, "compare");
int tot_edges_selected_all = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
tot_edges_selected_all += em->bm->totedgesel;
}
if (tot_edges_selected_all == 0) {
BKE_report(op->reports, RPT_ERROR, "No edge selected");
MEM_freeN(objects);
return OPERATOR_CANCELLED;
}
@ -608,8 +600,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
}
int tree_index = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
@ -736,8 +727,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
BLI_kdtree_3d_balance(tree_3d);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
bool changed = false;
@ -916,8 +906,7 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
edge_select_all:
BLI_assert(ELEM(type, SIMEDGE_SEAM, SIMEDGE_SHARP, SIMEDGE_FREESTYLE));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
@ -938,7 +927,6 @@ static int similar_edge_select_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
BLI_kdtree_1d_free(tree_1d);
BLI_kdtree_3d_free(tree_3d);
if (gset != nullptr) {
@ -966,19 +954,16 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
const int compare = RNA_enum_get(op->ptr, "compare");
int tot_verts_selected_all = 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
const Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
tot_verts_selected_all += em->bm->totvertsel;
}
if (tot_verts_selected_all == 0) {
BKE_report(op->reports, RPT_ERROR, "No vertex selected");
MEM_freeN(objects);
return OPERATOR_CANCELLED;
}
@ -1004,8 +989,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
int normal_tree_index = 0;
int tree_1d_index = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
int cd_dvert_offset = -1;
@ -1117,8 +1101,7 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
}
/* Run the matching operations. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
bool changed = false;
@ -1273,7 +1256,6 @@ static int similar_vert_select_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
BLI_kdtree_1d_free(tree_1d);
BLI_kdtree_3d_free(tree_3d);
if (gset != nullptr) {

File diff suppressed because it is too large Load Diff

View File

@ -44,6 +44,8 @@
#include "mesh_intern.hh" /* own include */
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Redo API
* \{ */
@ -1786,12 +1788,10 @@ BMElem *EDBM_elem_from_index_any(BMEditMesh *em, uint index)
int EDBM_elem_to_index_any_multi(
const Scene *scene, ViewLayer *view_layer, BMEditMesh *em, BMElem *ele, int *r_object_index)
{
uint bases_len;
int elem_index = -1;
*r_object_index = -1;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, nullptr, &bases_len);
for (uint base_index = 0; base_index < bases_len; base_index++) {
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(scene, view_layer, nullptr);
for (const int base_index : bases.index_range()) {
Base *base_iter = bases[base_index];
if (BKE_editmesh_from_object(base_iter->object) == em) {
*r_object_index = base_index;
@ -1799,7 +1799,6 @@ int EDBM_elem_to_index_any_multi(
break;
}
}
MEM_freeN(bases);
return elem_index;
}
@ -1809,12 +1808,9 @@ BMElem *EDBM_elem_from_index_any_multi(const Scene *scene,
uint elem_index,
Object **r_obedit)
{
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, nullptr, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(scene, view_layer, nullptr);
*r_obedit = nullptr;
Object *obedit = (object_index < bases_len) ? bases[object_index]->object : nullptr;
MEM_freeN(bases);
Object *obedit = (object_index < bases.size()) ? bases[object_index]->object : nullptr;
if (obedit != nullptr) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMElem *ele = EDBM_elem_from_index_any(em, elem_index);

View File

@ -1458,10 +1458,7 @@ MDeformVert *ED_mesh_active_dvert_get_only(Object *ob)
return nullptr;
}
void EDBM_mesh_stats_multi(Object **objects,
const uint objects_len,
int totelem[3],
int totelem_sel[3])
void EDBM_mesh_stats_multi(const Span<Object *> objects, int totelem[3], int totelem_sel[3])
{
if (totelem) {
totelem[0] = 0;
@ -1474,8 +1471,7 @@ void EDBM_mesh_stats_multi(Object **objects,
totelem_sel[2] = 0;
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
if (totelem) {
@ -1491,11 +1487,10 @@ void EDBM_mesh_stats_multi(Object **objects,
}
}
void EDBM_mesh_elem_index_ensure_multi(Object **objects, const uint objects_len, const char htype)
void EDBM_mesh_elem_index_ensure_multi(const Span<Object *> objects, const char htype)
{
int elem_offset[4] = {0, 0, 0, 0};
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
BM_mesh_elem_index_ensure_ex(bm, htype, elem_offset);

View File

@ -48,6 +48,9 @@
#include "mball_intern.h"
using blender::Span;
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Edit Mode Functions
* \{ */
@ -89,12 +92,9 @@ bool ED_mball_deselect_all_multi(bContext *C)
{
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewContext vc = ED_view3d_viewcontext_init(C, depsgraph);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
bool changed_multi = BKE_mball_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
return changed_multi;
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
return BKE_mball_deselect_all_multi_ex(bases);
}
/** \} */
@ -148,35 +148,32 @@ static int mball_select_all_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
if (action == SEL_TOGGLE) {
action = BKE_mball_is_any_selected_multi(bases, bases_len) ? SEL_DESELECT : SEL_SELECT;
action = BKE_mball_is_any_selected_multi(bases) ? SEL_DESELECT : SEL_SELECT;
}
switch (action) {
case SEL_SELECT:
BKE_mball_select_all_multi_ex(bases, bases_len);
BKE_mball_select_all_multi_ex(bases);
break;
case SEL_DESELECT:
BKE_mball_deselect_all_multi_ex(bases, bases_len);
BKE_mball_deselect_all_multi_ex(bases);
break;
case SEL_INVERT:
BKE_mball_select_swap_multi_ex(bases, bases_len);
BKE_mball_select_swap_multi_ex(bases);
break;
}
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
DEG_id_tag_update(&mb->id, ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, mb);
}
MEM_freeN(bases);
return OPERATOR_FINISHED;
}
@ -332,11 +329,10 @@ static int mball_select_similar_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
tot_mball_selected_all = BKE_mball_select_count_multi(bases, bases_len);
tot_mball_selected_all = BKE_mball_select_count_multi(bases);
short type_ref = 0;
KDTree_1d *tree_1d = nullptr;
@ -353,8 +349,8 @@ static int mball_select_similar_exec(bContext *C, wmOperator *op)
}
/* Get type of selected MetaBall */
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
switch (type) {
@ -387,8 +383,8 @@ static int mball_select_similar_exec(bContext *C, wmOperator *op)
BLI_kdtree_3d_balance(tree_3d);
}
/* Select MetaBalls with desired type. */
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
MetaBall *mb = (MetaBall *)obedit->data;
bool changed = false;
@ -419,7 +415,6 @@ static int mball_select_similar_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(bases);
if (tree_1d != nullptr) {
BLI_kdtree_1d_free(tree_1d);
}
@ -464,10 +459,9 @@ static int select_random_metaelems_exec(bContext *C, wmOperator *op)
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
MetaBall *mb = (MetaBall *)obedit->data;
if (!BKE_mball_is_any_unselected(mb)) {
@ -498,7 +492,6 @@ static int select_random_metaelems_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&mb->id, ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, mb);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -531,11 +524,9 @@ static int duplicate_metaelems_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
MetaBall *mb = (MetaBall *)obedit->data;
MetaElem *ml, *newml;
@ -558,7 +549,6 @@ static int duplicate_metaelems_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -589,11 +579,9 @@ static int delete_metaelems_exec(bContext *C, wmOperator * /*op*/)
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
MetaBall *mb = (MetaBall *)obedit->data;
MetaElem *ml, *next;
@ -618,7 +606,6 @@ static int delete_metaelems_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), 0);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -739,8 +726,7 @@ void MBALL_OT_reveal_metaelems(wmOperatorType *ot)
/** \name Select Pick Utility
* \{ */
Base *ED_mball_base_and_elem_from_select_buffer(Base **bases,
uint bases_len,
Base *ED_mball_base_and_elem_from_select_buffer(const Span<Base *> bases,
const uint select_id,
MetaElem **r_ml)
{
@ -748,9 +734,9 @@ Base *ED_mball_base_and_elem_from_select_buffer(Base **bases,
Base *base = nullptr;
MetaElem *ml = nullptr;
/* TODO(@ideasman42): optimize, eg: sort & binary search. */
for (uint base_index = 0; base_index < bases_len; base_index++) {
if (bases[base_index]->object->runtime->select_id == hit_object) {
base = bases[base_index];
for (Base *base_iter : bases) {
if (base_iter->object->runtime->select_id == hit_object) {
base = base_iter;
break;
}
}
@ -790,9 +776,8 @@ static bool ed_mball_findnearest_metaelem(bContext *C,
return false;
}
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc.scene, vc.view_layer, vc.v3d);
int hit_cycle_offset = 0;
if (use_cycle) {
@ -831,7 +816,7 @@ static bool ed_mball_findnearest_metaelem(bContext *C,
}
MetaElem *ml;
Base *base = ED_mball_base_and_elem_from_select_buffer(bases, bases_len, select_id, &ml);
Base *base = ED_mball_base_and_elem_from_select_buffer(bases, select_id, &ml);
if (ml == nullptr) {
continue;
}
@ -842,8 +827,6 @@ static bool ed_mball_findnearest_metaelem(bContext *C,
break;
}
MEM_freeN(bases);
return found;
}

View File

@ -1985,12 +1985,9 @@ static int collection_drop_exec(bContext *C, wmOperator *op)
translate_m4(delta_mat, UNPACK3(offset));
ObjectsInViewLayerParams params = {0};
uint objects_len;
Object **objects = BKE_view_layer_array_selected_objects_params(
view_layer, nullptr, &objects_len, &params);
ED_object_xform_array_m4(objects, objects_len, delta_mat);
MEM_freeN(objects);
blender::Vector<Object *> objects = BKE_view_layer_array_selected_objects_params(
view_layer, nullptr, &params);
ED_object_xform_array_m4(objects.data(), objects.size(), delta_mat);
}
return OPERATOR_FINISHED;
@ -4192,9 +4189,8 @@ static int object_transform_to_mouse_exec(bContext *C, wmOperator *op)
PropertyRNA *prop_matrix = RNA_struct_find_property(op->ptr, "matrix");
if (RNA_property_is_set(op->ptr, prop_matrix)) {
ObjectsInViewLayerParams params = {0};
uint objects_len;
Object **objects = BKE_view_layer_array_selected_objects_params(
view_layer, nullptr, &objects_len, &params);
blender::Vector<Object *> objects = BKE_view_layer_array_selected_objects_params(
view_layer, nullptr, &params);
float matrix[4][4];
RNA_property_float_get_array(op->ptr, prop_matrix, &matrix[0][0]);
@ -4208,9 +4204,7 @@ static int object_transform_to_mouse_exec(bContext *C, wmOperator *op)
invert_m4(mat_src_unit);
mul_m4_m4m4(final_delta, mat_dst_unit, mat_src_unit);
ED_object_xform_array_m4(objects, objects_len, final_delta);
MEM_freeN(objects);
ED_object_xform_array_m4(objects.data(), objects.size(), final_delta);
}
else if (CTX_wm_region_view3d(C)) {
int mval[2];

View File

@ -105,6 +105,8 @@
#include "object_intern.h" /* own include */
using blender::Vector;
static CLG_LogRef LOG = {"ed.object.edit"};
/* prototypes */
@ -133,10 +135,8 @@ Object *ED_object_active_context(const bContext *C)
return ob;
}
Object **ED_object_array_in_mode_or_selected(bContext *C,
bool (*filter_fn)(const Object *ob, void *user_data),
void *filter_user_data,
uint *r_objects_len)
Vector<Object *> ED_object_array_in_mode_or_selected(
bContext *C, bool (*filter_fn)(const Object *ob, void *user_data), void *filter_user_data)
{
ScrArea *area = CTX_wm_area(C);
const Scene *scene = CTX_data_scene(C);
@ -147,7 +147,6 @@ Object **ED_object_array_in_mode_or_selected(bContext *C,
const bool use_objects_in_mode = (ob_active != nullptr) &&
(ob_active->mode & (OB_MODE_EDIT | OB_MODE_POSE));
const eSpace_Type space_type = area ? eSpace_Type(area->spacetype) : SPACE_EMPTY;
Object **objects;
Object *ob = nullptr;
bool use_ob = true;
@ -185,37 +184,28 @@ Object **ED_object_array_in_mode_or_selected(bContext *C,
if ((ob != nullptr) && !filter_fn(ob, filter_user_data)) {
ob = nullptr;
}
*r_objects_len = (ob != nullptr) ? 1 : 0;
objects = static_cast<Object **>(MEM_mallocN(sizeof(*objects) * *r_objects_len, __func__));
if (ob != nullptr) {
objects[0] = ob;
}
return ob ? Vector<Object *>({ob}) : Vector<Object *>();
}
else {
const View3D *v3d = (space_type == SPACE_VIEW3D) ?
static_cast<const View3D *>(area->spacedata.first) :
nullptr;
/* When in a mode that supports multiple active objects, use "objects in mode"
* instead of the object's selection. */
if (use_objects_in_mode) {
ObjectsInModeParams params = {0};
params.object_mode = ob_active->mode;
params.no_dup_data = true;
params.filter_fn = filter_fn;
params.filter_userdata = filter_user_data;
objects = BKE_view_layer_array_from_objects_in_mode_params(
scene, view_layer, v3d, r_objects_len, &params);
}
else {
ObjectsInViewLayerParams params{};
params.no_dup_data = true;
params.filter_fn = filter_fn;
params.filter_userdata = filter_user_data;
objects = BKE_view_layer_array_selected_objects_params(
view_layer, v3d, r_objects_len, &params);
}
const View3D *v3d = (space_type == SPACE_VIEW3D) ?
static_cast<const View3D *>(area->spacedata.first) :
nullptr;
/* When in a mode that supports multiple active objects, use "objects in mode"
* instead of the object's selection. */
if (use_objects_in_mode) {
ObjectsInModeParams params = {0};
params.object_mode = ob_active->mode;
params.no_dup_data = true;
params.filter_fn = filter_fn;
params.filter_userdata = filter_user_data;
return BKE_view_layer_array_from_objects_in_mode_params(scene, view_layer, v3d, &params);
}
return objects;
ObjectsInViewLayerParams params{};
params.no_dup_data = true;
params.filter_fn = filter_fn;
params.filter_userdata = filter_user_data;
return BKE_view_layer_array_selected_objects_params(view_layer, v3d, &params);
}
/** \} */

View File

@ -29,6 +29,8 @@
#include "object_intern.h"
using blender::Vector;
/**
* Generic randomize vertices function
*/
@ -91,10 +93,9 @@ static int object_rand_verts_exec(bContext *C, wmOperator *op)
const uint seed = RNA_int_get(op->ptr, "seed");
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len, eObjectMode(ob_mode));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), eObjectMode(ob_mode));
for (const int ob_index : objects.index_range()) {
Object *ob_iter = objects[ob_index];
TransVertStore tvs = {nullptr};
@ -130,7 +131,6 @@ static int object_rand_verts_exec(bContext *C, wmOperator *op)
changed_multi = true;
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -70,6 +70,7 @@
using blender::float3;
using blender::MutableSpan;
using blender::Span;
using blender::Vector;
static bool vertex_group_supported_poll_ex(bContext *C, const Object *ob);
@ -86,9 +87,9 @@ static bool object_array_for_wpaint_filter(const Object *ob, void *user_data)
return false;
}
static Object **object_array_for_wpaint(bContext *C, uint *r_objects_len)
static Vector<Object *> object_array_for_wpaint(bContext *C)
{
return ED_object_array_in_mode_or_selected(C, object_array_for_wpaint_filter, C, r_objects_len);
return ED_object_array_in_mode_or_selected(C, object_array_for_wpaint_filter, C);
}
static bool vertex_group_use_vert_sel(Object *ob)
@ -3155,12 +3156,8 @@ static int vertex_group_smooth_exec(bContext *C, wmOperator *op)
RNA_enum_get(op->ptr, "group_select_mode"));
const float fac_expand = RNA_float_get(op->ptr, "expand");
uint objects_len;
Object **objects = object_array_for_wpaint(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
const Vector<Object *> objects = object_array_for_wpaint(C);
for (Object *ob : objects) {
int subset_count, vgroup_tot;
const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(
@ -3173,7 +3170,6 @@ static int vertex_group_smooth_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3220,12 +3216,8 @@ static int vertex_group_clean_exec(bContext *C, wmOperator *op)
const eVGroupSelect subset_type = static_cast<eVGroupSelect>(
RNA_enum_get(op->ptr, "group_select_mode"));
uint objects_len;
Object **objects = object_array_for_wpaint(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
const Vector<Object *> objects = object_array_for_wpaint(C);
for (Object *ob : objects) {
int subset_count, vgroup_tot;
const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(
@ -3238,7 +3230,6 @@ static int vertex_group_clean_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3333,10 +3324,8 @@ static int vertex_group_limit_total_exec(bContext *C, wmOperator *op)
RNA_enum_get(op->ptr, "group_select_mode"));
int remove_multi_count = 0;
uint objects_len;
Object **objects = object_array_for_wpaint(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
const Vector<Object *> objects = object_array_for_wpaint(C);
for (Object *ob : objects) {
int subset_count, vgroup_tot;
const bool *vgroup_validmap = BKE_object_defgroup_subset_from_select_type(
@ -3352,7 +3341,6 @@ static int vertex_group_limit_total_exec(bContext *C, wmOperator *op)
}
remove_multi_count += remove_count;
}
MEM_freeN(objects);
if (remove_multi_count) {
BKE_reportf(op->reports,

View File

@ -98,6 +98,8 @@
#include "render_intern.hh" /* own include */
using blender::Vector;
static bool object_materials_supported_poll_ex(bContext *C, const Object *ob);
/* -------------------------------------------------------------------- */
@ -120,10 +122,10 @@ static bool object_array_for_shading_edit_mode_enabled_filter(const Object *ob,
return false;
}
static Object **object_array_for_shading_edit_mode_enabled(bContext *C, uint *r_objects_len)
static Vector<Object *> object_array_for_shading_edit_mode_enabled(bContext *C)
{
return ED_object_array_in_mode_or_selected(
C, object_array_for_shading_edit_mode_enabled_filter, C, r_objects_len);
C, object_array_for_shading_edit_mode_enabled_filter, C);
}
static bool object_array_for_shading_edit_mode_disabled_filter(const Object *ob, void *user_data)
@ -137,10 +139,10 @@ static bool object_array_for_shading_edit_mode_disabled_filter(const Object *ob,
return false;
}
static Object **object_array_for_shading_edit_mode_disabled(bContext *C, uint *r_objects_len)
static Vector<Object *> object_array_for_shading_edit_mode_disabled(bContext *C)
{
return ED_object_array_in_mode_or_selected(
C, object_array_for_shading_edit_mode_disabled_filter, C, r_objects_len);
C, object_array_for_shading_edit_mode_disabled_filter, C);
}
/** \} */
@ -284,10 +286,8 @@ static int material_slot_assign_exec(bContext *C, wmOperator * /*op*/)
Object *obact = CTX_data_active_object(C);
const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : nullptr;
uint objects_len = 0;
Object **objects = object_array_for_shading_edit_mode_enabled(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = object_array_for_shading_edit_mode_enabled(C);
for (Object *ob : objects) {
short mat_nr_active = -1;
if (ob->totcol == 0) {
@ -358,7 +358,6 @@ static int material_slot_assign_exec(bContext *C, wmOperator * /*op*/)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
}
}
MEM_freeN(objects);
return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -390,10 +389,8 @@ static int material_slot_de_select(bContext *C, bool select)
Object *obact = CTX_data_active_object(C);
const Material *mat_active = obact ? BKE_object_material_get(obact, obact->actcol) : nullptr;
uint objects_len = 0;
Object **objects = object_array_for_shading_edit_mode_enabled(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = object_array_for_shading_edit_mode_enabled(C);
for (Object *ob : objects) {
short mat_nr_active = -1;
if (ob->totcol == 0) {
@ -485,8 +482,6 @@ static int material_slot_de_select(bContext *C, bool select)
}
}
MEM_freeN(objects);
return (changed_multi) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -688,10 +683,8 @@ static int material_slot_remove_unused_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
int removed = 0;
uint objects_len = 0;
Object **objects = object_array_for_shading_edit_mode_disabled(C, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
Vector<Object *> objects = object_array_for_shading_edit_mode_disabled(C);
for (Object *ob : objects) {
int actcol = ob->actcol;
for (int slot = 1; slot <= ob->totcol; slot++) {
while (slot <= ob->totcol && !BKE_object_material_slot_used(ob, slot)) {
@ -709,7 +702,6 @@ static int material_slot_remove_unused_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
}
MEM_freeN(objects);
if (!removed) {
return OPERATOR_CANCELLED;
@ -1558,18 +1550,16 @@ static blender::Vector<Object *> lightprobe_cache_irradiance_volume_subset_get(b
break;
}
case LIGHTCACHE_SUBSET_SELECTED: {
uint objects_len = 0;
ObjectsInViewLayerParams parameters;
parameters.filter_fn = nullptr;
parameters.no_dup_data = true;
Object **objects = BKE_view_layer_array_selected_objects_params(
view_layer, nullptr, &objects_len, &parameters);
for (Object *ob : blender::MutableSpan<Object *>(objects, objects_len)) {
Vector<Object *> objects = BKE_view_layer_array_selected_objects_params(
view_layer, nullptr, &parameters);
for (Object *ob : objects) {
if (is_irradiance_volume(ob)) {
irradiance_volume_setup(ob);
}
}
MEM_freeN(objects);
break;
}
case LIGHTCACHE_SUBSET_ACTIVE: {

View File

@ -56,6 +56,8 @@
#include "screen_intern.h"
using blender::Vector;
const char *screen_context_dir[] = {
"scene",
"view_layer",
@ -270,11 +272,9 @@ static eContextResult screen_ctx_visible_or_editable_bones_(const bContext *C,
EditBone *flipbone = nullptr;
if (arm && arm->edbo) {
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint i = 0; i < objects_len; i++) {
Object *ob = objects[i];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
arm = static_cast<bArmature *>(ob->data);
/* Attention: X-Axis Mirroring is also handled here... */
@ -314,7 +314,6 @@ static eContextResult screen_ctx_visible_or_editable_bones_(const bContext *C,
}
}
}
MEM_freeN(objects);
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return CTX_RESULT_OK;
@ -343,11 +342,9 @@ static eContextResult screen_ctx_selected_bones_(const bContext *C,
EditBone *flipbone = nullptr;
if (arm && arm->edbo) {
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint i = 0; i < objects_len; i++) {
Object *ob = objects[i];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *ob : objects) {
arm = static_cast<bArmature *>(ob->data);
/* Attention: X-Axis Mirroring is also handled here... */
@ -387,7 +384,6 @@ static eContextResult screen_ctx_selected_bones_(const bContext *C,
}
}
}
MEM_freeN(objects);
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return CTX_RESULT_OK;

View File

@ -87,6 +87,8 @@
#include "image_intern.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name View Navigation Utilities
* \{ */
@ -954,11 +956,9 @@ static int image_view_selected_exec(bContext *C, wmOperator * /*op*/)
/* get bounds */
float min[2], max[2];
if (ED_space_image_show_uvedit(sima, obedit)) {
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
bool success = ED_uvedit_minmax_multi(scene, objects, objects_len, min, max);
MEM_freeN(objects);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
bool success = ED_uvedit_minmax_multi(scene, objects, min, max);
if (!success) {
return OPERATOR_CANCELLED;
}

View File

@ -532,12 +532,11 @@ static void tree_element_posechannel_activate(bContext *C,
if (!(pchan->bone->flag & BONE_HIDDEN_P)) {
if (set != OL_SETSEL_EXTEND) {
/* Single select forces all other bones to get unselected. */
uint objects_len = 0;
Object **objects = BKE_object_pose_array_get_unique(
scene, view_layer, nullptr, &objects_len);
const Vector<Object *> objects = BKE_object_pose_array_get_unique(
scene, view_layer, nullptr);
for (uint object_index = 0; object_index < objects_len; object_index++) {
Object *ob_iter = BKE_object_pose_armature_get(objects[object_index]);
for (Object *ob : objects) {
Object *ob_iter = BKE_object_pose_armature_get(ob);
/* Sanity checks. */
if (ELEM(nullptr, ob_iter, ob_iter->pose, ob_iter->data)) {
@ -552,7 +551,6 @@ static void tree_element_posechannel_activate(bContext *C,
DEG_id_tag_update(static_cast<ID *>(ob_iter->data), ID_RECALC_SELECT);
}
}
MEM_freeN(objects);
}
if ((set == OL_SETSEL_EXTEND) && (pchan->bone->flag & BONE_SELECTED)) {
@ -639,16 +637,14 @@ static void tree_element_ebone_activate(bContext *C,
if (set == OL_SETSEL_NORMAL) {
if (!(ebone->flag & BONE_HIDDEN_A)) {
uint bases_len = 0;
ObjectsInModeParams ob_params{};
ob_params.object_mode = OB_MODE_EDIT;
ob_params.no_dup_data = true;
Base **bases = BKE_view_layer_array_from_bases_in_mode_params(
scene, view_layer, nullptr, &bases_len, &ob_params);
ED_armature_edit_deselect_all_multi_ex(bases, bases_len);
MEM_freeN(bases);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_mode_params(
scene, view_layer, nullptr, &ob_params);
ED_armature_edit_deselect_all_multi_ex(bases);
tree_element_active_ebone__sel(C, arm, ebone, true);
}

View File

@ -2223,7 +2223,7 @@ static void validate_object_select_id(Depsgraph *depsgraph,
if (obact_eval && ((obact_eval->base_flag & BASE_ENABLED_AND_MAYBE_VISIBLE_IN_VIEWPORT) != 0)) {
BKE_view_layer_synced_ensure(scene, view_layer);
Base *base = BKE_view_layer_base_find(view_layer, obact);
DRW_select_buffer_context_create(depsgraph, &base, 1, -1);
DRW_select_buffer_context_create(depsgraph, {base}, -1);
}
v3d->runtime.flag |= V3D_RUNTIME_DEPTHBUF_OVERRIDDEN;

View File

@ -44,6 +44,8 @@
#include "ED_screen.hh"
#include "ED_view3d.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Shared Internal API
* \{ */
@ -83,8 +85,7 @@ static bool gizmo_preselect_poll_for_draw(const bContext *C, wmGizmo *gz)
struct MeshElemGizmo3D {
wmGizmo gizmo;
Base **bases;
uint bases_len;
Vector<Base *> bases;
int base_index;
int vert_index;
int edge_index;
@ -134,12 +135,10 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
BKE_view_layer_synced_ensure(scene, view_layer);
if ((gz_ele->bases) == nullptr ||
if (gz_ele->bases.is_empty() ||
(gz_ele->bases[0] != BKE_view_layer_active_base_get(view_layer)))
{
MEM_SAFE_FREE(gz_ele->bases);
gz_ele->bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, v3d, &gz_ele->bases_len);
gz_ele->bases = BKE_view_layer_array_from_bases_in_edit_mode(scene, view_layer, v3d);
}
}
@ -157,7 +156,6 @@ static int gizmo_preselect_elem_test_select(bContext *C, wmGizmo *gz, const int
if (EDBM_unified_findnearest_from_raycast(&vc,
gz_ele->bases,
gz_ele->bases_len,
false,
true,
&base_index_vert,
@ -276,6 +274,7 @@ static void gizmo_preselect_elem_setup(wmGizmo *gz)
gz_ele->psel = EDBM_preselect_elem_create();
}
gz_ele->base_index = -1;
new (&gz_ele->bases) Vector<Base *>();
}
static void gizmo_preselect_elem_free(wmGizmo *gz)
@ -283,7 +282,7 @@ static void gizmo_preselect_elem_free(wmGizmo *gz)
MeshElemGizmo3D *gz_ele = (MeshElemGizmo3D *)gz;
EDBM_preselect_elem_destroy(gz_ele->psel);
gz_ele->psel = nullptr;
MEM_SAFE_FREE(gz_ele->bases);
gz_ele->bases.~Vector();
}
static int gizmo_preselect_elem_invoke(bContext * /*C*/,
@ -321,8 +320,7 @@ static void GIZMO_GT_mesh_preselect_elem_3d(wmGizmoType *gzt)
struct MeshEdgeRingGizmo3D {
wmGizmo gizmo;
Base **bases;
uint bases_len;
Vector<Base *> bases;
int base_index;
int edge_index;
EditMesh_PreSelEdgeRing *psel;
@ -364,12 +362,10 @@ static int gizmo_preselect_edgering_test_select(bContext *C, wmGizmo *gz, const
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
BKE_view_layer_synced_ensure(scene, view_layer);
if ((gz_ring->bases) == nullptr ||
if (gz_ring->bases.is_empty() ||
(gz_ring->bases[0] != BKE_view_layer_active_base_get(view_layer)))
{
MEM_SAFE_FREE(gz_ring->bases);
gz_ring->bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, v3d, &gz_ring->bases_len);
gz_ring->bases = BKE_view_layer_array_from_bases_in_edit_mode(scene, view_layer, v3d);
}
}
@ -377,15 +373,8 @@ static int gizmo_preselect_edgering_test_select(bContext *C, wmGizmo *gz, const
copy_v2_v2_int(vc.mval, mval);
uint base_index;
BMEdge *eed_test = EDBM_edge_find_nearest_ex(&vc,
&best.dist,
nullptr,
false,
false,
nullptr,
gz_ring->bases,
gz_ring->bases_len,
&base_index);
BMEdge *eed_test = EDBM_edge_find_nearest_ex(
&vc, &best.dist, nullptr, false, false, nullptr, gz_ring->bases, &base_index);
if (eed_test) {
best.ob = gz_ring->bases[base_index]->object;
@ -446,6 +435,7 @@ static void gizmo_preselect_edgering_setup(wmGizmo *gz)
gz_ring->psel = EDBM_preselect_edgering_create();
}
gz_ring->base_index = -1;
new (&gz_ring->bases) Vector<Base *>();
}
static void gizmo_preselect_edgering_free(wmGizmo *gz)
@ -453,7 +443,7 @@ static void gizmo_preselect_edgering_free(wmGizmo *gz)
MeshEdgeRingGizmo3D *gz_ring = (MeshEdgeRingGizmo3D *)gz;
EDBM_preselect_edgering_destroy(gz_ring->psel);
gz_ring->psel = nullptr;
MEM_SAFE_FREE(gz_ring->bases);
gz_ring->bases.~Vector();
}
static int gizmo_preselect_edgering_invoke(bContext * /*C*/,
@ -516,14 +506,12 @@ void ED_view3d_gizmo_mesh_preselect_get_active(bContext *C,
Base *base = nullptr;
Object *obedit = nullptr;
{
uint bases_len;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, CTX_wm_view3d(C), &bases_len);
if (object_index < bases_len) {
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
scene, view_layer, CTX_wm_view3d(C));
if (object_index < bases.size()) {
base = bases[object_index];
obedit = base->object;
}
MEM_freeN(bases);
}
*r_base = base;

View File

@ -106,6 +106,8 @@
// #include "BLI_time_utildefines.h"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Public Utilities
* \{ */
@ -203,19 +205,17 @@ struct EditSelectBuf_Cache {
static void editselect_buf_cache_init(ViewContext *vc, short select_mode)
{
if (vc->obedit) {
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc->scene, vc->view_layer, vc->v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode(
vc->scene, vc->view_layer, vc->v3d);
DRW_select_buffer_context_create(vc->depsgraph, bases, bases_len, select_mode);
MEM_freeN(bases);
DRW_select_buffer_context_create(vc->depsgraph, bases, select_mode);
}
else {
/* Use for paint modes, currently only a single object at a time. */
if (vc->obact) {
BKE_view_layer_synced_ensure(vc->scene, vc->view_layer);
Base *base = BKE_view_layer_base_find(vc->view_layer, vc->obact);
DRW_select_buffer_context_create(vc->depsgraph, &base, 1, select_mode);
DRW_select_buffer_context_create(vc->depsgraph, {base}, select_mode);
}
}
}
@ -3091,10 +3091,8 @@ static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPi
/* Setup view context for argument to callbacks. */
ViewContext vc = ED_view3d_viewcontext_init(&C, depsgraph);
uint bases_len;
Base **bases_ptr = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d, &bases_len);
Span<Base *> bases(bases_ptr, bases_len);
const Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc.scene, vc.view_layer, vc.v3d);
Curves &active_curves_id = *static_cast<Curves *>(vc.obedit->data);
const bke::AttrDomain selection_domain = bke::AttrDomain(active_curves_id.selection_domain);
@ -3105,7 +3103,7 @@ static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPi
ClosestCurveDataBlock(),
[&](const IndexRange range, const ClosestCurveDataBlock &init) {
ClosestCurveDataBlock new_closest = init;
for (Base *base : bases.slice(range)) {
for (Base *base : bases.as_span().slice(range)) {
Object &curves_ob = *base->object;
Curves &curves_id = *static_cast<Curves *>(curves_ob.data);
bke::crazyspace::GeometryDeformation deformation =
@ -3135,7 +3133,7 @@ static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPi
std::atomic<bool> deselected = false;
if (params.deselect_all || params.sel_op == SEL_OP_SET) {
threading::parallel_for(bases.index_range(), 1L, [&](const IndexRange range) {
for (Base *base : bases.slice(range)) {
for (Base *base : bases.as_span().slice(range)) {
Curves &curves_id = *static_cast<Curves *>(base->object->data);
bke::CurvesGeometry &curves = curves_id.geometry.wrap();
if (!ed::curves::has_anything_selected(curves)) {
@ -3156,7 +3154,6 @@ static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPi
}
if (!closest.curves_id) {
MEM_freeN(bases_ptr);
return deselected;
}
@ -3171,8 +3168,6 @@ static bool ed_curves_select_pick(bContext &C, const int mval[2], const SelectPi
DEG_id_tag_update(&closest.curves_id->id, ID_RECALC_GEOMETRY);
WM_event_add_notifier(&C, NC_GEOM | ND_DATA, closest.curves_id);
MEM_freeN(bases_ptr);
return true;
}
@ -3995,16 +3990,15 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel
hits = view3d_opengl_select(vc, &buffer, rect, VIEW3D_SELECT_ALL, VIEW3D_SELECT_FILTER_NOP);
uint bases_len = 0;
Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d, &bases_len);
Vector<Base *> bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(
vc->scene, vc->view_layer, vc->v3d);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
changed |= ED_armature_edit_deselect_all_visible_multi_ex(bases, bases_len);
changed |= ED_armature_edit_deselect_all_visible_multi_ex(bases);
}
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
obedit->id.tag &= ~LIB_TAG_DOIT;
bArmature *arm = static_cast<bArmature *>(obedit->data);
@ -4020,15 +4014,14 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel
}
EditBone *ebone;
Base *base_edit = ED_armature_base_and_ebone_from_select_buffer(
bases, bases_len, select_id, &ebone);
Base *base_edit = ED_armature_base_and_ebone_from_select_buffer(bases, select_id, &ebone);
ebone->temp.i |= select_id & BONESEL_ANY;
base_edit->object->id.tag |= LIB_TAG_DOIT;
}
}
for (uint base_index = 0; base_index < bases_len; base_index++) {
Object *obedit = bases[base_index]->object;
for (Base *base : bases) {
Object *obedit = base->object;
if (obedit->id.tag & LIB_TAG_DOIT) {
obedit->id.tag &= ~LIB_TAG_DOIT;
changed |= ED_armature_edit_select_op_from_tagged(static_cast<bArmature *>(obedit->data),
@ -4036,8 +4029,6 @@ static bool do_armature_box_select(ViewContext *vc, const rcti *rect, const eSel
}
}
MEM_freeN(bases);
return changed;
}
@ -4108,8 +4099,7 @@ static bool do_object_box_select(bContext *C,
buf_iter++)
{
bPoseChannel *pchan_dummy;
Base *base = ED_armature_base_and_pchan_from_select_buffer(
bases.data(), bases.size(), buf_iter->id, &pchan_dummy);
Base *base = ED_armature_base_and_pchan_from_select_buffer(bases, buf_iter->id, &pchan_dummy);
if (base != nullptr) {
base->object->id.tag |= LIB_TAG_DOIT;
}
@ -4167,8 +4157,7 @@ static bool do_pose_box_select(bContext *C,
buf_iter++)
{
Bone *bone;
Base *base = ED_armature_base_and_bone_from_select_buffer(
bases.data(), bases.size(), buf_iter->id, &bone);
Base *base = ED_armature_base_and_bone_from_select_buffer(bases, buf_iter->id, &bone);
if (base == nullptr) {
continue;

View File

@ -79,12 +79,9 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *op)
if (OBEDIT_FROM_OBACT(obact)) {
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
if (obedit->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@ -122,14 +119,11 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *op)
}
ED_transverts_free(&tvs);
}
MEM_freeN(objects);
}
else if (OBPOSE_FROM_OBACT(obact)) {
KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID);
uint objects_len = 0;
Object **objects_eval = BKE_object_pose_array_get(scene, view_layer_eval, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_eval = objects_eval[ob_index];
Vector<Object *> objects_eval = BKE_object_pose_array_get(scene, view_layer_eval, v3d);
for (Object *ob_eval : objects_eval) {
Object *ob = DEG_get_original_object(ob_eval);
bArmature *arm_eval = static_cast<bArmature *>(ob_eval->data);
@ -179,7 +173,6 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
}
MEM_freeN(objects_eval);
}
else {
/* Object mode. */
@ -332,10 +325,9 @@ static bool snap_selected_to_location(bContext *C,
if (obedit) {
float snap_target_local[3];
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (const int ob_index : objects.index_range()) {
obedit = objects[ob_index];
if (obedit->type == OB_MESH) {
@ -382,16 +374,13 @@ static bool snap_selected_to_location(bContext *C,
}
ED_transverts_free(&tvs);
}
MEM_freeN(objects);
}
else if (OBPOSE_FROM_OBACT(obact)) {
KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_object_pose_array_get(scene, view_layer, v3d, &objects_len);
Vector<Object *> objects = BKE_object_pose_array_get(scene, view_layer, v3d);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
bArmature *arm = static_cast<bArmature *>(ob->data);
float snap_target_local[3];
@ -461,7 +450,6 @@ static bool snap_selected_to_location(bContext *C,
DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY);
}
MEM_freeN(objects);
}
else {
KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID);
@ -789,10 +777,9 @@ static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_curs
if (obedit) {
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (const int ob_index : objects.index_range()) {
obedit = objects[ob_index];
/* We can do that quick check for meshes only... */
@ -824,7 +811,6 @@ static bool snap_curs_to_sel_ex(bContext *C, const int pivot_point, float r_curs
}
ED_transverts_free(&tvs);
}
MEM_freeN(objects);
}
else {
Object *obact = CTX_data_active_object(C);

View File

@ -790,10 +790,7 @@ static void init_proportional_edit(TransInfo *t)
}
/* For multi object editing. */
static void init_TransDataContainers(TransInfo *t,
Object *obact,
Object **objects,
uint objects_len)
static void init_TransDataContainers(TransInfo *t, Object *obact, Span<Object *> objects)
{
if (!ELEM(t->data_type,
&TransConvertType_Pose,
@ -825,26 +822,25 @@ static void init_TransDataContainers(TransInfo *t,
MEM_freeN(t->data_container);
}
bool free_objects = false;
if (objects == nullptr) {
Vector<Object *> local_objects;
if (objects.is_empty()) {
ObjectsInModeParams params = {0};
params.object_mode = object_mode;
/* Pose transform operates on `ob->pose` so don't skip duplicate object-data. */
params.no_dup_data = (object_mode & OB_MODE_POSE) == 0;
objects = BKE_view_layer_array_from_objects_in_mode_params(
local_objects = BKE_view_layer_array_from_objects_in_mode_params(
t->scene,
t->view_layer,
static_cast<const View3D *>((t->spacetype == SPACE_VIEW3D) ? t->view : nullptr),
&objects_len,
&params);
free_objects = true;
objects = local_objects;
}
t->data_container = static_cast<TransDataContainer *>(
MEM_callocN(sizeof(*t->data_container) * objects_len, __func__));
t->data_container_len = objects_len;
MEM_callocN(sizeof(*t->data_container) * objects.size(), __func__));
t->data_container_len = objects.size();
for (int i = 0; i < objects_len; i++) {
for (int i = 0; i < objects.size(); i++) {
TransDataContainer *tc = &t->data_container[i];
if (!(t->flag & T_NO_MIRROR) && (objects[i]->type == OB_MESH)) {
tc->use_mirror_axis_x = (((Mesh *)objects[i]->data)->symmetry & ME_SYMMETRY_X) != 0;
@ -882,10 +878,6 @@ static void init_TransDataContainers(TransInfo *t,
}
/* Otherwise leave as zero. */
}
if (free_objects) {
MEM_freeN(objects);
}
}
}
@ -1046,12 +1038,12 @@ void create_trans_data(bContext *C, TransInfo *t)
t->flag |= eTFlag(t->data_type->flags);
if (ob_armature) {
init_TransDataContainers(t, ob_armature, &ob_armature, 1);
init_TransDataContainers(t, ob_armature, {ob_armature});
}
else {
BKE_view_layer_synced_ensure(t->scene, t->view_layer);
Object *ob = BKE_view_layer_active_object_get(t->view_layer);
init_TransDataContainers(t, ob, nullptr, 0);
init_TransDataContainers(t, ob, {});
}
if (t->data_type == &TransConvertType_Object) {

View File

@ -51,6 +51,8 @@
#include "transform.hh"
#include "transform_gizmo.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Shared Callback's
* \{ */
@ -237,13 +239,11 @@ static bool gizmo2d_calc_bounds(const bContext *C, float *r_center, float *r_min
if (area->spacetype == SPACE_IMAGE) {
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr, &objects_len);
if (ED_uvedit_minmax_multi(scene, objects, objects_len, r_min, r_max)) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
if (ED_uvedit_minmax_multi(scene, objects, r_min, r_max)) {
has_select = true;
}
MEM_freeN(objects);
}
else if (area->spacetype == SPACE_SEQ) {
Scene *scene = CTX_data_scene(C);

View File

@ -607,16 +607,13 @@ static int gizmo_3d_foreach_selected(const bContext *C,
#define FOREACH_EDIT_OBJECT_BEGIN(ob_iter, use_mat_local) \
{ \
invert_m4_m4(obedit->world_to_object, obedit->object_to_world); \
uint objects_len = 0; \
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode( \
scene, view_layer, CTX_wm_view3d(C), &objects_len); \
for (uint ob_index = 0; ob_index < objects_len; ob_index++) { \
Object *ob_iter = objects[ob_index]; \
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode( \
scene, view_layer, CTX_wm_view3d(C)); \
for (Object * ob_iter : objects) { \
const bool use_mat_local = (ob_iter != obedit);
#define FOREACH_EDIT_OBJECT_END() \
} \
MEM_freeN(objects); \
} \
((void)0)
@ -847,11 +844,9 @@ static int gizmo_3d_foreach_selected(const bContext *C,
else if (ob && (ob->mode & OB_MODE_POSE)) {
invert_m4_m4(ob->world_to_object, ob->object_to_world);
uint objects_len = 0;
Object **objects = BKE_object_pose_array_get(scene, view_layer, v3d, &objects_len);
Vector<Object *> objects = BKE_object_pose_array_get(scene, view_layer, v3d);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob_iter = objects[ob_index];
for (Object *ob_iter : objects) {
const bool use_mat_local = (ob_iter != ob);
/* mislead counting bones... bah. We don't know the gizmo mode, could be mixed */
const int mode = TFM_ROTATION;
@ -880,7 +875,6 @@ static int gizmo_3d_foreach_selected(const bContext *C,
}
}
}
MEM_freeN(objects);
}
else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
if (ob->mode & OB_MODE_SCULPT) {

View File

@ -1180,15 +1180,14 @@ static void snap_target_uv_fn(TransInfo *t, float * /*vec*/)
{
BLI_assert(t->spacetype == SPACE_IMAGE);
if (t->tsnap.mode & SCE_SNAP_TO_VERTEX) {
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
t->scene, t->view_layer, nullptr, &objects_len);
const Vector<Object *> objects =
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
t->scene, t->view_layer, nullptr);
float dist_sq = square_f(float(SNAP_MIN_DISTANCE));
if (ED_uvedit_nearest_uv_multi(&t->region->v2d,
t->scene,
objects,
objects_len,
t->mval,
t->tsnap.target_operation & SCE_SNAP_TARGET_NOT_SELECTED,
&dist_sq,
@ -1202,7 +1201,6 @@ static void snap_target_uv_fn(TransInfo *t, float * /*vec*/)
else {
t->tsnap.status &= ~SNAP_TARGET_FOUND;
}
MEM_freeN(objects);
}
}

View File

@ -38,11 +38,14 @@
#include "WM_api.hh"
#include "WM_types.hh"
using blender::Span;
using blender::Vector;
#define B_UVEDIT_VERTEX 3
/* UV Utilities */
static int uvedit_center(Scene *scene, Object **objects, uint objects_len, float center[2])
static int uvedit_center(Scene *scene, const Span<Object *> objects, float center[2])
{
BMFace *f;
BMLoop *l;
@ -52,8 +55,7 @@ static int uvedit_center(Scene *scene, Object **objects, uint objects_len, float
zero_v2(center);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
@ -80,18 +82,14 @@ static int uvedit_center(Scene *scene, Object **objects, uint objects_len, float
return tot;
}
static void uvedit_translate(Scene *scene,
Object **objects,
uint objects_len,
const float delta[2])
static void uvedit_translate(Scene *scene, const Span<Object *> objects, const float delta[2])
{
BMFace *f;
BMLoop *l;
BMIter iter, liter;
float *luv;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
@ -121,13 +119,12 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block)
Scene *scene = CTX_data_scene(C);
float center[2];
int imx, imy, step, digits;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, CTX_data_view_layer(C), CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, CTX_data_view_layer(C), CTX_wm_view3d(C));
ED_space_image_get_size(sima, &imx, &imy);
if (uvedit_center(scene, objects, objects_len, center)) {
if (uvedit_center(scene, objects, center)) {
float range_xy[2][2] = {
{-10.0f, 10.0f},
{-10.0f, 10.0f},
@ -194,8 +191,6 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block)
UI_but_number_precision_set(but, digits);
UI_block_align_end(block);
}
MEM_freeN(objects);
}
static void do_uvedit_vertex(bContext *C, void * /*arg*/, int event)
@ -209,12 +204,11 @@ static void do_uvedit_vertex(bContext *C, void * /*arg*/, int event)
return;
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, CTX_data_view_layer(C), CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, CTX_data_view_layer(C), CTX_wm_view3d(C));
ED_space_image_get_size(sima, &imx, &imy);
uvedit_center(scene, objects, objects_len, center);
uvedit_center(scene, objects, center);
if (sima->flag & SI_COORDFLOATS) {
delta[0] = uvedit_old_center[0] - center[0];
@ -225,15 +219,12 @@ static void do_uvedit_vertex(bContext *C, void * /*arg*/, int event)
delta[1] = uvedit_old_center[1] / imy - center[1];
}
uvedit_translate(scene, objects, objects_len, delta);
uvedit_translate(scene, objects, delta);
WM_event_add_notifier(C, NC_IMAGE, sima->image);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
DEG_id_tag_update((ID *)obedit->data, ID_RECALC_GEOMETRY);
}
MEM_freeN(objects);
}
/* Panels */

View File

@ -36,6 +36,8 @@
#include "uvedit_clipboard_graph_iso.hh"
#include "uvedit_intern.hh" /* linker, extern "C" */
using blender::Vector;
void UV_clipboard_free();
class UV_ClipboardBuffer {
@ -279,12 +281,10 @@ static int uv_copy_exec(bContext *C, wmOperator * /*op*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
Scene *scene = CTX_data_scene(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
const bool use_seams = false;
@ -297,8 +297,6 @@ static int uv_copy_exec(bContext *C, wmOperator * /*op*/)
BM_uv_element_map_free(element_map);
}
MEM_freeN(objects);
/* TODO: Serialize `UvClipboard` to system clipboard. */
return OPERATOR_FINISHED;
@ -313,15 +311,13 @@ static int uv_paste_exec(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
Scene *scene = CTX_data_scene(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
bool changed_multi = false;
int complicated_search = 0;
int total_search = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
const bool use_seams = false;
@ -371,8 +367,6 @@ static int uv_paste_exec(bContext *C, wmOperator *op)
total_search);
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}

View File

@ -46,8 +46,7 @@ UvNearestHit uv_nearest_hit_init_max(const View2D *v2d);
bool uv_find_nearest_vert(
Scene *scene, Object *obedit, const float co[2], float penalty_dist, UvNearestHit *hit);
bool uv_find_nearest_vert_multi(Scene *scene,
Object **objects,
uint objects_len,
blender::Span<Object *> objects,
const float co[2],
float penalty_dist,
UvNearestHit *hit);
@ -55,8 +54,7 @@ bool uv_find_nearest_vert_multi(Scene *scene,
bool uv_find_nearest_edge(
Scene *scene, Object *obedit, const float co[2], float penalty, UvNearestHit *hit);
bool uv_find_nearest_edge_multi(Scene *scene,
Object **objects,
uint objects_len,
blender::Span<Object *> objects,
const float co[2],
float penalty,
UvNearestHit *hit);
@ -74,13 +72,14 @@ bool uv_find_nearest_face_ex(
Scene *scene, Object *obedit, const float co[2], UvNearestHit *hit, bool only_in_face);
bool uv_find_nearest_face(Scene *scene, Object *obedit, const float co[2], UvNearestHit *hit);
bool uv_find_nearest_face_multi_ex(Scene *scene,
Object **objects,
uint objects_len,
blender::Span<Object *> objects,
const float co[2],
UvNearestHit *hit,
bool only_in_face);
bool uv_find_nearest_face_multi(
Scene *scene, Object **objects, uint objects_len, const float co[2], UvNearestHit *hit);
bool uv_find_nearest_face_multi(Scene *scene,
blender::Span<Object *> objects,
const float co[2],
UvNearestHit *hit);
BMLoop *uv_find_nearest_loop_from_vert(Scene *scene, Object *obedit, BMVert *v, const float co[2]);
BMLoop *uv_find_nearest_loop_from_edge(Scene *scene, Object *obedit, BMEdge *e, const float co[2]);
@ -120,7 +119,7 @@ void UV_OT_shortest_path_select(wmOperatorType *ot);
/* `uvedit_select.cc` */
bool uvedit_select_is_any_selected(const Scene *scene, Object *obedit);
bool uvedit_select_is_any_selected_multi(const Scene *scene, Object **objects, uint objects_len);
bool uvedit_select_is_any_selected_multi(const Scene *scene, blender::Span<Object *> objects);
/**
* \warning This returns first selected UV,
* not ideal in many cases since there could be multiple.

View File

@ -226,25 +226,25 @@ void ED_uvedit_foreach_uv(const Scene *scene,
}
void ED_uvedit_foreach_uv_multi(const Scene *scene,
Object **objects_edit,
uint objects_len,
const Span<Object *> objects_edit,
const bool skip_invisible,
const bool skip_nonselected,
FunctionRef<void(float[2])> user_fn)
{
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects_edit[ob_index];
for (Object *obedit : objects_edit) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
ED_uvedit_foreach_uv(scene, em->bm, skip_invisible, skip_nonselected, user_fn);
}
}
bool ED_uvedit_minmax_multi(
const Scene *scene, Object **objects_edit, uint objects_len, float r_min[2], float r_max[2])
bool ED_uvedit_minmax_multi(const Scene *scene,
const Span<Object *> objects_edit,
float r_min[2],
float r_max[2])
{
bool changed = false;
INIT_MINMAX2(r_min, r_max);
ED_uvedit_foreach_uv_multi(scene, objects_edit, objects_len, true, true, [&](float luv[2]) {
ED_uvedit_foreach_uv_multi(scene, objects_edit, true, true, [&](float luv[2]) {
minmax_v2v2_v2(r_min, r_max, luv);
changed = true;
});
@ -267,14 +267,13 @@ void ED_uvedit_select_all(BMesh *bm)
}
static bool ED_uvedit_median_multi(const Scene *scene,
Object **objects_edit,
uint objects_len,
const Span<Object *> objects_edit,
float co[2])
{
uint sel = 0;
zero_v2(co);
ED_uvedit_foreach_uv_multi(scene, objects_edit, objects_len, true, true, [&](float luv[2]) {
ED_uvedit_foreach_uv_multi(scene, objects_edit, true, true, [&](float luv[2]) {
add_v2_v2(co, luv);
sel++;
});
@ -284,20 +283,22 @@ static bool ED_uvedit_median_multi(const Scene *scene,
return (sel != 0);
}
bool ED_uvedit_center_multi(
const Scene *scene, Object **objects_edit, uint objects_len, float cent[2], char mode)
bool ED_uvedit_center_multi(const Scene *scene,
Span<Object *> objects_edit,
float cent[2],
char mode)
{
bool changed = false;
if (mode == V3D_AROUND_CENTER_BOUNDS) { /* bounding box */
float min[2], max[2];
if (ED_uvedit_minmax_multi(scene, objects_edit, objects_len, min, max)) {
if (ED_uvedit_minmax_multi(scene, objects_edit, min, max)) {
mid_v2_v2v2(cent, min, max);
changed = true;
}
}
else {
if (ED_uvedit_median_multi(scene, objects_edit, objects_len, cent)) {
if (ED_uvedit_median_multi(scene, objects_edit, cent)) {
changed = true;
}
}
@ -318,20 +319,18 @@ bool ED_uvedit_center_from_pivot_ex(SpaceImage *sima,
copy_v2_v2(r_center, sima->cursor);
changed = true;
if (r_has_select != nullptr) {
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
*r_has_select = uvedit_select_is_any_selected_multi(scene, objects, objects_len);
MEM_freeN(objects);
Vector<Object *> objects =
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
*r_has_select = uvedit_select_is_any_selected_multi(scene, objects);
}
break;
}
default: {
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
changed = ED_uvedit_center_multi(scene, objects, objects_len, r_center, mode);
MEM_freeN(objects);
Vector<Object *> objects =
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
changed = ED_uvedit_center_multi(scene, objects, r_center, mode);
if (r_has_select != nullptr) {
*r_has_select = changed;
}
@ -546,21 +545,18 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool)
INIT_MINMAX2(min, max);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
if (tool == UV_ALIGN_AUTO) {
ED_uvedit_foreach_uv_multi(scene, objects, objects_len, true, true, [&](float luv[2]) {
minmax_v2v2_v2(min, max, luv);
});
ED_uvedit_foreach_uv_multi(
scene, objects, true, true, [&](float luv[2]) { minmax_v2v2_v2(min, max, luv); });
tool = (max[0] - min[0] >= max[1] - min[1]) ? UV_ALIGN_Y : UV_ALIGN_X;
}
ED_uvedit_center_multi(scene, objects, objects_len, cent, 0);
ED_uvedit_center_multi(scene, objects, cent, 0);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -582,8 +578,6 @@ static void uv_weld_align(bContext *C, eUVWeldAlign tool)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
}
MEM_freeN(objects);
}
static int uv_align_exec(bContext *C, wmOperator *op)
@ -652,21 +646,19 @@ static int uv_remove_doubles_to_selected(bContext *C, wmOperator *op)
const float threshold = RNA_float_get(op->ptr, "threshold");
const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
bool *changed = static_cast<bool *>(MEM_callocN(sizeof(bool) * objects_len, __func__));
bool *changed = static_cast<bool *>(MEM_callocN(sizeof(bool) * objects.size(), __func__));
/* Maximum index of an objects[i]'s UVs in UV_arr.
* It helps find which UV in *mloopuv_arr belongs to which object. */
uint *ob_mloopuv_max_idx = static_cast<uint *>(
MEM_callocN(sizeof(uint) * objects_len, __func__));
MEM_callocN(sizeof(uint) * objects.size(), __func__));
/* Calculate max possible number of kdtree nodes. */
int uv_maxlen = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (synced_selection && (em->bm->totvertsel == 0)) {
@ -683,7 +675,7 @@ static int uv_remove_doubles_to_selected(bContext *C, wmOperator *op)
int mloopuv_count = 0; /* Also used for *duplicates count. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
ED_uvedit_foreach_uv(scene, em->bm, true, true, [&](float luv[2]) {
@ -745,7 +737,7 @@ static int uv_remove_doubles_to_selected(bContext *C, wmOperator *op)
changed[ob_index] = true;
}
for (ob_index = 0; ob_index < objects_len; ob_index++) {
for (ob_index = 0; ob_index < objects.size(); ob_index++) {
if (changed[ob_index]) {
Object *obedit = objects[ob_index];
uvedit_live_unwrap_update(sima, scene, obedit);
@ -757,7 +749,6 @@ static int uv_remove_doubles_to_selected(bContext *C, wmOperator *op)
BLI_kdtree_2d_free(tree);
MEM_freeN(changed);
MEM_freeN(objects);
MEM_freeN(ob_mloopuv_max_idx);
return OPERATOR_FINISHED;
@ -770,14 +761,12 @@ static int uv_remove_doubles_to_unselected(bContext *C, wmOperator *op)
SpaceImage *sima = CTX_wm_space_image(C);
const float threshold = RNA_float_get(op->ptr, "threshold");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
/* Calculate max possible number of kdtree nodes. */
int uv_maxlen = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
uv_maxlen += em->bm->totloop;
}
@ -789,7 +778,7 @@ static int uv_remove_doubles_to_unselected(bContext *C, wmOperator *op)
int mloopuv_count = 0;
/* Add visible non-selected uvs to tree */
ED_uvedit_foreach_uv_multi(scene, objects, objects_len, true, false, [&](float luv[2]) {
ED_uvedit_foreach_uv_multi(scene, objects, true, false, [&](float luv[2]) {
BLI_kdtree_2d_insert(tree, mloopuv_count, luv);
mloopuv_arr.append(luv);
mloopuv_count++;
@ -798,9 +787,8 @@ static int uv_remove_doubles_to_unselected(bContext *C, wmOperator *op)
BLI_kdtree_2d_balance(tree);
/* For each selected uv, find duplicate non selected uv. */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (Object *obedit : objects) {
bool changed = false;
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
ED_uvedit_foreach_uv(scene, em->bm, true, true, [&](float luv[2]) {
KDTreeNearest_2d nearest;
@ -820,7 +808,6 @@ static int uv_remove_doubles_to_unselected(bContext *C, wmOperator *op)
}
BLI_kdtree_2d_free(tree);
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -909,11 +896,10 @@ static void uv_snap_cursor_to_pixels(SpaceImage *sima)
}
static bool uv_snap_cursor_to_selection(Scene *scene,
Object **objects_edit,
uint objects_len,
Span<Object *> objects_edit,
SpaceImage *sima)
{
return ED_uvedit_center_multi(scene, objects_edit, objects_len, sima->cursor, sima->around);
return ED_uvedit_center_multi(scene, objects_edit, sima->cursor, sima->around);
}
static void uv_snap_cursor_to_origin(float uvco[2])
@ -937,11 +923,10 @@ static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
changed = uv_snap_cursor_to_selection(scene, objects, objects_len, sima);
MEM_freeN(objects);
Vector<Object *> objects =
BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
changed = uv_snap_cursor_to_selection(scene, objects, sima);
break;
}
case 2:
@ -1099,22 +1084,19 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
const int target = RNA_enum_get(op->ptr, "target");
float offset[2] = {0};
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
if (target == 2) {
float center[2];
if (!ED_uvedit_center_multi(scene, objects, objects_len, center, sima->around)) {
MEM_freeN(objects);
if (!ED_uvedit_center_multi(scene, objects, center, sima->around)) {
return OPERATOR_CANCELLED;
}
sub_v2_v2v2(offset, sima->cursor, center);
}
bool changed_multi = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (synced_selection && (em->bm->totvertsel == 0)) {
@ -1144,7 +1126,6 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -1192,12 +1173,10 @@ static int uv_pin_exec(bContext *C, wmOperator *op)
const bool invert = RNA_boolean_get(op->ptr, "invert");
const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -1233,7 +1212,6 @@ static int uv_pin_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_COPY_ON_WRITE);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1301,12 +1279,10 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
const bool swap = RNA_boolean_get(op->ptr, "unselected");
const bool use_face_center = (ts->uv_selectmode == UV_SELECT_FACE);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMFace *efa;
BMLoop *l;
@ -1432,8 +1408,6 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1472,12 +1446,10 @@ static int uv_reveal_exec(bContext *C, wmOperator *op)
const bool use_face_center = (ts->uv_selectmode == UV_SELECT_FACE);
const bool select = RNA_boolean_get(op->ptr, "select");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMFace *efa;
BMLoop *l;
@ -1585,8 +1557,6 @@ static int uv_reveal_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -1691,12 +1661,10 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
const bool mark_sharp = RNA_boolean_get(op->ptr, "mark_sharp");
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
Mesh *mesh = (Mesh *)ob->data;
BMEditMesh *em = mesh->edit_mesh;
BMesh *bm = em->bm;
@ -1754,7 +1722,6 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -1796,14 +1763,12 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
const bool flag_set = !RNA_boolean_get(op->ptr, "clear");
const bool synced_selection = (ts->uv_flag & UV_SYNC_SELECTION) != 0;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
bool changed = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
Mesh *mesh = (Mesh *)ob->data;
BMEditMesh *em = mesh->edit_mesh;
BMesh *bm = em->bm;
@ -1832,11 +1797,9 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
}
if (changed) {
ED_uvedit_live_unwrap(scene, objects, objects_len);
ED_uvedit_live_unwrap(scene, objects);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}

View File

@ -56,6 +56,8 @@
#include "bmesh_tools.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Path Select Struct & Properties
* \{ */
@ -561,9 +563,8 @@ static int uv_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEve
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr, &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
float co[2];
@ -577,17 +578,17 @@ static int uv_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEve
UvNearestHit hit = uv_nearest_hit_init_max(&region->v2d);
bool hit_found = false;
if (uv_selectmode == UV_SELECT_FACE) {
if (uv_find_nearest_face_multi(scene, objects, objects_len, co, &hit)) {
if (uv_find_nearest_face_multi(scene, objects, co, &hit)) {
hit_found = true;
}
}
else if (uv_selectmode & UV_SELECT_EDGE) {
if (uv_find_nearest_edge_multi(scene, objects, objects_len, co, 0.0f, &hit)) {
if (uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit)) {
hit_found = true;
}
}
else {
if (uv_find_nearest_vert_multi(scene, objects, objects_len, co, 0.0f, &hit)) {
if (uv_find_nearest_vert_multi(scene, objects, co, 0.0f, &hit)) {
hit_found = true;
}
}
@ -681,8 +682,6 @@ static int uv_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmEve
}
}
MEM_freeN(objects);
return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -802,11 +801,9 @@ static int uv_shortest_path_select_exec(bContext *C, wmOperator *op)
const float aspect_y = ED_uvedit_get_aspect_y(CTX_data_edit_object(C));
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -845,7 +842,6 @@ static int uv_shortest_path_select_exec(bContext *C, wmOperator *op)
found_valid_elements = true;
}
}
MEM_freeN(objects);
if (!found_valid_elements) {
BKE_report(

View File

@ -46,6 +46,8 @@
#include "uvedit_intern.hh"
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name UV Loop Rip Data Struct
* \{ */
@ -913,13 +915,10 @@ static int uv_rip_exec(bContext *C, wmOperator *op)
}
const float aspect_y = aspx / aspy;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (Object *obedit : objects) {
if (uv_rip_object(scene, obedit, co, aspect_y)) {
changed_multi = true;
uvedit_live_unwrap_update(sima, scene, obedit);
@ -927,7 +926,6 @@ static int uv_rip_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
}
MEM_freeN(objects);
if (!changed_multi) {
BKE_report(op->reports, RPT_ERROR, "Rip failed");

View File

@ -65,17 +65,16 @@
#include "uvedit_intern.hh"
using blender::Span;
using blender::Vector;
static void uv_select_all_perform(const Scene *scene, Object *obedit, int action);
static void uv_select_all_perform_multi_ex(const Scene *scene,
Object **objects,
const uint objects_len,
Span<Object *> objects,
int action,
const Object *ob_exclude);
static void uv_select_all_perform_multi(const Scene *scene,
Object **objects,
const uint objects_len,
int action);
static void uv_select_all_perform_multi(const Scene *scene, Span<Object *> objects, int action);
static void uv_select_flush_from_tag_face(const Scene *scene, Object *obedit, const bool select);
static void uv_select_flush_from_tag_loop(const Scene *scene, Object *obedit, const bool select);
@ -869,15 +868,13 @@ bool uv_find_nearest_edge(
}
bool uv_find_nearest_edge_multi(Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
const float co[2],
const float penalty,
UvNearestHit *hit)
{
bool found = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (uv_find_nearest_edge(scene, obedit, co, penalty, hit)) {
found = true;
}
@ -934,15 +931,13 @@ bool uv_find_nearest_face(Scene *scene, Object *obedit, const float co[2], UvNea
}
bool uv_find_nearest_face_multi_ex(Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
const float co[2],
UvNearestHit *hit,
const bool only_in_face)
{
bool found = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (uv_find_nearest_face_ex(scene, obedit, co, hit, only_in_face)) {
found = true;
}
@ -950,10 +945,12 @@ bool uv_find_nearest_face_multi_ex(Scene *scene,
return found;
}
bool uv_find_nearest_face_multi(
Scene *scene, Object **objects, const uint objects_len, const float co[2], UvNearestHit *hit)
bool uv_find_nearest_face_multi(Scene *scene,
const Span<Object *> objects,
const float co[2],
UvNearestHit *hit)
{
return uv_find_nearest_face_multi_ex(scene, objects, objects_len, co, hit, false);
return uv_find_nearest_face_multi_ex(scene, objects, co, hit, false);
}
static bool uv_nearest_between(const BMLoop *l, const float co[2], const int cd_loop_uv_offset)
@ -1026,15 +1023,13 @@ bool uv_find_nearest_vert(
}
bool uv_find_nearest_vert_multi(Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
float const co[2],
const float penalty_dist,
UvNearestHit *hit)
{
bool found = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (uv_find_nearest_vert(scene, obedit, co, penalty_dist, hit)) {
found = true;
}
@ -1089,8 +1084,7 @@ static bool uvedit_nearest_uv(const Scene *scene,
bool ED_uvedit_nearest_uv_multi(const View2D *v2d,
const Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
const float mval_fl[2],
const bool ignore_selected,
float *dist_sq,
@ -1105,8 +1099,7 @@ bool ED_uvedit_nearest_uv_multi(const View2D *v2d,
float co[2];
sub_v2_v2v2(co, mval_fl, offset);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (uvedit_nearest_uv(scene, obedit, co, scale, ignore_selected, dist_sq, r_uv)) {
found = true;
}
@ -1778,8 +1771,7 @@ static int uv_select_edgering(Scene *scene, Object *obedit, UvNearestHit *hit, c
* \{ */
static void uv_select_linked_multi(Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
UvNearestHit *hit,
const bool extend,
bool deselect,
@ -1789,7 +1781,7 @@ static void uv_select_linked_multi(Scene *scene,
const bool uv_sync_select = (scene->toolsettings->uv_flag & UV_SYNC_SELECTION);
/* loop over objects, or just use hit->ob */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
if (hit && ob_index != 0) {
break;
}
@ -2039,14 +2031,12 @@ static int uv_select_more_less(bContext *C, const bool select)
BMIter iter, liter;
const ToolSettings *ts = scene->toolsettings;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
const bool is_uv_face_selectmode = (ts->uv_selectmode == UV_SELECT_FACE);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -2168,7 +2158,6 @@ static int uv_select_more_less(bContext *C, const bool select)
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2242,13 +2231,10 @@ bool uvedit_select_is_any_selected(const Scene *scene, Object *obedit)
return false;
}
bool uvedit_select_is_any_selected_multi(const Scene *scene,
Object **objects,
const uint objects_len)
bool uvedit_select_is_any_selected_multi(const Scene *scene, const Span<Object *> objects)
{
bool found = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (uvedit_select_is_any_selected(scene, obedit)) {
found = true;
break;
@ -2362,18 +2348,15 @@ static void uv_select_all_perform(const Scene *scene, Object *obedit, int action
}
static void uv_select_all_perform_multi_ex(const Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
int action,
const Object *ob_exclude)
{
if (action == SEL_TOGGLE) {
action = uvedit_select_is_any_selected_multi(scene, objects, objects_len) ? SEL_DESELECT :
SEL_SELECT;
action = uvedit_select_is_any_selected_multi(scene, objects) ? SEL_DESELECT : SEL_SELECT;
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
if (ob_exclude && (obedit == ob_exclude)) {
continue;
}
@ -2381,12 +2364,9 @@ static void uv_select_all_perform_multi_ex(const Scene *scene,
}
}
static void uv_select_all_perform_multi(const Scene *scene,
Object **objects,
const uint objects_len,
int action)
static void uv_select_all_perform_multi(const Scene *scene, Span<Object *> objects, int action)
{
uv_select_all_perform_multi_ex(scene, objects, objects_len, action, nullptr);
uv_select_all_perform_multi_ex(scene, objects, action, nullptr);
}
static int uv_select_all_exec(bContext *C, wmOperator *op)
@ -2398,19 +2378,15 @@ static int uv_select_all_exec(bContext *C, wmOperator *op)
int action = RNA_enum_get(op->ptr, "action");
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
uv_select_all_perform_multi(scene, objects, objects_len, action);
uv_select_all_perform_multi(scene, objects, action);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
uv_select_tag_update_for_object(depsgraph, ts, obedit);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2436,8 +2412,7 @@ void UV_OT_select_all(wmOperatorType *ot)
* \{ */
static bool uv_mouse_select_multi(bContext *C,
Object **objects,
uint objects_len,
const Span<Object *> objects,
const float co[2],
const SelectPick_Params *params)
{
@ -2477,7 +2452,7 @@ static bool uv_mouse_select_multi(bContext *C,
/* find nearest element */
if (selectmode == UV_SELECT_VERTEX) {
/* find vertex */
found_item = uv_find_nearest_vert_multi(scene, objects, objects_len, co, penalty_dist, &hit);
found_item = uv_find_nearest_vert_multi(scene, objects, co, penalty_dist, &hit);
if (found_item) {
if ((ts->uv_flag & UV_SYNC_SELECTION) == 0) {
BMesh *bm = BKE_editmesh_from_object(hit.ob)->bm;
@ -2487,7 +2462,7 @@ static bool uv_mouse_select_multi(bContext *C,
}
else if (selectmode == UV_SELECT_EDGE) {
/* find edge */
found_item = uv_find_nearest_edge_multi(scene, objects, objects_len, co, penalty_dist, &hit);
found_item = uv_find_nearest_edge_multi(scene, objects, co, penalty_dist, &hit);
if (found_item) {
if ((ts->uv_flag & UV_SYNC_SELECTION) == 0) {
BMesh *bm = BKE_editmesh_from_object(hit.ob)->bm;
@ -2497,14 +2472,14 @@ static bool uv_mouse_select_multi(bContext *C,
}
else if (selectmode == UV_SELECT_FACE) {
/* find face */
found_item = uv_find_nearest_face_multi(scene, objects, objects_len, co, &hit);
found_item = uv_find_nearest_face_multi(scene, objects, co, &hit);
if (!found_item) {
/* Fallback, perform a second pass without a limited threshold,
* which succeeds as long as the cursor is inside the UV face.
* Useful when zoomed in, to select faces with distant screen-space face centers. */
hit.dist_sq = FLT_MAX;
found_item = uv_find_nearest_face_multi_ex(scene, objects, objects_len, co, &hit, true);
found_item = uv_find_nearest_face_multi_ex(scene, objects, co, &hit, true);
}
if (found_item) {
@ -2513,13 +2488,13 @@ static bool uv_mouse_select_multi(bContext *C,
}
}
else if (selectmode == UV_SELECT_ISLAND) {
found_item = uv_find_nearest_edge_multi(scene, objects, objects_len, co, 0.0f, &hit);
found_item = uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit);
if (!found_item) {
/* Without this, we can be within the face of an island but too far from an edge,
* see face selection comment for details. */
hit.dist_sq = FLT_MAX;
found_item = uv_find_nearest_face_multi_ex(scene, objects, objects_len, co, &hit, true);
found_item = uv_find_nearest_face_multi_ex(scene, objects, co, &hit, true);
}
}
@ -2558,9 +2533,8 @@ static bool uv_mouse_select_multi(bContext *C,
}
else if (found || params->deselect_all) {
/* Deselect everything. */
uv_select_all_perform_multi(scene, objects, objects_len, SEL_DESELECT);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
uv_select_all_perform_multi(scene, objects, SEL_DESELECT);
for (Object *obedit : objects) {
uv_select_tag_update_for_object(depsgraph, ts, obedit);
}
changed = true;
@ -2581,7 +2555,7 @@ static bool uv_mouse_select_multi(bContext *C,
const bool toggle = params->sel_op == SEL_OP_XOR;
/* Current behavior of 'extend'
* is actually toggling, so pass extend flag as 'toggle' here */
uv_select_linked_multi(scene, objects, objects_len, &hit, extend, deselect, toggle, false);
uv_select_linked_multi(scene, objects, &hit, extend, deselect, toggle, false);
/* TODO: check if this actually changed. */
changed = true;
}
@ -2668,11 +2642,9 @@ static bool uv_mouse_select(bContext *C, const float co[2], const SelectPick_Par
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
bool changed = uv_mouse_select_multi(C, objects, objects_len, co, params);
MEM_freeN(objects);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
bool changed = uv_mouse_select_multi(C, objects, co, params);
return changed;
}
@ -2751,8 +2723,7 @@ enum eUVLoopGenericType {
};
static int uv_mouse_select_loop_generic_multi(bContext *C,
Object **objects,
uint objects_len,
const Span<Object *> objects,
const float co[2],
const bool extend,
enum eUVLoopGenericType loop_type)
@ -2767,7 +2738,7 @@ static int uv_mouse_select_loop_generic_multi(bContext *C,
int flush = 0;
/* Find edge. */
found_item = uv_find_nearest_edge_multi(scene, objects, objects_len, co, 0.0f, &hit);
found_item = uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit);
if (!found_item) {
return OPERATOR_CANCELLED;
}
@ -2777,7 +2748,7 @@ static int uv_mouse_select_loop_generic_multi(bContext *C,
/* Do selection. */
if (!extend) {
uv_select_all_perform_multi_ex(scene, objects, objects_len, SEL_DESELECT, obedit);
uv_select_all_perform_multi_ex(scene, objects, SEL_DESELECT, obedit);
}
if (loop_type == UV_LOOP_SELECT) {
@ -2807,9 +2778,8 @@ static int uv_mouse_select_loop_generic_multi(bContext *C,
ED_uvedit_selectmode_flush(scene, em);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obiter = objects[ob_index];
uv_select_tag_update_for_object(depsgraph, ts, obiter);
for (Object *ob : objects) {
uv_select_tag_update_for_object(depsgraph, ts, ob);
}
return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
@ -2821,11 +2791,9 @@ static int uv_mouse_select_loop_generic(bContext *C,
{
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
int ret = uv_mouse_select_loop_generic_multi(C, objects, objects_len, co, extend, loop_type);
MEM_freeN(objects);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
int ret = uv_mouse_select_loop_generic_multi(C, objects, co, extend, loop_type);
return ret;
}
@ -2978,9 +2946,8 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
deselect = RNA_boolean_get(op->ptr, "deselect");
}
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
if (pick) {
float co[2];
@ -2995,34 +2962,30 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
RNA_float_get_array(op->ptr, "location", co);
}
if (!uv_find_nearest_edge_multi(scene, objects, objects_len, co, 0.0f, &hit)) {
MEM_freeN(objects);
if (!uv_find_nearest_edge_multi(scene, objects, co, 0.0f, &hit)) {
return OPERATOR_CANCELLED;
}
}
if (!extend && !deselect) {
uv_select_all_perform_multi(scene, objects, objects_len, SEL_DESELECT);
uv_select_all_perform_multi(scene, objects, SEL_DESELECT);
}
uv_select_linked_multi(
scene, objects, objects_len, pick ? &hit : nullptr, extend, deselect, false, select_faces);
scene, objects, pick ? &hit : nullptr, extend, deselect, false, select_faces);
/* weak!, but works */
Object **objects_free = objects;
if (pick) {
objects = &hit.ob;
objects_len = 1;
DEG_id_tag_update(static_cast<ID *>(hit.ob->data), ID_RECALC_COPY_ON_WRITE | ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, hit.ob->data);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_COPY_ON_WRITE | ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
else {
for (Object *obedit : objects) {
DEG_id_tag_update(static_cast<ID *>(obedit->data),
ID_RECALC_COPY_ON_WRITE | ID_RECALC_SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
}
MEM_SAFE_FREE(objects_free);
return OPERATOR_FINISHED;
}
@ -3135,12 +3098,10 @@ static int uv_select_split_exec(bContext *C, wmOperator *op)
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMesh *bm = BKE_editmesh_from_object(obedit)->bm;
bool changed = false;
@ -3194,7 +3155,6 @@ static int uv_select_split_exec(bContext *C, wmOperator *op)
uv_select_tag_update_for_object(depsgraph, ts, obedit);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -3546,17 +3506,15 @@ static int uv_box_select_exec(bContext *C, wmOperator *op)
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
if (use_pre_deselect) {
uv_select_all_perform_multi(scene, objects, objects_len, SEL_DESELECT);
uv_select_all_perform_multi(scene, objects, SEL_DESELECT);
}
/* don't indent to avoid diff noise! */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -3667,7 +3625,7 @@ static int uv_box_select_exec(bContext *C, wmOperator *op)
UvNearestHit hit = {};
hit.ob = obedit;
hit.efa = efa;
uv_select_linked_multi(scene, objects, objects_len, &hit, true, !select, false, false);
uv_select_linked_multi(scene, objects, &hit, true, !select, false, false);
}
}
@ -3688,8 +3646,6 @@ static int uv_box_select_exec(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -3795,9 +3751,8 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
bool changed_multi = false;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
const eSelectOp sel_op = ED_select_op_modal(
eSelectOp(RNA_enum_get(op->ptr, "mode")),
@ -3806,11 +3761,10 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
const bool use_pre_deselect = SEL_OP_USE_PRE_DESELECT(sel_op);
if (use_pre_deselect) {
uv_select_all_perform_multi(scene, objects, objects_len, SEL_DESELECT);
uv_select_all_perform_multi(scene, objects, SEL_DESELECT);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -3883,7 +3837,7 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
UvNearestHit hit = {};
hit.ob = obedit;
hit.efa = efa;
uv_select_linked_multi(scene, objects, objects_len, &hit, true, !select, false, false);
uv_select_linked_multi(scene, objects, &hit, true, !select, false, false);
}
}
@ -3903,7 +3857,6 @@ static int uv_circle_select_exec(bContext *C, wmOperator *op)
uv_select_tag_update_for_object(depsgraph, ts, obedit);
}
}
MEM_freeN(objects);
return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
@ -4004,16 +3957,14 @@ static bool do_lasso_select_mesh_uv(bContext *C,
BLI_lasso_boundbox(&rect, mcoords, mcoords_len);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
if (use_pre_deselect) {
uv_select_all_perform_multi(scene, objects, objects_len, SEL_DESELECT);
uv_select_all_perform_multi(scene, objects, SEL_DESELECT);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
bool changed = false;
@ -4116,7 +4067,7 @@ static bool do_lasso_select_mesh_uv(bContext *C,
UvNearestHit hit = {};
hit.ob = obedit;
hit.efa = efa;
uv_select_linked_multi(scene, objects, objects_len, &hit, true, !select, false, false);
uv_select_linked_multi(scene, objects, &hit, true, !select, false, false);
}
}
@ -4136,7 +4087,6 @@ static bool do_lasso_select_mesh_uv(bContext *C,
uv_select_tag_update_for_object(depsgraph, ts, obedit);
}
}
MEM_freeN(objects);
return changed_multi;
}
@ -4203,12 +4153,10 @@ static int uv_select_pinned_exec(bContext *C, wmOperator *op)
BMLoop *l;
BMIter iter, liter;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -4239,7 +4187,6 @@ static int uv_select_pinned_exec(bContext *C, wmOperator *op)
uv_select_tag_update_for_object(depsgraph, ts, obedit);
}
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4342,14 +4289,12 @@ static int uv_select_overlap(bContext *C, const bool extend)
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
/* Calculate maximum number of tree nodes and prepare initial selection. */
uint uv_tri_len = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BM_mesh_elem_table_ensure(em->bm, BM_FACE);
@ -4385,7 +4330,7 @@ static int uv_select_overlap(bContext *C, const bool extend)
MemArena *arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
Heap *heap = BLI_heap_new_ex(BLI_POLYFILL_ALLOC_NGON_RESERVE);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMIter iter, liter;
@ -4515,14 +4460,13 @@ static int uv_select_overlap(bContext *C, const bool extend)
MEM_freeN(overlap);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
uv_select_tag_update_for_object(depsgraph, scene->toolsettings, objects[ob_index]);
for (Object *object : objects) {
uv_select_tag_update_for_object(depsgraph, scene->toolsettings, object);
}
BLI_bvhtree_free(uv_tree);
MEM_freeN(overlap_data);
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -4739,13 +4683,11 @@ static int uv_select_similar_vert_exec(bContext *C, wmOperator *op)
const float threshold = RNA_float_get(op->ptr, "threshold");
const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
int max_verts_selected_all = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMFace *face;
BMIter iter;
@ -4761,8 +4703,7 @@ static int uv_select_similar_vert_exec(bContext *C, wmOperator *op)
int tree_index = 0;
KDTree_1d *tree_1d = BLI_kdtree_1d_new(max_verts_selected_all);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
if (bm->totvertsel == 0) {
@ -4796,8 +4737,7 @@ static int uv_select_similar_vert_exec(bContext *C, wmOperator *op)
BLI_kdtree_1d_balance(tree_1d);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
if (bm->totvertsel == 0) {
@ -4835,7 +4775,6 @@ static int uv_select_similar_vert_exec(bContext *C, wmOperator *op)
}
}
MEM_SAFE_FREE(objects);
BLI_kdtree_1d_free(tree_1d);
return OPERATOR_FINISHED;
}
@ -4851,13 +4790,11 @@ static int uv_select_similar_edge_exec(bContext *C, wmOperator *op)
const float threshold = RNA_float_get(op->ptr, "threshold");
const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
int max_edges_selected_all = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMFace *face;
BMIter iter;
@ -4873,8 +4810,7 @@ static int uv_select_similar_edge_exec(bContext *C, wmOperator *op)
int tree_index = 0;
KDTree_1d *tree_1d = BLI_kdtree_1d_new(max_edges_selected_all);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
if (bm->totvertsel == 0) {
@ -4911,8 +4847,7 @@ static int uv_select_similar_edge_exec(bContext *C, wmOperator *op)
BLI_kdtree_1d_balance(tree_1d);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
if (bm->totvertsel == 0) {
@ -4950,7 +4885,6 @@ static int uv_select_similar_edge_exec(bContext *C, wmOperator *op)
}
}
MEM_SAFE_FREE(objects);
BLI_kdtree_1d_free(tree_1d);
return OPERATOR_FINISHED;
}
@ -4966,13 +4900,11 @@ static int uv_select_similar_face_exec(bContext *C, wmOperator *op)
const float threshold = RNA_float_get(op->ptr, "threshold");
const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
int max_faces_selected_all = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
max_faces_selected_all += em->bm->totfacesel;
/* TODO: Get a tighter bounds */
@ -4981,9 +4913,8 @@ static int uv_select_similar_face_exec(bContext *C, wmOperator *op)
int tree_index = 0;
KDTree_1d *tree_1d = BLI_kdtree_1d_new(max_faces_selected_all);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *ob = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
@ -5014,9 +4945,8 @@ static int uv_select_similar_face_exec(bContext *C, wmOperator *op)
BLI_kdtree_1d_balance(tree_1d);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *ob = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(ob);
BMesh *bm = em->bm;
bool changed = false;
@ -5049,7 +4979,6 @@ static int uv_select_similar_face_exec(bContext *C, wmOperator *op)
}
}
MEM_SAFE_FREE(objects);
BLI_kdtree_1d_free(tree_1d);
return OPERATOR_FINISHED;
}
@ -5071,17 +5000,16 @@ static int uv_select_similar_island_exec(bContext *C, wmOperator *op)
const float threshold = RNA_float_get(op->ptr, "threshold");
const eSimilarCmp compare = eSimilarCmp(RNA_enum_get(op->ptr, "compare"));
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
ListBase *island_list_ptr = static_cast<ListBase *>(
MEM_callocN(sizeof(*island_list_ptr) * objects_len, __func__));
MEM_callocN(sizeof(*island_list_ptr) * objects.size(), __func__));
int island_list_len = 0;
const bool face_selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
@ -5100,7 +5028,7 @@ static int uv_select_similar_island_exec(bContext *C, wmOperator *op)
int tree_index = 0;
KDTree_1d *tree_1d = BLI_kdtree_1d_new(island_list_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2);
@ -5130,7 +5058,7 @@ static int uv_select_similar_island_exec(bContext *C, wmOperator *op)
}
int tot_island_index = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_PROP_FLOAT2);
@ -5173,7 +5101,6 @@ static int uv_select_similar_island_exec(bContext *C, wmOperator *op)
MEM_SAFE_FREE(island_array);
MEM_SAFE_FREE(island_list_ptr);
MEM_SAFE_FREE(objects);
BLI_kdtree_1d_free(tree_1d);
return OPERATOR_FINISHED;
@ -5587,17 +5514,13 @@ void ED_uvedit_selectmode_clean_multi(bContext *C)
ViewLayer *view_layer = CTX_data_view_layer(C);
Depsgraph *depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, ((View3D *)nullptr), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, nullptr);
for (Object *obedit : objects) {
ED_uvedit_selectmode_clean(scene, obedit);
uv_select_tag_update_for_object(depsgraph, scene->toolsettings, obedit);
}
MEM_freeN(objects);
}
static int uv_select_mode_exec(bContext *C, wmOperator *op)

View File

@ -56,6 +56,8 @@
#include "uvedit_intern.hh"
using blender::Vector;
/* ********************** smart stitch operator *********************** */
/* object that stores display data for previewing before confirming stitching */
@ -2187,23 +2189,20 @@ static int stitch_init_all(bContext *C, wmOperator *op)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, v3d, &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, v3d);
if (objects_len == 0) {
MEM_freeN(objects);
if (objects.is_empty()) {
BKE_report(op->reports, RPT_ERROR, "No objects selected");
return 0;
}
if (objects_len > RNA_MAX_ARRAY_LENGTH) {
MEM_freeN(objects);
if (objects.size() > RNA_MAX_ARRAY_LENGTH) {
BKE_reportf(op->reports,
RPT_ERROR,
"Stitching only works with less than %i objects selected (%u selected)",
"Stitching only works with less than %i objects selected (%i selected)",
RNA_MAX_ARRAY_LENGTH,
objects_len);
int(objects.size()));
return 0;
}
@ -2242,9 +2241,9 @@ static int stitch_init_all(bContext *C, wmOperator *op)
}
ssc->objects = static_cast<Object **>(
MEM_callocN(sizeof(Object *) * objects_len, "Object *ssc->objects"));
MEM_callocN(sizeof(Object *) * objects.size(), "Object *ssc->objects"));
ssc->states = static_cast<StitchState **>(
MEM_callocN(sizeof(StitchState *) * objects_len, "StitchState"));
MEM_callocN(sizeof(StitchState *) * objects.size(), "StitchState"));
ssc->objects_len = 0;
int *objs_selection_count = nullptr;
@ -2258,11 +2257,11 @@ static int stitch_init_all(bContext *C, wmOperator *op)
* for all objects. */
objs_selection_count = static_cast<int *>(
MEM_mallocN(sizeof(int *) * objects_len, "objects_selection_count"));
MEM_mallocN(sizeof(int *) * objects.size(), "objects_selection_count"));
RNA_int_get_array(op->ptr, "objects_selection_count", objs_selection_count);
int total_selected = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (uint ob_index = 0; ob_index < objects.size(); ob_index++) {
total_selected += objs_selection_count[ob_index];
}
@ -2284,7 +2283,7 @@ static int stitch_init_all(bContext *C, wmOperator *op)
state_init->to_select = selected_uvs_arr;
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (uint ob_index = 0; ob_index < objects.size(); ob_index++) {
Object *obedit = objects[ob_index];
if (state_init != nullptr) {
@ -2305,7 +2304,6 @@ static int stitch_init_all(bContext *C, wmOperator *op)
}
}
MEM_freeN(objects);
MEM_SAFE_FREE(selected_uvs_arr);
MEM_SAFE_FREE(objs_selection_count);
MEM_SAFE_FREE(state_init);
@ -2489,7 +2487,7 @@ static StitchState *stitch_select(bContext *C,
UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &co[0], &co[1]);
if (ssc->mode == STITCH_VERT) {
if (uv_find_nearest_vert_multi(scene, ssc->objects, ssc->objects_len, co, 0.0f, &hit)) {
if (uv_find_nearest_vert_multi(scene, {ssc->objects, ssc->objects_len}, co, 0.0f, &hit)) {
/* Add vertex to selection, deselect all common uv's of vert other than selected and
* update the preview. This behavior was decided so that you can do stuff like deselect
* the opposite stitchable vertex and the initial still gets deselected */
@ -2512,7 +2510,7 @@ static StitchState *stitch_select(bContext *C,
return state;
}
}
else if (uv_find_nearest_edge_multi(scene, ssc->objects, ssc->objects_len, co, 0.0f, &hit)) {
else if (uv_find_nearest_edge_multi(scene, {ssc->objects, ssc->objects_len}, co, 0.0f, &hit)) {
/* find StitchState from hit->ob */
StitchState *state = nullptr;
for (uint ob_index = 0; ob_index < ssc->objects_len; ob_index++) {

View File

@ -75,6 +75,8 @@
#include "uvedit_intern.hh"
using blender::Span;
using blender::Vector;
using blender::geometry::ParamHandle;
using blender::geometry::ParamKey;
@ -256,13 +258,11 @@ static bool uvedit_have_selection(const Scene *scene, BMEditMesh *em, const Unwr
}
static bool uvedit_have_selection_multi(const Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
const UnwrapOptions *options)
{
bool have_select = false;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (uvedit_have_selection(scene, em, options)) {
have_select = true;
@ -483,8 +483,7 @@ static ParamHandle *construct_param_handle(const Scene *scene,
* Version of #construct_param_handle that handles multiple objects.
*/
static ParamHandle *construct_param_handle_multi(const Scene *scene,
Object **objects,
const uint objects_len,
const Span<Object *> objects,
const UnwrapOptions *options)
{
BMFace *efa;
@ -499,12 +498,11 @@ static ParamHandle *construct_param_handle_multi(const Scene *scene,
}
/* we need the vert indices */
EDBM_mesh_elem_index_ensure_multi(objects, objects_len, BM_VERT);
EDBM_mesh_elem_index_ensure_multi(objects, BM_VERT);
int offset = 0;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@ -767,8 +765,7 @@ static ParamHandle *construct_param_handle_subsurfed(const Scene *scene,
struct MinStretch {
const Scene *scene;
Object **objects_edit;
uint objects_len;
Vector<Object *> objects_edit;
ParamHandle *handle;
float blend;
double lasttime;
@ -788,23 +785,20 @@ static bool minimize_stretch_init(bContext *C, wmOperator *op)
options.only_selected_uvs = true;
options.correct_aspect = true;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, CTX_wm_view3d(C));
if (!uvedit_have_selection_multi(scene, objects, objects_len, &options)) {
MEM_freeN(objects);
if (!uvedit_have_selection_multi(scene, objects, &options)) {
return false;
}
MinStretch *ms = MEM_cnew<MinStretch>(__func__);
MinStretch *ms = MEM_new<MinStretch>(__func__);
ms->scene = scene;
ms->objects_edit = objects;
ms->objects_len = objects_len;
ms->blend = RNA_float_get(op->ptr, "blend");
ms->iterations = RNA_int_get(op->ptr, "iterations");
ms->i = 0;
ms->handle = construct_param_handle_multi(scene, objects, objects_len, &options);
ms->handle = construct_param_handle_multi(scene, objects, &options);
ms->lasttime = BLI_check_seconds_timer();
blender::geometry::uv_parametrizer_stretch_begin(ms->handle);
@ -844,8 +838,7 @@ static void minimize_stretch_iteration(bContext *C, wmOperator *op, bool interac
ms->lasttime = BLI_check_seconds_timer();
for (uint ob_index = 0; ob_index < ms->objects_len; ob_index++) {
Object *obedit = ms->objects_edit[ob_index];
for (Object *obedit : ms->objects_edit) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (synced_selection && (em->bm->totfacesel == 0)) {
@ -883,8 +876,7 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel)
blender::geometry::uv_parametrizer_stretch_end(ms->handle);
delete (ms->handle);
for (uint ob_index = 0; ob_index < ms->objects_len; ob_index++) {
Object *obedit = ms->objects_edit[ob_index];
for (Object *obedit : ms->objects_edit) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (synced_selection && (em->bm->totfacesel == 0)) {
@ -895,8 +887,7 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel)
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(ms->objects_edit);
MEM_freeN(ms);
MEM_delete(ms);
op->customdata = nullptr;
}
@ -1158,8 +1149,7 @@ static bool island_has_pins(const Scene *scene,
* \param params: Parameters and options to pass to the packing engine.
*/
static void uvedit_pack_islands_multi(const Scene *scene,
Object **objects,
const int objects_len,
const Span<Object *> objects,
BMesh **bmesh_override,
const SpaceImage *udim_source_closest,
const bool original_selection,
@ -1169,7 +1159,7 @@ static void uvedit_pack_islands_multi(const Scene *scene,
blender::Vector<FaceIsland *> island_vector;
blender::Vector<bool> pinned_vector;
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMesh *bm = nullptr;
if (bmesh_override) {
@ -1356,8 +1346,7 @@ static void uvedit_pack_islands_multi(const Scene *scene,
}
if (notify_wm && !is_cancelled) {
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
}
@ -1388,8 +1377,7 @@ struct UVPackIslandsData {
const Scene *scene;
Object **objects;
uint objects_len;
Vector<Object *> objects;
const SpaceImage *sima;
int udim_source;
@ -1412,7 +1400,6 @@ static void pack_islands_startjob(void *pidv, wmJobWorkerStatus *worker_status)
uvedit_pack_islands_multi(pid->scene,
pid->objects,
pid->objects_len,
nullptr,
(pid->udim_source == PACK_UDIM_SRC_CLOSEST) ? pid->sima : nullptr,
(pid->udim_source == PACK_ORIGINAL_AABB),
@ -1426,8 +1413,7 @@ static void pack_islands_startjob(void *pidv, wmJobWorkerStatus *worker_status)
static void pack_islands_endjob(void *pidv)
{
UVPackIslandsData *pid = static_cast<UVPackIslandsData *>(pidv);
for (uint ob_index = 0; ob_index < pid->objects_len; ob_index++) {
Object *obedit = pid->objects[ob_index];
for (Object *obedit : pid->objects) {
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
}
@ -1442,9 +1428,8 @@ static void pack_islands_freejob(void *pidv)
{
WM_cursor_wait(false);
UVPackIslandsData *pid = static_cast<UVPackIslandsData *>(pidv);
MEM_freeN(pid->objects);
WM_set_locked_interface(pid->wm, false);
MEM_freeN(pid);
MEM_delete(pid);
}
static int pack_islands_exec(bContext *C, wmOperator *op)
@ -1460,13 +1445,11 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
options.fill_holes = false;
options.correct_aspect = true;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, CTX_wm_view3d(C));
/* Early exit in case no UVs are selected. */
if (!uvedit_have_selection_multi(scene, objects, objects_len, &options)) {
MEM_freeN(objects);
if (!uvedit_have_selection_multi(scene, objects, &options)) {
return OPERATOR_CANCELLED;
}
@ -1479,12 +1462,10 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin);
}
UVPackIslandsData *pid = static_cast<UVPackIslandsData *>(
MEM_callocN(sizeof(UVPackIslandsData), "pack_islands_data"));
UVPackIslandsData *pid = MEM_new<UVPackIslandsData>(__func__);
pid->use_job = op->flag & OP_IS_INVOKE;
pid->scene = scene;
pid->objects = objects;
pid->objects_len = objects_len;
pid->objects = std::move(objects);
pid->sima = sima;
pid->udim_source = udim_source;
pid->wm = CTX_wm_manager(C);
@ -1750,12 +1731,10 @@ static int average_islands_scale_exec(bContext *C, wmOperator *op)
options.fill_holes = false;
options.correct_aspect = true;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(
scene, view_layer, CTX_wm_view3d(C));
if (!uvedit_have_selection_multi(scene, objects, objects_len, &options)) {
MEM_freeN(objects);
if (!uvedit_have_selection_multi(scene, objects, &options)) {
return OPERATOR_CANCELLED;
}
@ -1763,13 +1742,12 @@ static int average_islands_scale_exec(bContext *C, wmOperator *op)
const bool scale_uv = RNA_boolean_get(op->ptr, "scale_uv");
const bool shear = RNA_boolean_get(op->ptr, "shear");
ParamHandle *handle = construct_param_handle_multi(scene, objects, objects_len, &options);
ParamHandle *handle = construct_param_handle_multi(scene, objects, &options);
blender::geometry::uv_parametrizer_average(handle, false, scale_uv, shear);
blender::geometry::uv_parametrizer_flush(handle);
delete (handle);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
if (synced_selection && (em->bm->totvertsel == 0)) {
@ -1779,7 +1757,6 @@ static int average_islands_scale_exec(bContext *C, wmOperator *op)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -2261,8 +2238,7 @@ static void uv_map_clip_correct_properties(wmOperatorType *ot)
* For now keep using a single aspect for all faces in this case.
*/
static void uv_map_clip_correct(const Scene *scene,
Object **objects,
uint objects_len,
const Span<Object *> objects,
wmOperator *op,
bool per_face_aspect,
bool only_selected_uvs)
@ -2278,9 +2254,7 @@ static void uv_map_clip_correct(const Scene *scene,
INIT_MINMAX2(min, max);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
@ -2347,9 +2321,7 @@ static void uv_map_clip_correct(const Scene *scene,
return;
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *ob = objects[ob_index];
for (Object *ob : objects) {
BMEditMesh *em = BKE_editmesh_from_object(ob);
const BMUVOffsets offsets = BM_uv_map_get_offsets(em->bm);
@ -2415,21 +2387,19 @@ static void uvedit_unwrap(const Scene *scene,
}
static void uvedit_unwrap_multi(const Scene *scene,
Object **objects,
const int objects_len,
const Span<Object *> objects,
const UnwrapOptions *options,
int *r_count_changed = nullptr,
int *r_count_failed = nullptr)
{
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
uvedit_unwrap(scene, obedit, options, r_count_changed, r_count_failed);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_GEOM | ND_DATA, obedit->data);
}
}
void ED_uvedit_live_unwrap(const Scene *scene, Object **objects, int objects_len)
void ED_uvedit_live_unwrap(const Scene *scene, const Span<Object *> objects)
{
if (scene->toolsettings->edge_mode_live_unwrap) {
UnwrapOptions options{};
@ -2438,7 +2408,7 @@ void ED_uvedit_live_unwrap(const Scene *scene, Object **objects, int objects_len
options.only_selected_uvs = false;
options.fill_holes = (scene->toolsettings->uvcalc_flag & UVCALC_FILLHOLES) != 0;
options.correct_aspect = (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) == 0;
uvedit_unwrap_multi(scene, objects, objects_len, &options, nullptr);
uvedit_unwrap_multi(scene, objects, &options, nullptr);
blender::geometry::UVPackIsland_Params pack_island_params;
pack_island_params.setFromUnwrapOptions(options);
@ -2447,8 +2417,7 @@ void ED_uvedit_live_unwrap(const Scene *scene, Object **objects, int objects_len
pack_island_params.margin_method = ED_UVPACK_MARGIN_SCALED;
pack_island_params.margin = scene->toolsettings->uvcalc_margin;
uvedit_pack_islands_multi(
scene, objects, objects_len, nullptr, nullptr, false, true, &pack_island_params);
uvedit_pack_islands_multi(scene, objects, nullptr, nullptr, false, true, &pack_island_params);
}
}
@ -2468,9 +2437,8 @@ static int unwrap_exec(bContext *C, wmOperator *op)
* has the subsurf modifier in the right place. */
bool subsurf_error = use_subsurf;
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
UnwrapOptions options{};
options.topology_from_uvs = false;
@ -2485,14 +2453,12 @@ static int unwrap_exec(bContext *C, wmOperator *op)
options.pin_unselected = true;
}
if (!uvedit_have_selection_multi(scene, objects, objects_len, &options)) {
MEM_freeN(objects);
if (!uvedit_have_selection_multi(scene, objects, &options)) {
return OPERATOR_CANCELLED;
}
/* add uvs if they don't exist yet */
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
for (Object *obedit : objects) {
float obsize[3];
bool use_subsurf_final;
@ -2580,7 +2546,7 @@ static int unwrap_exec(bContext *C, wmOperator *op)
/* execute unwrap */
int count_changed = 0;
int count_failed = 0;
uvedit_unwrap_multi(scene, objects, objects_len, &options, &count_changed, &count_failed);
uvedit_unwrap_multi(scene, objects, &options, &count_changed, &count_failed);
blender::geometry::UVPackIsland_Params pack_island_params;
pack_island_params.setFromUnwrapOptions(options);
@ -2590,10 +2556,7 @@ static int unwrap_exec(bContext *C, wmOperator *op)
RNA_enum_get(op->ptr, "margin_method"));
pack_island_params.margin = RNA_float_get(op->ptr, "margin");
uvedit_pack_islands_multi(
scene, objects, objects_len, nullptr, nullptr, false, true, &pack_island_params);
MEM_freeN(objects);
uvedit_pack_islands_multi(scene, objects, nullptr, nullptr, false, true, &pack_island_params);
if (count_failed == 0 && count_changed == 0) {
BKE_report(op->reports,
@ -2821,19 +2784,15 @@ static int smart_project_exec(bContext *C, wmOperator *op)
/* Memory arena for list links (cleared for each object). */
MemArena *arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
Object **objects_changed = static_cast<Object **>(
MEM_mallocN(sizeof(*objects_changed) * objects_len, __func__));
uint object_changed_len = 0;
Vector<Object *> objects_changed;
BMFace *efa;
BMIter iter;
uint ob_index;
for (ob_index = 0; ob_index < objects_len; ob_index++) {
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -2947,17 +2906,14 @@ static int smart_project_exec(bContext *C, wmOperator *op)
MEM_freeN(thickface_project_groups);
if (changed) {
objects_changed[object_changed_len] = objects[ob_index];
object_changed_len += 1;
objects_changed.append(obedit);
}
}
BLI_memarena_free(arena);
MEM_freeN(objects);
/* Pack islands & Stretch to UV bounds */
if (object_changed_len > 0) {
if (!objects_changed.is_empty()) {
scene->toolsettings->uvcalc_margin = island_margin;
@ -2973,17 +2929,13 @@ static int smart_project_exec(bContext *C, wmOperator *op)
params.margin_method = eUVPackIsland_MarginMethod(RNA_enum_get(op->ptr, "margin_method"));
params.margin = RNA_float_get(op->ptr, "island_margin");
uvedit_pack_islands_multi(
scene, objects_changed, object_changed_len, nullptr, nullptr, false, true, &params);
uvedit_pack_islands_multi(scene, objects_changed, nullptr, nullptr, false, true, &params);
/* #uvedit_pack_islands_multi only supports `per_face_aspect = false`. */
const bool per_face_aspect = false;
uv_map_clip_correct(
scene, objects_changed, object_changed_len, op, per_face_aspect, only_selected_uvs);
uv_map_clip_correct(scene, objects_changed, op, per_face_aspect, only_selected_uvs);
}
MEM_freeN(objects_changed);
return OPERATOR_FINISHED;
}
@ -3092,29 +3044,28 @@ static int uv_from_view_exec(bContext *C, wmOperator *op)
BMIter iter, liter;
float rotmat[4][4];
float objects_pos_offset[4];
bool changed_multi = false;
const bool use_orthographic = RNA_boolean_get(op->ptr, "orthographic");
/* NOTE: objects that aren't touched are set to nullptr (to skip clipping). */
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
if (use_orthographic) {
/* Calculate average object position. */
float objects_pos_avg[4] = {0};
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
add_v4_v4(objects_pos_avg, objects[ob_index]->object_to_world[3]);
for (Object *object : objects) {
add_v4_v4(objects_pos_avg, object->object_to_world[3]);
}
mul_v4_fl(objects_pos_avg, 1.0f / objects_len);
mul_v4_fl(objects_pos_avg, 1.0f / objects.size());
negate_v4_v4(objects_pos_offset, objects_pos_avg);
}
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> changed_objects;
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool changed = false;
@ -3182,29 +3133,20 @@ static int uv_from_view_exec(bContext *C, wmOperator *op)
}
if (changed) {
changed_multi = true;
changed_objects.append(obedit);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
else {
ARRAY_DELETE_REORDER_LAST(objects, ob_index, 1, objects_len);
objects_len -= 1;
ob_index -= 1;
}
}
if (changed_multi) {
const bool per_face_aspect = true;
const bool only_selected_uvs = false;
uv_map_clip_correct(scene, objects, objects_len, op, per_face_aspect, only_selected_uvs);
if (changed_objects.is_empty()) {
return OPERATOR_CANCELLED;
}
MEM_freeN(objects);
if (changed_multi) {
return OPERATOR_FINISHED;
}
return OPERATOR_CANCELLED;
const bool per_face_aspect = true;
const bool only_selected_uvs = false;
uv_map_clip_correct(scene, objects, op, per_face_aspect, only_selected_uvs);
return OPERATOR_FINISHED;
}
static bool uv_from_view_poll(bContext *C)
@ -3254,11 +3196,9 @@ static int reset_exec(bContext *C, wmOperator * /*op*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (Object *obedit : objects) {
Mesh *mesh = (Mesh *)obedit->data;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@ -3276,7 +3216,6 @@ static int reset_exec(bContext *C, wmOperator * /*op*/)
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3518,11 +3457,9 @@ static int sphere_project_exec(bContext *C, wmOperator *op)
}
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter;
@ -3565,12 +3502,11 @@ static int sphere_project_exec(bContext *C, wmOperator *op)
}
const bool per_face_aspect = true;
uv_map_clip_correct(scene, &obedit, 1, op, per_face_aspect, only_selected_uvs);
uv_map_clip_correct(scene, {obedit}, op, per_face_aspect, only_selected_uvs);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3699,11 +3635,9 @@ static int cylinder_project_exec(bContext *C, wmOperator *op)
}
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (Object *obedit : objects) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter;
@ -3756,12 +3690,11 @@ static int cylinder_project_exec(bContext *C, wmOperator *op)
}
const bool per_face_aspect = true;
uv_map_clip_correct(scene, &obedit, 1, op, per_face_aspect, only_selected_uvs);
uv_map_clip_correct(scene, {obedit}, op, per_face_aspect, only_selected_uvs);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3853,10 +3786,9 @@ static int cube_project_exec(bContext *C, wmOperator *op)
const float cube_size_init = RNA_property_float_get(op->ptr, prop_cube_size);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d, &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, v3d);
for (const int ob_index : objects.index_range()) {
Object *obedit = objects[ob_index];
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@ -3894,12 +3826,11 @@ static int cube_project_exec(bContext *C, wmOperator *op)
uvedit_unwrap_cube_project(scene, em->bm, cube_size, true, only_selected_uvs, center);
const bool per_face_aspect = true;
uv_map_clip_correct(scene, &obedit, 1, op, per_face_aspect, only_selected_uvs);
uv_map_clip_correct(scene, {obedit}, op, per_face_aspect, only_selected_uvs);
DEG_id_tag_update(static_cast<ID *>(obedit->data), ID_RECALC_GEOMETRY);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@ -3971,7 +3902,7 @@ void ED_uvedit_add_simple_uvs(Main *bmain, const Scene *scene, Object *ob)
params.margin_method = ED_UVPACK_MARGIN_SCALED;
params.margin = 0.001f;
uvedit_pack_islands_multi(scene, &ob, 1, &bm, nullptr, false, true, &params);
uvedit_pack_islands_multi(scene, {ob}, &bm, nullptr, false, true, &params);
/* Write back from BMesh to Mesh. */
BMeshToMeshParams bm_to_me_params{};

View File

@ -765,6 +765,8 @@ const EnumPropertyItem rna_enum_grease_pencil_selectmode_items[] = {
# include "FRS_freestyle.h"
# endif
using blender::Vector;
static int rna_ToolSettings_snap_mode_get(PointerRNA *ptr)
{
ToolSettings *ts = (ToolSettings *)(ptr->data);
@ -2356,18 +2358,14 @@ static void rna_EditMesh_update(bContext *C, PointerRNA * /*ptr*/)
ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_view_layer_synced_ensure(scene, view_layer);
uint objects_len = 0;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
for (Object *obedit : objects) {
Mesh *mesh = BKE_mesh_from_object(obedit);
DEG_id_tag_update(&mesh->id, ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_GEOM | ND_DATA, mesh);
}
MEM_freeN(objects);
}
static char *rna_MeshStatVis_path(const PointerRNA * /*ptr*/)

View File

@ -10,6 +10,7 @@
#include <cmath>
#include "BLI_array.hh"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@ -28,6 +29,9 @@
#include "ED_object.hh"
#include "ED_screen.hh"
using blender::Array;
using blender::Vector;
/* -------------------------------------------------------------------- */
/** \name Generic Utilities
* \{ */
@ -165,9 +169,7 @@ struct ObCustomData_ForEditMode {
ValueInteraction inter;
/** This could be split into a sub-type if we support different kinds of data. */
Object **objects;
uint objects_len;
XFormObjectData **objects_xform;
blender::Array<XFormObjectData *> objects_xform;
};
/* Internal callback to free. */
@ -177,15 +179,12 @@ static void op_generic_value_exit(wmOperator *op)
if (cd) {
interactive_value_exit(&cd->inter);
for (uint ob_index = 0; ob_index < cd->objects_len; ob_index++) {
XFormObjectData *xod = cd->objects_xform[ob_index];
for (XFormObjectData *xod : cd->objects_xform) {
if (xod != nullptr) {
ED_object_data_xform_destroy(xod);
}
}
MEM_freeN(cd->objects);
MEM_freeN(cd->objects_xform);
MEM_freeN(cd);
MEM_delete(cd);
}
G.moving &= ~G_TRANSFORM_EDIT;
@ -194,9 +193,9 @@ static void op_generic_value_exit(wmOperator *op)
static void op_generic_value_restore(wmOperator *op)
{
ObCustomData_ForEditMode *cd = static_cast<ObCustomData_ForEditMode *>(op->customdata);
for (uint ob_index = 0; ob_index < cd->objects_len; ob_index++) {
ED_object_data_xform_restore(cd->objects_xform[ob_index]);
ED_object_data_xform_tag_update(cd->objects_xform[ob_index]);
for (XFormObjectData *xod : cd->objects_xform) {
ED_object_data_xform_restore(xod);
ED_object_data_xform_tag_update(xod);
}
}
@ -213,33 +212,26 @@ static int op_generic_value_invoke(bContext *C, wmOperator *op, const wmEvent *e
const Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
uint objects_len;
Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C), &objects_len);
if (objects_len == 0) {
MEM_freeN(objects);
Vector<Object *> objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
scene, view_layer, CTX_wm_view3d(C));
if (objects.is_empty()) {
return OPERATOR_CANCELLED;
}
ObCustomData_ForEditMode *cd = static_cast<ObCustomData_ForEditMode *>(
MEM_callocN(sizeof(*cd), __func__));
ObCustomData_ForEditMode *cd = MEM_new<ObCustomData_ForEditMode>(__func__);
cd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
cd->wait_for_input = RNA_boolean_get(op->ptr, "wait_for_input");
cd->is_active = !cd->wait_for_input;
cd->is_first = true;
cd->objects = objects;
cd->objects_len = objects_len;
if (cd->wait_for_input == false) {
interactive_value_init_from_property(C, &cd->inter, event, op->ptr, op->type->prop);
}
cd->objects_xform = static_cast<XFormObjectData **>(
MEM_callocN(sizeof(*cd->objects_xform) * objects_len, __func__));
for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
Object *obedit = objects[ob_index];
cd->objects_xform[ob_index] = ED_object_data_xform_create_from_edit_mode(
cd->objects_xform.reinitialize(objects.size());
for (const int i : objects.index_range()) {
Object *obedit = objects[i];
cd->objects_xform[i] = ED_object_data_xform_create_from_edit_mode(
static_cast<ID *>(obedit->data));
}