2
我需要通過單擊它們和彈出式非模態對話框來選擇對象以顯示有關對象的信息。它可以正常工作,但是如果用戶點擊任何GUI項目(包括對話框),並且後面有一個對象,則會選取三個js對象,從而更改彈出窗口中的信息。三個js防止通過GUI進行光線採集
以下是摘錄。
document.addEventListener('mousedown', onDocumentMouseDown, false);
jQuery的對話框發生器:
function createDialog(title, text, top) {
return $("<div class='dialog' title='" + title + "'><p id='bodyText'> " + text + "</p></div>")
.dialog({ position: { my: ("right" + 0 + "top+" + top), at: "right top" },
close : setDialogNull, });
}
onmousedown事件功能:
function onDocumentMouseDown(e) {
e.preventDefault();
console.log(dialog);
var mouseVector = new THREE.Vector3();
mouseVector.x = 2 * (e.clientX/window.innerWidth) - 1;
mouseVector.y = 1 - 2 * (e.clientY/window.innerHeight);
var raycaster = new THREE.Raycaster();
raycaster.setFromCamera(mouseVector, camera);
var intersects = raycaster.intersectObjects(objectCollection);
if (intersects.length > 0) {
var selectedObject = intersects[0];
console.log("Intersected object", intersects[0]);
selectedObject.object.material = (selectedObject.object.material.wireframe) ? selectedBoxMaterial : unselectedBoxMaterial;
var text = intersects[0].distance;
var title = "Shelf info";
if (dialog == false) {
createDialog(title, text, offset);
offset = offset - 50;
console.log(offset);
dialog = true;
console.log(dialog);
}
if (dialog == true) {
{jQuery("#bodyText").text(text);
}
}
}
其他GUI元素與dat.GUI創建。
在搜索這個問題時,大部分結果都是關於Unity的,而不是一個有經驗的開發人員,我不太瞭解如何去適應它們。