BoxLineGeometry.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. THREE.BoxLineGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  2. THREE.BufferGeometry.call( this );
  3. width = width || 1;
  4. height = height || 1;
  5. depth = depth || 1;
  6. widthSegments = Math.floor( widthSegments ) || 1;
  7. heightSegments = Math.floor( heightSegments ) || 1;
  8. depthSegments = Math.floor( depthSegments ) || 1;
  9. var widthHalf = width / 2;
  10. var heightHalf = height / 2;
  11. var depthHalf = depth / 2;
  12. var segmentWidth = width / widthSegments;
  13. var segmentHeight = height / heightSegments;
  14. var segmentDepth = depth / depthSegments;
  15. var vertices = [];
  16. var x = - widthHalf, y = - heightHalf, z = - depthHalf;
  17. for ( var i = 0; i <= widthSegments; i ++ ) {
  18. vertices.push( x, - heightHalf, - depthHalf, x, heightHalf, - depthHalf );
  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. x += segmentWidth;
  23. }
  24. for ( var i = 0; i <= heightSegments; i ++ ) {
  25. vertices.push( - widthHalf, y, - depthHalf, widthHalf, y, - depthHalf );
  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. y += segmentHeight;
  30. }
  31. for ( var i = 0; i <= depthSegments; i ++ ) {
  32. vertices.push( - widthHalf, - heightHalf, z, - widthHalf, heightHalf, z );
  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. z += segmentDepth;
  37. }
  38. this.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
  39. };
  40. THREE.BoxLineGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  41. THREE.BoxLineGeometry.prototype.constructor = THREE.BoxLineGeometry;