Good afternoon, people
I'm starting Babylon a short time ago, I'm looking for some way to figure out the mouse position when there is a click on the canvas. I was able to easily find this for a given object, but not for the scene itself (!?) I do not know what could be wrong, it seems silly, but I have not found for hours ... Who can help, thank you!
window.addEventListener('DOMContentLoaded', function () {
var canvas = document.getElementById('canvas');
var engine = new BABYLON.Engine(canvas, true);
var createScene = function () {
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color3.White();
var box = BABYLON.Mesh.CreateBox("Box",4.0,scene);
var camera = new BABYLON.ArcRotateCamera("arcCam",
BABYLON.Tools.ToRadians(45),
BABYLON.Tools.ToRadians(45),
10.0,box.position,scene);
camera.attachControl(canvas,true);
var light = new BABYLON.PointLight("pointLight",new BABYLON.Vector3(
0,10,0),scene);
light.diffuse = new BABYLON.Color3(1,1,1);
var onpickAction = new BABYLON.ExecuteCodeAction(
BABYLON.ActionManager.OnPickTrigger,
function(evt) {
console.log("(",evt.pointerX,",",evt.pointerY,")");
});
//não funciona
scene.actionManager = new BABYLON.ActionManager(scene);
scene.actionManager.registerAction(onpickAction);
//funciona normalmente
box.actionManager = new BABYLON.ActionManager(scene);
box.actionManager.registerAction(onpickAction);
return scene;
}
var scene = createScene();
engine.runRenderLoop(function () {
scene.render();
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babylonjs/2.5.0/babylon.js"></script><style>#canvas{width:100%;height:100%;}</style></head><body><canvasid="canvas"></canvas>
</body>
</html>