feature-faces
Mike Lynch 2023-07-28 17:39:57 +10:00
parent 8a581a9d64
commit 13b3d3514a
1 changed files with 70 additions and 4 deletions

74
main.js
View File

@ -83,6 +83,43 @@ function rotXY(theta) {
function fallbackCopyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text;
// Avoid scrolling to bottom
textArea.style.top = "0";
textArea.style.left = "0";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Fallback: Copying text command was ' + msg);
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
document.body.removeChild(textArea);
}
function copyTextToClipboard(text) {
if (!navigator.clipboard) {
fallbackCopyTextToClipboard(text);
return;
}
navigator.clipboard.writeText(text).then(function() {
console.log('Async: Copying to clipboard was successful!');
}, function(err) {
console.error('Async: Could not copy text: ', err);
});
}
@ -162,9 +199,16 @@ function createShape(name) {
} }
function floatParam(linkUrl, param) {
const value = linkUrl.searchParams(param);
createShape(DEFAULT_SHAPE); if( value ) {
const fl = parseFloat(value);
if( fl !== NaN ) {
return fl;
}
}
return 0;
}
camera.position.z = 4; camera.position.z = 4;
@ -213,14 +257,32 @@ renderer.domElement.addEventListener("pointerup", (event) => {
const gui = new GUI(); const gui = new GUI();
const linkUrl = new URL(window.location.toLocaleString());
const linkparams = {};
const gui_params = { const gui_params = {
shape: DEFAULT_SHAPE, shape: DEFAULT_SHAPE,
hyperplane: 2, hyperplane: 2,
xRotate: 'YW', xRotate: 'YW',
yRotate: 'XZ', yRotate: 'XZ',
damping: false damping: false,
copylink: function () {
const url =
}
}; };
for( const param in [ "shape", "hyperplane", "xRotate", "yRotate", "damping" ]) {
const value = linkUrl.searchParams(param);
if( value ) {
gui_params[param] = value;
}
}
dpsi = floatParam(linkUrl, 'dpsi');
dtheta = floatParam(linkUrl, 'dtheta');
gui.add(gui_params, 'shape', gui.add(gui_params, 'shape',
[ '5-cell', '16-cell', 'tesseract', '24-cell', '120-cell', '600-cell' ] [ '5-cell', '16-cell', 'tesseract', '24-cell', '120-cell', '600-cell' ]
).onChange(createShape) ).onChange(createShape)
@ -229,6 +291,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()
const ROTFN = { const ROTFN = {
XY: rotXY, XY: rotXY,
@ -241,6 +304,9 @@ const ROTFN = {
createShape(gui_params["shape"]);
const rotation = new THREE.Matrix4(); const rotation = new THREE.Matrix4();
function animate() { function animate() {