[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [54913] trunk/blender/source/blender/ editors/armature: Code Maintenance - Splitting up Armature/ Pose Editing Files

Joshua Leung aligorith at gmail.com
Thu Feb 28 00:34:29 CET 2013


Revision: 54913
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=54913
Author:   aligorith
Date:     2013-02-27 23:34:29 +0000 (Wed, 27 Feb 2013)
Log Message:
-----------
Code Maintenance - Splitting up Armature/Pose Editing Files

This commit splits editarmature.c and poseobject.c into several files, such that
certain types of functionality are (mostly) self-contained within particular
files (instead of being mixed in with other functionality in a large file).

In particular, this was done so that:
1) Armature EditMode tools are now in the armature_*.c files only, and Pose Mode
tools in pose_*.c files only.
     - In one or two cases, this hasn't been possible as the two modes rely on
much of the same shared infrastructure.
2) The "clear loc/rot/scale" operators and pose show/hide are no longer housed
in editarmature.c
3) Selection operators, Transform operators, structural (add/delete) operators,
and supporting utilities for the modes (enter/exit/roll-calculations) are not
all interleaved in an ad-hoc manner

Notes:
* I've tried to ensure that the history of the new files has been maintained by
doing
   svn copy {editarmature.c/poseobject.c} {armature_*.c/pose_*.c}
   Unfortunately, this means that the diffs are a bit messy.
* There should be no functional/logic changes here. Just code moving around and
cosmetic comment tweaks where needed.
* #includes have largely been untouched for now, but could be cleaned up later
* CMake changes untested, but should work in theory.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/armature/CMakeLists.txt
    trunk/blender/source/blender/editors/armature/armature_intern.h

Added Paths:
-----------
    trunk/blender/source/blender/editors/armature/armature_add.c
    trunk/blender/source/blender/editors/armature/armature_edit.c
    trunk/blender/source/blender/editors/armature/armature_naming.c
    trunk/blender/source/blender/editors/armature/armature_relations.c
    trunk/blender/source/blender/editors/armature/armature_select.c
    trunk/blender/source/blender/editors/armature/armature_skinning.c
    trunk/blender/source/blender/editors/armature/armature_utils.c
    trunk/blender/source/blender/editors/armature/pose_edit.c
    trunk/blender/source/blender/editors/armature/pose_group.c
    trunk/blender/source/blender/editors/armature/pose_select.c
    trunk/blender/source/blender/editors/armature/pose_transform.c

Removed Paths:
-------------
    trunk/blender/source/blender/editors/armature/editarmature.c
    trunk/blender/source/blender/editors/armature/poseobject.c

