Select to view content in your preferred language

Tiling roof using CGA for better texture overlay

875
1
06-14-2022 10:11 AM
KaleiOliver_utsa
New Contributor

Very new to CityEngine, especially the code. I am trying to recreate some archaeological architecture at a site in Peru and want the textures to mirror how the buildings actually looked, with a thatched gable roof. I have been writing code to generate this kind of building, but I am so incredibly inexperienced with writing CGA files. Everything I've got I learned from YouTube or the CGA helper. I am trying to use a jpg of a thatched roof texture to overlay on my gable roof, but I am struggling with the orientation. Right now, I have it in my code as :

Roof--> roofGable (20, 1, 1)
# color, uv set 0
setupProjection(0, world.zx, 8, 😎
texture(roof_tex)
// = set(material.colormap,roof_tex)
projectUV(0).

I saw in the CGA help that there is a tileUV function, but I haven't been able to figure it out with what that link gives me. 

 

What I am trying to accomplish is having the thatched roof jpg oriented the same way on all of the roof faces, but I assume I need to split the roof into different faces to achieve this. I think that is done with the comp function? But what are the different faces of the roof called in CGA? 

I will insert my code here and the photos of what it generates. Any feedback on my code is welcome, as I am really just starting from scratch here. 

 

In summary: requesting help with tileUV function and/or comp (?) splitting the roof faces. 

 

Thanks!

 

Code: 

/**
* File: Test_rule2rule.cga
* Created: 9 Jun 2022 18:02:40 GMT
* Author: spp566
*/

version "2021.0"


@Range (min=4,max=250,restricted=false)
#attributes
attr height = 10

#textures

const back_tex = "images/Textures/R.jpg"
const roof_tex = "images/Textures/thatched.jpg"
@File

 

@StartRule

Footprint -->
extrude (height) Building

Building -->
comp(f) {front: WallOne | left: WallTwo | back: WallThree | right: WallFour | top: Roof}


WallOne-->
# color, uv set 0
setupProjection(0, scope.xy, 5, 5)
texture(back_tex)
// = set(material.colormap,back_tex)
projectUV(0)

WallTwo-->
# color, uv set 0
setupProjection(0, scope.xy, 5, 5)
texture(back_tex)
// = set(material.colormap,back_tex)
projectUV(0)

WallThree-->
# color, uv set 0
setupProjection(0, scope.xy, 5, 5)
texture(back_tex)
// = set(material.colormap,back_tex)
projectUV(0)

WallFour-->
# color, uv set 0
setupProjection(0, scope.xy, 5, 5)
texture(back_tex)
// = set(material.colormap,back_tex)
projectUV(0)

Roof--> roofGable (20, 1, 1)
# color, uv set 0
setupProjection(0, world.zx, 8, 😎
texture(roof_tex)
// = set(material.colormap,roof_tex)
projectUV(0)

0 Kudos
1 Reply
CherylLau
Esri Regular Contributor

You could use the horizontal and vertical selectors in a comp split to select the bottom face of the roof (which is hidden inside the building, so I NIL it) and the vertical roof pediment sides (which I made a Wall).  The remaining faces (all) go to RoofFace which sets up the projection for the roof texture so that it aligns with the roof eave edges (by choosing scope.xy in this case).

 

Roof -->
	roofGable(20, 1, 1)
	comp(f) { horizontal: NIL
			| vertical: Wall
			| all: RoofFace }

Wall -->
	setupProjection(0, scope.xy, 5, 5)
	texture(back_tex)
	projectUV(0)
	
RoofFace -->
	setupProjection(0, scope.xy, 8, 8)
	texture(roof_tex)
	projectUV(0)

 

Note that this solution will not work for all gable roofs.  If the roof slope is too steep, the slanted faces will get categorized as vertical.  Similarly, if the roof slope is too flat, the slanted faces will get categorized as horizontal.  Unfortunately, I don't have a solution that would work all the time.

0 Kudos