Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three JS dashed line material not showing

Tags:

three.js

line

I'm trying to create lines with a dashed pattern, but somehow the material isn't reflected on the line I'm creating and I just can't see what I'm doing wrong here...

I'm using code from this example, which should produce this:

enter image description here

When I take the following code:

var geometry = new THREE.Geometry();
geometry.vertices.push(new THREE.Vector3(0,0,0));
geometry.vertices.push(new THREE.Vector3(100,0,0));

var material = new THREE.LineDashedMaterial({ color: 0xffaa00, dashSize: 3, gapSize: 1, linewidth: 2 });

var mesh = new THREE.Line(geometry, material);
scene.add(mesh);

This is what I get:

enter image description here

Any hint would be appreciated!

like image 927
Ropstah Avatar asked Feb 20 '16 13:02

Ropstah


2 Answers

geometry.computeLineDistances();

http://threejs.org/docs/#api/core/Geometry

.lineDistances

An array containing distances between vertices for Line geometries. This is required for LinePieces/LineDashedMaterial to render correctly. Line distances can also be generated with computeLineDistances.

like image 50
Derte Trdelnik Avatar answered Nov 20 '22 06:11

Derte Trdelnik


Geometry.computeLineDistances() has been deprecated, so Derte Trdelnik's answer can not work now.

Use Line.computeLineDistances() instead.

like image 14
Young Zest Avatar answered Nov 20 '22 06:11

Young Zest