I’m working on an extension using both Ruby and the Sketchup SDK. I’ve run into a roadblock regarding Geolocated models that have a true north offset specified.
How does one access the True north offset value from the SDK. I see there is an SULocationSetNorthAngle but no corresponding SULocationGetNorthAngle. When I query the models GeoReference attribute dictionary, there is something called GeoReferenceNorthAngle but this value appears to be the magnetic declination for the specified location - not the NorthAngle offset that the content creator specified. My question is how do I access the value of the TrueNorth offset that the user specified.
When I access the models geometry (i.e. SUFaceGetVertices), I observe that the vertex locations have all been rotated by the north angle offset. This is highly annoying as the extension requires the geometry to be in the original models coordinate system (the red, green, blue axes of the model). Is there a way to get the vertexes in the original coordinate system?
The NorthAngle value in SUShadowInfoRef appears to be a small angle - perhaps an offset between map grid north and true solar north. Curiously, there does not seem to be anything in the ShadowInfo that corresponds to the user input rotation value.
I was however able to find the correct value in the “SiteContext” attribute dictionary. In that dictionary, there are two values: ModelRotation and AxisAngleAtGeolocation. In my limited tests, the values for these keys have been identical but do roughly correspond to what the user specified. I tried temporarily resetting these to zero (programmatically within the execution of the extension) to see if this would prevent the API from rotation the vertexes but no luck. It was however possible to de-rotate the values upon reading the vertexes back to the original model coordinate system once the rotation value was found.
A follow up question I would have is whether or not there is a difference between the two keys and which one should I use. Can I expect this behavior to continue through future versions of Sketchup.
Yup, that is the dictionary created by the Add Location (“habitat_site_context”) extension. It did not exist when all the geolocation was entirely native. So it is a recent addition (for SU2024 and higher, I think.)
The SiteContext dictionary only exists for the internals of Add Location.
When we set the geolocation we set both the ShadowInfo.NorthAngle as well as GeoReference.GeoReferenceNorthAngle (note that there is a comment in the code base that NorthAngle is the reliable one so don’t use the GeoReferenceNorthAngle).
This is complicated by the fact that the solar north plugin allows the user to change the north angle.
So what we do in Add Location is to calculate the north angle manually and prompt the user if it seemed they manipulated the NorthAngle with the solar north plugin.
How geolocation works with Add Location
When you open add location true north offset is pre filled with the true north at a position (a.k.a. NorthAngle and GeoReferenceNorthAngle), if you change this pre-set offset your model & model axis rotate in both add location as well as SketchUp. this rotation is stored in ProjectNorth, and is used to be able to check for consistency and being able to reset the model to its original state (via right click menu)
NorthAngle is NOT the magnetic declination
sorry for getting a bit technical.
NorthAngle is the offset between “up” or the green axis in and north, when you open AddLocation either for geolocation or importing context (map tiles, terrain buildings) you see a 2D map (using WGS84/Mercator projection) where north is always “up”, this map is angle preserving coming from first navigation on the sea, then on the street, but not distance preserving (which is what we need to import context geometry like terrain or map tiles accurately). So we need to convert to a different 2d representation of our globe which is UTM (universal transversal mercator), but in this representation north is not “up” anymore, north is at an angle (NorthAngle).
Possible Solution
I am no expert on the C API so I will give advice using ruby - I hope you can use that to translate to C without too much issue. You can get a transformation from the axes from the model and then invert it: Sketchup.active_model.axes.transformation.inverse then you can transform points or vectors to get the coordinates in the “original coordinate system”.
For example Sketchup.active_model. axes.xaxis.transform(Sketchup.active_model. axes.transformation.inverse) => Vector3d(1, -1.29684e-17, 0)