Compare commits
No commits in common. "3f83bde5330c834de25866705a7459a334234251" and "f79a90e0d9d6335faedf0cb373b3575a62ce9d9e" have entirely different histories.
3f83bde533
...
f79a90e0d9
|
@ -2,7 +2,7 @@ import * as THREE from 'three';
|
||||||
|
|
||||||
|
|
||||||
const HYPERPLANE = 2.0;
|
const HYPERPLANE = 2.0;
|
||||||
const W_FORESHORTENING = 0.4;
|
const NODE_FORESHORTENING = 0.4;
|
||||||
|
|
||||||
class FourDShape extends THREE.Group {
|
class FourDShape extends THREE.Group {
|
||||||
|
|
||||||
|
@ -15,10 +15,11 @@ class FourDShape extends THREE.Group {
|
||||||
this.nodes3 = {};
|
this.nodes3 = {};
|
||||||
this.links = structure.links;
|
this.links = structure.links;
|
||||||
this.faces = ( "faces" in structure ) ? structure.faces : [];
|
this.faces = ( "faces" in structure ) ? structure.faces : [];
|
||||||
|
this.node_size = structure.geometry.node_size;
|
||||||
|
this.link_size = structure.geometry.link_size;
|
||||||
this.node_scale = 1;
|
this.node_scale = 1;
|
||||||
this.link_scale = 1;
|
this.link_scale = 1;
|
||||||
this.hyperplane = HYPERPLANE;
|
this.hyperplane = HYPERPLANE;
|
||||||
this.foreshortening = W_FORESHORTENING;
|
|
||||||
this.initShapes();
|
this.initShapes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,63 +44,36 @@ class FourDShape extends THREE.Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
makeLink(material, link) {
|
makeLink(material, link) {
|
||||||
const n1 = this.nodes3[link.source];
|
const n1 = this.nodes3[link.source].v3;
|
||||||
const n2 = this.nodes3[link.target];
|
const n2 = this.nodes3[link.target].v3;
|
||||||
const s1 = n1.scale;
|
const length = n1.distanceTo(n2);
|
||||||
const s2 = n2.scale;
|
|
||||||
const length = n1.v3.distanceTo(n2.v3);
|
|
||||||
const centre = new THREE.Vector3();
|
const centre = new THREE.Vector3();
|
||||||
centre.lerpVectors(n1.v3, n2.v3, 0.5);
|
centre.lerpVectors(n1, n2, 0.5);
|
||||||
const geometry = new THREE.CylinderGeometry(this.link_scale * s2, this.link_scale * s1, 1);
|
const geometry = new THREE.CylinderGeometry(this.link_size, this.link_size, 1);
|
||||||
const cyl = new THREE.Mesh(geometry, material);
|
const cyl = new THREE.Mesh(geometry, material);
|
||||||
const edge = new THREE.Group();
|
const edge = new THREE.Group();
|
||||||
edge.add(cyl);
|
edge.add(cyl);
|
||||||
edge.position.copy(centre);
|
edge.position.copy(centre);
|
||||||
edge.scale.copy(new THREE.Vector3(1, 1, length));
|
edge.scale.copy(new THREE.Vector3(1, 1, length));
|
||||||
edge.lookAt(n2.v3);
|
edge.lookAt(n2);
|
||||||
cyl.rotation.x = Math.PI / 2.0;
|
cyl.rotation.x = Math.PI / 2.0;
|
||||||
this.add(edge);
|
this.add(edge);
|
||||||
return edge;
|
return edge;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateLink(link, links_show) {
|
updateLink(link, links_show) {
|
||||||
const n1 = this.nodes3[link.source];
|
const n1 = this.nodes3[link.source].v3;
|
||||||
const n2 = this.nodes3[link.target];
|
const n2 = this.nodes3[link.target].v3;
|
||||||
const s1 = n1.scale;
|
const length = n1.distanceTo(n2);
|
||||||
const s2 = n2.scale;
|
|
||||||
const length = n1.v3.distanceTo(n2.v3);
|
|
||||||
const centre = new THREE.Vector3();
|
const centre = new THREE.Vector3();
|
||||||
centre.lerpVectors(n1.v3, n2.v3, 0.5);
|
centre.lerpVectors(n1, n2, 0.5);
|
||||||
// is this really the only way to do this?
|
link.object.scale.copy(new THREE.Vector3(this.link_scale, this.link_scale, length));
|
||||||
//const geometry = new THREE.CylinderGeometry(this.link_scale * s2, this.link_scale * s1, 1);
|
|
||||||
//link.object.children[0].geometry.dispose();
|
|
||||||
this.forshortenLink(link.object.children[0].geometry, this.link_scale * s2, this.link_scale * s1);
|
|
||||||
//const link_hack = this.link_scale * (s1 + s2) * 0.5;
|
|
||||||
link.object.scale.copy(new THREE.Vector3(1, 1, length));
|
|
||||||
link.object.position.copy(centre);
|
link.object.position.copy(centre);
|
||||||
link.object.lookAt(n2.v3);
|
link.object.lookAt(n2);
|
||||||
link.object.children[0].rotation.x = Math.PI / 2.0;
|
link.object.children[0].rotation.x = Math.PI / 2.0;
|
||||||
// link.object.children[0].geometry.needsUpdate = true;
|
|
||||||
// link.object.children[0].geometry.computeVertexNormals();
|
|
||||||
link.object.visible = (!links_show || link.label in links_show);
|
link.object.visible = (!links_show || link.label in links_show);
|
||||||
}
|
}
|
||||||
|
|
||||||
forshortenLink(geometry, top, bottom) {
|
|
||||||
const count = geometry.attributes.position.count;
|
|
||||||
for( let i = 0; i < count; i++ ) {
|
|
||||||
const x = geometry.attributes.position.getX(i);
|
|
||||||
const y = geometry.attributes.position.getY(i);
|
|
||||||
const z = geometry.attributes.position.getZ(i);
|
|
||||||
if( z == 0 ) {
|
|
||||||
geometry.attributes.position.setX(i, x * top);
|
|
||||||
geometry.attributes.position.setY(i, y * top);
|
|
||||||
} else {
|
|
||||||
geometry.attributes.position.setX(i, x * bottom);
|
|
||||||
geometry.attributes.position.setY(i, y * bottom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
setFaceGeometry(face, geometry) {
|
setFaceGeometry(face, geometry) {
|
||||||
const values = [];
|
const values = [];
|
||||||
|
@ -159,7 +133,6 @@ class FourDShape extends THREE.Group {
|
||||||
const material = this.getMaterial(n, this.node_ms);
|
const material = this.getMaterial(n, this.node_ms);
|
||||||
this.nodes3[n.id] = {
|
this.nodes3[n.id] = {
|
||||||
v3: v3,
|
v3: v3,
|
||||||
scale: k,
|
|
||||||
label: n.label,
|
label: n.label,
|
||||||
object: this.makeNode(material, v3, k)
|
object: this.makeNode(material, v3, k)
|
||||||
};
|
};
|
||||||
|
@ -181,10 +154,9 @@ class FourDShape extends THREE.Group {
|
||||||
const v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations);
|
const v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations);
|
||||||
const k = this.fourDscale(v4.w);
|
const k = this.fourDscale(v4.w);
|
||||||
const v3 = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
|
const v3 = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
|
||||||
const s4 = k * this.node_scale * this.foreshortening;
|
const s4 = k * this.node_scale * NODE_FORESHORTENING;
|
||||||
const s3 = new THREE.Vector3(s4, s4, s4);
|
const s3 = new THREE.Vector3(s4, s4, s4);
|
||||||
this.nodes3[n.id].v3 = v3;
|
this.nodes3[n.id].v3 = v3;
|
||||||
this.nodes3[n.id].scale = k * this.foreshortening;
|
|
||||||
this.nodes3[n.id].object.position.copy(v3);
|
this.nodes3[n.id].object.position.copy(v3);
|
||||||
this.nodes3[n.id].object.scale.copy(s3);
|
this.nodes3[n.id].object.scale.copy(s3);
|
||||||
this.nodes3[n.id].object.visible = ( !nodes_show || n.label in nodes_show );
|
this.nodes3[n.id].object.visible = ( !nodes_show || n.label in nodes_show );
|
||||||
|
|
8
gui.js
8
gui.js
|
@ -2,8 +2,8 @@ import { GUI } from 'lil-gui';
|
||||||
|
|
||||||
|
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
thickness: 0.02,
|
thickness: 0.5,
|
||||||
nodesize: 0.02,
|
nodesize: 1.5,
|
||||||
linkopacity: 0.5,
|
linkopacity: 0.5,
|
||||||
link2opacity: 0.5,
|
link2opacity: 0.5,
|
||||||
shape: '120-cell',
|
shape: '120-cell',
|
||||||
|
@ -67,14 +67,14 @@ class FourDGUI {
|
||||||
});
|
});
|
||||||
this.gui.add(this.params, 'hyperplane', 0.5, 1 / 0.8);
|
this.gui.add(this.params, 'hyperplane', 0.5, 1 / 0.8);
|
||||||
this.gui.add(this.params, 'zoom', 0.1, 2.0);
|
this.gui.add(this.params, 'zoom', 0.1, 2.0);
|
||||||
this.gui.add(this.params, 'thickness', 0, 0.1);
|
this.gui.add(this.params, 'thickness', 0, 1);
|
||||||
this.gui.add(this.params, 'linkopacity', 0, 1).onChange(
|
this.gui.add(this.params, 'linkopacity', 0, 1).onChange(
|
||||||
(v) => setLinkOpacity(v, true)
|
(v) => setLinkOpacity(v, true)
|
||||||
);
|
);
|
||||||
this.gui.add(this.params, 'link2opacity', 0, 1).onChange(
|
this.gui.add(this.params, 'link2opacity', 0, 1).onChange(
|
||||||
(v) => setLinkOpacity(v, false)
|
(v) => setLinkOpacity(v, false)
|
||||||
);
|
);
|
||||||
this.gui.add(this.params, 'nodesize', 0, 0.1);
|
this.gui.add(this.params, 'nodesize', 0.1, 4);
|
||||||
this.gui.addColor(this.params, 'color').onChange(setColor);
|
this.gui.addColor(this.params, 'color').onChange(setColor);
|
||||||
this.gui.addColor(this.params, 'background').onChange(setBackground);
|
this.gui.addColor(this.params, 'background').onChange(setBackground);
|
||||||
this.gui.add(this.params, 'xRotate', [ 'YW', 'YZ', 'ZW' ]);
|
this.gui.add(this.params, 'xRotate', [ 'YW', 'YZ', 'ZW' ]);
|
||||||
|
|
56
polytopes.js
56
polytopes.js
|
@ -80,6 +80,10 @@ export const cell5 = () => {
|
||||||
{ id:9, source:3, target: 5},
|
{ id:9, source:3, target: 5},
|
||||||
{ id:10, source:4, target: 5},
|
{ id:10, source:4, target: 5},
|
||||||
],
|
],
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [ { name: '--' }],
|
options: [ { name: '--' }],
|
||||||
description: `Five tetrahedra joined at ten faces with three
|
description: `Five tetrahedra joined at ten faces with three
|
||||||
tetrahedra around each edge. The 5-cell is the simplest regular
|
tetrahedra around each edge. The 5-cell is the simplest regular
|
||||||
|
@ -111,6 +115,10 @@ export const cell16 = () => {
|
||||||
name: '16-cell',
|
name: '16-cell',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [ { name: '--' }],
|
options: [ { name: '--' }],
|
||||||
description: `Sixteen tetrahedra joined at 32 faces with four
|
description: `Sixteen tetrahedra joined at 32 faces with four
|
||||||
tetrahedra around each edge. The 16-cell is the four-dimensional
|
tetrahedra around each edge. The 16-cell is the four-dimensional
|
||||||
|
@ -149,6 +157,10 @@ export const tesseract = () => {
|
||||||
name: 'Tesseract',
|
name: 'Tesseract',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{ name: 'none', links: [ 0 ] },
|
{ name: 'none', links: [ 0 ] },
|
||||||
{ name: 'one 16-cell', links: [ 0, 1 ] },
|
{ name: 'one 16-cell', links: [ 0, 1 ] },
|
||||||
|
@ -209,6 +221,10 @@ export const cell24 = () => {
|
||||||
name: '24-cell',
|
name: '24-cell',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
base: {},
|
base: {},
|
||||||
options: [
|
options: [
|
||||||
{ name: 'none', links: [ 0 ] },
|
{ name: 'none', links: [ 0 ] },
|
||||||
|
@ -396,6 +412,10 @@ export const cell120_layered = (max) => {
|
||||||
name: '120-cell layered',
|
name: '120-cell layered',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
nolink2opacity: true,
|
nolink2opacity: true,
|
||||||
options: options,
|
options: options,
|
||||||
description: `This version of the 120-cell lets you explore its
|
description: `This version of the 120-cell lets you explore its
|
||||||
|
@ -427,6 +447,10 @@ export const cell120_inscribed = () => {
|
||||||
name: '120-cell',
|
name: '120-cell',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{ name: "none", links: [ 0 ]},
|
{ name: "none", links: [ 0 ]},
|
||||||
{ name: "one inscribed 600-cell", links: [ 0, 1 ] },
|
{ name: "one inscribed 600-cell", links: [ 0, 1 ] },
|
||||||
|
@ -558,6 +582,10 @@ export const cell600 = () => {
|
||||||
name: '600-cell',
|
name: '600-cell',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{ name: "none", links: [ 0 ]},
|
{ name: "none", links: [ 0 ]},
|
||||||
{ name: "one 24-cell", links: [ 0, 1 ] },
|
{ name: "one 24-cell", links: [ 0, 1 ] },
|
||||||
|
@ -607,6 +635,10 @@ export const cell600_layered = () => {
|
||||||
name: '600-cell layered',
|
name: '600-cell layered',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
nolink2opacity: true,
|
nolink2opacity: true,
|
||||||
options: options,
|
options: options,
|
||||||
description: `This version of the 600-cell lets you explore its
|
description: `This version of the 600-cell lets you explore its
|
||||||
|
@ -634,6 +666,10 @@ export const snub24cell = () => {
|
||||||
name: 'Snub 24-cell',
|
name: 'Snub 24-cell',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [ { name: "--" } ],
|
options: [ { name: "--" } ],
|
||||||
description: `The snub 24-cell is a semiregular polytope which
|
description: `The snub 24-cell is a semiregular polytope which
|
||||||
connects the 24-cell with the 600-cell. It consists of 24 icosahedra
|
connects the 24-cell with the 600-cell. It consists of 24 icosahedra
|
||||||
|
@ -700,6 +736,10 @@ export const dodecahedron = () => {
|
||||||
name: 'Dodecahedron',
|
name: 'Dodecahedron',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{ name: "none", links: [ 0 ]},
|
{ name: "none", links: [ 0 ]},
|
||||||
{ name: "one tetrahedron", links: [ 0, 1 ] },
|
{ name: "one tetrahedron", links: [ 0, 1 ] },
|
||||||
|
@ -734,6 +774,10 @@ export const tetrahedron = () => {
|
||||||
{ id:5, source:2, target: 4},
|
{ id:5, source:2, target: 4},
|
||||||
{ id:6, source:3, target: 4},
|
{ id:6, source:3, target: 4},
|
||||||
],
|
],
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [ { name: '--' }],
|
options: [ { name: '--' }],
|
||||||
description: `The simplest three-dimensional polytope, consisting of four triangles joined at six edges. The 5-cell is its four-dimensional analogue.`,
|
description: `The simplest three-dimensional polytope, consisting of four triangles joined at six edges. The 5-cell is its four-dimensional analogue.`,
|
||||||
};
|
};
|
||||||
|
@ -767,6 +811,10 @@ export const octahedron = () => {
|
||||||
name: 'Octahedron',
|
name: 'Octahedron',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [ { name: '--' }],
|
options: [ { name: '--' }],
|
||||||
description: `The three-dimensional cross-polytope, the 16-cell is its four-dimensional analogue.`,
|
description: `The three-dimensional cross-polytope, the 16-cell is its four-dimensional analogue.`,
|
||||||
};
|
};
|
||||||
|
@ -791,6 +839,10 @@ export const cube = () => {
|
||||||
name: 'Cube',
|
name: 'Cube',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [ { name: '--' }],
|
options: [ { name: '--' }],
|
||||||
description: `The three-dimensional measure polytope, the tesseract is its four-dimensional analogue.`,
|
description: `The three-dimensional measure polytope, the tesseract is its four-dimensional analogue.`,
|
||||||
};
|
};
|
||||||
|
@ -833,6 +885,10 @@ export const icosahedron = () => {
|
||||||
name: 'Icosahedron',
|
name: 'Icosahedron',
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
links: links,
|
links: links,
|
||||||
|
geometry: {
|
||||||
|
node_size: 0.02,
|
||||||
|
link_size: 0.02
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{ name: "--"},
|
{ name: "--"},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue