JCPalmer Posted July 22, 2015 Share Posted July 22, 2015 I have implemented baking in Blender, but only for the Blender Renderer, not yet the Cycles renderer. It works, including with multi-materials, but is wasteful in such a case. My test scene shows this case https://googledrive.com/host/0B6-s6ZjHyEwUfkxKTWU2cXZQOGxydC1KS2o0NHUzRzFUTFlNYldDUmIzZ0JxeGVqMlU3c3M . The problem is I was processing each material for a Mesh as I was constructing it. If there were 2 materials that required the same type of baking, you would get 2 identical textures. The baked textures are not just for a single material, but the whole mesh, including any image textures. I am solving this problem by having a python class to pre-process all the baking requirements of a mesh ahead of time. When baking is required, I can just bake once, and apply it to the mesh with no multimaterials at all. No multi-materials should also improve performance, which is good for a gaming API. Also, the same API for baking is used regardless of renderer. Cycles might be supportable, implemented as baked textures. I can detect Nodes & a diffuse shader, but do not know which node types should cause which type of baking. Here is the class so far, but I am not sure which shader types map into the Babylon texture types. Here is the comprehensive list of Node types. Please advise if other node types can be used to identify textures to bake.http://www.blender.org/api/blender_python_api_2_75_release/bpy.types.ShaderNode.html# need to evaluate the need to bake a mesh before even starting; class also stores specific types of bakesclass BakingRecipe: def __init__(self, mesh, forceBaking = False): # initialize all members self.needsBaking = forceBaking self.cyclesRenderer = False self.diffuseBaking = forceBaking self.ambientBaking = False self.opacityBaking = False self.reflectionBaking = False self.emissiveBaking = False self.bumpBaking = False self.specularBaking = False # transfer from Mesh exporter properties self.bakeSize = mesh.data.bakeSize self.bakeQuality = mesh.data.bakeQuality # for lossy compression formats for material_slot in mesh.material_slots: # a material slot is not a reference to an actual material; need to look up for mat in bpy.data.materials: if material_slot.name == mat.name: material = mat break # testing for Cycles renderer has to be different if material.use_nodes == True: self.needsBaking = True self.cyclesRenderer = True for node in material.node_tree.nodes: id = node.bl_idname if id == 'ShaderNodeBsdfDiffuse': self.diffuseBaking = True if id == 'ShaderNodeAmbientOcclusion': self.ambientBaking = True if id == '': self.opacityBaking = True if id == 'ShaderNodeEmission': self.emissiveBaking = True if id == 'ShaderNodeNormal' or id == 'ShaderNodeNormalMap': self.bumpBaking = True if id == '': self.specularBaking = True else: textures = [mtex for mtex in material.texture_slots if mtex and mtex.texture] for mtex in textures: if mtex.texture.type == 'IMAGE': continue self.needsBaking = True if mtex.use_map_diffuse or mtex.use_map_color_diffuse: if mtex.texture_coords == 'REFLECTION': self.reflectionBaking = True else: self.diffuseBaking = True if mtex.use_map_ambient: self.ambientBaking = True if mtex.use_map_alpha: self.opacityBaking = True if mtex.use_map_emit: self.emissiveBaking = True if mtex.use_map_normal: self.bumpBaking = True if mtex.use_map_color_spec: self.specularBaking = True Wingnut 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted July 31, 2015 Share Posted July 31, 2015 Thanks JC. I sure wish I could participate in conversations with you, on these subjects. I just KNOW that one of these days, you're going to enable Babylon.App.CreateBlender(). You have done (and still doing) an EXCELLENT job at trying to harvest and utilize every possible data that could be inside a .blend file. Too cool. Meantime, until I CAN participate tolerably, THANKS for teaching us (me) what you are doing and the issues you deal-with. Great post. 'BakingRecipe'... heh. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted July 31, 2015 Author Share Posted July 31, 2015 You are welcome. Cycles baking is now done. Tested with multi-materials. Still not sure on the Cycles baking recipe for specular, but stuck something in. There are so many Blender features that BJS does not use, that there definitely needs to be documentation. Am about 90% done. Having been doing a few commits to check on how it looks.https://github.com/BabylonJS/Extensions/tree/master/TowerOfBabel Am not going to release anything until documentation is done. .Babylon exporter still needs to be tested, but if you look at the background section of doc, you see that much has already been test indirectly. webGLmmk 1 Quote Link to comment Share on other sites More sharing options...
Wingnut Posted August 1, 2015 Share Posted August 1, 2015 Gorgeous readMe doc. Fantastically explained, great pics, clean format. Yay! What a nice treat... exactly when I am learning Blender and need to install exporters. Jc, do you have a moment to give me a status report on ShapeKeys? Now that I re-understand your two-pass TOB exporter system (genius, by the way), you possibly have ShapeKey classes already being spawned (if present in the .blend file). I'm asking on behalf of a forum user friend, and I have not yet studied Blender ShapeKeys. I suspect it is a mesh-morphing system. I suppose a serious "manipulation" is needed to transform your found ShapeKeys objects... into something usable in webGL. And I bet a ShapeKeys field can be data-FAT when operating on a high-poly mesh or 10. Of course, it is not your job to do those conversions/honorings, and I want to thank you for the converting of other classes that you've already done... without much help. Good deal! "Honoring"? Is that the correct word? "There are so many Blender features that BJS does not use". That's expected, of course. Blender is a power modeler and BJS is a "view" of .blend files and cannot be expected to "honor" all of Blender's features. That is an impossible task. Hear me well, newbies who expect 1-to-1 feature-honoring for Blender->BJS! Like I have room to talk. I have done TONS of expecting, without knowing the issues behind the expectation/dream. The newbies will still ask, expect, and demand. Your docs are definitely ready to explain the situation to everyone. But just the same, near the bottom of your TOB readme... if you could put some approximate stats as-of xxx date... that would be cool. Something like... as of xxx date, there is approximately xxx .blend file items... that are NOT honored on first pass. There is yyy first-pass-honored .blend items... that are NOT honored on second pass. I bet it's quite satisfying to see TOB chow-up any .blend file and grow your pile of 2nd pass objects. Roto-tiller. It's handy for updating, too, because you can tweak these 2nd-pass objects so easily, as Blender or BJS does future changes. Good good good. Now, staying updated for all the future changes in the first-pass of .blend files, there's a challenge, eh? Every new Blender feature... potentially requires another TOB spawn-off class, I guess. Spawn-off... and look-into honoring that new feature in BJS, someday. You can easily see the Blender features work-pile, I bet. Pretty tall, probably. I'll try to help if I can. It's an interesting project... and seriously useful. Really, it's imperative. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted August 3, 2015 Author Share Posted August 3, 2015 Thanks, a consequence of working @ Xerox for a decade+ is: how to document is pretty much beaten into you (before you ask I only document my own stuff). Still adding into & pushing up to see how it looks. Cannot get an image and text to display side by side. Quick answer on shape keys plans. I am waiting for something to happen. Am too far in front & bleeding. They may have caught up. Will check again after this release. On BJS side, have implemented SIMD for Morph 1.3 lib, but never pushed up. To be honest, newbies should be able to read & understand Doc, but not interested in impressing them though. Now Blender experts like Super Mitch with looks like 20 years experience are another story. Getting another 5 or 6 under the BJS tent as a result of Cycles is better than a 1000 newbies. 3JS is in deep crap with these people if it does not do Cycles exporting once this is available. Both exporters are done & going into QA testing. The baking scene works on both exporters, but I have a bunch of .blends. Have found a regression bug in 2.2 with instances in a .babylon. But I do not need it to work with 2.2 to PR it. Instances work fine in 2.1. (make sure not to inline texture files with 2.1 .babylon though) 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.