Changeset View
Changeset View
Standalone View
Standalone View
source/blender/modifiers/intern/MOD_meshsequencecache.c
| Show All 12 Lines | |||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup modifiers | * \ingroup modifiers | ||||
| */ | */ | ||||
| #include <string.h> | |||||
| #include "BLI_utildefines.h" | |||||
| #include "BLI_string.h" | |||||
| #include "DNA_cachefile_types.h" | #include "DNA_cachefile_types.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DNA_meshdata_types.h" | #include "DNA_meshdata_types.h" | ||||
| #include "DNA_modifier_types.h" | #include "DNA_modifier_types.h" | ||||
| #include "DNA_object_types.h" | #include "DNA_object_types.h" | ||||
| #include "DNA_scene_types.h" | #include "DNA_scene_types.h" | ||||
| #include "BKE_cachefile.h" | #include "BKE_cachefile.h" | ||||
| Show All 13 Lines | |||||
| static void initData(ModifierData *md) | static void initData(ModifierData *md) | ||||
| { | { | ||||
| MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | ||||
| mcmd->cache_file = NULL; | mcmd->cache_file = NULL; | ||||
| mcmd->object_path[0] = '\0'; | mcmd->object_path[0] = '\0'; | ||||
| mcmd->read_flag = MOD_MESHSEQ_READ_ALL; | mcmd->read_flag = MOD_MESHSEQ_READ_ALL; | ||||
| mcmd->reader = NULL; | |||||
| mcmd->reader_object_path[0] = '\0'; | |||||
| } | } | ||||
| static void copyData(const ModifierData *md, ModifierData *target, const int flag) | static void copyData(const ModifierData *md, ModifierData *target, const int flag) | ||||
| { | { | ||||
| #if 0 | #if 0 | ||||
| const MeshSeqCacheModifierData *mcmd = (const MeshSeqCacheModifierData *)md; | const MeshSeqCacheModifierData *mcmd = (const MeshSeqCacheModifierData *)md; | ||||
| #endif | #endif | ||||
| MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target; | MeshSeqCacheModifierData *tmcmd = (MeshSeqCacheModifierData *)target; | ||||
| modifier_copyData_generic(md, target, flag); | modifier_copyData_generic(md, target, flag); | ||||
| tmcmd->reader = NULL; | tmcmd->reader = NULL; | ||||
| tmcmd->reader_object_path[0] = '\0'; | |||||
| } | } | ||||
| static void freeData(ModifierData *md) | static void freeData(ModifierData *md) | ||||
| { | { | ||||
| MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | ||||
| if (mcmd->reader) { | if (mcmd->reader) { | ||||
| #ifdef WITH_ALEMBIC | mcmd->reader_object_path[0] = '\0'; | ||||
| CacheReader_free(mcmd->reader); | BKE_cachefile_reader_free(mcmd->cache_file, &mcmd->reader); | ||||
| #endif | |||||
| mcmd->reader = NULL; | |||||
| } | } | ||||
| } | } | ||||
| static bool isDisabled(const struct Scene *UNUSED(scene), | static bool isDisabled(const struct Scene *UNUSED(scene), | ||||
| ModifierData *md, | ModifierData *md, | ||||
| bool UNUSED(useRenderParams)) | bool UNUSED(useRenderParams)) | ||||
| { | { | ||||
| MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | ||||
| /* leave it up to the modifier to check the file is valid on calculation */ | /* leave it up to the modifier to check the file is valid on calculation */ | ||||
| return (mcmd->cache_file == NULL) || (mcmd->object_path[0] == '\0'); | return (mcmd->cache_file == NULL) || (mcmd->object_path[0] == '\0'); | ||||
| } | } | ||||
| static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) | static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh) | ||||
| { | { | ||||
| #ifdef WITH_ALEMBIC | #ifdef WITH_ALEMBIC | ||||
| MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md; | ||||
| /* Only used to check whether we are operating on org data or not... */ | /* Only used to check whether we are operating on org data or not... */ | ||||
| Mesh *me = (ctx->object->type == OB_MESH) ? ctx->object->data : NULL; | Mesh *me = (ctx->object->type == OB_MESH) ? ctx->object->data : NULL; | ||||
| Mesh *org_mesh = mesh; | Mesh *org_mesh = mesh; | ||||
| Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); | Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph); | ||||
| CacheFile *cache_file = mcmd->cache_file; | |||||
| const float frame = DEG_get_ctime(ctx->depsgraph); | const float frame = DEG_get_ctime(ctx->depsgraph); | ||||
| const float time = BKE_cachefile_time_offset(mcmd->cache_file, frame, FPS); | const float time = BKE_cachefile_time_offset(cache_file, frame, FPS); | ||||
| const char *err_str = NULL; | const char *err_str = NULL; | ||||
| CacheFile *cache_file = (CacheFile *)DEG_get_original_id(&mcmd->cache_file->id); | if (!mcmd->reader || !STREQ(mcmd->reader_object_path, mcmd->object_path)) { | ||||
| STRNCPY(mcmd->reader_object_path, mcmd->object_path); | |||||
| BKE_cachefile_ensure_handle(G.main, cache_file); | BKE_cachefile_reader_open(cache_file, &mcmd->reader, ctx->object, mcmd->object_path); | ||||
| if (!mcmd->reader) { | |||||
| mcmd->reader = CacheReader_open_alembic_object( | |||||
| cache_file->handle, NULL, ctx->object, mcmd->object_path); | |||||
| if (!mcmd->reader) { | if (!mcmd->reader) { | ||||
| modifier_setError(md, "Could not create Alembic reader for file %s", cache_file->filepath); | modifier_setError(md, "Could not create Alembic reader for file %s", cache_file->filepath); | ||||
| return mesh; | return mesh; | ||||
| } | } | ||||
| } | } | ||||
| if (me != NULL) { | if (me != NULL) { | ||||
| MVert *mvert = mesh->mvert; | MVert *mvert = mesh->mvert; | ||||
| ▲ Show 20 Lines • Show All 85 Lines • Show Last 20 Lines | |||||