Random texture

2900
8
11-20-2012 04:23 AM
ziadfilfili
New Contributor II
Hi there,

I need help in applying random texture to my buildings.
All my textures has the same name but different numbering.

Is there a way for a random rule texture where it can be applied for all the buildings with the same height at once ?

cheers,
0 Kudos
8 Replies
JoanneO_Brien
Occasional Contributor
have you tried something like:
attr height = 10
const buildingtex = fileRandom("assets/buildingtex*")

Lot--> Building(comp.index)
Building(myIndex)--> case height == 10 : Texture1
                              else: Texture2.
Texture1-->setupProjection(0, scope.xy, scope.sx, scope.sy)
  projectUV(0) 
                           texture(buildingtex)


The fileRandom will choose random textures within your path, when they've all got the same name and different numbers you add the name at the start and the * indicates the numbers that will change.

Hope that helps! :)
ziadfilfili
New Contributor II
Many thanks for the assistance.
I tried the code you gave but it didn't work.
So i tried the script found within the image attachment.

I have 16 facade textures in my assets that i want to apply to all the buildings in my scene randomly.

I got something to work out.
But what I really want is to associate ONE Facade texture for the 4 sides of the building and not different facade textures for every side.

How can I generate that?!
0 Kudos
MatthiasBuehler1
Frequent Contributor II
Hi !

then, you forgot to define the filesearch as a 'const'.

const buildingtex = fileRandom("assets/buildingtex/myFacade*.jpg")
0 Kudos
BenHaas
New Contributor
Is there any way to randomize color?
0 Kudos
JoanneO_Brien
Occasional Contributor
If you have specific colours you want you could randomise using the Stochastic Rule where you assign a percentage for each colour, then it can randomly pick between those colours. Alternatively have you looked at the colorRamp operation? I haven't played around much with this myself yet but I might be useful for your query, check it out in the help files anyway.

hope that helps! :)
0 Kudos
floLang
New Contributor II
Very interesting ! but lets say, i want to use a random facade rule instead of a texture - how would that be managed ?
greetings
0 Kudos
JoanneO_Brien
Occasional Contributor
you can also do randomised colour by
color(rand(0,1),rand(0,1),rand(0,1))


Again with the facade rules you could always use a stocastic function where you say
Facade1--> ...
Facade2-->...
Facade3-->...
RandomFacade--> 30% : Facade1
30% : Facade2
else: Facade3
0 Kudos
boycepostma
New Contributor
Hi !

then, you forgot to define the filesearch as a 'const'.

const buildingtex = fileRandom("assets/buildingtex/myFacade*.jpg")



OH MAN! Thanks for this Matthias (though way old).

I was searching forever to find a way to keep a random texture the same throughout the CGA code. The help contents needs a little ProTip specifying this.

-ap-
0 Kudos