rayMesh on native always return infinity. 2.4.3

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)
        });
    }
}`

Please provide a test project, it can help to reproduce your problem.

Ok.
There it is as requested :smiley:

rayMeshTest.zip (955.5 KB)

Oh… another thing is that I added these on creator.d.ts because there is declared as ray_cast … not as raycast <lines 18470 >
`
/** I JUST ADDED THIS

        !#en

        Check whether ray intersect with Mesh

        @param worldRay worldRay

        @param mesh mesh

        */

        static rayMesh(worldRay: geomUtils.Ray, mesh: Mesh): any[];

        

        /** I JUST ADDED THIS

        !#en

        Check whether ray intersect with nodes

        !#zh

        检测射线是否与物体有交集

        @param root If root is null, then traversal nodes from scene node

        @param worldRay worldRay

        @param handler handler

        @param filter filter 

        */

        static raycast(root: Node, worldRay: geomUtils.Ray, handler: Function, filter: Function): any[];

`

It is an engine issue on native platform, get this patch and it will work fine.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.