BoxLineGeometry.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. console.warn( "THREE.BoxLineGeometry: As part of the transition to ES6 Modules, the files in 'examples/js' have been deprecated in r117 (May 2020) and will be deleted in r124 (December 2020). You can find more information about developing using ES6 Modules in https://threejs.org/docs/index.html#manual/en/introduction/Import-via-modules." );
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  6. THREE.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 THREE.Float32BufferAttribute( vertices, 3 ) );
  43. };
  44. THREE.BoxLineGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  45. THREE.BoxLineGeometry.prototype.constructor = THREE.BoxLineGeometry;