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

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mesh_tissue/lattice.py')
-rw-r--r--mesh_tissue/lattice.py57
1 files changed, 35 insertions, 22 deletions
diff --git a/mesh_tissue/lattice.py b/mesh_tissue/lattice.py
index 296ad91a..5d9c66f0 100644
--- a/mesh_tissue/lattice.py
+++ b/mesh_tissue/lattice.py
@@ -132,7 +132,7 @@ def grid_from_mesh(mesh, swap_uv):
if len(faces_loop) == 0:
running_grid = False
-
+ bm.free()
return verts_grid, edges_grid, faces_grid
@@ -225,12 +225,20 @@ class lattice_along_surface(Operator):
soft_max=1,
description="Lattice displace"
)
+ weight_factor : FloatProperty(
+ name="Factor",
+ default=0,
+ min=0.000,
+ max=1.000,
+ precision=3,
+ description="Thickness factor to use for zero vertex group influence"
+ )
grid_object = ""
source_object = ""
@classmethod
def poll(cls, context):
- try: return bpy.context.object.mode == 'OBJECT'
+ try: return context.object.mode == 'OBJECT'
except: return False
def draw(self, context):
@@ -249,6 +257,9 @@ class lattice_along_surface(Operator):
)
row = col.row()
row.prop(self, "use_groups")
+ if self.use_groups:
+ row = col.row()
+ row.prop(self, "weight_factor")
col.separator()
col.label(text="Scale:")
col.prop(
@@ -277,16 +288,16 @@ class lattice_along_surface(Operator):
def execute(self, context):
if self.source_object == self.grid_object == "" or True:
- if len(bpy.context.selected_objects) != 2:
+ if len(context.selected_objects) != 2:
self.report({'ERROR'}, "Please, select two objects")
return {'CANCELLED'}
- grid_obj = bpy.context.object
+ grid_obj = context.object
if grid_obj.type not in ('MESH', 'CURVE', 'SURFACE'):
self.report({'ERROR'}, "The surface object is not valid. Only Mesh,"
"Curve and Surface objects are allowed.")
return {'CANCELLED'}
obj = None
- for o in bpy.context.selected_objects:
+ for o in context.selected_objects:
if o.name != grid_obj.name and o.type in \
('MESH', 'CURVE', 'SURFACE', 'FONT'):
obj = o
@@ -305,9 +316,9 @@ class lattice_along_surface(Operator):
grid_obj = bpy.data.objects[self.grid_object]
obj = bpy.data.objects[self.source_object]
obj_me = simple_to_mesh(obj)# obj.to_mesh(bpy.context.depsgraph, apply_modifiers=True)
- for o in bpy.context.selected_objects: o.select_set(False)
+ for o in context.selected_objects: o.select_set(False)
grid_obj.select_set(True)
- bpy.context.view_layer.objects.active = grid_obj
+ context.view_layer.objects.active = grid_obj
temp_grid_obj = grid_obj.copy()
temp_grid_obj.data = simple_to_mesh(grid_obj)
@@ -318,7 +329,7 @@ class lattice_along_surface(Operator):
if len(grid_mesh.polygons) > 64 * 64:
bpy.data.objects.remove(temp_grid_obj)
- bpy.context.view_layer.objects.active = obj
+ context.view_layer.objects.active = obj
obj.select_set(True)
self.report({'ERROR'}, "Maximum resolution allowed for Lattice is 64")
return {'CANCELLED'}
@@ -347,7 +358,7 @@ class lattice_along_surface(Operator):
bb = max - min
lattice_loc = (max + min) / 2
bpy.ops.object.add(type='LATTICE')
- lattice = bpy.context.active_object
+ lattice = context.active_object
lattice.location = lattice_loc
lattice.scale = Vector((bb.x / self.scale_x, bb.y / self.scale_y,
bb.z / self.scale_z))
@@ -359,16 +370,14 @@ class lattice_along_surface(Operator):
if bb.z == 0:
lattice.scale.z = 1
- bpy.context.view_layer.objects.active = obj
+ context.view_layer.objects.active = obj
bpy.ops.object.modifier_add(type='LATTICE')
obj.modifiers[-1].object = lattice
# set as parent
if self.set_parent:
- obj.select_set(True)
- lattice.select_set(True)
- bpy.context.view_layer.objects.active = lattice
- bpy.ops.object.parent_set(type='LATTICE')
+ override = {'active_object': obj, 'selected_objects' : [lattice,obj]}
+ bpy.ops.object.parent_set(override, type='OBJECT', keep_transform=False)
# reading grid structure
verts_grid, edges_grid, faces_grid = grid_from_mesh(
@@ -384,15 +393,19 @@ class lattice_along_surface(Operator):
lattice.data.points_u = nu
lattice.data.points_v = nv
lattice.data.points_w = nw
+ if self.use_groups:
+ vg = temp_grid_obj.vertex_groups.active
+ weight_factor = self.weight_factor
for i in range(nu):
for j in range(nv):
for w in range(nw):
if self.use_groups:
try:
- displace = temp_grid_obj.vertex_groups.active.weight(
- verts_grid[i][j]) * scale_normal * bb.z
+ weight_influence = vg.weight(verts_grid[i][j])
except:
- displace = 0#scale_normal * bb.z
+ weight_influence = 0
+ weight_influence = weight_influence * (1 - weight_factor) + weight_factor
+ displace = weight_influence * scale_normal * bb.z
else:
displace = scale_normal * bb.z
target_point = (grid_mesh.vertices[verts_grid[i][j]].co +
@@ -418,7 +431,7 @@ class lattice_along_surface(Operator):
lattice.select_set(True)
obj.select_set(False)
bpy.ops.object.delete(use_global=False)
- bpy.context.view_layer.objects.active = obj
+ context.view_layer.objects.active = obj
obj.select_set(True)
bpy.ops.object.modifier_remove(modifier=obj.modifiers[-1].name)
if nu > 64 or nv > 64:
@@ -433,18 +446,18 @@ class lattice_along_surface(Operator):
#lattice.select_set(False)
obj.select_set(False)
#bpy.ops.object.delete(use_global=False)
- bpy.context.view_layer.objects.active = lattice
+ context.view_layer.objects.active = lattice
lattice.select_set(True)
if self.high_quality_lattice:
- bpy.context.object.data.points_w = 8
+ context.object.data.points_w = 8
else:
- bpy.context.object.data.use_outside = True
+ context.object.data.use_outside = True
if self.hide_lattice:
bpy.ops.object.hide_view_set(unselected=False)
- bpy.context.view_layer.objects.active = obj
+ context.view_layer.objects.active = obj
obj.select_set(True)
lattice.select_set(False)