How to read the final blended position of shape keys...

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
dvochin
Posts: 0
Joined: Mon Aug 20, 2012 9:39 pm

How to read the final blended position of shape keys...

Post by dvochin »

Hello!

I have a mesh that has several modified shape keys applied and each of these shape keys is blended (to protect mesh borders)...

I need to access from Blender python the fully-blended position of my mesh as it is displayed in object mode with the current settings of all shape keys sliders at the current position.

In other words I need to 'bake' the mesh at a given state of shape keys... hopefully without having to remove all shape keys to do it.

Is there a way to do it (hopefully with bmesh) I've tried things like (C.object.data.shape_keys.key_blocks[1].data[0].co but to no avail)

Thanks!

Dan,

dvochin
Posts: 0
Joined: Mon Aug 20, 2012 9:39 pm

Post by dvochin »

Ha! finally found it! Add a new shape key 'from mix', and the 'baked' verts position are in its array!

aKeys = oMeshO.data.shape_keys.key_blocks
bpy.ops.object.shape_key_add(from_mix=True) ###LEARN: How to 'bake' the current shape key mix into one.
nKeys = len(aKeys)
aVertsBakedKeys = aKeys[nKeys-1].data # We obtain the vert positions from the 'baked shape key'

aVertsBakedKeys[nVert] = your baked vert position!

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

There's no need for an operator call or any destructive action. You can apply the shape keys etc. in memory.

Code: Select all

import bmesh
bm = bmesh.new()
bm.from_object(bpy.context.scene, bpy.context.object)
print(bm.verts[#].co)
Or

Code: Select all

bpy.context.object.to_mesh(,..)
if you
want a mesh datablock
I'm sitting, waiting, wishing, building Blender in superstition...

dvochin
Posts: 0
Joined: Mon Aug 20, 2012 9:39 pm

Post by dvochin »

Hi CoDEmanX, I though I tried with bmesh but wasn't getting the mix. Will try thoroughly tomorrow with your 2 code segments and report what I find.

Many thanks! :)

Post Reply