Tue, Dec 3, 4:05 AM CST

Renderosity Forums / Poser - OFFICIAL



Welcome to the Poser - OFFICIAL Forum

Forum Coordinators: RedPhantom

Poser - OFFICIAL F.A.Q (Last Updated: 2024 Dec 03 1:43 am)



Subject: Python script to scatter props around a scene?


ranman38 ( ) posted Mon, 04 February 2013 at 2:42 PM · edited Thu, 21 November 2024 at 8:43 AM

Something like ecosystem in VUE, even if on a much smaller scale?

Thanks



PhilC ( ) posted Mon, 04 February 2013 at 3:02 PM
ranman38 ( ) posted Mon, 04 February 2013 at 3:04 PM

I was thinking more like taking a tree or bush and scattering multiple copies around randomly. Thanks though Phil.



willyb53 ( ) posted Mon, 04 February 2013 at 3:06 PM

Poser version of send in the clones from DAZ.  does not do characters atm.

 

Bill

People that know everything by definition can not learn anything


ranman38 ( ) posted Mon, 04 February 2013 at 3:09 PM

thanks. :)  Any free scripts? lol



PhilC ( ) posted Mon, 04 February 2013 at 3:15 PM · edited Mon, 04 February 2013 at 3:15 PM

Should not be too difficult to script.

Which version of Poser are you using?

PC or Mac?

Would the copies need to be identical or would you want random scaling?

 


ranman38 ( ) posted Mon, 04 February 2013 at 3:16 PM · edited Mon, 04 February 2013 at 3:24 PM

PC

random and uniform scale :)



3doutlaw ( ) posted Mon, 04 February 2013 at 3:23 PM

Philc has got an Array script in poser toolbox, that may do what you want.

Of course, it is fixed distances, it seems.

For something like Carrara's Surface Replicator...there is a randomnization to the locations (which seems "addable" or makeable, based on something like PhilC's script as a base...for owner/personal use only of course)

