Select to view content in your preferred language

Window textures

3487
7
Jump to solution
10-28-2014 06:03 AM
IonutAlixandroae
Deactivated User

Hello,

I have a question regarding writing a rule for windows texturing.

I have 1 folder ("WindowTextures") with 3 subfolders("Group1","Group2" and "Group3") and each "Group" folder contains a number of jpgs  that are textures for windows named "window.1", "window.2", "window.3" etc.

I need a rule that applies random jpgs from a "Group" folder to  a building`s windows, but also be able to change the group jpgss from the inspector.

This also applies to wall textures because I have several jpgs separated on material type - a folder for brick material with several jpgs, a folder for wood material with several jpgs etc ( I have like 4 or 5 material type) and I want to apply that rule to multiple buildings and to have random brick texture but also random material texture.

Is it possible?

Thanks !!

Ionut

P.S. - I attached the rule

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Try something like this:

# Pick your group in the inspector, or move it to some internal logic.

@Range("Group1","Group2","Group3")

attr windowGroup = "Group1"

# Make the random file path for the window textures.

const windowTextureRandomPath = "WindowTextures/" + windowGroup + "/window.*.jpg")

# Make the texture be an attribute, so you may override.

attr randomWindowTexture = fileRandom(windowTextureRandomPath)

# Let me know if this works for you. :)

Chris

View solution in original post

7 Replies
by Anonymous User
Not applicable

Try something like this:

# Pick your group in the inspector, or move it to some internal logic.

@Range("Group1","Group2","Group3")

attr windowGroup = "Group1"

# Make the random file path for the window textures.

const windowTextureRandomPath = "WindowTextures/" + windowGroup + "/window.*.jpg")

# Make the texture be an attribute, so you may override.

attr randomWindowTexture = fileRandom(windowTextureRandomPath)

# Let me know if this works for you. :)

Chris

IonutAlixandroae
Deactivated User

It`s perfect Chris!! Thanks!!

The thing is that it gives me random textures from one group. If I apply the rule I need to have random textures from random group.

(Eg. I have Brick,Cement and Wood Groups, each one of them with 5 textures. If I apply the rule on 3 lots, it gives me random textures from BrickGroup, instead maybe random texture from Brick, Wood and Cement...)

Thanks!!!

0 Kudos
by Anonymous User
Not applicable

First I tried replacing line 03 with this:

attr windowGroup = "Group" + rint(rand(1,3))

Then I realized I got more twos than ones and threes. Can anyone guess why? ( about double)

So then I did this...

attr windowGroup = "Group" + groupNum

const groupNum =

  33%: "1"

  33%: "2"

  else:"3"

This ensures each gets roughly a third each. Of course you might like to change the percentages, which you can do in this case. Also, to see the random numbers change, make sure to use "Update Seed and Regenerate", rather than just "Generate".

Chris

0 Kudos
IonutAlixandroae
Deactivated User

I tried to do the same with texturing the roofs (each type) but something is missing and I can`t see any texture.

Can you check please?

I attached the rule

Thanks!!!

0 Kudos
by Anonymous User
Not applicable

Ionut, you don't need someone to look at your rule... You need to dive into debugging. Try getting well versed in using the Model Hierarchy window with the Inspect Model mode. Learn to use the print statement to see what attribute values are. Bypass rules by sending them to shorter test rules. Track through the code from the point you think is broken. Go backwards. See where it went wrong. Also, post the code in question along with a screen shot. That will help us all answer your questions without opening the CGA on our side.

That said, look at this part of your rule:

HipRoof -->

  roofHip(45) RoofMassScale

RoofMassScale is getting a duplicate of the current shape. You ARE getting a textured shape from the rest of the code, but it is covered up by the shapes from RoofMassScale.

Also, some of your roof code is using setupProjection with uvSet 1 - you need uvSet 2.

Chris

IonutAlixandroae
Deactivated User

I understand . Thank you for your help. So I will.

Thanks again!!

0 Kudos
by Anonymous User
Not applicable

To see textures, change:

HipRoof -->

  roofHip(45) RoofMassScale

To this:

HipRoof -->

  roofHip(45) # RoofMassScale (comment out RoofMassScale)

Because RoofMassScale is putting it's shapes right on top of the shapes generated by the rest of the HipRoofRule. You branch the code at that point. I'm just guessing on this, but I think if you move that RoofMassScale to the very end of the HipRoof rule, then that will work the way you want it. Just a guess.

0 Kudos