Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ where `dom_element` is the `div` in which the viewer should live. The primary in
<dd>
Set up a web socket connection to a server at the given URL. The viewer will listen for messages on the socket as binary MsgPack blobs. Each message will be decoded using <code>msgpack.decode()</code> from <a href="https://github.com/msgpack/msgpack-javascript">msgpack-javascript</a> and the resulting object will be passed directly to <code>Viewer.handle_command()</code> as documented above.
<p>
Note that we do support the MsgPack extension types listed in <a href="https://github.com/msgpack/msgpack-javascript#extension-types">msgpack-javascript#extension-types</a>, with additional support for the <code>Float32Array</code> type which is particularly useful for efficiently sending point data and for <code>Uint32Array</code>.
Note that we do support the MsgPack extension types listed in <a href="https://github.com/msgpack/msgpack-javascript#extension-types">msgpack-javascript#extension-types</a>, with additional support for the <code>Float32Array</code> type which is particularly useful for efficiently sending point data and for <code>Uint32Array</code>, <code>Uint8Array</code>, and <code>Int32Array</code>.
</dd>
</dl>

Expand Down
2 changes: 1 addition & 1 deletion dist/main.min.js

Large diffs are not rendered by default.

46 changes: 43 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,50 @@ import { XRButton } from 'three/examples/jsm/webxr/XRButton.js';
import { XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory';
require('ccapture.js');

// We must implement extension types 0x16 and 0x17. The trick to
// decoding them is they must be converted from littleEndian.
// We implement several MessagePack extension types for arrays, inspired by the
// conventions for msgpack-lite:
// https://github.com/kawanet/msgpack-lite/tree/master#extension-types
//
// Specifically, we support:
// - 0x12 Uint8Array
// - 0x15 Int32Array
// - 0x16 Uint32Array
// - 0x17 Float32Array
//
// The trick to decoding them is they must be converted from littleEndian.
const extensionCodec = new msgpack.ExtensionCodec();
// Uint8Array
extensionCodec.register({
type: 0x12,
encode: (obj) => {
console.error("Uint8Array encode not implemented")
return null;
},
decode: (data) => {
const to_return = new Uint8Array(data.byteLength);
let dataview = new DataView(data.buffer, data.byteOffset, data.byteLength);
for (let i = 0; i < to_return.length; i++) {
to_return[i] = dataview.getUint8(i);
}
return to_return
},
});
// Int32Array
extensionCodec.register({
type: 0x15,
encode: (obj) => {
console.error("Int32Array encode not implemented")
return null;
},
decode: (data) => {
const to_return = new Int32Array(data.byteLength / 4);
let dataview = new DataView(data.buffer, data.byteOffset, data.byteLength);
for (let i = 0; i < to_return.length; i++) {
to_return[i] = dataview.getInt32(i * 4, true); // true b.c. littleEndian
}
return to_return
},
});
// Uint32Array
extensionCodec.register({
type: 0x16,
Expand All @@ -32,7 +73,6 @@ extensionCodec.register({
return to_return
},
});
+
// Float32Array
extensionCodec.register({
type: 0x17,
Expand Down