[Bf-blender-cvs] [e45e593] alembic_pointcache: Support for topology changes by making the mesh cache modifier into a constructive modifier.
Lukas Tönne
noreply at git.blender.org
Tue Oct 21 20:32:19 CEST 2014
Commit: e45e593c353f286dc0694ebc88d41fc2546f8abf
Author: Lukas Tönne
Date: Fri Oct 17 17:01:52 2014 +0200
Branches: alembic_pointcache
https://developer.blender.org/rBe45e593c353f286dc0694ebc88d41fc2546f8abf
Support for topology changes by making the mesh cache modifier into a
constructive modifier.
Warning! this may well break with the deform-only file types (MDD and
PC2), so it needs careful review before considering trunk merge. In any
case, this is just a test for Alembic import.
===================================================================
M source/blender/modifiers/intern/MOD_meshcache.c
M source/blender/pointcache/intern/mesh.cpp
===================================================================
diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c
index 9520884..496911e 100644
--- a/source/blender/modifiers/intern/MOD_meshcache.c
+++ b/source/blender/modifiers/intern/MOD_meshcache.c
@@ -36,6 +36,7 @@
#include "BLI_path_util.h"
#include "BLI_math.h"
+#include "BKE_cdderivedmesh.h"
#include "BKE_DerivedMesh.h"
#include "BKE_scene.h"
#include "BKE_global.h"
@@ -53,6 +54,8 @@
#include "MOD_util.h"
+struct BMEditMesh;
+
static void initData(ModifierData *md)
{
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
@@ -102,10 +105,9 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
}
-static bool MOD_meshcache_read_alembic_times(struct PTCReader *reader,
- float (*vertexCos)[3], const int verts_tot, const char UNUSED(interp),
- const float time, const float UNUSED(fps), const char UNUSED(time_mode),
- const char **err_str)
+static DerivedMesh *MOD_meshcache_read_alembic_times(struct PTCReader *reader, const char UNUSED(interp),
+ const float time, const float UNUSED(fps), const char UNUSED(time_mode),
+ const char **err_str)
{
DerivedMesh *result;
@@ -115,39 +117,125 @@ static bool MOD_meshcache_read_alembic_times(struct PTCReader *reader,
}
result = PTC_reader_mesh_cache_acquire_result(reader);
- if (result->getNumVerts(result) != verts_tot) {
- result->needsFree = 1;
- result->release(result);
-
- *err_str = "Cache file vertex count mismatch";
- return false;
- }
- result->getVertCos(result, vertexCos);
- result->release(result);
-
- return true;
+ return result;
}
-static void meshcache_do(
- MeshCacheModifierData *mcmd, Object *ob, DerivedMesh *UNUSED(dm),
- float (*vertexCos_Real)[3], int numVerts)
+static DerivedMesh *meshcache_read_deform_cache(MeshCacheModifierData *mcmd, Object *ob, DerivedMesh *dm, float time, const char **err_str)
{
+ Scene *scene = mcmd->modifier.scene;
const bool use_factor = mcmd->factor < 1.0f;
- float (*vertexCos_Store)[3] = (use_factor || (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ?
- MEM_mallocN(sizeof(*vertexCos_Store) * numVerts, __func__) : NULL;
- float (*vertexCos)[3] = vertexCos_Store ? vertexCos_Store : vertexCos_Real;
+ const float fps = FPS;
+
+ float (*vertexCos_Real)[3], (*vertexCos_Store)[3], (*vertexCos)[3];
+ int numVerts = dm->getNumVerts(dm);
+ DerivedMesh *finaldm = NULL;
+
+ char filepath[FILE_MAX];
+ bool ok;
+
+ vertexCos_Real = MEM_mallocN(sizeof(*vertexCos_Real) * numVerts, __func__);
+ dm->getVertCos(dm, vertexCos_Real);
+
+ vertexCos_Store = (use_factor || (mcmd->deform_mode == MOD_MESHCACHE_DEFORM_INTEGRATE)) ?
+ MEM_mallocN(sizeof(*vertexCos_Store) * numVerts, __func__) : NULL;
+ vertexCos = vertexCos_Store ? vertexCos_Store : vertexCos_Real;
+
+ /* 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(G.main, (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)) {
+ modifier_setError(&mcmd->modifier, "'Integrate' only valid for Mesh objects");
+ }
+ else if (UNLIKELY(me->totvert != numVerts)) {
+ modifier_setError(&mcmd->modifier, "'Integrate' original mesh vertex mismatch");
+ }
+ else if (UNLIKELY(me->totpoly == 0)) {
+ modifier_setError(&mcmd->modifier, "'Integrate' requires faces");
+ }
+ else {
+ /* the moons align! */
+ int i;
+ float (*vertexCos_Source)[3] = MEM_mallocN(sizeof(*vertexCos_Source) * numVerts, __func__);
+ float (*vertexCos_New)[3] = MEM_mallocN(sizeof(*vertexCos_New) * numVerts, __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);
+ }
+ }
+
+ 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);
+ }
+
+ finaldm = CDDM_copy(dm);
+// dm->release(dm);
+
+ CDDM_apply_vert_coords(finaldm, vertexCos_Real);
+ MEM_freeN(vertexCos_Real);
+
+ return finaldm;
+}
+
+static DerivedMesh *meshcache_do(MeshCacheModifierData *mcmd, Object *ob, DerivedMesh *dm)
+{
Scene *scene = mcmd->modifier.scene;
const float fps = FPS;
- char filepath[FILE_MAX];
+ DerivedMesh *finaldm = NULL;
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) {
@@ -155,21 +243,15 @@ static void meshcache_do(
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 */
@@ -178,21 +260,15 @@ static void meshcache_do(
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;
- }
}
}
@@ -200,12 +276,19 @@ static void meshcache_do(
/* -------------------------------------------------------------------- */
/* 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(G.main, (ID *)ob));
-
switch (mcmd->type) {
case MOD_MESHCACHE_TYPE_MDD:
+ case MOD_MESHCACHE_TYPE_PC2:
+ finaldm = meshcache_read_deform_cache(mcmd, ob, dm, time, &err_str);
+ break;
+ case MOD_MESHCACHE_TYPE_ALEMBIC_HDF5: {
+ struct PTCReader *reader = PTC_reader_mesh_cache(scene, ob, mcmd);
+ finaldm = MOD_meshcache_read_alembic_times(reader, mcmd->interp, time, fps, mcmd->time_mode, &err_str);
+ PTC_reader_free(reader);
+ break;
+ }
+#if 0
+ case MOD_MESHCACHE_TYPE_MDD:
ok = MOD_meshcache_read_mdd_times(filepath, vertexCos, numVerts,
mcmd->interp, time, fps, mcmd->time_mode, &err_str);
break;
@@ -220,65 +303,18 @@ static void meshcache_do(
PTC_reader_free(reader);
break;
}
+#endif
default:
- ok = false;
+ finaldm = NULL;
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)) {
- modifier_setError(&mcmd->modifier, "'Integrate' only valid for Mesh objects");
- }
- else if (UNLIKELY(me->totvert != numVerts)) {
- modifier_setError(&mcmd->modifier, "'Integrate' original mesh vertex mismatch");
- }
- else if (UNLIKELY(me->totpoly == 0)) {
- modifier_setError(&mcmd->modifier, "'Integrate' requires faces");
- }
- else {
- /* the moons align! */
- int i;
-
- float (*vertexCos_Source)[3] = MEM_mallocN(sizeof(*vertexCos_Source) * numVerts, __func__);
- float (*vertexCos_New)[3] = MEM_mallocN(sizeof(*vertexCos_New) * numVerts, __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)) {
modifier_set
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list