GameMonetize Posted July 6, 2017 Share Posted July 6, 2017 I know that some of you desperately asked for it http://doc.babylonjs.com/tutorials/how_materials_work hunts, Pryme8, Dad72 and 1 other 4 Quote Link to comment Share on other sites More sharing options...
Dad72 Posted July 7, 2017 Share Posted July 7, 2017 Is there an example of use? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 7, 2017 Author Share Posted July 7, 2017 just call material.forceCompilation(mesh) and the shader will be compile. this has to be done before the first render obviously. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 12, 2017 Share Posted July 12, 2017 Does this work when the material is Multi-Material, or does each sub-material need to be iterated through? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 12, 2017 Author Share Posted July 12, 2017 You need to iterate through all of them but this is definitely something we should do for 3.1 Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 12, 2017 Share Posted July 12, 2017 Thanks, I actually found that I need to get all the simple materials of a mesh and its descendants. I have this coded so far in QI.Mesh, since I cannot bring myself to switch to 3.1 Alpha on day one. I can move to BABYLON.Mesh after I get one kink out. /** * Get Every material in use by the mesh & it's children. This is primarily for compileMaterials(), * but needs to be broken out, so it can be called recursively. * * @param repo - This is an array of dictionaries with entries of a mesh & material, initialized when missing. * @param mesh - An argument of the mesh to operate on, default this. Needed because function is implemented at QI.Mesh. * @returns an array of dictionaries with entries of a mesh & material. */ public getEverySimpleMaterial(repo? : Array<{mesh: BABYLON.Mesh, mat: BABYLON.Material}>, mesh : BABYLON.Mesh = this) : Array<{mesh: BABYLON.Mesh, mat: BABYLON.Material}> { if (!repo) repo = new Array<{mesh: BABYLON.Mesh, mat: BABYLON.Material}>(0); // take care of this mesh if (mesh.material instanceof BABYLON.MultiMaterial) { var subMaterials = (<BABYLON.MultiMaterial> mesh.material).subMaterials; for (var i = 0, len = subMaterials.length; i < len; i++) { repo.push( {mesh : mesh, mat: subMaterials[i]} ); } } else repo.push( {mesh : mesh, mat: mesh.material} ); // take care of children (those which are not QI.Mesh, can only go one level) var children = mesh.getChildMeshes(); for (var i = 0, len = children.length; i < len; i++) { if (children[i] instanceof QI.Mesh) (<QI.Mesh> children[i]).getEverySimpleMaterial(repo); else (<QI.Mesh> mesh).getEverySimpleMaterial(repo, <BABYLON.Mesh> children[i]); } return repo; } /** * Ensure that all materials for this mesh & it's children are actively forced to compile */ public compileMaterials(completionCallback : () => void) : void { var everyMatSet = this.getEverySimpleMaterial(); console.log("Total number of materials " + everyMatSet.length); var compiledMaterials = 0; var nMaterials = everyMatSet.length; // the callback to forceCompilation var callback = function(material : BABYLON.Material) : void { console.log(material.name); if (++compiledMaterials < nMaterials) return; completionCallback(); }; // force compile each mesh & material set for (var i = 0; i < nMaterials; i++) { console.log("queued " + everyMatSet[i].mat.name); everyMatSet[i].mat.forceCompilation(everyMatSet[i].mesh, callback); } } That kink is one of my child meshes is colorShader for LinesMesh (Hair). Do I need to do a test for StandardMaterial? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 12, 2017 Share Posted July 12, 2017 also realized getChildMeshes is recursive, so therefore there only need be one level of recursion in getEverySimpleMaterial(). In process of removing the QI.Mesh checks. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 12, 2017 Share Posted July 12, 2017 Well the answer is yes, you do need to screen for StandardMaterial, at least for adding to the callback count requirement. ShaderMaterial does not override isReadyForSubMesh(), so the callback cannot be called. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 12, 2017 Share Posted July 12, 2017 I implemented the forced compiling of even ShaderMaterials, but just do not block for it. https://github.com/BabylonJS/Extensions/commit/d4d6f914b7dc8b7d36c98ac0732d9f4a1905b374 When I had a simple merged head & hair, I had been getting pretty good sync with any GrandEntrance sound effect, but as the number of meshes increase for full scale characters (clothes, shoes) the sound was getting ahead. This closed some of that. The effects also needed tweeking. Let me know if you want me to move this, or steal it yourself. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2017 Author Share Posted July 13, 2017 Is scene.materials not enough to get all materials? Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 13, 2017 Share Posted July 13, 2017 For those defining all their meshes before the first render (but mesh do you pass to forceCompilation). I am attempting to dynamically add meshes to a scene that is already rendering meshes. I retrieve the geo (inside .js files) & buffer the data for texture files asyc ahead of time to reduce the slow down. There is going a brief hiccup though. That is kind of disguised using these animations to initially display meshes. Do not want either the animation to not be smooth or be behind the audio. I am fine it this was just in my code. Would have marked the topic [solved], if it were mine. I am perfectly positioned for async shader compiling! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 13, 2017 Author Share Posted July 13, 2017 makes sense! Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 19, 2017 Share Posted July 19, 2017 I was looking for a way to force compile without an actual mesh, in the time between when a Launch button appears & the user clicks it. Do I have to make a 0 vertex Mesh to pass it to forceCompilation? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted July 19, 2017 Author Share Posted July 19, 2017 yep 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.