ExplodeModifier.js 750 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Make all faces use unique vertices
  3. * so that each face can be separated from others
  4. *
  5. * @author alteredq / http://alteredqualia.com/
  6. */
  7. THREE.ExplodeModifier = function () {
  8. };
  9. THREE.ExplodeModifier.prototype.modify = function ( geometry ) {
  10. var vertices = [];
  11. for ( var i = 0, il = geometry.faces.length; i < il; i ++ ) {
  12. var n = vertices.length;
  13. var face = geometry.faces[ i ];
  14. var a = face.a;
  15. var b = face.b;
  16. var c = face.c;
  17. var va = geometry.vertices[ a ];
  18. var vb = geometry.vertices[ b ];
  19. var vc = geometry.vertices[ c ];
  20. vertices.push( va.clone() );
  21. vertices.push( vb.clone() );
  22. vertices.push( vc.clone() );
  23. face.a = n;
  24. face.b = n + 1;
  25. face.c = n + 2;
  26. }
  27. geometry.vertices = vertices;
  28. };