Street texture

692
5
12-20-2011 02:47 PM
by Anonymous User
Not applicable
Original User: Zaldan

Hi Matt!

I have another texture question... different issue I think. The textures look weird on the streets (the textures on the building models are fine) this is after I made a new scene in which the model is geolocated (far from the center). Could this have something to do with it? Other than that there are no changes and it was working fine before. I'm also using a better computer from the one I was having problems with previously.

Let me know if it is something obvious or not. Otherwise I am very pleased with CE2011 :)

I'm attaching an image with the builtin uv test applied, with the texture applied and the texture map itself.

Thanks,

Marie
0 Kudos
5 Replies
MatthiasBuehler1
Frequent Contributor II
hey there !

this could indeed be an issue with the scene coordinate system.

Can you check the code whether the UV projection of the color texture contains 'world' ?

Something like :
setupProjection(0, world.xz, 586, 442)

lemme kno-hooow. :)
0 Kudos
by Anonymous User
Not applicable
Original User: Zaldan

It does, actually - the code looks like this:

StreetTexture(size) -->
setupProjection(0,world.xz,size,size,0.2) projectUV(0)
setupProjection(2,world.xz,size*5,size*5,0.2) projectUV(2)
texture(streettex)
set(material.dirtmap, dirttex)

In the same scene I tried creating a new street network at the center and applied the rule - textures looked fine. The shape generation had problems near the origin though. Seems like the whole model is in one coordinate system and the street texture is in another...

Thanks and happy pre-holidays :)
0 Kudos
MatthiasBuehler1
Frequent Contributor II
hi !

I can reproduce it too.

I have forwarded it to the devs, ok ?

I'll let you know what this is about precisely. I have the feeling, but only they know for sure .. ;)


chocolate cheers !
0 Kudos
by Anonymous User
Not applicable
Original User: decrement

Hi Zaldan,
your suspicion was right - the model generation happens in a local coordinate system and is immune to numerical problems due to large coordinates. In contrast, the "world" selector in the setupProjection() operation forces the usage of absolute "CityEngine CS" coordinates which can give numerical problems if coordinates are large (6 digits or larger).

There are two workarounds which should help you achieve your goals:

Workaround 1:

  1. Align the scope to the CityEngine CS coordinate axes

  2. use scope-relative setupProjection and add an offset based on the global position



[INDENT]
attr streettex = "builtin:uvtest.png"

texOffsetX(size) = getGeoCoord(X) % size
texOffsetZ(size) = -getGeoCoord(Y) % size

StreetTexture2(size) -->
 alignScopeToAxes()
 setupProjection(0,scope.xz,size,size, -texOffsetX(size), -texOffsetZ(size)) 
 projectUV(0)
 texture(streettex) 
[/INDENT]


Workaround 2:

  1. align the scope to the CityEngine CS coordinate axes

  2. use scope-relative setupProjection

  3. translate the uv coordinates (after projection!) by an offset based on the global position



[INDENT]
attr streettex = "builtin:uvtest.png"

texOffsetX(size) = getGeoCoord(X) % size
texOffsetZ(size) = -getGeoCoord(Y) % size
 
StreetTexture3(size) -->
 alignScopeToAxes()
 setupProjection(0,scope.xz,size,size) projectUV(0)
 translateUV(0, texOffsetX(size) / size, texOffsetZ(size) / size)
 texture(streettex)
[/INDENT]


Workaround 1 is preferable because it encodes the translation into the projection matrix, while in workaround 2 the offset gets added to the texture coordinates of every vertex.
Both approaches work if you use a meter-based coordinate system. If your scene coordinate system is  feet-based, you need to account for that:
[INDENT]
const f2m = 0.3047996       
texOffsetX(size) = (getGeoCoord(X)*f2m) % size
texOffsetZ(size) = (-getGeoCoord(Y)*f2m) % size
[/INDENT]
The reason is that everything in CGA happens in the meter-based CityEngine CS - but the getGeoCoord() function is bound to the selected coordinate system.

I hope that sets you up
greetings
Decrement
0 Kudos
MarieSaldana1
New Contributor
Thank you. Workaround 2 actually was better for me because it tiles the textures properly, whereas #1 kept the texture size as '1.

Thanks again!

Marie
0 Kudos