I am trying to use Carl Besters CCTV code. I have the cameras in CityEngine but when I run the cga script the viewshed is rotated by 180 degrees. So basically the narrow part is rotated around and the wide part is centered on the camera. Anyone have any suggestions? Code is below.
/**
* File: CCTV2.cga
* Created: 8 October 2015 12:02:25 GMT
* Author: Carl Bester
*/
version "2017.1"
#####################################
##Attributes
attr viewObject = "models/WebCamView.dae"
@Hidden
#The elevation of the camera
attr Elevation = 50
#The maximum distance range of the camera
attr ViewLength = 150
#The optical viewing angle of the camera
@Range(10,120)
attr CameraAngle = 90
#Azimuth direction of the camera
@Range(0,359)
attr Direction = 0
#The vertical viewing range of the furthest point (from bottom to top of the screen
attr VerticalHeight = 50
#The Calculated width of the scene
@Hidden
attr Width = getWidth(ViewLength)
#The vertical rotation of the camera view
@Range(0,90)
attr VerticalRotation = 20
#The actual azimuth value used to rotate the view. Internal Attributes
@Range (0,360)
@Hidden
attr HorizontalRotation = getRealDirection(Direction)
#####################################
##Functions
getWidth(x) = (tan(CameraAngle/2)*ViewLength)*2
getRealDirection(x) = -1 * (x + 180)
#####################################
##Rules
@StartRule
Lot--> Object
Object--> i(viewObject)
Rotate
Rotate--> rotate(abs, world,VerticalRotation,HorizontalRotation,0)
Scale
Scale--> s(Width,VerticalHeight,ViewLength)
center(xy)
set (material.color.a ,0.5)
Yellow
#####################################
##Colors
Yellow--> color("#FFFF00")
I can't tell what the problem is, but if your object should be rotated 180 degrees, then use the r() operation to rotate it.
https://doc.arcgis.com/en/cityengine/latest/cga/cga-r.htm
Hint: You can use the Model Hierarchy (Window -> Show Model Hierarchy -> Inspect Model -> click on shapes) to view the scope of your shapes at any point in the shape tree. This will help you determine which axis you need to rotate around.
Thank you for responding to the above post. I realize it’s been a while since this topic was made, but I am currently attempting to use the same cga rules posted above for some camera visibility analysis. I am new to City Engine and its cga language / rules, and I have a couple of simple questions about the above cga ruleset.
Is the“WebCamView.dae” file above, the “viewobject” file, a simple triangle or pyramid model? Can I make this model by creating a pyramid-shaped multipatch in ArcGIS Pro and then do Multipatch to Collada geoprocessing? How does the ruleset take into account the location of the camera locations, or how do I input camera locations into City Engine? Is each camera location its own model within the above collada file?
Also, I don’t understand the section above for the “Object” rule (towards the bottom). What does "i(ViewObject)" do to the attribute "viewobject"?
Also, what does "@Hidden" mean?
For the original poster, if I had to guess, I would attempt to find the problem by varying some of camera direction parameters. I find the "getrealdirection" function and the "Direction" attribute to be suspect for your case, based off of how the attribute HorizontalRotation is calculated in the ruleset.
Thank you,
Chris C
I can only answer some general cga questions.
The i() operation inserts an asset. In this case, the asset is a .dae file, but the i() operation accepts other types as well.
insert operation—CGA | Documentation
@Hidden is an annotation written before an attribute that makes that attribute not appear in the Inspector. It does not affect the outcome of the code. It only controls whether or not an attribute will appear in the Inspector.
Thank you for the response, Cheryl. So the viewobject does start as a .dae file, and the i() operation is just a way to insert the shape at the right place within the rule. That makes sense.
Is there anyone I might be able to contact regarding my questions above concerning how the "viewobject" file above is created?
Thank you,
Chris C
Chris,
I had been working on this and the was on another project, and now I'm just now getting back on this. I still do not know CityEngine very well and have been asking the guy that did the original code lots of questions but just can't seem to get it to work. I have the original model that I received from him that I can shoot you. It'd be nice to have a fresh set of eyes take a look. If you want the model just shoot me an e-mail at richard.leeson87@gmail.com. Also the original web page I found the original this on is at http://urban-scene.blogspot.com/2016/01/cityengine-arcgis-pro-combine-to-show.html.
Hi everyone who stumbles across this post,
Rich L and I found that for the CCTV ruleset to work properly the initial model (.dae file) needed to be imported into CityEngine in a specific orientation. The Model Hierarchy window was useful for figuring out which initial orientation the model had to have for the CCTV ruleset to function properly. This rotation cannot be applied within the CCTV ruleset because of the manipulations to the model scale and direction that occur within the ruleset. The way to get around this might be to build a model in a 3d modelling software, and create a unique model for each possible orientation of the model (six possible - like the faces of a square). Then attempt to apply each model within the CCTV ruleset and find the one that works properly.
Good luck,
Chris