Changeset View
Changeset View
Standalone View
Standalone View
source/blender/depsgraph/intern/depsgraph_lineart.cc
- This file was added.
| /* SPDX-License-Identifier: GPL-2.0-or-later | |||||
| * Copyright 2018 Blender Foundation. All rights reserved. */ | |||||
| /** \file | |||||
| * \ingroup depsgraph | |||||
| * | |||||
| * Physics utilities for effectors and collision. | |||||
| */ | |||||
| #include "intern/depsgraph_lineart.h" | |||||
| #include "MEM_guardedalloc.h" | |||||
| #include "BLI_compiler_compat.h" | |||||
| #include "BLI_listbase.h" | |||||
| #include "BKE_gpencil_modifier.h" | |||||
| #include "BKE_modifier.h" | |||||
| #include "DNA_object_types.h" | |||||
| #include "DEG_depsgraph_build.h" | |||||
| #include "DEG_depsgraph_lineart.h" | |||||
| #include "DEG_depsgraph_query.h" | |||||
| #include "depsgraph.h" | |||||
| namespace deg = blender::deg; | |||||
| /*************************** Evaluation Query API *****************************/ | |||||
| /* Get ID from an ID type object, in a safe manner. This means that object can be nullptr, | |||||
| * in which case the function returns nullptr. | |||||
| */ | |||||
| template<class T> static ID *object_id_safe(T *object) | |||||
| { | |||||
| if (object == nullptr) { | |||||
| return nullptr; | |||||
| } | |||||
| return &object->id; | |||||
| } | |||||
| ListBase *DEG_get_lineart_relations(const Depsgraph *graph) | |||||
| { | |||||
| const deg::Depsgraph *deg_graph = reinterpret_cast<const deg::Depsgraph *>(graph); | |||||
| blender::Map<const ID *, ListBase *> *hash = deg_graph->lineart_relations; | |||||
| if (hash == nullptr) { | |||||
| return nullptr; | |||||
| } | |||||
| /* Using nullptr as lookup key as we don't need to read objects separatedly from different | |||||
| * collections. */ | |||||
| return hash->lookup_default(nullptr, nullptr); | |||||
| } | |||||
| /********************** Depsgraph Building API ************************/ | |||||
| void DEG_add_lineart_relations(DepsNodeHandle *handle, | |||||
| Collection *collection, | |||||
| bool allow_duplicates, | |||||
| const char *name) | |||||
| { | |||||
| Depsgraph *depsgraph = DEG_get_graph_from_handle(handle); | |||||
| deg::Depsgraph *deg_graph = (deg::Depsgraph *)depsgraph; | |||||
| ListBase *relations = build_lineart_relations(deg_graph, collection, allow_duplicates); | |||||
| LISTBASE_FOREACH (LineartRelation *, relation, relations) { | |||||
| DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_GEOMETRY, name); | |||||
| DEG_add_object_relation(handle, relation->ob, DEG_OB_COMP_TRANSFORM, name); | |||||
| } | |||||
| } | |||||
| /******************************** Internal API ********************************/ | |||||
| namespace blender::deg { | |||||
| ListBase *build_lineart_relations(Depsgraph *graph, Collection *collection, bool allow_duplicates) | |||||
| { | |||||
| Map<const ID *, ListBase *> *hash = graph->lineart_relations; | |||||
| if (hash == nullptr) { | |||||
| graph->lineart_relations = new Map<const ID *, ListBase *>(); | |||||
| hash = graph->lineart_relations; | |||||
| } | |||||
| /* Using nullptr as lookup key as we don't need to read objects separatedly from different | |||||
| * collections. */ | |||||
| return hash->lookup_or_add_cb(nullptr, [&]() { | |||||
| ::Depsgraph *depsgraph = reinterpret_cast<::Depsgraph *>(graph); | |||||
| return BKE_lineart_relations_create(depsgraph, collection, allow_duplicates); | |||||
| }); | |||||
| } | |||||
| void clear_lineart_relations(Depsgraph *graph) | |||||
| { | |||||
| for (int i = 0; i < DEG_PHYSICS_RELATIONS_NUM; i++) { | |||||
| Map<const ID *, ListBase *> *hash = graph->lineart_relations; | |||||
| if (hash) { | |||||
| for (ListBase *list : hash->values()) { | |||||
| BKE_lineart_relations_free(list); | |||||
| } | |||||
| delete hash; | |||||
| graph->lineart_relations = nullptr; | |||||
| } | |||||
| } | |||||
| } | |||||
| } // namespace blender::deg | |||||