...there is also spacing (i.e. when randomizing, don't choose a point that is within x/y from another (this seems the hard part)

...a randomnization to the rotations

...then you could use a drop to floor script on all of 'em.

I gotta believe that someone has a mathematical formula (random distribution of points or something) for it, then it takes someone to plug that into a python script for props


3doutlaw ( ) posted Mon, 04 February 2013 at 3:24 PM

Oooo...PhilC is on it!  :tongue1:

Watching intently, as this would go well with primorge's morphing blade of grass!!


3doutlaw ( ) posted Mon, 04 February 2013 at 3:30 PM · edited Mon, 04 February 2013 at 3:33 PM

Here is a chap who had a similar quandry, and came up with something:  Random Non-Overlapping Distribution of Objects

...and here is another loooong discussion on same topic:  Random distribution of objects in space, with no overlap


markschum ( ) posted Mon, 04 February 2013 at 4:01 PM

I wrote a crowd generator script once. It could probably be used. I will post it later tonight if Phil hasn't done one.


LaurieA ( ) posted Mon, 04 February 2013 at 4:17 PM

That would have been handy when I was placing those hundred plus crayons for an image I did. LOL.

Laurie



pitklad ( ) posted Mon, 04 February 2013 at 4:29 PM · edited Mon, 04 February 2013 at 4:30 PM

Attached Link: randomize prop rotation values

**PhilC** and ****markschum**** made a script to randomize prop rotation values in this thread I guess with some modifications it could make what you want


My FreeStuff


Snarlygribbly ( ) posted Mon, 04 February 2013 at 5:11 PM · edited Mon, 04 February 2013 at 5:11 PM

Sometime ago I wrote something quick and dirty that does this. It has no UI - you have to edit the values in a the parameters section of the code, near the top:


import poser, random

'''
ALL MEASUREMENTS ARE IN INCHES!!!
'''

Parameters

PROP = 'RuntimelibrariespropsVegetationTreesBlossom tree.pp2'
XTRANSNAME = 'xTran'
ZTRANSNAME = 'zTran'
YROTATENAME = 'yRotate'
MAXIMUM_NO_OF_INSTANCES = 30
MIN_X = -500
MAX_X = 500
MIN_Z = -500
MAX_Z = 500
RANDOM_ROTATE = True
MINIMUM_SEPARATION = 100
GIVE_UP_AFTER = 8

scene = poser.Scene()

Initialise variables

count = 0
rangeX = MAX_X - MIN_X
rangeZ = MAX_Z - MIN_Z
done =

print 'Starting prop generation ...'

while count < MAXIMUM_NO_OF_INSTANCES:
    
    # Load the prop
    scene.LoadLibraryProp(PROP)
    prop = scene.CurrentActor()
    print 'nProp #%s loaded' % (count + 1)
    
    # Generate random co-ordinates
    attempt = 0
    give_up = True
    
    while attempt < GIVE_UP_AFTER:
        bx = (random.randint(0, rangeX) + MIN_X)
        bz = (random.randint(0, rangeZ) + MIN_Z)
        x = bx / 103.2
        z = bz / 103.2
        block = (int(bx / MINIMUM_SEPARATION), int(bz / MINIMUM_SEPARATION))
        print 'Attempt %s: x,z = %s,%s, block = %s' % (attempt, bz, bx, block)
        if not done.get(block, None):
            done[block] = prop
            give_up = False
            break
        else:
            attempt += 1
    
    if give_up:
        print 'n--- GIVING UP!! ---'
        break
    
    # Place prop
    prop.SetParameter(XTRANSNAME, x)
    prop.SetParameter(ZTRANSNAME, z)
    print 'Positioned at %s, %s' % (x, z)
    
    # Rotate if requested
    if RANDOM_ROTATE:
        r = random.randint(0, 360)
        prop.SetParameter(YROTATENAME, r)
        print 'Rotated to %s degrees' % r
    
    count += 1

print 'nAnalysis of prop generation:'
for k, v in done.items():
    print 'Block %s : %s' % (k, v.Name())

Free stuff @ https://poser.cobrablade.net/


Snarlygribbly ( ) posted Mon, 04 February 2013 at 5:15 PM

file_491341.txt

Hm. Some critical formatting has gotten lost during the copy/paste :-(

I'll attach the code as a txt file...

Free stuff @ https://poser.cobrablade.net/


PhilC ( ) posted Mon, 04 February 2013 at 5:45 PM

file_491343.txt

Maybe we can combine our efforts. I've done the GUI it should be relatively easy to slip Snarlygribbly's placement code in it at the point indicated.


ranman38 ( ) posted Mon, 04 February 2013 at 5:50 PM

get an error

 File "add-random-copies.py", line 225
    def errorMessage(self,msg):
                              ^
IndentationError: unindent does not match any outer indentation level



PhilC ( ) posted Mon, 04 February 2013 at 6:11 PM

file_491345.txt

I'm not getting that error, what program are you editing the script in?

Attached now includes Snarlygribbly's placement code. Ran it through very quickly and got a result. Give it a whirl, see what you get.

I've got to go cook something or else Jan will fade away. Will test more later.


ranman38 ( ) posted Mon, 04 February 2013 at 6:13 PM

poser pro 2010



3doutlaw ( ) posted Mon, 04 February 2013 at 10:25 PM

Works for me....but I dont understand the inputs?  It says max coverage, but keeps failing for invalid max distance?  Is it supposed to put the selected prop on another prop that you load, like a plane (first field)?  What is the min and max coverage?  (number of I assume means the number of props you are attempting to dup)

I just kept getting "invalid max distance"...never got it to do anything.  :(


PhilC ( ) posted Tue, 05 February 2013 at 12:58 AM

file_491352.txt

OK try this one. It has a much simpler placement code but does not test for overlaps.


Snarlygribbly ( ) posted Tue, 05 February 2013 at 1:40 AM

Quote - Works for me....but I dont understand the inputs?  It says max coverage, but keeps failing for invalid max distance?  Is it supposed to put the selected prop on another prop that you load, like a plane (first field)?  What is the min and max coverage?  (number of I assume means the number of props you are attempting to dup)

I just kept getting "invalid max distance"...never got it to do anything.  :(

In my code, Min/Max X and Z is used to constrain the random generation to a square area defined by those values. The Min values need to be lower than the Max values.

Everything is placed at a yTrans value of 0 so no plane is needed.

The code isn't clever, but has been used enough (by others) for me to know that it works :-)

I don't have Poser with me at the moment so I can't see what Phil has done, but knowing him I don't doubt that it's something cool :-)

Have fun ...

Free stuff @ https://poser.cobrablade.net/


PhilC ( ) posted Tue, 05 February 2013 at 2:08 AM · edited Tue, 05 February 2013 at 2:10 AM

err not really, its very very basic :)

Latest version still has your code in it so it will be easy to swop between the two.

Much will depend upon what result the user is after. Hopefully it will provide a framework for customization.


3doutlaw ( ) posted Tue, 05 February 2013 at 7:14 AM

OK, so the first field, you have to select a prop (it does not use the selected prop in the scene, it will just say invalid distance or something)

For the other fields I put (this is using version 3 above):

Max x and z Tran in Poser - 25

Max x and z Tran in Poser - 10

Number of - 10

I did get 10 objects, but the first one was at x=1526.6, z=1382.7...all of them were way far away.

I was thinking they would be constrained to between 10 and 25?

I tried similar with version 2, and got the output below:

Starting prop generation ...

Prop #11 loaded
Attempt 0: x,z = -491,-495, block = (-5, -5)
Positioned at -4.79651162791, -4.75775193798
Rotated to 41 degrees

Prop #12 loaded
Attempt 0: x,z = -498,-489, block = (-5, -5)
Attempt 1: x,z = -485,-496, block = (-5, -5)
Attempt 2: x,z = -497,-496, block = (-5, -5)
Attempt 3: x,z = -493,-490, block = (-5, -5)
Attempt 4: x,z = -493,-489, block = (-5, -5)
Attempt 5: x,z = -491,-497, block = (-5, -5)
Attempt 6: x,z = -486,-488, block = (-5, -5)
Attempt 7: x,z = -494,-492, block = (-5, -5)

--- GIVING UP!! ---

Analysis of prop generation:
Block (-5, -5) : Blade_uvm_1
Max dist =  25
Min dist =  10
Num of copies =  10


PhilC ( ) posted Tue, 05 February 2013 at 7:53 AM

Which Poser version and what OS are you using?

In 2012 in Windows the label reads "Max x and z Tran in Poser units." I'm aware that a Mac will do its level best to screw up the formatting and possibly trubcate the text. The size of a Poser unit does vary between versions but not by much. A average adult figure is about 0.75 Poser units high. If you put in values of 10 and 25 then yes the props will be very spread apart.

You can select what units the dials will display by going to Edit > General Preferences > Interface > Units.


3doutlaw ( ) posted Tue, 05 February 2013 at 8:00 AM · edited Tue, 05 February 2013 at 8:02 AM

Poser 9, Windows

My poser units were set to Inches


3doutlaw ( ) posted Tue, 05 February 2013 at 8:06 AM

file_491360.png

OK, I changed it from 1 to 3, with 10 count, and after spinning the camera around I found them out in front and to the right of Andy.


PhilC ( ) posted Tue, 05 February 2013 at 8:20 AM

That sounds right. To get them to also be to the left and behind you'll need a negative minimum value.


Rosemaryr ( ) posted Tue, 05 February 2013 at 8:31 AM

bookmarking, and watching with interest....

 

RosemaryR
---------------------------
"This...this is magnificent!"
"Oh, yeah. Ooooo. Aaaaah. That's how it starts.
Then, later, there's ...running. And....screaming."


ranman38 ( ) posted Tue, 05 February 2013 at 9:44 AM

Ok, that seems to be working. Needs really low values to be in camera so to speak. Thanks guys.



3doutlaw ( ) posted Tue, 05 February 2013 at 1:26 PM · edited Tue, 05 February 2013 at 1:27 PM

file_491378.png

This is too fun to be done!  ;-)

I wanted to give it a try at making a distribution...so I just added another routine.  There was not enough fields for the variables I used, so one of them is "fixed".  The pic is with 3/3/200 (200 objects in a 3x3 area with a distance of 0.1).  There is probably a better way to optimize that last loop (i.e. remove used values so there are less choices), but I just wanted to see if I could do it.  :)


3doutlaw ( ) posted Tue, 05 February 2013 at 1:27 PM

file_491379.txt

Whoops, only 1 file attachment allowed...this probably needs to go over to Python scripting now, to make it really awesome!


ranman38 ( ) posted Tue, 05 February 2013 at 2:14 PM

If we are wishing here, then I wish it would make "billboard" instances of the original to keep poly count low.

lol  You never know. :)



3doutlaw ( ) posted Tue, 05 February 2013 at 2:32 PM

Now that would be quite a trick! 

I would think it is possible to turn all the objects in the same direction automatically, so that if you are using billboards, they would all face a similar direction.


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.