| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * 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. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup modifiers | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-25 11:56:24 +01:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "BLI_math.h"
 | 
					
						
							|  |  |  | #include "BLI_path_util.h"
 | 
					
						
							|  |  |  | #include "BLI_string.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | #include "BLT_translation.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-24 04:02:30 +00:00
										 |  |  | #include "DNA_mesh_types.h"
 | 
					
						
							|  |  |  | #include "DNA_meshdata_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "DNA_object_types.h"
 | 
					
						
							|  |  |  | #include "DNA_scene_types.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | #include "DNA_screen_types.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | #include "BKE_context.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | #include "BKE_main.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-07 15:37:31 +01:00
										 |  |  | #include "BKE_mesh.h"
 | 
					
						
							|  |  |  | #include "BKE_scene.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | #include "BKE_screen.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "UI_interface.h"
 | 
					
						
							|  |  |  | #include "UI_resources.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "RNA_access.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-22 15:03:42 +02:00
										 |  |  | #include "DEG_depsgraph_query.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 16:43:04 +00:00
										 |  |  | #include "MEM_guardedalloc.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #include "MOD_meshcache_util.h" /* utility functions */
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | #include "MOD_modifiertypes.h"
 | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | #include "MOD_ui_common.h"
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static void initData(ModifierData *md) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md; | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   mcmd->flag = 0; | 
					
						
							|  |  |  |   mcmd->type = MOD_MESHCACHE_TYPE_MDD; | 
					
						
							|  |  |  |   mcmd->interp = MOD_MESHCACHE_INTERP_LINEAR; | 
					
						
							|  |  |  |   mcmd->frame_scale = 1.0f; | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   mcmd->factor = 1.0f; | 
					
						
							| 
									
										
										
										
											2013-01-21 16:43:04 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* (Y, Z). Blender default */ | 
					
						
							|  |  |  |   mcmd->forward_axis = 1; | 
					
						
							|  |  |  |   mcmd->up_axis = 2; | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-02 03:59:19 +00:00
										 |  |  | static bool dependsOnTime(ModifierData *md) | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md; | 
					
						
							|  |  |  |   return (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA); | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static bool isDisabled(const struct Scene *UNUSED(scene), | 
					
						
							|  |  |  |                        ModifierData *md, | 
					
						
							|  |  |  |                        bool UNUSED(useRenderParams)) | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md; | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /* leave it up to the modifier to check the file is valid on calculation */ | 
					
						
							|  |  |  |   return (mcmd->factor <= 0.0f) || (mcmd->filepath[0] == '\0'); | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static void meshcache_do(MeshCacheModifierData *mcmd, | 
					
						
							|  |  |  |                          Scene *scene, | 
					
						
							|  |  |  |                          Object *ob, | 
					
						
							|  |  |  |                          float (*vertexCos_Real)[3], | 
					
						
							|  |  |  |                          int numVerts) | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   const bool use_factor = mcmd->factor < 1.0f; | 
					
						
							|  |  |  |   float(*vertexCos_Store)[3] = (use_factor || | 
					
						
							|  |  |  |                                 (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ? | 
					
						
							|  |  |  |                                    MEM_malloc_arrayN( | 
					
						
							|  |  |  |                                        numVerts, sizeof(*vertexCos_Store), __func__) : | 
					
						
							|  |  |  |                                    NULL; | 
					
						
							|  |  |  |   float(*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const float fps = FPS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   char filepath[FILE_MAX]; | 
					
						
							|  |  |  |   const char *err_str = NULL; | 
					
						
							|  |  |  |   bool ok; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   float time; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  |   /* Interpret Time (the reading functions also do some of this ) */ | 
					
						
							|  |  |  |   if (mcmd->play_mode == MOD_MESHCACHE_PLAY_CFEA) { | 
					
						
							|  |  |  |     const float cfra = BKE_scene_frame_get(scene); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (mcmd->time_mode) { | 
					
						
							|  |  |  |       case MOD_MESHCACHE_TIME_FRAME: { | 
					
						
							|  |  |  |         time = cfra; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       case MOD_MESHCACHE_TIME_SECONDS: { | 
					
						
							|  |  |  |         time = cfra / fps; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       case MOD_MESHCACHE_TIME_FACTOR: | 
					
						
							|  |  |  |       default: { | 
					
						
							|  |  |  |         time = cfra / fps; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* apply offset and scale */ | 
					
						
							|  |  |  |     time = (mcmd->frame_scale * time) - mcmd->frame_start; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   else { /*  if (mcmd->play_mode == MOD_MESHCACHE_PLAY_EVAL) { */ | 
					
						
							|  |  |  |     switch (mcmd->time_mode) { | 
					
						
							|  |  |  |       case MOD_MESHCACHE_TIME_FRAME: { | 
					
						
							|  |  |  |         time = mcmd->eval_frame; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       case MOD_MESHCACHE_TIME_SECONDS: { | 
					
						
							|  |  |  |         time = mcmd->eval_time; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       case MOD_MESHCACHE_TIME_FACTOR: | 
					
						
							|  |  |  |       default: { | 
					
						
							|  |  |  |         time = mcmd->eval_factor; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  |   /* Read the File (or error out when the file is bad) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* would be nice if we could avoid doing this _every_ frame */ | 
					
						
							|  |  |  |   BLI_strncpy(filepath, mcmd->filepath, sizeof(filepath)); | 
					
						
							|  |  |  |   BLI_path_abs(filepath, ID_BLEND_PATH_FROM_GLOBAL((ID *)ob)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (mcmd->type) { | 
					
						
							|  |  |  |     case MOD_MESHCACHE_TYPE_MDD: | 
					
						
							|  |  |  |       ok = MOD_meshcache_read_mdd_times( | 
					
						
							|  |  |  |           filepath, vertexCos, numVerts, mcmd->interp, time, fps, mcmd->time_mode, &err_str); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     case MOD_MESHCACHE_TYPE_PC2: | 
					
						
							|  |  |  |       ok = MOD_meshcache_read_pc2_times( | 
					
						
							|  |  |  |           filepath, vertexCos, numVerts, mcmd->interp, time, fps, mcmd->time_mode, &err_str); | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |     default: | 
					
						
							|  |  |  |       ok = false; | 
					
						
							|  |  |  |       break; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  |   /* tricky shape key integration (slow!) */ | 
					
						
							|  |  |  |   if (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE) { | 
					
						
							|  |  |  |     Mesh *me = ob->data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* we could support any object type */ | 
					
						
							|  |  |  |     if (UNLIKELY(ob->type != OB_MESH)) { | 
					
						
							| 
									
										
										
										
											2020-05-08 10:14:02 +02:00
										 |  |  |       BKE_modifier_set_error(&mcmd->modifier, "'Integrate' only valid for Mesh objects"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (UNLIKELY(me->totvert != numVerts)) { | 
					
						
							| 
									
										
										
										
											2020-05-08 10:14:02 +02:00
										 |  |  |       BKE_modifier_set_error(&mcmd->modifier, "'Integrate' original mesh vertex mismatch"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (UNLIKELY(me->totpoly == 0)) { | 
					
						
							| 
									
										
										
										
											2020-05-08 10:14:02 +02:00
										 |  |  |       BKE_modifier_set_error(&mcmd->modifier, "'Integrate' requires faces"); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |       /* the moons align! */ | 
					
						
							|  |  |  |       int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       float(*vertexCos_Source)[3] = MEM_malloc_arrayN( | 
					
						
							|  |  |  |           numVerts, sizeof(*vertexCos_Source), __func__); | 
					
						
							|  |  |  |       float(*vertexCos_New)[3] = MEM_malloc_arrayN(numVerts, sizeof(*vertexCos_New), __func__); | 
					
						
							|  |  |  |       MVert *mv = me->mvert; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       for (i = 0; i < numVerts; i++, mv++) { | 
					
						
							|  |  |  |         copy_v3_v3(vertexCos_Source[i], mv->co); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       BKE_mesh_calc_relative_deform( | 
					
						
							|  |  |  |           me->mpoly, | 
					
						
							|  |  |  |           me->totpoly, | 
					
						
							|  |  |  |           me->mloop, | 
					
						
							|  |  |  |           me->totvert, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           (const float(*)[3])vertexCos_Source, /* from the original Mesh*/ | 
					
						
							|  |  |  |           (const float(*)[3])vertexCos_Real,   /* the input we've been given (shape keys!) */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           (const float(*)[3])vertexCos, /* the result of this modifier */ | 
					
						
							|  |  |  |           vertexCos_New                 /* the result of this function */ | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       /* write the corrected locations back into the result */ | 
					
						
							|  |  |  |       memcpy(vertexCos, vertexCos_New, sizeof(*vertexCos) * numVerts); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       MEM_freeN(vertexCos_Source); | 
					
						
							|  |  |  |       MEM_freeN(vertexCos_New); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /* -------------------------------------------------------------------- */ | 
					
						
							|  |  |  |   /* Apply the transformation matrix (if needed) */ | 
					
						
							|  |  |  |   if (UNLIKELY(err_str)) { | 
					
						
							| 
									
										
										
										
											2020-05-08 10:14:02 +02:00
										 |  |  |     BKE_modifier_set_error(&mcmd->modifier, "%s", err_str); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else if (ok) { | 
					
						
							|  |  |  |     bool use_matrix = false; | 
					
						
							|  |  |  |     float mat[3][3]; | 
					
						
							|  |  |  |     unit_m3(mat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (mat3_from_axis_conversion(mcmd->forward_axis, mcmd->up_axis, 1, 2, mat)) { | 
					
						
							|  |  |  |       use_matrix = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (mcmd->flip_axis) { | 
					
						
							|  |  |  |       float tmat[3][3]; | 
					
						
							|  |  |  |       unit_m3(tmat); | 
					
						
							| 
									
										
										
										
											2019-04-22 09:15:10 +10:00
										 |  |  |       if (mcmd->flip_axis & (1 << 0)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         tmat[0][0] = -1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:15:10 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (mcmd->flip_axis & (1 << 1)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         tmat[1][1] = -1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:15:10 +10:00
										 |  |  |       } | 
					
						
							|  |  |  |       if (mcmd->flip_axis & (1 << 2)) { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         tmat[2][2] = -1.0f; | 
					
						
							| 
									
										
										
										
											2019-04-22 09:15:10 +10:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |       mul_m3_m3m3(mat, tmat, mat); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       use_matrix = true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (use_matrix) { | 
					
						
							|  |  |  |       int i; | 
					
						
							|  |  |  |       for (i = 0; i < numVerts; i++) { | 
					
						
							|  |  |  |         mul_m3_v3(mat, vertexCos[i]); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (vertexCos_Store) { | 
					
						
							|  |  |  |     if (ok) { | 
					
						
							|  |  |  |       if (use_factor) { | 
					
						
							|  |  |  |         interp_vn_vn(*vertexCos_Real, *vertexCos_Store, mcmd->factor, numVerts * 3); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       else { | 
					
						
							|  |  |  |         memcpy(vertexCos_Real, vertexCos_Store, sizeof(*vertexCos_Store) * numVerts); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     MEM_freeN(vertexCos_Store); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static void deformVerts(ModifierData *md, | 
					
						
							|  |  |  |                         const ModifierEvalContext *ctx, | 
					
						
							|  |  |  |                         Mesh *UNUSED(mesh), | 
					
						
							|  |  |  |                         float (*vertexCos)[3], | 
					
						
							|  |  |  |                         int numVerts) | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md; | 
					
						
							|  |  |  |   Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   meshcache_do(mcmd, scene, ctx->object, vertexCos, numVerts); | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | static void deformVertsEM(ModifierData *md, | 
					
						
							|  |  |  |                           const ModifierEvalContext *ctx, | 
					
						
							|  |  |  |                           struct BMEditMesh *UNUSED(editData), | 
					
						
							|  |  |  |                           Mesh *UNUSED(mesh), | 
					
						
							|  |  |  |                           float (*vertexCos)[3], | 
					
						
							|  |  |  |                           int numVerts) | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md; | 
					
						
							|  |  |  |   Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   meshcache_do(mcmd, scene, ctx->object, vertexCos, numVerts); | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  | static void panel_draw(const bContext *UNUSED(C), Panel *panel) | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   uiLayout *layout = panel->layout; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   PointerRNA *ptr = modifier_panel_get_property_pointers(panel, NULL); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   uiLayoutSetPropSep(layout, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   uiItemR(layout, ptr, "cache_format", 0, NULL, ICON_NONE); | 
					
						
							|  |  |  |   uiItemR(layout, ptr, "filepath", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   uiItemR(layout, ptr, "factor", UI_ITEM_R_SLIDER, NULL, ICON_NONE); | 
					
						
							|  |  |  |   uiItemR(layout, ptr, "deform_mode", 0, NULL, ICON_NONE); | 
					
						
							|  |  |  |   uiItemR(layout, ptr, "interpolation", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   modifier_panel_end(layout, ptr); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  | static void time_remapping_panel_draw(const bContext *UNUSED(C), Panel *panel) | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   uiLayout *layout = panel->layout; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   PointerRNA *ptr = modifier_panel_get_property_pointers(panel, NULL); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   uiItemR(layout, ptr, "time_mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   uiLayoutSetPropSep(layout, true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   uiItemR(layout, ptr, "play_mode", UI_ITEM_R_EXPAND, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   if (RNA_enum_get(ptr, "play_mode") == MOD_MESHCACHE_PLAY_CFEA) { | 
					
						
							|  |  |  |     uiItemR(layout, ptr, "frame_start", 0, NULL, ICON_NONE); | 
					
						
							|  |  |  |     uiItemR(layout, ptr, "frame_scale", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |   } | 
					
						
							|  |  |  |   else { /* play_mode == MOD_MESHCACHE_PLAY_EVAL */ | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |     int time_mode = RNA_enum_get(ptr, "time_mode"); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |     if (time_mode == MOD_MESHCACHE_TIME_FRAME) { | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |       uiItemR(layout, ptr, "eval_frame", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (time_mode == MOD_MESHCACHE_TIME_SECONDS) { | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |       uiItemR(layout, ptr, "eval_time", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { /* time_mode == MOD_MESHCACHE_TIME_FACTOR */ | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |       uiItemR(layout, ptr, "eval_factor", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  | static void axis_mapping_panel_draw(const bContext *UNUSED(C), Panel *panel) | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | { | 
					
						
							|  |  |  |   uiLayout *col; | 
					
						
							|  |  |  |   uiLayout *layout = panel->layout; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   PointerRNA *ptr = modifier_panel_get_property_pointers(panel, NULL); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   uiLayoutSetPropSep(layout, true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   col = uiLayoutColumn(layout, true); | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   uiLayoutSetRedAlert(col, RNA_enum_get(ptr, "forward_axis") == RNA_enum_get(ptr, "up_axis")); | 
					
						
							|  |  |  |   uiItemR(col, ptr, "forward_axis", 0, NULL, ICON_NONE); | 
					
						
							|  |  |  |   uiItemR(col, ptr, "up_axis", 0, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 14:13:26 -05:00
										 |  |  |   uiItemR(layout, ptr, "flip_axis", UI_ITEM_R_EXPAND, NULL, ICON_NONE); | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void panelRegister(ARegionType *region_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   PanelType *panel_type = modifier_panel_register( | 
					
						
							|  |  |  |       region_type, eModifierType_MeshCache, panel_draw); | 
					
						
							|  |  |  |   modifier_subpanel_register(region_type, | 
					
						
							|  |  |  |                              "time_remapping", | 
					
						
							|  |  |  |                              "Time Remapping", | 
					
						
							|  |  |  |                              NULL, | 
					
						
							|  |  |  |                              time_remapping_panel_draw, | 
					
						
							|  |  |  |                              panel_type); | 
					
						
							|  |  |  |   modifier_subpanel_register( | 
					
						
							|  |  |  |       region_type, "axis_mapping", "Axis Mapping", NULL, axis_mapping_panel_draw, panel_type); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | ModifierTypeInfo modifierType_MeshCache = { | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |     /* name */ "MeshCache", | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* structName */ "MeshCacheModifierData", | 
					
						
							|  |  |  |     /* structSize */ sizeof(MeshCacheModifierData), | 
					
						
							| 
									
										
										
										
											2020-09-25 12:49:18 +02:00
										 |  |  |     /* srna */ &RNA_MeshCacheModifier, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |     /* type */ eModifierTypeType_OnlyDeform, | 
					
						
							| 
									
										
										
										
											2020-04-21 13:09:41 +02:00
										 |  |  |     /* flags */ eModifierTypeFlag_AcceptsCVs | eModifierTypeFlag_AcceptsVertexCosOnly | | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |         eModifierTypeFlag_SupportsEditmode, | 
					
						
							| 
									
										
										
										
											2020-09-25 12:45:30 +02:00
										 |  |  |     /* icon */ ICON_MOD_MESHDEFORM, /* TODO: Use correct icon. */ | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-08 10:14:02 +02:00
										 |  |  |     /* copyData */ BKE_modifier_copydata_generic, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* deformVerts */ deformVerts, | 
					
						
							|  |  |  |     /* deformMatrices */ NULL, | 
					
						
							|  |  |  |     /* deformVertsEM */ deformVertsEM, | 
					
						
							|  |  |  |     /* deformMatricesEM */ NULL, | 
					
						
							| 
									
										
										
										
											2020-04-21 13:09:41 +02:00
										 |  |  |     /* modifyMesh */ NULL, | 
					
						
							|  |  |  |     /* modifyHair */ NULL, | 
					
						
							|  |  |  |     /* modifyPointCloud */ NULL, | 
					
						
							|  |  |  |     /* modifyVolume */ NULL, | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     /* initData */ initData, | 
					
						
							|  |  |  |     /* requiredDataMask */ NULL, | 
					
						
							|  |  |  |     /* freeData */ NULL, | 
					
						
							|  |  |  |     /* isDisabled */ isDisabled, | 
					
						
							|  |  |  |     /* updateDepsgraph */ NULL, | 
					
						
							|  |  |  |     /* dependsOnTime */ dependsOnTime, | 
					
						
							|  |  |  |     /* dependsOnNormals */ NULL, | 
					
						
							|  |  |  |     /* foreachObjectLink */ NULL, | 
					
						
							|  |  |  |     /* foreachIDLink */ NULL, | 
					
						
							|  |  |  |     /* foreachTexLink */ NULL, | 
					
						
							|  |  |  |     /* freeRuntimeData */ NULL, | 
					
						
							| 
									
										
										
										
											2020-06-05 10:41:03 -04:00
										 |  |  |     /* panelRegister */ panelRegister, | 
					
						
							| 
									
										
										
										
											2020-06-15 17:37:07 +02:00
										 |  |  |     /* blendWrite */ NULL, | 
					
						
							|  |  |  |     /* blendRead */ NULL, | 
					
						
							| 
									
										
										
										
											2013-01-21 15:41:00 +00:00
										 |  |  | }; |