Pointer.Pressed.AddHandler doesn't work inside Scene

Fuse.Input.Pointer.Pressed.AddHandler(Parent, OnPointerPressed);

Doesn’t work if CustomComponent if it’s inside a Scene.

<App>

    <Panel>

        <Scene Camera="CameraEntity">

            <Entity ux:Name="CameraEntity">
                <Frustum FovDegrees="120" ZNear="10" ZFar="10000" ux:Name="_CameraFrustum" />
                <Transform3D Position="0, 0, 0" RotationDegrees="0, 0, 0" Scaling="1, 1, 1" ux:Name="_CameraTransform" />
            </Entity>

            <CustomComponent ux:Name="MyCustomComponent" />

        </Scene>

        <Panel HitTestMode="LocalBounds" />

    </Panel>

</App>

Only way I got those touch events inside my CustomComponent was with:

<App>
    <JavaScript>

        module.exports.VisualPointerPressed = function(args)
        {
            MyCustomComponent.PointerPressed(args.x, args.y, args.index);
        }

        module.exports.VisualPointerReleased = function(args)
        {
            MyCustomComponent.PointerReleased(args.x, args.y, args.index);
        }

        module.exports.VisualPointerMoved = function(args)
        {
            MyCustomComponent.PointerMoved(args.x, args.y, args.index);
        }

        module.exports.VisualPointerWheelMoved = function(args)
        {
            //Can't get Wheel delta with this thing at all
        }

    </JavaScript>

    <Panel>

        <Scene Camera="CameraEntity">

            <Entity ux:Name="CameraEntity">
                <Frustum FovDegrees="120" ZNear="10" ZFar="10000" ux:Name="_CameraFrustum" />
                <Transform3D Position="0, 0, 0" RotationDegrees="0, 0, 0" Scaling="1, 1, 1" ux:Name="_CameraTransform" />
            </Entity>

            <CustomComponent ux:Name="MyCustomComponent" />

        </Scene>

        <Panel HitTestMode="LocalBounds" Pointer.Pressed="{VisualPointerPressed}" Pointer.Moved="{VisualPointerMoved}" Pointer.Released="{VisualPointerReleased}" Pointer.WheelMoved="{VisualPointerWheelMoved}"> 
            </Panel>

    </Panel>

</App>

And then Fuse.Scripting.ScriptClass.Register methods. Which feels like way too much work for getting a pointer events.

Thanks for reporting!

I have raised an issue for this. Will keep this thread updated

I’m on osx 0.21.0(6650) and cannot get pointer events to my custom RenderNode.

I think this should work in a way that I can add handler to Pointer at OnRooted method inside my Custom RenderNode.

override protected void OnRooted()
{
    Fuse.Input.Pointer.Pressed.AddHandler(Parent, OnPointerPressed);
}

But it doesn’t.

Here’s a test case for you:

http://www.simppa.fi/fuse/TestPointer021.zip

Also would like to add that the complicated way (explained in first post) of doing it doesn’t work either.

Would be really nice if this would not get forgotten, since it’s keeping me in a version 0.20.3, where Pointer work at least somehow on Android. (Not on iOS)

I’ve recently done several fixes on viewports, which includes hit testing on scenes. It should work, as I think I only fixed a problem with MeshRenderer and non-fullscreen Scenes.

Pointer events are dependent on the hit testing of your component. You need to implement OnHitTest as well as HitTestLocalBounds, otherwise you won’t get any pointer events.

If you want to test the bounds quickly you can return VisualBounds.Infinite, which means you don’t know what the bounds. This will result in OnHitTest being called for all your objects on each pointer even though (it loses the optimization for hittesting).

Ok so I need to implement that in my uno code, right?

Can you please paste me the code.

Ah starting to get somewhere with

protected override void OnHitTest(HitTestContext args)
{
    args.Hit(this);
}

protected override VisualBounds HitTestLocalBounds
{
    get { return VisualBounds.Infinite; }
}

Yes, that basic code will register a hit always. You’ll need to start figuring out whether you actually hit your object or not now.

Here’s a simple 3D visual that can detect hits on itself (a cube). It uses infinite bounds as a test as well.

public class MyObject : Visual
{
    float3 _color = float3(0.5f);
    public float3 Color
    {
        get { return _color; }
        set 
        { 
            _color = value;
            InvalidateVisual();
        }
    }

    public override void Draw(Fuse.DrawContext dc)
    {
        draw DefaultShading, Cube
        {
            World: WorldTransform;
            DrawContext: dc;
            Size: 1;
            DiffuseColor: _color;
        };
    }

    protected override void OnHitTest(HitTestContext args)
    {
        var ray = args.WorldRay;
        var box = new Box(float3(-0.5f),float3(0.5f));
        box = Box.Transform(box,WorldTransform);

        float distance = 0;
        if (Collision.RayIntersectsBox(ray, box, out distance))
            args.Hit(this);
    }

    protected override VisualBounds HitTestLocalBounds
    {
        //use infinite bounds for 3D space as in general trying to calculate 2D scene bounds is quite challenging
        get { return VisualBounds.Infinite; }
    }
}