+ Reply to Thread
Results 1 to 5 of 5

Thread: Instance Export

  1. #1
    Robert Hexter
    Join Date
    Mar 2012
    Posts
    78
    Points
    5
    Answers Provided
    1


    0

    Default 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:

    Click image for larger version

Name:	ReportProblems.jpg
Views:	73
Size:	512.3 KB
ID:	13993

    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

    So,
    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.

    report=model.getReports()
    pprint.pprint(report)

    {'asset': ['/Example_Instance_City__2011_2/assets/stra_bld_41.obj',
    '/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()):

    {
    AssetUUID:{
    '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
    },

    AssetUUID:{
    '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,
    AssetUUID:{
    '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.
    Last edited by rhexter; 05-01-2012 at 08:10 PM.

  2. #2
    Matthias Buehler

    Join Date
    Oct 2011
    Posts
    1,676
    Points
    438
    Answers Provided
    140


    0

    Default 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.


    * * *

    btw.
    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.
    Last edited by matthiasbuehler; 05-02-2012 at 06:14 AM.
    _________________

    CityEngine Machinist

    * YOUTUBE CHANNEL : www.youtube.com/channel/UCNS4TLgToEDQiH9pi06ofOA
    * tutorial videos : http://forums.arcgis.com/threads/648...URCES-FAQ-HELP
    * Please use the rating buttons on the right side !

  3. #3
    Robert Hexter
    Join Date
    Mar 2012
    Posts
    78
    Points
    5
    Answers Provided
    1


    0

    Default 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:


    Code:
            ## 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)
    	center(xz)
    
    	## 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?
    Last edited by rhexter; 05-02-2012 at 10:57 AM.

  4. #4
    Matthias Buehler

    Join Date
    Oct 2011
    Posts
    1,676
    Points
    438
    Answers Provided
    140


    0

    Default 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 :
    Code:
    Lot -->
    	scatter(surface,3,uniform) { PutInstance }
    
    PutInstance -->
    	s(.5,.5,.5)
    	r(0,45,0)
    	center(xz)
    	i("builtin:cube")
    	
    	s(.001,.001,.001)
    	center(xz)
    	
    	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 :

    Code:
    from scripting import *
    
    # Get a CityEngine instance
    ce = CE()
    
    #globals
    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]
        
        if(model.getReports().has_key('xpos')):
            xPosArray = reports['xpos']
            yPosArray = reports['ypos']
            zPosArray = reports['zpos']
            
            i=0
            for o in xPosArray:
                fillList = []
                fillList.append (xPosArray[i])
                fillList.append (yPosArray[i])
                fillList.append (zPosArray[i])
                print fillList
                instancePointList.append(fillList)
                i += 1
    
        
    # Called after all shapes are generated.
    def finishExport(exportContextUUID):
        ctx = ScriptExportModelSettings(exportContextUUID)
        
        print instancePointList
    _________________

    CityEngine Machinist

    * YOUTUBE CHANNEL : www.youtube.com/channel/UCNS4TLgToEDQiH9pi06ofOA
    * tutorial videos : http://forums.arcgis.com/threads/648...URCES-FAQ-HELP
    * Please use the rating buttons on the right side !

  5. #5
    Matthias Buehler

    Join Date
    Oct 2011
    Posts
    1,676
    Points
    438
    Answers Provided
    140


    0

    Default Re: Instance Export

    oh, and the screenshot :

    Click image for larger version

Name:	InstancingScreen.png
Views:	41
Size:	107.0 KB
ID:	14057
    _________________

    CityEngine Machinist

    * YOUTUBE CHANNEL : www.youtube.com/channel/UCNS4TLgToEDQiH9pi06ofOA
    * tutorial videos : http://forums.arcgis.com/threads/648...URCES-FAQ-HELP
    * Please use the rating buttons on the right side !

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts