ExplodeModifier.js 773 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. var ExplodeModifier = function () {
  8. };
  9. 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. };
  29. export { ExplodeModifier };