BoxLineGeometry.js 2.1 KB

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