CGA Code Lesson #4 – Texturing, Part 1: Projecting u,v Textures Onto x/y/z Scopes

CGA OPERATIONS COVERED

 setupProjection(0, scope.xy, '1, '1)

INTRODUCTION

Tutorial 7 is on Façade Modeling but where I got stuck was the part where they started to explain projecting textures onto shapes. I wanted a deeper understanding of the operations used in texturing, one that could not be gained by simply banging through the exercise. This post explains how we orient two dimensional images to three-dimensional shapes; a future installment will describe the rest of the texturing process. I couldn’t find a single, concise explanation anywhere, so here goes. I hope this saves you a lot of time.

Projecting textures onto surfaces is like shining a projector onto a screen except you’re aiming for one of the six faces of the “scope” cube (Figure 1) that surrounds a shape. Seen in Figure 1, the scope is an invisible bounding box that defines the shape’s maximum x,y and z extents. Each scope has its own set of x,y,z axes independent to those of a scene.

Figure 1: A scope and its axes

Image Axes (u,v)

Any image file (jpg, png or other) you project onto the scope has its own x,y,z axes called u, v and w – or since the image is two-dimensional, u and v.  CityEngine has a built-in “test pattern” image, uvtest.png (Figure 2) that you can call in a CGA rule with file name “builtin:uvtest.png”. The u,v axis of an image, labeled u=0, v=0 in the test pattern, is in the lower left corner. When you project an image onto a shape, you must designate where the u,v axis (u=0, v=0) meets the x,y,z axes. This is done in the setupProjection( ) operation.

Figure 2: The uvtest.png “test pattern”.

Let’s get an understanding of how the axes line up.  There are six possible axis combinations: xy or xy;  yx or yz;  zx or zy.   They are expressed in the setupProjection( ) operation as scope.** (example: scope.xy).   When we align u,v with scope.xy as in Figure 3, note how and where the two coordinate pairs meet.  Note also what happens to the projection in Figure 3b when the shape is extruded into three dimensions. All six combinations appear in Figure 4.

Figure 3: The uvtest.png “test pattern” aligned with the x,y axes of the scope (left) and seen after the shape is extruded (right).

Figure 4: The six possible alignments of u,v to the x/y/z axes. To see the x,y,z axes of the 3D shapes in CityEngine, click a shape, the Inspect Model button and the shape again.

The slide series visualizes the six possible alignments in even greater detail; the x/y/z axis combinations are indicated and a black arrow shows the direction of extrusion from the origin.

Use the CGA code below to create a cube and project the uvtest.png test pattern onto various x/y/z combinations.

# Modify the scope.xy parameter to change the 
# projection axes. Possible values: scope.xy,
# scope.xz, scope.yx, scope.yz, scope.zx, scope.zy 

StartCube -->
 primitiveCube(5,5,5)
 setupProjection(0, scope.xy, '1, '1)
 projectUV(0)
 texture("builtin:uvtest.png")

Leave a Reply

Your email address will not be published. Required fields are marked *