Babylonjs,获得点(x,y,z)指向其中一个面的网格

时间:2016-11-07 11:06:25

标签: 3d babylonjs

我有一个3D点,我需要知道这个点是否在我场景中的任何网格中。

我找到了:

var pickResult = scene.pick(scene.pointerX, scene.pointerY);

但是我需要传递3D点而不是指针位置。

2 个答案:

答案 0 :(得分:0)

据我所知,你需要保留一个包含你需要检查的所有网格的数组。

var meshList = []; // List Containing all your meshes you want to check if the point is in
var point = new BABYLON.Vector3(x,y,z); // Where x,y,z are replaced with your coordinates

for(i=0; i<meshList.length; i++){
    if(meshList[i].intersectsPoint(point)){
        console.log("Your point is in a mesh");
    }
}

答案 1 :(得分:0)

您可以使用scene.pickWithRay:

var rayPick1 = new BABYLON.Ray(origin, direction);
var meshFound1 = scene.pickWithRay(rayPick1, function (item) {

});