I am using babylonjs/core - 4.0.3 for my react project.
While importing the BabylonJs ES6 styles the action events are not firing for meshes
Code:
import { Scene } from '@babylonjs/core/scene';
import { Vector3 } from '@babylonjs/core/Maths/math';
import { FreeCamera } from '@babylonjs/core/Cameras/freeCamera';
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
import { ActionManager } from '@babylonjs/core/Actions/actionManager';
import { ExecuteCodeAction } from '@babylonjs/core/Actions/directActions';
import { Mesh } from '@babylonjs/core/Meshes/mesh';
import '@babylonjs/core/Meshes/meshBuilder';
const createScene = function() {
const scene = new Scene(engine);
const camera = new FreeCamera('camera1', new Vector3(0, 5, -10), scene);
camera.setTarget(Vector3.Zero());
camera.attachControl(canvas, true);
const light = new HemisphericLight('light1', new Vector3(0, 1, 0), scene);
light.intensity = 0.7;
const sphere = Mesh.CreateSphere('sphere1', 16, 2, scene);
sphere.position.y = 1;
scene.exclusiveDoubleMode = false;
const meshes = [sphere];
for (let i = 0; i < meshes.length; i++) {
const mesh = meshes[i];
mesh.actionManager = new ActionManager(scene);
mesh.actionManager.registerAction(
// the events wont fire for this code
new ExecuteCodeAction(ActionManager.OnPickDownTrigger, (mesh) => {
console.log(`mesh clicked`);
})
);
}
return scene;
};
But when the code is imported the legacy way the the events are fired.
Code:
import * as BABYLON from '@babylonjs/core/Legacy/legacy';
import { Scene } from '@babylonjs/core/scene';
import { Vector3 } from '@babylonjs/core/Maths/math';
import { FreeCamera } from '@babylonjs/core/Cameras/freeCamera';
import { HemisphericLight } from '@babylonjs/core/Lights/hemisphericLight';
import { ActionManager } from '@babylonjs/core/Actions/actionManager';
import { Mesh } from '@babylonjs/core/Meshes/mesh';
import '@babylonjs/core/Meshes/meshBuilder';
const createScene = function() {
const scene = new Scene(engine);
const camera = new FreeCamera('camera1', new Vector3(0, 5, -10), scene);
camera.setTarget(Vector3.Zero());
camera.attachControl(canvas, true);
const light = new HemisphericLight('light1', new Vector3(0, 1, 0), scene);
light.intensity = 0.7;
const sphere = Mesh.CreateSphere('sphere1', 16, 2, scene);
sphere.position.y = 1;
scene.exclusiveDoubleMode = false;
const meshes = [sphere];
for (let i = 0; i < meshes.length; i++) {
const mesh = meshes[i];
mesh.actionManager = new ActionManager(scene);
mesh.actionManager.registerAction(
// the code will execute in this case
new BABYLON.ExecuteCodeAction(ActionManager.OnPickDownTrigger, (mesh) => {
console.log(`mesh clicked`);
})
);
}
return scene;
};