onetrickwolf Posted February 11, 2016 Share Posted February 11, 2016 Hey I am coming from three.js and have been working with Babylon on and off for about a month. We are making a 3D model viewer and are interested in using PBRMaterials because they really make the models look amazing. I am trying to figure out the best way to let users choose a model, have that model loaded, the textures loaded, then apply the textures as PBRMaterials to the model. There seems to be A LOT of ways to approach this and was wondering someone could just give me some light advice on how they would do this? I was converting the models and textures to Babylon files using the FBX converter and also the OBJ importer, but those try to set up materials automatically. I have been looking at using the AssetManager. Perhaps converting JUST the mesh to FBX, then convert to .babylon, load the babylon file in, load the textures in, then create PBRMaterials out of the textures and apply them to the mesh. Would this be a good approach? Any examples out there that might help me? Thanks! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 11, 2016 Share Posted February 11, 2016 Hello, I think there is no better than others solution. I like your approach but I guess it will be easier to help you if you describe your options or the questions you may face Quote Link to comment Share on other sites More sharing options...
onetrickwolf Posted February 12, 2016 Author Share Posted February 12, 2016 Well one thing I am having a bit of trouble with is how to load a model then apply a texture...it makes sense to me on paper but can't seem to get it working...this is what I've tried: var model; var assetsManager = new BABYLON.AssetsManager(scene); var meshTask = assetsManager.addMeshTask("skull task", "", "./", "models/skull/skull.babylon"); meshTask.onSuccess = function(task){ model = task.loadedMeshes[0]; } var textureTask = assetsManager.addTextureTask("image task", "models/skull/elongated_skull_D.png"); textureTask.onSuccess = function(task) { model.material.diffuseTexture = task.texture; } Getting: Uncaught TypeError: Cannot set property 'diffuseTexture' of null Quote Link to comment Share on other sites More sharing options...
jerome Posted February 12, 2016 Share Posted February 12, 2016 This means that your texture is loaded faster, so before, than the skull (big file) and that the model doesn't exist yet when you try to set its material texture. Quote Link to comment Share on other sites More sharing options...
Wingnut Posted February 12, 2016 Share Posted February 12, 2016 So, the textureTask should be put inside-of meshTask.onSuccess? I bet so. Quote Link to comment Share on other sites More sharing options...
onetrickwolf Posted February 12, 2016 Author Share Posted February 12, 2016 Okay little confused. So I have a .babylon file that includes textures and the AssetLoader automatically loads the textures it seems. However, I tried manipulating the textures and it's not working: var meshTask = assetsManager.addMeshTask("skull task", "", "./", "models/skull/elongated_skull.babylon"); meshTask.onSuccess = function(task){ model = task.loadedMeshes[0]; console.log(model.material); //returning null }; Any ideas? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 12, 2016 Share Posted February 12, 2016 hello are they other meshes in your file or just one? onetrickwolf 1 Quote Link to comment Share on other sites More sharing options...
adam Posted February 12, 2016 Share Posted February 12, 2016 It appears as though the skull model does not have a default material. http://www.babylonjs-playground.com/#SXEV7 onetrickwolf 1 Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 12, 2016 Share Posted February 12, 2016 Correct onetrickwolf 1 Quote Link to comment Share on other sites More sharing options...
adam Posted February 12, 2016 Share Posted February 12, 2016 It is working in this example: http://www.babylonjs-playground.com/#SXEV7#1 This is the image I used for a texture: onetrickwolf 1 Quote Link to comment Share on other sites More sharing options...
onetrickwolf Posted February 12, 2016 Author Share Posted February 12, 2016 Ah thanks I will play around with it and let you know what I find! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted February 12, 2016 Share Posted February 12, 2016 I rarely use a .babylon & never used AssetManager, but was having an issue with multiple meshes, head / eyes / eye lashes / teeth/ tongue / hair, showing up before everything was ready. Looked interesting to see eyes / teeth flash briefly, but not very professional. I used a scene.executeWhenReady() to launch my render loop, so nothing shows till all are ready. scene.executeWhenReady(function() { engine.runRenderLoop(function () { scene.render(); }); recorder = QI.AudioRecorder.getInstance(resetPhonemeControls); }) I do know if waiting till everything is done defeats the purpose of an asset manager, cause I do not know what its purpose is. Might not you just submit all your tasks, specifying only on errors, then just put your material assignment / start your render loop inside the executeWhenReady? onetrickwolf 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.