Merge branch 'feature-node-foreshortening'
commit
1ec7955861
|
@ -2,7 +2,7 @@ import * as THREE from 'three';
|
||||||
|
|
||||||
|
|
||||||
const HYPERPLANE = 2.0;
|
const HYPERPLANE = 2.0;
|
||||||
|
const NODE_FORESHORTENING = 0.4;
|
||||||
|
|
||||||
class FourDShape extends THREE.Group {
|
class FourDShape extends THREE.Group {
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ class FourDShape extends THREE.Group {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
makeNode(material, v3) {
|
makeNode(material, v3, scale) {
|
||||||
const geometry = new THREE.SphereGeometry(this.node_size);
|
const geometry = new THREE.SphereGeometry(this.node_size);
|
||||||
const sphere = new THREE.Mesh(geometry, material);
|
const sphere = new THREE.Mesh(geometry, material);
|
||||||
sphere.position.copy(v3);
|
sphere.position.copy(v3);
|
||||||
|
@ -100,24 +100,41 @@ class FourDShape extends THREE.Group {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fourDtoV3(x, y, z, w, rotations) {
|
fourDtoV3_old(x, y, z, w, rotations) {
|
||||||
const v4 = new THREE.Vector4(x, y, z, w);
|
const v4 = new THREE.Vector4(x, y, z, w);
|
||||||
for ( const m4 of rotations ) {
|
for ( const m4 of rotations ) {
|
||||||
v4.applyMatrix4(m4);
|
v4.applyMatrix4(m4);
|
||||||
}
|
}
|
||||||
const k = this.hyperplane / (this.hyperplane + v4.w);
|
const k = this.fourDscale(v4.w);
|
||||||
return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
|
return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fourDscale(w) {
|
||||||
|
return this.hyperplane / ( this.hyperplane + w );
|
||||||
|
}
|
||||||
|
|
||||||
|
fourDrotate(x, y, z, w, rotations) {
|
||||||
|
const v4 = new THREE.Vector4(x, y, z, w);
|
||||||
|
for ( const m4 of rotations ) {
|
||||||
|
v4.applyMatrix4(m4);
|
||||||
|
}
|
||||||
|
return v4;
|
||||||
|
}
|
||||||
|
|
||||||
|
fourDtoV3(v4) {
|
||||||
|
const k = this.fourDscale(v4.w);
|
||||||
|
return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
|
||||||
|
}
|
||||||
|
|
||||||
initShapes() {
|
initShapes() {
|
||||||
for( const n of this.nodes4 ) {
|
for( const n of this.nodes4 ) {
|
||||||
const v3 = this.fourDtoV3(n.x, n.y, n.z, n.w, []);
|
const k = this.fourDscale(n.w);
|
||||||
|
const v3 = new THREE.Vector3(n.x * k, n.y * k, n.z * k);
|
||||||
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,
|
label: n.label,
|
||||||
object: this.makeNode(material, v3)
|
object: this.makeNode(material, v3, k)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
for( const l of this.links ) {
|
for( const l of this.links ) {
|
||||||
|
@ -134,10 +151,14 @@ class FourDShape extends THREE.Group {
|
||||||
render3(rotations, nodes_show, links_show) {
|
render3(rotations, nodes_show, links_show) {
|
||||||
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 v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations);
|
||||||
|
const k = this.fourDscale(v4.w);
|
||||||
|
const v3 = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
|
||||||
|
const s4 = k * this.node_scale * NODE_FORESHORTENING;
|
||||||
|
const s3 = new THREE.Vector3(s4, s4, s4);
|
||||||
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(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 );
|
||||||
}
|
}
|
||||||
for( const l of this.links ) {
|
for( const l of this.links ) {
|
||||||
|
|
Loading…
Reference in New Issue