Skip to content

Commit

Permalink
updates from k3d-pro
Browse files Browse the repository at this point in the history
  • Loading branch information
artur-trzesiok committed Jan 18, 2022
1 parent 68729af commit 5477450
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
62 changes: 38 additions & 24 deletions js/src/standalone.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
const msgpack = require('msgpack-lite');
const pako = require('pako');
const fflate = require('fflate');
const TFEdit = require('./transferFunctionEditor');
const serialize = require('./core/lib/helpers/serialize');
const K3D = require('./core/Core');
const ThreeJsProvider = require('./providers/threejs/provider');

const MsgpackCodec = msgpack.createCodec({ preset: true });

window.Float16Array = require('./core/lib/helpers/float16Array');

MsgpackCodec.addExtPacker(0x20, Float16Array, (val) => val);
MsgpackCodec.addExtUnpacker(0x20, (val) => Float16Array(val.buffer));

require('katex/dist/katex.min.css');
require('dat.gui/build/dat.gui.css');

Expand All @@ -14,37 +20,45 @@ function msgpackDecode(data) {
}

function CreateK3DAndLoadBinarySnapshot(data, targetDOMNode) {
let K3DInstance;

data = pako.inflate(data);
data = msgpackDecode(data);

try {
K3DInstance = new K3D(
ThreeJsProvider,
targetDOMNode,
data.plot,
);
} catch (e) {
console.log(e);
return null;
}

return K3DInstance.setSnapshot(data).then(() => {
setTimeout(() => {
if (data.plot.camera.length > 0) {
K3DInstance.setCamera(data.plot.camera);
K3DInstance.render();
return new Promise((resolve, reject) => {
let K3DInstance;

fflate.unzlib(new Uint8Array(data), (err, decompressData) => {
if (!err) {
data = decompressData;
}
}, 10);

return K3DInstance;
data = msgpackDecode(data);

try {
K3DInstance = new K3D(
ThreeJsProvider,
targetDOMNode,
data.plot,
);
} catch (e) {
console.log(e);
return reject(e);
}

K3DInstance.setSnapshot(data).then(() => {
setTimeout(() => {
if (data.plot.camera.length > 0) {
K3DInstance.setCamera(data.plot.camera);
K3DInstance.render();
}
}, 10);

resolve(K3DInstance);
});
});
});
}

module.exports = {
K3D,
msgpackDecode,
serialize,
CreateK3DAndLoadBinarySnapshot,
TransferFunctionEditor: TFEdit.transferFunctionEditor,
TransferFunctionModel: TFEdit.transferFunctionModel,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"main": "js/src/labplugin.js",
"repository": {
"type": "git",
"url": "https://github.com/K3D-tools/K3D-jupyter.git.git"
"url": "https://github.com/K3D-tools/K3D-jupyter"
},
"scripts": {
"build": "jlpm run build:labextension:dev",
Expand Down

0 comments on commit 5477450

Please sign in to comment.