Blender V4.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
9#include "DNA_curve_types.h"
10#include "DNA_object_types.h"
11
12#include "BLI_utildefines.h"
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
22static Curve *curve_from_font_object(Object *object, Depsgraph *depsgraph)
23{
24 Curve *curve = (Curve *)object->data;
25 Curve *new_curve = (Curve *)BKE_id_copy_ex(nullptr, &curve->id, nullptr, LIB_ID_COPY_LOCALIZE);
26
27 Object *evaluated_object = DEG_get_evaluated_object(depsgraph, object);
28 BKE_vfont_to_curve_nubase(evaluated_object, FO_EDIT, &new_curve->nurb);
29
30 new_curve->type = OB_CURVES_LEGACY;
31
32 new_curve->flag &= ~CU_3D;
34
35 return new_curve;
36}
37
38static Curve *curve_from_curve_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
39{
40 Object *evaluated_object = DEG_get_evaluated_object(depsgraph, object);
41 Curve *curve = (Curve *)evaluated_object->data;
42 Curve *new_curve = (Curve *)BKE_id_copy_ex(nullptr, &curve->id, nullptr, LIB_ID_COPY_LOCALIZE);
43
44 if (apply_modifiers) {
47 evaluated_object,
49 &new_curve->nurb,
51 }
52
53 return new_curve;
54}
55
56Curve *BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
57{
58 if (!ELEM(object->type, OB_FONT, OB_CURVES_LEGACY)) {
59 return nullptr;
60 }
61
62 if (object->type == OB_FONT) {
63 return curve_from_font_object(object, depsgraph);
64 }
65
66 return curve_from_curve_object(object, depsgraph, apply_modifiers);
67}
ListBase * BKE_curve_nurbs_get(Curve *cu)
Definition curve.cc:4965
void BKE_curve_dimension_update(Curve *cu)
Definition curve.cc:437
display list (or rather multi purpose list) stuff.
void BKE_curve_calc_modifiers_pre(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, struct ListBase *source_nurb, struct ListBase *target_nurb, bool for_render)
@ LIB_ID_COPY_LOCALIZE
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
Definition lib_id.cc:760
@ FO_EDIT
Definition BKE_vfont.hh:69
bool BKE_vfont_to_curve_nubase(Object *ob, eEditFontMode mode, ListBase *r_nubase)
Definition vfont.cc:2036
#define ELEM(...)
@ DAG_EVAL_RENDER
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
Scene * DEG_get_input_scene(const Depsgraph *graph)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
Object is a sort of wrapper for general info.
@ OB_FONT
@ OB_CURVES_LEGACY
static Curve * curve_from_font_object(Object *object, Depsgraph *depsgraph)
Curve * BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
static Curve * curve_from_curve_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
const Depsgraph * depsgraph
ListBase nurb