new mesh module - editmode coordinates?

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

new mesh module - editmode coordinates?

Post by kakapo »

how can i get the undeformed editmode vertex coordinates with the new mesh module?

the cage parameter of mesh.getfromobject doesn't have an effect in my scripts. i always get the deformed coordinates.

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post by khughes »

Use Mesh.getFromObject(srcmesh,1); the second parameter (cage) defaults to 0, which returns the deformed mesh.

getFromObject(name, cage=0)
Replace the mesh's existing data with the raw mesh data from a Blender Object. This method supports all the geometry based objects (mesh, text, curve, surface, and meta). If the object has modifiers, they will be applied before to the object before extracting the vertex data unless the cage parameter is 1.

Parameters:
name - name of the Blender object which contains the geometry data.
(type=string)
cage - determines whether the original vertices or derived vertices (for objects with modifiers) are used. The default is derived vertices.
(type=int)

Note: The mesh coordinates are in local space, not the world space of its object. For world space vertex coordinates, each vertex location must be multiplied by the object's 4x4 transform matrix (see transform).

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

yes, sounds nice and exactly like what i need but it doesn't work! :)

using "cage=1" as second parameter gives an error and just using "1" doesn't have an effect.

am i doing something wrong or is this a bug?

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

does this work for anyone? who is the developer of the new mesh module?

LetterRip
Posts: 0
Joined: Thu Mar 25, 2004 7:03 am

Post by LetterRip »

khughes is the module developer :)

LetterRip

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

oh! :)

why do i get the "getFromObject() takes no keyword arguments" message? looks like there is something wrong to me.

and is it necessary to do some "going into or leaving editmode" trick like blender python sometimes requires (which often confuses me)?

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post by khughes »

Sorry; the "cage=" parameter is just there to show there is a second optional parameter and its default value. Just pass the "1" parameter alone.

And yes, the Mesh module is like the NMesh module. You need to be out of edit mode if you make changes to the mesh. I usually just put a "Blender.Window.Editmode(0)" at the start of my script to force this,

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

and what do i have to do to get the undeformed coordinates? go out of editmode aswell? i think i was in object mode when i tried it. i have no idea what i am doing wrong. i can't get the editmode coordinates. but except for that problem i find the mesh module much nicer than nmesh. :)

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post by khughes »

It's best to not be in edit mode at all when using Mesh and NMesh. This is because edit mode uses special data structures which the NMesh and Mesh modes do not access. Any changes to the mesh in edit mode cannot be seen from Python until you exit edit mode and the data structures are copied back to the mesh structure by Blender.

Maybe I'm also misundertanding what you mean by "editmode coordinates". I assume you mean the vertex coordinates.

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

by "editmode coordinates" i mean the undeformed coordinates. the coordinates of the vertices just like they appear in editmode without armature deformations and so on. they are needed in my model format as the bind pose of the armature.

how would i get them? i wasn't able to figure that out for your new mesh module.

strangely my old exporter which uses nmesh can't output "editmode coordinates" anymore with 2.40 although it worked for 2.37a but i only noticed this at a quick glance and would have to investigate this further. NMesh.GetRaw and NMesh.GetRawFromObject seem to return the same in 2.40.

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post by khughes »

I can't speak about meshes deformed by armatures (I don't know how to use armatures), but I just tested an example of a cube with a wave modifier applied to it, a plane (or any mesh), and this script:

Code: Select all

import Blender

cage=1 # cage = 0 for deformed vertices
me = Blender.Mesh.Get('Plane')
me.getFromObject('Cube',cage)
for v in me.verts:
    print v.co
When cage=0, I see the verts deformed by the wave modifer. When cage=1, I see the undeformed verts.

If this works for you, but something similar doesn't work for armatures, then submit a bug report with a sampe blend file and I'll look at it.

kakapo
Posts: 0
Joined: Sat Sep 04, 2004 2:32 pm

Post by kakapo »

argh, it was my fault. stupid me! my model viewer always displayed the wrong data because of a nasty bug. i should have compared the text output of simple objects like in your example earlier.

i am very sorry for wasting your time! :oops:

the new mesh module is great! this cage parameter solution is much nicer than using NMesh.GetRaw and NMesh.GetRawFromObject!

khughes
Posts: 0
Joined: Sat Jan 08, 2005 9:30 pm
Location: Northern California

Post by khughes »

No problem; a good portion of my development time on this module was learning how other things in Blender worked, so I wouldn't have been surprised if I'd missed something here. Glad it's doing what you need! :D

Post Reply