Three.js line vector to cylinder?

后端 未结 9 1830
粉色の甜心
粉色の甜心 2020-12-14 23:53

I have this to create a line between 2 points:

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


        
9条回答
  •  春和景丽
    2020-12-14 23:57

    I've had the exact same problem -- in WebGL the line width is always 1. So here's a function I wrote that will take two Vector3 objects and produce a cylinder mesh:

    var cylinderMesh = function( pointX, pointY )
    {
        // edge from X to Y
        var direction = new THREE.Vector3().subVectors( pointY, pointX );
        var arrow = new THREE.ArrowHelper( direction, pointX );
    
        // cylinder: radiusAtTop, radiusAtBottom, 
        //     height, radiusSegments, heightSegments
        var edgeGeometry = new THREE.CylinderGeometry( 2, 2, direction.length(), 6, 4 );
    
        var edge = new THREE.Mesh( edgeGeometry, 
            new THREE.MeshBasicMaterial( { color: 0x0000ff } ) );
        edge.rotation = arrow.rotation.clone();
        edge.position = new THREE.Vector3().addVectors( pointX, direction.multiplyScalar(0.5) );
        return edge;
    }
    

提交回复
热议问题