Blender V5.0
transform_convert_object_texspace.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "MEM_guardedalloc.h"
10
11#include "BLI_math_matrix.h"
12#include "BLI_math_vector.h"
13
14#include "BKE_layer.hh"
15#include "BKE_object.hh"
16#include "BKE_report.hh"
17
18#include "DNA_mesh_types.h"
19
20#include "transform.hh"
21#include "transform_snap.hh"
22
23/* Own include. */
24#include "transform_convert.hh"
25
26namespace blender::ed::transform {
27
28/* -------------------------------------------------------------------- */
34
35static void createTransTexspace(bContext * /*C*/, TransInfo *t)
36{
37 ViewLayer *view_layer = t->view_layer;
38 TransData *td;
39 TransDataExtension *td_ext;
40 Object *ob;
41 ID *id;
42 char *texspace_flag;
43
45 ob = BKE_view_layer_active_object_get(view_layer);
46
47 if (ob == nullptr) { /* Shouldn't logically happen, but still. */
48 return;
49 }
50
51 id = static_cast<ID *>(ob->data);
52 if (id == nullptr || !ELEM(GS(id->name), ID_ME, ID_CU_LEGACY, ID_MB)) {
53 BKE_report(t->reports, RPT_ERROR, "Unsupported object type for texture space transform");
54 return;
55 }
56
58 BKE_report(t->reports, RPT_ERROR, "Cannot create transform on linked data");
59 return;
60 }
61
62 {
65 tc->data_len = 1;
66 td = tc->data = MEM_callocN<TransData>("TransTexspace");
67 td_ext = tc->data_ext = MEM_callocN<TransDataExtension>("TransTexspace");
68 }
69
70 td->flag = TD_SELECTED;
71 td->extra = ob;
72
73 copy_m3_m4(td->mtx, ob->object_to_world().ptr());
74 copy_m3_m4(td->axismtx, ob->object_to_world().ptr());
77
78 if (BKE_object_obdata_texspace_get(ob, &texspace_flag, &td->loc, &td_ext->scale)) {
79 ob->dtx |= OB_TEXSPACE;
80 *texspace_flag &= ~ME_TEXSPACE_FLAG_AUTO;
81 }
82
83 copy_v3_v3(td->iloc, td->loc);
84 copy_v3_v3(td->center, td->loc);
85 copy_v3_v3(td_ext->iscale, td_ext->scale);
86}
87
89
90/* -------------------------------------------------------------------- */
93
95{
96
97 if (t->state != TRANS_CANCEL) {
99 }
100
102 TransData *td = tc->data;
103
104 for (int i = 0; i < tc->data_len; i++, td++) {
105 if (td->flag & TD_SKIP) {
106 continue;
107 }
108 Object *ob = static_cast<Object *>(td->extra);
110 }
111 }
112}
113
115
117 /*flags*/ 0,
118 /*create_trans_data*/ createTransTexspace,
119 /*recalc_data*/ recalcData_texspace,
120 /*special_aftertrans_update*/ nullptr,
121};
122
123} // namespace blender::ed::transform
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
General operations, lookup, etc. for blender objects.
bool BKE_object_obdata_texspace_get(Object *ob, char **r_texspace_flag, float **r_texspace_location, float **r_texspace_size)
bool BKE_object_obdata_is_libdata(const Object *ob)
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define BLI_assert(a)
Definition BLI_assert.h:46
void pseudoinverse_m3_m3(float inverse[3][3], const float mat[3][3], float epsilon)
void copy_m3_m4(float m1[3][3], const float m2[4][4])
#define PSEUDOINVERSE_EPSILON
void normalize_m3(float R[3][3]) ATTR_NONNULL()
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define ELEM(...)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ ID_CU_LEGACY
@ ID_ME
@ ID_MB
@ ME_TEXSPACE_FLAG_AUTO
@ OB_TEXSPACE
Read Guarded memory(de)allocation.
#define GS(x)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
static void createTransTexspace(bContext *, TransInfo *t)
void transform_snap_project_individual_apply(TransInfo *t)
static void recalcData_texspace(TransInfo *t)
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
TransDataContainer * data_container
Definition transform.hh:802
i
Definition text_draw.cc:230
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:42
conversion and adaptation of different datablocks to a common struct.