| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2011-10-23 17:52:20 +00:00
										 |  |  |  * ***** 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) 2005 by the Blender Foundation. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): Daniel Dunbar | 
					
						
							|  |  |  |  *                 Ton Roosendaal, | 
					
						
							|  |  |  |  *                 Ben Batt, | 
					
						
							|  |  |  |  *                 Brecht Van Lommel, | 
					
						
							|  |  |  |  *                 Campbell Barton | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 13:57:17 +00:00
										 |  |  | /** \file blender/modifiers/intern/MOD_hook.c
 | 
					
						
							|  |  |  |  *  \ingroup modifiers | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							| 
									
										
										
										
											2010-08-04 04:01:27 +00:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 22:33:43 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2011-09-26 18:51:10 +00:00
										 |  |  | #include "BLI_string.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "BKE_action.h"
 | 
					
						
							|  |  |  | #include "BKE_cdderivedmesh.h"
 | 
					
						
							|  |  |  | #include "BKE_modifier.h"
 | 
					
						
							|  |  |  | #include "BKE_deform.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 19:18:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 22:33:43 +00:00
										 |  |  | #include "depsgraph_private.h"
 | 
					
						
							|  |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-13 14:16:36 +00:00
										 |  |  | #include "MOD_util.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void initData(ModifierData *md)  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	hmd->force = 1.0; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void copyData(ModifierData *md, ModifierData *target) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							|  |  |  | 	HookModifierData *thmd = (HookModifierData *) target; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | 	copy_v3_v3(thmd->cent, hmd->cent); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	thmd->falloff = hmd->falloff; | 
					
						
							|  |  |  | 	thmd->force = hmd->force; | 
					
						
							|  |  |  | 	thmd->object = hmd->object; | 
					
						
							|  |  |  | 	thmd->totindex = hmd->totindex; | 
					
						
							|  |  |  | 	thmd->indexar = MEM_dupallocN(hmd->indexar); | 
					
						
							|  |  |  | 	memcpy(thmd->parentinv, hmd->parentinv, sizeof(hmd->parentinv)); | 
					
						
							| 
									
										
										
										
											2012-01-11 08:51:06 +00:00
										 |  |  | 	BLI_strncpy(thmd->name, hmd->name, sizeof(thmd->name)); | 
					
						
							|  |  |  | 	BLI_strncpy(thmd->subtarget, hmd->subtarget, sizeof(thmd->subtarget)); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-14 06:29:17 +00:00
										 |  |  | static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	HookModifierData *hmd = (HookModifierData *)md; | 
					
						
							|  |  |  | 	CustomDataMask dataMask = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* ask for vertexgroups if we need them */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (hmd->name[0]) dataMask |= CD_MASK_MDEFORMVERT; | 
					
						
							|  |  |  | 	if (hmd->indexar) dataMask |= CD_MASK_ORIGINDEX; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return dataMask; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void freeData(ModifierData *md) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (hmd->indexar) MEM_freeN(hmd->indexar); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-02 03:59:19 +00:00
										 |  |  | static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return !hmd->object; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void foreachObjectLink( | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  |         ModifierData *md, Object *ob, | 
					
						
							|  |  |  |         void (*walk)(void *userData, Object *ob, Object **obpoin), | 
					
						
							|  |  |  |         void *userData) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	walk(userData, ob, &hmd->object); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-14 06:29:17 +00:00
										 |  |  | static void updateDepgraph(ModifierData *md, DagForest *forest, | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  |                            struct Scene *UNUSED(scene), | 
					
						
							|  |  |  |                            Object *UNUSED(ob), | 
					
						
							|  |  |  |                            DagNode *obNode) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (hmd->object) { | 
					
						
							|  |  |  | 		DagNode *curNode = dag_get_node(forest, hmd->object); | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		if (hmd->subtarget[0]) | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 			dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Hook Modifier"); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, "Hook Modifier"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 08:29:20 +00:00
										 |  |  | static float hook_falloff(const float co_1[3], const float co_2[3], const float falloff_squared, float fac) | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (falloff_squared) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 		float len_squared = len_squared_v3v3(co_1, co_2); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		if (len_squared > falloff_squared) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 			return 0.0f; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		else if (len_squared > 0.0f) { | 
					
						
							| 
									
										
										
										
											2011-03-27 13:49:53 +00:00
										 |  |  | 			return fac * (1.0f - (len_squared / falloff_squared)); | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return fac; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 15:50:28 +00:00
										 |  |  | static void deformVerts_do(HookModifierData *hmd, Object *ob, DerivedMesh *dm, | 
					
						
							|  |  |  |                            float (*vertexCos)[3], int numVerts) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	bPoseChannel *pchan = BKE_pose_channel_find_name(hmd->object->pose, hmd->subtarget); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	float vec[3], mat[4][4], dmat[4][4]; | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 	int i, *index_pt; | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	const float falloff_squared = hmd->falloff * hmd->falloff; /* for faster comparisons */ | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2011-07-11 09:15:20 +00:00
										 |  |  | 	MDeformVert *dvert; | 
					
						
							|  |  |  | 	int defgrp_index, max_dvert; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	/* get world-space matrix of target, corrected for the space the verts are in */ | 
					
						
							|  |  |  | 	if (hmd->subtarget[0] && pchan) { | 
					
						
							|  |  |  | 		/* bone target if there's a matching pose-channel */ | 
					
						
							| 
									
										
										
										
											2013-05-26 18:36:25 +00:00
										 |  |  | 		mul_m4_m4m4(dmat, hmd->object->obmat, pchan->pose_mat); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* just object target */ | 
					
						
							|  |  |  | 		copy_m4_m4(dmat, hmd->object->obmat); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	invert_m4_m4(ob->imat, ob->obmat); | 
					
						
							|  |  |  | 	mul_serie_m4(mat, ob->imat, dmat, hmd->parentinv, | 
					
						
							| 
									
										
										
										
											2011-11-11 13:09:14 +00:00
										 |  |  | 	             NULL, NULL, NULL, NULL, NULL); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-11 09:15:20 +00:00
										 |  |  | 	modifier_get_vgroup(ob, dm, hmd->name, &dvert, &defgrp_index); | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	max_dvert = (dvert) ? numVerts : 0; | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Regarding index range checking below.
 | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * This should always be true and I don't generally like  | 
					
						
							|  |  |  | 	 * "paranoid" style code like this, but old files can have | 
					
						
							|  |  |  | 	 * indices that are out of range because old blender did | 
					
						
							|  |  |  | 	 * not correct them on exit editmode. - zr | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (hmd->force == 0.0f) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 		/* do nothing, avoid annoying checks in the loop */ | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	else if (hmd->indexar) { /* vertex indices? */ | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		const float fac_orig = hmd->force; | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 		float fac; | 
					
						
							|  |  |  | 		const int *origindex_ar; | 
					
						
							| 
									
										
										
										
											2011-12-10 03:37:37 +00:00
										 |  |  | 		 | 
					
						
							|  |  |  | 		/* if DerivedMesh is present and has original index data, use it */ | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 		if (dm && (origindex_ar = dm->getVertDataArray(dm, CD_ORIGINDEX))) { | 
					
						
							|  |  |  | 			for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 				if (*index_pt < numVerts) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 					int j; | 
					
						
							| 
									
										
										
										
											2011-12-10 03:37:37 +00:00
										 |  |  | 					 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 					for (j = 0; j < numVerts; j++) { | 
					
						
							|  |  |  | 						if (origindex_ar[j] == *index_pt) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 							float *co = vertexCos[j]; | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 							if ((fac = hook_falloff(hmd->cent, co, falloff_squared, fac_orig))) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 								if (dvert) | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 									fac *= defvert_find_weight(dvert + j, defgrp_index); | 
					
						
							| 
									
										
										
										
											2011-12-10 03:37:37 +00:00
										 |  |  | 								 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 								if (fac) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 									mul_v3_m4v3(vec, mat, co); | 
					
						
							|  |  |  | 									interp_v3_v3v3(co, co, vec, fac); | 
					
						
							|  |  |  | 								} | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 							} | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 		else { /* missing dm or ORIGINDEX */ | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 			for (i = 0, index_pt = hmd->indexar; i < hmd->totindex; i++, index_pt++) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 				if (*index_pt < numVerts) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 					float *co = vertexCos[*index_pt]; | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 					if ((fac = hook_falloff(hmd->cent, co, falloff_squared, fac_orig))) { | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 						if (dvert) | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 							fac *= defvert_find_weight(dvert + (*index_pt), defgrp_index); | 
					
						
							| 
									
										
										
										
											2011-12-10 03:37:37 +00:00
										 |  |  | 						 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 						if (fac) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 							mul_v3_m4v3(vec, mat, co); | 
					
						
							|  |  |  | 							interp_v3_v3v3(co, co, vec, fac); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	else if (dvert) {  /* vertex group hook */ | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 		const float fac_orig = hmd->force; | 
					
						
							| 
									
										
										
										
											2011-12-10 03:37:37 +00:00
										 |  |  | 		 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		for (i = 0; i < max_dvert; i++, dvert++) { | 
					
						
							| 
									
										
										
										
											2010-06-13 00:11:42 +00:00
										 |  |  | 			float fac; | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 			float *co = vertexCos[i]; | 
					
						
							| 
									
										
										
										
											2011-12-10 03:37:37 +00:00
										 |  |  | 			 | 
					
						
							| 
									
										
										
										
											2012-05-03 21:35:04 +00:00
										 |  |  | 			if ((fac = hook_falloff(hmd->cent, co, falloff_squared, fac_orig))) { | 
					
						
							| 
									
										
										
										
											2010-10-15 08:32:27 +00:00
										 |  |  | 				fac *= defvert_find_weight(dvert, defgrp_index); | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 				if (fac) { | 
					
						
							| 
									
										
										
										
											2010-06-13 00:11:42 +00:00
										 |  |  | 					mul_v3_m4v3(vec, mat, co); | 
					
						
							|  |  |  | 					interp_v3_v3v3(co, co, vec, fac); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 15:50:28 +00:00
										 |  |  | static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, | 
					
						
							|  |  |  |                         float (*vertexCos)[3], int numVerts, | 
					
						
							| 
									
										
										
										
											2012-05-09 15:00:26 +00:00
										 |  |  |                         ModifierApplyFlag UNUSED(flag)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2011-12-15 08:57:48 +00:00
										 |  |  | 	DerivedMesh *dm = derivedData; | 
					
						
							|  |  |  | 	/* We need a valid dm for meshes when a vgroup is set... */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (!dm && ob->type == OB_MESH && hmd->name[0] != '\0') | 
					
						
							| 
									
										
										
										
											2011-12-15 08:57:48 +00:00
										 |  |  | 		dm = get_dm(ob, NULL, dm, NULL, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	deformVerts_do(hmd, ob, dm, vertexCos, numVerts); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (derivedData != dm) | 
					
						
							| 
									
										
										
										
											2011-12-15 08:57:48 +00:00
										 |  |  | 		dm->release(dm); | 
					
						
							| 
									
										
										
										
											2011-12-08 15:50:28 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 17:32:37 +00:00
										 |  |  | static void deformVertsEM(ModifierData *md, Object *ob, struct BMEditMesh *editData, | 
					
						
							| 
									
										
										
										
											2011-12-08 15:50:28 +00:00
										 |  |  |                           DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	HookModifierData *hmd = (HookModifierData *) md; | 
					
						
							| 
									
										
										
										
											2011-12-15 08:57:48 +00:00
										 |  |  | 	DerivedMesh *dm = derivedData; | 
					
						
							|  |  |  | 	/* We need a valid dm for meshes when a vgroup is set... */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (!dm && ob->type == OB_MESH && hmd->name[0] != '\0') | 
					
						
							| 
									
										
										
										
											2011-12-15 08:57:48 +00:00
										 |  |  | 		dm = get_dm(ob, editData, dm, NULL, 0); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-08 15:50:28 +00:00
										 |  |  | 	deformVerts_do(hmd, ob, dm, vertexCos, numVerts); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 	if (derivedData != dm) | 
					
						
							| 
									
										
										
										
											2011-12-08 15:50:28 +00:00
										 |  |  | 		dm->release(dm); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ModifierTypeInfo modifierType_Hook = { | 
					
						
							|  |  |  | 	/* name */              "Hook", | 
					
						
							|  |  |  | 	/* structName */        "HookModifierData", | 
					
						
							|  |  |  | 	/* structSize */        sizeof(HookModifierData), | 
					
						
							|  |  |  | 	/* type */              eModifierTypeType_OnlyDeform, | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	/* flags */             eModifierTypeFlag_AcceptsCVs | | 
					
						
							|  |  |  | 	                        eModifierTypeFlag_SupportsEditmode, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* copyData */          copyData, | 
					
						
							|  |  |  | 	/* deformVerts */       deformVerts, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* deformMatrices */    NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* deformVertsEM */     deformVertsEM, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* deformMatricesEM */  NULL, | 
					
						
							|  |  |  | 	/* applyModifier */     NULL, | 
					
						
							|  |  |  | 	/* applyModifierEM */   NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* initData */          initData, | 
					
						
							|  |  |  | 	/* requiredDataMask */  requiredDataMask, | 
					
						
							|  |  |  | 	/* freeData */          freeData, | 
					
						
							|  |  |  | 	/* isDisabled */        isDisabled, | 
					
						
							|  |  |  | 	/* updateDepgraph */    updateDepgraph, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* dependsOnTime */     NULL, | 
					
						
							|  |  |  | 	/* dependsOnNormals */	NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* foreachObjectLink */ foreachObjectLink, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* foreachIDLink */     NULL, | 
					
						
							| 
									
										
										
										
											2011-08-12 18:11:22 +00:00
										 |  |  | 	/* foreachTexLink */    NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | }; |