I’m trying to identify a touch on 3d model. ( version 2.4.3 )
I had to simplify for native because this function is always returning inf.
cc.geomUtils.intersect.rayMesh(modelRay, meshRenderer.mesh);
On web version it is working correctly
That’s the complete function being called on TOUCH_START
`simpleRay(event: cc.Event.EventTouch) {
let handlerFunction = function (modelRay: cc.geomUtils.Ray, node: cc.Node, distance: number) {
if(cc.sys.isNative){
return distance;
}else{
let meshRenderer = node.getComponent(cc.MeshRenderer);
//allow collision only if hit the mesh
if(meshRenderer && meshRenderer.mesh){
return cc.geomUtils.intersect.rayMesh(modelRay, meshRenderer.mesh);
}
}
};
let filterFunction = function (nodeToFilter:cc.Node) {
if(nodeToFilter.parent != null && nodeToFilter.parent.parent != null && nodeToFilter.parent.parent == this.interactableParent){
return true;
}
return false;
}
let ray = this.camera.getRay(event.getLocation());
const results : I3dRaycastResult = cc.geomUtils.intersect.raycast(null, ray, handlerFunction, filterFunction.bind(this)) as I3dRaycastResult;
if(results != null && results.length > 0) {
results.forEach(element => {
console.log(`Interactable was clicked: ${element.node.name} - with distance: ${element.distance}`);
element.node.scale = 50;
this.scheduleOnce(()=>{
element.node.scale = 100;
},0.1)
});
}
}`