Jump to content

Flat Mesh from Blender


Snouto
 Share

Recommended Posts

Yo 3D dudes and dudettes

I've just updated the Blender exporter and BJS to the latest versions as I was using some fairly old code. One of the first things I noticed was that my .babylon file has gone from 2.1mb down to 600kb, which is awesome, so bravo to you guys for that excellent piece of optimisation.

I also noticed through first observing and then from looking about the internets that the export option to make everything Flat has vanished. I confirmed this from a post by @JCPalmer here 

For my project I still wish to maintain that flat look, so I understand one way to do this is via BJS code using Mesh.convertToFlatShadedMesh()

I just wanted to ask if this is indeed the correct approach to reproduce the flat shading appearance from Blender? It does work for me (albeit I have to ensure the meshes I'm iterating through after load support mesh.subMeshes, otherwise a JS error is thrown) but I'm not sure this is the most optimal way. I did try adjusting the angle of the split edged modifier in Blender but that didn't appear to make the slightest bit of difference once I exported to BJS. 

If I stick with convertToFlatShadedMesh() when loading my scenes and objects am I incurring an additional performance hit over the old exporter approach of "Flat shade entire scene", or are these two things essentially the same outcome just with the processing occurring in different places? If the latter, how might I take care of that processing at the model level rather than the client browser?

Cheers and keep up the excellent work!

Link to comment
Share on other sites

7 hours ago, JCPalmer said:

What happens when you drop it down to 0? 

Sigh....I hate myself sometimes. Tried a bunch of angles except god-damn 0. Okay so that works on a couple of the meshes in my scene that need it. Here's the thing though, whereas before it was super convenient to be able to apply the flat mesh across the whole scene it seems now I have to choose individual meshes and set the EdgeSplit manually. If i was only doing this one time that would probably be fine but in my case I am receiving regular updates to the FBX model I'm importing and so every time I import a new FBX I'm going to have to manually go through every mesh and set the EdgeSplit again. This is less than optimal, plus I'm really lazy.

Since there is also the script option I mentioned earlier, if I were to simply use Mesh.convertToFlatShadedMesh only and skip setting EdgeSplits across dozens of meshes in Blender, am I going to experience a significant performance or quality drop/difference in the browser? I can accept a bit of a performance drop right at the start as my code iterates each mesh and fires that JS command, but is there any knock-on effect to my scene after that process completes? Just asking so I understand my options.

Cheers JCP.

[edit] Another option springs to mind, and that is to use a simple python script within Blender to auto add an EdgeSplit modifier to all meshes:

import bpy

for obj in bpy.data.objects:
    if obj.type == "MESH":
        edgeSplit = obj.modifiers.new("EdgeSplit", type = "EDGE_SPLIT")
        edgeSplit.split_angle = 0
        bpy.context.scene.update()

I'd still like to reduce the amount of steps I need to take every time an FBX is imported so would appreciate some further information as asked above. Cheers :)

Edited by Snouto
Added a bit about Blender .py script
Link to comment
Share on other sites

Yep:

  • put your Edge Split modifier on your active object
  • select all objects where you want to copy this modifier (by keeping your current object active)
  • Ctrl + L > Modifiers (or 3DView > Object > Make Links)

By doing that, note that all modifiers already assigned on selected objects are deleted (not applied), and replaced by the modifiers from the current active object.

To avoid this you can tweak your script by checking if the modifier exist, and if so modify its value:

import bpy

for obj in bpy.data.objects:
    if obj.type == "MESH": 
        bpy.context.scene.objects.active = obj
        edgeSplit = None
        if obj.modifiers.get("EdgeSplit"):
            edgeSplit = obj.modifiers.get("EdgeSplit")
        else:
            edgeSplit = obj.modifiers.new("EdgeSplit", type = "EDGE_SPLIT")
        edgeSplit.split_angle = 0
        bpy.context.scene.update()

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...