Page MenuHome

Bmesh module does not support smooth shading / split normals
Open, NormalPublic

Description

Blender Version
Broken: 2.75 RC2

Short description of error
BMLoop.calc_normal() returns normal for flat-shading, regardless of applied shading.

Exact steps for others to reproduce the error
Based on a (as simple as possible) attached .blend file with minimum amount of steps

Run the following script, both APIs should give the same normals, but Bmesh module returns the same for all 3 objects.

import bpy
import bmesh

scene = bpy.context.scene
for ob in scene.objects:
    ob.select = True
bpy.ops.object.delete()

bpy.ops.mesh.primitive_cube_add(location=(0,3,0))
cube1 = bpy.context.object

bpy.ops.mesh.primitive_cube_add(location=(0,0,0))
bpy.ops.object.shade_smooth()
cube2 = bpy.context.object

bpy.ops.mesh.primitive_cube_add(location=(0,-3,0))
bpy.ops.object.shade_smooth()
bpy.ops.mesh.customdata_custom_splitnormals_add()
cube3 = bpy.context.object

# no difference
cube1.data.use_auto_smooth = True
cube2.data.use_auto_smooth = True
cube3.data.use_auto_smooth = True

cube1.data.calc_normals_split()
cube2.data.calc_normals_split()
cube3.data.calc_normals_split()

bm1 = bmesh.new()
bm1.from_mesh(cube1.data)
bm1.faces.ensure_lookup_table()

bm2 = bmesh.new()
bm2.from_mesh(cube2.data)
bm2.faces.ensure_lookup_table()

bm3 = bmesh.new()
bm3.from_mesh(cube3.data)
bm3.faces.ensure_lookup_table()
bm3.normal_update()

print("Standard API:")
print(cube1.data.loops[0].normal, "Flat")
print(cube2.data.loops[0].normal, "Smooth")
print(cube3.data.loops[0].normal, "Smooth")
print("---")
print("Bmesh module:")
print(bm1.faces[0].loops[0].calc_normal(), "Flat")
print(bm2.faces[0].loops[0].calc_normal(), "Smooth")
print(bm3.faces[0].loops[0].calc_normal(), "Smooth")
print("------")

Note: Standard API could be used instead, but there's no RNA method for triangulation (only modifier and operator). Mixing Bmesh module and standard API seems unsafe (and there's no direct access to loops in bm). Object.to_mesh() could use support for triangulation, hence quad_mathod / ngon_method to improve the situation.

Details

Type
To Do

Event Timeline

codemanx updated the task description. (Show Details)Jun 22 2015, 8:36 PM
codemanx added projects: BF Blender, Modeling, Python.
codemanx set Type to Bug.
codemanx added a subscriber: codemanx.
codemanx created this task.
codemanx raised the priority of this task from to Needs Triage by Developer.
codemanx updated the task description. (Show Details)Jun 22 2015, 8:43 PM
codemanx updated the task description. (Show Details)Jun 22 2015, 8:53 PM

I do not see any bug really here, more like known TODOs/feature request?

Custom normals are only accessible from main mesh RNA currently, this is known limitation.

@Campbell Barton (campbellbarton) will let you decide here.

Bastien Montagne (mont29) triaged this task as Normal priority.Jun 23 2015, 5:15 PM

If split normals are not available (yet), that's fine. Should be made clear in the description of the bmesh function however. Vertex normals work correctly as far as I can tell.

This is a TODO. normal custom-data layer isn't accessible yet.