Modified: trunk/blender/source/blender/editors/armature/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/armature/CMakeLists.txt	2013-02-27 22:48:34 UTC (rev 54912)
+++ trunk/blender/source/blender/editors/armature/CMakeLists.txt	2013-02-27 23:34:29 UTC (rev 54913)
@@ -36,16 +36,24 @@
 )
 
 set(SRC
+	armature_add.c
+	armature_edit.c
+	armature_naming.c
 	armature_ops.c
-	editarmature.c
+	armature_relations.c
+	armature_select.c
+	armature_utils.c
 	editarmature_generate.c
 	editarmature_retarget.c
 	editarmature_sketch.c
 	meshlaplacian.c
+	pose_edit.c
+	pose_group.c
+	pose_select.c
+	pose_transform.c
 	poseSlide.c
 	poseUtils.c
 	poselib.c
-	poseobject.c
 	reeb.c
 
 	BIF_generate.h

Copied: trunk/blender/source/blender/editors/armature/armature_add.c (from rev 54737, trunk/blender/source/blender/editors/armature/editarmature.c)
===================================================================
--- trunk/blender/source/blender/editors/armature/armature_add.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/armature/armature_add.c	2013-02-27 23:34:29 UTC (rev 54913)
@@ -0,0 +1,880 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, 2002-2009 full recode.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ * Operators and API's for creating bones
+ */
+
+/** \file blender/editors/armature/armature_add.c
+ *  \ingroup edarmature
+ */
+
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <math.h> 
+#include <float.h> 
+
+
+#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_modifier_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+
+#include "BKE_animsys.h"
+#include "BKE_action.h"
+#include "BKE_armature.h"
+#include "BKE_constraint.h"
+#include "BKE_context.h"
+#include "BKE_deform.h"
+#include "BKE_depsgraph.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_global.h"
+#include "BKE_idprop.h"
+#include "BKE_main.h"
+#include "BKE_object.h"
+#include "BKE_report.h"
+#include "BKE_modifier.h"
+
+#include "BIF_gl.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_armature.h"
+#include "ED_keyframing.h"
+#include "ED_object.h"
+#include "ED_screen.h"
+#include "ED_util.h"
+#include "ED_view3d.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "armature_intern.h"
+
+/* *************** Adding stuff in editmode *************** */
+
+/* default bone add, returns it selected, but without tail set */
+/* XXX should be used everywhere, now it mallocs bones still locally in functions */
+EditBone *ED_armature_edit_bone_add(bArmature *arm, const char *name)
+{
+	EditBone *bone = MEM_callocN(sizeof(EditBone), "eBone");
+	
+	BLI_strncpy(bone->name, name, sizeof(bone->name));
+	unique_editbone_name(arm->edbo, bone->name, NULL);
+	
+	BLI_addtail(arm->edbo, bone);
+	
+	bone->flag |= BONE_TIPSEL;
+	bone->weight = 1.0f;
+	bone->dist = 0.25f;
+	bone->xwidth = 0.1f;
+	bone->zwidth = 0.1f;
+	bone->ease1 = 1.0f;
+	bone->ease2 = 1.0f;
+	bone->rad_head = 0.10f;
+	bone->rad_tail = 0.05f;
+	bone->segments = 1;
+	bone->layer = arm->layer;
+	
+	return bone;
+}
+
+/* v3d and rv3d are allowed to be NULL */
+void add_primitive_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d)
+{
+	Object *obedit = scene->obedit; // XXX get from context
+	bArmature *arm = obedit->data;
+	float obmat[3][3], curs[3], viewmat[3][3], totmat[3][3], imat[3][3];
+	EditBone    *bone;
+
+	/* Get inverse point for head and orientation for tail */
+	invert_m4_m4(obedit->imat, obedit->obmat);
+	mul_v3_m4v3(curs, obedit->imat, give_cursor(scene, v3d));
+
+	if (rv3d && (U.flag & USER_ADD_VIEWALIGNED))
+		copy_m3_m4(obmat, rv3d->viewmat);
+	else unit_m3(obmat);
+	
+	copy_m3_m4(viewmat, obedit->obmat);
+	mul_m3_m3m3(totmat, obmat, viewmat);
+	invert_m3_m3(imat, totmat);
+	
+	ED_armature_deselect_all(obedit, 0);
+	
+	/* Create a bone */
+	bone = ED_armature_edit_bone_add(arm, "Bone");
+
+	arm->act_edbone = bone;
+
+	copy_v3_v3(bone->head, curs);
+	
+	if (rv3d && (U.flag & USER_ADD_VIEWALIGNED))
+		add_v3_v3v3(bone->tail, bone->head, imat[1]);   // bone with unit length 1
+	else
+		add_v3_v3v3(bone->tail, bone->head, imat[2]);   // bone with unit length 1, pointing up Z
+}
+
+
+/* previously addvert_armature */
+/* the ctrl-click method */
+static int armature_click_extrude_exec(bContext *C, wmOperator *UNUSED(op))
+{
+	View3D *v3d;
+	bArmature *arm;
+	EditBone *ebone, *newbone, *flipbone;
+	float mat[3][3], imat[3][3];
+	const float *curs;
+	int a, to_root = 0;
+	Object *obedit;
+	Scene *scene;
+
+	scene = CTX_data_scene(C);
+	v3d = CTX_wm_view3d(C);
+	obedit = CTX_data_edit_object(C);
+	arm = obedit->data;
+	
+	/* find the active or selected bone */
+	for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+		if (EBONE_VISIBLE(arm, ebone)) {
+			if (ebone->flag & BONE_TIPSEL || arm->act_edbone == ebone)
+				break;
+		}
+	}
+	
+	if (ebone == NULL) {
+		for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+			if (EBONE_VISIBLE(arm, ebone)) {
+				if (ebone->flag & BONE_ROOTSEL || arm->act_edbone == ebone)
+					break;
+			}
+		}
+		if (ebone == NULL) 
+			return OPERATOR_CANCELLED;
+		
+		to_root = 1;
+	}
+	
+	ED_armature_deselect_all(obedit, 0);
+	
+	/* we re-use code for mirror editing... */
+	flipbone = NULL;
+	if (arm->flag & ARM_MIRROR_EDIT)
+		flipbone = ED_armature_bone_get_mirrored(arm->edbo, ebone);
+
+	for (a = 0; a < 2; a++) {
+		if (a == 1) {
+			if (flipbone == NULL)
+				break;
+			else {
+				SWAP(EditBone *, flipbone, ebone);
+			}
+		}
+		
+		newbone = ED_armature_edit_bone_add(arm, ebone->name);
+		arm->act_edbone = newbone;
+		
+		if (to_root) {
+			copy_v3_v3(newbone->head, ebone->head);
+			newbone->rad_head = ebone->rad_tail;
+			newbone->parent = ebone->parent;
+		}
+		else {
+			copy_v3_v3(newbone->head, ebone->tail);
+			newbone->rad_head = ebone->rad_tail;
+			newbone->parent = ebone;
+			newbone->flag |= BONE_CONNECTED;
+		}
+		
+		curs = give_cursor(scene, v3d);
+		copy_v3_v3(newbone->tail, curs);
+		sub_v3_v3v3(newbone->tail, newbone->tail, obedit->obmat[3]);
+		
+		if (a == 1)
+			newbone->tail[0] = -newbone->tail[0];
+		
+		copy_m3_m4(mat, obedit->obmat);
+		invert_m3_m3(imat, mat);
+		mul_m3_v3(imat, newbone->tail);
+		
+		newbone->length = len_v3v3(newbone->head, newbone->tail);
+		newbone->rad_tail = newbone->length * 0.05f;
+		newbone->dist = newbone->length * 0.25f;
+		
+	}
+	
+	ED_armature_sync_selection(arm->edbo);
+
+	WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
+	
+	return OPERATOR_FINISHED;
+}
+
+static int armature_click_extrude_invoke(bContext *C, wmOperator *op, wmEvent *event)
+{
+	/* TODO most of this code is copied from set3dcursor_invoke,
+	 * it would be better to reuse code in set3dcursor_invoke */
+
+	/* temporarily change 3d cursor position */
+	Scene *scene;
+	ARegion *ar;
+	View3D *v3d;
+	float *fp, tvec[3], oldcurs[3], mval_f[2];
+	int retv;
+
+	scene = CTX_data_scene(C);
+	ar = CTX_wm_region(C);
+	v3d = CTX_wm_view3d(C);
+	
+	fp = give_cursor(scene, v3d);
+	
+	copy_v3_v3(oldcurs, fp);
+
+	VECCOPY2D(mval_f, event->mval);
+	ED_view3d_win_to_3d(ar, fp, mval_f, tvec);
+	copy_v3_v3(fp, tvec);
+
+	/* extrude to the where new cursor is and store the operation result */
+	retv = armature_click_extrude_exec(C, op);
+
+	/* restore previous 3d cursor position */
+	copy_v3_v3(fp, oldcurs);
+
+	return retv;
+}
+
+void ARMATURE_OT_click_extrude(wmOperatorType *ot)
+{
+	/* identifiers */
+	ot->name = "Click-Extrude";
+	ot->idname = "ARMATURE_OT_click_extrude";
+	ot->description = "Create a new bone going from the last selected joint to the mouse position";
+	
+	/* api callbacks */
+	ot->invoke = armature_click_extrude_invoke;
+	ot->exec = armature_click_extrude_exec;
+	ot->poll = ED_operator_editarmature;
+	
+	/* flags */
+	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+	/* props */
+}
+
+/* adds an EditBone between the nominated locations (should be in the right space) */
+EditBone *add_points_bone(Object *obedit, float head[3], float tail[3])
+{
+	EditBone *ebo;
+	
+	ebo = ED_armature_edit_bone_add(obedit->data, "Bone");
+	
+	copy_v3_v3(ebo->head, head);
+	copy_v3_v3(ebo->tail, tail);
+	
+	return ebo;
+}
+
+
+static EditBone *get_named_editbone(ListBase *edbo, char *name)
+{
+	EditBone  *eBone;
+
+	if (name) {
+		for (eBone = edbo->first; eBone; eBone = eBone->next) {
+			if (!strcmp(name, eBone->name))
+				return eBone;
+		}
+	}
+
+	return NULL;
+}
+
+/* Call this before doing any duplications
+ * */
+void preEditBoneDuplicate(ListBase *editbones)
+{
+	EditBone *eBone;
+	
+	/* clear temp */
+	for (eBone = editbones->first; eBone; eBone = eBone->next) {
+		eBone->temp = NULL;
+	}
+}
+
+/*
+ * Note: When duplicating cross objects, editbones here is the list of bones
+ * from the SOURCE object but ob is the DESTINATION object
+ * */
+void updateDuplicateSubtargetObjects(EditBone *dupBone, ListBase *editbones, Object *src_ob, Object *dst_ob)
+{
+	/* If an edit bone has been duplicated, lets
+	 * update it's constraints if the subtarget
+	 * they point to has also been duplicated
+	 */
+	EditBone     *oldtarget, *newtarget;
+	bPoseChannel *pchan;
+	bConstraint  *curcon;
+	ListBase     *conlist;
+	
+	if ( (pchan = BKE_pose_channel_verify(dst_ob->pose, dupBone->name)) ) {
+		if ( (conlist = &pchan->constraints) ) {
+			for (curcon = conlist->first; curcon; curcon = curcon->next) {
+				/* does this constraint have a subtarget in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list