(stackoverflow的新手,webgl/three.js的新手,...)
我正在使用three.js r54绘制一个力导向图.节点之间的边缘是THREE.Lines,很好,但是用raycaster不能选择线条.所以我的目标是采用圆柱代替(或同时)线条(也因为我可以做更多的东西:使用纹理,......)
这就是我正在做的放置圆柱体:
// init reference vector
var upVec = new THREE.Vector3(0,1,0);
//---withhin a loop---
// get direction
var direction = startPoint.subSelf(endPoint).clone();
// half length for cylinder height
var halfLength = direction.length() * 0.5;
// get offset
var offset = endPoint.clone().addSelf(direction.clone().multiplyScalar(0.5));
// normalize direc
direction.normalize();
//newUpVec = upVec - (upVec *(dot) direction) * direction - projection of direction
var newUpVec = upVec.clone().subSelf(direction.clone().multiplyScalar(upVec.dot(direction.clone()))).normalize();
var right = newUpVec.clone().crossSelf(direction.clone());
//build rotation matrix
var rot = new THREE.Matrix4(right.x, right.y, right.z, 0,
newUpVec.x, newUpVec.y, …Run Code Online (Sandbox Code Playgroud)