inteja
June 17, 2021, 6:34am
1
In relation to this docs page:
When I try to switch the engine.inputElement
using:
It always seems to use the initial engine.inputElement
and there’s no console errors.
I’d create a PG but I don’t think it’ll work with multi-canvas rendering.
I’ve basically been modifying the views demo.
https://www.babylonjs.com/demos/views/
There’s no inputElement
getter/setter in the engine class (only a getInputElement
method), so that can’t work.
Adding @PolygonalSun in case something has changed since the doc has been written.
inteja
June 17, 2021, 9:30am
3
@Evgeni_Popov hmmm looking through Engine class I can see that now but I thought the api docs were auto generated from code? inputElement property is in the api docs with comment “Gets or sets the HTML element to use for attaching events”
inteja
June 17, 2021, 9:33am
4
Ah I see it’s in EngineView class
Ah true, I forgot the engine code was split into several files.
So, I don’t know why it is not working… Are you able to test in 4.2?
inteja
June 17, 2021, 11:29am
6
I’ll try. The demo seems to accept the first assignment but in my code, subsequent assignments to inputElement don’t have any effect.
I’ll try testing in 4.2
1 Like
inteja
June 17, 2021, 11:09pm
7
@Evgeni_Popov & @PolygonalSun I think I’ve confirmed this is a bug in 5.0.0alpha as it works fine in 4.2.0
Here’s the relevant demo links:
And the code:
1 Like
It does not seem to work in 4.2 neither: even when incrementing the canvas, when using the mouse I’m always rotating/moving the cube in the canvas #0 .
Anyway, you need to also detach the previous camera / attach the new camera, something like that (index.html):
function incrementInputCanvas() {
previousInputCanvasIndex = currentInputCanvasIndex;
currentInputCanvasIndex++;
if (currentInputCanvasIndex >= 4) {
currentInputCanvasIndex = 0;
}
var inputCanvasId = "renderCanvas" + currentInputCanvasIndex;
scene.detachControl();
engine.views[previousInputCanvasIndex].camera.detachControl();
engine.inputElement = document.getElementById(inputCanvasId);
scene.attachControl();
engine.views[currentInputCanvasIndex].camera.attachControl();
updateInputCanvasName();
}
For this code to work, you should also change (index.js):
engine.registerView(document.getElementById("renderCanvas0"));
to:
engine.registerView(document.getElementById("renderCanvas0"), camera);
1 Like
inteja
June 18, 2021, 8:28am
9
That’s the expected behaviour. The input is changed from canvas to canvas but that input controls the camera of canvas #0 .
Whereas in the 5.0.0 version the input is always locked to canvas #0 , which is incorrect.
Ok, so I can’t help more.
There has been a lot of changes regarding input handling in 5.0, let’s see if @PolygonalSun has some ideas.
1 Like
inteja
June 18, 2021, 9:38am
11
Thanks for the info about input handling changes in 5.0.0 @Evgeni_Popov and yes I will need to do camera swaps in my own application, but with my demos above I just wanted to isolate the issue to input handling.
In the meantime I can revert to using 4.2.0 and an older version of TS to avoid the other issue I encountered last week with TS and 4.2.0 .
I’m able to also repro the behavior that you’ve described. I think that what might be going on is that the event listeners are only being set for the first canvas that it finds. I’ll dig in more to see what’s actually going on.
2 Likes
So I’ve figured out what’s going on and I have a fix in the works. I’m hoping to have it live next week.
3 Likes
I will do the nightly in a bit
3 Likes