How to Split Scene into Smaller Areas at Export?

3230
2
04-21-2016 03:46 PM
ThomasMoore6
New Contributor II

I need to split the entire scene into 512m or 256m blocks when I export it to fbx. It doesn't have to be perfect, but I'm trying to avoid copying and pasting graphs, blocks, and shapes to different layers in the scene and exporting the layers one at a time (which is the only way I could come up with on the fly). Now that I have time, I'm hoping someone here can set me on the right path to make this work.

Tags (3)
0 Kudos
2 Replies
ThomasFuchs
Esri Regular Contributor

Hello Thomas,

you can use the CityEngine Python Scripting Interface to automatically export to small patches of your scene.

The code example below creates 4 patches and should be a good starting point:

def checkInside(shape,xMin,xMax,zMin,zMax):
    vert = ce.getVertices(shape)
    for i in xrange(2,len(vert),3):
        if (xMin <= vert[i-2] <= xMax) & (zMin <= vert <= zMax):
            return True
    return False

def exportPatch(shapes,xMin,xMax,zMin,zMax):
    exportSettings = FBXExportModelSettings()
    exportSettings.setBaseName("fbx_batchexport_"+str(xMin)+"_"+str(zMin))
    exportShapes = []
    for shape in shapes:
        if checkInside(shape,xMin,xMax,zMin,zMax):
            exportShapes.extend([shape])
    if len(exportShapes):
        ce.export(exportShapes, exportSettings)
        
def iterate():
    shapes = ce.getObjectsFrom(ce.scene(),ce.isShape)
    patchSize = 256
    xMin = 0
    xMax = 512
    zMin = 0
    zMax = 512
    for x in xrange(xMin,xMax,patchSize):
        for z in xrange(zMin,zMax,patchSize):
            exportPatch(shapes,x,x+patchSize,z,z+patchSize)
ThomasMoore6
New Contributor II

Sorry for the late response, I've been on other projects for a while.

I'm still relatively new to CE, but I'm getting up to speed fast.

I had a few hours to make some attempts to the script, but alas, it doesn't seem to be splitting anything. I feel like I'm missing something somewhere.

I tried it as a standalone batch script and from the FBX export window (added it to the script line). I get more warnings while just running the batch, but nothing big. When I try to export roads with the default CompleteStreets.cga example script applied as a rule, it doesn't export anything at all.

Is there anything I can post to help? I'm going to keep trying.

0 Kudos