Hi,
i’m new in babylon. I want slow rotate my model on one axis. When I delete “newMeshes[0].rotation = new BABYLON.Vector3(0, 0);” in the model loading I can’t rotate model in render loop. Can someone explain me why it work like that and show example how rotate models properly ?
my code:
const canvas = document.getElementById(“renderCanvas”); // Get the canvas element
const engine = new BABYLON.Engine(canvas, true); // Generate the BABYLON 3D engine
const createScene = function () {
// Creates a basic Babylon Scene object
const scene = new BABYLON.Scene(engine);
// Creates and positions a free camera
const camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 2.5, 15, new BABYLON.Vector3(0, 0, 0));
camera.upperBetaLimit = Math.PI / 2.2;
camera.attachControl(canvas, true);
const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(1, 1, 0));
light.intensity = 1;
const ground = BABYLON.MeshBuilder.CreateGround("ground", {width: 6, height: 6}, scene);
BABYLON.SceneLoader.ImportMesh("", "src/", "monke.gltf", scene, function (newMeshes) {
newMeshes[0].position = new BABYLON.Vector3(0, 1, 0);
});
BABYLON.SceneLoader.ImportMesh("", "src/", "monke.gltf", scene, function (newMeshes) {
newMeshes[0].position = new BABYLON.Vector3(0, 1, 0);
newMeshes[0].rotation = new BABYLON.Vector3(0, 0);
});
return scene;
};
const scene = createScene(); //Call the createScene function
engine.runRenderLoop(function () {
for (let i = 0; i < scene.meshes.length; i++)
{
const mesh = scene.meshes[i];
mesh.rotation.y += 0.01;
}
scene.render();
});
window.addEventListener("resize", function () {
engine.resize();
});