1 # gpl authors: Oscurart, Greg
4 "name": "Random Vertices",
5 "author": "Oscurart, Greg",
8 "location": "Object > Transform > Random Vertices",
9 "description": "Randomize selected components of active object",
16 from bpy
.types
import Operator
19 from bpy
.props
import (
26 def add_object(self
, context
, valmin
, valmax
, factor
, vgfilter
):
27 # select an option with weight map or not
28 mode
= bpy
.context
.active_object
.mode
30 objact
= bpy
.context
.active_object
35 bpy
.ops
.object.mode_set(mode
='OBJECT')
36 bpy
.ops
.object.mode_set(mode
='EDIT')
39 odata
= bmesh
.from_edit_mesh(objact
.data
)
40 odata
.select_flush(False)
42 # if the vertex is selected add to the list
43 for vertice
in odata
.verts
[:]:
45 listver
.append(vertice
.index
)
47 # If the minimum value is greater than the maximum,
48 # it adds a value to the maximum
49 if valmin
[0] >= valmax
[0]:
50 valmax
[0] = valmin
[0] + 1
52 if valmin
[1] >= valmax
[1]:
53 valmax
[1] = valmin
[1] + 1
55 if valmin
[2] >= valmax
[2]:
56 valmax
[2] = valmin
[2] + 1
58 odata
.verts
.ensure_lookup_table()
60 random_factor
= factor
61 for vertice
in listver
:
62 odata
.verts
.ensure_lookup_table()
63 if odata
.verts
[vertice
].select
:
65 has_group
= getattr(objact
.data
.vertices
[vertice
], "groups", None)
66 vertex_group
= has_group
[0] if has_group
else None
67 vertexweight
= getattr(vertex_group
, "weight", None)
69 random_factor
= factor
* vertexweight
71 random_factor
= factor
74 odata
.verts
[vertice
].co
= (
75 (((random
.randrange(valmin
[0], valmax
[0], 1)) * random_factor
) / 1000) +
76 odata
.verts
[vertice
].co
[0],
77 (((random
.randrange(valmin
[1], valmax
[1], 1)) * random_factor
) / 1000) +
78 odata
.verts
[vertice
].co
[1],
79 (((random
.randrange(valmin
[2], valmax
[2], 1)) * random_factor
) / 1000) +
80 odata
.verts
[vertice
].co
[2]
84 self
.report({'WARNING'},
85 "Some of the Selected Vertices don't have a Group with Vertex Weight assigned")
86 bpy
.ops
.object.mode_set(mode
=mode
)
89 class MESH_OT_random_vertices(Operator
):
90 bl_idname
= "mesh.random_vertices"
91 bl_label
= "Random Vertices"
92 bl_description
= ("Randomize the location of vertices by a specified\n"
93 "Multiplier Factor and random values in the defined range\n"
94 "or a multiplication of them and the Vertex Weights")
95 bl_options
= {'REGISTER', 'UNDO'}
97 vgfilter
= BoolProperty(
99 description
="Use Vertex Weight defined in the Active Group",
102 factor
= FloatProperty(
104 description
="Base Multiplier of the randomization effect",
107 valmin
= IntVectorProperty(
109 description
="Define the minimum range of randomization values",
112 valmax
= IntVectorProperty(
114 description
="Define the maximum range of randomization values",
119 def poll(cls
, context
):
120 return (context
.object and context
.object.type == "MESH" and
121 context
.mode
== "EDIT_MESH")
123 def execute(self
, context
):
124 add_object(self
, context
, self
.valmin
, self
.valmax
, self
.factor
, self
.vgfilter
)
132 bpy
.utils
.register_class(MESH_OT_random_vertices
)
136 bpy
.utils
.unregister_class(MESH_OT_random_vertices
)
139 if __name__
== '__main__':