diff --git a/examples/files.json b/examples/files.json index 50e4ea19b26d35..c1e030d09dc625 100644 --- a/examples/files.json +++ b/examples/files.json @@ -339,6 +339,7 @@ "webgpu_lights_phong", "webgpu_lights_rectarealight", "webgpu_lights_selective", + "webgpu_lines_fat_wireframe", "webgpu_lines_fat", "webgpu_loader_gltf", "webgpu_loader_gltf_anisotropy", diff --git a/examples/jsm/lines/LineSegmentsGeometry.js b/examples/jsm/lines/LineSegmentsGeometry.js index c7cf8774bc9c41..ca9741528ac129 100644 --- a/examples/jsm/lines/LineSegmentsGeometry.js +++ b/examples/jsm/lines/LineSegmentsGeometry.js @@ -82,6 +82,8 @@ class LineSegmentsGeometry extends InstancedBufferGeometry { this.setAttribute( 'instanceStart', new InterleavedBufferAttribute( instanceBuffer, 3, 0 ) ); // xyz this.setAttribute( 'instanceEnd', new InterleavedBufferAttribute( instanceBuffer, 3, 3 ) ); // xyz + this.instanceCount = this.attributes.instanceStart.count; + // this.computeBoundingBox(); diff --git a/examples/jsm/lines/webgpu/LineSegments2.js b/examples/jsm/lines/webgpu/LineSegments2.js index afdce7dda40cff..c4d76511ed86d9 100644 --- a/examples/jsm/lines/webgpu/LineSegments2.js +++ b/examples/jsm/lines/webgpu/LineSegments2.js @@ -13,8 +13,6 @@ import { } from 'three'; import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js'; -const _viewport = new Vector4(); - const _start = new Vector3(); const _end = new Vector3(); @@ -358,19 +356,6 @@ class LineSegments2 extends Mesh { } - onBeforeRender( renderer ) { - - const uniforms = this.material.uniforms; - - if ( uniforms && uniforms.resolution ) { - - renderer.getViewport( _viewport ); - this.material.uniforms.resolution.value.set( _viewport.z, _viewport.w ); - - } - - } - } export { LineSegments2 }; diff --git a/examples/jsm/lines/webgpu/Wireframe.js b/examples/jsm/lines/webgpu/Wireframe.js new file mode 100644 index 00000000000000..972031540d2ba7 --- /dev/null +++ b/examples/jsm/lines/webgpu/Wireframe.js @@ -0,0 +1,56 @@ +import { + InstancedInterleavedBuffer, + InterleavedBufferAttribute, + Line2NodeMaterial, + Mesh, + Vector3 +} from 'three'; +import { LineSegmentsGeometry } from '../../lines/LineSegmentsGeometry.js'; + +const _start = new Vector3(); +const _end = new Vector3(); + +class Wireframe extends Mesh { + + constructor( geometry = new LineSegmentsGeometry(), material = new Line2NodeMaterial( { color: Math.random() * 0xffffff } ) ) { + + super( geometry, material ); + + this.isWireframe = true; + + this.type = 'Wireframe'; + + } + + // for backwards-compatibility, but could be a method of LineSegmentsGeometry... + + computeLineDistances() { + + const geometry = this.geometry; + + const instanceStart = geometry.attributes.instanceStart; + const instanceEnd = geometry.attributes.instanceEnd; + const lineDistances = new Float32Array( 2 * instanceStart.count ); + + for ( let i = 0, j = 0, l = instanceStart.count; i < l; i ++, j += 2 ) { + + _start.fromBufferAttribute( instanceStart, i ); + _end.fromBufferAttribute( instanceEnd, i ); + + lineDistances[ j ] = ( j === 0 ) ? 0 : lineDistances[ j - 1 ]; + lineDistances[ j + 1 ] = lineDistances[ j ] + _start.distanceTo( _end ); + + } + + const instanceDistanceBuffer = new InstancedInterleavedBuffer( lineDistances, 2, 1 ); // d0, d1 + + geometry.setAttribute( 'instanceDistanceStart', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 0 ) ); // d0 + geometry.setAttribute( 'instanceDistanceEnd', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 1 ) ); // d1 + + return this; + + } + +} + +export { Wireframe }; diff --git a/examples/screenshots/webgpu_lines_fat_wireframe.jpg b/examples/screenshots/webgpu_lines_fat_wireframe.jpg new file mode 100644 index 00000000000000..e08c9ab64a96bc Binary files /dev/null and b/examples/screenshots/webgpu_lines_fat_wireframe.jpg differ diff --git a/examples/webgpu_lines_fat.html b/examples/webgpu_lines_fat.html index d9c72733b0b595..824ca2f4d7b178 100644 --- a/examples/webgpu_lines_fat.html +++ b/examples/webgpu_lines_fat.html @@ -102,7 +102,6 @@ const geometry = new LineGeometry(); geometry.setPositions( positions ); geometry.setColors( colors ); - geometry.instanceCount = positions.length / 3 - 1; matLine = new THREE.Line2NodeMaterial( { diff --git a/examples/webgpu_lines_fat_wireframe.html b/examples/webgpu_lines_fat_wireframe.html new file mode 100644 index 00000000000000..1421073c8a41fe --- /dev/null +++ b/examples/webgpu_lines_fat_wireframe.html @@ -0,0 +1,268 @@ + + + + three.js webgpu - lines - fat - wireframe + + + + + + + +
+ +
three.js - fat lines
+ + + + + + + +