Lerige Posted February 1, 2015 Share Posted February 1, 2015 Hi all,My context: I have to load different meshes (not a complete scene) from different babylon files, without lights, and then I assemble them in one scene.Some of the babylon files come from Blender and others from .obj conversion.All my meshes from .obj should cast shadows. But I'd like to get "cast shadows" information from Blender files, since Blender meshes could, or could not, cast shadows. The shadow generator is defined independently in the code.I also have to say that I'm both new to Babylon and Blender. Yes, I'm looking for trouble I've made three hypothesis...H1/ complete Blender meshes "cast shadow" exportI've noticed a "cast shadow" check box in Blender mesh Babylon properties but nothing seems to be exported.To fix this I've added this line in io_export_babylon.py:# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def to_scene_file(self, file_handler, meshesAndNodes): file_handler.write('{') write_string(file_handler, 'name', self.name, True) write_string(file_handler, 'id', self.name) if hasattr(self, 'parentId'): write_string(file_handler, 'parentId', self.parentId) if hasattr(self, 'materialId'): write_string(file_handler, 'materialId', self.materialId) write_int(file_handler, 'billboardMode', self.billboardMode) write_vector(file_handler, 'position', self.position) write_vector(file_handler, 'rotation', self.rotation) write_vector(file_handler, 'scaling', self.scaling) write_bool(file_handler, 'isVisible', self.isVisible) write_bool(file_handler, 'isEnabled', self.isEnabled) write_bool(file_handler, 'useFlatShading', self.useFlatShading) write_bool(file_handler, 'checkCollisions', self.checkCollisions) write_bool(file_handler, 'castShadows', self.castShadows) # added line write_bool(file_handler, 'receiveShadows', self.receiveShadows)OK, now I have a complete .babylon file, but the problem is the property is not read by babylon at import... If I'm not mistaken I saw nothing in babylonFileLoader class to read this.This is easy to fix but would add a new shadow mesh property independent of shadowGenerator. This is not nice...H2/ work with materials... and then, I've saw there is already a standard "cast" checkbox in shadow section of Blender Materials. This seems logical, and so I'd like to get back this information in babylon.I see some advantages:- I use standard Blender properties- I do not have to duplicate information between Blender material and meshes, with risk of errorsOnce again it's easy to export the information: first, add this lineclass Material: def __init__(self, material, scene, filepath): self.name = BabylonExporter.nameSpace + '.' + material.name BabylonExporter.log('processing begun of material: ' + self.name) self.ambient = material.ambient * material.diffuse_color self.diffuse = material.diffuse_intensity * material.diffuse_color self.specular = material.specular_intensity * material.specular_color self.emissive = material.emit * material.diffuse_color self.specularPower = material.specular_hardness self.alpha = material.alpha self.backFaceCulling = material.game_settings.use_backface_culling self.castShadows = material.use_cast_shadows # added lineand then add this one:# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - def to_scene_file(self, file_handler): file_handler.write('{') write_string(file_handler, 'name', self.name, True) write_string(file_handler, 'id', self.name) write_color(file_handler, 'ambient', self.ambient) write_color(file_handler, 'diffuse', self.diffuse) write_color(file_handler, 'specular', self.specular) write_color(file_handler, 'emissive', self.emissive) write_float(file_handler, 'specularPower', self.specularPower) write_float(file_handler, 'alpha', self.alpha) write_bool(file_handler, 'backFaceCulling', self.backFaceCulling) write_bool(file_handler, 'castShadows', self.castShadows) # added line for texSlot in self.textures: texSlot.to_scene_file(file_handler) file_handler.write('}') But once again I'll have to update babylonFileLoader to read this.Not hard, but at this moment I am not sure at all it is the "philosophy" of Babylon materials to hold this information.H3/ Forget all this and use naming convention to know what to do with casting shadows !Conclusion: so, before doing anything, I need your opinion Maybe I completely missed the point, but it seems interesting to catch this Blender cast shadow materiel property...Thanks for reading. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted February 1, 2015 Share Posted February 1, 2015 Hello:) shadows are loaded from ShadowsGeneratorsThis is already handle by Blender exporter:https://github.com/BabylonJS/Babylon.js/blob/master/Exporters/Blender/io_export_babylon.py#L268 But in you case, because you are importing a mesh and not the complete scene you do not get this info Doc extract from here:http://doc.babylonjs.com/page.php?p=22661: ShadowGeneratorsA shadowGenerator is defined by the following JSON:{"useVarianceShadowMap": boolean,"usePoissonSampling": boolean,"mapSize": int (between 64 and 2048, must be a power of 2),"lightId": string,"renderList": array of string (which are IDs of meshes)} Quote Link to comment Share on other sites More sharing options...
Vousk-prod. Posted February 2, 2015 Share Posted February 2, 2015 There is an unwanted ":" at the end of the docs link above, the correct link for babylon file format doc is :http://doc.babylonjs...ge.php?p=22661 GameMonetize 1 Quote Link to comment Share on other sites More sharing options...
Lerige Posted February 2, 2015 Author Share Posted February 2, 2015 Hello Thanks for your answer. You're right: I can't use standard scene import in this case. I've decided to manage this with a parent "empty" blender object in which I put everything without shadow. This will do the job ! GameMonetize 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.