Skip to content

Commit de9b967

Browse files
authored
LineGeometry: Override setFromPoints method (#29681)
* Added setFromPoints method to LineGeometry * Added method to the docs
1 parent 9f05e61 commit de9b967

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

docs/examples/en/lines/LineGeometry.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ <h3>[method:this setPositions]( [param:Array array] )</h3>
7575
The length must be a multiple of three.
7676
</p>
7777

78+
<h3>[method:this setFromPoints]( [param:Array points] )</h3>
79+
<p>
80+
Replace the vertex positions with an array of points.
81+
Can be either a `Vector3` or `Vector2` array.
82+
</p>
83+
7884
<h2>Source</h2>
7985

8086
<p>

examples/jsm/lines/LineGeometry.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,31 @@ class LineGeometry extends LineSegmentsGeometry {
6262

6363
}
6464

65+
setFromPoints( points ) {
66+
67+
// converts a vector3 or vector2 array to pairs format
68+
69+
const length = points.length - 1;
70+
const positions = new Float32Array( 6 * length );
71+
72+
for ( let i = 0; i < length; i ++ ) {
73+
74+
positions[ 6 * i ] = points[ i ].x;
75+
positions[ 6 * i + 1 ] = points[ i ].y;
76+
positions[ 6 * i + 2 ] = points[ i ].z || 0;
77+
78+
positions[ 6 * i + 3 ] = points[ i + 1 ].x;
79+
positions[ 6 * i + 4 ] = points[ i + 1 ].y;
80+
positions[ 6 * i + 5 ] = points[ i + 1 ].z || 0;
81+
82+
}
83+
84+
super.setPositions( positions );
85+
86+
return this;
87+
88+
}
89+
6590
fromLine( line ) {
6691

6792
const geometry = line.geometry;

0 commit comments

Comments
 (0)