1 回答

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超10個(gè)贊
有很多方法可以做到這一點(diǎn)。一種不需要太多數(shù)學(xué)知識(shí)并讓 Three.js 處理繁重工作的簡(jiǎn)單方法是使用嵌套在另一個(gè)對(duì)象中的Object3D:子對(duì)象是“環(huán)”,父對(duì)象將環(huán)移動(dòng)到中點(diǎn)并“看起來(lái)”沿著線向下,使其垂直。
// Create end vectors
var v1 = new THREE.Vector3(1, 3, 5);
var v2 = new THREE.Vector3(7, 8, 10);
// Get midpoint
var mid = new THREE.Vector3();
mid.addVectors(v1, v2);
mid.multiplyScalar(0.5);
// Nest child object inside parent
var parent = new THREE.Object3D();
var child = new THREE.Object3D();
parent.add(child);
// Set child position to any point in the XY plane with radius = 1
// This is a point in your "disc"
child.position.set(0, 1, 0);
// Move parent to midpoint
parent.position.copy(mid);
// Rotate parent to look towards end of the line
// This makes the "disc" perpendicular to the line
parent.lookAt(v1);
// Get world position of child?
var discPoint = new THREE.Vector3();
child.getWorldPosition(discPoint);
console.log(discPoint);
的本地位置child
仍然是[0, 1, 0]
,但是在平移和旋轉(zhuǎn)父級(jí)之后的世界位置就是您正在尋找的答案?;蛘?,您可以簡(jiǎn)單地使用Object3D.localToWorld,但我認(rèn)為這個(gè)父/子示例可以更清楚地說(shuō)明該過(guò)程。
添加回答
舉報(bào)