index.html 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <head>
  2. <style> body { margin: 0; } </style>
  3. <script src="//unpkg.com/three"></script>
  4. <script src="//unpkg.com/3d-force-graph"></script>
  5. <!-- <script src="../../dist/3d-force-graph.js"></script> -->
  6. </head>
  7. <body>
  8. <div id="3d-graph"></div>
  9. <script>
  10. // Random tree
  11. const N = 30;
  12. const gData = {
  13. nodes: [...Array(N).keys()].map(i => ({ id: i })),
  14. links: [...Array(N).keys()]
  15. .filter(id => id)
  16. .map(id => ({
  17. source: id,
  18. target: Math.round(Math.random() * (id-1))
  19. }))
  20. };
  21. const graph = ForceGraph3D()
  22. (document.getElementById('3d-graph'))
  23. .graphData(gData);
  24. const planeGeometry = new THREE.PlaneGeometry(1000, 1000, 1, 1);
  25. const planeMaterial = new THREE.MeshLambertMaterial({color: 0xFF0000, side: THREE.DoubleSide});
  26. const mesh = new THREE.Mesh(planeGeometry, planeMaterial);
  27. mesh.position.set(-100, -200, -100);
  28. mesh.rotation.set(0.5 * Math.PI, 0, 0);
  29. graph.scene().add(mesh);
  30. </script>
  31. </body>