Blender  V3.3
obj_export_nurbs.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "BLI_listbase.h"
8 #include "BLI_math.h"
9 #include "BLI_math_vec_types.hh"
10 
11 #include "DEG_depsgraph.h"
12 #include "DEG_depsgraph_query.h"
13 
14 #include "IO_wavefront_obj.h"
15 #include "obj_export_nurbs.hh"
16 
17 namespace blender::io::obj {
19  const OBJExportParams &export_params,
20  Object *curve_object)
21  : export_object_eval_(curve_object)
22 {
23  export_object_eval_ = DEG_get_evaluated_object(depsgraph, curve_object);
24  export_curve_ = static_cast<Curve *>(export_object_eval_->data);
25  set_world_axes_transform(export_params.forward_axis, export_params.up_axis);
26 }
27 
28 void OBJCurve::set_world_axes_transform(const eIOAxis forward, const eIOAxis up)
29 {
30  float axes_transform[3][3];
31  unit_m3(axes_transform);
32  /* +Y-forward and +Z-up are the Blender's default axis settings. */
33  mat3_from_axis_conversion(forward, up, IO_AXIS_Y, IO_AXIS_Z, axes_transform);
34  mul_m4_m3m4(world_axes_transform_, axes_transform, export_object_eval_->obmat);
35  /* #mul_m4_m3m4 does not transform last row of #Object.obmat, i.e. location data. */
36  mul_v3_m3v3(world_axes_transform_[3], axes_transform, export_object_eval_->obmat[3]);
37  world_axes_transform_[3][3] = export_object_eval_->obmat[3][3];
38 }
39 
40 const char *OBJCurve::get_curve_name() const
41 {
42  return export_object_eval_->id.name + 2;
43 }
44 
46 {
47  return BLI_listbase_count(&export_curve_->nurb);
48 }
49 
51 {
52  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
53  return nurb->pntsu * nurb->pntsv;
54 }
55 
57  const int vertex_index,
58  const float scaling_factor) const
59 {
60  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
61  float3 r_coord;
62  const BPoint &bpoint = nurb->bp[vertex_index];
63  copy_v3_v3(r_coord, bpoint.vec);
64  mul_m4_v3(world_axes_transform_, r_coord);
65  mul_v3_fl(r_coord, scaling_factor);
66  return r_coord;
67 }
68 
70 {
71  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
72  int degree = nurb->type == CU_POLY ? 1 : nurb->orderu - 1;
73  /* Total control points = Number of points in the curve (+ degree of the
74  * curve if it is cyclic). */
75  int r_tot_control_points = nurb->pntsv * nurb->pntsu;
76  if (nurb->flagu & CU_NURB_CYCLIC) {
77  r_tot_control_points += degree;
78  }
79  return r_tot_control_points;
80 }
81 
83 {
84  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
85  return nurb->type == CU_POLY ? 1 : nurb->orderu - 1;
86 }
87 
89 {
90  const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
91  return nurb->flagu;
92 }
93 
94 } // namespace blender::io::obj
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
void unit_m3(float m[3][3])
Definition: math_matrix.c:40
void mul_m4_v3(const float M[4][4], float r[3])
Definition: math_matrix.c:729
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
Definition: math_matrix.c:897
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
Definition: math_matrix.c:500
bool mat3_from_axis_conversion(int src_forward, int src_up, int dst_forward, int dst_up, float r_mat[3][3])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
struct Object * DEG_get_evaluated_object(const struct Depsgraph *depsgraph, struct Object *object)
@ CU_POLY
@ CU_NURB_CYCLIC
eIOAxis
Definition: IO_orientation.h:7
@ IO_AXIS_Y
Definition: IO_orientation.h:9
@ IO_AXIS_Z
int total_spline_vertices(int spline_index) const
int total_spline_control_points(int spline_index) const
short get_nurbs_flagu(int spline_index) const
int get_nurbs_degree(int spline_index) const
const char * get_curve_name() const
OBJCurve(const Depsgraph *depsgraph, const OBJExportParams &export_params, Object *curve_object)
float3 vertex_coordinates(int spline_index, int vertex_index, float scaling_factor) const
const Depsgraph * depsgraph
float vec[4]
ListBase nurb
char name[66]
Definition: DNA_ID.h:378
short flagu
short orderu
short type
BPoint * bp
float obmat[4][4]
void * data