Wireframe.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. console.warn( "THREE.Wireframe: 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.Wireframe = function ( geometry, material ) {
  3. THREE.Mesh.call( this );
  4. this.type = 'Wireframe';
  5. this.geometry = geometry !== undefined ? geometry : new THREE.LineSegmentsGeometry();
  6. this.material = material !== undefined ? material : new THREE.LineMaterial( { color: Math.random() * 0xffffff } );
  7. };
  8. THREE.Wireframe.prototype = Object.assign( Object.create( THREE.Mesh.prototype ), {
  9. constructor: THREE.Wireframe,
  10. isWireframe: true,
  11. computeLineDistances: ( function () { // for backwards-compatability, but could be a method of LineSegmentsGeometry...
  12. var start = new THREE.Vector3();
  13. var end = new THREE.Vector3();
  14. return function computeLineDistances() {
  15. var geometry = this.geometry;
  16. var instanceStart = geometry.attributes.instanceStart;
  17. var instanceEnd = geometry.attributes.instanceEnd;
  18. var lineDistances = new Float32Array( 2 * instanceStart.data.count );
  19. for ( var i = 0, j = 0, l = instanceStart.data.count; i < l; i ++, j += 2 ) {
  20. start.fromBufferAttribute( instanceStart, i );
  21. end.fromBufferAttribute( instanceEnd, i );
  22. lineDistances[ j ] = ( j === 0 ) ? 0 : lineDistances[ j - 1 ];
  23. lineDistances[ j + 1 ] = lineDistances[ j ] + start.distanceTo( end );
  24. }
  25. var instanceDistanceBuffer = new THREE.InstancedInterleavedBuffer( lineDistances, 2, 1 ); // d0, d1
  26. geometry.setAttribute( 'instanceDistanceStart', new THREE.InterleavedBufferAttribute( instanceDistanceBuffer, 1, 0 ) ); // d0
  27. geometry.setAttribute( 'instanceDistanceEnd', new THREE.InterleavedBufferAttribute( instanceDistanceBuffer, 1, 1 ) ); // d1
  28. return this;
  29. };
  30. }() )
  31. } );