Blender V4.3
obj_export_nurbs.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 "BLI_listbase.h"
10#include "BLI_math_matrix.h"
11#include "BLI_math_rotation.h"
12#include "BLI_math_vector.h"
14
15#include "DEG_depsgraph.hh"
17
18#include "IO_wavefront_obj.hh"
19#include "obj_export_nurbs.hh"
20
21namespace blender::io::obj {
23 const OBJExportParams &export_params,
24 Object *curve_object)
25 : export_object_eval_(curve_object)
26{
27 export_object_eval_ = DEG_get_evaluated_object(depsgraph, curve_object);
28 export_curve_ = static_cast<Curve *>(export_object_eval_->data);
29 set_world_axes_transform(export_params.forward_axis, export_params.up_axis);
30}
31
32void OBJCurve::set_world_axes_transform(const eIOAxis forward, const eIOAxis up)
33{
34 float axes_transform[3][3];
35 unit_m3(axes_transform);
36 /* +Y-forward and +Z-up are the Blender's default axis settings. */
37 mat3_from_axis_conversion(forward, up, IO_AXIS_Y, IO_AXIS_Z, axes_transform);
38 mul_m4_m3m4(world_axes_transform_, axes_transform, export_object_eval_->object_to_world().ptr());
39 /* #mul_m4_m3m4 does not transform last row of #Object.object_to_world, i.e. location data. */
41 world_axes_transform_[3], axes_transform, export_object_eval_->object_to_world().location());
42 world_axes_transform_[3][3] = export_object_eval_->object_to_world()[3][3];
43}
44
45const char *OBJCurve::get_curve_name() const
46{
47 return export_object_eval_->id.name + 2;
48}
49
51{
52 return BLI_listbase_count(&export_curve_->nurb);
53}
54
55int OBJCurve::total_spline_vertices(const int spline_index) const
56{
57 const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
58 return nurb->pntsu * nurb->pntsv;
59}
60
61float3 OBJCurve::vertex_coordinates(const int spline_index,
62 const int vertex_index,
63 const float global_scale) const
64{
65 const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
66 float3 r_coord;
67 const BPoint &bpoint = nurb->bp[vertex_index];
68 copy_v3_v3(r_coord, bpoint.vec);
69 mul_m4_v3(world_axes_transform_, r_coord);
70 mul_v3_fl(r_coord, global_scale);
71 return r_coord;
72}
73
74int OBJCurve::total_spline_control_points(const int spline_index) const
75{
76 const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
77 int degree = nurb->type == CU_POLY ? 1 : nurb->orderu - 1;
78 /* Total control points = Number of points in the curve (+ degree of the
79 * curve if it is cyclic). */
80 int tot_control_points = nurb->pntsv * nurb->pntsu;
81 if (nurb->flagu & CU_NURB_CYCLIC) {
82 tot_control_points += degree;
83 }
84 return tot_control_points;
85}
86
87int OBJCurve::get_nurbs_degree(const int spline_index) const
88{
89 const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
90 return nurb->type == CU_POLY ? 1 : nurb->orderu - 1;
91}
92
93short OBJCurve::get_nurbs_flagu(const int spline_index) const
94{
95 const Nurb *const nurb = static_cast<Nurb *>(BLI_findlink(&export_curve_->nurb, spline_index));
96 return nurb->flagu;
97}
98
99} // 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])
void mul_m4_v3(const float M[4][4], float r[3])
void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4])
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])
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ CU_POLY
@ CU_NURB_CYCLIC
eIOAxis
@ IO_AXIS_Y
@ 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
float3 vertex_coordinates(int spline_index, int vertex_index, float global_scale) 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)
const Depsgraph * depsgraph
float vec[4]
ListBase nurb
char name[66]
Definition DNA_ID.h:425
short flagu
short orderu
short type
BPoint * bp