-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleafify.py
147 lines (120 loc) · 4.18 KB
/
leafify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Author: Rojuienx <[email protected] http://github.com/rojuinex>
# Version: 0.1.0
# Date Created: December 28th, 2012
# Copyright (c) 2012, Rojuinex (See license agreement)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
# Created using Sam Hocevar's <[email protected]> Leafify Script as a refrence. #
# Original script contributed by FergusL and Aiena #
# contactable at #blenderpython @ irc.freenode.net #
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * #
bl_info = {
"name": "Leafify",
"author": "Rojuienx <[email protected]>",
"version": (0, 1, 0),
"blender": (2, 6, 5),
"location": "View3D > Tools",
"description": "Creates double sided faces. Located in toolshelf and spacebar leafify",
"warning": "Currently in Beta",
"wiki_url": "https://github.com/Rojuinex/leafify",
"tracker_url": "https://github.com/Rojuinex/leafify/issues",
"category": "Mesh"
}
import bpy
import bmesh
from mathutils import Vector
class OBJECT_OT_leafify(bpy.types.Operator):
"""Duplicates and flips selected faces to replicate dual-sided mesehs"""
bl_idname = "mesh.leafify"
bl_label = "Leafify"
bl_options = {"REGISTER", "UNDO"}
leafify_offset = bpy.props.FloatVectorProperty(
name = "Transformation Offset",
default = (0.0, 0.0, 0.0),
subtype = "TRANSLATION",
description = "Offset between faces.",
)
leafify_preflip = bpy.props.BoolProperty(
name = "Flip Original Normals",
default = True,
description = "Flip original face normals"
)
leafify_allow_zero = bpy.props.BoolProperty(
name = "Allow Zero",
default = False,
description = "Don't warn about non-zero values."
)
@classmethod
def poll(self, context):
if context.active_object == None:
return False
# TODO: Check to see if faces are selected
if context.mode == 'EDIT_MESH':
return True
return False
def draw(self, context):
col = self.layout.column()
col.label("Plese use a non-zero vector.", icon='NONE')
col.prop(self, "leafify_preflip")
col.prop(self, "leafify_offset")
col.prop(self, "leafify_allow_zero")
# end of draw
def action_common(self, context):
if self.leafify_preflip == True:
bpy.ops.mesh.flip_normals()
offset = self.leafify_offset
bpy.ops.mesh.duplicate_move(
MESH_OT_duplicate = {"mode":1},
TRANSFORM_OT_translate = {
"value": offset,
"constraint_axis": (False, False, False),
"constraint_orientation": "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),
"texture_space": False,
"release_confirm": False
}
)
bpy.ops.mesh.flip_normals()
# end of action_common
def execute(self, context):
self.action_common(context)
return {"FINISHED"}
# end of execute
def invoke(self, context, event):
self.action_common(context)
return {"FINISHED"}
# end of invoke
class LeafifyPanel(bpy.types.Panel):
"""Options for Leafify"""
bl_label = "Leafify"
bl_idname = "OBJECT_PT_leafify_props"
bl_space_type = "VIEW_3D"
bl_region_type = "TOOLS"
bl_context = "mesh_edit"
def draw(self, context):
row = self.layout.row()
row.operator("mesh.leafify", icon = "UV_VERTEXSEL")
def add_object_manual_map():
url_manual_prefix = "https://github.com/Rojuinex/leafify#"
url_manual_mapping = (
("bpy.ops.mesh.leafify", "usage"),
)
return url_manual_prefix, url_manual_mapping
def register():
bpy.utils.register_module(__name__)
bpy.utils.register_manual_map(add_object_manual_map)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.utils.unregister_manual_map(add_object_manual_map)
del bpy.types.Scene.leafify_preflip
del bpy.types.Scene.leafify_normal
del bpy.types.Scene.leafify_offset
if __name__ == "__main__":
register()