I'm trying to update an exporter to work with Blender 2.8 but can't seem to get a mesh data-block modified by modifiers or shape keys. It always gives me the base mesh.

I'm currently using Object.to_mesh(). But reading Object.data or bmesh.from_mesh(obj) all returns only the base mesh. So what is the new function to call for getting a mesh data-block with the modifiers and shape keys applied?



Using the bmesh from object, can be written to another mesh as the deformed modified mesh.

Test script, writes context object deformed / modified mesh to new mesh "ObjBmesh"

import bpy
import bmesh

context = bpy.context
ob = context.object
dg = context.evaluated_depsgraph_get()

bm = bmesh.new()
bm.from_object(ob, dg)

Would like too, to be able to use Object.to_mesh(...) which should be quicker. Will look into the importers and see if any are using this method to apply deforms / modifiers and report back.


Just tested batFINGER's solutions. It's pretty convoluted and you have to call bm.clear() every time the mesh updates before calling the last two functions. It works but really doesn't feel like the intended way to do things. Digging a bit further I think I found the intended solution:

#We only have to do this once:
ob = bpy.context.active_object #getting the object we want.
dg = bpy.context.evaluated_depsgraph_get() #getting the dependency graph

#This has to be done every time the object updates:
ob = ob.evaluated_get(dg) #this gives us the evaluated version of the object. Aka with all modifiers and deformations applied.
me = ob.to_mesh() #turn it into the mesh data block we want.

Still annoying that we can't pick between preview and render for which version of the modifiers it applies (it seems to always pick preview). If there is a way to do that I would love to know.


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.