Wireframe.js 2.0 KB

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