AnsweredAssumed Answered

Controlling geometry naming and hierarchy of FBX Export from CityEngine

Question asked by virtualarchitectures on Jan 31, 2019

I'm trying to export an FBX from CityEngine and assign IDs from the shape attributes to the shapes in such a way that each 3D object within the model has the correct IDs as its name when imported into 3rd party software such as Unity. I have a working solution using a python script (see below) but it doesn't fully meet my requirement.

 

Code is also available on GitHub: CityEngine FBX Export with Object IDs.

 

'''
Created on 12 Apr 2018
@author: Liam O'Sullivan
Edited on 14 Jan 2019
@editor: Oliver Dawkins
'''
from scripting import *

# get a CityEngine instance
ce = CE()


def export(objects):
    dir = "C:/CityEngineExport/"
    name = "CityEngineExport"
    settings = FBXExportModelSettings()
    settings.setBaseName(name)
    settings.setOutputPath(dir)
    settings.setMeshGranularity("AS_GENERATED")
    settings.setCreateShapeGroups(True)
    settings.setFileType("BINARY")
    ce.export(objects, settings)

if __name__ == '__main__':

    objects = ce.getObjectsFrom(ce.scene, ce.isShape)

    for o in objects:
        tempID = ce.getAttribute(o, 'OBJECTID')
        objID = str(tempID).replace('.0', '')

        #sets the name of the shapes in the project
        ce.setName(o, '' +str(objID))

    export(ce.getObjectsFrom(objects))
pass

 

This script reads a specific object attribute, in this case OBJECTID, and assigns that value as the name of each object. The script then exports the collection of named objects to an FBX file. The script assumes that the directory specified for the export already exists e.g. dir = "C:/CityEngineExport/". The file will be exported with the specified file name e.g. name = "CityEngineExport".

 

When I import the data into Unity, the geometry for each object is nested within an empty game object. Ideally the named object and the geometry would be at the same level in the hierarchy. Is there a better way to achieve this when exporting an FBX file from City Engine.

 

Unity hierarchy

 

Many thanks.

Outcomes