Search the Community
Showing results for tags 'assetmanager'.
-
I read in another thread that BabylonJS intelligently handles multiple uses of the one texture for optimal performance i.e. internally if the texture path is the same then no extra vram is used for subsequent new textures with the same path. I suspect I've been overcomplicating things up until now but here's some related questions. Question 1 If I load my textures with AssetsManager like so: var textureTask = assetsManager.addTextureTask("my-texture", "./path/to/my-texture.jpg"); Are the following methods of applying the textures equivalent behind the scenes (i.e. neither uses more VRAM)? // Method 1 textureTask.onSuccess = function(task) { material.diffuseTexture = task.texture; } // Method 2 - elsewhere in application after assetsManager.onFinish() has been called. material.diffuseTexture = new BABYLON.Texture("./path/to/my-texture.jpg", scene); Question 2 What I've been doing up until now is assigning loaded assets to an assets array which I then pass around to various objects to use what they need like so: textureTask.onSuccess = function(task) { assets[task.name] = task.texture; } // Stuff ... var myCustomObject = new CustomObject(assets); // In CustomObject ... material.diffuseTexture = assets["my-texture"].clone(); The reason for the .clone() is when I need different uv scale and offset per instance. If my method 1 and 2 are functionally equivalent and don't result in any additional vram usage or performance hit then I'm wasting my time passing around an array of loaded assets when I could simply instantiate a new texture with the same path that I know has already been loaded by AssetsManager. Can anyone shed some light on this? How do other people manage this efficiently?
-
Hi, I've been trying to load a json file using the assetmanagers textfile task, but this only returns an arraybuffer. I would have expected that the task returns a simple string which I then can parse to a json object. When loading the file directly through an xmlhttprequest, I get the string which can be parsed without a problem. Here's an example: http://www.babylonjs-playground.com/#GIKDTN#3 You can see in the console log, that the textfile task returns an arraybuffer and then fails to parse it as a json object. What am I doing wrong here? Thanks EDIT: I guess this is a bug in Babylon.js 3.2.0, when I switch to stable version in the playground, it works as I expected.
-
Hello, I've not been working in BJS for a while now, and am back on a job. I've imported loads of OBJ files into babylon.js, and never had an issue. However, I must have forgotten everything already. I need to have the OBJ file into babylon.js tomorrow, and m stuck. I know it's an idiot issue, but I'm too stupid to sort out why this OBJ won't load. http://qedsoft.com/DEMOS2017/obj_loader/index.html Thanks, DB Or better yet - if I import an OBJ file into Blender, the mesh imports as a completely black material with no texture. How do I correct this? It all imorts fine into Maya, which is what I normally use. However, it seems that I'm the only one using Maya in WebGL production, and there is no compatibility between Maya and babylon.js - not that I've ever found reliable. Could someone PLEASE write a reliable FBX converter to babylon.js? Everyone's been asking for this for many years now. I wish I had the skills to write it and support it.
-
I need to preload some skybox maps in order to create a CubeTexture, since there are six maps loaded, how do I then regroup these separate images back as a single reference? Cheers If anyone has the same issue - just call addCubeTextureTask on Assetsmanger
-
TL;DR The `loadMesh` onSuccess gets called, But i got no mesh! haaaaalp! Hi all, I've been having a problem with my asset-manager when loading meshes. I've taken a look at the playground 'import mesh' and the code is almost the same, however on the 'addMeshTask' success callback I do not get access to the loaded mesh via 'task.getLoadedMeshes[0]' (as seen in the playground). I'm really confused as to what could be causing it to trigger a success event, but not have any 'loaded' meshes. My code is open source: https://github.com/dweng0/wildflower to get it up and running you'll need to do an `npm install` and npm install -g` when thats all done, in the command line, you'll need to run `webpack` then set up the mock server with `npm run serve` Then in your browser go to localhost:3000 (have the console open). I've added a debug in the offending function, but it starts in the AssetsManager.ts -> `loadCharacter` function loadCharacter(url: string, character: CharacterManifest, manifest: ICharacterData) { let bodyTextureUrl = url + character.url + "/textures" + manifest.textureUrl; let meshUrl = url + character.url + manifest.meshUrl; debugger; // load body texture this.loadTexture(character.name + "_texture", bodyTextureUrl, () => { console.log(character.name + " texture loaded"); }, () => {}); // todo load mesh this.loadMesh(character.name + "_mesh", manifest.meshes[0], meshUrl, (task: BABYLON.MeshAssetTask) => { console.log(task.loadedMeshes[0]); <==== No mesh WTF!!!!!!!!!!! task.loadedMeshes[0].material = this._scene.getMaterialByName(character.name + "_texture"); / }, () => { debugger; console.log('did it fail?'); }); } loadMesh(taskName: string, meshNames: any, rootUrl: string, success: (meshAsset: BABYLON.MeshAssetTask) => any, fail: () => any) { console.log('loading mesh', taskName); let meshLoader = this._assets.addMeshTask(taskName, taskName, rootUrl, meshNames); meshLoader.onSuccess = success.bind(this); meshLoader.onError = fail.bind(this); return meshLoader; }
-
Hi, I had trouble loading sounds and playing them directly at startup. I realised that the AssetManager calls the onFinish callback before loaded sounds _audioBuffer is set and are _readyToPlay. I dont know if it was a designed choice but it would be really useful either if the asset manager waited by default for the readytoplay flag to be set, or if there was an option to set when adding the job to the manager.
- 4 replies
-
- assetmanager
- sounds
-
(and 1 more)
Tagged with:
-
Hi! I've been using Babylon for a week or so now and really like how easy it is to use and how well the tutorials are written (I'm using it for a robotics simulation project I'm currently working on). Anyways, I have a question about how textures (and other AssetTasks as well: https://github.com/BabylonJS/Babylon.js/blob/master/src/Tools/babylon.assetsManager.ts) are loaded using the AssetManager. I have a texture image that's being served at /app/assets/sceneassets/mytextureimg.jpg. My Babylon scene is loaded at the url /app/testbabylon. When I try to load a texture using the addTextureTask method of the AssetManager, I specify that the asset is located at "/app/assets/sceneassets/mytextureimg.jpg", however, the network request that the AssetManager makes is to "/app/testbabylon/app/assets/sceneassets/mytextureimg.jpg". This is clearly relative to my current path, I can use an absolute path (in dev: "http://localhost:4000/app/assets/sceneassets/mytextureimg.jpg") and it works correctly, however this seems messy (especially if switching domains). If I end up using "//app/assets/sceneassets/mytextureimg.jpg" the network request is "http://app/assets/sceneassets/mytextureimg.jpg" - which doesn't point to anything. My main question is whether its possible to specify the AssetManager to use the root url of my domain for texture (and/or image, cubetexture, etc.) loading (or have something like a "rootUrl" parameter like AddMeshTask seems to have). Just for reference, here's a snippet of the code I'm using (material is an object that has a name and diffuseTexture property; where diffuseTexture is the url string, scene is a Babylon Scene object). setupMaterial(material, scene) { const babylonMaterial = new Babylon.StandardMaterial(material.name, scene); if (material.diffuseTexture) { const diffuseTask = scene.loader.addTextureTask( `diffuseTextureTask${material.name}`, material.diffuseTexture); diffuseTask.onSuccess = (task) => { babylonMaterial.diffuseTexture = task.texture; }; } return babylonMaterial; } Thanks for any help, Flux159
-
Can I use the Asset Manager to load an .hdr and create a HDRCubeTexture with it? If so, can you provide an example? Thank you, amorgan
- 3 replies
-
- assetmanager
- hdrcubetexture
-
(and 1 more)
Tagged with:
-
Hi everyone, I just cant see why my code does not work It seems the task I defined does not seem to be running no error, nothing this.canvas = document.getElementById('renderCanvas'); this.engine = new BABYLON.Engine(this.canvas, true); this.scene = this.CreateScene(); this.engine.runRenderLoop((function(){ this.scene.render(); }).bind(this)); $(window).on('resize',(function(){ this.engine.resize(); }).bind(this)); System.prototype.CreateScene = function(){ // create a basic BJS Scene object var scene = new BABYLON.Scene(this.engine); // create a FreeCamera, and set its position to (x:0, y:5, z:-10) var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5,-10), scene); // target the camera to scene origin camera.setTarget(BABYLON.Vector3.Zero()); // attach the camera to the canvas camera.attachControl(this.canvas, false); // create a basic light, aiming 0,1,0 - meaning, to the sky var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0,1,0), scene); var assetsManager = new BABYLON.AssetsManager(scene); var meshTask = assetsManager.addMeshTask("loading task1", "", "./data/", "blender.babylon"); meshTask.onSuccess = function (task) { task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0); }; assetsManager.onFinish = function (tasks) { this.engine.runRenderLoop(function () { scene.render(); }); }; return scene;}; any idea what I could be doing wrong thanks