Commit: 888b22bc8758e93d520644cc038d184f3131386b
Author: Kévin Dietrich
Date:   Tue May 31 04:40:56 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB888b22bc8758e93d520644cc038d184f3131386b

Add a deformVert callback to the modifier to handle curve streaming.

===================================================================

M       source/blender/alembic/ABC_alembic.h
M       source/blender/alembic/intern/alembic_capi.cc
M       source/blender/modifiers/intern/MOD_meshsequencecache.c

===================================================================

diff --git a/source/blender/alembic/ABC_alembic.h 
b/source/blender/alembic/ABC_alembic.h
index 31065c0..a9b4299 100644
--- a/source/blender/alembic/ABC_alembic.h
+++ b/source/blender/alembic/ABC_alembic.h
@@ -63,7 +63,10 @@ int ABC_check_subobject_valid(const char *filepath, const 
char *object_path);
 
 void ABC_get_transform(struct Object *ob, const char *filepath, const char 
*object_path, float r_mat[4][4], float time);
 
-struct DerivedMesh *ABC_read_mesh(const char *filepath, const char 
*object_path, const float path);
+struct DerivedMesh *ABC_read_mesh(const char *filepath, const char 
*object_path, const float time);
+
+void ABC_read_vertex_cache(const char *filepath, const char *object_path, 
const float time,
+                           float (*vertexCos)[3], int max_verts);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/alembic/intern/alembic_capi.cc 
b/source/blender/alembic/intern/alembic_capi.cc
index 54bb6b6..5363f71 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -757,8 +757,8 @@ static DerivedMesh *read_points_sample(const IObject 
&iobject, const float time)
        return dm;
 }
 
-#if 0
-DerivedMesh *read_curves_sample(const IObject &iobject, const float time)
+#if 1
+DerivedMesh *read_curves_sample(DerivedMesh *dm, const IObject &iobject, const 
float time)
 {
        ICurves points(iobject, kWrapExisting);
        ICurvesSchema schema = points.getSchema();
@@ -768,7 +768,10 @@ DerivedMesh *read_curves_sample(const IObject &iobject, 
const float time)
        const P3fArraySamplePtr &positions = sample.getPositions();
 
        const size_t num_verts = positions->size();
-       DerivedMesh *dm = CDDM_new(num_verts, 0, 0, 0, 0);
+
+       if (num_verts != dm->getNumVerts(dm)) {
+               return dm;
+       }
 
        MVert *mverts = dm->getVertArray(dm);
 
@@ -778,6 +781,26 @@ DerivedMesh *read_curves_sample(const IObject &iobject, 
const float time)
 }
 #endif
 
+void read_curves_sample(float (*vertexCos)[3], int max_verts, const IObject 
&iobject, const float time)
+{
+       ICurves points(iobject, kWrapExisting);
+       ICurvesSchema schema = points.getSchema();
+       ISampleSelector sample_sel(time);
+       const ICurvesSchema::Sample sample = schema.getValue(sample_sel);
+
+       const P3fArraySamplePtr &positions = sample.getPositions();
+
+       for (int i = 0; i < min_ff(max_verts, positions->size()); ++i) {
+               float *vert = vertexCos[i];
+               Imath::V3f pos_in = (*positions)[i];
+
+               /* Convert Y-up to Z-up. */
+               vert[0] = pos_in[0];
+               vert[1] = -pos_in[2];
+               vert[2] = pos_in[1];
+       }
+}
+
 DerivedMesh *ABC_read_mesh(const char *filepath, const char *object_path, 
const float time)
 {
        IArchive archive = open_archive(filepath);
@@ -802,11 +825,30 @@ DerivedMesh *ABC_read_mesh(const char *filepath, const 
char *object_path, const
        else if (IPoints::matches(header)) {
                return read_points_sample(iobject, time);
        }
-#if 0
-       else if (ICurves::matches(header)) {
-               return read_curves_sample(iobject, time);
-       }
-#endif
 
        return NULL;
 }
+
+void ABC_read_vertex_cache(const char *filepath, const char *object_path, 
const float time,
+                           float (*vertexCos)[3], int max_verts)
+{
+       IArchive archive = open_archive(filepath);
+
+       if (!archive.valid()) {
+               return;
+       }
+
+       IObject iobject;
+
+       find_object(archive.getTop(), iobject, object_path);
+
+       if (!iobject.valid()) {
+               return;
+       }
+
+       const Alembic::Abc::ObjectHeader &header = iobject.getHeader();
+
+       if (ICurves::matches(header)) {
+               return read_curves_sample(vertexCos, max_verts, iobject, time);
+       }
+}
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c 
b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index 4439f46..7443513 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -106,6 +106,44 @@ static DerivedMesh *applyModifier(ModifierData *md, Object 
*ob,
 #endif
 }
 
+static void deformVerts(ModifierData *md, Object *ob,
+                        DerivedMesh *derivedData,
+                        float (*vertexCos)[3],
+                        int numVerts,
+                        ModifierApplyFlag flag)
+{
+       MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
+
+       Scene *scene = md->scene;
+       const float frame = BKE_scene_frame_get(scene);
+       const float time = frame / FPS;
+
+       char filepath[1024];
+       BLI_strncpy(filepath, mcmd->filepath, 1024);
+
+       int fframe;
+       int frame_len;
+
+       if (BLI_path_frame_get(filepath, &fframe, &frame_len)) {
+               char ext[32];
+               BLI_path_frame_strip(filepath, true, ext);
+               BLI_path_frame(filepath, frame, frame_len);
+               BLI_ensure_extension(filepath, 1024, ext);
+
+               if (!BLI_exists(filepath)) {
+                       return;
+               }
+       }
+
+       ABC_read_vertex_cache(filepath,
+                             mcmd->abc_object_path,
+                          time,
+                             vertexCos,
+                             numVerts);
+
+       UNUSED_VARS(ob, derivedData, flag);
+}
+
 static bool dependsOnTime(ModifierData *md)
 {
        UNUSED_VARS(md);
@@ -116,10 +154,11 @@ ModifierTypeInfo modifierType_MeshSequenceCache = {
     /* name */              "Mesh Cache Seq",
     /* structName */        "MeshSeqCacheModifierData",
     /* structSize */        sizeof(MeshSeqCacheModifierData),
-    /* type */              eModifierTypeType_Nonconstructive,
-    /* flags */             eModifierTypeFlag_AcceptsMesh | 
eModifierTypeFlag_Single,
+    /* type */              eModifierTypeType_DeformOrConstruct,
+    /* flags */             eModifierTypeFlag_AcceptsMesh |
+                            eModifierTypeFlag_AcceptsCVs,
     /* copyData */          copyData,
-    /* deformVerts */       NULL,
+    /* deformVerts */       deformVerts,
     /* deformMatrices */    NULL,
     /* deformVertsEM */     NULL,
     /* deformMatricesEM */  NULL,

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to