4 Replies Latest reply on May 3, 2012 8:11 AM by MBuehler-esristaff

    Instance Export

      So guys I think I'm having a problem with the data coming out of a report, here I use one instance building as an example:


      The image shows the placement of a single instance of a model,
      below image left: (green, yellow, blue highlights) show the report data dumped
      below image right: corresponding highlights snapshot of the report UI

      1) I see only one model placed in the viewport, the report thinks there are two models of the same type(in this case). I can understand there could be more than one model, as we could hypothetically have many objects placed along with this one model as further detail. This is not the case with this example.

      ..the larger issue since we can have more than one model

      2) the format of the dictionary received back from the python cmd appears incorrect, instead of a dictionary of dictionaries we have this funky dictionary with lists.
      I initially concluded that each element of each list (example element [0] in each list) for each key (xpos, xrot, etc) would correspond to each model (asset[0] or asset[1]),
      however this does not appear to be the case as the list elements indices are mixed up when compared to the data in the report within the inspector (the min and max values). Since the min max values are not the same, I conclude this to be the reason for the two elements in each key within the dict.


      {'asset': ['/Example_Instance_City__2011_2/assets/stra_bld_41.obj',
      'xpos': [-196.50341796875, -25.73431396484375],
      'xrot': [0.0, 0.0],
      'xscale': [1.2198159669490822, 0.04303470562802464],
      'ypos': [188.96078491210938, 188.9607925415039],
      'yrot': [28.259279251098633, -24.37846565246582],
      'yscale': [1.19670941334878, 0.022371693164823615],
      'zpos': [30.52911376953125, 4.428466796875],
      'zrot': [0.0, 0.0],
      'zscale': [1.173602692726634, 0.0017086774440385223]}

      3) There appears to be an inconsistency, I could not use the data in this dict to transfer to a gameEngine, i need to ensure that the values that are in the min max columns for each entry are at a consistent indices in the lists for each key in the dict that is generated (I have 27k instances in my scene I would not want to check manually):

      'asset': element[0]
      'xpos': element[0] = MinValue from report
      'yrot': element[0] = MaxValue from report
      'zscale': element[0] = MaxValue from report

      Is this a bug?

      A Suggestion
      It may be more appropriate to generate something like this as output for the dict from the report function (report=model.getReports()):

               'asset': '/Example_Instance_City__2011_2/assets/stra_bld_41.obj',
               'xpos': -196.50341796875, 'xrot': 0.0, 'xscale': 1.2198159669490822,
               'ypos': 188.96078491210938, 'yrot': 28.259279251098633, 'yscale': 1.19670941334878,
               'zpos': 30.52911376953125, 'zrot': 0.0, 'zscale': 1.173602692726634

               'asset': '/Example_Instance_City__2011_2/assets/stra_bld_41.obj'],
               'xpos': -25.73431396484375, 'xrot': 0.0, 'xscale': 0.04303470562802464,
               'ypos': 188.9607925415039, 'yrot': -24.37846565246582, 'yscale': 0.022371693164823615,
               'zpos': 4.428466796875, 'zrot':0.0, 'zscale':0.0017086774440385223,
                     'asset': '/Example_Instance_City__2011_2/assets/stra_window_3.obj'],
                     'xpos': [-25.73431396484375, ....], 'xrot': [0.0, ....], 'xscale': [0.04303470562802464, ...]
                     'ypos': [188.9607925415039, ....], 'yrot': [-24.37846565246582,...], 'yscale': [0.022371693164823615, ....],
                     'zpos': [4.428466796875, ...], 'zrot':[0.0, ....], 'zscale':[0.0017086774440385223, .....]
      Nest the dicts, keep the lists for multiple instances of the same asset:

      A function on the user side, externally, can then recursively search with in each dict to look for an AssetUUID key to access those nested instances if required.
        • Re: Instance Export
          an initial input.

          it may happen that the report is not perfectly up to date if you see there's 2 entries when there should be just 1.

          try 'ctrl-shift-g' to set a new seed, then have a fresh look at the reports tab.

          * * *

          just recently I asked one of the devs about the output structure of the reports and he mentioned that this is the most generic form for all possible reporting uses. thus, one has to rearrange the reported data using Python for the specific need using the script based exporter method within the finishModel() method. since reporting is supposed to be generic, the output of the reported data is not given back 'layouted' specific for transformation/rotation/scaling usage.

          * * *

          all reported values are stored in a list, one value after the other. The 'Reports Tab' just reads that list and displays some statistic data of that list, but not all of course.
          • Re: Instance Export
            Okay then lets simplify this.

            Currently I do the following in my cga report, this report data is then read from a python export script, this report should be being generated at export time for each model that gets passed over by the script based exporters finishModel function:

                    ## report instance ID
                    report("asset", asset) 
                    ## scale and center scope
             //s(0.001,'1, 0.001) center(xz)
             s((scope.sx/scope.sx)/100,'1, (scope.sz/scope.sz)/100)
             ## report (convert) position in world coords
             report("xpos", convert(x, scope, world, pos, 0,0,0))
             report("ypos", convert(y, scope, world, pos, 0,0,0))
             report("zpos", convert(z, scope, world, pos, 0,0,0))

            1) How do I get accurate transformations for a placed model instance?

            I want this:
            'ypos': [188.96078491210938, 188.9607925415039] //close enough
            'xscale': [9.192412351176117e-05, 9.192412351176117e-05],
            Not this:
            'yscale': [1.2100649279297098, 0.02422198033067778]
            'xpos': [-196.509521484375, -25.73651123046875] // huh?

            I don't want to see:
            min and max values that differ,
            I do not understand Min and Max transformations that differ on a singular assets transformation..

            2) When I do this is this applying to the bounding box or just the data that is being rendered, out of interest?
            • Re: Instance Export
              I'll reply more soon, have to run.

              here's how I usually report positions :

              try on a simple quadratic Lot for example. check the mouse coordinates via the Navigation Display in the viewport.

              CGA :
              Lot -->
               scatter(surface,3,uniform) { PutInstance }
              PutInstance -->
               report("xpos", convert(x, scope, world, pos, 0,0,0))
               report("ypos", convert(y, scope, world, pos, 0,0,0))
               report("zpos", convert(z, scope, world, pos, 0,0,0))

              Python :

              from scripting import *
              # Get a CityEngine instance
              ce = CE()
              instancePointList = []
              # Called before the export start.
              def initExport(exportContextUUID):
                  ctx = ScriptExportModelSettings(exportContextUUID)
              # Called for each shape before generation.
              def initModel(exportContextUUID, shapeUUID):
                  ctx = ScriptExportModelSettings(exportContextUUID)
                  shape = Shape(shapeUUID)
              # Called for each shape after generation.
              def finishModel(exportContextUUID, shapeUUID, modelUUID):
                  ctx = ScriptExportModelSettings(exportContextUUID)
                  shape = Shape(shapeUUID)
                  model = Model(modelUUID)
                  reports = model.getReports()
                  fillList = [] # vector as list [x,y,z]
                      xPosArray = reports['xpos']
                      yPosArray = reports['ypos']
                      zPosArray = reports['zpos']
                      for o in xPosArray:
                          fillList = []
                          fillList.append (xPosArray[i])
                          fillList.append (yPosArray[i])
                          fillList.append (zPosArray[i])
                          print fillList
                          i += 1
              # Called after all shapes are generated.
              def finishExport(exportContextUUID):
                  ctx = ScriptExportModelSettings(exportContextUUID)
                  print instancePointList
              • Re: Instance Export
                oh, and the screenshot :