0
$\begingroup$

I am creating a bmesh from a list of points in 3d space (e.g. a circle):

def extrude_mesh(self, context, bm):
    if context.scene.extrude_mesh:

        dir = self.shape.get_dir() * context.scene.draw_distance * 2

        if self.shape.is_extruded():
            dir = self.shape.get_dir() * self.shape.extrusion

        r = bmesh.ops.extrude_face_region(bm, geom=bm.faces[:])
        verts = [e for e in r['geom'] if isinstance(e, bmesh.types.BMVert)]
        bmesh.ops.translate(bm, vec=dir, verts=verts)

.............

def create_object(self, context):

    # Create a mesh and an object and 
    # add the object to the scene collection
    mesh = bpy.data.meshes.new("MyMesh")
    obj  = bpy.data.objects.new("MyObject", mesh)

    bpy.context.scene.collection.objects.link(obj)

    bpy.ops.object.select_all(action='DESELECT')

    bpy.context.view_layer.objects.active = obj
    obj.select_set(state=True)

    # Create a bmesh and for list of vertices
    bm = bmesh.new()
    bm.from_mesh(mesh) 

    for v in self.shape.vertices:
        bm.verts.new(v)

    bm.verts.index_update()

    bm.faces.new(bm.verts)

    self.extrude_mesh(context, bm)

    bm.to_mesh(mesh)  
    bm.free()

The new object that is created has the rotation (0,0,0), but I want the rotation to be the direction of the face from which I created the bmesh.

P.S. Just saw that I could just set the rotation_euler to the direction of the shape?

P.P.S. Tried it but doesnt solve the problem. Any ideas? The orientation of the mesh is alright but the rotation of the objects is (0,0,0) because it is created like this.

$\endgroup$
  • $\begingroup$ Related blender.stackexchange.com/questions/19533/… $\endgroup$ – batFINGER Mar 28 at 12:13
  • $\begingroup$ @batFINGER: Ok, I see, but the rotation in 3d space of my extruded object is correct, I just want the rotation in the view to be reflected as rotation of the object but it is set to '(0,0,0)' $\endgroup$ – Jayanam Mar 28 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.