我成功加载了一个obj文件,但我试图通过用两个点标记3d模型并在它们之间画一条直线来添加一个测量工具。像Potree这样的东西(不幸的是,它不支持.obj文件)。怎么能这样做因为我使用three.js。
答案 0 :(得分:5)
mousedown
监听器camera
到鼠标位置的光线投射Vector3
缩短代码:
function onDocumentMouseDown( event ) {
var vector = new THREE.Vector2();
vector.set(
( event.clientX / window.innerWidth ) * 2 - 1,
- ( event.clientY / window.innerHeight ) * 2 + 1 );
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera( vector, camera );
var intersects = raycaster.intersectObjects( model.children );
if ( intersects.length > 0 ) {
pointA = intersects[ 0 ].point;
// some logic to save pointB
// on the second click...
//pointB = intersects[ 0 ].point;
var distance = pointA.distanceTo( pointB );
// draw Line
var geometry = new THREE.Geometry();
geometry.vertices.push( pointA );
geometry.vertices.push( pointB );
var material = new THREE.LineBasicMaterial();
line = new THREE.Line( geometry, material );
scene.add(line);
}
}
工作示例,距离输出在控制台中:http://jsfiddle.net/ev3tuLuc/95/