我嘗試在three.js
的球體上繪製一個點(大小可見)。此點位於從相機開始的線與球體的交點處。Three.js - 在相機方向和球體交點處畫一個大點
我受到this link的啓發。
你可以在我的上this link
結果正如你所看到的,我已經隱藏了drawPointIntersection()
功能,該功能後render()
函數調用。這是在這個函數中,我做了說明來闡明這一點。
下面是這部分代碼:
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.js R75與THREE.Points
方法繪製球體上的點。
在此先感謝
的球在世界座標空間(我認爲)和在世界座標空間中相機的正向不一定是(0,0,-1)。 –