Improve Add Advanced Objects -> Easy Lattice
ClosedPublic

Authored by Jesse Y (deadpin) on Dec 6 2017, 6:32 AM.

Details

Reviewers
Campbell Barton (campbellbarton)
Group Reviewers
Addons
Summary

The attached patch does the following:

  • Removes broken/unused code that would attempt to delete already added easy-lattices
  • Allows the creation of multiple easy-lattices in the same scene AND for the same object (incl. support for multiple vertex groups)
  • Add scale factor so the user can create lattices smaller/larger than the target mesh
  • Add Catmull-Rom option
  • Code style (variable naming, UI naming, return values, etc.)

The code that attempted to delete lattices added by the add-on did not really work, especially in the cases where the user has changed the name of the modifier etc. Additionally, all that code prevented the usage of the add-on more than once in a given scene and more than once on a given object. These changes addresses those problems and cleans up along the way.

It also adds another property, the scale factor, allowing the user to create a lattice that is smaller or larger than the target object.

Diff Detail

Updated to fix 2 more pre-existing bugs:

  • Crashes would occur if adding an EasyLattice while in localview
  • It actually did not automatically use all vertices of the mesh if none were selected (causing a non-diagnoseable failure for the user)

I couldn't find a good example of handling the localview situation correctly. Right now I'm toggling out of localview if I detect it and then proceeding onward.

Thanks for the patch, looks good, will apply shortly.

This revision is now accepted and ready to land.Dec 6 2017, 2:40 PM

Toggling out of local mode is not maybe needed.
Something like this seems to work (code is from the object_utils)

@@ -92,12 +92,22 @@
     # the rotation comes from the combined obj world
     # matrix which was converted to euler pairs
     ob.rotation_euler = buildRot_World(obj)
-
     ob.show_x_ray = True
+
     # Link object to scene
     scn = bpy.context.scene
-    scn.objects.link(ob)
+
+    # take care of the local view, as it will crash otherwise
+    base = scn.objects.link(ob)
     scn.objects.active = ob
+
+    v3d = None
+    if bpy.context.space_data and bpy.context.space_data.type == 'VIEW_3D':
+        v3d = bpy.context.space_data
+
+    if v3d and v3d.local_view:
+        base.layers_from_view(bpy.context.space_data)
+
     scn.update()