POV-Ray : Newsgroups : povray.advanced-users : Need a script to randomly scatter objects vertically Server Time
28 Nov 2021 15:30:24 EST (-0500)
  Need a script to randomly scatter objects vertically (Message 11 to 20 of 30)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Tor Olav Kristensen
Subject: Re: Need a script to randomly scatter objects vertically
Date: 21 Apr 2021 21:55:00
Message: <web.6080d64cc2ce34cb6d7cc5a589db30a9@news.povray.org>
"Norbert Kern" <nor### [at] t-onlinede> wrote:
>... I want
> to point to an old macro made by JRG (Jonathan Rafael Ghiglia) back in 2001 -
> his "clutter macro". Since I wasn't able to find the link on this server I
> include the macro here.
>...

Hi Norbert

I suspect that there is an error in JRG's Interpolate macro in the enclosed zip
file.

I would guess that it should return this expression:

    (P1 + (T - T1)/(T2 - T1)*(P2 - P1))

- instead of this one:

    (P1 + (T1 + T/(T2 - T1))*(P2 - P1))

--
Tor Olav
http://subcube.com
https://github.com/t-o-k


Post a reply to this message

From: Thomas de Groot
Subject: Re: Need a script to randomly scatter objects vertically
Date: 22 Apr 2021 02:46:42
Message: <60811bd2$1@news.povray.org>
Op 21/04/2021 om 20:07 schreef Norbert Kern:
> Mike Horvath <mik### [at] gmailcom> wrote:
>> I have some mesh based terrain model. I would like to drop trees
>> vertically on to it based on some rules:
>>
>> 1. the trees should not overlap with each other
>> 2. the tree density should depend on the (configurable) slope of the ground
>> 3. trees are circular so the only important data is the radius of the tree
>> 4. the script needs to output the generated coordinates to a text file
>>
>> Can someone help me write such a script? Thanks!
>>
>>
>> Michael
> 
> 
> 
> I know that Thomas made some very nice macros public in this thread, but I want
> to point to an old macro made by JRG (Jonathan Rafael Ghiglia) back in 2001 -
> his "clutter macro". Since I wasn't able to find the link on this server I
> include the macro here.
> 
I had all but forgotten about this macro! Thanks for the reminder 
indeed. Hight time to try it again.

> With some modifications every point of your list is doable - perhaps I'm able to
> do it in the next days. Especially interesting is your first point - but I
> haven't looked into Thomas macro regarding it - perhaps this problem is already
> solved...
> 
Not really.

> Furthermore, if you want to use a very large number of trees, you should use
> only visible coordinates. Back in 2005 I published a method
>
(http://news.povray.org/povray.binaries.scene-files/message/%3C432414bf%40news.povray.org%3E/#%3C432414bf%40news.povray
> .org%3E
> for macro -
>
http://news.povray.org/povray.binaries.images/thread/%3Cdg0ifb%242oi%241%40chho.imagico.de%3E/
> for the thread).
>
vegmanythings! Of course! Another of those macros I have and then, 
somehow, forget about because I follow my own routine. :-/

> 
> Stay healthy
> 
Thanks. Up to now, successfully...

-- 
Thomas


Post a reply to this message

From: Norbert Kern
Subject: Re: Need a script to randomly scatter objects vertically
Date: 22 Apr 2021 12:50:00
Message: <web.6081a84bc2ce34cbfd796d7fb7ae6630@news.povray.org>
"Tor Olav Kristensen" <tor### [at] TOBEREMOVEDgmailcom> wrote:

> Hi Norbert
>
> I suspect that there is an error in JRG's Interpolate macro in the enclosed zip
> file.
>
> I would guess that it should return this expression:
>
>     (P1 + (T - T1)/(T2 - T1)*(P2 - P1))
>
> - instead of this one:
>
>     (P1 + (T1 + T/(T2 - T1))*(P2 - P1))
>
> --
> Tor Olav
> http://subcube.com
> https://github.com/t-o-k


Thanks Tor!

