Added a callback to set link and node visibility based on label at

the render stage
feature-120-cell-layers
Mike Lynch 2023-10-27 12:45:46 +11:00
parent 944416f92b
commit 2f59c0b3a5
3 changed files with 26 additions and 8 deletions

View File

@ -20,6 +20,7 @@ class FourDShape extends THREE.Group {
this.node_scale = 1; this.node_scale = 1;
this.link_scale = 1; this.link_scale = 1;
this.hyperplane = HYPERPLANE; this.hyperplane = HYPERPLANE;
this.label_visible = () => true;
this.initShapes(); this.initShapes();
} }
@ -71,6 +72,9 @@ class FourDShape extends THREE.Group {
link.object.position.copy(centre); link.object.position.copy(centre);
link.object.lookAt(n2); link.object.lookAt(n2);
link.object.children[0].rotation.x = Math.PI / 2.0; link.object.children[0].rotation.x = Math.PI / 2.0;
const l1 = this.nodes3[link.source].label;
const l2 = this.nodes3[link.target].label;
link.object.visible = this.label_visible(l1) && this.label_visible(l2);
} }
@ -115,6 +119,7 @@ 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,
label: n.label,
object: this.makeNode(material, v3) object: this.makeNode(material, v3)
}; };
} }
@ -129,17 +134,19 @@ class FourDShape extends THREE.Group {
} }
render3(rotations) { render3(rotations, visibility) {
this.label_visible = visibility;
this.scalev3 = new THREE.Vector3(this.node_scale, this.node_scale, this.node_scale); this.scalev3 = new THREE.Vector3(this.node_scale, this.node_scale, this.node_scale);
for( const n of this.nodes4 ) { for( const n of this.nodes4 ) {
const v3 = this.fourDtoV3(n.x, n.y, n.z, n.w, rotations); const v3 = this.fourDtoV3(n.x, n.y, n.z, n.w, rotations);
this.nodes3[n.id].v3 = v3; this.nodes3[n.id].v3 = v3;
this.nodes3[n.id].object.position.copy(v3); this.nodes3[n.id].object.position.copy(v3);
this.nodes3[n.id].object.scale.copy(this.scalev3); this.nodes3[n.id].object.scale.copy(this.scalev3);
this.nodes3[n.id].object.visible = this.label_visible(n.label);
} }
for( const l of this.links ) { for( const l of this.links ) {
this.updateLink(l); this.updateLink(l, visibility);
} }
for( const f of this.faces ) { for( const f of this.faces ) {
@ -147,7 +154,6 @@ class FourDShape extends THREE.Group {
} }
} }
} }
export { FourDShape }; export { FourDShape };

7
gui.js
View File

@ -8,6 +8,7 @@ const DEFAULTS = {
linkopacity: 0.5, linkopacity: 0.5,
link2opacity: 0.5, link2opacity: 0.5,
shape: '120-cell', shape: '120-cell',
visibility: 5,
inscribed: false, inscribed: false,
inscribe_all: false, inscribe_all: false,
color: 0x3293a9, color: 0x3293a9,
@ -22,7 +23,7 @@ const DEFAULTS = {
class FourDGUI { class FourDGUI {
constructor(changeShape, setColor, setBackground, setLinkOpacity) { constructor(changeShape, setColor, setBackground, setLinkOpacity, setVisibility) {
this.gui = new GUI(); this.gui = new GUI();
this.parseLinkParams(); this.parseLinkParams();
const guiObj = this; const guiObj = this;
@ -34,6 +35,7 @@ class FourDGUI {
linkopacity: this.link['linkopacity'], linkopacity: this.link['linkopacity'],
link2opacity: this.link['linkopacity'], link2opacity: this.link['linkopacity'],
nodesize: this.link['nodesize'], nodesize: this.link['nodesize'],
depth: this.link['depth'],
color: this.link['color'], color: this.link['color'],
background: this.link['background'], background: this.link['background'],
hyperplane: this.link['hyperplane'], hyperplane: this.link['hyperplane'],
@ -60,6 +62,7 @@ class FourDGUI {
(v) => setLinkOpacity(v, false) (v) => setLinkOpacity(v, false)
); );
this.gui.add(this.params, 'nodesize', 0.1, 4); this.gui.add(this.params, 'nodesize', 0.1, 4);
this.gui.add(this.params, 'visibility', [ 0, 1, 2, 3, 4, 5 ]).onChange((v) => setVisibility(v));
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, 'rotation', [ 'rigid', 'tumbling', 'inside-out', 'axisymmetrical' ]); this.gui.add(this.params, 'rotation', [ 'rigid', 'tumbling', 'inside-out', 'axisymmetrical' ]);
@ -96,7 +99,7 @@ class FourDGUI {
const guiObj = this; const guiObj = this;
this.urlParams = this.linkUrl.searchParams; this.urlParams = this.linkUrl.searchParams;
for( const param of [ "shape", "rotation" ]) { for( const param of [ "shape", "rotation", "visiblity" ]) {
const value = this.urlParams.get(param); const value = this.urlParams.get(param);
if( value ) { if( value ) {
this.link[param] = value; this.link[param] = value;

15
main.js
View File

@ -61,6 +61,10 @@ for( const face_m of face_ms ) {
face_m.opacity = FACE_OPACITY; face_m.opacity = FACE_OPACITY;
} }
// the best way to do this -
// each STRUCTURE should present a menu of OPTIONS which
// are say a set of inscribed shapes, or a subset etc
// ie 120-cell - inscribed, layers, hopf fibrations etc
const STRUCTURES = { const STRUCTURES = {
'5-cell': POLYTOPES.cell5(), '5-cell': POLYTOPES.cell5(),
@ -144,13 +148,18 @@ function setLinkOpacity(o, primary) {
} }
let gui; // let gui; //
let visible_labels = 6;
function changeShape() { function changeShape() {
console.log("change shape!")
createShape(gui.params.shape, gui.params.inscribed, gui.params.inscribe_all); createShape(gui.params.shape, gui.params.inscribed, gui.params.inscribe_all);
} }
gui = new FourDGUI(changeShape, setColors, setBackground, setLinkOpacity); function setVisibility(v) {
console.log("setVisibility");
visible_labels = v;
}
gui = new FourDGUI(changeShape, setColors, setBackground, setLinkOpacity, setVisibility);
// these are here to pick up colour settings from the URL params // these are here to pick up colour settings from the URL params
setColors(gui.params.color); setColors(gui.params.color);
@ -212,7 +221,7 @@ function animate() {
shape.hyperplane = gui.params.hyperplane; shape.hyperplane = gui.params.hyperplane;
shape.link_scale = gui.params.thickness; shape.link_scale = gui.params.thickness;
shape.node_scale = gui.params.nodesize; shape.node_scale = gui.params.nodesize;
shape.render3(rotations); shape.render3(rotations, (l) => l <= visible_labels);
renderer.render( scene, camera ); renderer.render( scene, camera );
} }