-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Geometry: Move computeLineDistance() to Line/LineSegments #13147
Changes from 6 commits
4b82ecc
c0e5d25
e463b8c
0286198
2fbec23
0ec8b93
e1391a9
ccfee63
aeb4865
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,75 @@ Line.prototype = Object.assign( Object.create( Object3D.prototype ), { | |
|
||
isLine: true, | ||
|
||
computeLineDistances: ( function () { | ||
|
||
var start = new Vector3(); | ||
var end = new Vector3(); | ||
|
||
return function computeLineDistances() { | ||
|
||
var distance = 0; | ||
var geometry = this.geometry; | ||
|
||
if ( geometry.isBufferGeometry ) { | ||
|
||
// we assume non-indexed geometry | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you think you should handle indexed geometry gracefully? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right. It should be better with 0286198 |
||
|
||
if ( geometry.index === null ) { | ||
|
||
var positionAttribute = geometry.attributes.position; | ||
var lineDistances = []; | ||
|
||
for ( var i = 0, l = positionAttribute.count; i < l; i ++ ) { | ||
|
||
if ( i > 0 ) { | ||
|
||
start.fromBufferAttribute( positionAttribute, i - 1 ); | ||
end.fromBufferAttribute( positionAttribute, i ); | ||
|
||
distance += start.distanceTo( end ); | ||
|
||
} | ||
|
||
lineDistances[ i ] = distance; | ||
|
||
} | ||
|
||
geometry.addAttribute( 'lineDistance', new THREE.Float32BufferAttribute( lineDistances, 1 ) ); | ||
|
||
} else { | ||
|
||
console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' ); | ||
|
||
} | ||
|
||
} else if ( geometry.isGeometry ) { | ||
|
||
var vertices = geometry.vertices; | ||
|
||
for ( var i = 0, l = vertices.length; i < l; i ++ ) { | ||
|
||
if ( i > 0 ) { | ||
|
||
start.copy( vertices[ i - 1 ] ); | ||
end.copy( vertices[ i ] ); | ||
|
||
distance += start.distanceTo( end ); | ||
|
||
} | ||
|
||
geometry.lineDistances[ i ] = distance; | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. geometry.lineDistances[ 0 ] = 0;
for ( var i = 1, l = vertices.length; i < l; i ++ ) {
geometry.lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That did not work for me since geometry.lineDistances[ 0 ] = 0;
for ( var i = 1, l = vertices.length; i < l; i ++ ) {
geometry.lineDistances[ i ] = geometry.lineDistances[ i - 1 ];
geometry.lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
} |
||
|
||
} | ||
|
||
return this; | ||
|
||
}; | ||
|
||
}() ), | ||
|
||
raycast: ( function () { | ||
|
||
var inverseMatrix = new Matrix4(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: With
CanvasRenderer
it is not necessary to compute the line distances for dashed lines...