-
Notifications
You must be signed in to change notification settings - Fork 0
/
oscurart_worn_edges_map.py
96 lines (74 loc) · 2.79 KB
/
oscurart_worn_edges_map.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
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
bl_info = {
"name": "Worn Edges",
"author": "Oscurart",
"version": (1, 2),
"blender": (2, 68, 0),
"location": "Vertex Paint > Paint > Worn Edges",
"description": "Create a Vertex Color map with Worn Edges",
"warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Paint"}
import bpy
from random import random
import bmesh
def CreateWornEdges(context, factor):
actobj = bpy.context.object
bpy.ops.object.mode_set(mode="EDIT")
bm = bmesh.from_edit_mesh(actobj.data)
sf = [(vert.calc_shell_factor() - 1.0) * factor for vert in bm.verts[:]]
bpy.ops.object.mode_set(mode="VERTEX_PAINT")
purge = {}
for ind, loop in enumerate(bpy.context.object.data.loops[:]):
if loop.vertex_index not in purge:
purge[loop.vertex_index] = [ind]
else:
purge[loop.vertex_index].append(ind)
for vert in actobj.data.vertices[:]:
if vert.select:
ran = (sf[vert.index], sf[vert.index], sf[vert.index])
for i in purge[vert.index]:
actobj.data.vertex_colors.active.data[i].color = ran
actobj.data.update()
class OscurartWorn(bpy.types.Operator):
"""Tooltip"""
bl_idname = "paint.worn_edges"
bl_label = "Worn Edges Map"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
return context.active_object is not None
factor = bpy.props.FloatProperty(name="Factor", min=.001, default=1)
def execute(self, context):
CreateWornEdges(context, self.factor)
return {'FINISHED'}
def add_osc_futurism_button(self, context):
self.layout.operator(
OscurartWorn.bl_idname,
text="Worn Edges",
icon="PLUGIN")
def register():
bpy.utils.register_class(OscurartWorn)
bpy.types.VIEW3D_MT_paint_vertex.append(add_osc_futurism_button)
def unregister():
bpy.utils.unregister_class(OscurartWorn)
bpy.types.VIEW3D_MT_paint_vertex.remove(add_osc_futurism_button)
if __name__ == '__main__':
register()