Texture random and depending on

1830
3
Jump to solution
04-04-2013 01:18 AM
MichaelPrede
New Contributor
Hi all!

I have simple boxes and some textures:
leftrighttex1.jpg
leftrighttex2.jpg
leftrighttex3.jpg
...
frontbacktex1.jpg
frontbacktex2.jpg
frontbacktex3.jpg
.


I would like to texturize the boxes with following rule:

left and right side have the same random texture
than:
front and back side texture with the same id like left and right:
leftrightex1.jpg >> frontbacktex1.jpg
leftrightex2.jpg >> frontbacktex2.jpg

In my following test rule left and right side have random but different textures AND I've no idea how to select the front/back texture depending on left/right texture.

Thanks a lot for help!

michael





[PHP]/**
* File:    test2.cga
* Created:
* Author:
*/

version "2012.1"

leftrighttex = fileRandom("assets/facades/textures/leftrighttex*.jpg")
frontbacktex = fileRandom("assets/facades/textures/frontbacktex*.jpg")

Lot -->
extrude(world.y, 10)
comp(f) { 0 : NIL | left : Leftright | right : Leftright | front : Frontback | back : Frontback}


Leftright -->
setupProjection(0, scope.xy, '1, '1)
texture(leftrighttex)
projectUV(0)
comp(f) { front : Frontback | back : Frontback}

Frontback -->
setupProjection(0, scope.xy, '1, '1)
texture(frontbacktex)
projectUV(0)

[/PHP]
0 Kudos
1 Solution

Accepted Solutions
MatthiasBuehler1
Frequent Contributor
Hi ..

try this :

I did not check the code, may contain an error, but gives you the idea :


 texPath = "assets/myTextures/" const textureIndex = rint(rand(1, 3))   @StartRule Lot -->     alignScopeToAxes(y)     s(1,1,1)     center(xz)     i("builtin:cube")     comp(f) {front : Face("front") | back : Face("back") | all: Face("other") }  Face ( sideSelector ) -->     case sideSelector == "front" || sideSelector == "back" :         setupProjection(0, scope.xy, '1, '1)         projectUV(0)         texture ( texPath + "frontback" + textureIndex + ".jpg" )     else :         DoSomethingElse.


Note that the actually used texture path is concatenated by different elements you're interested in.
Using a 'const' makes sure that you have a constant number value throughout the whole model.

Does this help ?

View solution in original post

0 Kudos
3 Replies
MatthiasBuehler1
Frequent Contributor
Hi ..

try this :

I did not check the code, may contain an error, but gives you the idea :


 texPath = "assets/myTextures/" const textureIndex = rint(rand(1, 3))   @StartRule Lot -->     alignScopeToAxes(y)     s(1,1,1)     center(xz)     i("builtin:cube")     comp(f) {front : Face("front") | back : Face("back") | all: Face("other") }  Face ( sideSelector ) -->     case sideSelector == "front" || sideSelector == "back" :         setupProjection(0, scope.xy, '1, '1)         projectUV(0)         texture ( texPath + "frontback" + textureIndex + ".jpg" )     else :         DoSomethingElse.


Note that the actually used texture path is concatenated by different elements you're interested in.
Using a 'const' makes sure that you have a constant number value throughout the whole model.

Does this help ?
0 Kudos
MichaelPrede
New Contributor
error correction... wow it works!

Thanks a lot!

michael
0 Kudos
MatthiasBuehler1
Frequent Contributor
I've fixed the bracket errors above.
0 Kudos