Alembic export: CoW/Depsgraph fixes
authorSybren A. Stüvel <sybren@stuvel.eu>
Wed, 6 Jun 2018 13:43:10 +0000 (15:43 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Thu, 7 Jun 2018 08:48:52 +0000 (10:48 +0200)
source/blender/alembic/intern/abc_exporter.cc
source/blender/alembic/intern/abc_mesh.cc
source/blender/alembic/intern/abc_mesh.h
source/blender/alembic/intern/abc_points.cc

index dbffcb46790bc5cb603f9f5f4540d4d3cf0128de..eda3deab64dbaed6dbf61d4daa1033af181cd45e 100644 (file)
@@ -60,6 +60,8 @@ extern "C" {
 #include "BKE_modifier.h"
 #include "BKE_particle.h"
 #include "BKE_scene.h"
+
+#include "DEG_depsgraph_query.h"
 }
 
 using Alembic::Abc::TimeSamplingPtr;
@@ -381,14 +383,13 @@ void AbcExporter::createTransformWritersHierarchy(Depsgraph *depsgraph)
 
 void AbcExporter::exploreTransform(Depsgraph *depsgraph, Base *ob_base, Object *parent, Object *dupliObParent)
 {
-       Object *ob = ob_base->object;
-
        /* If an object isn't exported itself, its duplilist shouldn't be
         * exported either. */
        if (!export_object(&m_settings, ob_base, dupliObParent != NULL)) {
                return;
        }
 
+       Object *ob = DEG_get_evaluated_object(depsgraph, ob_base->object);
        if (object_type_is_exportable(m_scene, ob)) {
                createTransformWriter(depsgraph, ob, parent, dupliObParent);
        }
index 6afdccb7732a0cf3a8032c2a108ac26b028e1510..bf569916a07e7efc51512409210f312a515e133e 100644 (file)
@@ -369,7 +369,8 @@ void AbcMeshWriter::do_write()
        if (!m_first_frame && !m_is_animated)
                return;
 
-       struct Mesh *mesh = getFinalMesh();
+       bool needsfree;
+       struct Mesh *mesh = getFinalMesh(needsfree);
 
        try {
                if (m_settings.use_subdiv_schema && m_subdiv_schema.valid()) {
@@ -379,10 +380,10 @@ void AbcMeshWriter::do_write()
                        writeMesh(mesh);
                }
 
-               freeMesh(mesh);
+               if (needsfree) BKE_id_free(NULL, mesh);
        }
        catch (...) {
-               freeMesh(mesh);
+               if (needsfree) BKE_id_free(NULL, mesh);
                throw;
        }
 }
@@ -518,7 +519,7 @@ void AbcMeshWriter::writeFaceSets(struct Mesh *dm, Schema &schema)
        }
 }
 
-Mesh *AbcMeshWriter::getFinalMesh()
+Mesh *AbcMeshWriter::getFinalMesh(bool &r_needsfree)
 {
        /* We don't want subdivided mesh data */
        if (m_subsurf_mod) {
@@ -526,6 +527,7 @@ Mesh *AbcMeshWriter::getFinalMesh()
        }
 
        struct Mesh *mesh = mesh_get_eval_final(m_depsgraph, m_scene, m_object, CD_MASK_MESH);
+       r_needsfree = false;
 
        if (m_subsurf_mod) {
                m_subsurf_mod->mode &= ~eModifierMode_DisableTemporary;
@@ -546,9 +548,8 @@ Mesh *AbcMeshWriter::getFinalMesh()
                Mesh *result = BKE_bmesh_to_mesh_nomain(bm, &bmmp);
                BM_mesh_free(bm);
 
-               freeMesh(mesh);
-
                mesh = result;
+               r_needsfree = true;
        }
 
        m_custom_data_config.pack_uvs = m_settings.pack_uv;
@@ -561,11 +562,6 @@ Mesh *AbcMeshWriter::getFinalMesh()
        return mesh;
 }
 
-void AbcMeshWriter::freeMesh(struct Mesh *mesh)
-{
-       BKE_id_free(NULL, mesh);
-}
-
 void AbcMeshWriter::writeArbGeoParams(struct Mesh *dm)
 {
        if (m_is_liquid) {
index 53d1f04fd55566500116c3d848f77ca8e241f33f..ee761ec55bd47210ae0d838b4aefebe2267a3303 100644 (file)
@@ -74,8 +74,7 @@ private:
                         std::vector<int32_t> &creaseLengths,
                         std::vector<float> &creaseSharpness);
 
-       struct Mesh *getFinalMesh();
-       void freeMesh(struct Mesh *mesh);
+       struct Mesh *getFinalMesh(bool &r_needsfree);
 
        void getMaterialIndices(struct Mesh *mesh, std::vector<int32_t> &indices);
 
index c0d10ea46457786a269563e528683bd0df98a423..4200962f33ee1ed15ef81afe0a68204db6b58755 100644 (file)
@@ -40,6 +40,8 @@ extern "C" {
 #include "BKE_scene.h"
 
 #include "BLI_math.h"
+
+#include "DEG_depsgraph_query.h"
 }
 
 using Alembic::AbcGeom::kVertexScope;
@@ -102,7 +104,7 @@ void AbcPointsWriter::do_write()
                        continue;
                }
 
-               state.time = BKE_scene_frame_get(m_scene);
+               state.time = DEG_get_ctime(m_depsgraph);
 
                if (psys_get_particle_state(&sim, p, &state, 0) == 0) {
                        continue;