Hello! the last 2-3 days found this strange issue after i rename some folders
I don’t know if is a BABYLON issue or VITE issue
i try to load some data with AssetsManager > addBinaryFileTask
is working perfect!
but does not detect if the file is not exist or if folder not exist!
NOTE: the file i try to load is in /public/data/exist.png
So by accident i rename folder and i discover that AssetsManager return _isCompleted true on non existing file!!
const _binaryTask = Assets._manager.addBinaryFileTask(_LOAD.nameid, _file);
i.e icon.png that not exist.
console log onFinish
{
"name": "test",
"_isCompleted": true,
"_taskState": 2,
"url": "/icon.png",
"data": ArrayBuffer {byteLength: 538}
}
i have tested in PG and AssetsManager is working
Please any idea how to solve???
PS: yesterday i got error from logger.ts ‘Error running tasks-done callbacks’
windows 11
nodejs 25.2.0
npm@11.6.0
package.json
{
"name": "test-v2",
"description": "test V2",
"license": "",
"author": "",
"private": true,
"version": "0.0.2",
"type": "module",
"scripts": {
"preview": "vite preview",
"build": "tsc && vite build",
"start": "vite"
},
"devDependencies": {
"typescript": "latest",
"vite": "latest"
},
"dependencies": {
"@babylonjs/core": "^8.37.0",
"@babylonjs/materials": "^8.37.0",
"earcut": "^3.0.2",
"opentype.js": "^1.3.4"
}
}
from
tsconfig.json
{
"compilerOptions": {
"target": "es6",
"paths": {
"/*": ["./*", "./public/*"]
},
"lib": [ "dom", "es6" ],
"useDefineForClassFields": true,
"module": "ESNext",
"rootDir": "src",
"moduleResolution": "node",
"resolveJsonModule": true,
"noResolve": false,
"sourceMap": true,
"noEmit": true,
"preserveConstEnums": true,
"isolatedModules": true,
"esModuleInterop": true,
"noImplicitAny": false,
"noUnusedLocals": false,
"noUnusedParameters": true,
"noImplicitReturns": true,
"skipLibCheck": true
},
"include": [ "src" ]
}
vite.config.ts
import { defineConfig } from "vite"
export default defineConfig({})
files in /src/js/
settings.js
export const _LOAD = {
nameid: 'test', // any name id
filename: 'icon.png', // test.png NOT EXIST!
//filename: 'exist.png', // exist.png and working!
path: '/data/' // a.k.a folder
//path: 'http://localhost:5173/data/' // test with url, also return 200 OK if file not exist
};
loadAssets.js
import { AssetsManager } from '@babylonjs/core';
import {_LOAD} from './settings.js';
export class Assets{
static _manager;
static _binary;
constructor(scene){
Assets._manager = new AssetsManager(scene);
const _file = _LOAD.path+_LOAD.filename;
console.log('load name = '+_LOAD.nameid+' file and path '+_file);
const _binaryTask = Assets._manager.addBinaryFileTask(_LOAD.nameid, _file);
_binaryTask.onSuccess = (task) => {
Assets._binary = task.data
};
Assets._manager.onTaskErrorObservable.add((task) => {
console.log("task failed", task.errorObject.message, task.errorObject.exception);
});
//Assets._manager.onTaskSuccessObservable.add((task) => {
// console.log("task successful", task);
//});
}
}
index.js
import { Engine, Scene, Camera, ArcRotateCamera, DirectionalLight,
StandardMaterial, MeshBuilder, Vector3, Color3, Color4, Layer, GlowLayer,
Texture, DynamicTexture, AssetsManager, TransformNode, KeyboardEventTypes} from '@babylonjs/core';
import {GridMaterial, ShadowOnlyMaterial} from '@babylonjs/materials';
import {_LOAD} from './settings.js';
import {Assets} from './loadAssets.js';
export class App{
static canvas;
static engine;
static scene;
static cam;
static _run = 0;
constructor(){
App.canvas = document.querySelector('#renderCanvas');
App.engine = new Engine(App.canvas, true);
App.scene = new Scene(App.engine);
App.scene.ambientColor = new Color3(1.0, 1.0, 1.0);
App.scene.clearColor = new Color3(0.95, 0.95, 0.89);
App.cam = new ArcRotateCamera('arc-camera', Math.PI / 2, Math.PI / 2, 6, new Vector3(1, 0, 0), App.scene);
App.cam.attachControl(App.canvas, true);
const light = new DirectionalLight('light', new Vector3(1, -1, 1), App.scene);
light.intensity = 0.6;
const glow = new GlowLayer('glow', App.scene);
glow.intensity = 0.9;
new Assets(App.scene);
Assets._manager.load();
/* Assets._manager.loadAsync(); */
Assets._manager.onFinish = async (task) => {
console.log('onFinish task is',task);
//console.dir('Assets._binary?',Assets._binary);
App._run = App.init();
App.runGame();
};
window.addEventListener('resize', () => {
App.engine.resize();
})
};
static init(){
// build Assets._binary data
return App.scene
};
static runGame() {
App.engine.runRenderLoop( () =>{
App._run.render()
});
App._run.animationsEnabled = true
};
}
files in /public/
favicon.ico
/data/exist.png