Compare commits

...

1 Commits

Author SHA1 Message Date
Mike Lynch 8ebb104bb3 Isometric projections 2024-04-25 10:37:45 +10:00
1 changed files with 20 additions and 19 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.projection = 1;
this.initShapes(); this.initShapes();
} }
@ -100,15 +101,6 @@ class FourDShape extends THREE.Group {
} }
fourDtoV3_old(x, y, z, w, rotations) {
const v4 = new THREE.Vector4(x, y, z, w);
for ( const m4 of rotations ) {
v4.applyMatrix4(m4);
}
const k = this.fourDscale(v4.w);
return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
}
fourDscale(w) { fourDscale(w) {
return this.hyperplane / ( this.hyperplane + w ); return this.hyperplane / ( this.hyperplane + w );
} }
@ -121,11 +113,24 @@ class FourDShape extends THREE.Group {
return v4; return v4;
} }
fourDtoV3(v4) { renderNodePerspective(n, 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);
return new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k); const position = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k);
const s4 = k * this.node_scale * NODE_FORESHORTENING;
const scale = new THREE.Vector3(s4, s4, s4);
return { position: position, scale: scale }
} }
renderNodeIsometric(n, rotations) {
const v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations);
const position = new THREE.Vector3(v4.x, v4.y + v4.w, v4.z);
const s4 = this.node_scale;
const scale = new THREE.Vector3(s4, s4, s4);
return { position: position, scale: scale }
}
initShapes() { initShapes() {
for( const n of this.nodes4 ) { for( const n of this.nodes4 ) {
const k = this.fourDscale(n.w); const k = this.fourDscale(n.w);
@ -151,14 +156,10 @@ 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 v4 = this.fourDrotate(n.x, n.y, n.z, n.w, rotations); const node3d = this.renderNodeIsometric(n, rotations);
const k = this.fourDscale(v4.w); this.nodes3[n.id].v3 = node3d.position;
const v3 = new THREE.Vector3(v4.x * k, v4.y * k, v4.z * k); this.nodes3[n.id].object.position.copy(node3d.position);
const s4 = k * this.node_scale * NODE_FORESHORTENING; this.nodes3[n.id].object.scale.copy(node3d.scale);
const s3 = new THREE.Vector3(s4, s4, s4);
this.nodes3[n.id].v3 = v3;
this.nodes3[n.id].object.position.copy(v3);
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 ) {