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/dual_mesh.py')
-rw-r--r--mesh_tissue/dual_mesh.py92
1 files changed, 52 insertions, 40 deletions
diff --git a/mesh_tissue/dual_mesh.py b/mesh_tissue/dual_mesh.py
index 404d5ef5..c464bb6d 100644
--- a/mesh_tissue/dual_mesh.py
+++ b/mesh_tissue/dual_mesh.py
@@ -57,29 +57,40 @@ class dual_mesh_tessellated(Operator):
('QUAD', 'Quad Faces', ''),
('TRI', 'Triangles', '')],
name="Source Faces",
- description="Source polygons",
- default="QUAD",
+ description="Triangles works with any geometry." \
+ "Quad option is faster when the object has only Quads",
+ default="TRI",
options={'LIBRARY_EDITABLE'}
)
+ link_component : BoolProperty(
+ name="Editable Component",
+ default=False,
+ description="Add Component Object to the Scene"
+ )
+
def execute(self, context):
auto_layer_collection()
ob0 = context.object
name1 = "DualMesh_{}_Component".format(self.source_faces)
# Generate component
if self.source_faces == 'QUAD':
- verts = [(0.0, 0.0, 0.0), (0.0, 0.5, 0.0),
+ verts = [(1.0, 0.0, 0.0), (0.5, 0.0, 0.0),
+ (0.0, 0.0, 0.0), (0.0, 0.5, 0.0),
(0.0, 1.0, 0.0), (0.5, 1.0, 0.0),
(1.0, 1.0, 0.0), (1.0, 0.5, 0.0),
- (1.0, 0.0, 0.0), (0.5, 0.0, 0.0),
- (1/3, 1/3, 0.0), (2/3, 2/3, 0.0)]
+ (2/3, 1/3, 0.0), (1/3, 2/3, 0.0)]
edges = [(0,1), (1,2), (2,3), (3,4), (4,5), (5,6), (6,7),
(7,0), (1,8), (8,7), (3,9), (9,5), (8,9)]
faces = [(7,8,1,0), (8,9,3,2,1), (9,5,4,3), (9,8,7,6,5)]
else:
- verts = [(0.0,0.0,0.0), (0.5,0.0,0.0), (1.0,0.0,0.0), (0.0,1.0,0.0), (0.5,1.0,0.0), (1.0,1.0,0.0)]
- edges = [(0,1), (1,2), (2,5), (5,4), (4,3), (3,0), (1,4)]
- faces = [(0,1,4,3), (1,2,5,4)]
+ verts = [(0.0, 0.0, 0.0), (1.0, 0.0, 0.0),
+ (0.0, 1.0, 0.0), (1.0, 1.0, 0.0),
+ (0.5, 1/3, 0.0), (0.0, 0.5, 0.0),
+ (1.0, 0.5, 0.0), (0.5, 0.0, 0.0)]
+ edges = [(0,5), (1,7), (3,6), (2,3), (2,5), (1,6), (0,7),
+ (4,5), (4,7), (4,6)]
+ faces = [(5,0,7,4), (7,1,6,4), (3,2,5,4,6)]
# check pre-existing component
try:
@@ -94,38 +105,38 @@ class dual_mesh_tessellated(Operator):
me = bpy.data.meshes.new("Dual-Mesh") # add a new mesh
me.from_pydata(verts, edges, faces)
me.update(calc_edges=True, calc_edges_loose=True)
- if self.source_faces == 'QUAD': n_seams = 8
- else: n_seams = 6
- for i in range(n_seams): me.edges[i].use_seam = True
+ if self.source_faces == 'QUAD': seams = (0,1,2,3,4,5,6,9)
+ else: seams = (0,1,2,3,4,5,7)
+ for i in seams: me.edges[i].use_seam = True
ob1 = bpy.data.objects.new(name1, me)
- bpy.context.collection.objects.link(ob1)
# fix visualization issue
- bpy.context.view_layer.objects.active = ob1
- ob1.select_set(True)
- bpy.ops.object.editmode_toggle()
- bpy.ops.object.editmode_toggle()
- ob1.select_set(False)
- # hide component
- ob1.hide_select = True
- ob1.hide_render = True
- ob1.hide_viewport = True
+ if self.link_component:
+ context.collection.objects.link(ob1)
+ context.view_layer.objects.active = ob1
+ ob1.select_set(True)
+ bpy.ops.object.editmode_toggle()
+ bpy.ops.object.editmode_toggle()
+ ob1.select_set(False)
+ ob1.hide_render = True
ob = convert_object_to_mesh(ob0,False,False)
ob.name = 'DualMesh'
- #ob = bpy.data.objects.new("DualMesh", convert_object_to_mesh(ob0,False,False))
- #bpy.context.collection.objects.link(ob)
- #bpy.context.view_layer.objects.active = ob
- #ob.select_set(True)
+ ob.tissue.tissue_type = 'TESSELLATE'
+ ob.tissue.bool_lock = True
ob.tissue_tessellate.component = ob1
ob.tissue_tessellate.generator = ob0
ob.tissue_tessellate.gen_modifiers = self.apply_modifiers
ob.tissue_tessellate.merge = True
ob.tissue_tessellate.bool_dissolve_seams = True
- if self.source_faces == 'TRI': ob.tissue_tessellate.fill_mode = 'FAN'
- bpy.ops.object.update_tessellate()
+ if self.source_faces == 'TRI': ob.tissue_tessellate.fill_mode = 'TRI'
+ bpy.ops.object.tissue_update_tessellate()
+ ob.tissue.bool_lock = False
ob.location = ob0.location
ob.matrix_world = ob0.matrix_world
return {'FINISHED'}
+ def invoke(self, context, event):
+ return context.window_manager.invoke_props_dialog(self)
+
class dual_mesh(Operator):
bl_idname = "object.dual_mesh"
bl_label = "Convert to Dual Mesh"
@@ -151,9 +162,9 @@ class dual_mesh(Operator):
items=[
('BEAUTY', 'Beauty', 'Arrange the new triangles evenly'),
('CLIP', 'Clip',
- 'Split the polygons with an ear clipping algorithm')],
- name="Polygon Method",
- description="Method for splitting the polygons into triangles",
+ 'Split the N-gon with an ear clipping algorithm')],
+ name="N-gon Method",
+ description="Method for splitting the N-gons into triangles",
default="BEAUTY",
options={'LIBRARY_EDITABLE'}
)
@@ -172,12 +183,12 @@ class dual_mesh(Operator):
mode = context.mode
if mode == 'EDIT_MESH':
mode = 'EDIT'
- act = bpy.context.active_object
+ act = context.active_object
if mode != 'OBJECT':
sel = [act]
bpy.ops.object.mode_set(mode='OBJECT')
else:
- sel = bpy.context.selected_objects
+ sel = context.selected_objects
doneMeshes = []
for ob0 in sel:
@@ -206,7 +217,7 @@ class dual_mesh(Operator):
ob.data = ob.data.copy()
bpy.ops.object.select_all(action='DESELECT')
ob.select_set(True)
- bpy.context.view_layer.objects.active = ob0
+ context.view_layer.objects.active = ob0
bpy.ops.object.mode_set(mode='EDIT')
# prevent borders erosion
@@ -272,23 +283,23 @@ class dual_mesh(Operator):
bpy.ops.object.mode_set(mode='EDIT')
# select quad faces
- bpy.context.tool_settings.mesh_select_mode = (False, False, True)
+ context.tool_settings.mesh_select_mode = (False, False, True)
bpy.ops.mesh.select_face_by_sides(number=4, extend=False)
# deselect boundaries
bpy.ops.object.mode_set(mode='OBJECT')
for i in bound_v:
- bpy.context.active_object.data.vertices[i].select = False
+ context.active_object.data.vertices[i].select = False
for i in bound_e:
- bpy.context.active_object.data.edges[i].select = False
+ context.active_object.data.edges[i].select = False
for i in bound_p:
- bpy.context.active_object.data.polygons[i].select = False
+ context.active_object.data.polygons[i].select = False
bpy.ops.object.mode_set(mode='EDIT')
- bpy.context.tool_settings.mesh_select_mode = (False, False, True)
+ context.tool_settings.mesh_select_mode = (False, False, True)
bpy.ops.mesh.edge_face_add()
- bpy.context.tool_settings.mesh_select_mode = (True, False, False)
+ context.tool_settings.mesh_select_mode = (True, False, False)
bpy.ops.mesh.select_all(action='DESELECT')
# delete boundaries
@@ -330,11 +341,12 @@ class dual_mesh(Operator):
for o in clones:
o.data = ob.data
+ bm.free()
for o in sel:
o.select_set(True)
- bpy.context.view_layer.objects.active = act
+ context.view_layer.objects.active = act
bpy.ops.object.mode_set(mode=mode)
return {'FINISHED'}