Blender  V2.93
curve_convert.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include "DNA_curve_types.h"
22 #include "DNA_object_types.h"
23 #include "DNA_vfont_types.h"
24 
25 #include "BLI_utildefines.h"
26 
27 #include "BKE_curve.h"
28 #include "BKE_displist.h"
29 #include "BKE_font.h"
30 #include "BKE_lib_id.h"
31 #include "BKE_modifier.h"
32 
33 #include "DEG_depsgraph.h"
34 #include "DEG_depsgraph_query.h"
35 
37 {
38  Curve *curve = (Curve *)object->data;
40 
41  Object *evaluated_object = DEG_get_evaluated_object(depsgraph, object);
42  BKE_vfont_to_curve_nubase(evaluated_object, FO_EDIT, &new_curve->nurb);
43 
44  new_curve->type = OB_CURVE;
45 
46  new_curve->flag &= ~CU_3D;
47  BKE_curve_dimension_update(new_curve);
48 
49  return new_curve;
50 }
51 
52 static Curve *curve_from_curve_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
53 {
54  Object *evaluated_object = DEG_get_evaluated_object(depsgraph, object);
55  Curve *curve = (Curve *)evaluated_object->data;
57 
58  if (apply_modifiers) {
61  evaluated_object,
63  &new_curve->nurb,
65  }
66 
67  return new_curve;
68 }
69 
70 Curve *BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
71 {
72  if (!ELEM(object->type, OB_FONT, OB_CURVE)) {
73  return NULL;
74  }
75 
76  if (object->type == OB_FONT) {
77  return curve_from_font_object(object, depsgraph);
78  }
79 
80  return curve_from_curve_object(object, depsgraph, apply_modifiers);
81 }
void BKE_curve_dimension_update(struct Curve *cu)
Definition: curve.c:467
ListBase * BKE_curve_nurbs_get(struct Curve *cu)
Definition: curve.c:5079
display list (or rather multi purpose list) stuff.
bool BKE_curve_calc_modifiers_pre(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, struct ListBase *source_nurb, struct ListBase *target_nurb, const bool for_render)
bool BKE_vfont_to_curve_nubase(struct Object *ob, int mode, struct ListBase *r_nubase)
Definition: font.c:1732
@ LIB_ID_COPY_LOCALIZE
Definition: BKE_lib_id.h:145
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
#define ELEM(...)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
@ DAG_EVAL_RENDER
Definition: DEG_depsgraph.h:62
struct Scene * DEG_get_input_scene(const Depsgraph *graph)
eEvaluationMode DEG_get_mode(const Depsgraph *graph)
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ CU_3D
Object is a sort of wrapper for general info.
@ OB_FONT
@ OB_CURVE
#define FO_EDIT
Curve * BKE_curve_new_from_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
Definition: curve_convert.c:70
static Curve * curve_from_font_object(Object *object, Depsgraph *depsgraph)
Definition: curve_convert.c:36
static Curve * curve_from_curve_object(Object *object, Depsgraph *depsgraph, bool apply_modifiers)
Definition: curve_convert.c:52
Curve curve
const Depsgraph * depsgraph
void * data