Commit: df9d4f4bff50f3467e751c697f85917a3b140c8b
Author: Kévin Dietrich
Date:   Sat May 16 11:20:29 2015 +0200
Branches: openvdb
https://developer.blender.org/rBdf9d4f4bff50f3467e751c697f85917a3b140c8b

Add an operator to update the transformation matrices of the grids.

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

M       release/scripts/startup/bl_ui/properties_physics_smoke.py
M       source/blender/blenkernel/BKE_smoke.h
M       source/blender/blenkernel/intern/smoke.c
M       source/blender/editors/object/object_intern.h
M       source/blender/editors/object/object_modifier.c
M       source/blender/editors/object/object_ops.c
M       source/blender/openvdb/intern/openvdb_smoke_export.cpp
M       source/blender/openvdb/openvdb_capi.cpp
M       source/blender/openvdb/openvdb_capi.h
M       source/blender/openvdb/openvdb_intern.h

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

diff --git a/release/scripts/startup/bl_ui/properties_physics_smoke.py 
b/release/scripts/startup/bl_ui/properties_physics_smoke.py
index 115c0ca..270f091 100644
--- a/release/scripts/startup/bl_ui/properties_physics_smoke.py
+++ b/release/scripts/startup/bl_ui/properties_physics_smoke.py
@@ -338,6 +338,7 @@ class PHYSICS_PT_smoke_openvdb(PhysicButtonsPanel, Panel):
         row.prop(domain, "frame_start")
         row.prop(domain, "frame_end")
         layout.operator("object.smoke_vdb_export")
+        layout.operator("object.smoke_vdb_transform_update")
 
 
 class PHYSICS_PT_smoke_field_weights(PhysicButtonsPanel, Panel):
diff --git a/source/blender/blenkernel/BKE_smoke.h 
b/source/blender/blenkernel/BKE_smoke.h
index 1ab6477..3045336 100644
--- a/source/blender/blenkernel/BKE_smoke.h
+++ b/source/blender/blenkernel/BKE_smoke.h
@@ -52,11 +52,19 @@ int smoke_get_data_flags(struct SmokeDomainSettings *sds);
 
 struct FluidDomainDescr get_fluid_description(struct SmokeDomainSettings *sds, 
struct Object *ob);
 
+typedef void (*update_cb)(void *, float progress, int *cancel);
+
 void smokeModifier_OpenVDB_export(struct SmokeModifierData *smd, struct Scene 
*scene,
                                   struct Object *ob, struct DerivedMesh *dm,
-                                  void (*update_cb)(void *, float progress, 
int *cancel),
+                                  update_cb update,
                                   void *update_cb_data);
 
+void smokeModifier_OpenVDB_update_transform(struct SmokeModifierData *smd,
+                                            struct Scene *scene,
+                                            struct Object *ob,
+                                            update_cb update,
+                                            void *update_cb_data);
+
 void smokeModifier_OpenVDB_import(struct SmokeModifierData *smd, struct Scene 
*scene, struct Object *ob);
 
 #endif /* __BKE_SMOKE_H__ */
