Blender V5.3
curve_convert.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "DNA_curve_types.h"
10#include "DNA_object_types.h"
11
12#include "BLI_utildefines.hh"
13
14#include "BKE_curve.hh"
15#include "BKE_displist.h"
16#include "BKE_lib_id.hh"
17#include "BKE_vfont.hh"
18
19#include "DEG_depsgraph.hh"
21
22namespace blender {
23
24static Curve *curve_from_font_object(Object *object, Depsgraph *depsgraph)
25{
26 Curve *curve = id_cast<Curve *>(object->data);
27 Curve *new_curve = id_cast<Curve *>(
28 BKE_id_copy_ex(nullptr, &curve->id, nullptr, LIB_ID_COPY_LOCALIZE));
29
30 Object *evaluated_object = DEG_get_evaluated(depsgraph, object);
31 BKE_vfont_to_curve_nubase(evaluated_object, FO_EDIT, &new_curve->nurb);
32
33 new_curve->ob_type = OB_CURVES_LEGACY;
34
35 new_curve->flag &= ~CU_3D;
37
38 return new_curve;
39}
40
41static Curve *curve_from_curve_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
42{
43 Object *evaluated_object = DEG_get_evaluated(depsgraph, object);
44 Curve *curve = id_cast<Curve *>(evaluated_object->data);
45 Curve *new_curve = id_cast<Curve *>(
46 BKE_id_copy_ex(nullptr, &curve->id, nullptr, LIB_ID_COPY_LOCALIZE));
47
48 if (apply_modifiers) {
50 DEG_get_input_scene(depsgraph),
51 evaluated_object,
53 &new_curve->nurb,
54 DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
55 }
56
57 return new_curve;
58}
59
60Curve *BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
61{
62 if (!ELEM(object->type, OB_FONT, OB_CURVES_LEGACY)) {
63 return nullptr;
64 }
65
66 if (object->type == OB_FONT) {
67 return curve_from_font_object(object, depsgraph);
68 }
69
70 return curve_from_curve_object(object, depsgraph, apply_modifiers);
71}
72
73} // namespace blender
display list (or rather multi purpose list) stuff.
Object is a sort of wrapper for general info.
#define ELEM(...)
BMesh Iterators.
ListBaseT< Nurb > * BKE_curve_nurbs_get(Curve *cu)
Definition curve.cc:4992
static Curve * curve_from_curve_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
void BKE_curve_calc_modifiers_pre(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, ListBaseT< Nurb > *source_nurb, ListBaseT< Nurb > *target_nurb, bool for_render)
@ LIB_ID_COPY_LOCALIZE
Curve * BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
Scene * DEG_get_input_scene(const Depsgraph *graph)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:851
static Curve * curve_from_font_object(Object *object, Depsgraph *depsgraph)
bool BKE_vfont_to_curve_nubase(Object *ob, eEditFontMode mode, ListBaseT< Nurb > *r_nubase)
void BKE_curve_dimension_update(Curve *cu)
Definition curve.cc:459
ListBaseT< Nurb > nurb