Skip to content

Commit

Permalink
Merge pull request #404 from K3D-tools/devel
Browse files Browse the repository at this point in the history
code autoformat
  • Loading branch information
artur-trzesiok authored Dec 18, 2022
2 parents fa53000 + 8e4af46 commit c64cb18
Show file tree
Hide file tree
Showing 85 changed files with 889 additions and 885 deletions.
2 changes: 1 addition & 1 deletion js/src/amd-public-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
var module = require('module');
var url = new URL(module.uri, document.location)
// Using lastIndexOf('/')+1 gives us the empty string if there is no '/', so pathname becomes '/'
url.pathname = url.pathname.slice(0,url.pathname.lastIndexOf('/')+1);
url.pathname = url.pathname.slice(0, url.pathname.lastIndexOf('/') + 1);
__webpack_public_path__ = `${url.origin}${url.pathname}`;
4 changes: 2 additions & 2 deletions js/src/core/lib/Loader.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const validateAndPrepareObject = require('./helpers/objectValidator');
const _ = require('../../lodash');
const timeSeries = require('./timeSeries');
const { error } = require('./Error');
const {error} = require('./Error');

/**
* @method K3D.Loader
Expand Down Expand Up @@ -64,7 +64,7 @@ function loader(K3D, data) {
's',
);

return { json, obj: K3DObject };
return {json, obj: K3DObject};
})
.catch((err) => {
console.error(err);
Expand Down
2 changes: 1 addition & 1 deletion js/src/core/lib/detachWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function detachWindowGUI(gui, K3D) {
}, []);

K3D.disable();
newK3D.load({ objects });
newK3D.load({objects});
newK3D.setCamera(K3D.getWorld().controls.getCameraArray());

_.assign(K3D, newK3D);
Expand Down
304 changes: 152 additions & 152 deletions js/src/core/lib/headless.html
Original file line number Diff line number Diff line change
@@ -1,174 +1,174 @@
<script>
window.headlessK3D = true;
window.headlessK3D = true;
</script>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>K3D headless engine</title>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
}
<meta charset="utf-8">
<title>K3D headless engine</title>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
}

#canvasTarget {
width: 100%;
height: 100%;
position: absolute;
}
</style>
<script id='requirejs' src="require.js"></script>
<script id='k3d' src="standalone.js"></script>
#canvasTarget {
width: 100%;
height: 100%;
position: absolute;
}
</style>
<script id='requirejs' src="require.js"></script>
<script id='k3d' src="standalone.js"></script>
</head>
<body>
<div id="canvasTarget"></div>

<script>
function stringToArrayBuffer(str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);

for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}

return buf;
}
function stringToArrayBuffer(str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);

var K3DInstance, pingFailed = 0;

window.refreshed = false;
for (var i = 0, strLen = str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}

require(['k3d'], function (lib) {
try {
K3DInstance = new lib.K3D(
lib.ThreeJsProvider,
document.getElementById('canvasTarget'),
{}
);
} catch (e) {
console.log(e);
return;
return buf;
}

setInterval(function () {
var req = new XMLHttpRequest();
req.open('GET', '/ping', true);
var K3DInstance, pingFailed = 0;

req.onerror = function (e) {
pingFailed++;
window.refreshed = false;

if (pingFailed > 5) {
window.close();
}
};

req.onload = function (e) {
pingFailed = 0;
};
req.send(null);
}, 5000);

window.k3dRefresh = function () {
var req = new XMLHttpRequest();

window.refreshed = false;

req.overrideMimeType('text/plain; charset=x-user-defined');
req.open('POST', '/', false); //synchronous
req.send(null);

if (req.status == 200) {

var data = K3DInstance.msgpack.decode(
new Uint8Array(stringToArrayBuffer(req.response)),
{codec: K3DInstance.MsgpackCodec}
);

var map = {
cameraAutoFit: "setCameraAutoFit",
lighting: "setDirectionalLightingIntensity",
time: "setTime",
gridAutoFit: "setGridAutoFit",
gridVisible: "setGridVisible",
gridColor: "setGridColor",
depthPeels: "setDepthPeels",
fpsMeter: "setFpsMeter",
fps: "setFps",
screenshotScale: "setScreenshotScale",
// voxel_paint_color: "setVoxelPaintColor",
clearColor: "setClearColor",
grid: "setGrid",
auto_rendering: "setAutoRendering",
camera: "setCamera",
cameraAnimation: "setCameraAnimation",
clippingPlanes: "setClippingPlanes",
// object_ids: "onObjectsListChange",
menuVisibility: "setMenuVisibility",
colorbarObjectId: "setColorMapLegend",
// colorbar_scientific: "setColorbarScientific",
// rendering_steps: "setRenderingSteps",
axes: "setAxes",
cameraNoRotate: "setCameraLock",
cameraNoZoom: "setCameraLock",
cameraNoPan: "setCameraLock",
cameraRotateSpeed: "setCameraSpeeds",
cameraZoomSpeed: "setCameraSpeeds",
cameraPanSpeed: "setCameraSpeeds",
cameraFov: "setCameraFOV",
cameraDampingFactor: "setCameraDampingFactor",
axesHelper: "setAxesHelper",
snapshot_type: "setSnapshotType",
name: "setName",
mode: "setViewMode",
cameraMode: "setCameraMode",
// manipulate_mode: "setManipulateMode"
};

Object.keys(data.plot_diff).forEach(function (k) {
if (map[k]) {
K3DInstance[map[k]](data.plot_diff[k]);
} else {
K3DInstance.parameters[k] = data.plot_diff[k];
}
});

let promises = [];

Object.keys(data.objects_diff).forEach(function (k) {
let diff = data.objects_diff[k];

if (diff === null) {
K3DInstance.removeObject(k);
require(['k3d'], function (lib) {
try {
K3DInstance = new lib.K3D(
lib.ThreeJsProvider,
document.getElementById('canvasTarget'),
{}
);
} catch (e) {
console.log(e);
return;
}

let json = K3DInstance.getWorld().ObjectsListJson[diff.id] || {};
let load = Object.keys(json).length === 0;

Object.keys(diff).forEach((k) => {
json[k] = diff[k] = K3DInstance.serialize.deserialize(diff[k]);
});

if (load) {
promises.push(K3DInstance.load({objects: [json]}));
} else {
promises.push(K3DInstance.reload(json, diff));
}
});

if (promises.length > 0) {
Promise.all(promises).then(function () {
window.refreshed = true;
});
} else {
window.refreshed = true;
}
}
}
});

setInterval(function () {
var req = new XMLHttpRequest();
req.open('GET', '/ping', true);

req.onerror = function (e) {
pingFailed++;

if (pingFailed > 5) {
window.close();
}
};

req.onload = function (e) {
pingFailed = 0;
};
req.send(null);
}, 5000);

window.k3dRefresh = function () {
var req = new XMLHttpRequest();

window.refreshed = false;

req.overrideMimeType('text/plain; charset=x-user-defined');
req.open('POST', '/', false); //synchronous
req.send(null);

if (req.status == 200) {

var data = K3DInstance.msgpack.decode(
new Uint8Array(stringToArrayBuffer(req.response)),
{codec: K3DInstance.MsgpackCodec}
);

var map = {
cameraAutoFit: "setCameraAutoFit",
lighting: "setDirectionalLightingIntensity",
time: "setTime",
gridAutoFit: "setGridAutoFit",
gridVisible: "setGridVisible",
gridColor: "setGridColor",
depthPeels: "setDepthPeels",
fpsMeter: "setFpsMeter",
fps: "setFps",
screenshotScale: "setScreenshotScale",
// voxel_paint_color: "setVoxelPaintColor",
clearColor: "setClearColor",
grid: "setGrid",
auto_rendering: "setAutoRendering",
camera: "setCamera",
cameraAnimation: "setCameraAnimation",
clippingPlanes: "setClippingPlanes",
// object_ids: "onObjectsListChange",
menuVisibility: "setMenuVisibility",
colorbarObjectId: "setColorMapLegend",
// colorbar_scientific: "setColorbarScientific",
// rendering_steps: "setRenderingSteps",
axes: "setAxes",
cameraNoRotate: "setCameraLock",
cameraNoZoom: "setCameraLock",
cameraNoPan: "setCameraLock",
cameraRotateSpeed: "setCameraSpeeds",
cameraZoomSpeed: "setCameraSpeeds",
cameraPanSpeed: "setCameraSpeeds",
cameraFov: "setCameraFOV",
cameraDampingFactor: "setCameraDampingFactor",
axesHelper: "setAxesHelper",
snapshot_type: "setSnapshotType",
name: "setName",
mode: "setViewMode",
cameraMode: "setCameraMode",
// manipulate_mode: "setManipulateMode"
};

Object.keys(data.plot_diff).forEach(function (k) {
if (map[k]) {
K3DInstance[map[k]](data.plot_diff[k]);
} else {
K3DInstance.parameters[k] = data.plot_diff[k];
}
});

let promises = [];

Object.keys(data.objects_diff).forEach(function (k) {
let diff = data.objects_diff[k];

if (diff === null) {
K3DInstance.removeObject(k);
return;
}

let json = K3DInstance.getWorld().ObjectsListJson[diff.id] || {};
let load = Object.keys(json).length === 0;

Object.keys(diff).forEach((k) => {
json[k] = diff[k] = K3DInstance.serialize.deserialize(diff[k]);
});

if (load) {
promises.push(K3DInstance.load({objects: [json]}));
} else {
promises.push(K3DInstance.reload(json, diff));
}
});

if (promises.length > 0) {
Promise.all(promises).then(function () {
window.refreshed = true;
});
} else {
window.refreshed = true;
}
}
}
});
</script>
</body>
</html>
3 changes: 1 addition & 2 deletions js/src/core/lib/helpers/colorMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function toColor(val) {
function mergeColorMapWithOpacity(colormap, opacity) {
const merged = {};
let sortedKeys;
let
i;
let i;

function findNeighbors(key, property) {
const startKeyIndex = sortedKeys.indexOf(key);
Expand Down
12 changes: 6 additions & 6 deletions js/src/core/lib/helpers/marchingCubesPolygonise.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@

const vertexList = new Float32Array(12 * 3);
const fieldNeighbours = new Float32Array(8);
const { edgeTable } = require('./marchingCubesLookupTables');
const { triangleTable } = require('./marchingCubesLookupTables');
const {edgeTable} = require('./marchingCubesLookupTables');
const {triangleTable} = require('./marchingCubesLookupTables');

module.exports = function (positions, field, iso,
width, height, length,
k, j, i,
x, y, z,
sx, sy, sz) {
width, height, length,
k, j, i,
x, y, z,
sx, sy, sz) {
let index = 0;
const ptr = i * width * height + j * width + k;
let o = 0;
Expand Down
Loading

0 comments on commit c64cb18

Please sign in to comment.