Using satellite imagery as roof textures in CityEngine

Before we start the code I used here came from a GIS mapping tutorial from CityEngine, I can’t seem to find the original page after them being merged with ESRI but you can see a cached copy of the page here.

First let us get some satellite imagery, I suggest you use an extract from an existing satellite imagery from your GIS. If you are taking the imagery from elsewhere you don’t need to follow all these steps…

  1. In ArcGIS — Draw a box using the Draw toolbar
  2. In ArcGIS — Select the underlying imagery in the Table of Contents right-click and select “Data –> Export Data”. Depending on what your are doing and the size of imagery you want you may want to use JPG and the settings below have worked for me. I suggest you experiment for the best results. I also suggest you export straight to the maps directory in your CityEngine project
  3. In CityEngine — Drag and drop from your maps directory into your CityEngine scene, it should come in under any data you already have. If it doesn’t check that in the Scene window the map layer does not have the eye crossed out also ensure that the show/hide map layers button is clicked.
  4. In CityEngine — Create a new rule file and copy this code in (be sure to change the relevant parts to your settings).
    # dimension of the satellite map
    const mapdimension_x = 1134.181 #change this to satellite image details
    const mapdimension_z = 939.650 #change this to satellite image details
    # offset of the satellite map
    const mapoffset_x = 597694.521 #change this to satellite image details
    const mapoffset_z = -3560369.907 #change this to satellite image details
    extrude(rand(3,15)) Mass
    Mass -->
    # split building mass into roof and side faces
    comp(f){top : Roof | side : Facade}
    Roof --> Rooftex
    Rooftex --> 
    setupProjection(0, world.xz, mapdimension_x, mapdimension_z) 
    set(material.colormap, "maps/SATELLITEIMAGENAME.jpg") #change this 
    translateUV(0, -mapoffset_x/mapdimension_x, -mapoffset_z/mapdimension_z) 
  5. In CityEngine — To get the x-size and x-offset numbers select the map layer in the Scene window (default location bottom left) and look at the Layer tab in the Inspector window (default right), copy these numbers to the const variables at the beginning of the rule file.
  6. In CityEngine — Now apply that rule (after changes to your shapes/lots) and generate your model!