Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Sharybin <sergey.vfx@gmail.com>2019-05-09 12:26:49 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2019-05-16 12:49:21 +0300
commite693918d40741b0839cea84d2e0c386cc262e0c3 (patch)
tree8527faec0d6f9975aa25f0cd011046ff19db8caf /doc/python_api/examples/bpy.types.Depsgraph.5.py
parentb679887bd5f77f2cd4611a4dd77e5177de3c2326 (diff)
Dependency graph API changes
Main goal here is to make it obvious and predictable about what is going on. Summary of changes. - Access to dependency graph is now only possible to a fully evaluated graph. This is now done via context.evaluated_depsgraph_get(). The call will ensure both relations and datablocks are updated. This way we don't allow access to some known bad state of the graph, and also making explicit that getting update dependency graph is not cheap. - Access to evaluated ID is now possible via id.evaluated_get(). It was already possible to get evaluated ID via dependency graph, but that was a bit confusing why access to original is done via ID and to evaluated via depsgraph. If datablock is not covered by dependency graph it will be returned as-is. - Similarly, request for original from an ID which is not evaluated will return ID as-is. - Removed scene.update(). This is very expensive to update all the view layers. - Added depsgraph.update(). Now when temporary changes to objects are to be done, this is to happen on original object and then dependency graph is to be updated. - Changed object.to_mesh() to behave the following way: * When is used for original object modifiers are ignored. For meshes this acts similar to mesh-copy, not very useful but allows to keep code paths similar (i.e. for exporter which has Apply Modifiers option it's only matter choosing between original and evaluated object, the to_mesh() part can stay the same). For curves this gives a mesh which is constructed from displist without taking own modifiers and modifiers of bevel/taper objects into account. For metaballs this gives empty mesh. Polygonization of metaball is not possible from a single object. * When is used for evaluated object modifiers are always applied. In fact, no evaluation is happening, the mesh is either copied as-is, or constructed from current state of curve cache. Arguments to apply modifiers and calculate original coordinates (ORCO, aka undeformed coordinates) are removed. The ORCO is to be calculated as part of dependency graph evaluation. File used to regression-test (a packed Python script into .blend): {F7033464} Patch to make addons tests to pass: {F7033466} NOTE: I've included changes to FBX exporter, and those are addressing report T63689. NOTE: All the enabled-by-default addons are to be ported still, but first want to have agreement on this part of changes. NOTE: Also need to work on documentation for Python API, but, again, better be done after having agreement on this work. Reviewers: brecht, campbellbarton, mont29 Differential Revision: https://developer.blender.org/D4834
Diffstat (limited to 'doc/python_api/examples/bpy.types.Depsgraph.5.py')
-rw-r--r--doc/python_api/examples/bpy.types.Depsgraph.5.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/doc/python_api/examples/bpy.types.Depsgraph.5.py b/doc/python_api/examples/bpy.types.Depsgraph.5.py
new file mode 100644
index 00000000000..781d0202931
--- /dev/null
+++ b/doc/python_api/examples/bpy.types.Depsgraph.5.py
@@ -0,0 +1,61 @@
+"""
+Dependency graph: Simple exporter
++++++++++++++++++++++++++++++++++
+
+This example is a combination of all previous ones, and shows how to write a simple exporter
+script.
+"""
+import bpy
+
+
+class OBJECT_OT_simple_exporter(bpy.types.Operator):
+ """Simple (fake) exporter of selected objects"""
+ bl_label = "DEG Export Selected"
+ bl_idname = "object.simple_exporter"
+
+ apply_modifiers: bpy.props.BoolProperty(name="Apply Modifiers")
+
+ def execute(self, context):
+ depsgraph = context.evaluated_depsgraph_get()
+ for object_instance in depsgraph.object_instances:
+ if not self.is_object_instance_from_selected(object_instance):
+ # We only export selected objects
+ continue
+ # NOTE: This will create a mesh for every instance, which is not ideal at all. In
+ # reality destination format will support some sort of instancing mechanism, so the
+ # code here will simply say "instance this object at object_instance.matrix_world".
+ mesh = self.create_mesh_for_object_instance(object_instance)
+ if mesh is None:
+ # Happens for non-geometry objects.
+ continue
+ print(f"Exporting mesh with {len(mesh.vertices)} vertices "
+ f"at {object_instance.matrix_world}")
+ bpy.data.meshes.remove(mesh)
+
+ return {'FINISHED'}
+
+ def is_object_instance_from_selected(self, object_instance):
+ # For instanced objects we check selection of their instancer (more accurately: check
+ # selection status of the original object corresponding to the instancer).
+ if object_instance.parent:
+ return object_instance.parent.original.select_get()
+ # For non-instanced objects we check selection state of the original object.
+ return object_instance.object.original.select_get()
+
+ def create_mesh_for_object_instance(self, object_instance):
+ if self.apply_modifiers:
+ return object_instance.object.to_mesh()
+ else:
+ return object_instance.object.original.to_mesh()
+
+
+def register():
+ bpy.utils.register_class(OBJECT_OT_simple_exporter)
+
+
+def unregister():
+ bpy.utils.unregister_class(OBJECT_OT_simple_exporter)
+
+
+if __name__ == "__main__":
+ register()