射线检测不应该是鼠标点击屏幕的时候按照鼠标点击的位置检测,然后由近及远或者由远及近依次获取到点击的模型吗?
start () {
// Your initialization goes here.
systemEvent.on(SystemEventType.TOUCH_START, this._touchStart, this);
}
_touchStart(touch, event){
const ray = new geometry.ray();
const camera = this.node.getComponent(CameraComponent);
const pos = touch.getLocation();
camera.screenPointToRay(pos.x, pos.y, ray);
const result = this.node.scene.renderScene.raycastModels(ray);
console.log('=================result', result);
}
折腾了好一会才发现,现在好像是按场景编辑的节点树顺序依次遍历放到数组中返回来的,现在是实际想点击的是最靠近玩家屏幕的那个模型,但实际上因为场景中节点的渲染顺序并不是严格由远及近的顺序,就很难拿到想要的那个模型!除非模型都挂一个唯一的标识……,这操作似乎就不那么可取了!