BoxLineGeometry.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. console.warn( "THREE.BoxLineGeometry: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  3. THREE.BufferGeometry.call( this );
  4. width = width || 1;
  5. height = height || 1;
  6. depth = depth || 1;
  7. widthSegments = Math.floor( widthSegments ) || 1;
  8. heightSegments = Math.floor( heightSegments ) || 1;
  9. depthSegments = Math.floor( depthSegments ) || 1;
  10. var widthHalf = width / 2;
  11. var heightHalf = height / 2;
  12. var depthHalf = depth / 2;
  13. var segmentWidth = width / widthSegments;
  14. var segmentHeight = height / heightSegments;
  15. var segmentDepth = depth / depthSegments;
  16. var vertices = [];
  17. var x = - widthHalf, y = - heightHalf, z = - depthHalf;
  18. for ( var 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 ( var 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 ( var 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. THREE.BoxLineGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  42. THREE.BoxLineGeometry.prototype.constructor = THREE.BoxLineGeometry;