readonly face normal option eg.
authorCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jul 2009 18:17:21 +0000 (18:17 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 27 Jul 2009 18:17:21 +0000 (18:17 +0000)
 me.faces[0].normal

release/io/export_ply.py
source/blender/makesrna/intern/rna_mesh.c

index 6fdf4bf..3668693 100644 (file)
@@ -130,12 +130,10 @@ def write(filename, scene, ob, \
                
                
                smooth = f.smooth
-               # XXX need face normals
-               """
                if not smooth:
-                       normal = tuple(f.no)
+                       normal = tuple(f.normal)
                        normal_key = rvec3d(normal)
-               """
+               
                if faceUV:
                        uv = active_uv_layer[i]
                        uv = uv.uv1, uv.uv2, uv.uv3, uv.uv4 # XXX - crufty :/
@@ -149,12 +147,10 @@ def write(filename, scene, ob, \
                pf= ply_faces[i]
                for j, vidx in enumerate(f_verts):
                        v = mesh_verts[vidx]
-                       """
+                       
                        if smooth:
-                               normal=         tuple(v.no)
+                               normal=         tuple(v.normal)
                                normal_key = rvec3d(normal)
-                       """
-                       normal_key = None # XXX
                        
                        if faceUV:
                                uvcoord=        uv[j][0], 1.0-uv[j][1]
index 3a7015b..525814f 100644 (file)
@@ -39,6 +39,7 @@
 #include "DNA_scene_types.h"
 
 #include "BLI_editVert.h"
+#include "BLI_arithb.h"
 
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
@@ -110,6 +111,17 @@ static void rna_MEdge_crease_set(PointerRNA *ptr, float value)
        medge->crease= (char)(CLAMPIS(value*255.0f, 0, 255));
 }
 
+static void rna_MeshFace_normal_get(PointerRNA *ptr, float *values)
+{
+       Mesh *me= (Mesh*)ptr->id.data;
+       MFace *mface= (MFace*)ptr->data;
+       
+       if(mface->v4)
+               CalcNormFloat4(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, me->mvert[mface->v4].co, values);
+       else
+               CalcNormFloat(me->mvert[mface->v1].co, me->mvert[mface->v2].co, me->mvert[mface->v3].co, values);
+}
+
 /* notice red and blue are swapped */
 static void rna_MeshColor_color1_get(PointerRNA *ptr, float *values)
 {
@@ -892,6 +904,13 @@ static void rna_def_mface(BlenderRNA *brna)
        prop= RNA_def_property(srna, "smooth", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_SMOOTH);
        RNA_def_property_ui_text(prop, "Smooth", "");
+       
+       prop= RNA_def_property(srna, "normal", PROP_FLOAT, PROP_VECTOR);
+       RNA_def_property_array(prop, 3);
+       RNA_def_property_range(prop, -1.0f, 1.0f);
+       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+       RNA_def_property_float_funcs(prop, "rna_MeshFace_normal_get", NULL, NULL);
+       RNA_def_property_ui_text(prop, "face normal", "local space unit length normal vector for this face");
 }
 
 static void rna_def_mtface(BlenderRNA *brna)