I would never recognize such errors.

Norbert


Post a reply to this message

From: Mike Horvath
Subject: Re: Need a script to randomly scatter objects vertically
Date: 11 May 2021 17:16:34
Message: <609af432$1@news.povray.org>
I finally got around to this. Thanks!

I don't quite understand the code yet. A few questions:

1. How do I make it so that the probability is lower depending on the
    slope of the terrain? This should vary depending on the type of
    object. For instance, the sphere might not like a high slope. The
    spike might not care very much.
2. The spikes seem to point in the direction of the normal. Can I
    disable this? I want them to always be vertical.
3. Is there a way to round the y coordinate to the nearest 8 units and
    the x and z coordinates to the nearest 10 units? I am working with
    virtual LEGO and the precision is very coarse.

Thanks again!


Michael


On 4/21/2021 2:07 PM, Norbert Kern wrote:
> I know that Thomas made some very nice macros public in this thread, but I want
> to point to an old macro made by JRG (Jonathan Rafael Ghiglia) back in 2001 -
> his "clutter macro". Since I wasn't able to find the link on this server I
> include the macro here.
> 
> With some modifications every point of your list is doable - perhaps I'm able to
> do it in the next days. Especially interesting is your first point - but I
> haven't looked into Thomas macro regarding it - perhaps this problem is already
> solved...
> 
> Furthermore, if you want to use a very large number of trees, you should use
> only visible coordinates. Back in 2005 I published a method
>
(http://news.povray.org/povray.binaries.scene-files/message/%3C432414bf%40news.povray.org%3E/#%3C432414bf%40news.povray
> .org%3E
> for macro -
>
http://news.povray.org/povray.binaries.images/thread/%3Cdg0ifb%242oi%241%40chho.imagico.de%3E/
> for the thread).
> 
> 
> Stay healthy
> Norbert
>


Post a reply to this message

From: Alain Martel
Subject: Re: Need a script to randomly scatter objects vertically
Date: 12 May 2021 10:19:27
Message: <609be3ef$1@news.povray.org>

> I finally got around to this. Thanks!
> 
> I don't quite understand the code yet. A few questions:
> 
> 1. How do I make it so that the probability is lower depending on the



> 2. The spikes seem to point in the direction of the normal. Can I

> 3. Is there a way to round the y coordinate to the nearest 8 units and


> 
> Thanks again!
> 
> 
> Michael
> 
> 
For the spikes. You just need to ignore the normal returned by the trace 
function when placing them.
So, remove any vrotate or vorient.

For the rounding... I would try using the modulo function.
Something like this :
#declare LEGO_Position = <Position.x-mod(Position.x, 10), 
Position.y-mod(Position.y, 8), Position.z-mod(Position.z, 10)>


Post a reply to this message

From: Mike Horvath
Subject: Re: Need a script to randomly scatter objects vertically
Date: 12 May 2021 18:19:49
Message: <609c5485$1@news.povray.org>
Do the size and orientation of the landscape and probability functions 
matter? The example seems to be contained in a 10 unit square with one 
corner at the origin, but can it be a 100 unit square? Can the square be 
located elsewhere than the origin?

The documentation is lacking/confusing.


Mike


Post a reply to this message

From: Mike Horvath
Subject: Re: Need a script to randomly scatter objects vertically
Date: 12 May 2021 18:20:58
Message: <609c54ca$1@news.povray.org>
On 5/12/2021 10:19 AM, Alain Martel wrote:
> For the spikes. You just need to ignore the normal returned by the trace 
> function when placing them.
> So, remove any vrotate or vorient.

There is actually a macro setting for this, I found out. But it is for 
*all* the objects, not for each object individually.


> 
> For the rounding... I would try using the modulo function.
> Something like this :
> #declare LEGO_Position = <Position.x-mod(Position.x, 10), 
> Position.y-mod(Position.y, 8), Position.z-mod(Position.z, 10)>

Thanks!


Mike


Post a reply to this message

