BoxLineGeometry.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {
  2. BufferGeometry,
  3. Float32BufferAttribute
  4. } from '../../../build/three.module.js';
  5. var BoxLineGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  6. BufferGeometry.call( this );
  7. width = width || 1;
  8. height = height || 1;
  9. depth = depth || 1;
  10. widthSegments = Math.floor( widthSegments ) || 1;
  11. heightSegments = Math.floor( heightSegments ) || 1;
  12. depthSegments = Math.floor( depthSegments ) || 1;
  13. var widthHalf = width / 2;
  14. var heightHalf = height / 2;
  15. var depthHalf = depth / 2;
  16. var segmentWidth = width / widthSegments;
  17. var segmentHeight = height / heightSegments;
  18. var segmentDepth = depth / depthSegments;
  19. var vertices = [];
  20. var x = - widthHalf, y = - heightHalf, z = - depthHalf;
  21. for ( var i = 0; i <= widthSegments; i ++ ) {
  22. vertices.push( x, - heightHalf, - depthHalf, x, heightHalf, - depthHalf );
  23. vertices.push( x, heightHalf, - depthHalf, x, heightHalf, depthHalf );
  24. vertices.push( x, heightHalf, depthHalf, x, - heightHalf, depthHalf );
  25. vertices.push( x, - heightHalf, depthHalf, x, - heightHalf, - depthHalf );
  26. x += segmentWidth;
  27. }
  28. for ( var i = 0; i <= heightSegments; i ++ ) {
  29. vertices.push( - widthHalf, y, - depthHalf, widthHalf, y, - depthHalf );
  30. vertices.push( widthHalf, y, - depthHalf, widthHalf, y, depthHalf );
  31. vertices.push( widthHalf, y, depthHalf, - widthHalf, y, depthHalf );
  32. vertices.push( - widthHalf, y, depthHalf, - widthHalf, y, - depthHalf );
  33. y += segmentHeight;
  34. }
  35. for ( var i = 0; i <= depthSegments; i ++ ) {
  36. vertices.push( - widthHalf, - heightHalf, z, - widthHalf, heightHalf, z );
  37. vertices.push( - widthHalf, heightHalf, z, widthHalf, heightHalf, z );
  38. vertices.push( widthHalf, heightHalf, z, widthHalf, - heightHalf, z );
  39. vertices.push( widthHalf, - heightHalf, z, - widthHalf, - heightHalf, z );
  40. z += segmentDepth;
  41. }
  42. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  43. };
  44. BoxLineGeometry.prototype = Object.create( BufferGeometry.prototype );
  45. BoxLineGeometry.prototype.constructor = BoxLineGeometry;
  46. export { BoxLineGeometry };