Is it possible to move a constraint map based on th xz coordinates of the current view?

925
4
09-11-2017 01:44 PM
NicolaiSteinø
Occasional Contributor

I would like to be able to automatically shift a map with a radial gradient (say black to white) for controlling the level of detail. If the center of the radial gradient is always right below my viewpoint, I could use the grey levels to change the level of detail as a function of the distance from the viewpoint. Could this be done with Python?

4 Replies
ThomasFuchs
Esri Regular Contributor

Hello Nicolai Steinø

Yes, this is possible with a function layer (reference point is the center).

Here is a simple CGA rule that colors buildings by LOD:

attr LOD = 0

@StartRule
Lot --> extrude(rand(10,30)) ColorByLOD

ColorByLOD -->
     case LOD > 3: color(1,0,0)
     case LOD > 2: color(1,1,0)
     case LOD > 1: color(0,1,0)
     else: color(0,0,1)

Make sure the rule attribute LOD is connected to the layer attribute:

When you move the camera, call the following python script:

from scripting import *

# get a CityEngine instance
ce = CE()

if __name__ == '__main__':
    
    l = ce.getObjectsFrom(ce.scene, ce.isLayer, ce.withName("'LOD"))[0]
    CameraPoI = ce.get3DViews()[0].getCameraPoI()
    ce.setAttributeLayerExtents(l, [CameraPoI[0],CameraPoI[2],3000,3000])
    ce.setLayerAttributes(l, "attr LOD = sin(u * 180) * sin(v * 180) * 4")
    
    sceneShapes = ce.getObjectsFrom(ce.scene, ce.isShape)
    ce.generateModels(sceneShapes, False)

Then your city should look like this:

NicolaiSteinø
Occasional Contributor

This is genuinely cool! Thanks a lot.

0 Kudos
AbeleGiandoso
Occasional Contributor

Amazing!

"Make sure the rule attribute LOD is connected to the layer attribute"

How do you do that?

0 Kudos
CherylLau
Esri Regular Contributor

In the Inspector, click on the drop down arrow next to the rule attribute (see Thomas's screenshot) -> Connect Attribute -> Layer attribute -> select LOD.