How can I get different floors of a building to align to terrain?

1664
1
06-23-2016 12:59 PM
JavadSalimi
New Contributor III

I would like the different floors of a particular building to align to the terrain but when I use the align to terrain feature (with translate to average and heightmap equal to my terrain (dtm), the upper floors are not aligned relative to the floors beneath them which is what I would like them to do. Below is a before and after:

The bottom image shows all 4 floors collapsed on to the terrain...not the desired effect.

Thank you

0 Kudos
1 Reply
ThomasFuchs
Esri Regular Contributor

Hello Javad Salimi

Thank you for your question.

You can use the Python script below to align selected floor shapes of a building to a terrain.

First specify the ce.alignShapes() parameters as documented here​:

  • Align function
  • Heightmap
  • Offset
from scripting import *

# get a CityEngine instance
ce = CE()

# align shapes parameters
alignFunction = AlignShapesSettings.TRANSLATE_TO_MIN
heightmapName = 'Terrain_Satellite'
groundOffset = 0.0

# selected floor shapes
floors = ce.getObjectsFrom(ce.selection())

# get initial heights
initialFloorHeight = []
for f in floors:
    vertices = ce.getVertices(f)
    initialFloorHeight.append(min(vertices[1::3]))
initialGroundFloorHeight = min(initialFloorHeight)

# align floor shapes to ground 
settings = AlignShapesSettings()
settings.setHeightmap(heightmapName)
settings.setAlignFunction(alignFunction)
for i in xrange(0,len(floors)):
    settings.setOffset(groundOffset + initialFloorHeight - initialGroundFloorHeight)
    ce.alignShapes(floors, settings)