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.