Rand

1445
10
11-30-2016 01:57 AM
PmssS
by
New Contributor II

Hi,

CityEngine 2015

is it possible to use 'rand' to randomize only two values, such as:

attr lenght = rand (6 - 12)

the use of "," will give me all the numbers between those two. That is not what I want.

I test this and it worked for a Block (Parameters = No subdivision and Uneven) and I tried again for another block with the same parameters and did not work.

is there an alternative?

cheers

Pedro

0 Kudos
10 Replies
ThomasFuchs
Esri Regular Contributor

Attributes can also be conditional or stochastic:

attr length = 50%: 6
           else: 12

Here, there is a 50% chance length evaluates to 6 and a 50% chance it evaluates to 12.

Note: conditional and stochastic attributes are evaluated only once during the generation process. If a rule is assigned to more than one shape, for each shape the conditional/stochastic attributes are evaluated to a value once and then keep that value.

For additional info please refer the CityEngine help on Attributes 

0 Kudos
PmssS
by
New Contributor II

strange but does not randomize between the two values... it only shows the value for the highest percentage.

0 Kudos
DavidWasserman
Regular Contributor

It randomizes based on the %. To get it to choose each one with the same likelihood, they need the same %. The listRandom() approach unlike the % case-else structure cannot be biased in the same way I believe. 

David Wasserman, AICP
0 Kudos
DavidWasserman
Regular Contributor

To add to this, if you want to choose between multiple random value ranges you could use the string-list functionality combined with int/float casting (everything in CE is Float I believe). You could have a string list as an input in the rule parameter even if you wanted to change it in the inspector.
example:

attr string_list= "3;4;5"

rand_value=float(listRandom(string_list)) #Returns 3 or 4 or 5 as a float. 

Thomas's example is the more accepted way to do this especially if the choices are meant to be hard coded, but there are multiple ways to do same thing. 

 

David Wasserman, AICP
0 Kudos
CherylLau
Esri Regular Contributor

Are the random seeds different for your shapes?  (Inspector -> Information)

PmssS
by
New Contributor II

Well, if keep the block parameters type I will only have one seed value.

I have just done the "recursive subdivision" of the block and no, it is all the same seed value.

However for each area within the lot different shape sizes are being made 6 or 12 - Success.

well partial success. I still have in front of the random heights according to a percentage and the fact that the shapes are cut/trimmed in the limit of the block.

I am trying to understand how the international city scene has been made to use some of the rule...

0 Kudos
PmssS
by
New Contributor II

Hi,

created the heights randomly but not able to create a sort of percentage for it. this is the attempt>

#Attributes

attr height = 2.6

attr extrudeFactor = 40% : 0

                                  10% : 2

                                  10% : 3

                                  else: 1

#Rules

 (...)

Extrusion-->

                  extrude (floor(float(listRandom(extrudeFactor)))*height) # didn't work, before I had ...extrude (floor(rand(0,5))*height) but I would like to have a bit more control over the random result

0 Kudos
LR
by
Regular Contributor

You just need extrude (height*extrudeFactor).

0 Kudos
PmssS
by
New Contributor II

Should be that easy but it is not. In fact it did not work as you proposed.

I tried a different way the result is strange. for a large area if in the inspector the Block parameters/type is equal to “no division” nothing is randomized but if  I change to “recursive subdivision” it will randomize between each subdivision but it will lose the orientation. All this and being able to define in the inspector the density of small areas that are extruded (I think this part I have done in the original rule file in the part for texture... I assume for the density should be similar) Have a look I know looks awful but I am learning... any help is welcome

###################################################

# Control Attributes

#

 

attr Height = 2.6

attr Width = 2.4

attr Lenght = 50%:6

                              50%:12

                              else: 0

attr spacerow = rand (10,16)

attr spacecoll = rand (1,3)

###################################################

#height test

const extrudeFactor = 20% : rand(1,3)

                               20% : rand (3,5)

                               20% : rand (2,4)

                               20% : rand (1,2)

                               20% : rand (3,4)                              

                              else: 1

########################################################################

########################################################################

###

###   RULES

@StartRule

  

 

Lot--> ######Divide the ground 1

     

    split(x,adjust) {~1:Nothing| {Lenght:Ground | spacecoll:NothingLenght:Ground}* | ~1:Nothing}

 

Ground--> ######Divide the ground 2

     

    split(z,adjust) {~1:Nothing| {Width:Gfloor | Width:GfloorWidth:GfloorWidth:Gfloor | spacerow:Nothing| Width:Gfloor| Width:Gfloor| spacerow:Nothing}* | ~1:Nothing}

 

 

Gfloor-->

   

    case scope.sx < 5:  # too small to build a house

      NIL

           

      else:

      extrude (floor(extrudeFactor)*Height)

    split (y) { Height : Casa } *

0 Kudos