Itoo Software Forum

Author Topic: Randomize Count size on objects  (Read 397 times)

MT4250

  • Newbie
  • *
  • Posts: 5
Randomize Count size on objects
« on: September 21, 2016, 10:38:13 AM »
Hi,

This should be a simple task.

Let say i have a spline which I want to distribute like 3 boxes on this but I want to have the ability to use a random size so the box fit within the length of the spline.
So I have set a linear spline with 3 counts but the thing is that it fits but I cant figure how to randomize the fixed side width in X, YZ works like it should with randomization but I cant randomize the X when using count or adaptive.


Paul Roberts

  • iToo Software
  • Hero Member
  • *****
  • Posts: 1517
Re: Randomize Count size on objects
« Reply #1 on: September 21, 2016, 01:02:27 PM »
Hi,

Unfortunately this is a limitation with these two modes. They require the segment sizes to to be the same to correctly scale the segments. One option though is to use an expression to scale the final segment in the section to make sure it fits. In that way you can randomise the others. This requires two techniques: One to detect the last segment, and another to scale it.

If you want to recreate count mode then detecting the final segment is easy. You can simply test the current segment count value. To do this you would use the variable SegmentXCounter. To scale the final segment you need to find out how much space is left along the spline. To do this use XSectionLength and XSectionPosition. The first of these returns the length in scene units of the current spline section, the second returns a scalar (0-1) of the splines current position. Using these you can work out exactly how much space remains and use it to scale the final segment.

XSectionLength*(1-XSectionPosition)

I've attached an example of this for you to take a look at, this can be adapted for more complex uses.

I hope that helps, please let me know if you have any further questions.

Many Thanks,

Paul
Paul Roberts
iToo Software