Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. var planePointA = new THREE.Vector3(),
  2. planePointB = new THREE.Vector3(),
  3. planePointC = new THREE.Vector3();
  4.  
  5. var mathPlane = new THREE.Plane();
  6. plane.localToWorld(planePointA.copy(plane.geometry.vertices[plane.geometry.faces[0].a]));
  7. plane.localToWorld(planePointB.copy(plane.geometry.vertices[plane.geometry.faces[0].b]));
  8. plane.localToWorld(planePointC.copy(plane.geometry.vertices[plane.geometry.faces[0].c]));
  9. mathPlane.setFromCoplanarPoints(planePointA, planePointB, planePointC);
  10.  
  11. obj.geometry.faces.forEach(function(face) {
  12. obj.localToWorld(a.copy(obj.geometry.vertices[face.a]));
  13. obj.localToWorld(b.copy(obj.geometry.vertices[face.b]));
  14. obj.localToWorld(c.copy(obj.geometry.vertices[face.c]));
  15. lineAB = new THREE.Line3(a, b);
  16. lineBC = new THREE.Line3(b, c);
  17. lineCA = new THREE.Line3(c, a);
  18. setPointOfIntersection(lineAB, mathPlane);
  19. setPointOfIntersection(lineBC, mathPlane);
  20. setPointOfIntersection(lineCA, mathPlane);
  21. });
  22.  
  23. var pointsOfIntersection = new THREE.Geometry();
  24. ...
  25. var pointOfIntersection = new THREE.Vector3();
  26.  
  27. function setPointOfIntersection(line, plane) {
  28. pointOfIntersection = plane.intersectLine(line);
  29. if (pointOfIntersection) {
  30. pointsOfIntersection.vertices.push(pointOfIntersection.clone());
  31. };
  32. }
  33.  
  34. var pointsMaterial = new THREE.PointsMaterial({
  35. size: .5,
  36. color: "yellow"
  37. });
  38. var points = new THREE.Points(pointsOfIntersection, pointsMaterial);
  39. scene.add(points);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement