74 lines
2.0 KiB
JavaScript
74 lines
2.0 KiB
JavaScript
import * as THREE from 'three';
|
|
|
|
// wtf dude
|
|
|
|
class TaperedLink extends THREE.Group {
|
|
|
|
constructor(baseMaterial, n1, n2, r1, r2) {
|
|
super();
|
|
//const geometry = new THREE.ConeGeometry( 1, 1, 32, true );
|
|
const geometry = new THREE.CylinderGeometry( 1, 1, 1, 16, 1, true);
|
|
const cplane = new THREE.Plane(new THREE.Vector3(0, -1, 0), 0.5);
|
|
const material = baseMaterial.clone();
|
|
// material.clippingPlanes = [ cplane ];
|
|
this.object = new THREE.Mesh( geometry, material );
|
|
this.add( this.object );
|
|
this.update(n1, n2, r1, r2);
|
|
}
|
|
|
|
update_cone_busted(n1, n2, r1, r2) {
|
|
const kraw = r1 - r2;
|
|
let k = ( kraw == 0 ) ? 0.001 : kraw;
|
|
let nbase = n1.v3;
|
|
let napex = n2.v3;
|
|
let rbase = r1;
|
|
let rapex = r2;
|
|
if( k < 0 ) {
|
|
nbase = n2.v3;
|
|
napex = n1.v3;
|
|
rbase = r2;
|
|
rapex = r1;
|
|
k = -k;
|
|
}
|
|
|
|
const l = nbase.distanceTo(napex);
|
|
const lapex = l * rapex / k;
|
|
const h = l + lapex;
|
|
this.object.scale.copy(new THREE.Vector3(rbase, h, rbase));
|
|
const h_offset = 0.5 * h / l;
|
|
const pos = new THREE.Vector3();
|
|
pos.lerpVectors(nbase, napex, h_offset);
|
|
|
|
|
|
//this.scale.copy(new THREE.Vector3(rbase, h, rbase));
|
|
this.position.copy(pos); // the group, not the cone!!
|
|
|
|
this.lookAt(napex);
|
|
this.rotation.y = 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
|
|
);
|
|
|
|
*/
|
|
}
|
|
|
|
update(n1, n2, r1, r2) {
|
|
const length = n1.v3.distanceTo(n2.v3);
|
|
const centre = new THREE.Vector3();
|
|
centre.lerpVectors(n1.v3, n2.v3, 0.5);
|
|
const link_mean = (r1 + r2) * 0.5;
|
|
this.scale.copy(new THREE.Vector3(link_mean, link_mean, length));
|
|
this.position.copy(centre);
|
|
this.lookAt(n2.v3);
|
|
this.children[0].rotation.x = Math.PI / 2.0;
|
|
this.visible = true;
|
|
}
|
|
|
|
|
|
export { TaperedLink };
|