Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--release/scripts/startup/bl_ui/properties_data_curve.py2
-rw-r--r--source/blender/blenkernel/BKE_curve.h4
-rw-r--r--source/blender/blenkernel/intern/curve.c50
-rw-r--r--source/blender/blenkernel/intern/displist.c12
-rw-r--r--source/blender/blenkernel/intern/object.c5
-rw-r--r--source/blender/blenloader/intern/readfile.c1
-rw-r--r--source/blender/editors/curve/curve_intern.h2
-rw-r--r--source/blender/editors/curve/curve_ops.c2
-rw-r--r--source/blender/editors/curve/editcurve.c63
-rw-r--r--source/blender/makesdna/DNA_curve_types.h1
10 files changed, 116 insertions, 26 deletions
diff --git a/release/scripts/startup/bl_ui/properties_data_curve.py b/release/scripts/startup/bl_ui/properties_data_curve.py
index 117a662cd07..1d90535b46f 100644
--- a/release/scripts/startup/bl_ui/properties_data_curve.py
+++ b/release/scripts/startup/bl_ui/properties_data_curve.py
@@ -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"
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index dee27cebf59..8b2107071d3 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -76,7 +76,7 @@ struct BoundBox *BKE_curve_boundbox_get(struct Object *ob);
void BKE_curve_texspace_calc(struct Curve *cu);
void BKE_curve_texspace_get(struct Curve *cu, float r_loc[3], float r_rot[3], float r_size[3]);
-bool BKE_curve_minmax(struct Curve *cu, float min[3], float max[3]);
+bool BKE_curve_minmax(struct Curve *cu, bool use_radius, float min[3], float max[3]);
bool BKE_curve_center_median(struct Curve *cu, float cent[3]);
bool BKE_curve_center_bounds(struct Curve *cu, float cent[3]);
void BKE_curve_translate(struct Curve *cu, float offset[3], int do_keys);
@@ -122,7 +122,7 @@ struct Nurb *BKE_nurb_duplicate(struct Nurb *nu);
struct Nurb *BKE_nurb_copy(struct Nurb *src, int pntsu, int pntsv);
void BKE_nurb_test2D(struct Nurb *nu);
-void BKE_nurb_minmax(struct Nurb *nu, float min[3], float max[3]);
+void BKE_nurb_minmax(struct Nurb *nu, bool use_radius, float min[3], float max[3]);
void BKE_nurb_makeFaces(struct Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv);
void BKE_nurb_makeCurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride);
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index d57b5149538..969db19a256 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -143,7 +143,6 @@ void BKE_curve_editNurb_free(Curve *cu)
void BKE_curve_free(Curve *cu)
{
BKE_nurbList_free(&cu->nurb);
- BKE_displist_free(&cu->disp);
BKE_curve_editfont_free(cu);
BKE_curve_editNurb_free(cu);
@@ -223,8 +222,6 @@ Curve *BKE_curve_copy(Curve *cu)
cun->key = BKE_key_copy(cu->key);
if (cun->key) cun->key->from = (ID *)cun;
- cun->disp.first = cun->disp.last = NULL;
-
cun->editnurb = NULL;
cun->editfont = NULL;
cun->selboxes = NULL;
@@ -379,7 +376,11 @@ void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3])
if (!r_size) r_size = msize;
INIT_MINMAX(min, max);
- BKE_displist_minmax(&cu->disp, min, max);
+ if (!BKE_curve_minmax(cu, true, min, max)) {
+ min[0] = min[1] = min[2] = -1.0f;
+ max[0] = max[1] = max[2] = 1.0f;
+ }
+
mid_v3_v3v3(r_loc, min, max);
r_size[0] = (max[0] - min[0]) / 2.0f;
@@ -642,18 +643,34 @@ void BKE_nurb_test2D(Nurb *nu)
}
}
-void BKE_nurb_minmax(Nurb *nu, float min[3], float max[3])
+/* if use_radius is truth, minmax will take points' radius into account,
+ * which will make boundbox closer to bevelled curve.
+ */
+void BKE_nurb_minmax(Nurb *nu, bool use_radius, float min[3], float max[3])
{
BezTriple *bezt;
BPoint *bp;
int a;
+ float point[3];
if (nu->type == CU_BEZIER) {
a = nu->pntsu;
bezt = nu->bezt;
while (a--) {
+ if (use_radius) {
+ float radius_vector[3];
+ radius_vector[0] = radius_vector[1] = radius_vector[2] = bezt->radius;
+
+ add_v3_v3v3(point, bezt->vec[1], radius_vector);
+ minmax_v3v3_v3(min, max, point);
+
+ sub_v3_v3v3(point, bezt->vec[1], radius_vector);
+ minmax_v3v3_v3(min, max, point);
+ }
+ else {
+ minmax_v3v3_v3(min, max, bezt->vec[1]);
+ }
minmax_v3v3_v3(min, max, bezt->vec[0]);
- minmax_v3v3_v3(min, max, bezt->vec[1]);
minmax_v3v3_v3(min, max, bezt->vec[2]);
bezt++;
}
@@ -662,7 +679,20 @@ void BKE_nurb_minmax(Nurb *nu, float min[3], float max[3])
a = nu->pntsu * nu->pntsv;
bp = nu->bp;
while (a--) {
- minmax_v3v3_v3(min, max, bp->vec);
+ if (nu->pntsv == 1 && use_radius) {
+ float radius_vector[3];
+ radius_vector[0] = radius_vector[1] = radius_vector[2] = bp->radius;
+
+ add_v3_v3v3(point, bp->vec, radius_vector);
+ minmax_v3v3_v3(min, max, point);
+
+ sub_v3_v3v3(point, bp->vec, radius_vector);
+ minmax_v3v3_v3(min, max, point);
+ }
+ else {
+ /* Surfaces doesn't use bevel, so no need to take radius into account. */
+ minmax_v3v3_v3(min, max, bp->vec);
+ }
bp++;
}
}
@@ -3840,13 +3870,13 @@ ListBase *BKE_curve_nurbs_get(Curve *cu)
/* basic vertex data functions */
-bool BKE_curve_minmax(Curve *cu, float min[3], float max[3])
+bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3])
{
ListBase *nurb_lb = BKE_curve_nurbs_get(cu);
Nurb *nu;
for (nu = nurb_lb->first; nu; nu = nu->next)
- BKE_nurb_minmax(nu, min, max);
+ BKE_nurb_minmax(nu, use_radius, min, max);
return (nurb_lb->first != NULL);
}
@@ -3893,7 +3923,7 @@ bool BKE_curve_center_bounds(Curve *cu, float cent[3])
{
float min[3], max[3];
INIT_MINMAX(min, max);
- if (BKE_curve_minmax(cu, min, max)) {
+ if (BKE_curve_minmax(cu, false, min, max)) {
mid_v3_v3v3(cent, min, max);
return true;
}
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 9670a1892b0..dd1df6ef4b0 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1265,11 +1265,6 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
}
}
- /* make copy of 'undeformed" displist for texture space calculation
- * actually, it's not totally undeformed -- pre-tessellation modifiers are
- * already applied, thats how it worked for years, so keep for compatibility (sergey) */
- BKE_displist_copy(&cu->disp, dispbase);
-
if (!forOrco) {
curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal,
forRender, renderResolution);
@@ -1569,11 +1564,6 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
if ((cu->flag & CU_PATH) && !forOrco)
calc_curvepath(ob, &nubase);
- /* make copy of 'undeformed" displist for texture space calculation
- * actually, it's not totally undeformed -- pre-tessellation modifiers are
- * already applied, thats how it worked for years, so keep for compatibility (sergey) */
- BKE_displist_copy(&cu->disp, dispbase);
-
if (!forOrco)
curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal, forRender, renderResolution);
@@ -1587,7 +1577,6 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco)
{
- Curve *cu = ob->data;
ListBase *dispbase;
/* The same check for duplis as in do_makeDispListCurveTypes.
@@ -1596,7 +1585,6 @@ void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco)
if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT))
return;
- BKE_displist_free(&cu->disp);
BKE_object_free_derived_caches(ob);
if (!ob->curve_cache) {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index b730378bbe0..0694bde7b91 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -312,6 +312,11 @@ void BKE_object_free_derived_caches(Object *ob)
if (ob->curve_cache) {
BKE_displist_free(&ob->curve_cache->disp);
+ BLI_freelistN(&ob->curve_cache->bev);
+ if (ob->curve_cache->path) {
+ free_path(ob->curve_cache->path);
+ ob->curve_cache->path = NULL;
+ }
}
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 047dc3609c7..be76a8b8c88 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3414,7 +3414,6 @@ static void direct_link_curve(FileData *fd, Curve *cu)
if (cu->wordspace == 0.0f) cu->wordspace = 1.0f;
}
- cu->disp.first = cu->disp.last = NULL;
cu->editnurb = NULL;
cu->lastsel = NULL;
cu->editfont = NULL;
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index da8f86580f6..3ee83c20852 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -118,6 +118,8 @@ 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);
+
/* helper functions */
void ed_editnurb_translate_flag(struct ListBase *editnurb, short flag, const float vec[3]);
bool ed_editnurb_extrude_flag(struct EditNurb *editnurb, short flag);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index 1cf194e02c4..e978b81523f 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -137,6 +137,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)
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index def0d3cba50..caa06eb15d0 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -47,6 +47,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"
@@ -6807,3 +6808,65 @@ 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;
+ float min[3], max[3], size[3], loc[3];
+ int a;
+
+ if (ELEM(NULL, object->curve_cache, object->curve_cache->disp.first)) {
+ BKE_displist_make_curveTypes(scene, object, FALSE);
+ }
+
+ INIT_MINMAX(min, max);
+ BKE_displist_minmax(&object->curve_cache->disp, min, max);
+
+ 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;
+}
diff --git a/source/blender/makesdna/DNA_curve_types.h b/source/blender/makesdna/DNA_curve_types.h
index 0141c4b61db..24035464259 100644
--- a/source/blender/makesdna/DNA_curve_types.h
+++ b/source/blender/makesdna/DNA_curve_types.h
@@ -178,7 +178,6 @@ typedef struct Curve {
struct BoundBox *bb;
ListBase nurb; /* actual data, called splines in rna */
- ListBase disp; /* undeformed display list, used mostly for texture space calculation */
EditNurb *editnurb; /* edited data, not in file, use pointer so we can check for it */