关于linesegments不工作的三个虚线材料

时间:2017-08-26 13:12:25

标签: javascript three.js

在Three.js中我试图绘制一个带有虚线边缘的立方体,但线条仍显示为实线。这是我的代码:

    var mat_line = new THREE.LineDashedMaterial( { color: "black", dashSize: 1, gapSize: 1 } );

    var geometry = new THREE.BoxGeometry( 10, 10, 10 );
    geometry.computeLineDistances();

    var cube = new THREE.Mesh( geometry, mat_cube );
    scene.add( cube )    

    var edges = new THREE.EdgesGeometry( geometry )
    var line = new THREE.LineSegments( edges, mat_line )
    scene.add( line )

谁能看到我在哪里出错了?或者这个工作流程是不可能的?

1 个答案:

答案 0 :(得分:5)

您希望将LineDashedMaterialEdgesGeometry一起使用。

要使用LineDashedMaterial,该行必须指定行距离。

使用这样的模式:

var material = new THREE.LineDashedMaterial( { color: 0xff0000, dashSize: 1, gapSize: 1 } );

var geometry = new THREE.BoxGeometry( 10, 10, 10 );

geometry = new THREE.EdgesGeometry( geometry );

var line = new THREE.LineSegments( geometry, material );

line.computeLineDistances();

scene.add( line );

three.js r.92