【发布时间】:2016-03-19 01:44:44
【问题描述】:
我尝试用three.js 在球体上画一个点(大小可见)。该点位于从相机开始的线与球体的交点处。
我的灵感来自this link。
你可以在this link上查看我的结果
如您所见,我隐藏了在render() 函数之后调用的drawPointIntersection() 函数。这是在这个函数中,我指示绘制这一点。
这是这部分代码:
function drawPointIntersection() {
// Direction of camera
var direction = new THREE.Vector3(0, 0, -1);
var startPoint = camera.position.clone();
var ray = new THREE.Raycaster(startPoint, direction);
// Get point of camera direction projected on sphere
var rayIntersects = ray.intersectObject(scene, true);
// Distance between camera and projected point
console.log(rayIntersects[0]);
// Draw point of camera direction on sphere
var dotGeometry = new THREE.Geometry();
// Looking for right syntax with coordinates of intersection point
//dotGeometry.vertices.push(new THREE.Vector3(0, 0, 0));
dotGeometry.vertices.push(new THREE.Vector3(rayIntersects[1]);
//dotGeometry.vertices.push(new THREE.Vector3(rayIntersects.point.x, rayIntersects.point.y, rayIntersects.point.z);
var dotMaterial = new THREE.PointsMaterial({size: 10, sizeAttenuation: false});
var dot = new THREE.Points(dotGeometry, dotMaterial);
scene.add(dot);
}
如您所见,我尝试使用不同的语法来获取ray.intersectObject(scene, true) 返回的点的坐标,但没有任何效果:
dotGeometry.vertices.push(new THREE.Vector3(0, 0, 0));
dotGeometry.vertices.push(new THREE.Vector3(rayIntersects[1]);
dotGeometry.vertices.push(new THREE.Vector3(rayIntersects.point.x, rayIntersects.point.y, rayIntersects.point.z);
我让你注意到相机正在围绕球体旋转。
我不知道为什么它不起作用,如果有人可以告诉我如何获取这些坐标以便使用 THREE.Points 方法和three.js R75 在球体上绘制点。
提前致谢
【问题讨论】:
-
球体在世界坐标空间中(我认为),相机的前进方向不一定是世界坐标空间中的(0,0,-1)。
标签: javascript three.js