您可以使用如下所示的函数将具有面的现有几何图形转换为适合渲染虚线的几何图形。使用新几何构造THREE.Line
具有类型THREE.LinePieces
。
function geo2line( geo ) {
var geometry = new THREE.Geometry();
var vertices = geometry.vertices;
for ( i = 0; i < geo.faces.length; i++ ) {
var face = geo.faces[ i ];
if ( face instanceof THREE.Face3 ) {
vertices.push( geo.vertices[ face.a ].clone() );
vertices.push( geo.vertices[ face.b ].clone() );
vertices.push( geo.vertices[ face.b ].clone() );
vertices.push( geo.vertices[ face.c ].clone() );
vertices.push( geo.vertices[ face.c ].clone() );
vertices.push( geo.vertices[ face.a ].clone() );
} else if ( face instanceof THREE.Face4 ) {
vertices.push( geo.vertices[ face.a ].clone() );
vertices.push( geo.vertices[ face.b ].clone() );
vertices.push( geo.vertices[ face.b ].clone() );
vertices.push( geo.vertices[ face.c ].clone() );
vertices.push( geo.vertices[ face.c ].clone() );
vertices.push( geo.vertices[ face.d ].clone() );
vertices.push( geo.vertices[ face.d ].clone() );
vertices.push( geo.vertices[ face.a ].clone() );
}
}
geometry.computeLineDistances();
return geometry;
}
三.js r.56