[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58171] branches/soc-2013-depsgraph_mt: Added an operator to match texture space to object's bounding box

Sergey Sharybin sergey.vfx at gmail.com
Thu Jul 11 13:05:57 CEST 2013


Revision: 58171
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58171
Author:   nazgul
Date:     2013-07-11 11:05:56 +0000 (Thu, 11 Jul 2013)
Log Message:
-----------
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.

Modified Paths:
--------------
    branches/soc-2013-depsgraph_mt/release/scripts/startup/bl_ui/properties_data_curve.py
    branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_intern.h
    branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_ops.c
    branches/soc-2013-depsgraph_mt/source/blender/editors/curve/editcurve.c

Modified: branches/soc-2013-depsgraph_mt/release/scripts/startup/bl_ui/properties_data_curve.py
===================================================================
--- branches/soc-2013-depsgraph_mt/release/scripts/startup/bl_ui/properties_data_curve.py	2013-07-11 10:45:01 UTC (rev 58170)
+++ branches/soc-2013-depsgraph_mt/release/scripts/startup/bl_ui/properties_data_curve.py	2013-07-11 11:05:56 UTC (rev 58171)
@@ -140,7 +140,9 @@
         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"
 

Modified: branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_intern.h
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_intern.h	2013-07-11 10:45:01 UTC (rev 58170)
+++ branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_intern.h	2013-07-11 11:05:56 UTC (rev 58171)
@@ -124,5 +124,7 @@
 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 */
 

Modified: branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_ops.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_ops.c	2013-07-11 10:45:01 UTC (rev 58170)
+++ branches/soc-2013-depsgraph_mt/source/blender/editors/curve/curve_ops.c	2013-07-11 11:05:56 UTC (rev 58171)
@@ -134,6 +134,8 @@
 	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)

Modified: branches/soc-2013-depsgraph_mt/source/blender/editors/curve/editcurve.c
===================================================================
--- branches/soc-2013-depsgraph_mt/source/blender/editors/curve/editcurve.c	2013-07-11 10:45:01 UTC (rev 58170)
+++ branches/soc-2013-depsgraph_mt/source/blender/editors/curve/editcurve.c	2013-07-11 11:05:56 UTC (rev 58171)
@@ -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 @@
 
 	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;
+}




More information about the Bf-blender-cvs mailing list