Conditional Rules for Assets

2543
1
07-10-2013 03:33 PM
JoanneO_Brien
Occasional Contributor
Hi

So what I'm trying to do is create a model that can choose random brick textures, and then when it selects those brick textures I want it to be able to determine the setupProjection sizes from set sizes depending on which textures it's chosen eg:

attr wall_tex = fileRandom("assets/monier/monier_bricks/*Mortar.jpg")
attr wall_normal = substring(wall_tex,0,find(wall_tex,"-",1))+"-normal.jpg" 
attr wall_spec = substring(wall_tex,0,find(wall_tex,"-",1))+"-specular.jpg"

const frontTexWidth =  case wall_tex == ("assets/monier/monier_bricks/*Metro*Mortar.jpg") : 1.44
 case wall_tex == ("assets/monier/monier_bricks/*Mezzo*Mortar.jpg") : 1.44
 case wall_tex == ("assets/monier/monier_bricks/*Presto*Mortar.jpg") : 2.16
 case wall_tex == ("assets/monier/monier_bricks/*Block*Mortar.jpg") : 1.8
 else : 5.76 
const frontTexHeight =  case wall_tex == ("assets/monier/monier_bricks/*Metro*Mortar.jpg") : 0.84
 case wall_tex == ("assets/monier/monier_bricks/*Mezzo*Mortar.jpg") : 1.29
 case wall_tex == ("assets/monier/monier_bricks/*Presto*Mortar.jpg") : 1.72
 case wall_tex == ("assets/monier/monier_bricks/*Block*Mortar.jpg") : 1.032
 else : 1.72

Wall -->
 setupProjection(0, scope.xy, frontTexWidth,frontTexHeight) 
 texture(wall_tex)
 projectUV(0)
 projectUV(1)
 set(material.specularmap, wall_spec)
 projectUV(3)
 set(material.normalmap, wall_normal)  


Here my specular and normal maps don't seem to be working either.

I then want to be able to select random window textures, but using a conidtional rule where the window type can be small or large, and depending on what it chooses:
@Range ("small","large")
attr winType = "" # This isn't defined in my object attributes but I want it to randomally choose one type for each house.

attr window_tex  = case winType == "small" : fileRandom("assets/window/houseWindow/windowSize1_*.JPG")
 case winType == "large" : fileRandom("assets/window/houseWindow/windowSize2_*.JPG")
 else : fileRandom("assets/window/houseWindow/windowSize1_*.JPG")


Unfortunately though it only seems to choose one window ie one small window for the whole model rather than a selection of small windows.

Thirdly I'd like to insert my roof texture depending on random files and again adjust the setupProjection depending on the file sizes:
@Range("Gable","Hip","Flat")
attr RoofType = ""

attr roofAngle = 22.5
attr gableOverhang = 0.4
attr hipOverhang = 0.5

const rooftile_tex   = 50% : fileRandom("assets/monier/monier tiles/portuguese*-normal.png")
 else : fileRandom("assets/monier/monier tiles/hacienda*-normal.png")

const roofTexWidth =  case rooftile_tex == ("assets/monier/monier tiles/portuguese*-normal.png") : 2.0
 else : 2.1
const roofTexHeight =  case rooftile_tex == ("assets/monier/monier tiles/portuguese*-normal.png") : 2.0
 else : 2.54

Roof -->
 case RoofType == "Gable" : 
 roofGable(roofAngle, gableOverhang, gableOverhang) # roof angle and overhang
 s('1,Roof_Height,'1) # scale to the correct height
 setupProjection(0, scope.xz, roofTexWidth, roofTexHeight)
 texture(rooftile_tex)
 projectUV(0)
...

I haven't placed all the code but hopefully enough to give you an idea of what I want...except again it's not working quite right! It doesn't seem to be registering my delection of textures, so I was wondering if that naming convention was correct or not for the selection?

lastly I have doors...which do come in beautifully but alas only seem to be producing the narrow doors and not the wide ones, so I'm wondering what I'm missing?
@Range ("singleDoor","doubleDoor")
attr doorType = "" # This isn't specified in object attr but want a random selection of either

attr frontdoor_tex  =  case doorType == "singleDoor" : fileRandom("assets/Doors/frontDoors/singleDoor_*.JPG")
 case doorType == "doubleDoor" : fileRandom("assets/Doors/frontDoors/doubleDoor_*.JPG")
 else : fileRandom("assets/Doors/frontDoors/singleDoor_*.JPG")

const doorWidth = case doorType == "singleDoor" : 0.97
 case doorType == "doubleDoor" : 15
 else : 0.97
const doorHeight = 2.04  

Entrance -->
  split(x) { ~1: SolidWall
  | doorWidth: split(y){doorHeight : Door | ~2: SolidWall}
  | ~1: SolidWall}

Door -->
 s('1,'1,0.1)
 t(0,0,-0.2)
 texture(frontdoor_tex)
 i("builtin:cube")


I hope I've put enough info in for you to understand...and sorry for the length! Just wanting to get a bit more complex in my models now!
0 Kudos
1 Reply
MatthiasBuehler1
Frequent Contributor
Hi,


case wall_tex == ("assets/monier/monier_bricks/*Metro*Mortar.jpg")


is valid syntax, but it's not doing the wildcard search I assume you hope it does.
[ means this checks if the file actually really contains a asterisk (*) character in the name ]


wildcards are only allowed specifically in the ce.lib functions, e.g. fileRandom(), fileSearch() and such.

thus you need to find an other way to check the wall_tex for your purposes.

can you track this down ?

Matt
0 Kudos