2023-07-22 01:11:18 +00:00
|
|
|
import * as THREE from 'three';
|
|
|
|
|
2023-07-22 03:24:42 +00:00
|
|
|
const NODE_SIZE = 0.2;
|
|
|
|
const LINK_SIZE = 0.1;
|
|
|
|
|
2023-07-22 03:40:01 +00:00
|
|
|
function makeWireFrame(link_m, node_m, graph) {
|
2023-07-22 03:24:42 +00:00
|
|
|
const nodeids = {}
|
|
|
|
const group = new THREE.Group();
|
|
|
|
for ( const n of graph.nodes ) {
|
|
|
|
nodeids[n.id] = [ n.x, n.y, n.z ];
|
2023-07-22 03:40:01 +00:00
|
|
|
const geometry = new THREE.SphereGeometry(NODE_SIZE);
|
|
|
|
const sphere = new THREE.Mesh(geometry, mode_m);
|
2023-07-22 03:24:42 +00:00
|
|
|
group.add(sphere);
|
2023-07-22 03:40:01 +00:00
|
|
|
sphere.position.x = n.x;
|
|
|
|
sphere.position.y = n.y;
|
|
|
|
sphere.position.z = n.z;
|
2023-07-22 03:24:42 +00:00
|
|
|
}
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// const shape = makeShape({
|
|
|
|
// nodes: [
|
|
|
|
// { id: 1, x: -10, y: -10, z: -10 },
|
|
|
|
// { id: 2, x: 10, y: 10, z: 10}
|
|
|
|
// ],
|
|
|
|
// links: [
|
|
|
|
// { id: 1, source: 1, target: 1 }
|
|
|
|
// ]
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-22 01:11:18 +00:00
|
|
|
const scene = new THREE.Scene();
|
|
|
|
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
|
|
|
|
|
|
|
|
const renderer = new THREE.WebGLRenderer();
|
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
|
document.body.appendChild( renderer.domElement );
|
|
|
|
|
2023-07-22 03:24:42 +00:00
|
|
|
|
|
|
|
const group = new THREE.Group();
|
|
|
|
|
|
|
|
const sphere_g = new THREE.SphereGeometry( 1 );
|
|
|
|
const sphere_m = new THREE.MeshBasicMaterial( { color: 0x33ff00 } );
|
|
|
|
const sphere = new THREE.Mesh( sphere_g, sphere_m );
|
|
|
|
group.add( sphere );
|
|
|
|
|
2023-07-22 03:40:01 +00:00
|
|
|
sphere.position.x = -2;
|
|
|
|
|
|
|
|
const sphere2_g = new THREE.SphereGeometry( 1 );
|
|
|
|
const sphere2 = new THREE.Mesh( sphere_g, sphere_m );
|
|
|
|
group.add( sphere2 );
|
|
|
|
|
|
|
|
|
|
|
|
sphere2.position.x = 2;
|
|
|
|
|
|
|
|
|
2023-07-22 03:24:42 +00:00
|
|
|
const cyl_g = new THREE.CylinderGeometry( 0.2, 0.2, 4 );
|
|
|
|
const cyl_m = new THREE.MeshBasicMaterial( { color: 0x009930 } );
|
|
|
|
const cyl = new THREE.Mesh( cyl_g, cyl_m );
|
|
|
|
group.add( cyl );
|
|
|
|
|
|
|
|
|
2023-07-22 03:40:01 +00:00
|
|
|
// const shape = makeShape({
|
|
|
|
// nodes: [
|
|
|
|
// { id: 1, x: -10, y: -10, z: -10 },
|
|
|
|
// { id: 2, x: 10, y: 10, z: 10}
|
|
|
|
// ],
|
|
|
|
// links: [
|
|
|
|
// { id: 1, source: 1, target: 1 }
|
|
|
|
// ]
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-07-22 03:24:42 +00:00
|
|
|
scene.add(group);
|
|
|
|
|
|
|
|
|
2023-07-22 01:11:18 +00:00
|
|
|
|
|
|
|
camera.position.z = 5;
|
|
|
|
|
2023-07-22 03:24:42 +00:00
|
|
|
let tick = 0;
|
|
|
|
|
2023-07-22 01:11:18 +00:00
|
|
|
function animate() {
|
|
|
|
requestAnimationFrame( animate );
|
|
|
|
|
2023-07-22 03:40:01 +00:00
|
|
|
group.position.x = Math.sin(tick) * 2;
|
2023-07-22 03:24:42 +00:00
|
|
|
group.rotation.y = tick;
|
2023-07-22 01:11:18 +00:00
|
|
|
|
2023-07-22 03:24:42 +00:00
|
|
|
tick += 0.01;
|
2023-07-22 01:11:18 +00:00
|
|
|
renderer.render( scene, camera );
|
|
|
|
}
|
|
|
|
animate();
|