screenToWorld problems

var Logo1Init = pc.createScript('logo1Init');
Logo1Init.attributes.add('camera',{type:'entity'});


Logo1Init.prototype.initialize = function() {
    this.firstFrame = true;   
};


Logo1Init.prototype.update = function(dt) {
    if(this.firstFrame)
    {
        var screenUpX = window.innerWidth / 2;
        var screenUpY = 0;   
        var boundingSize = this.entity.model.meshInstances[0].aabb;
        this.point = this.camera.camera.screenToWorld(screenUpX, screenUpY, -this.entity.getLocalPosition().z);
        this.entity.setPosition(this.point.x, this.point.y /* + boundingSize.halfExtents.y /**/, this.point.z);
        this.firstFrame = false;
        this.entity.fire('reset');
    }
};

returns NOT top center of screen - about [center, height / 8]
camera is one, check in update

Do you have a project that you can show this issue please?

https://playcanvas.com/project/680610/overview/exotic-mix

Couldn’t run your project to the point where I could see the logo model but I’ve check this in a new project: https://playcanvas.com/editor/scene/929353

And it is positioned to where I would expect it to be given that the position is the center of the cube:

In another branch worked correctly with disabled 8th wall AR

If you can create a smaller project that showcases the issue and is runnable for me, I could try taking another look at it. Username yaustar if you need to make it private.

This bug present if 8wall enabled.
Mark - TOP-CENTER point of screen.
3rd parameter works like multiplied by 100

var screenUpX = window.innerWidth / 2;
var screenUpY = 0;   
this.point = this.cameraEnt.camera.screenToWorld(screenUpX, screenUpY, -this.entity.getLocalPosition().z);
this.entity.setPosition(new pc.Vec3(this.point.x,this.point.y,this.point.z));


Plate with text, child of camera
@yaustar

Can you provide a smaller example with reproducible steps that people could look at please? The project is just too large to look at properly.

Little bit later. I too busy now ((

One of the things that comes to mind is whether 8th Wall creates another camera entity?

Check on second camera (without XR) and first (with XR) - works fine on second camera only.
With xrController - looks like Zdistance works *100 and broke vertical FOV.
Edit: try use second camera only for screenToWorld - broke too. Works only if positioning on second camera.

image
Get point and positioning on 2nd camera

Are you saying that Camera3D_UI UI_3D is not positioned correct when you are in AR?

Edit: I would check that when XR is entered, that another camera is created with a different FOV.

But I use Camera (with XR) for screenToWorld. Another camera is absent. Right?
May be that bug is after correcting back camera aspect and screen aspect?

I honestly don’t know how 8th Wall works under the hood. For something to be positioned incorrectly with screenToWorld makes me think the wrong camera is used for screenToWorld and wonder if the library is creating a 3rd camera at runtime with a different FOV?

The example I made works on mobile and when I rotate the phone.

var PlateAnimReposition = pc.createScript('plateAnimReposition');
PlateAnimReposition.attributes.add('cameraEnt',{type:'entity'});

PlateAnimReposition.prototype.initialize = function() {
    this.firstFrame = true;
    window.tools.delay(5.0, function() {
        this.entity.animation.play('Plate_anim.json');
    }.bind(this), this);
};

// update code called every frame
PlateAnimReposition.prototype.postUpdate = function(dt) {
    if(this.firstFrame)
    {
        var screenUpX = window.innerWidth / 2;
        var screenUpY = 0;   
        //var boundingSize = this.entity.model.meshInstances[0].aabb;
        this.point = this.cameraEnt.camera.screenToWorld(screenUpX, screenUpY, -this.entity.getLocalPosition().z);
        this.entity.setPosition(new pc.Vec3(this.point.x,this.point.y,this.point.z));
        //this.app.fire('debug:addtext', this.entity.getLocalPosition());
        this.firstFrame = false;
    }
};

Use on camera child entity on 1st (XR) and 2nd (no XR) cameras.

What happens if you remove

    if(this.firstFrame)

So it updates every frame?

Trying. Broken. And trying dynamically change Z in screenToWorld.

On device screenshot camera.nearClip=0.1, screenToWorld z=0.02

Huh. If screen.x coordinate is zero or screen width - world point is far beyond the screen.
Log from device.
image
Camera stream has aspect 3:4, device aspect about 9:16.
Suspicious coincidence!
PS: if I calculate vector on second camera and positioning on first camera - same bug.
Real frustum first camera not equal frustum second camera, may be.

Looks like 90 degrees rotate frustum