Wireframe.js 1.6 KB

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