From: Bald Eagle
Subject: Re: Need a script to randomly scatter objects vertically
Date: 13 May 2021 07:05:00
Message: <web.609d0778c2ce34cb1f9dae3025979125@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:

> 1. How do I make it so that the probability is lower depending on the
>     slope of the terrain? This should vary depending on the type of
>     object. For instance, the sphere might not like a high slope. The
>     spike might not care very much.

I just took a brief look at this.

Since your objects get placed using a loop, you can add conditionals and
multipliers.

So maybe have a rand value selecting for each type of object.  Using #switch,
you can do object-specific things like define values, orientation, etc.

In each block of object code you can simply do a calculation on the slope to see
if it's a good value.  If it is, you can just use another rand value and if it's
below a certain threshold, then place your object.  #if (RandVal < 80)  object
{Object} #end  Would place it 80% if the time.

There's a terrain scale that gets used to adjust other calculations in the
scene.  That ought to make the fairly code size independent.

Looks like everything is at the origin, so you'll have to do it and then
translate, or translate to the origin, do it, and then translate back.

That's all I picked up / thought up on a quick read-through.


Post a reply to this message

From: Mike Horvath
Subject: Re: Need a script to randomly scatter objects vertically
Date: 13 May 2021 14:24:30
Message: <609d6ede$1@news.povray.org>
On 5/13/2021 7:03 AM, Bald Eagle wrote:
> In each block of object code you can simply do a calculation on the slope to see
> if it's a good value.  If it is, you can just use another rand value and if it's
> below a certain threshold, then place your object.  #if (RandVal < 80)  object
> {Object} #end  Would place it 80% if the time.
> 
> There's a terrain scale that gets used to adjust other calculations in the
> scene.  That ought to make the fairly code size independent.
> 
> Looks like everything is at the origin, so you'll have to do it and then
> translate, or translate to the origin, do it, and then translate back.
> 
> That's all I picked up / thought up on a quick read-through.
> 


Could I create a slope map or object pigment? That would be a lot 
smoother gradient I think than doing a few checks here and there using 
conditionals.

I would need to feed the 3D mesh into some function or macro and get a 
2D pigment as output. Dunno how to do that.


Mike


Post a reply to this message

From: Bald Eagle
Subject: Re: Need a script to randomly scatter objects vertically
Date: 13 May 2021 15:00:00
Message: <web.609d7610c2ce34cb1f9dae3025979125@news.povray.org>
Mike Horvath <mik### [at] gmailcom> wrote:

> Could I create a slope map or object pigment? That would be a lot
> smoother gradient I think than doing a few checks here and there using
> conditionals.

Not having implemented any of this in a working scene, I don't presently have
any practical knowledge of everything that's going on.  As it appeared to me,
there were a few pigments/functions that governed stuff, and a trace to get a
normal at a point.  I'm not sure why more maps or pigments would be required or
how they would be used.

If you're placing objects based on the sampling results of the ground plane /
heightfield, then the decision about what object to place and how would be done
in the loop.
Maybe there's a way to have several loops, but I think that would be less
efficient.

As for an object pigment, there is NO gradient at all - or rather - an abrupt,
infinite gradient - a sudden discontinuity from inside to outside.  Bill
Pokorny, myself, and possibly others have experimented with sampling methods
geared toward creating an actual smooth gradient for the object pattern to
(IIRC) use it in isosurfaces.

> I would need to feed the 3D mesh into some function or macro and get a
> 2D pigment as output. Dunno how to do that.

You're gonna have to give me a sample image or a drawing that shows what the 3D
mesh is and what needs to go where and why - and then maybe I tell you how to
accomplish your goal.

You _can_ trivially turn your 3D mesh into a "2D" pigment by just using the mesh
as an object in an object pigment, or if you want that silhouette effect, using
an object pigment in a function, setting y to 0, and putting that back into a
pigment pattern....

But I'm presently just guessing / speculating about what your actual needs and
final goals are.


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2021 Persistence of Vision Raytracer Pty. Ltd.