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:
authormeta-androcto <meta.androcto1@gmail.com>2019-07-01 14:06:16 +0300
committermeta-androcto <meta.androcto1@gmail.com>2019-07-01 14:06:16 +0300
commit498d912a9d5854c0cfc1f54ed8b4216d442b89f1 (patch)
tree66e565094b4eec07c2e05c9106724ee5e4649454 /mesh_tissue/dual_mesh.py
parentfffaf5d2759d38d4166f608eab8871fcd59a7e11 (diff)
mesh_tissue: initial update 2.80
Diffstat (limited to 'mesh_tissue/dual_mesh.py')
-rw-r--r--mesh_tissue/dual_mesh.py166
1 files changed, 103 insertions, 63 deletions
diff --git a/mesh_tissue/dual_mesh.py b/mesh_tissue/dual_mesh.py
index 96f3b59b..eefd4c07 100644
--- a/mesh_tissue/dual_mesh.py
+++ b/mesh_tissue/dual_mesh.py
@@ -32,8 +32,8 @@
bl_info = {
"name": "Dual Mesh",
"author": "Alessandro Zomparelli (Co-de-iT)",
- "version": (0, 3),
- "blender": (2, 78, 0),
+ "version": (0, 4),
+ "blender": (2, 8, 0),
"location": "",
"description": "Convert a generic mesh to its dual",
"warning": "",
@@ -47,15 +47,105 @@ from bpy.props import (
EnumProperty,
)
import bmesh
+from .utils import *
+class dual_mesh_tessellated(Operator):
+ bl_idname = "object.dual_mesh_tessellated"
+ bl_label = "Dual Mesh"
+ bl_description = ("Generate a polygonal mesh using Tessellate. (Non-destructive)")
+ bl_options = {'REGISTER', 'UNDO'}
+
+ apply_modifiers : BoolProperty(
+ name="Apply Modifiers",
+ default=True,
+ description="Apply object's modifiers"
+ )
+
+ source_faces : EnumProperty(
+ items=[
+ ('QUAD', 'Quad Faces', ''),
+ ('TRI', 'Triangles', '')],
+ name="Source Faces",
+ description="Source polygons",
+ default="QUAD",
+ options={'LIBRARY_EDITABLE'}
+ )
+
+ 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),
+ (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)]
+ 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)]
+
+ # check pre-existing component
+ try:
+ _verts = [0]*len(verts)*3
+ __verts = [c for co in verts for c in co]
+ ob1 = bpy.data.objects[name1]
+ ob1.data.vertices.foreach_get("co",_verts)
+ for a, b in zip(_verts, __verts):
+ if abs(a-b) > 0.0001:
+ raise ValueError
+ except:
+ 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, calc_loop_triangles=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
+ 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
+ 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_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'
+ print(ob1)
+ print(ob0)
+ print(bpy.context.object)
+ bpy.ops.object.update_tessellate()
+ ob.location = ob0.location
+ ob.matrix_world = ob0.matrix_world
+ return {'FINISHED'}
+
class dual_mesh(Operator):
bl_idname = "object.dual_mesh"
- bl_label = "Dual Mesh"
- bl_description = ("Convert a generic mesh into a polygonal mesh")
+ bl_label = "Convert to Dual Mesh"
+ bl_description = ("Convert a generic mesh into a polygonal mesh. (Destructive)")
bl_options = {'REGISTER', 'UNDO'}
- quad_method: EnumProperty(
+ quad_method : EnumProperty(
items=[('BEAUTY', 'Beauty',
'Split the quads in nice triangles, slower method'),
('FIXED', 'Fixed',
@@ -70,7 +160,7 @@ class dual_mesh(Operator):
default="FIXED",
options={'LIBRARY_EDITABLE'}
)
- polygon_method: EnumProperty(
+ polygon_method : EnumProperty(
items=[
('BEAUTY', 'Beauty', 'Arrange the new triangles evenly'),
('CLIP', 'Clip',
@@ -80,12 +170,12 @@ class dual_mesh(Operator):
default="BEAUTY",
options={'LIBRARY_EDITABLE'}
)
- preserve_borders: BoolProperty(
+ preserve_borders : BoolProperty(
name="Preserve Borders",
default=True,
description="Preserve original borders"
)
- apply_modifiers: BoolProperty(
+ apply_modifiers : BoolProperty(
name="Apply Modifiers",
default=True,
description="Apply object's modifiers"
@@ -103,16 +193,6 @@ class dual_mesh(Operator):
sel = bpy.context.selected_objects
doneMeshes = []
- '''
- if self.new_object:
- bpy.ops.object.duplicate_move()
- for i in range(len(sel)):
- bpy.context.selected_objects[i].name = sel[i].name + "_dual"
- if sel[i] == act:
- bpy.context.scene.objects.active = bpy.context.selected_objects[i]
- sel = bpy.context.selected_objects
- '''
-
for ob0 in sel:
if ob0.type != 'MESH':
continue
@@ -153,16 +233,7 @@ class dual_mesh(Operator):
)
bpy.ops.mesh.extrude_region_move(
MESH_OT_extrude_region={"mirror": False},
- TRANSFORM_OT_translate={"value": (0, 0, 0),
- "constraint_axis": (False, False, False),
- "orient_type": 'GLOBAL', "mirror": False,
- "proportional": 'DISABLED',
- "proportional_edit_falloff": 'SMOOTH', "proportional_size": 1,
- "snap": False, "snap_target": 'CLOSEST',
- "snap_point": (0, 0, 0), "snap_align": False,
- "snap_normal": (0, 0, 0), "gpencil_strokes": False,
- "texture_space": False, "remove_on_cancel": False,
- "release_confirm": False}
+ TRANSFORM_OT_translate={"value": (0, 0, 0)}
)
bpy.ops.mesh.select_mode(
@@ -185,19 +256,21 @@ class dual_mesh(Operator):
bpy.ops.object.modifier_apply(
apply_as='DATA', modifier='dual_mesh_subsurf'
)
+
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
verts = ob.data.vertices
bpy.ops.object.mode_set(mode='OBJECT')
- verts[0].select = True
+ verts[-1].select = True
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_more(use_face_step=False)
bpy.ops.mesh.select_similar(
type='EDGE', compare='EQUAL', threshold=0.01)
bpy.ops.mesh.select_all(action='INVERT')
+
bpy.ops.mesh.dissolve_verts()
bpy.ops.mesh.select_all(action='DESELECT')
@@ -244,7 +317,7 @@ class dual_mesh(Operator):
bm = bmesh.from_edit_mesh(ob.data)
for v in bm.verts:
if len(v.link_edges) == 2 and len(v.link_faces) < 3:
- v.select_set(True)
+ v.select = True
# dissolve
bpy.ops.mesh.dissolve_verts()
@@ -280,36 +353,3 @@ class dual_mesh(Operator):
bpy.ops.object.mode_set(mode=mode)
return {'FINISHED'}
-
-
-"""
-class dual_mesh_panel(bpy.types.Panel):
- bl_label = "Dual Mesh"
- bl_category = "Tools"
- bl_space_type = "VIEW_3D"
- bl_region_type = "TOOLS"
- bl_context = "objectmode"
-
- def draw(self, context):
- layout = self.layout
- col = layout.column(align=True)
- try:
- if bpy.context.active_object.type == 'MESH':
- col.operator("object.dual_mesh")
- except:
- pass
-"""
-
-
-def register():
- bpy.utils.register_class(dual_mesh)
- # bpy.utils.register_class(dual_mesh_panel)
-
-
-def unregister():
- bpy.utils.unregister_class(dual_mesh)
- # bpy.utils.unregister_class(dual_mesh_panel)
-
-
-if __name__ == "__main__":
- register()