[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2519] contrib/py/scripts/addons/ object_drop_to_ground.py: Tried to implement random location on ground , but for some strange reason the object falls bellow ground , I suspect it has something to do with me changing the ooriginal location .
james bond
thekilon at yahoo.co.uk
Tue Oct 25 14:15:07 CEST 2011
Revision: 2519
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2519
Author: kilon
Date: 2011-10-25 12:15:06 +0000 (Tue, 25 Oct 2011)
Log Message:
-----------
Tried to implement random location on ground , but for some strange reason the object falls bellow ground , I suspect it has something to do with me changing the ooriginal location . Anyway i have kept the code but disabled the gui for now. If you want to try uncomment line 156. I will keep working on this
Modified Paths:
--------------
contrib/py/scripts/addons/object_drop_to_ground.py
Modified: contrib/py/scripts/addons/object_drop_to_ground.py
===================================================================
--- contrib/py/scripts/addons/object_drop_to_ground.py 2011-10-24 12:50:53 UTC (rev 2518)
+++ contrib/py/scripts/addons/object_drop_to_ground.py 2011-10-25 12:15:06 UTC (rev 2519)
@@ -28,7 +28,7 @@
"tracker_url": "http://projects.blender.org/tracker/?func=detail&atid=467&aid=25349",
"category": "Object"}
-import bpy
+import bpy , random
from bpy.props import *
import mathutils
import math
@@ -84,6 +84,24 @@
print('\nno hit')
return
+# compute randomisation based on the general or specific percentage chosen
+# if the specific percentage is zero then the general percentage is used
+def compute_percentage(min,max,value,percentage):
+ range = max-min
+ general_percentage = bpy.context.scene.general_percentage
+
+ if percentage == 0:
+ percentage_random = ( value -((range*(general_percentage/100))/2) )+ (range * (general_percentage / 100) * random.random())
+ else:
+ percentage_random = ( value - ((range*(percentage/100))/2)) + (range * (percentage / 100) * random.random())
+
+ if percentage_random > max:
+ percentage_random = max
+ if percentage_random < min:
+ percentage_random = min
+
+ return percentage_random
+
def main(self, context):
print('\n_______START__________')
@@ -104,6 +122,13 @@
for ob in obs:
bpy.ops.object.select_all(action='DESELECT')
ob.select = True
+ if sc.random_loc :
+ print("randomising the location of object : ", ob.name)
+ print("current location :" + str(ob.location))
+ ob.location = (compute_percentage(0,100,ob.location[0],10),
+ compute_percentage(0,100,ob.location[1],10),
+ compute_percentage(0,100,ob.location[2],10))
+ print("randomised location : ", str(ob.location))
do_drop(context, tmpObj, ob)
bpy.ops.object.select_all(action='DESELECT')
@@ -128,6 +153,7 @@
col.operator("object.drop_to_ground", text="Drop")
col.prop(context.scene, "align_object")
col.prop(context.scene, "use_center")
+ # col.prop(context.scene, "random_loc")
class OBJECT_OT_drop_to_ground(bpy.types.Operator):
@@ -155,11 +181,15 @@
name="Use the center to drop",
description="When dropping the object will be relocated on the basis of its senter",
default=False)
+ bpy.types.Scene.random_loc = BoolProperty(
+ name="Random Location",
+ description="When dropping the object will be relocated randomly ",
+ default=False)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Scene.align_object
del bpy.types.Scene.use_center
-
+ del bpy.types.Scene.random_loc
if __name__ == '__main__':
register()
More information about the Bf-extensions-cvs
mailing list