| 
									
										
										
										
											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_collision.c
 | 
					
						
							|  |  |  |  *  \ingroup modifiers | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-10 05:41:51 +00:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							| 
									
										
										
										
											2010-08-10 05:41:51 +00:00
										 |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-16 05:46:10 +00:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | #include "BLI_math.h"
 | 
					
						
							| 
									
										
										
										
											2011-01-07 18:36:47 +00:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-12 00:36:50 +00:00
										 |  |  | #include "BKE_collision.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | #include "BKE_global.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | #include "BKE_library.h"
 | 
					
						
							|  |  |  | #include "BKE_mesh.h"
 | 
					
						
							| 
									
										
										
										
											2018-06-05 15:59:53 +02:00
										 |  |  | #include "BKE_mesh_runtime.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | #include "BKE_modifier.h"
 | 
					
						
							| 
									
										
										
										
											2016-12-28 17:30:58 +01:00
										 |  |  | #include "BKE_pointcache.h"
 | 
					
						
							| 
									
										
										
										
											2010-06-27 05:39:55 +00:00
										 |  |  | #include "BKE_scene.h"
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-01 09:06:34 +10:00
										 |  |  | #include "MOD_modifiertypes.h"
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | #include "MOD_util.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "DEG_depsgraph_query.h"
 | 
					
						
							| 
									
										
										
										
											2017-08-01 09:06:34 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | static void initData(ModifierData *md) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	CollisionModifierData *collmd = (CollisionModifierData *) md; | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	collmd->x = NULL; | 
					
						
							|  |  |  | 	collmd->xnew = NULL; | 
					
						
							|  |  |  | 	collmd->current_x = NULL; | 
					
						
							|  |  |  | 	collmd->current_xnew = NULL; | 
					
						
							|  |  |  | 	collmd->current_v = NULL; | 
					
						
							| 
									
										
										
										
											2011-03-18 15:31:32 +00:00
										 |  |  | 	collmd->time_x = collmd->time_xnew = -1000; | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 	collmd->mvert_num = 0; | 
					
						
							|  |  |  | 	collmd->tri_num = 0; | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 	collmd->is_static = false; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	collmd->bvhtree = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void freeData(ModifierData *md) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	CollisionModifierData *collmd = (CollisionModifierData *) md; | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 14:21:02 +02:00
										 |  |  | 	if (collmd) {  /* Seriously? */ | 
					
						
							| 
									
										
										
										
											2015-07-30 15:43:07 +10:00
										 |  |  | 		if (collmd->bvhtree) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			BLI_bvhtree_free(collmd->bvhtree); | 
					
						
							| 
									
										
										
										
											2015-07-30 15:43:07 +10:00
										 |  |  | 			collmd->bvhtree = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MEM_SAFE_FREE(collmd->x); | 
					
						
							|  |  |  | 		MEM_SAFE_FREE(collmd->xnew); | 
					
						
							|  |  |  | 		MEM_SAFE_FREE(collmd->current_x); | 
					
						
							|  |  |  | 		MEM_SAFE_FREE(collmd->current_xnew); | 
					
						
							|  |  |  | 		MEM_SAFE_FREE(collmd->current_v); | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-08 15:04:10 +02:00
										 |  |  | 		MEM_SAFE_FREE(collmd->tri); | 
					
						
							| 
									
										
										
										
											2015-07-30 15:43:07 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-18 15:31:32 +00:00
										 |  |  | 		collmd->time_x = collmd->time_xnew = -1000; | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 		collmd->mvert_num = 0; | 
					
						
							|  |  |  | 		collmd->tri_num = 0; | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 		collmd->is_static = false; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-02 03:59:19 +00:00
										 |  |  | static bool dependsOnTime(ModifierData *UNUSED(md)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-02 03:59:19 +00:00
										 |  |  | 	return true; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-12 08:04:56 +02:00
										 |  |  | static void deformVerts( | 
					
						
							| 
									
										
										
										
											2018-05-12 08:21:07 +02:00
										 |  |  |         ModifierData *md, const ModifierEvalContext *ctx, | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  |         Mesh *mesh, | 
					
						
							| 
									
										
										
										
											2018-05-12 08:04:56 +02:00
										 |  |  |         float (*vertexCos)[3], | 
					
						
							| 
									
										
										
										
											2018-05-12 08:21:07 +02:00
										 |  |  |         int UNUSED(numVerts)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	CollisionModifierData *collmd = (CollisionModifierData *) md; | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	Mesh *mesh_src; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	MVert *tempVert = NULL; | 
					
						
							| 
									
										
										
										
											2018-05-01 17:33:04 +02:00
										 |  |  | 	Object *ob = ctx->object; | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	if (mesh == NULL) { | 
					
						
							| 
									
										
										
										
											2018-06-29 19:02:19 +02:00
										 |  |  | 		mesh_src = MOD_get_mesh_eval(ob, NULL, NULL, NULL, false, false); | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* Not possible to use get_mesh() in this case as we'll modify its vertices
 | 
					
						
							|  |  |  | 		 * and get_mesh() would return 'mesh' directly. */ | 
					
						
							|  |  |  | 		BKE_id_copy_ex( | 
					
						
							|  |  |  | 		        NULL, (ID *)mesh, (ID **)&mesh_src, | 
					
						
							|  |  |  | 		        LIB_ID_CREATE_NO_MAIN | | 
					
						
							|  |  |  | 		        LIB_ID_CREATE_NO_USER_REFCOUNT | | 
					
						
							|  |  |  | 		        LIB_ID_CREATE_NO_DEG_TAG | | 
					
						
							|  |  |  | 		        LIB_ID_COPY_NO_PREVIEW, | 
					
						
							|  |  |  | 		        false); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 	if (!ob->pd) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		printf("CollisionModifier deformVerts: Should not happen!\n"); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	if (mesh_src) { | 
					
						
							| 
									
										
										
										
											2011-02-13 03:21:27 +00:00
										 |  |  | 		float current_time = 0; | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 		unsigned int mvert_num = 0; | 
					
						
							| 
									
										
										
										
											2011-02-13 03:21:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 		BKE_mesh_apply_vert_coords(mesh_src, vertexCos); | 
					
						
							|  |  |  | 		BKE_mesh_calc_normals(mesh_src); | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:28:18 +02:00
										 |  |  | 		current_time = DEG_get_ctime(ctx->depsgraph); | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 18:21:54 +00:00
										 |  |  | 		if (G.debug_value > 0) | 
					
						
							| 
									
										
										
										
											2011-03-18 15:31:32 +00:00
										 |  |  | 			printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew); | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 		mvert_num = mesh_src->totvert; | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-22 20:47:03 +00:00
										 |  |  | 		if (current_time > collmd->time_xnew) { | 
					
						
							| 
									
										
										
										
											2011-02-13 03:21:27 +00:00
										 |  |  | 			unsigned int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 			/* check if mesh has changed */ | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 			if (collmd->x && (mvert_num != collmd->mvert_num)) | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				freeData((ModifierData *)collmd); | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-28 06:31:57 +00:00
										 |  |  | 			if (collmd->time_xnew == -1000) { /* first time */ | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 				collmd->x = MEM_dupallocN(mesh_src->mvert); /* frame start position */ | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 				for (i = 0; i < mvert_num; i++) { | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 					/* we save global positions */ | 
					
						
							| 
									
										
										
										
											2012-04-29 17:11:40 +00:00
										 |  |  | 					mul_m4_v3(ob->obmat, collmd->x[i].co); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				collmd->xnew = MEM_dupallocN(collmd->x); // frame end position
 | 
					
						
							|  |  |  | 				collmd->current_x = MEM_dupallocN(collmd->x); // inter-frame
 | 
					
						
							|  |  |  | 				collmd->current_xnew = MEM_dupallocN(collmd->x); // inter-frame
 | 
					
						
							|  |  |  | 				collmd->current_v = MEM_dupallocN(collmd->x); // inter-frame
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 				collmd->mvert_num = mvert_num; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 					const MLoop *mloop = mesh_src->mloop; | 
					
						
							|  |  |  | 					const MLoopTri *looptri = BKE_mesh_runtime_looptri_ensure(mesh_src); | 
					
						
							|  |  |  | 					collmd->tri_num = BKE_mesh_runtime_looptri_len(mesh_src); | 
					
						
							| 
									
										
										
										
											2018-01-14 22:14:20 +01:00
										 |  |  | 					MVertTri *tri = MEM_malloc_arrayN(collmd->tri_num, sizeof(*tri), __func__); | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 					BKE_mesh_runtime_verttri_from_looptri(tri, mloop, looptri, collmd->tri_num); | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 					collmd->tri = tri; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2012-02-23 21:07:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 				/* create bounding box hierarchy */ | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 				collmd->bvhtree = bvhtree_build_from_mvert( | 
					
						
							|  |  |  | 				        collmd->x, | 
					
						
							|  |  |  | 				        collmd->tri, collmd->tri_num, | 
					
						
							|  |  |  | 				        ob->pd->pdef_sboft); | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-18 15:31:32 +00:00
										 |  |  | 				collmd->time_x = collmd->time_xnew = current_time; | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 				collmd->is_static = true; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 			else if (mvert_num == collmd->mvert_num) { | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 				/* put positions to old positions */ | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				tempVert = collmd->x; | 
					
						
							|  |  |  | 				collmd->x = collmd->xnew; | 
					
						
							|  |  |  | 				collmd->xnew = tempVert; | 
					
						
							| 
									
										
										
										
											2011-03-18 15:31:32 +00:00
										 |  |  | 				collmd->time_x = collmd->time_xnew; | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 				memcpy(collmd->xnew, mesh_src->mvert, mvert_num * sizeof(MVert)); | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 				bool is_static = true; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 				for (i = 0; i < mvert_num; i++) { | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 					/* we save global positions */ | 
					
						
							| 
									
										
										
										
											2012-04-29 17:11:40 +00:00
										 |  |  | 					mul_m4_v3(ob->obmat, collmd->xnew[i].co); | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 					/* detect motion */ | 
					
						
							|  |  |  | 					is_static = is_static && equals_v3v3(collmd->x[i].co, collmd->xnew[i].co); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 				memcpy(collmd->current_xnew, collmd->x, mvert_num * sizeof(MVert)); | 
					
						
							|  |  |  | 				memcpy(collmd->current_x, collmd->x, mvert_num * sizeof(MVert)); | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				/* check if GUI setting has changed for bvh */ | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 				if (collmd->bvhtree) { | 
					
						
							| 
									
										
										
										
											2016-05-06 06:03:03 +10:00
										 |  |  | 					if (ob->pd->pdef_sboft != BLI_bvhtree_get_epsilon(collmd->bvhtree)) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 						BLI_bvhtree_free(collmd->bvhtree); | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 						collmd->bvhtree = bvhtree_build_from_mvert( | 
					
						
							|  |  |  | 						        collmd->current_x, | 
					
						
							|  |  |  | 						        collmd->tri, collmd->tri_num, | 
					
						
							|  |  |  | 						        ob->pd->pdef_sboft); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				/* happens on file load (ONLY when i decomment changes in readfile.c) */ | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 				if (!collmd->bvhtree) { | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 					collmd->bvhtree = bvhtree_build_from_mvert( | 
					
						
							|  |  |  | 					        collmd->current_x, | 
					
						
							|  |  |  | 					        collmd->tri, collmd->tri_num, | 
					
						
							|  |  |  | 					        ob->pd->pdef_sboft); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 				else if (!collmd->is_static || !is_static) { | 
					
						
							| 
									
										
										
										
											2012-07-07 22:51:57 +00:00
										 |  |  | 					/* recalc static bounding boxes */ | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 					bvhtree_update_from_mvert( | 
					
						
							|  |  |  | 					        collmd->bvhtree, | 
					
						
							|  |  |  | 					        collmd->current_x, collmd->current_xnew, | 
					
						
							|  |  |  | 					        collmd->tri, collmd->tri_num, | 
					
						
							|  |  |  | 					        true); | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-10-07 13:27:11 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				collmd->is_static = is_static; | 
					
						
							| 
									
										
										
										
											2011-03-18 15:31:32 +00:00
										 |  |  | 				collmd->time_xnew = current_time; | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 			else if (mvert_num != collmd->mvert_num) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				freeData((ModifierData *)collmd); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-24 06:24:53 +00:00
										 |  |  | 		else if (current_time < collmd->time_xnew) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 			freeData((ModifierData *)collmd); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-03-06 18:40:15 +00:00
										 |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2015-07-31 14:00:07 +10:00
										 |  |  | 			if (mvert_num != collmd->mvert_num) { | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 				freeData((ModifierData *)collmd); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-06-17 17:04:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	if (mesh_src != mesh) { | 
					
						
							|  |  |  | 		BKE_id_free(NULL, mesh_src); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ModifierTypeInfo modifierType_Collision = { | 
					
						
							|  |  |  | 	/* name */              "Collision", | 
					
						
							|  |  |  | 	/* structName */        "CollisionModifierData", | 
					
						
							|  |  |  | 	/* structSize */        sizeof(CollisionModifierData), | 
					
						
							|  |  |  | 	/* type */              eModifierTypeType_OnlyDeform, | 
					
						
							| 
									
										
										
										
											2012-05-06 13:38:33 +00:00
										 |  |  | 	/* flags */             eModifierTypeFlag_AcceptsMesh | | 
					
						
							|  |  |  | 	                        eModifierTypeFlag_Single, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* copyData */          NULL, | 
					
						
							| 
									
										
										
										
											2018-04-18 15:45:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	/* deformVerts_DM */    NULL, | 
					
						
							| 
									
										
										
										
											2018-04-18 15:45:54 +02:00
										 |  |  | 	/* deformMatrices_DM */ NULL, | 
					
						
							|  |  |  | 	/* deformVertsEM_DM */  NULL, | 
					
						
							|  |  |  | 	/* deformMatricesEM_DM*/NULL, | 
					
						
							|  |  |  | 	/* applyModifier_DM */  NULL, | 
					
						
							|  |  |  | 	/* applyModifierEM_DM */NULL, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-17 15:26:59 +02:00
										 |  |  | 	/* deformVerts */       deformVerts, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* deformMatrices */    NULL, | 
					
						
							|  |  |  | 	/* deformVertsEM */     NULL, | 
					
						
							|  |  |  | 	/* deformMatricesEM */  NULL, | 
					
						
							|  |  |  | 	/* applyModifier */     NULL, | 
					
						
							|  |  |  | 	/* applyModifierEM */   NULL, | 
					
						
							| 
									
										
										
										
											2018-04-18 15:45:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* initData */          initData, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* requiredDataMask */  NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* freeData */          freeData, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* isDisabled */        NULL, | 
					
						
							| 
									
										
											  
											
												Depsgraph: New dependency graph integration commit
This commit integrates the work done so far on the new dependency graph system,
where goal was to replace legacy depsgraph with the new one, supporting loads of
neat features like:
- More granular dependency relation nature, which solves issues with fake cycles
  in the dependencies.
- Move towards all-animatable, by better integration of drivers into the system.
- Lay down some basis for upcoming copy-on-write, overrides and so on.
The new system is living side-by-side with the previous one and disabled by
default, so nothing will become suddenly broken. The way to enable new depsgraph
is to pass `--new-depsgraph` command line argument.
It's a bit early to consider the system production-ready, there are some TODOs
and issues were discovered during the merge period, they'll be addressed ASAP.
But it's important to merge, because it's the only way to attract artists to
really start testing this system.
There are number of assorted documents related on the design of the new system:
* http://wiki.blender.org/index.php/User:Aligorith/GSoC2013_Depsgraph#Design_Documents
* http://wiki.blender.org/index.php/User:Nazg-gul/DependencyGraph
There are also some user-related information online:
* http://code.blender.org/2015/02/blender-dependency-graph-branch-for-users/
* http://code.blender.org/2015/03/more-dependency-graph-tricks/
Kudos to everyone who was involved into the project:
- Joshua "Aligorith" Leung -- design specification, initial code
- Lukas "lukas_t" Toenne -- integrating code into blender, with further fixes
- Sergey "Sergey" "Sharybin" -- some mocking around, trying to wrap up the
  project and so
- Bassam "slikdigit" Kurdali -- stressing the new system, reporting all the
  issues and recording/writing documentation.
- Everyone else who i forgot to mention here :)
											
										 
											2015-05-12 15:05:57 +05:00
										 |  |  | 	/* updateDepsgraph */   NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | 	/* dependsOnTime */     dependsOnTime, | 
					
						
							| 
									
										
										
										
											2011-03-05 10:29:10 +00:00
										 |  |  | 	/* dependsOnNormals */	NULL, | 
					
						
							|  |  |  | 	/* foreachObjectLink */ NULL, | 
					
						
							|  |  |  | 	/* foreachIDLink */     NULL, | 
					
						
							| 
									
										
										
										
											2011-08-12 18:11:22 +00:00
										 |  |  | 	/* foreachTexLink */    NULL, | 
					
						
							| 
									
										
										
										
											2010-04-11 22:12:30 +00:00
										 |  |  | }; |