Swarm Script

richardandtracyrichardandtracy Posts: 6,486
edited July 4 in Freebies

I'm developing a script to create swarms of instanced objects in a volume. I want to replicate swarms of objects in a rectangular bounding volume. The sort of thing I'm thinking of is a load of leaves blowing down wind of a tree, a swarm of butterflies/birds or an invasion of flying pixies, where they can be utterly random (leaves) or show an individual variation on a general orientation (flock of birds).

I have got the general randomness and limits working with my proof of concept script, but I need to make some efforts to try to prevent the instances from intersecting with each other. The proof of concept output from the script is shown below with a socket set box and 100 instances in a 50cm cube volume. The instances have random scale, position and orientation in 3 axes. The random values for the rotation and scale are all user specified between upper and lower limits. It's a tiny bit intimidating initially as 14 limits and the number of instances need to be specified, but I'll write a help file to explain (if I eventually reckon it is in state to release on an unsuspecting public.

I hope I can develop this into a useful idea. Can anyone think of uses you might have for a little script like this, or am I doing it just for myself? That latter option wouldn't be the first time.. ;)

Regards,

Richard 

Random 3D Script Test R01.png
1066 x 902 - 680K
Post edited by richardandtracy on

Comments

  • barbultbarbult Posts: 25,428

    Are you attempting to replicate the Volume scatter mode of UltraScatter Pro?

  • richardandtracyrichardandtracy Posts: 6,486
    I don't know. Not having ultrascatter pro, it's hard to tell. Regards, Richard.
  • barbultbarbult Posts: 25,428

    UltraScatter2 has the Volume mode, too, if you have that.

  • StargazeyStargazey Posts: 269
    edited July 5

    I think this script would be really useful and just what I've been looking for!

    (I'm sure Ultrascatter is very good, but it seems to be a bit of overkill for what I need, not to mention rather expensive if you don't need all it's "bells and whistles".)

    Post edited by Stargazey on
  • WendyLuvsCatzWendyLuvsCatz Posts: 39,292

    anything that changes the weird default way instances are created is good

    I find the triangular formation the most useless layout ever and if not using Ultrascatter, I use instances+

    https://www.daz3d.com/instances-plus-for-daz-studio

    why it does not by default create a grid is beyond me

  • richardandtracyrichardandtracy Posts: 6,486

    I have UltraScatter, not US2. US2 seems amazing, but much more than I could ever need. Howie Farkes must be completely brilliant to come up with what he does, but it's both expensive and so capable I'd never begin to explore its limits.

    In UltraScatter I have only noticed a surface mode, which is occasionally useful. I will confess, I do think UltraScatter is incredibly clever, but I've only used it once except when testing it out, and never really felt I've used it to its full extent. I've been left with the nagging feeling that, possibly, I'm not clever enough to ever think of a task that stretches it to its extents. The attract and repel features are amazing, but overkill for what I need. And well beyond what I can program.

    I have created a basic 2d linear array script, then extended that into 3d just recently (both of which create rectangular grids of instances). I've done a circular array too. However, I've done nothing random before, and implementing a random scale led to a good few dead ends before working out a way that worked. Having a single character in the wrong case really didn't help the de-bugging.

    The instances are created from a single selected node (though with my circular/linear array scripts it can be a root node for a complete character instance to be created, and I think this may be the same - testing still needed), and then that node is instanced into a volume that doesn't need to enclose the original node. The instances are all named the same as the original node with a number following the original node name to create a unique name for the instance. The instances are collected into an instance group to keep the scene tab tidy and allow the instances to be moved/rotated as a block together if needed.

    So, why am I doing this? There are a few reasons 

    1. The existing tools I have don't seem to entirely do what I want .
    2. I don't have much spare cash to buy commercial scripts, and there don't seem to be any freebies that do what I want.
    3. I'm not convinced that I could use the tools I can buy to their full extent.
    4. I feel more comfortable with tools I've made. I'm an engineer and make tools (hardware or software tools as necessary) to help my work as a matter of course, and I make the tools suit the way I work and think. Which means they need to be simple.
    5. I enjoy a little programming every now and again and haven't had a chance for the last 9 months when my PC failed and it was a low priority to fix 
    6. And if someone else can use the tool too, it's no extra expense and if it helps someone else, then it just goes a little way to returning to the community a tiny bit of the vast help and benefits the community has given me.

    Regards,

    Richard 

  • WendyLuvsCatzWendyLuvsCatz Posts: 39,292
    edited July 5

    well Draagonstorm won't care I think from her new plane of existence

    so arrays would be fine as long as you script it yourself not looking at hers

    as you are

    some others may appreciate it

    I am sure there are many options like a circle or elipse or rectangle edge not covered

    That Carrara replicators for example do and I miss

    (have to use ultrascatter on primitives those shapes)

    Post edited by WendyLuvsCatz on
  • barbultbarbult Posts: 25,428

    Richard has a nice circle script.

  • Eustace ScrubbEustace Scrubb Posts: 2,718
    edited July 5

    For a swarm, I'm thinking a spherical arrangement from Center/Focus Point (a Null) would be highly useful, especially as "swarm" calls to mind clusters of insects around a hive or a victim.  So:

    • B number of bugs (instances of HouseFly.pp2 for example).

    • Locate each instance at position (X(Random), Y(Random), Z(Random)) wherein:

      • Each of the variables are ranged between MinRadius and MaxRadius from Center,

      • Total Radius (TRadius [Center]) is between MinRadius and MaxRadius, and calculated as (TRadius = √(X(Random)² + Y(Random)² + Z(Random)² ))

    (As far as overlap, maybe add an (insanely laggy for large swarms!) offset check, wherein Position(n) is recalculated if TRadius [Position(n-q)] is less than the X, Y, or Z dimensions of the instance for each prior instance while q < n and n =< B.)

    Post edited by Eustace Scrubb on
  • richardandtracyrichardandtracy Posts: 6,486

    I came up with the thread name just as I was writing the thread title, and it's probably less appropriate for a rectangular bounded volume than an ellipsoid, as Eustace Scrubb suggested.

    I'm planning to do simple little scripts, so I will leave the rectangular one as it is with it's primary suitability for blown leaves and things like that. I have managed to do a fairly rough & ready overlap prevention that tries 100 times to get a non overlapping location before it abandons the instance and moves on to the next.

    Then, I think I could possibly make another fairly simple script to generate instances inside an ellipsoid bounding volume around a central point, along with a bias of the instance's towards the middle. This would be more suitable for swarms. Good thought Eustace Scrubb.

    I've discovered that the script will instance complete characters including any clothing etc. so long as the root node is chosen - in the same way as my linear array script. 

    I can't update the thread with a progress image just now as the day's progress is largely limited to bug fixing and preventing overlaps. I can see that a help file is going to be very necessary to give ideas on how to use it.

    Regards,

    Richard 

  • richardandtracyrichardandtracy Posts: 6,486
    edited July 12

    I have finally got to the point of a working Cuboid Swarm Script with basic collision detection that does the job I originally wanted it for. It fills a user defined volume with instances of the original model, randomly positioned, randomly scaled (within user defined limits) and at various angles (within user defined limits again).

    It's suitable for wind blown leaves, butterflies, dragonflies, shoal of fish, that sort of thing. The picture below shows how it works with a single one facet green leaf model instanced 2000 times in an 8 cubic metre volume (2*2*2m) then a second set with another 2000 brown leaves was off to the right. The window in the image shows the inputs. 

    The instances are all tidied up into an instance group, which may be translated, rotated or scaled as one object without needing to deal with the individual instances. The same seed object may be used for many different Cuboid Swarms.  Swarms of different objects can overlap, but the basic collision prevention only happens during generation inside a swarm between members of the swarm.

    There is a programmed limit of 10,000 in a group. You can select a character's root node, and instance all clothing etc up to 10,000 times. It will take a long time and I will not vouch for your machine's stability if you do it.

    I leave you to imagine whether it's useful for you, but I hope it is.

    Regards,

    Richard 

    Cuboid Swarm Script Promo.jpg
    1200 x 800 - 295K
    zip
    zip
    Cuboid Swarm Script.zip
    540K
    Post edited by richardandtracy on
  • richardandtracyrichardandtracy Posts: 6,486
    edited July 13

    Right. How about three Holly Leaves for the script to create the leaf swarm shown in the script above. If yes, see the attached.

    Regards,

    Richard.

    Holly Leaves Promo.jpg
    800 x 800 - 178K
    zip
    zip
    Holly Leaves.zip
    2M
    Post edited by richardandtracy on
Sign In or Register to comment.