How do I have a cga rule attribute retrieve and use a value from a particular source Layer, if I do not want to set a shapes attribute source manually in the Inspector?(I may want to use different image maps (sources) to control a particular attribute under different rule conditions)
just create a new Map Layer of the 'mapping type'. choose your image file and create an attribute in the dialog. once the layer has been generated, you can check (and edit) the layer attributes in the Inspector.
usually, I create mapped attributes based on the image brightness, then create a simple function which maps that value range from 0-1 to a desired range, e.g. 300 x brightness + 20
once this is created, point your CGA rule via the Attribute Connection Editor to the specific layer's target attr value.
don't forget to initialize the attr in your rule too ! (e.g. just attr mappedHeight = 0)
point your CGA rule via the Attribute Connection Editor to the specific layer's target attr value.
If I have this initialized in my rule:
attr mappedHeight = 0
how do I:
point your CGA rule via the Attribute Connection Editor
I am currently only understanding this to be a manual process of changing the shapes attribute source input within the Attribute Connection Editor? I would like to have the rule tell the shape what its specific layer/map and attribute of interest is, not do it myself.
I am confused because I want to, within my rule, have the rule determine the connection to which mapLayer:
//set/connect the shapes "mappedHeight" attribute, to the MapLayers attribute "mappedHeight", where MapLayer is determined by something else.. set(shape.mappedHeight, MapLayer.mappedHeight)
first step : check the following manual page, it shows the Connection Editor basics :
Help > Manual > Mapping Attributes > Mapping Attributes with Connection Editor
[ check the attr icon with the black triangle pointing in a rectangle ]
additionally : it is important to understand that CityEngine uses some heuristics to find the right connections automatically when a rule is assigned to a shape :
If you assign a rule e.g. to a 'Lot' via Drag'n'Drop, CityEngine checks if : 1st priority] an Object Attr exists for the initialized attrs. If so, the connection automatically is made to the Object Attr 2nd priority] a Map Layer attribute exists for the initialized attrs. If so, the connection automatically is made to the corresponding Map Layer attr 3rd priority] the Rule value is used
I hope this helps you further !
oh, and also good to know, the @StartRule annotation adapts some behavior : Once drag-n-dropped and a StartRule is defined within a cga rule file, the model generation is directly triggered ( great for demos ! ).