diff --git a/docs/api/core/Geometry.html b/docs/api/core/Geometry.html
index 6c0fa7383c5673b6d7d691b81ae1523b949f77ac..b066b41ce8d48bc499efd6a1144db6f4a358d1b3 100644
--- a/docs/api/core/Geometry.html
+++ b/docs/api/core/Geometry.html
@@ -107,8 +107,7 @@
An array containing distances between vertices for Line geometries.
- This is required for [page:LineSegments] / [page:LineDashedMaterial] to render correctly.
- Line distances can be generated automatically with [page:.computeLineDistances].
+ This is required for [page:LineDashedMaterial] to render correctly.
Computes flat [page:Face3.vertexNormals vertex normals]. Sets the vertex normal of each vertex of each face to be the same as the face's normal.
- Compute [page:.lineDistances].
-
Computes [page:.morphNormals].
diff --git a/docs/api/deprecated/DeprecatedList.html b/docs/api/deprecated/DeprecatedList.html
index 3e260b359a8b9e9d9b0c19e464bd4dbd4f1949c6..154af485b31e68040c52ee9216d0d8bb35584272 100644
--- a/docs/api/deprecated/DeprecatedList.html
+++ b/docs/api/deprecated/DeprecatedList.html
@@ -153,6 +153,12 @@
+ Geometry.computeTangents() has been removed.
+
+ Geometry.computeLineDistances() has been removed. Use [page:Line.computeLineDistances] instead.
+
+
BufferGeometry.addIndex has been renamed to [page:BufferGeometry.setIndex].
diff --git a/docs/api/objects/Line.html b/docs/api/objects/Line.html
index 1d25da9104fd36aa1973f6769946e0c652c514ab..2b9de5cb97ca6d1ae6d9c0eae2e453c03d1b4d36 100644
--- a/docs/api/objects/Line.html
+++ b/docs/api/objects/Line.html
@@ -74,6 +74,11 @@
Methods
See the base [page:Object3D] class for common methods.
+
[method:Line computeLineDistances]()
+
+ Computes an array of distance values which are necessary for [page:LineDashedMaterial]. The method calculates for each point in the geometry the distance to the very beginning of the line.
+
+
[method:Array raycast]( [page:Raycaster raycaster], [page:Array intersects] )
Get intersections between a casted [page:Ray] and this Line.
diff --git a/examples/canvas_lines_dashed.html b/examples/canvas_lines_dashed.html
index 9b90d702e5978559c8a7addd43f12f8b00ae90b5..e48f326033e876f17eeb9f4010183ae0fac8a9a2 100644
--- a/examples/canvas_lines_dashed.html
+++ b/examples/canvas_lines_dashed.html
@@ -49,8 +49,7 @@
var objects = [];
- var WIDTH = window.innerWidth,
- HEIGHT = window.innerHeight;
+ var WIDTH = window.innerWidth, HEIGHT = window.innerHeight;
init();
animate();
@@ -63,28 +62,17 @@
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x111111 );
- root = new THREE.Object3D();
-
var subdivisions = 6;
var recursion = 1;
var points = hilbert3D( new THREE.Vector3( 0,0,0 ), 25.0, recursion, 0, 1, 2, 3, 4, 5, 6, 7 );
-
var spline = new THREE.CatmullRomCurve3( points );
- var geometrySpline = new THREE.Geometry();
-
- for ( var i = 0; i < points.length * subdivisions; i ++ ) {
- var t = i / ( points.length * subdivisions );
- geometrySpline.vertices[ i ] = spline.getPoint( t );
-
- }
+ var samples = spline.getPoints( points.length * subdivisions );
+ var geometrySpline = new THREE.BufferGeometry().setFromPoints( samples );
var geometryCube = cube( 50 );
- geometryCube.computeLineDistances();
- geometrySpline.computeLineDistances();
-
var object = new THREE.Line( geometrySpline, new THREE.LineDashedMaterial( { color: 0xffffff, dashSize: 1, gapSize: 0.5 } ) );
objects.push( object );
@@ -186,7 +174,6 @@
var object = objects[ i ];
- //object.rotation.x = 0.25 * time * ( i%2 == 1 ? 1 : -1);
object.rotation.x = 0.25 * time;
object.rotation.y = 0.25 * time;
diff --git a/examples/webgl_lines_dashed.html b/examples/webgl_lines_dashed.html
index c962aba59d380394b38387b8fca76b8311646cde..777c14d3a525ef27f6e797cc7a397652117a8637 100644
--- a/examples/webgl_lines_dashed.html
+++ b/examples/webgl_lines_dashed.html
@@ -45,9 +45,7 @@
var renderer, scene, camera, stats;
var objects = [];
-
- var WIDTH = window.innerWidth,
- HEIGHT = window.innerHeight;
+ var WIDTH = window.innerWidth, HEIGHT = window.innerHeight;
init();
animate();
@@ -61,37 +59,28 @@
scene.background = new THREE.Color( 0x111111 );
scene.fog = new THREE.Fog( 0x111111, 150, 200 );
- root = new THREE.Object3D();
-
var subdivisions = 6;
var recursion = 1;
- var points = hilbert3D( new THREE.Vector3( 0,0,0 ), 25.0, recursion, 0, 1, 2, 3, 4, 5, 6, 7 );
-
+ var points = hilbert3D( new THREE.Vector3( 0, 0, 0 ), 25.0, recursion, 0, 1, 2, 3, 4, 5, 6, 7 );
var spline = new THREE.CatmullRomCurve3( points );
- var geometrySpline = new THREE.Geometry();
- for ( var i = 0; i < points.length * subdivisions; i ++ ) {
+ var samples = spline.getPoints( points.length * subdivisions );
+ var geometrySpline = new THREE.BufferGeometry().setFromPoints( samples );
- var t = i / ( points.length * subdivisions );
- geometrySpline.vertices[ i ] = spline.getPoint( t );
+ var line = new THREE.Line( geometrySpline, new THREE.LineDashedMaterial( { color: 0xffffff, dashSize: 1, gapSize: 0.5 } ) );
+ line.computeLineDistances();
- }
+ objects.push( line );
+ scene.add( line );
var geometryCube = cube( 50 );
- geometryCube.computeLineDistances();
- geometrySpline.computeLineDistances();
-
- var object = new THREE.Line( geometrySpline, new THREE.LineDashedMaterial( { color: 0xffffff, dashSize: 1, gapSize: 0.5 } ) );
-
- objects.push( object );
- scene.add( object );
+ var lineSegments = new THREE.LineSegments( geometryCube, new THREE.LineDashedMaterial( { color: 0xffaa00, dashSize: 3, gapSize: 1, linewidth: 2 } ) );
+ lineSegments.computeLineDistances();
- var object = new THREE.LineSegments( geometryCube, new THREE.LineDashedMaterial( { color: 0xffaa00, dashSize: 3, gapSize: 1, linewidth: 2 } ) );
-
- objects.push( object );
- scene.add( object );
+ objects.push( lineSegments );
+ scene.add( lineSegments );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
@@ -113,47 +102,49 @@
var h = size * 0.5;
- var geometry = new THREE.Geometry();
-
- geometry.vertices.push(
- new THREE.Vector3( -h, -h, -h ),
- new THREE.Vector3( -h, h, -h ),
+ var geometry = new THREE.BufferGeometry();
+ var position = [];
- new THREE.Vector3( -h, h, -h ),
- new THREE.Vector3( h, h, -h ),
+ position.push(
+ -h, -h, -h,
+ -h, h, -h,
- new THREE.Vector3( h, h, -h ),
- new THREE.Vector3( h, -h, -h ),
+ -h, h, -h,
+ h, h, -h,
- new THREE.Vector3( h, -h, -h ),
- new THREE.Vector3( -h, -h, -h ),
+ h, h, -h,
+ h, -h, -h,
+ h, -h, -h,
+ -h, -h, -h,
- new THREE.Vector3( -h, -h, h ),
- new THREE.Vector3( -h, h, h ),
+ -h, -h, h,
+ -h, h, h,
- new THREE.Vector3( -h, h, h ),
- new THREE.Vector3( h, h, h ),
+ -h, h, h,
+ h, h, h,
- new THREE.Vector3( h, h, h ),
- new THREE.Vector3( h, -h, h ),
+ h, h, h,
+ h, -h, h,
- new THREE.Vector3( h, -h, h ),
- new THREE.Vector3( -h, -h, h ),
+ h, -h, h,
+ -h, -h, h,
- new THREE.Vector3( -h, -h, -h ),
- new THREE.Vector3( -h, -h, h ),
+ -h, -h, -h,
+ -h, -h, h,
- new THREE.Vector3( -h, h, -h ),
- new THREE.Vector3( -h, h, h ),
+ -h, h, -h,
+ -h, h, h,
- new THREE.Vector3( h, h, -h ),
- new THREE.Vector3( h, h, h ),
+ h, h, -h,
+ h, h, h,
- new THREE.Vector3( h, -h, -h ),
- new THREE.Vector3( h, -h, h )
+ h, -h, -h,
+ h, -h, h
);
+ geometry.addAttribute( 'position', new THREE.Float32BufferAttribute( position, 3 ) );
+
return geometry;
}
@@ -180,14 +171,16 @@
var time = Date.now() * 0.001;
- for ( var i = 0; i < objects.length; i ++ ) {
+ scene.traverse( function( object ) {
+
+ if ( object.isLine ) {
- var object = objects[ i ];
+ object.rotation.x = 0.25 * time;
+ object.rotation.y = 0.25 * time;
- object.rotation.x = 0.25 * time;
- object.rotation.y = 0.25 * time;
+ }
- }
+ } );
renderer.render( scene, camera );
diff --git a/src/Three.Legacy.js b/src/Three.Legacy.js
index 24851c89a795c8a0cda49cf4291ca4eadbfb137c..7029b3582ca99ed61fce5ec4e252534065100cc9 100644
--- a/src/Three.Legacy.js
+++ b/src/Three.Legacy.js
@@ -832,11 +832,20 @@ Object.assign( Vector4.prototype, {
//
-Geometry.prototype.computeTangents = function () {
+Object.assign( Geometry.prototype, {
- console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
+ computeTangents: function () {
-};
+ console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
+
+ },
+ computeLineDistances: function () {
+
+ console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
+
+ }
+
+} );
Object.assign( Object3D.prototype, {
diff --git a/src/core/Geometry.js b/src/core/Geometry.js
index 2f42843942275ee717d581c2daaa4f278642eda4..de998ee08d6bc4714afa9a9a124060402dc41a17 100644
--- a/src/core/Geometry.js
+++ b/src/core/Geometry.js
@@ -656,25 +656,6 @@ Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ),
},
- computeLineDistances: function () {
-
- var d = 0;
- var vertices = this.vertices;
-
- for ( var i = 0, il = vertices.length; i < il; i ++ ) {
-
- if ( i > 0 ) {
-
- d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
-
- }
-
- this.lineDistances[ i ] = d;
-
- }
-
- },
-
computeBoundingBox: function () {
if ( this.boundingBox === null ) {
diff --git a/src/objects/Line.js b/src/objects/Line.js
index 7392eb443777272f9bce25d6b32070358d0cdaf7..240f3cbb8c5713500617b2bc52c26e8ebff44a76 100644
--- a/src/objects/Line.js
+++ b/src/objects/Line.js
@@ -35,6 +35,67 @@ 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
+
+ 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.push( distance );
+
+ }
+
+ geometry.addAttribute( 'lineDistance', new THREE.Float32BufferAttribute( lineDistances, 1 ) );
+
+ } 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;
+
+ }
+
+ }
+
+ return this;
+
+ };
+
+ }() ),
+
raycast: ( function () {
var inverseMatrix = new Matrix4();