Geometry Nodes: Rewrite mesh delete geometry node #108435

Merged
Hans Goudey merged 24 commits from HooglyBoogly/blender:delete-mesh-rewrite into main 2023-06-01 14:55:27 +02:00
7 changed files with 160 additions and 96 deletions
Showing only changes of commit 4f9981b935 - Show all commits

View File

@ -17,7 +17,13 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#ifndef NOMINMAX
# define NOMINMAX
# include <windows.h>
# undef NOMINMAX
#else
# include <windows.h>
#endif
#undef rad
#undef rad1

View File

@ -57,6 +57,7 @@ set(SRC
tree/tree_element_driver.cc
tree/tree_element_gpencil_layer.cc
tree/tree_element_id.cc
tree/tree_element_id_curve.cc
tree/tree_element_id_library.cc
tree/tree_element_id_mesh.cc
tree/tree_element_id_scene.cc
@ -78,6 +79,7 @@ set(SRC
tree/tree_element_driver.hh
tree/tree_element_gpencil_layer.hh
tree/tree_element_id.hh
tree/tree_element_id_curve.hh
tree/tree_element_id_library.hh
tree/tree_element_id_mesh.hh
tree/tree_element_id_scene.hh

View File

@ -552,24 +552,13 @@ static void outliner_add_id_contents(SpaceOutliner *space_outliner,
case ID_LI:
case ID_SCE:
case ID_ME:
case ID_CU_LEGACY:
BLI_assert_msg(0, "ID type expected to be expanded through new tree-element design");
break;
case ID_OB: {
outliner_add_object_contents(space_outliner, te, tselem, (Object *)id);
break;
}
case ID_CU_LEGACY: {
Curve *cu = (Curve *)id;
if (outliner_animdata_test(cu->adt)) {
outliner_add_element(space_outliner, &te->subtree, cu, te, TSE_ANIM_DATA, 0);
}
for (int a = 0; a < cu->totcol; a++) {
outliner_add_element(space_outliner, &te->subtree, cu->mat[a], te, TSE_SOME_ID, a);
}
break;
}
case ID_MB: {
MetaBall *mb = (MetaBall *)id;

View File

@ -20,6 +20,7 @@
#include "../outliner_intern.hh"
#include "common.hh"
#include "tree_element_id_curve.hh"
#include "tree_element_id_library.hh"
#include "tree_element_id_mesh.hh"
#include "tree_element_id_scene.hh"
@ -42,8 +43,9 @@ std::unique_ptr<TreeElementID> TreeElementID::createFromID(TreeElement &legacy_t
return std::make_unique<TreeElementIDScene>(legacy_te, (Scene &)id);
case ID_ME:
return std::make_unique<TreeElementIDMesh>(legacy_te, (Mesh &)id);
case ID_OB:
case ID_CU_LEGACY:
return std::make_unique<TreeElementIDCurve>(legacy_te, (Curve &)id);
case ID_OB:
case ID_MB:
case ID_MA:
case ID_TE:

View File

@ -0,0 +1,44 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spoutliner
*/
#include "DNA_curve_types.h"
#include "DNA_listBase.h"
#include "DNA_outliner_types.h"
#include "../outliner_intern.hh"
#include "tree_element_id_curve.hh"
namespace blender::ed::outliner {
TreeElementIDCurve::TreeElementIDCurve(TreeElement &legacy_te, Curve &curve)
: TreeElementID(legacy_te, curve.id), curve_(curve)
{
}
bool TreeElementIDCurve::isExpandValid() const
{
return true;
}
void TreeElementIDCurve::expand(SpaceOutliner &space_outliner) const
{
expand_animation_data(space_outliner, curve_.adt);
expandMaterials(space_outliner);
}
void TreeElementIDCurve::expandMaterials(SpaceOutliner &space_outliner) const
{
for (int a = 0; a < curve_.totcol; a++) {
outliner_add_element(
&space_outliner, &legacy_te_.subtree, curve_.mat[a], &legacy_te_, TSE_SOME_ID, a);
}
}
} // namespace blender::ed::outliner

View File

@ -0,0 +1,28 @@
/* SPDX-FileCopyrightText: 2023 Blender Foundation
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup spoutliner
*/
#pragma once
#include "tree_element_id.hh"
namespace blender::ed::outliner {
class TreeElementIDCurve final : public TreeElementID {
Curve &curve_;
public:
TreeElementIDCurve(TreeElement &legacy_te, Curve &curve);
void expand(SpaceOutliner &) const override;
bool isExpandValid() const override;
private:
void expandMaterials(SpaceOutliner &) const;
};
} // namespace blender::ed::outliner

View File

@ -375,7 +375,7 @@ class UVAABBIsland {
*/
static void pack_islands_alpaca_turbo(const int64_t exclude_index,
const rctf &exclude,
const Span<UVAABBIsland *> islands,
const Span<std::unique_ptr<UVAABBIsland>> islands,
const float target_aspect_y,
MutableSpan<uv_phi> r_phis,
rctf *r_extent)
@ -390,9 +390,9 @@ static void pack_islands_alpaca_turbo(const int64_t exclude_index,
/* Visit every island in order, except the excluded islands at the start. */
for (int64_t index = exclude_index; index < islands.size(); index++) {
UVAABBIsland *island = islands[index];
const float dsm_u = island->uv_diagonal.x;
const float dsm_v = island->uv_diagonal.y;
UVAABBIsland &island = *islands[index];
const float dsm_u = island.uv_diagonal.x;
const float dsm_v = island.uv_diagonal.y;
bool restart = false;
if (zigzag) {
@ -409,7 +409,7 @@ static void pack_islands_alpaca_turbo(const int64_t exclude_index,
}
/* Place the island. */
uv_phi &phi = r_phis[island->index];
uv_phi &phi = r_phis[island.index];
phi.rotation = 0.0f;
phi.translation.x = u0 + dsm_u * 0.5f;
phi.translation.y = v0 + dsm_v * 0.5f;
@ -486,7 +486,7 @@ static void update_hole_rotate(float2 &hole,
*/
static void pack_islands_alpaca_rotate(const int64_t exclude_index,
const rctf &exclude,
const Span<UVAABBIsland *> islands,
const Span<std::unique_ptr<UVAABBIsland>> islands,
const float target_aspect_y,
MutableSpan<uv_phi> r_phis,
rctf *r_extent)
@ -506,30 +506,30 @@ static void pack_islands_alpaca_rotate(const int64_t exclude_index,
/* Visit every island in order, except the excluded islands at the start. */
for (int64_t index = exclude_index; index < islands.size(); index++) {
UVAABBIsland *island = islands[index];
uv_phi &phi = r_phis[island->index];
const float uvdiag_x = island->uv_diagonal.x * island->aspect_y;
float min_dsm = std::min(uvdiag_x, island->uv_diagonal.y);
float max_dsm = std::max(uvdiag_x, island->uv_diagonal.y);
UVAABBIsland &island = *islands[index];
uv_phi &phi = r_phis[island.index];
const float uvdiag_x = island.uv_diagonal.x * island.aspect_y;
float min_dsm = std::min(uvdiag_x, island.uv_diagonal.y);
float max_dsm = std::max(uvdiag_x, island.uv_diagonal.y);
if (min_dsm < hole_diagonal.x && max_dsm < hole_diagonal.y) {
/* Place island in the hole. */
if (hole_rotate == (min_dsm == island->uv_diagonal.x)) {
if (hole_rotate == (min_dsm == island.uv_diagonal.x)) {
phi.rotation = DEG2RADF(90.0f);
phi.translation.x = hole[0] + island->uv_diagonal.y * 0.5f / island->aspect_y;
phi.translation.y = hole[1] + island->uv_diagonal.x * 0.5f * island->aspect_y;
phi.translation.x = hole[0] + island.uv_diagonal.y * 0.5f / island.aspect_y;
phi.translation.y = hole[1] + island.uv_diagonal.x * 0.5f * island.aspect_y;
}
else {
phi.rotation = 0.0f;
phi.translation.x = hole[0] + island->uv_diagonal.x * 0.5f;
phi.translation.y = hole[1] + island->uv_diagonal.y * 0.5f;
phi.translation.x = hole[0] + island.uv_diagonal.x * 0.5f;
phi.translation.y = hole[1] + island.uv_diagonal.y * 0.5f;
}
/* Update space left in the hole. */
float p[6];
p[0] = hole[0];
p[1] = hole[1];
p[2] = hole[0] + (hole_rotate ? max_dsm : min_dsm) / island->aspect_y;
p[2] = hole[0] + (hole_rotate ? max_dsm : min_dsm) / island.aspect_y;
p[3] = hole[1] + (hole_rotate ? min_dsm : max_dsm);
p[4] = hole[0] + (hole_rotate ? hole_diagonal.y : hole_diagonal.x);
p[5] = hole[1] + (hole_rotate ? hole_diagonal.x : hole_diagonal.y);
@ -546,7 +546,7 @@ static void pack_islands_alpaca_rotate(const int64_t exclude_index,
restart = (next_v1 < v0 + min_dsm);
}
else {
restart = (next_u1 < u0 + min_dsm / island->aspect_y);
restart = (next_u1 < u0 + min_dsm / island.aspect_y);
}
if (restart) {
update_hole_rotate(hole, hole_diagonal, hole_rotate, u0, v0, next_u1, next_v1);
@ -559,25 +559,25 @@ static void pack_islands_alpaca_rotate(const int64_t exclude_index,
/* Place the island. */
if (zigzag == (min_dsm == uvdiag_x)) {
phi.rotation = DEG2RADF(90.0f);
phi.translation.x = u0 + island->uv_diagonal.y * 0.5f / island->aspect_y;
phi.translation.y = v0 + island->uv_diagonal.x * 0.5f * island->aspect_y;
phi.translation.x = u0 + island.uv_diagonal.y * 0.5f / island.aspect_y;
phi.translation.y = v0 + island.uv_diagonal.x * 0.5f * island.aspect_y;
}
else {
phi.rotation = 0.0f;
phi.translation.x = u0 + island->uv_diagonal.x * 0.5f;
phi.translation.y = v0 + island->uv_diagonal.y * 0.5f;
phi.translation.x = u0 + island.uv_diagonal.x * 0.5f;
phi.translation.y = v0 + island.uv_diagonal.y * 0.5f;
}
/* Move according to the "Alpaca rules", with rotation. */
if (zigzag) {
/* Move upwards. */
v0 += min_dsm;
next_u1 = max_ff(next_u1, u0 + max_dsm / island->aspect_y);
next_u1 = max_ff(next_u1, u0 + max_dsm / island.aspect_y);
next_v1 = max_ff(next_v1, v0);
}
else {
/* Move sideways. */
u0 += min_dsm / island->aspect_y;
u0 += min_dsm / island.aspect_y;
next_v1 = max_ff(next_v1, v0 + max_dsm);
next_u1 = max_ff(next_u1, u0);
}
@ -592,7 +592,7 @@ static void pack_islands_alpaca_rotate(const int64_t exclude_index,
*/
static void pack_islands_fast(const int64_t exclude_index,
const rctf &exclude,
const Span<UVAABBIsland *> aabbs,
const Span<std::unique_ptr<UVAABBIsland>> aabbs,
const bool rotate,
const float target_aspect_y,
MutableSpan<uv_phi> r_phis,
@ -607,7 +607,7 @@ static void pack_islands_fast(const int64_t exclude_index,
}
/** Frits Göbel, 1979. */
static void pack_gobel(const Span<UVAABBIsland *> aabbs,
static void pack_gobel(const Span<std::unique_ptr<UVAABBIsland>> aabbs,
const float scale,
const int m,
MutableSpan<uv_phi> r_phis)
@ -643,7 +643,7 @@ static void pack_gobel(const Span<UVAABBIsland *> aabbs,
}
}
/* Attempt to find an "Optimal" packing of the islands, e.g. assuming squares or circles. */
static void pack_islands_optimal_pack(const Span<UVAABBIsland *> aabbs,
static void pack_islands_optimal_pack(const Span<std::unique_ptr<UVAABBIsland>> aabbs,
const UVPackIsland_Params &params,
MutableSpan<uv_phi> r_phis,
rctf *r_extent)
@ -694,7 +694,7 @@ static void pack_islands_optimal_pack(const Span<UVAABBIsland *> aabbs,
}
/* Wrapper around #BLI_box_pack_2d. */
static void pack_island_box_pack_2d(const Span<UVAABBIsland *> aabbs,
static void pack_island_box_pack_2d(const Span<std::unique_ptr<UVAABBIsland>> aabbs,
const UVPackIsland_Params &params,
MutableSpan<uv_phi> r_phis,
rctf *r_extent)
@ -1093,7 +1093,7 @@ class UVMinimumEnclosingSquareFinder {
* If that square is smaller than `r_extent`, then update `r_phis` accordingly.
* \return True if `r_phis` and `r_extent` are modified.
*/
static bool rotate_inside_square(const Span<UVAABBIsland *> island_indices,
static bool rotate_inside_square(const Span<std::unique_ptr<UVAABBIsland>> island_indices,
const Span<PackIsland *> islands,
const UVPackIsland_Params &params,
const float scale,
@ -1194,7 +1194,7 @@ static bool rotate_inside_square(const Span<UVAABBIsland *> island_indices,
* Performance would normally be `O(n^4)`, however the occupancy
* bitmap_radix is fixed, which gives a reduced time complexity of `O(n^3)`.
*/
static int64_t pack_island_xatlas(const Span<UVAABBIsland *> island_indices,
static int64_t pack_island_xatlas(const Span<std::unique_ptr<UVAABBIsland>> island_indices,
const Span<PackIsland *> islands,
const float scale,
const float margin,
@ -1402,69 +1402,69 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
const bool all_can_rotate = can_rotate(islands, params);
/* First, copy information from our input into the AABB structure. */
Array<UVAABBIsland *> aabbs(islands.size());
Array<std::unique_ptr<UVAABBIsland>> aabbs(islands.size());
for (const int64_t i : islands.index_range()) {
PackIsland *pack_island = islands[i];
float island_scale = scale;
if (!pack_island->can_scale_(params)) {
island_scale = 1.0f;
}
UVAABBIsland *aabb = new UVAABBIsland();
std::unique_ptr<UVAABBIsland> aabb = std::make_unique<UVAABBIsland>();
aabb->index = i;
aabb->uv_diagonal.x = pack_island->half_diagonal_.x * 2 * island_scale + 2 * margin;
aabb->uv_diagonal.y = pack_island->half_diagonal_.y * 2 * island_scale + 2 * margin;
aabb->aspect_y = pack_island->aspect_y;
aabbs[i] = aabb;
aabbs[i] = std::move(aabb);
}
/* Sort from "biggest" to "smallest". */
if (all_can_rotate) {
std::stable_sort(aabbs.begin(),
aabbs.end(),
[&params, &islands](const UVAABBIsland *a, const UVAABBIsland *b) {
const bool can_translate_a = islands[a->index]->can_translate_(params);
const bool can_translate_b = islands[b->index]->can_translate_(params);
if (can_translate_a != can_translate_b) {
return can_translate_b; /* Locked islands are placed first. */
}
/* TODO: Fix when (params.target_aspect_y != 1.0f) */
std::stable_sort(
aabbs.begin(),
aabbs.end(),
[&](const std::unique_ptr<UVAABBIsland> &a, const std::unique_ptr<UVAABBIsland> &b) {
const bool can_translate_a = islands[a->index]->can_translate_(params);
const bool can_translate_b = islands[b->index]->can_translate_(params);
if (can_translate_a != can_translate_b) {
return can_translate_b; /* Locked islands are placed first. */
}
/* TODO: Fix when (params.target_aspect_y != 1.0f) */
/* Choose the AABB with the longest large edge. */
float a_u = a->uv_diagonal.x * a->aspect_y;
float a_v = a->uv_diagonal.y;
float b_u = b->uv_diagonal.x * b->aspect_y;
float b_v = b->uv_diagonal.y;
if (a_u > a_v) {
std::swap(a_u, a_v);
}
if (b_u > b_v) {
std::swap(b_u, b_v);
}
float diff_u = a_u - b_u;
float diff_v = a_v - b_v;
diff_v += diff_u * 0.05f; /* Robust sort, smooth over round-off errors. */
if (diff_v == 0.0f) { /* Tie break. */
return diff_u > 0.0f;
}
return diff_v > 0.0f;
});
/* Choose the AABB with the longest large edge. */
float a_u = a->uv_diagonal.x * a->aspect_y;
float a_v = a->uv_diagonal.y;
float b_u = b->uv_diagonal.x * b->aspect_y;
float b_v = b->uv_diagonal.y;
if (a_u > a_v) {
std::swap(a_u, a_v);
}
if (b_u > b_v) {
std::swap(b_u, b_v);
}
float diff_u = a_u - b_u;
float diff_v = a_v - b_v;
diff_v += diff_u * 0.05f; /* Robust sort, smooth over round-off errors. */
if (diff_v == 0.0f) { /* Tie break. */
return diff_u > 0.0f;
}
return diff_v > 0.0f;
});
}
else {
std::stable_sort(
aabbs.begin(),
aabbs.end(),
[&](const std::unique_ptr<UVAABBIsland> &a, const std::unique_ptr<UVAABBIsland> &b) {
const bool can_translate_a = islands[a->index]->can_translate_(params);
const bool can_translate_b = islands[b->index]->can_translate_(params);
if (can_translate_a != can_translate_b) {
return can_translate_b; /* Locked islands are placed first. */
}
std::stable_sort(aabbs.begin(),
aabbs.end(),
[&params, &islands](const UVAABBIsland *a, const UVAABBIsland *b) {
const bool can_translate_a = islands[a->index]->can_translate_(params);
const bool can_translate_b = islands[b->index]->can_translate_(params);
if (can_translate_a != can_translate_b) {
return can_translate_b; /* Locked islands are placed first. */
}
/* Choose the AABB with larger rectangular area. */
return b->uv_diagonal.x * b->uv_diagonal.y <
a->uv_diagonal.x * a->uv_diagonal.y;
});
/* Choose the AABB with larger rectangular area. */
return b->uv_diagonal.x * b->uv_diagonal.y < a->uv_diagonal.x * a->uv_diagonal.y;
});
}
/* If some of the islands are locked, we build a summary about them here. */
@ -1499,7 +1499,7 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
alpaca_cutoff = std::max(alpaca_cutoff, locked_island_count); /* ...TODO... */
Span<UVAABBIsland *> slow_aabbs = aabbs.as_span().take_front(
Span<std::unique_ptr<UVAABBIsland>> slow_aabbs = aabbs.as_span().take_front(
std::min(alpaca_cutoff, islands.size()));
rctf extent = {0.0f, 1e30f, 0.0f, 1e30f};
@ -1546,13 +1546,6 @@ static float pack_islands_scale_margin(const Span<PackIsland *> islands,
r_phis,
&final_extent);
/* Housekeeping. */
for (const int64_t i : aabbs.index_range()) {
UVAABBIsland *aabb = aabbs[i];
aabbs[i] = nullptr;
delete aabb;
}
return get_aspect_scaled_extent(final_extent, params);
}