コード例 #1
0
ファイル: import_selection.py プロジェクト: sorayaelcar/Sving
def new_from_selection(scene, target_location, editmode):
    # Create the set BBox
    # Note: We take ALL selected objects into account for the BBox calculation.
    bbox = BoundingBox()

    # Selection contains all selected objects in scene
    # roots contains all selected root objects (objects which have no selected parent)
    selection = []
    roots     = {}
    for ob in scene.objects.selected:
        #print "Add ", ob.getName(), " to BBox"
        bbox.add(ob)
        selection.append(ob)

        key = ob.getName()
        if roots.get(key) == None:
            newRoot = ob
            parent = ob.getParent()
            while parent != None and parent.isSelected():
                key = parent.getName()
                if roots.get(key) != None:
                    #print "Found key", key, "In roots list"
                    newRoot = None
                    break
                else:
                    newRoot = parent
                    parent = newRoot.getParent()
                    #print "key", parent.getName(), "not in roots list"
            if newRoot != None:
                key = newRoot.getName()
                roots[key] = newRoot
                print "Added new root :", key

    # unselect all curently selected objects:
    for ob in selection:
        ob.select(False)

    source_location = bbox.getCollectionLocation()
    offset = target_location - source_location
    
    target_list = []
    report = "";

    #Create copies of all objects in selection (if appropriate)
    image_dict = {}
    
    processed_objects = {}
    for key in roots.iterkeys():
        print "Processing root ", key
        root = roots[key]
        if processed_objects.get(key) == None:
            processed_objects[key] = root
            all_children, new_children, log = new_from_children(root, processed_objects, image_dict, offset)
            if log != "":
                report = report + log
            if sculpty.check(root):
                #print "Copy from ", ob.getName() 
                new_root, log = new_from_object(root,image_dict, offset)
                if new_root != None:
                    new_root.select(False)
                    if len(new_children) > 0:
                        Blender.Redraw()
                        print "Add",len(new_children),"Children to root", new_root.getName()
                        new_root.makeParent(new_children)
                        target_list.extend(new_children)
                    target_list.append(new_root)
                #else:
                #    print "Warn: copy of [", ob.getName(), "] failed."
            else:
                log = "Warn: Not a sculptie [" + root.getName() + "]  (Object not copied)|"
    
            if log != "":
                print log
                report = report + log


    # get over a bug in blender that fails to set 
    # correct lighting after creating a sculptie.
    for ob in target_list:
        ob.select(True)
        Blender.Window.EditMode(1)
        Blender.Window.EditMode(0) 
        ob.select(False)

    for ob in target_list:
        ob.select(True)

    return report
コード例 #2
0
def new_from_selection(scene, target_location, editmode):
    # Create the set BBox
    # Note: We take ALL selected objects into account for the BBox calculation.
    bbox = BoundingBox()

    # Selection contains all selected objects in scene
    # roots contains all selected root objects (objects which have no selected parent)
    selection = []
    roots = {}
    for ob in scene.objects.selected:
        #print "Add ", ob.getName(), " to BBox"
        bbox.add(ob)
        selection.append(ob)

        key = ob.getName()
        if roots.get(key) == None:
            newRoot = ob
            parent = ob.getParent()
            while parent != None and parent.isSelected():
                key = parent.getName()
                if roots.get(key) != None:
                    #print "Found key", key, "In roots list"
                    newRoot = None
                    break
                else:
                    newRoot = parent
                    parent = newRoot.getParent()
                    #print "key", parent.getName(), "not in roots list"
            if newRoot != None:
                key = newRoot.getName()
                roots[key] = newRoot
                print "Added new root :", key

    # unselect all curently selected objects:
    for ob in selection:
        ob.select(False)

    source_location = bbox.getCollectionLocation()
    offset = target_location - source_location

    target_list = []
    report = ""

    #Create copies of all objects in selection (if appropriate)
    image_dict = {}

    processed_objects = {}
    for key in roots.iterkeys():
        print "Processing root ", key
        root = roots[key]
        if processed_objects.get(key) == None:
            processed_objects[key] = root
            all_children, new_children, log = new_from_children(
                root, processed_objects, image_dict, offset)
            if log != "":
                report = report + log
            if sculpty.check(root):
                #print "Copy from ", ob.getName()
                new_root, log = new_from_object(root, image_dict, offset)
                if new_root != None:
                    new_root.select(False)
                    if len(new_children) > 0:
                        Blender.Redraw()
                        print "Add", len(
                            new_children
                        ), "Children to root", new_root.getName()
                        new_root.makeParent(new_children)
                        target_list.extend(new_children)
                    target_list.append(new_root)
                #else:
                #    print "Warn: copy of [", ob.getName(), "] failed."
            else:
                log = "Warn: Not a sculptie [" + root.getName(
                ) + "]  (Object not copied)|"

            if log != "":
                print log
                report = report + log

    # get over a bug in blender that fails to set
    # correct lighting after creating a sculptie.
    for ob in target_list:
        ob.select(True)
        Blender.Window.EditMode(1)
        Blender.Window.EditMode(0)
        ob.select(False)

    for ob in target_list:
        ob.select(True)

    return report