Hi everyone, I’m new to Babylonjs.
I started with basic project with light, camera and basic models in glb format but when i try to importMesh from same folder, I’m getting error saying that “Unable to find a plugin to load .glb files. Trying to use .babylon default plugin. To load from a specific filetype (eg. gltf)”.
The code that i wrote is
import React, { Component } from “react”;
import * as BABYLON from “babylonjs”;
var scene;
var boxMesh;
class BabylonScene extends Component {
constructor(props) {
super(props);
this.state = { useWireFrame: false, shouldAnimate: false };
}
componentDidMount = () => {
// start ENGINE
this.engine = new BABYLON.Engine(this.canvas, true);
//Create Scene
scene = new BABYLON.Scene(this.engine);
//--Light---
this.addLight();
//--Camera---
this.addCamera();
//--Meshes---
this.addModels();
// Add Events
window.addEventListener("resize", this.onWindowResize, false);
// Render Loop
this.engine.runRenderLoop(() => {
scene.render();
});
//Animation
// scene.registerBeforeRender(() => {
// boxMesh.rotation.y += 0.01;
// boxMesh.rotation.x += 0.01;
// });
};
componentWillUnmount() {
window.removeEventListener(“resize”, this.onWindowResize, false);
}
onWindowResize = event => {
this.engine.resize();
};
/* Add Lights */
addLight = () => {
// Create a basic light, aiming 0,1,0 - meaning, to the sky.
var light = new BABYLON.HemisphericLight(
"light1",
new BABYLON.Vector3(0, 10, 0),
scene
);
};
/* Add Camera */
addCamera = () => {
// ---------------ArcRotateCamera or Orbit Control----------
var camera = new BABYLON.ArcRotateCamera(
“Camera”,
Math.PI / 2,
Math.PI / 4,
4,
BABYLON.Vector3.Zero(),
scene
);
camera.inertia = 0;
camera.angularSensibilityX = 250;
camera.angularSensibilityY = 250;
// This attaches the camera to the canvas
camera.attachControl(this.canvas, true);
camera.setPosition(new BABYLON.Vector3(5, 5, 5));
};
/*** Add Models */
addModels = () => {
BABYLON.SceneLoader.ImportMesh("Pillow", "../models/", "Pillow.glb");
};
render() {
return (
<canvas
style={{ width: window.innerWidth, height: window.innerHeight }}
ref={canvas => {
this.canvas = canvas;
}}
/>
);
}
}
export default BabylonScene;