[Closed] Random chance of deleting an object based on distance from a location?
Hello.
I have an idea, but don’t know how to put it onto action.
What I want to do is randomly delete objects, based on how far away the objects are from a certain point or object.
For example, I have objects arranged in the 3D space, their position ranges from 0 – 100 on the Y axis. Objects on 0 units X axis have a 100% chance of not being deleted, and objects 100 units from the X axis have 100% chance of being deleted.
The aim of this is to have a randomly generated set of objects, which “fade” the further they are from a location, or it could even be the distance from say a cube.
I have thought about using particles, but I want to control the original layout of the objects, for example it could be an interlocking grid, or leaves on a tree.
If anyone has any ideas how I might go about this it would be really appreciated!
Thanks,
Dean
I have just made a quick mock up, please see attachment. On the left is the original, and the right shows how it might look after running a script.
#1 find maximum distance (max_dist)
#2 using normalized distance (dist):
#3 get probability of object being deleted:
(random (dist/max_dist) 1.0) > 0
but i would probably use visibility track (expression or script controller) instead of deleting an objects
Something like this could work:
(
gc()
delete objects
for x = 12.5 to 400 by 25 do
(
for y = 12.5 to 400 by 25 do
(
plane lengthsegs:1 widthsegs:1 pos:[x,y,0] wirecolor:black
)
)
fn SelectRandomNodesByDistance pos:[0,0,0] axis:#y nodes:#() =
(
max_dist = -1e9
min_dist = 1e9
nodes = for node in nodes collect
(
case axis of
(
#x:dist = abs node.pos.x - pos.x
#y:dist = abs node.pos.y - pos.y
#z:dist = abs node.pos.z - pos.z
#all:dist = distance node.pos pos
)
max_dist = amax max_dist dist
min_dist = amin min_dist dist
#(dist, node)
)
max_dist += min_dist
result = for node in nodes where (random min_dist max_dist) < node[1] collect node[2]
return result
)
sel = SelectRandomNodesByDistance pos:[0,0,0] axis:#y nodes:objects
sel.wirecolor = red
)
@Denis thanks for the tips, a simple solution like this will probably work well. You’re also right, deleting objects probably isn’t the best, but could even just re-name them, select them, wire colour, etc,
@Jorge thanks for the script, that’s really given me something to look at and understand, although what I want to achieve is a script that can be used on an existing scene, not just planes. I want to experiment with all kinds of geometric shapes.
Thanks for the help and advise so far!
Dean
You can pass whatever nodes you would like to the function. The planes in this case are just for testing it.
I have highlighted the part of the code you can remove (the one that creates the planes). Then just call the function like:
SelectRandomNodesByDistance pos:[0,0,0] axis:#y nodes:[b]objects[/b]
Where ‘objects’ is the array of nodes you want to work with.
The function will return an array of nodes that you can work with.
Hi Jorge,
I think I understand your script, and it works well, I just needed something that would work with some pre-made geometry.
So I have taken Denis’ idea and turned it into a simple, but effective script which does what I want.
md = 100
for m in selection do (
od = m.pos.x
randomchance = random (od/md) 1
if (0.95 < randomchance) then m.wirecolor = color 0 0 0
)
md is the max distance the furthest object is from the y axis. At the moment this is just a manual figure, rather than automatically finding the furthest object.
I think this will work well for my purposes.