Building Rule with Texture

3570
9
10-20-2011 11:21 AM
Toni_ChristineNeumann
New Contributor
I m new with CityEngine, and also with this kind of scripting...
I found in the old forum this script for a rule file for a simple shape with a border on the roof:

attr height = 21
attr parapet_height = 2
attr parapet_width = .25

Lot --> extrude(height)Building

Building --> comp(f) { front : Facade | side : Sidefacade | top : Roof | bottom : Base}

Base --> NIL

Roof --> offset(-parapet_width)
comp(f) { inside: color("#fff000") I | border: O }

I --> t(0, 0, -parapet_height)
extrude (parapet_height) Rmass

Rmass --> comp(f) { vertical : Rside | bottom : Rbase | top : Rtop }

Rtop --> NIL


now i tried to combine it with texture on the roof. Somehow it doesnt work,
here is the script:

attr height = 21
attr parapet_height = 2
attr parapet_width = .25

Lot --> extrude(height)Building

Building --> comp(f) { front : Facade | side : Sidefacade | top : Roof | bottom : Base}

Base --> NIL

Roof --> offset(-parapet_width)
comp(f) { inside: color("#fff000") I | border: O }
(here i would like to change it for a texture, but than the roof doesnt work anymoore)

I --> t(0, 0, -parapet_height)
extrude (parapet_height) Rmass

Rmass --> comp(f) { vertical : Rside | bottom : Rbase | top : Rtop }

Rtop --> NIL


does anyone have a solution?
thanks
0 Kudos
9 Replies
MatthiasBuehler1
Frequent Contributor II
hi ..

I rewrote the complete example with proper code.

Of course the code is longer, but it also deals with all the issues correctly.

[ see also attached files ]

lemme know if you have questions.




attr buildingHeight = 20
attr facadeColor = "#ffdddd"
attr roofColor = "#444444"
attr roofInnerColor = "#eeeeee"
attr roofWallThickness = 0.3
attr roofWallHeight = 0.65

attr facadeTexDimHorizontal = 6
attr facadeTexDimVertical = 4

facadeTex = "assets/wall.c.06.jpg"
dirtTex = "assets/dirtmap.15.jpg"

Lot -->
 extrude (world.y, buildingHeight)
 comp(f) {side : Facade | top : Roof}

Facade -->
 # color
 color(facadeColor)
 # texture, UV set 0
 setupProjection(0, scope.xy, facadeTexDimHorizontal, facadeTexDimVertical) # scope is zUp after comp(f) !
 projectUV(0)
 texture ( facadeTex )
 # dirt, UV set 2
 setupProjection(2, scope.xy, '1, '1)
 projectUV(2)
 set (material.dirtmap, dirtTex )
 translateUV(2, rand(1), 0) # offset the texture slightly to the right. range between 0 and 1, "1 full texture tile".

Roof -->
 offset ( - roofWallThickness)
 comp(f) {inside : RoofSurface | border : RoofWallInner}

RoofSurface -->
 t(0,0,-roofWallHeight) # scope is oriented zUP after a comp(f), thus I move down in z !
 extrude(world.y, roofWallHeight)
 comp(f) {top : NIL | bottom : RoofFloor | all : RoofWallInner}

RoofFloor -->
 color(roofColor)
 setupProjection(2, scope.xy, '1, '1)
 projectUV(2)
 set (material.dirtmap, dirtTex ) 

RoofWallInner -->
 color(roofInnerColor)
 alignScopeToGeometry(zUp, 0, world.lowest)
 setupProjection(2, scope.xy, 10, 10) # choosing just any dimensions, I'm not scaling '1 here !
 projectUV(2)
 set (material.dirtmap, dirtTex ) 
 





matt
0 Kudos
MatthiasBuehler1
Frequent Contributor II
and here's a screenshot of how a simple generated model looks like.
0 Kudos
Toni_ChristineNeumann
New Contributor
Thank you very much!
0 Kudos
MarieSaldana1
New Contributor
I have a related question:

Does uv projection behave differently on different uvSets? For example, just by changing from 0 to 2 the tiling automatically changes, and the sides of the roof lose their texture (see attached screenshots)

Is it not possible to use the dirtmap channel if your facade is already broken into separate faces? I guess you're not supposed to be texturing at that point anyway.

Walls -->
alignScopeToAxes ()
setupProjection(0,world.xy,tile,tile,0)
texture(dirtTex) 
projectUV(0)
Walls.

Thanks!!!

Marie
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi Marie ! cool to meet you here too ! :)



Work in the CityEngine mostly uses either 1 UV channel ( ID 0 ) or 1 UV channels ( IDs 0 and 2 ).

So each UV set has it's own set of coordinates, how either the texture or the dirt map is projected onto the geometry.

So you can :
- tell your texture (ID 0) to repeat all 5 meters with
setupProjection ( 0, scope.xy, 5,5 )
- tell your texture (ID 0) to repeat exactly once on the scope of the shape (e.g. on a full facade)
setupProjection ( 0, scope.xy, '1,'1)
- tell your dirtMap (ID 2) to repeat all 5 meters with
setupProjection ( 2, scope.xy, 5,5 )
- tell your dirtMap(ID 2) to repeat exactly once on the scope of the shape
setupProjection ( 2, scope.xy, '1,'1)

or any other combination like :
setupProjection ( 0, scope.xy, '1,5) , ...

different texturing tasks just need different projections you must define.

ok ?

Please note that you can only port dirt maps only with either FBX or Collada file formats. All the other file formats do not support this type of setting up multiplied textures.
0 Kudos
MarieSaldana1
New Contributor
Thank you! :)

I think what I was doing wrong is that I also have to setup and project uvSet(0), even if I'm not using a texture on that channel, correct? Otherwise the the projection on uvSet(2) doesn't work.

Marie
0 Kudos
MatthiasBuehler1
Frequent Contributor II
Nope, you can use them independently of each other.

Though, you must make sure that the projection really corresponds to the scope orientation. I'll post a scope video in an other thread here about the scope.

so e.g. :
if your scope is zUp, the texture must be projected in x/y. if your scope is yUp (e.g. like on Lots), you need to project in x/z to see the textures correctly.



if you just want to use:

1) TEXTURES, you need to :
setupProjection ( 0 .. )
projectUV ( 0 ..)
texture (..)

2) TEXTURES AND DIRTMAPS, you need to :
setupProjection ( 0 .. )
projectUV ( 0 .. )
texture (..)
setupProjection ( 2 .. )
projectUV ( 2 ..)
set (material.dirtmap ..)
0 Kudos
MarieSaldana1
New Contributor
Ok, scope, etc. I think I get that.

What was confusing me I think is:

I cannot use texture() for uvSet(2), I must use set(material.dirtmap)

yes??? do I finally understand this? :p
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi ..

yes, this is true ! :)

texture() only accepts the UVs from UVset 0
and
set(material.dirtmap) only accepts UVs from UVset 2.
0 Kudos