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

Function decodeCameraFromBytes

src/utils/urlCameraStateCodec.ts:77–106  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

75 * Decode camera state from raw bytes (72 bytes).
76 */
77export function decodeCameraFromBytes(bytes: Uint8Array): CameraViewState | null {
78 if (bytes.length !== 72) return null;
79
80 const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
81
82 const px = view.getFloat64(0, true);
83 const py = view.getFloat64(8, true);
84 const pz = view.getFloat64(16, true);
85 const tx = view.getFloat64(24, true);
86 const ty = view.getFloat64(32, true);
87 const tz = view.getFloat64(40, true);
88 const qx = view.getFloat64(48, true);
89 const qy = view.getFloat64(56, true);
90 const qz = view.getFloat64(64, true);
91
92 const qwSquared = 1 - qx * qx - qy * qy - qz * qz;
93 if (qwSquared < 0) return null;
94 const qw = Math.sqrt(qwSquared);
95
96 return {
97 position: [px, py, pz],
98 target: [tx, ty, tz],
99 quaternion: [qx, qy, qz, qw],
100 distance: Math.sqrt(
101 (px - tx) * (px - tx) +
102 (py - ty) * (py - ty) +
103 (pz - tz) * (pz - tz)
104 ),
105 };
106}
107
108/**
109 * Decode camera state from Base64URL binary format.

Callers 3

decodeShareDataFunction · 0.90
decodeCameraStateBinaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected