I apologize in advance, I use auto-translate.
I have a problem that I have not been able to solve for several hours now.
“Unable to find a plugin to load .gltf files. Trying to use .babylon default plugin. To load from a specific filetype (eg. gltf)”
I’m using vite in my build, I don’t understand why I can’t get the plugin to load a model
Here is the code for my scene component:
import {
Scene,
WebGPUEngine,
Vector3,
MeshBuilder,
ActionManager,
ExecuteCodeAction,
SceneLoader,
} from 'babylonjs';
import Menu from '../root';
import { StaticCamera } from '../MenuProviders/Cameras/StaticCamera';
import { SpotLigth } from '../MenuProviders/Light/SpotLigth';
import { DevKit } from '../../DevelopEntity/DevKit';
import '@babylonjs/loaders/index';
export class Main {
/**
* Движок.
*/
private engine;
/**
* Канвас
*/
private viewport;
/**
* Родитель
*/
private root;
/**
* Ресурсы для построения сцены
*/
private resources;
/**
* TODO: Надо описать
* @param engine
* @param viewport
* @param root
*/
constructor(
engine: WebGPUEngine,
viewport: HTMLCanvasElement,
resources: any,
root: Menu,
) {
this.engine = engine;
this.viewport = viewport;
this.resources = resources;
this.root = root;
}
scene() {
const scene = new Scene(this.engine);
new DevKit(
{ scene },
{
scene: scene,
viewport: this.viewport,
target: Vector3.Zero(),
},
);
const cube = MeshBuilder.CreateBox('box', {
size: 1,
height: 2,
width: 2,
});
// Загружаем модель в сцену
const rootURL = './assets/adam/';
const fileName = 'adamHead.gltf';
SceneLoader.Append(
rootURL,
fileName,
scene,
function (scene) {
console.log('Model loaded successfully!');
},
null,
function (scene, message) {
console.error('Error loading model: ', message);
}
);
cube.actionManager = new ActionManager(scene);
cube.actionManager.registerAction(
new ExecuteCodeAction(ActionManager.OnPickTrigger, () => {
this.root.change('menu', 'store');
}),
);
/**
* Камера
*/
new StaticCamera(
scene,
'menu__main_camera',
this.viewport,
new Vector3(0, 0, -10),
);
/**
* Свет
*/
const mainLigth = new SpotLigth(
'menu__main_spot_ligth',
scene,
new Vector3(-4.6, 4.1, -14.9),
new Vector3(0.5, -0.2, 0.7),
90,
1,
);
mainLigth.setIntensity(0.2);
/**
* TODO: возможно стоит разобраться с clone() ради оптимизации
*/
const mainLigth_Two = new SpotLigth(
'menu__main_spot_ligth_two',
scene,
new Vector3(4.6, 4.1, -14.9),
new Vector3(0, -0.1, 0.9),
90,
1,
);
mainLigth_Two.setIntensity(0.2);
return scene;
}
}
All versions of the packages are the same
package.json
{
"name": "other",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"prepare": "husky install"
},
"devDependencies": {
"@babylonjs/core": "^7.10.0",
"@babylonjs/gui": "^7.10.0",
"@babylonjs/inspector": "^7.10.0",
"@types/earcut": "^2.1.4",
"husky": "^9.0.11",
"typescript": "^5.4.5",
"vite": "^5.2.13"
},
"dependencies": {
"@babylonjs/loaders": "^7.10.0",
"@heroiclabs/nakama-js": "^2.7.1",
"babylonjs": "^7.10.0",
"babylonjs-gui": "^7.10.0",
"babylonjs-serializers": "^7.10.0",
"jszip": "^3.10.1"
}
}
Please help, I’m getting tired of searching in the browser search bar.