修改配置
This commit is contained in:
38
dist/PointPick.js
vendored
Normal file
38
dist/PointPick.js
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const three_1 = require("three");
|
||||
/**
|
||||
* 点选
|
||||
*
|
||||
* @export
|
||||
* @param {Viewer} view
|
||||
* @param {number} ptx
|
||||
* @param {number} pty
|
||||
* @returns {(Mesh | undefined)}
|
||||
*/
|
||||
function PointPick(view, ptx, pty) {
|
||||
let raycaster = new three_1.Raycaster();
|
||||
raycaster.setFromCamera({
|
||||
x: (ptx / view._Width) * 2 - 1,
|
||||
y: -(pty / view._Height) * 2 + 1 //y轴相反
|
||||
}, view.m_Camera.Camera);
|
||||
//https://github.com/mrdoob/three.js/issues/14128
|
||||
raycaster.ray.origin.set((ptx / view._Width) * 2 - 1, -(pty / view._Height) * 2 + 1, -1).unproject(view.m_Camera.Camera);
|
||||
let minDis = Infinity;
|
||||
let minObj = undefined;
|
||||
view.m_Scene.children.forEach(obj => {
|
||||
if (obj instanceof three_1.Mesh) {
|
||||
let intersects = [];
|
||||
obj.raycast(raycaster, intersects);
|
||||
for (let i of intersects) {
|
||||
if (i.distance < minDis) {
|
||||
minObj = obj;
|
||||
minDis = i.distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return minObj;
|
||||
}
|
||||
exports.PointPick = PointPick;
|
||||
//# sourceMappingURL=PointPick.js.map
|
||||
Reference in New Issue
Block a user