Link copying and param parsing works

feature-faces
Mike Lynch 2023-07-29 10:40:15 +10:00
parent 13b3d3514a
commit fe5761aede
2 changed files with 32 additions and 22 deletions

52
main.js
View File

@ -199,8 +199,8 @@ function createShape(name) {
} }
function floatParam(linkUrl, param) { function floatParam(params, param) {
const value = linkUrl.searchParams(param); const value = params.get(param);
if( value ) { if( value ) {
const fl = parseFloat(value); const fl = parseFloat(value);
if( fl !== NaN ) { if( fl !== NaN ) {
@ -259,28 +259,40 @@ const gui = new GUI();
const linkUrl = new URL(window.location.toLocaleString()); const linkUrl = new URL(window.location.toLocaleString());
const linkparams = {}; const link_params = {};
const gui_params = { const urlParams = linkUrl.searchParams;
shape: DEFAULT_SHAPE, for( const param of [ "shape", "xRotate", "yRotate" ]) {
hyperplane: 2, const value = urlParams.get(param);
xRotate: 'YW',
yRotate: 'XZ',
damping: false,
copylink: function () {
const url =
}
};
for( const param in [ "shape", "hyperplane", "xRotate", "yRotate", "damping" ]) {
const value = linkUrl.searchParams(param);
if( value ) { if( value ) {
gui_params[param] = value; link_params[param] = value;
} }
} }
dpsi = floatParam(linkUrl, 'dpsi'); link_params['hyperplane'] = floatParam(urlParams, 'hyperplane');
dtheta = floatParam(linkUrl, 'dtheta');
dpsi = floatParam(urlParams, 'dpsi');
dtheta = floatParam(urlParams, 'dtheta');
const gui_params = {
shape: link_params['shape'] || DEFAULT_SHAPE,
hyperplane: link_params['hyperplane'] || 2,
xRotate: link_params['xRotate'] || 'YW',
yRotate: link_params['yRotate'] || 'XZ',
damping: false,
"copy link": function () {
const url = new URL(linkUrl.origin + linkUrl.pathname);
url.searchParams.append("shape", gui_params.shape);
url.searchParams.append("hyperplane", gui_params.hyperplane.toString());
url.searchParams.append("xRotate", gui_params.xRotate);
url.searchParams.append("yRotate", gui_params.yRotate);
url.searchParams.append("dtheta", dtheta.toString());
url.searchParams.append("dpsi", dpsi.toString());
copyTextToClipboard(url);
}
};
gui.add(gui_params, 'shape', gui.add(gui_params, 'shape',
@ -291,7 +303,7 @@ gui.add(gui_params, 'hyperplane', 1.5, 4);
gui.add(gui_params, 'xRotate', [ 'YW', 'YZ', 'ZW' ]); gui.add(gui_params, 'xRotate', [ 'YW', 'YZ', 'ZW' ]);
gui.add(gui_params, 'yRotate', [ 'XZ', 'XY', 'XW' ]); gui.add(gui_params, 'yRotate', [ 'XZ', 'XY', 'XW' ]);
gui.add(gui_params, 'damping'); gui.add(gui_params, 'damping');
gui.add() gui.add(gui_params, 'copy link');
const ROTFN = { const ROTFN = {
XY: rotXY, XY: rotXY,

View File

@ -76,8 +76,6 @@ export const cell16 = () => {
let nodes = PERMUTE.coordinates([1, 1, 1, 1], 0); let nodes = PERMUTE.coordinates([1, 1, 1, 1], 0);
nodes = nodes.filter((n) => n.x * n.y * n.z * n.w > 0); nodes = nodes.filter((n) => n.x * n.y * n.z * n.w > 0);
scale_and_index(nodes, 0.75); scale_and_index(nodes, 0.75);
console.log('cell16 auto_detect_edges');
console.log(nodes);
const links = auto_detect_edges(nodes, 6); const links = auto_detect_edges(nodes, 6);
return { return {