Blender 2.5. Objects normal rotated 180

I have noticed that when I add a mesh to Blender 2.5 that the object has it’s normal rotated 180 about the X axis.

Here is some example code. I think that the point of the pyramid should be pointing up.


# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2008-2009, Aaron Keith
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****


import bpy
import Mathutils


# next two utility functions are stolen from import_obj.py

def unpack_list(list_of_tuples):
    l = []
    for t in list_of_tuples:
        l.extend(t)
    return l

def unpack_face_list(list_of_tuples):
    l = []
    for t in list_of_tuples:
        face = [i for i in t]

        if len(face) != 3 and len(face) != 4:
            raise RuntimeError("{0} vertices in face.".format(len(face)))
        
        # rotate indices if the 4th is 0
        if len(face) == 4 and face[3] == 0:
            face = [face[3], face[0], face[1], face[2]]

        if len(face) == 3:
            face.append(0)
            
        l.extend(face)

    return l



class AddExample(bpy.types.Operator):
    '''Add a example mesh.'''
    bl_idname = "mesh.primitive_Example_add"
    bl_label = "Add Example"
    bl_register = True
    bl_undo = True



    def execute(self, context):
          
        verts = [[0.0, 0.0, 0.0] , [1.0, 0.0, 0.0] , [0.0, 1.0, 0.0] , [1.0, 1.0, 0.0] , [0.5,0.5,1.0]]
        faces =  [[0, 1, 3,2] , [1, 3, 4],[2,3,4],[0,2,4]  ] 

        mesh = bpy.data.add_mesh("Test")
    
        mesh.add_geometry((len(verts)), 0, int(len(faces)))
        mesh.verts.foreach_set("co", unpack_list(verts))
        mesh.faces.foreach_set("verts_raw", unpack_face_list(faces))

        mesh.update()

        ob_new = bpy.data.add_object('MESH', "Test_ob")
        ob_new.data = mesh

        scene = context.scene
        
        scene.objects.link(ob_new)
        scene.objects.active = ob_new
        ob_new.selected = True
        #bpy.ops.object.rotation_clear()  #Need to add this to get the meshing pointing up.
        
        return ('FINISHED',)

# Register the operator
bpy.ops.add(AddExample)

# Add to a menu
import dynamic_menu

menu_func = (lambda self, context: self.layout.operator(AddExample.bl_idname, text="Example"))
    
menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, menu_func)

if __name__ == "__main__":
    bpy.ops.mesh.primitive_Example_add()
    

Is this a known bug or am I missing a step when I create the mesh?

My workaround is to do a bpy.ops.object.rotation_clear() on the object.

i did suspect the same,
and some others too. It is in this thread:
> http://blenderartists.org/forum/showthread.php?t=173112

but i know too less about all the new things
and one simple way for me was to clear the rotation of the object too
and it did flip in the desired orientation. Dont know if one of my
matrix-muls not working …
…the name of the vector-cross-product in mathutils did change… but thats not the only thing.

Your example is for an ‘old’ Blender 2.5 ?!
E.g. Mathutils does not exist anymore it is now mathutils

and some bpy changes too

NO: mesh = bpy.data.add_mesh(“Test”)
replaced by
mesh = bpy.data.meshes.new(“Test”)

ob_new = bpy.data.add_object(‘MESH’, “Test_ob”)
does not work
what worked is this using the just updated mesh:
ob_new = bpy.data.objects.new(‘MESH’, mesh) #changed PKHG

and registering is done differently (in my experiment with your code)
I mirrored it from add_mesh_torus.py (in .blender/scripts/op )

With your code changed (using the Torus icon ) your AddExample was added in the
shift-A -> mesh and I got a pyramid :slight_smile:

Result
http://i41.tinypic.com/214qu74.jpg
:edit:
I would like to know how to add own icons, I misused the torus Icon in my test …