[Bf-extensions-cvs] [838d757] master: Moved physics baking code to a new physics module.
Lukas Tönne
noreply at git.blender.org
Thu Dec 18 18:16:04 CET 2014
Commit: 838d75776d1985fa602513e1e8e063a4a4f7c0e7
Author: Lukas Tönne
Date: Thu Dec 18 18:15:33 2014 +0100
Branches: master
https://developer.blender.org/rBAC838d75776d1985fa602513e1e8e063a4a4f7c0e7
Moved physics baking code to a new physics module.
===================================================================
M object_physics_meadow/patch.py
A object_physics_meadow/physics.py
M object_physics_meadow/ui.py
===================================================================
diff --git a/object_physics_meadow/patch.py b/object_physics_meadow/patch.py
index 80f5652..b25ae5d 100644
--- a/object_physics_meadow/patch.py
+++ b/object_physics_meadow/patch.py
@@ -183,101 +183,3 @@ def make_patches(context, groundob, gridob, template_objects):
relcopies = temp_copies.get(relob, None)
if relcopies:
setattr(data, prop, relcopies[index])
-
-#-----------------------------------------------------------------------
-
-sim_modifier_types = { 'CLOTH', 'DYNAMIC_PAINT', 'FLUID_SIMULATION', 'PARTICLE_SYSTEM', 'SMOKE', 'SOFT_BODY' }
-
-# stores the enabled state of sim objects to allow toggling for bakes
-class BakeSimContext():
- def __enter__(self):
- scene = bpy.context.scene
-
- self.mod_toggles = {}
- for ob in scene.objects:
- for md in ob.modifiers:
- if md.type in sim_modifier_types:
- self.mod_toggles[(ob, md)] = (md.show_viewport, md.show_render)
-
- return self.mod_toggles
-
- def __exit__(self, exc_type, exc_value, traceback):
- scene = bpy.context.scene
-
- for ob in scene.objects:
- for md in ob.modifiers:
- if md.type in sim_modifier_types:
- if (ob, md) in self.mod_toggles:
- toggle = self.mod_toggles[(ob, md)]
- md.show_viewport = toggle[0]
- md.show_render = toggle[1]
-
-def enable_single_sim_psys(context, sim_ob, sim_psys):
- scene = context.scene
- for ob in scene.objects:
- for md in ob.modifiers:
- if md.type not in sim_modifier_types:
- continue
-
- enable = (md.type == 'PARTICLE_SYSTEM' and md.particle_system == sim_psys)
-
- md.show_viewport = enable
- md.show_render = enable
-
-def bake_psys(context, ob, psys):
- cache = psys.point_cache
- context_override = context.copy()
- context_override["point_cache"] = cache
-
- select_single_object(ob)
- curpsys = ob.particle_systems.active
- ob.particle_systems.active = psys
-
- if cache.is_baked:
- bpy.ops.ptcache.free_bake(context_override)
-
- # make sure only the active psys is enabled
- enable_single_sim_psys(context, ob, psys)
-
- bpy.ops.ptcache.bake(context_override, bake=True)
-
- # restore
- ob.particle_systems.active = curpsys
-
-def count_bakeable(context):
- num = 0
- for ob in patch_objects(context):
- for psys in ob.particle_systems:
- num += 1
- return num
-
-def bake_all(context):
- settings = _settings.get(context)
- wm = context.window_manager
-
- total_time = 0.0
- avg_time = 0.0
-
- total = count_bakeable(context)
-
- with progress.ProgressContext("Bake Blob", 0, total):
- for ob in patch_objects(context):
- for psys in ob.particle_systems:
- progress.progress_add(1)
- bake_psys(context, ob, psys)
-
-def patch_objects_rebake(context):
- settings = _settings.get(context)
- wm = context.window_manager
-
- # we disable all sim modifiers selectively to make sure only one sim has to be calculated at a time
- with BakeSimContext():
- scene = context.scene
- curframe = scene.frame_current
-
- # XXX have to set this because bake operator only bakes up to the last frame ...
- scene.frame_current = scene.frame_end
-
- bake_all(context)
-
- scene.frame_set(curframe)
diff --git a/object_physics_meadow/physics.py b/object_physics_meadow/physics.py
new file mode 100644
index 0000000..f32b985
--- /dev/null
+++ b/object_physics_meadow/physics.py
@@ -0,0 +1,124 @@
+### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+
+import bpy, time, sys
+from mathutils import *
+
+from object_physics_meadow import settings as _settings, patch
+from object_physics_meadow.util import *
+from object_physics_meadow import progress
+
+#-----------------------------------------------------------------------
+
+sim_modifier_types = { 'CLOTH', 'DYNAMIC_PAINT', 'FLUID_SIMULATION', 'PARTICLE_SYSTEM', 'SMOKE', 'SOFT_BODY' }
+
+# stores the enabled state of sim objects to allow toggling for bakes
+class BakeSimContext():
+ def __enter__(self):
+ scene = bpy.context.scene
+
+ self.mod_toggles = {}
+ for ob in scene.objects:
+ for md in ob.modifiers:
+ if md.type in sim_modifier_types:
+ self.mod_toggles[(ob, md)] = (md.show_viewport, md.show_render)
+
+ return self.mod_toggles
+
+ def __exit__(self, exc_type, exc_value, traceback):
+ scene = bpy.context.scene
+
+ for ob in scene.objects:
+ for md in ob.modifiers:
+ if md.type in sim_modifier_types:
+ if (ob, md) in self.mod_toggles:
+ toggle = self.mod_toggles[(ob, md)]
+ md.show_viewport = toggle[0]
+ md.show_render = toggle[1]
+
+def enable_single_sim_psys(context, sim_ob, sim_psys):
+ scene = context.scene
+ for ob in scene.objects:
+ for md in ob.modifiers:
+ if md.type not in sim_modifier_types:
+ continue
+
+ enable = (md.type == 'PARTICLE_SYSTEM' and md.particle_system == sim_psys)
+
+ md.show_viewport = enable
+ md.show_render = enable
+
+def bake_psys(context, ob, psys):
+ cache = psys.point_cache
+ context_override = context.copy()
+ context_override["point_cache"] = cache
+
+ select_single_object(ob)
+ curpsys = ob.particle_systems.active
+ ob.particle_systems.active = psys
+
+ if cache.is_baked:
+ bpy.ops.ptcache.free_bake(context_override)
+
+ # make sure only the active psys is enabled
+ enable_single_sim_psys(context, ob, psys)
+
+ bpy.ops.ptcache.bake(context_override, bake=True)
+
+ # restore
+ ob.particle_systems.active = curpsys
+
+def count_bakeable(context):
+ num = 0
+ for ob in patch.patch_objects(context):
+ for psys in ob.particle_systems:
+ num += 1
+ return num
+
+def bake_all(context):
+ settings = _settings.get(context)
+ wm = context.window_manager
+
+ total_time = 0.0
+ avg_time = 0.0
+
+ total = count_bakeable(context)
+
+ with progress.ProgressContext("Bake Blob", 0, total):
+ for ob in patch.patch_objects(context):
+ for psys in ob.particle_systems:
+ progress.progress_add(1)
+ bake_psys(context, ob, psys)
+
+def scene_bake_all(context):
+ settings = _settings.get(context)
+ wm = context.window_manager
+
+ # we disable all sim modifiers selectively to make sure only one sim has to be calculated at a time
+ with BakeSimContext():
+ scene = context.scene
+ curframe = scene.frame_current
+
+ # XXX have to set this because bake operator only bakes up to the last frame ...
+ scene.frame_current = scene.frame_end
+
+ bake_all(context)
+
+ scene.frame_set(curframe)
diff --git a/object_physics_meadow/ui.py b/object_physics_meadow/ui.py
index 6ee0767..ac5d64c 100644
--- a/object_physics_meadow/ui.py
+++ b/object_physics_meadow/ui.py
@@ -22,7 +22,7 @@ import bpy, os
from bpy.types import Operator, Panel
from bpy.props import *
-from object_physics_meadow import meadow, settings as _settings, patch, blob
+from object_physics_meadow import meadow, settings as _settings, patch, blob, physics
from object_physics_meadow.settings import find_meadow_object
from object_physics_meadow.util import *
from object_physics_meadow import progress
@@ -244,7 +244,7 @@ class RebakeMeadowOperator(MeadowOperatorBase, Operator):
def execute(self, context):
with ObjectSelection():
progress_baking()
- patch.patch_objects_rebake(context)
+ physics.scene_bake_all(context)
return {'FINISHED'}
More information about the Bf-extensions-cvs
mailing list