0
0

BoxLineGeometry.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. ( function () {
  2. class BoxLineGeometry extends THREE.BufferGeometry {
  3. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  4. super();
  5. widthSegments = Math.floor( widthSegments );
  6. heightSegments = Math.floor( heightSegments );
  7. depthSegments = Math.floor( depthSegments );
  8. const widthHalf = width / 2;
  9. const heightHalf = height / 2;
  10. const depthHalf = depth / 2;
  11. const segmentWidth = width / widthSegments;
  12. const segmentHeight = height / heightSegments;
  13. const segmentDepth = depth / depthSegments;
  14. const vertices = [];
  15. let x = - widthHalf;
  16. let y = - heightHalf;
  17. let z = - depthHalf;
  18. for ( let i = 0; i <= widthSegments; i ++ ) {
  19. vertices.push( x, - heightHalf, - depthHalf, x, heightHalf, - depthHalf );
  20. vertices.push( x, heightHalf, - depthHalf, x, heightHalf, depthHalf );
  21. vertices.push( x, heightHalf, depthHalf, x, - heightHalf, depthHalf );
  22. vertices.push( x, - heightHalf, depthHalf, x, - heightHalf, - depthHalf );
  23. x += segmentWidth;
  24. }
  25. for ( let i = 0; i <= heightSegments; i ++ ) {
  26. vertices.push( - widthHalf, y, - depthHalf, widthHalf, y, - depthHalf );
  27. vertices.push( widthHalf, y, - depthHalf, widthHalf, y, depthHalf );
  28. vertices.push( widthHalf, y, depthHalf, - widthHalf, y, depthHalf );
  29. vertices.push( - widthHalf, y, depthHalf, - widthHalf, y, - depthHalf );
  30. y += segmentHeight;
  31. }
  32. for ( let i = 0; i <= depthSegments; i ++ ) {
  33. vertices.push( - widthHalf, - heightHalf, z, - widthHalf, heightHalf, z );
  34. vertices.push( - widthHalf, heightHalf, z, widthHalf, heightHalf, z );
  35. vertices.push( widthHalf, heightHalf, z, widthHalf, - heightHalf, z );
  36. vertices.push( widthHalf, - heightHalf, z, - widthHalf, - heightHalf, z );
  37. z += segmentDepth;
  38. }
  39. this.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
  40. }
  41. }
  42. THREE.BoxLineGeometry = BoxLineGeometry;
  43. } )();