Anders and Briegel in Python
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

38 lines
1.2KB

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