Fixed objects disappearing when using edit tool

This commit is contained in:
Yousef Khadadeh 2025-09-29 15:44:01 +03:00
parent b58e11c703
commit 2aff80d56f
4 changed files with 45 additions and 34 deletions

View file

@ -170,6 +170,19 @@ void DrawingProgramCache::traverse_bvh_run_function_recursive(const std::shared_
}
}
CollabListType::ObjectInfoPtr DrawingProgramCache::get_front_object_colliding_with(const SCollision::ColliderCollection<float>& cC) {
auto cCWorld = drawP.world.drawData.cam.c.collider_to_world<SCollision::ColliderCollection<WorldScalar>, SCollision::ColliderCollection<float>>(cC);
CollabListType::ObjectInfoPtr p;
traverse_bvh_run_function(cCWorld.bounds, [&](const std::shared_ptr<DrawingProgramCacheBVHNode>& bvhNode, const std::vector<CollabListType::ObjectInfoPtr>& components) {
for(auto& c : components) {
if((!p || c->pos >= p->pos) && c->obj->collides_with_world_coords(drawP.world.drawData.cam.c, cCWorld))
p = c;
}
return true;
});
return p;
}
void DrawingProgramCache::preupdate_component(const CollabListType::ObjectInfoPtr& c) {
auto parentBvhNode = c->obj->parentBvhNode.lock();
if(parentBvhNode) {

View file

@ -66,8 +66,10 @@ class DrawingProgramCache {
const std::vector<CollabListType::ObjectInfoPtr>& get_unsorted_component_list() const;
const std::chrono::steady_clock::time_point& get_last_bvh_build_time() const;
void clear_own_cached_surfaces();
private:
CollabListType::ObjectInfoPtr get_front_object_colliding_with(const SCollision::ColliderCollection<float>& cC);
private:
static std::unordered_set<std::shared_ptr<DrawingProgramCacheBVHNode>> nodesWithCachedSurfaces;
void draw_cache_image_to_canvas(SkCanvas* canvas, const DrawData& drawData, const std::shared_ptr<DrawingProgramCacheBVHNode>& bvhNode);

View file

@ -70,32 +70,36 @@ std::function<bool(const std::shared_ptr<DrawingProgramCacheBVHNode>&, std::vect
return toRet;
}
void DrawingProgramSelection::add_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool onlyFrontObject) {
auto cCWorld = drawP.world.drawData.cam.c.collider_to_world<SCollision::ColliderCollection<WorldScalar>, SCollision::ColliderCollection<float>>(cC);
void DrawingProgramSelection::add_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool frontObjectOnly) {
std::unordered_set<CollabListType::ObjectInfoPtr> selectedComponents;
drawP.compCache.traverse_bvh_erase_function(cCWorld.bounds, erase_select_objects_in_bvh_func(selectedComponents, cC, cCWorld));
if(onlyFrontObject && !selectedComponents.empty()) {
CollabListType::ObjectInfoPtr p = *std::max_element(selectedComponents.begin(), selectedComponents.end(), [](auto& a, auto& b) {
return a->pos < b->pos;
});
selectedComponents.clear();
selectedComponents.emplace(p);
if(frontObjectOnly) {
CollabListType::ObjectInfoPtr a = drawP.compCache.get_front_object_colliding_with(cC);
if(a) {
selectedComponents.emplace(a);
drawP.compCache.erase_component(a);
}
}
else {
auto cCWorld = drawP.world.drawData.cam.c.collider_to_world<SCollision::ColliderCollection<WorldScalar>, SCollision::ColliderCollection<float>>(cC);
drawP.compCache.traverse_bvh_erase_function(cCWorld.bounds, erase_select_objects_in_bvh_func(selectedComponents, cC, cCWorld));
}
add_to_selection(selectedComponents);
}
void DrawingProgramSelection::remove_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool onlyFrontObject) {
void DrawingProgramSelection::remove_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool frontObjectOnly) {
auto cCWorld = drawP.world.drawData.cam.c.collider_to_world<SCollision::ColliderCollection<WorldScalar>, SCollision::ColliderCollection<float>>(cC);
std::unordered_set<CollabListType::ObjectInfoPtr> selectedComponents;
cache.traverse_bvh_erase_function(cCWorld.bounds, erase_select_objects_in_bvh_func(selectedComponents, cC, cCWorld));
if(onlyFrontObject && !selectedComponents.empty()) {
CollabListType::ObjectInfoPtr p = *std::max_element(selectedComponents.begin(), selectedComponents.end(), [](auto& a, auto& b) {
return a->pos < b->pos;
});
selectedComponents.clear();
selectedComponents.emplace(p);
if(frontObjectOnly) {
CollabListType::ObjectInfoPtr a = cache.get_front_object_colliding_with(cC);
if(a) {
selectedComponents.emplace(a);
cache.erase_component(a);
}
}
else {
cache.traverse_bvh_erase_function(cCWorld.bounds, erase_select_objects_in_bvh_func(selectedComponents, cC, cCWorld));
cache.clear_own_cached_surfaces();
}
cache.clear_own_cached_surfaces();
std::erase_if(selectedSet, [&](auto& c) {
return selectedComponents.contains(c);
});
@ -111,19 +115,6 @@ void DrawingProgramSelection::remove_from_cam_coord_collider_to_selection(const
}
}
CollabListType::ObjectInfoPtr DrawingProgramSelection::get_front_object_colliding_with(const SCollision::ColliderCollection<float>& cC) {
auto cCWorld = drawP.world.drawData.cam.c.collider_to_world<SCollision::ColliderCollection<WorldScalar>, SCollision::ColliderCollection<float>>(cC);
CollabListType::ObjectInfoPtr p;
cache.traverse_bvh_run_function(cCWorld.bounds, [&](const std::shared_ptr<DrawingProgramCacheBVHNode>& bvhNode, const std::vector<CollabListType::ObjectInfoPtr>& components) {
for(auto& c : components) {
if((!p || c->pos >= p->pos) && c->obj->collides_with_world_coords(drawP.world.drawData.cam.c, cCWorld))
p = c;
}
return true;
});
return p;
}
void DrawingProgramSelection::add_to_selection(const std::unordered_set<CollabListType::ObjectInfoPtr>& newSelection) {
selectedSet.insert(newSelection.begin(), newSelection.end());
for(auto& obj : newSelection)
@ -241,6 +232,10 @@ void DrawingProgramSelection::commit_transform_selection() {
set_to_selection(selectedSetTemp);
}
CollabListType::ObjectInfoPtr DrawingProgramSelection::get_front_object_colliding_with(const SCollision::ColliderCollection<float>& cC) {
return cache.get_front_object_colliding_with(cC);
}
void DrawingProgramSelection::invalidate_cache_at_optional_aabb_before_pos(const std::optional<SCollision::AABB<WorldScalar>>& aabb, uint64_t placementToInvalidateAt) {
cache.invalidate_cache_at_optional_aabb_before_pos(aabb, placementToInvalidateAt);
}

View file

@ -7,8 +7,9 @@ class DrawingProgram;
class DrawingProgramSelection {
public:
DrawingProgramSelection(DrawingProgram& initDrawP);
void add_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool onlyFrontObject = false);
void remove_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool onlyFrontObject = false);
void add_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool frontObjectOnly = false);
void remove_from_cam_coord_collider_to_selection(const SCollision::ColliderCollection<float>& cC, bool frontObjectOnly = false);
CollabListType::ObjectInfoPtr get_front_object_colliding_with(const SCollision::ColliderCollection<float>& cC);
void deselect_all();