Faces shade smooth export

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Ilya81
Posts: 2
Joined: Wed Jun 06, 2012 1:59 pm
Location: St-Petersbug, Russia

Faces shade smooth export

Postby Ilya81 » Wed Jun 06, 2012 2:20 pm

The question isn't new but I've not succeeded to find an appropriate answer. I need to differ faces_shade_smooth when it's applied only to a faces group but groups aren't smoothed between them. I've succeded to find only use_smooth property and the built-in export script acts the same way (i. e. doesn't differ smooth groups).

I've found how to do it from UI but I don't know how can I export it in a script.

Tell me please how can I exactly get if a particular polygon that uses smooth does belong to some group or doesn't (i. e. if it should be smoothed with some other polygon or not).

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Wed Jun 06, 2012 10:22 pm

by groups you mean vertex groups right?

hope this helps:

Code: Select all

import bpy

o = bpy.context.object
m = o.data

print("Object:   %s" % o.name)
print("Mesh:     %s" % m.name)
print("Polygons: %i" % len(m.polygons))
print()

for poly in m.polygons:
   
    if not poly.select:
        continue
   
    print("Polygon %i smooth? %s" % (poly.index, poly.use_smooth))

    for vert_index in poly.vertices:
        vertex = m.vertices[vert_index]
       
        print("  Vertex %i" % vert_index)
        print("  Vertex groups: %i" % len(vertex.groups))
        for g in vertex.groups:
            print("    %s" % o.vertex_groups[g.group].name)
        print()
I'm sitting, waiting, wishing, building Blender in superstition...

Ilya81
Posts: 2
Joined: Wed Jun 06, 2012 1:59 pm
Location: St-Petersbug, Russia

Postby Ilya81 » Thu Jun 07, 2012 9:24 am

Unfortunantly that is not I'm looking for. I've already tried this way and found out that smooth groups don't match vertex groups (really I'm not sure if smooth groups are represented for vertices, edges or polygons). E. g. if I select a mesh, enter in edit mode, select some polygons, press W and select from popup menu "Shade smooth" I don't create a vertex group. I can see that in the object data tab the list of vertex groups is still empty.

The smooth groups effect is only that polygons are being smoothed only inside groups but not between them. Such feature was for a long time 3D Studio Max and appeared only in some latest versions of Blender. The problem is how to export it, standard scripts still are not modified for this new feature.

CoDEmanX
Posts: 894
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Postby CoDEmanX » Thu Jun 07, 2012 2:04 pm

the operator exec function of bpy.ops.mesh.faces_shade_smooth call:

mesh_set_smooth_faces(em, 1);

which does:

Code: Select all

   BMIter iter;
   BMFace *efa;

   if (em == NULL) return;
   
   BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
      if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
         BM_elem_flag_set(efa, BM_ELEM_SMOOTH, smooth);
      }
   }


in python it would be:

Code: Select all

for efa in bm:
    if efa.select:
        efa.use_smooth = smooth # 0 or 1


so my above code is right, the information is stored in poly.use_smooth
I'm sitting, waiting, wishing, building Blender in superstition...


Return to “Python”

Who is online

Users browsing this forum: No registered users and 2 guests