Exemplo n.º 1
0
def load_point_set(filename):
    """Read a point set and duplicate
	obj for each location.
	
	Insert every created object in sc
	"""
    Window.WaitCursor(True)

    sc = Scene.GetCurrent()
    ref_obj = sc.getActiveObject()

    #unselect everything except ref
    for obj in Object.GetSelected():
        obj.sel = 0

    ref_obj.sel = 1

    #read points
    pts = load(open(filename, 'rb'))

    for pid, vec in pts.iteritems():
        Object.Duplicate()
        obj = sc.getActiveObject()
        obj.setLocation(*vec)

    #return
    Window.RedrawAll()
def main():
    print '\nStarting BoneWeight Copy...'
    scn = Blender.Scene.GetCurrent()
    contextSel = Object.GetSelected()
    if not contextSel:
        Blender.Draw.PupMenu(
            'Error%t|2 or more mesh objects need to be selected.|aborting.')
        return

    PREF_QUALITY = Blender.Draw.Create(0)
    PREF_NO_XCROSS = Blender.Draw.Create(0)
    PREF_SEL_ONLY = Blender.Draw.Create(0)

    pup_block = [\
    ('Quality:', PREF_QUALITY, 0, 4, 'Generate interpolated verts for a higher quality result.'),\
    ('No X Crossing', PREF_NO_XCROSS, 'Do not snap across the zero X axis'),\
    '',\
    '"Update Selected" copies',\
    'active object weights to',\
    'selected verts on the other',\
    'selected mesh objects.',\
    ('Update Selected', PREF_SEL_ONLY, 'Only copy new weights to selected verts on the target mesh. (use active object as source)'),\
    ]

    if not Blender.Draw.PupBlock("Copy Weights for %i Meshs" % len(contextSel),
                                 pup_block):
        return

    PREF_SEL_ONLY = PREF_SEL_ONLY.val
    PREF_NO_XCROSS = PREF_NO_XCROSS.val
    quality = PREF_QUALITY.val

    act_ob = scn.objects.active
    if PREF_SEL_ONLY and act_ob == None:
        Blender.Draw.PupMenu(
            'Error%t|When dealing with 2 or more meshes with vgroups|There must be an active object|to be used as a source|aborting.'
        )
        return

    sel = []
    from_data = None

    for ob in contextSel:
        if ob.type == 'Mesh':
            me = ob.getData(mesh=1)
            groups = me.getVertGroupNames()

            # If this is the only mesh with a group OR if its one of many, but its active.
            if groups and ((ob == act_ob and PREF_SEL_ONLY) or
                           (not PREF_SEL_ONLY)):
                if from_data:
                    Blender.Draw.PupMenu(
                        'More then 1 mesh has vertex weights, only select 1 mesh with weights. aborting.'
                    )
                    return
                else:
                    # This uses worldspace_verts_idx which gets (idx,co) pairs, then zsorts.
                    if quality:
                        for _ob in contextSel:
                            _ob.sel = 0
                        ob.sel = 1
                        Object.Duplicate(mesh=1)
                        ob = scn.objects.active
                        me = ob.getData(mesh=1)
                        # groups will be the same
                        print '\tGenerating higher %ix quality weights.' % quality
                        subdivMesh(me, quality)
                        scn.unlink(ob)
                    from_data = (ob, me, worldspace_verts_idx(me, ob), groups)

            else:
                data = (ob, me, worldspace_verts(me, ob), groups)
                sel.append(data)

    if not from_data:
        Blender.Draw.PupMenu('Error%t|No mesh with vertex groups found.')
        return

    if not sel:
        Blender.Draw.PupMenu(
            'Error%t|Select 2 or more mesh objects, aborting.')
        if quality: from_data[1].verts = None
        return

    t = Blender.sys.time()
    Window.WaitCursor(1)

    # Now do the copy.
    print '\tCopying from "%s" to %i other mesh(es).' % (from_data[0].name,
                                                         len(sel))
    for data in sel:
        copy_bone_influences(from_data, data, PREF_SEL_ONLY, PREF_NO_XCROSS)

    # We cant unlink the mesh, but at least remove its data.
    if quality:
        from_data[1].verts = None

    print 'Copy Complete in %.6f sec' % (Blender.sys.time() - t)
    Window.DrawProgressBar(1.0, '')
    Window.WaitCursor(0)