Added a shape with a single link to make testing easier
This commit is contained in:
parent
a1fff090fc
commit
cc7f77a5a9
2
gui.js
2
gui.js
@ -7,7 +7,7 @@ const DEFAULTS = {
|
|||||||
linksize: 1.0,
|
linksize: 1.0,
|
||||||
linkopacity: 0.75,
|
linkopacity: 0.75,
|
||||||
link2opacity: 0.75,
|
link2opacity: 0.75,
|
||||||
shape: '16-cell',
|
shape: 'linky',
|
||||||
option: 'none',
|
option: 'none',
|
||||||
visibility: 5,
|
visibility: 5,
|
||||||
inscribed: false,
|
inscribed: false,
|
||||||
|
|||||||
27
polytopes.js
27
polytopes.js
@ -55,8 +55,28 @@ export function auto_detect_edges(nodes, neighbours, debug=false) {
|
|||||||
return links;
|
return links;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const linkTest = () => {
|
||||||
|
return {
|
||||||
|
name: 'linky',
|
||||||
|
nodes: [
|
||||||
|
{ id:1, label: 1, x: -1, y: -1, z:-1, w: 0 },
|
||||||
|
{ id:2, label: 2, x: 1, y: 1, z: 1, w: 0 },
|
||||||
|
],
|
||||||
|
links: [
|
||||||
|
{ id: 1, source: 1, target: 2 }
|
||||||
|
],
|
||||||
|
options: [ { name: '--' }],
|
||||||
|
description: `link`,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// too small and simple to calculate
|
// too small and simple to calculate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export const cell5 = () => {
|
export const cell5 = () => {
|
||||||
const c1 = Math.sqrt(5) / 4;
|
const c1 = Math.sqrt(5) / 4;
|
||||||
return {
|
return {
|
||||||
@ -844,7 +864,8 @@ export const icosahedron = () => {
|
|||||||
|
|
||||||
export const build_all = () => {
|
export const build_all = () => {
|
||||||
return [
|
return [
|
||||||
tetrahedron(),
|
linkTest(),
|
||||||
|
/* tetrahedron(),
|
||||||
octahedron(),
|
octahedron(),
|
||||||
cube(),
|
cube(),
|
||||||
icosahedron(),
|
icosahedron(),
|
||||||
@ -858,9 +879,9 @@ export const build_all = () => {
|
|||||||
cell600_layered(),
|
cell600_layered(),
|
||||||
cell120_inscribed(),
|
cell120_inscribed(),
|
||||||
cell120_layered()
|
cell120_layered()
|
||||||
];
|
*/ ];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const radii = (shape) => {
|
export const radii = (shape) => {
|
||||||
return shape.nodes.map(n => Math.sqrt(n.x * n.x + n.y * n.y + n.z * n.z + n.w * n.w))
|
return shape.nodes.map(n => Math.sqrt(n.x * n.x + n.y * n.y + n.z * n.z + n.w * n.w))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,46 +9,55 @@ class TaperedLink extends THREE.Group {
|
|||||||
const geometry = new THREE.ConeGeometry( 0.75, 1, 32, true );
|
const geometry = new THREE.ConeGeometry( 0.75, 1, 32, true );
|
||||||
const cplane = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0.5);
|
const cplane = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0.5);
|
||||||
const material = baseMaterial.clone();
|
const material = baseMaterial.clone();
|
||||||
// material.clippingPlanes = [ cplane ];
|
material.clippingPlanes = [ cplane ];
|
||||||
this.object = new THREE.Mesh( geometry, material );
|
this.cone = new THREE.Mesh( geometry, material );
|
||||||
this.add( this.object );
|
this.add( this.cone );
|
||||||
this.update(n1, n2, r1, r2);
|
this.update(n1, n2, r1, r2);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(n1, n2, r1, r2) {
|
update(n1, n2, r1, r2) {
|
||||||
const kraw = r1 - r2;
|
const kraw = r1 - r2;
|
||||||
const k = ( kraw == 0 ) ? 0.001 : kraw;
|
let k = ( kraw == 0 ) ? 0.001 : kraw;
|
||||||
let nbase = n1;
|
let nbase = n1.v3;
|
||||||
let napex = n2;
|
let napex = n2.v3;
|
||||||
let rbase = r1;
|
let rbase = r1;
|
||||||
let rapex = r2;
|
let rapex = r2;
|
||||||
if( k < 0 ) {
|
if( k < 0 ) {
|
||||||
nbase = n2;
|
nbase = n2.v3;
|
||||||
napex = n1;
|
napex = n1.v3;
|
||||||
rbase = r2;
|
rbase = r2;
|
||||||
rapex = r1;
|
rapex = r1;
|
||||||
|
k = -k;
|
||||||
}
|
}
|
||||||
const l = nbase.v3.distanceTo(napex.v3);
|
|
||||||
|
|
||||||
|
// FIXME - the problem is that when the h_offset > 1, the centroid
|
||||||
|
// of the cone is on the other side of napex, so it looks the wrong way
|
||||||
|
|
||||||
|
const l = nbase.distanceTo(napex);
|
||||||
const h = l * rbase / k;
|
const h = l * rbase / k;
|
||||||
//const pos = new THREE.Vector3(0, h/2 - l/2, 0);
|
const h_offset = 0.5 * h / l;
|
||||||
//pos.add(nbase.v3);
|
const pos = new THREE.Vector3();
|
||||||
this.object.scale.copy(new THREE.Vector3(rbase, h, rbase));
|
if( l > 0 ) {
|
||||||
this.object.position.copy(nbase.v3);
|
pos.lerpVectors(nbase, napex, h_offset);
|
||||||
this.object.lookAt(napex.v3);
|
}
|
||||||
this.object.rotation.x = Math.PI / 2.0;
|
if( h_offset < 1 ) {
|
||||||
|
this.cone.scale.copy(new THREE.Vector3(rbase, h, rbase));
|
||||||
|
} else {
|
||||||
|
// you're on the other side of napex so flip the cone
|
||||||
|
this.cone.scale.copy(new THREE.Vector3(rbase, -h, rbase));
|
||||||
|
}
|
||||||
|
this.lookAt(napex);
|
||||||
|
this.position.copy(pos);
|
||||||
|
this.cone.rotation.x = Math.PI / 2.0;
|
||||||
|
const clipnorm = new THREE.Vector3();
|
||||||
|
clipnorm.copy(napex);
|
||||||
|
clipnorm.sub(nbase);
|
||||||
|
clipnorm.negate();
|
||||||
|
clipnorm.normalize();
|
||||||
|
this.cone.material.clippingPlanes[0].setFromNormalAndCoplanarPoint(
|
||||||
|
clipnorm, napex
|
||||||
|
);
|
||||||
}
|
}
|
||||||
// this.object.material.clippingPlanes[0].normal.y = -1;
|
|
||||||
// this.object.material.clippingPlanes[0].constant = l / 2;
|
|
||||||
//this.object.position.copy(new THREE.Vector3(0, h/2 - l/2, 0));
|
|
||||||
// } else {
|
|
||||||
// const h = l * r2 / k;
|
|
||||||
// this.object.scale.copy(new THREE.Vector3(r2, h, r2));
|
|
||||||
// // this.object.material.clippingPlanes[0].normal.y = 1;
|
|
||||||
// // this.object.material.clippingPlanes[0].constant = l / 2;
|
|
||||||
// //this.object.position.copy(new THREE.Vector3(0, h / 2 + l / 2, 0));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user