diff options
Diffstat (limited to 'release')
-rw-r--r-- | release/scripts/op/object_randomize_transform.py | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/release/scripts/op/object_randomize_transform.py b/release/scripts/op/object_randomize_transform.py index f60f25242c7..7d962892c6a 100644 --- a/release/scripts/op/object_randomize_transform.py +++ b/release/scripts/op/object_randomize_transform.py @@ -21,7 +21,7 @@ import bpy -def randomize_selected(seed, loc, rot, scale, scale_even, scale_min): +def randomize_selected(seed, delta, loc, rot, scale, scale_even): import random from random import uniform @@ -35,20 +35,31 @@ def randomize_selected(seed, loc, rot, scale, scale_even, scale_min): for obj in bpy.context.selected_objects: if loc: - obj.location += rand_vec(loc) + if delta: + obj.delta_location += rand_vec(loc) + else: + obj.location += rand_vec(loc) else: # otherwise the values change under us uniform(0.0, 0.0), uniform(0.0, 0.0), uniform(0.0, 0.0) if rot: # TODO, non euler's vec = rand_vec(rot) - obj.rotation_euler[0] += vec[0] - obj.rotation_euler[1] += vec[1] - obj.rotation_euler[2] += vec[2] + if delta: + obj.delta_rotation_euler[0] += vec[0] + obj.delta_rotation_euler[1] += vec[1] + obj.delta_rotation_euler[2] += vec[2] + else: + obj.rotation_euler[0] += vec[0] + obj.rotation_euler[1] += vec[1] + obj.rotation_euler[2] += vec[2] else: uniform(0.0, 0.0), uniform(0.0, 0.0), uniform(0.0, 0.0) if scale: - org_sca_x, org_sca_y, org_sca_z = obj.scale + if delta: + org_sca_x, org_sca_y, org_sca_z = obj.delta_scale + else: + org_sca_x, org_sca_y, org_sca_z = obj.scale if scale_even: sca_x = sca_y = sca_z = uniform(scale[0], - scale[0]) @@ -57,22 +68,15 @@ def randomize_selected(seed, loc, rot, scale, scale_even, scale_min): sca_x, sca_y, sca_z = rand_vec(scale) aX = sca_x + org_sca_x - bX = org_sca_x * scale_min aY = sca_y + org_sca_y - bY = org_sca_y * scale_min aZ = sca_z + org_sca_z - bZ = org_sca_z * scale_min - if aX < bX: - aX = bX - if aY < bY: - aY = bY - if aZ < bZ: - aZ = bZ - - obj.scale = aX, aY, aZ + if delta: + obj.delta_scale = aX, aY, aZ + else: + obj.scale = aX, aY, aZ else: uniform(0.0, 0.0), uniform(0.0, 0.0), uniform(0.0, 0.0) @@ -89,8 +93,11 @@ class RandomizeLocRotSize(bpy.types.Operator): description="Seed value for the random generator", default=0, min=0, max=1000) + use_delta = BoolProperty(name="Transform Delta", + description="Randomize delta transform values instead of regular transform", default=False) + use_loc = BoolProperty(name="Randomize Location", - description="Randomize the scale values", default=True) + description="Randomize the location values", default=True) loc = FloatVectorProperty(name="Location", description="Maximun distance the objects can spread over each axis", @@ -109,9 +116,9 @@ class RandomizeLocRotSize(bpy.types.Operator): scale_even = BoolProperty(name="Scale Even", description="Use the same scale value for all axis", default=False) - scale_min = FloatProperty(name="Minimun Scale Factor", + '''scale_min = FloatProperty(name="Minimun Scale Factor", description="Lowest scale percentage possible", - default=0.15, min=-1.0, max=1.0, precision=3) + default=0.15, min=-1.0, max=1.0, precision=3)''' scale = FloatVectorProperty(name="Scale", description="Maximum scale randomization over each axis", @@ -119,16 +126,19 @@ class RandomizeLocRotSize(bpy.types.Operator): def execute(self, context): from math import radians + seed = self.random_seed + delta = self.use_delta + loc = None if not self.use_loc else self.loc rot = None if not self.use_rot else self.rot * radians(1.0) scale = None if not self.use_scale else self.scale scale_even = self.scale_even - scale_min = self.scale_min + #scale_min = self.scale_min - randomize_selected(seed, loc, rot, scale, scale_even, scale_min) + randomize_selected(seed, delta, loc, rot, scale, scale_even) return {'FINISHED'} |