Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3KB

  1. var materials = {};
  2. var curveProperties = {
  3. splineDensity: 8,
  4. curvature: 20
  5. };
  6. materials.prepare = function() {
  7. var sprite = new THREE.Texture(document.getElementById("ball"));
  8. sprite.needsUpdate = true;
  9. materials.edge = new THREE.LineBasicMaterial({
  10. color: "gray",
  11. transparent: false,
  12. linewidth: 1
  13. });
  14. materials.point = new THREE.PointsMaterial({
  15. size: 0.1,
  16. map: sprite,
  17. alphaTest: 0.5,
  18. transparent: true,
  19. vertexColors: THREE.VertexColors
  20. });
  21. materials.qubit = new THREE.PointsMaterial({
  22. size: 0.3,
  23. map: sprite,
  24. alphaTest: 0.5,
  25. transparent: true,
  26. vertexColors: THREE.VertexColors
  27. });
  28. };
  29. materials.makeCurve = function(a, b) {
  30. var length = new THREE.Vector3().subVectors(a, b).length();
  31. var bend = new THREE.Vector3(length / curveProperties.curvature, length / curveProperties.curvature, 0);
  32. var mid = new THREE.Vector3().add(a).add(b).multiplyScalar(0.5).add(bend);
  33. var spline = new THREE.CatmullRomCurve3([a, mid, b]);
  34. var geometry = new THREE.Geometry();
  35. var splinePoints = spline.getPoints(curveProperties.splineDensity);
  36. Array.prototype.push.apply(geometry.vertices, splinePoints);
  37. return new THREE.Line(geometry, materials.edge);
  38. };