MCPcopy Create free account
hub / github.com/ColmapView/Colmapview.github.io / encodeCameraStateBinary

Function encodeCameraStateBinary

src/utils/urlCameraStateCodec.ts:42–65  ·  view source on GitHub ↗
(state: CameraViewState)

Source from the content-addressed store, hash-verified

40 * Quaternion is normalized to qw >= 0, with qw derived on decode from unit length.
41 */
42export function encodeCameraStateBinary(state: CameraViewState): Uint8Array {
43 const buffer = new ArrayBuffer(72);
44 const view = new DataView(buffer);
45
46 const [px, py, pz] = state.position;
47 const [tx, ty, tz] = state.target;
48 const [origQx, origQy, origQz, qw] = state.quaternion;
49
50 const qx = qw < 0 ? -origQx : origQx;
51 const qy = qw < 0 ? -origQy : origQy;
52 const qz = qw < 0 ? -origQz : origQz;
53
54 view.setFloat64(0, px, true);
55 view.setFloat64(8, py, true);
56 view.setFloat64(16, pz, true);
57 view.setFloat64(24, tx, true);
58 view.setFloat64(32, ty, true);
59 view.setFloat64(40, tz, true);
60 view.setFloat64(48, qx, true);
61 view.setFloat64(56, qy, true);
62 view.setFloat64(64, qz, true);
63
64 return new Uint8Array(buffer);
65}
66
67/**
68 * Encode camera state to URL hash string.

Callers 4

encodeShareDataFunction · 0.90
encodeCameraStateFunction · 0.85

Calls

no outgoing calls

Tested by 1