Added an operator to match texture space to object's bounding box
This operator could be useful after recent changes to how curve's texture space is calculated.
This commit is contained in:
@@ -140,6 +140,8 @@ class DATA_PT_curve_texture_space(CurveButtonsPanel, Panel):
|
||||
row.column().prop(curve, "texspace_location", text="Location")
|
||||
row.column().prop(curve, "texspace_size", text="Size")
|
||||
|
||||
layout.operator("curve.match_texture_space")
|
||||
|
||||
|
||||
class DATA_PT_geometry_curve(CurveButtonsPanel, Panel):
|
||||
bl_label = "Geometry"
|
||||
|
||||
@@ -124,5 +124,7 @@ void CURVE_OT_vertex_add(struct wmOperatorType *ot);
|
||||
void CURVE_OT_extrude(struct wmOperatorType *ot);
|
||||
void CURVE_OT_cyclic_toggle(struct wmOperatorType *ot);
|
||||
|
||||
void CURVE_OT_match_texture_space(struct wmOperatorType *ot);
|
||||
|
||||
#endif /* ED_UTIL_INTERN_H */
|
||||
|
||||
|
||||
@@ -134,6 +134,8 @@ void ED_operatortypes_curve(void)
|
||||
WM_operatortype_append(CURVE_OT_vertex_add);
|
||||
WM_operatortype_append(CURVE_OT_extrude);
|
||||
WM_operatortype_append(CURVE_OT_cyclic_toggle);
|
||||
|
||||
WM_operatortype_append(CURVE_OT_match_texture_space);
|
||||
}
|
||||
|
||||
void ED_operatormacros_curve(void)
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_fcurve.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_key.h"
|
||||
@@ -7144,3 +7145,88 @@ int ED_curve_actSelection(Curve *cu, float center[3])
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/******************** Match texture space operator ***********************/
|
||||
|
||||
static int match_texture_space_poll(bContext *C)
|
||||
{
|
||||
Object *object = CTX_data_active_object(C);
|
||||
|
||||
return object && ELEM3(object->type, OB_CURVE, OB_SURF, OB_FONT);
|
||||
}
|
||||
|
||||
static int match_texture_space_exec(bContext *C, wmOperator *UNUSED(op))
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
Object *object = CTX_data_active_object(C);
|
||||
Curve *curve = (Curve *) object->data;
|
||||
DispList *dl;
|
||||
float min[3], max[3], size[3], loc[3];
|
||||
bool do_it = false;
|
||||
int a;
|
||||
|
||||
if (ELEM(NULL, object->curve_cache, object->curve_cache->disp.first)) {
|
||||
BKE_displist_make_curveTypes(scene, object, FALSE);
|
||||
}
|
||||
|
||||
INIT_MINMAX(min, max);
|
||||
|
||||
dl = object->curve_cache->disp.first;
|
||||
while (dl) {
|
||||
int tot = ELEM(dl->type, DL_INDEX3, DL_INDEX4) ? dl->nr : dl->nr * dl->parts;
|
||||
float *fp;
|
||||
|
||||
if (tot) {
|
||||
do_it = true;
|
||||
}
|
||||
|
||||
fp = dl->verts;
|
||||
while (tot--) {
|
||||
minmax_v3v3_v3(min, max, fp);
|
||||
fp += 3;
|
||||
}
|
||||
dl = dl->next;
|
||||
}
|
||||
|
||||
if (do_it == false) {
|
||||
min[0] = min[1] = min[2] = -1.0f;
|
||||
max[0] = max[1] = max[2] = 1.0f;
|
||||
}
|
||||
|
||||
mid_v3_v3v3(loc, min, max);
|
||||
|
||||
size[0] = (max[0] - min[0]) / 2.0f;
|
||||
size[1] = (max[1] - min[1]) / 2.0f;
|
||||
size[2] = (max[2] - min[2]) / 2.0f;
|
||||
|
||||
for (a = 0; a < 3; a++) {
|
||||
if (size[a] == 0.0f) size[a] = 1.0f;
|
||||
else if (size[a] > 0.0f && size[a] < 0.00001f) size[a] = 0.00001f;
|
||||
else if (size[a] < 0.0f && size[a] > -0.00001f) size[a] = -0.00001f;
|
||||
}
|
||||
|
||||
copy_v3_v3(curve->loc, loc);
|
||||
copy_v3_v3(curve->size, size);
|
||||
zero_v3(curve->rot);
|
||||
|
||||
curve->texflag &= ~CU_AUTOSPACE;
|
||||
|
||||
WM_event_add_notifier(C, NC_GEOM | ND_DATA, curve);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void CURVE_OT_match_texture_space(wmOperatorType *ot)
|
||||
{
|
||||
/* identifiers */
|
||||
ot->name = "Match Texture Space";
|
||||
ot->idname = "CURVE_OT_match_texture_space";
|
||||
ot->description = "Match texture space to object's bounding box";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec = match_texture_space_exec;
|
||||
ot->poll = match_texture_space_poll;
|
||||
|
||||
/* flags */
|
||||
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user