Set the alignment
Store, read and clear the 4×4 alignment matrix of a version, and let the server compute one from point pairs.
An Alignment moves, rotates and possibly scales a model version relative to the other models. It is one 4×4 matrix stored on the Version; nothing is recorded about which models were loaded when it was defined or which one it was aligned to. The viewers apply it in both LOCAL and GEO mode, and the BIM.works UI has an Align models tool and an Alignment section in the node popup (with MODEL_ALIGNMENT) that write the same matrix. Its Manual alignment moves and turns the whole loaded model with the same controls as moving objects (how-to/using-bimworks/edit-a-model#move-and-rotate): drag it, turn it on the ring or with Space, type exact values; Enter stores the stored alignment combined with that change.
Before you start#
You need a client with the model:write scope for setting and fs:read for reading, and the Vid of the version. The matrix is sixteen numbers in the storage order of the server's Matrix4d, column-major with the translation in elements 12, 13 and 14 (the WebGL convention), in millimetres.
The JavaScript SDK wraps setting and computing the matrix (client.geometry3d, Geometry3d). Over HTTP, UpdateVersion sets and clears it and GetVersion reads it (below). The Java SDK has no alignment calls.
Steps#
-
Set the matrix. The identity below shifted by 2 metres in x; the response is the updated version.
JavaScript#const factory = new BimWorksClientFactory("https://bim.works"); const client = await factory.createClientWithApiToken("<your API token>"); const alignment = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2000, 0, 0, 1 ]; await client.geometry3d.setAlignment("<version uuid of the second demo model>", alignment); -
Read it back with GetVersion (below): the version's
alignmentholds the sixteen numbers, and is absent when the version has none. -
Clear it by setting
null:await client.geometry3d.setAlignment(BIM_WORKS_SECOND_MODEL, null). -
Compute one from points.
CalculateAlignmentreturns the matrix that maps thebpoints, in the model to move, onto theapoints:point1aandpoint1bare required. One pair only moves the model; two pairs also turn it and scale it, with one scale for every direction; three pairs give a full linear transform, which can scale each direction differently, skew and mirror; across the plane of the three points, which they leave open, it scales by the geometric mean of the in-plane scales. This is what the UI's alignment tool does with the points the user clicks; Align PDF floor plans picks them in two viewers.JavaScript#const matrix = await client.geometry3d.calculateAlignment( {x: 2000, y: 0, z: 0}, {x: 0, y: 0, z: 0}, // where a point should land, and that point in the model to move {x: 12000, y: 0, z: 0}, {x: 10000, y: 0, z: 0} // a second pair ); await client.geometry3d.setAlignment("<version uuid of the second demo model>", matrix);A point is
[x, y, z], an array or avec3, or an object{x, y, z}, in millimetres.
A loaded viewer does not pick up a changed alignment by itself: reload the version (modelManager.removeModels and addModels) or call viewer.updateModel(vid).
Over HTTP#
UpdateVersion sets the matrix as alignment, the same sixteen numbers in millimetres, and leaves the version's other fields as they are. It answers the updated version.
Bearer <auth token>application/jsonAuthorization: Bearer <auth token>
Content-Type: application/json
Accept: application/jsoncurl -X POST "$BIMWORKS_URL/openapi/fs/UpdateVersion" \
-H "Authorization: Bearer $BIMWORKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"version_uuid": BIM_WORKS_SECOND_MODEL,
"alignment": [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2000, 0, 0, 1]
}'"clear": ["alignment"] in place of alignment removes it. GetVersion answers the version with its alignment:
Bearer <auth token>application/jsonAuthorization: Bearer <auth token>
Content-Type: application/json
Accept: application/jsoncurl -X POST "$BIMWORKS_URL/openapi/fs/GetVersion" \
-H "Authorization: Bearer $BIMWORKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"uuid": BIM_WORKS_SECOND_MODEL
}'Computing a matrix from point pairs has no operation; it is the JavaScript SDK's calculateAlignment.
Check#
GetVersion answers the sixteen numbers you set as alignment, and the model appears shifted by 2 m in the 3D viewer after reloading it.