The free camera serialization cannot save the touch screen swipe perspective information

(Sorry, I didn’t use pg here because the serialized file is not well displayed when loaded.)

1.When I use the following code, the mobile device can support swipe to switch the free camera perspective

**var camera = new FreeCamera('FreeCamera', new Vector3(0, 8, -20), scene)**

** scene.activeCamera = camera**
** camera.attachControl(scene, true)**

2.But if i use thefollowing code, the mobile device can’t support swipe(a .babylon file with freecamera)

    **await SceneLoader.AppendAsync(**

** ‘…/assets/’,**
** ‘camera.babylon’,**
** scene,**
** () => {},**
** ‘.babylon’**
)
** .then(() => {**
let camera = scene.getCameraByName(‘freeCamera’) as FreeCamera
scene.activeCamera = camera
camera.attachControl(scene, true)
})

Unfortunately without a repro there is not so much we can do :frowning:

This is a classic pg code. When opened on a mobile device, you can change the camera’s rotation perspective by swiping.

In this pg, the freeCamera is used from the ‘scene.babylon’ file (since I didn’t know how to upload my scene.babylon file, I didn’t use pg for demonstration initially. If it’s convenient, you can create a scene file yourself; it only needs to contain a freeCamera).

In this pg, when opened on a mobile device, the rotation of the free camera perspective cannot be controlled by swiping the screen.

There is an error in the attachControl call - scene is most certainly not a first variable. Remove it, use only the boolean.

Can you share the scene data you are using? The JSON itself? it’s always possible to use it as a base64 data url

Sorry, I’m not very familiar with the forum, so I’m not sure how to send a JSON file. However, during my testing, I created and exported multiple scenes with a free camera. When I appended these scenes and used the serialized free camera, the camera successfully switched and gained control without any errors. The only issue was that I couldn’t rotate the camera perspective using touch on mobile devices. (It works fine on a computer though).

I totally get that, and I want to be able to resolve the issue, but for that we need a reproduction.
The playground you have shared fails to load because the scene file is missing, so it’s hard to debug this.
You can share the json here or in the playground. It should be a simple JSON, if I understand you correctly. Save it in the playground, we will take it from there. No need for more than the camera.

Can you try this one https://playground.babylonjs.com/#D4DKWL#4

At least it could work as a workaround during the time the bug would be checked.

yell!this can temporarily solve the problem, thanks my bro

I believe this will solve it permanently, but looking for feedback from the team first - Fixing an issue with touch camera initialization by RaananW · Pull Request #15141 · BabylonJS/Babylon.js (github.com)

1 Like