From cab5878ac82f6a749df2ebbe93558b145154ae94 Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Tue, 9 Apr 2024 15:05:39 +1000 Subject: [PATCH 1/2] Added node size scaling with w-foreshortening - looks kind of goofy --- fourDShape.js | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/fourDShape.js b/fourDShape.js index db99a53..daea51f 100644 --- a/fourDShape.js +++ b/fourDShape.js @@ -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 sphere = new THREE.Mesh(geometry, material); 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); for ( const m4 of rotations ) { 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); } + 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() { 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); this.nodes3[n.id] = { v3: v3, label: n.label, - object: this.makeNode(material, v3) + object: this.makeNode(material, v3, k) }; } for( const l of this.links ) { @@ -134,10 +151,14 @@ class FourDShape extends THREE.Group { render3(rotations, nodes_show, links_show) { this.scalev3 = new THREE.Vector3(this.node_scale, this.node_scale, this.node_scale); 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; + 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(this.scalev3); + this.nodes3[n.id].object.scale.copy(s3); this.nodes3[n.id].object.visible = ( !nodes_show || n.label in nodes_show ); } for( const l of this.links ) { From 1e5db22c25471b7ae7d46fe40112b6c32dfc3cbb Mon Sep 17 00:00:00 2001 From: Mike Lynch Date: Sun, 14 Apr 2024 16:08:46 +1000 Subject: [PATCH 2/2] scale factor for node foreshortening --- fourDShape.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fourDShape.js b/fourDShape.js index daea51f..d42ac17 100644 --- a/fourDShape.js +++ b/fourDShape.js @@ -2,7 +2,7 @@ import * as THREE from 'three'; const HYPERPLANE = 2.0; - +const NODE_FORESHORTENING = 0.4; class FourDShape extends THREE.Group { @@ -154,7 +154,7 @@ class FourDShape extends THREE.Group { 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; + 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].object.position.copy(v3);