[Bf-python] axis copy needs a short improvement

Campbell Barton cbarton at metavr.com
Tue Jul 4 17:04:09 CEST 2006


Hi, eas reading through the script - its short so Ill include it.

Some questions and points....

   1. Is there any reason to rotate the mesh data?, why not modify the
      existing objects matrix by the rotation matrix of the source
      object- that way its not limited to meshes.
      Id strongly recomment we do this. Object scripts that modify mesh
      data without telling the user are a bit of a worry. - what if they
      are using the object in another scene?
   2. cible.mat.rotationPart().toEuler().toMatrix()  can be replaced
      with   cible.getEuler('worldspace').toMatrix()
   3. included mesh tx function is not needed, use mesh transform (if
      you need to edit the data in a mesh at all)
   4. If you do this script on the same data a few times as well as on
      copys, it will add a new mesh rather then replacing the old one.

JMS if you dont want to, would you mind if I re-did this script?
- Cam



from Blender.Mathutils import *


def applyTransform(mesh,mat):
  for v in mesh.verts:
      vec = v.co*mat
      v.co[0], v.co[1], v.co[2] = vec[0], vec[1], vec[2]




oblist =Object.GetSelected()
lenob=len(oblist)

error = 0
for o in oblist[1:]:
    if o.getType() != "Mesh":
        Draw.PupMenu("Error: selected objects must be meshes")
        error = 1

if not error:
    if lenob<2:
        Draw.PupMenu("Error: you must select at least 2 objects")
    else :
        source=oblist[0]
        nsource=source.name
        texte="Copy axis orientation from: " + nsource + " ?%t|OK"
        result=Draw.PupMenu(texte)


        for cible in oblist[1:]:
            if source.rot!=cible.rot:
                rotcible=cible.mat.rotationPart().toEuler().toMatrix()
                rotsource=source.mat.rotationPart().toEuler().toMatrix()
                rotsourcet = Matrix(rotsource)
                rotsourcet.invert()
                mat=rotcible*rotsourcet
                ncible=cible.name
                me=NMesh.GetRaw(ncible)
                applyTransform(me,mat)
                NMesh.PutRaw(me,ncible)
                cible.makeDisplayList()
                cible.rot=source.rot




jean-michel soler wrote:
> Campbell Barton a écrit :
>
>> getData(mesh=1) is the only change you should need to make.
>
>
> ok, make it .
>
> jms .
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-python
>


-- 
Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list