diff --git a/source/blender/blenkernel/intern/smoke.c 
b/source/blender/blenkernel/intern/smoke.c
index 727b076..dc0fbf1 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -3109,8 +3109,7 @@ static void cache_filename(char *string, const char 
*path, const char *relbase,
 }
 
 void smokeModifier_OpenVDB_export(SmokeModifierData *smd, Scene *scene, Object 
*ob, DerivedMesh *dm,
-                                  void (*update_cb)(void *, float progress, 
int *cancel),
-                                  void *update_cb_data)
+                                  update_cb update, void *update_cb_data)
 {
        SmokeDomainSettings *sds = smd->domain;
        int orig_frame, fr, cancel = 0;
@@ -3133,7 +3132,7 @@ void smokeModifier_OpenVDB_export(SmokeModifierData *smd, 
Scene *scene, Object *
 
                progress = (fr - sds->startframe) / (float)sds->endframe;
 
-               update_cb(update_cb_data, progress, &cancel);
+               update(update_cb_data, progress, &cancel);
 
                if (cancel) {
                        scene->r.cfra = orig_frame;
@@ -3181,4 +3180,41 @@ void smokeModifier_OpenVDB_import(SmokeModifierData 
*smd, Scene *scene, Object *
        printf("%s\n", __func__);
 }
 
+void smokeModifier_OpenVDB_update_transform(SmokeModifierData *smd,
+                                            Scene *scene,
+                                            Object *ob,
+                                            update_cb update,
+                                            void *update_cb_data)
+{
+       SmokeDomainSettings *sds = smd->domain;
+       int orig_frame, fr, cancel = 0;
+       float progress;
+       const char *relbase = modifier_path_relbase(ob);
+       char filename[FILE_MAX];
+
+       orig_frame = scene->r.cfra;
+
+       for (fr = sds->startframe; fr <= sds->endframe; fr++) {
+               FluidDomainDescr descr = get_fluid_description(sds, ob);
+               /* smd->time is overwritten with scene->r.cfra in 
smokeModifier_process,
+                * so we can't use it here... */
+               scene->r.cfra = fr;
+
+               cache_filename(filename, sds->path, relbase, fr);
+
+               OpenVDB_update_fluid_transform(filename, descr);
+
+               progress = (fr - sds->startframe) / (float)sds->endframe;
+
+               update(update_cb_data, progress, &cancel);
+
+               if (cancel) {
+                       scene->r.cfra = orig_frame;
+                       return;
+               }
+       }
+
+       scene->r.cfra = orig_frame;
+}
+
 #endif /* WITH_SMOKE */
diff --git a/source/blender/editors/object/object_intern.h 
b/source/blender/editors/object/object_intern.h
index 89575e1..dda38f0 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -185,6 +185,7 @@ void OBJECT_OT_skin_radii_equalize(struct wmOperatorType 
*ot);
 void OBJECT_OT_skin_armature_create(struct wmOperatorType *ot);
 void OBJECT_OT_laplaciandeform_bind(struct wmOperatorType *ot);
 void OBJECT_OT_smoke_vdb_export(struct wmOperatorType *ot);
+void OBJECT_OT_smoke_vdb_transform_update(struct wmOperatorType *ot);
 
 /* object_constraint.c */
 void OBJECT_OT_constraint_add(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_modifier.c 
b/source/blender/editors/object/object_modifier.c
index 112dffe..5f0142b 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2410,3 +2410,66 @@ void OBJECT_OT_smoke_vdb_export(wmOperatorType *ot)
        /* flags */
        ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
 }
+
+static void smoke_transform_startjob(void *customdata, short *stop, short 
*do_update, float *progress)
+{
+       SmokeExportJob *sej = customdata;
+
+       sej->stop = stop;
+       sej->do_update = do_update;
+       sej->progress = progress;
+
+       G.is_break = false;
+
+       smokeModifier_OpenVDB_update_transform(sej->smd, sej->scene, sej->ob, 
sej->dm,
+                                              smoke_export_update, (void 
*)sej);
+
+       *do_update = true;
+       *stop = 0;
+}
+
+static int smoke_transform_exec(bContext *C, wmOperator *op)
+{
+       Object *ob = ED_object_active_context(C);
+       SmokeModifierData *smd = (SmokeModifierData *)modifiers_findByType(ob, 
eModifierType_Smoke);
+       Scene *scene = CTX_data_scene(C);
+       wmJob *wm_job;
+       SmokeExportJob *sej;
+
+       if (!smd) {
+               return OPERATOR_CANCELLED;
+       }
+
+       /* setup job */
+       wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, 
"OpenVDB export",
+                            WM_JOB_PROGRESS, WM_JOB_TYPE_SMOKE_EXPORT);
+
+       sej = MEM_callocN(sizeof(SmokeExportJob), "smoke export job");
+       sej->smd = smd;
+       sej->scene = scene;
+       sej->ob = ob;
+       sej->dm = ob->derivedDeform;
+
+       WM_jobs_customdata_set(wm_job, sej, smoke_export_free);
+       WM_jobs_timer(wm_job, 0.1, NC_OBJECT | ND_MODIFIER, NC_OBJECT | 
ND_MODIFIER);
+       WM_jobs_callbacks(wm_job, smoke_transform_startjob, NULL, NULL, 
smoke_export_endjob);
+
+       WM_jobs_start(CTX_wm_manager(C), wm_job);
+
+       return OPERATOR_FINISHED;
+
+       UNUSED_VARS(op);
+}
+
+void OBJECT_OT_smoke_vdb_transform_update(wmOperatorType *ot)
+{
+       ot->name = "Update transform matrix";
+       ot->description = "Update transformation matrices for all grids in the 
file";
+       ot->idname = "OBJECT_OT_smoke_vdb_transform_update";
+
+       ot->poll = ED_operator_object_active_editable;
+       ot->exec = smoke_transform_exec;
+
+       /* flags */
+       ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
+}
diff --git a/source/blender/editors/object/object_ops.c 
b/source/blender/editors/object/object_ops.c
index c60e4d1..7ecf2dc 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -246,6 +246,7 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_unlink_data);
        WM_operatortype_append(OBJECT_OT_laplaciandeform_bind);
        WM_operatortype_append(OBJECT_OT_smoke_vdb_export);
+       WM_operatortype_append(OBJECT_OT_smoke_vdb_transform_update);
 
        WM_operatortype_append(OBJECT_OT_lod_add);
        WM_operatortype_append(OBJECT_OT_lod_remove);
diff --git a/source/blender/openvdb/intern/openvdb_smoke_export.cpp 
b/source/blender/openvdb/intern/openvdb_smoke_export.cpp
index b04f283..d084552 100644
--- a/source/blender/openvdb/intern/openvdb_smoke_export.cpp
+++ b/source/blender/openvdb/intern/openvdb_smoke_export.cpp
@@ -328,4 +328,52 @@ void OpenVDB_import_fluid(FLUID_3D *fluid, WTURBULENCE 
*wt, FluidDomainDescr *de
        file.close();
 }
 
+void OpenVDB_update_fluid_transform(const char *filename, FluidDomainDescr 
descr)
+{
+       /* TODO(kevin): deduplicate this call */
+       initialize();
+
+       Mat4R obj_mat = Mat4R(
+               descr.obmat[0][0], descr.obmat[0][1], descr.obmat[0][2], 
descr.obmat[0][3],
+               descr.obmat[1][0], descr.obmat[1][1], descr.obmat[1][2], 
descr.obmat[1][3],
+               descr.obmat[2][0], descr.obmat[2][1], descr.obmat[2][2], 
descr.obmat[2][3],
+               descr.obmat[3][0], descr.obmat[3][1], descr.obmat[3][2], 
descr.obmat[3][3]);
+
+       Mat4R fluid_mat = Mat4R(
+               descr.fluidmat[0][0], descr.fluidmat[0][1], 
descr.fluidmat[0][2], descr.fluidmat[0][3],
+               descr.fluidmat[1][0], descr.fluidmat[1][1], 
descr.fluidmat[1][2], descr.fluidmat[1][3],
+               descr.fluidmat[2][0], descr.fluidmat[2][1], 
descr.fluidmat[2][2], descr.fluidmat[2][3],
+               descr.fluidmat[3][0], descr.fluidmat[3][1], 
descr.fluidmat[3][2], descr.fluidmat[3][3]);
+
+       Mat4R fluid_matBig = Mat4R(
+               descr.fluidmathigh[0][0], descr.fluidmathigh[0][1], 
descr.fluidmathigh[0][2], descr.fluidmathigh[0][3],
+               descr.fluidmathigh[1][0], descr.fluidmathigh[1][1], 
descr.fluidmathigh[1][2], descr.fluidmathigh[1][3],
+               descr.fluidmathigh[2][0], descr.fluidmathigh[2][1], 
descr.fluidmathigh[2][2], descr.fluidmathigh[2][3],
+               descr.fluidmathigh[3][0], descr.fluidmathigh[3][1], 
descr.fluidmathigh[3][2], descr.fluidmathigh[3][3]);
+
+       math::Transform::Ptr transform = 
math::Transform::createLinearTransform(fluid_mat * obj_mat);
+       math::Transform::Ptr transformBig = 
math::Transform::createLinearTransform(fluid_matBig * obj_mat);
+
+       io::File file(filename);
+       file.open();
+       GridPtrVecPtr grids = file.getGrids();
+       GridBase::Ptr grid;
+
+       for (size_t i = 0; i < grids->size(); ++i) {
+               grid = (*grids)[i];
+
+               const std::string name = grid->getName();
+               size_t found = name.find("High");
+
+               if (found != std::string::npos) {
+                       grid->setTransform(transformBig);
+               }
+               else {
+                       grid->setTransform(transform);
+               }
+       }
+
+       file.close();
+}
+
 } // namespac

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to