Exemplo n.º 1
0
def new_from_children(parent, processed_objects, image_dict, offset):

    report = ""
    new_children = []
    all_children = []
    
    siblings = obChildren(parent)
    for ob in siblings:
        allready_processed_object = processed_objects.get(ob.getName())
        if allready_processed_object == None:
            processed_objects[ob.getName()] = ob
            ac, children, creport = new_from_children(ob, processed_objects, image_dict, offset)
            if creport != "":
                report = report + creport
            if sculpty.check(ob):
                #print "Copy from ", ob.getName() 
                new_object, log = new_from_object(ob,image_dict, offset)
                if new_object != None:
                    if len(children) > 0:
                        Blender.Redraw()
                        new_object.makeParent(children)
                        all_children.extend(ac)
                    new_object.select(False)
                    new_children.append(new_object)
                #else:
                #    print "Warn: copy of [", ob.getName(), "] failed."
            else:
                log = "Warn: Not a sculptie [" + ob.getName() + "]  (Object not copied)|"
    
            if log != "":
                print log
                report = report + log
    return all_children, new_children, report
Exemplo n.º 2
0
def new_from_children(parent, processed_objects, image_dict, offset):

    report = ""
    new_children = []
    all_children = []

    siblings = obChildren(parent)
    for ob in siblings:
        allready_processed_object = processed_objects.get(ob.getName())
        if allready_processed_object == None:
            processed_objects[ob.getName()] = ob
            ac, children, creport = new_from_children(ob, processed_objects,
                                                      image_dict, offset)
            if creport != "":
                report = report + creport
            if sculpty.check(ob):
                #print "Copy from ", ob.getName()
                new_object, log = new_from_object(ob, image_dict, offset)
                if new_object != None:
                    if len(children) > 0:
                        Blender.Redraw()
                        new_object.makeParent(children)
                        all_children.extend(ac)
                    new_object.select(False)
                    new_children.append(new_object)
                #else:
                #    print "Warn: copy of [", ob.getName(), "] failed."
            else:
                log = "Warn: Not a sculptie [" + ob.getName(
                ) + "]  (Object not copied)|"

            if log != "":
                print log
                report = report + log
    return all_children, new_children, report
Exemplo n.º 3
0
    def __init__(self):

        # Read from repository
        bake_settings = Blender.Registry.GetKey(BAKE_REGISTRY, True)
        if bake_settings == None:
            bake_settings = {}
        for key, value in default_bake_settings.iteritems():
            if key not in bake_settings:
                bake_settings[key] = value
            elif bake_settings[key] is None:
                bake_settings[key] = value
            #else:
            #    print "Got setting from repo:", key,value
                    
        # ==========================================
        # Settings
        # ==========================================
        #print "bake_sculpt_mesh_util(): Setting up BakeApp environment"
        self.keep_center         = bake_settings['keep_center']
        self.keep_scale          = bake_settings['keep_scale']
        self.keep_seams          = bake_settings['keep_seams']
        self.optimize_resolution = bake_settings['optimize_resolution']
        self.auto_correct        = bake_settings['auto_correct']
        self.clear               = bake_settings['clear']
        self.fill                = bake_settings['fill']
        self.finalise            = bake_settings['finalise']
        self.range_min_r         = bake_settings['range_min'].x
        self.range_min_g         = bake_settings['range_min'].y
        self.range_min_b         = bake_settings['range_min'].z
        self.range_max_r         = bake_settings['range_max'].x
        self.range_max_g         = bake_settings['range_max'].y
        self.range_max_b         = bake_settings['range_max'].z
        self.range_scale         = bake_settings['range_scale']
        self.alpha               = bake_settings['alpha']
        self.alpha_filename      = bake_settings['alpha_file']
        self.update_file()
        self.save_settings       = bake_settings['save']
        self.save_defaults       = False

        # Optimization makes only sense when in multi bake mode            
        self.sculptie_counter = 0
        scene = Blender.Scene.GetCurrent()
        for ob in scene.objects.selected:
            if sculpty.check(ob):
                self.sculptie_counter += 1
        self.activeObject = scene.objects.active
        if self.sculptie_counter == 1:
            self.optimize_resolution = False
Exemplo n.º 4
0
    def bake(self):
        #print "bake_sculpt_mesh_util(): Baker started"
        startTime = Blender.sys.time()  #for timing purposes

        # We must bake in Object Mode (contraint imposed by blender)
        editmode = Blender.Window.EditMode()
        #print "Using editmode ... ", editmode
        Blender.Window.WaitCursor(1)
        if editmode:
            Blender.Window.EditMode(0)

        # prepare for bake, set centers and create bounding box
        bb = sculpty.BoundingBox(local=True)
        bb.rgb.min = sculpty.XYZ(
                self.range_min_r,
                self.range_min_g,
                self.range_min_b)
        bb.rgb.max = sculpty.XYZ(
                self.range_max_r,
                self.range_max_g,
                self.range_max_b)
        bb.rgb.update()

        
        scene = Blender.Scene.GetCurrent()
        if not self.keep_center:
            sculpty.set_selected_object_centers(scene)

        selection = []
        selection.extend(scene.objects.selected)
        for ob in selection:
            if sculpty.check(ob):
                bb.add(ob)            
        if self.keep_scale:
            bb = bb.normalised()
        if self.keep_center:
            bb = bb.centered()
        # Good to go, do the bake
        success = False
        image = None
        a = self.alpha
        if a == 3:
            alpha_image = Blender.Image.Load(self.alpha_filename)

        print "do_optimize is set to:", self.optimize_resolution
        image_dict = {}
        log = ""
        number_of_bake_candidates = len(selection)
        success = False
        for ob in selection:
            Blender.Window.WaitCursor(1)
            can_bake, reassigned_sculptmap, image, lg = check_for_bake(ob, image_dict, self.auto_correct)
            is_active = sculpty.active(ob)
            log = log + lg
            print "Object", ob.getName(), "can bake:",can_bake, "is active:", is_active
            if can_bake and is_active:

                if sculpty.bake_object(ob, bb, self.clear,
                            self.keep_seams, self.keep_center, self.optimize_resolution):
                    if need_rebake(ob, self.auto_correct):
                        if self.auto_correct:
                            sculpty.bake_object(ob, bb, self.clear,
                                self.keep_seams, self.keep_center, self.optimize_resolution)
                            log = log + "Info: Rebaked ob["+ob.getName()+"]. (reason: flipped vertex normals) |"
                            #print "rebake done"
                        else:
                            log = log + "Warn: ob["+ob.getName()+"] has flipped vertex normals. Please check for inside/out|"

                    success = success or True
                
                for image in sculpty.map_images(ob.getData(False, True)):
                    n = Blender.sys.splitext(image.name)
                    print "Baking [", n[0], "]"
                    if n[0] in ["Untitled", "Sphere_map", "Torus_map",
                            "Cylinder_map", "Plane_map", "Hemi_map",
                            "Sphere", "Torus", "Cylinder", "Plane", "Hemi"]:
                        image.name = ob.name
                    if self.range_scale:
                        if 'primstar' not in image.properties:
                            image.properties['primstar'] = {}
                        image.properties['primstar']['scale_x'] /= bb.rgb.scale.x
                        image.properties['primstar']['scale_y'] /= bb.rgb.scale.y
                        image.properties['primstar']['scale_z'] /= bb.rgb.scale.z
                    if self.fill:
                        sculpty.fill_holes(image)
                    if self.finalise:
                        sculpty.finalise(image)
                        if a == 2:
                            sculpty.bake_preview(image)
                        elif a == 1:
                            sculpty.clear_alpha(image)
                        elif a == 3:
                            sculpty.set_alpha(image, alpha_image)
                    if image.packed:
                        image.pack()
                    image.glFree()
        if self.activeObject != None:
            self.activeObject.select(True)
        if editmode:
            #print "Return to edit mode now ..."
            Blender.Window.EditMode(1)
        else:
            #print "Return to object mode now ..."
            if success and number_of_bake_candidates == 1:
                #print "stop by in edit mode"
                Blender.Window.EditMode(1)
                Blender.Redraw()
                Blender.Window.EditMode(0)

        for ob in selection:
            ob.select(True)
            
        if log != "":
            text = "Bake Report %t|" + log +"|OK"
            #print text
            Blender.Draw.PupMenu(text)  
        #Blender.Window.WaitCursor(0)
        #print "release cursor 2"
        Blender.Redraw()

        if success:
            gui.debug(1, 'finished baking: in %.4f sec.' % \
                    ((Blender.sys.time() - startTime)))
        else:
            gui.debug(0, 'bake failed after %.4f sec.' % \
                    ((Blender.sys.time() - startTime)))
Exemplo n.º 5
0
    def __init__(self, master):
        self.master = master
        self.cube_icon = gui.BitmapImage(data="""#define cube_width 16
#define cube_height 16
static unsigned char cube_bits[] = {
   0x00, 0x00, 0x80, 0x03, 0x70, 0x1c, 0x8c, 0x62, 0x94, 0x53, 0x64, 0x4c,
   0xa4, 0x4b, 0x2c, 0x69, 0x34, 0x59, 0x64, 0x4d, 0xa4, 0x4b, 0x2c, 0x69,
   0x30, 0x19, 0x40, 0x05, 0x80, 0x03, 0x00, 0x00 };
""")
        self.file_icon = gui.BitmapImage(data="""#define file_open_width 16
#define file_open_height 16
static unsigned char file_open_bits[] = {
   0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0xfe, 0x01, 0x0c, 0x02, 0x08, 0x04,
   0x00, 0x04, 0xf0, 0x00, 0x08, 0x7f, 0xf8, 0x40, 0x08, 0x40, 0x08, 0x40,
   0x08, 0x40, 0x08, 0x40, 0xf8, 0x7f, 0x00, 0x00 };
""")

        # ==========================================
        # Settings
        # ==========================================

        self.keep_center = BooleanVar(self.master)
        self.keep_center.set(settings['keep_center'])
        self.keep_scale = BooleanVar(self.master)
        self.keep_scale.set(settings['keep_scale'])
        self.keep_seams = BooleanVar(self.master)
        self.keep_seams.set(settings['keep_seams'])
        self.optimize_resolution = BooleanVar(self.master)
        self.optimize_resolution.set(settings['optimize_resolution'])
        self.auto_correct = BooleanVar(self.master)
        self.auto_correct.set(settings['auto_correct'])
        self.clear = BooleanVar(self.master)
        self.clear.set(settings['clear'])
        self.fill = BooleanVar(self.master)
        self.fill.set(settings['fill'])
        self.finalise = BooleanVar(self.master)
        self.finalise.set(settings['finalise'])
        self.range_min_r = IntVar(self.master)
        self.range_min_r.set(settings['range_min'].x)
        self.range_min_g = IntVar(self.master)
        self.range_min_g.set(settings['range_min'].y)
        self.range_min_b = IntVar(self.master)
        self.range_min_b.set(settings['range_min'].z)
        self.range_max_r = IntVar(self.master)
        self.range_max_r.set(settings['range_max'].x)
        self.range_max_g = IntVar(self.master)
        self.range_max_g.set(settings['range_max'].y)
        self.range_max_b = IntVar(self.master)
        self.range_max_b.set(settings['range_max'].z)
        self.range_scale = BooleanVar(self.master)
        self.range_scale.set(settings['range_scale'])
        self.alpha = IntVar(self.master)
        self.alpha.set(settings['alpha'])
        self.alpha_filename = settings['alpha_file']
        self.alpha_file = StringVar(self.master)
        self.update_file()
        self.save_settings = BooleanVar(self.master)
        self.save_settings.set(settings['save'])
        self.save_defaults = BooleanVar(self.master)
        self.save_defaults.set(False)

        self.doBake = False

        # ==========================================
        # Main window frame
        # ==========================================

        top_frame = gui.Frame(master, border=4)
        top_frame.pack()
        frame = gui.LabelFrame(top_frame, text=LABEL, labelanchor=NW)
        frame.pack()
        settings_frame = gui.Frame(frame)
        settings_frame.pack(fill=X)

        # ==========================================
        # Bake settings frame
        # ==========================================

        f = gui.LabelFrame(settings_frame, text="Bake")
        f.pack(side=LEFT, fill=Y)
        w = gui.Checkbutton(f, text="Keep Center", variable=self.keep_center)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f, text="Keep Scale", variable=self.keep_scale)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f, text="Keep Seams", variable=self.keep_seams)
        w.pack(anchor=W, expand=True)

        # ===================================================================
        # The Optimise Resolution option only appears with multi bake objects
        #====================================================================
        self.sculptie_counter = 0
        scene = Blender.Scene.GetCurrent()

        w = gui.Checkbutton(f,
                            text="Optimize Resolution",
                            variable=self.optimize_resolution)
        w.pack(anchor=W, expand=True)

        for ob in scene.objects.selected:
            if sculpty.check(ob):
                self.sculptie_counter += 1
        if self.sculptie_counter != 1:
            w.configure(state=NORMAL)
        else:
            w.configure(state=DISABLED)
            self.optimize_resolution.set(False)

        # ===================================================================
        # enable auto correction during bake
        #====================================================================
        w = gui.Checkbutton(f, text="Auto correct", variable=self.auto_correct)
        w.pack(anchor=W, expand=True)

        # ==========================================
        # Image settings frame
        # ==========================================

        f = gui.LabelFrame(settings_frame, text="Image")
        f.pack(side=LEFT, fill=Y)
        w = gui.Checkbutton(f, text="Clear", variable=self.clear)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f, text="Fill", variable=self.fill)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f, text="Finalise", variable=self.finalise)
        w.pack(anchor=W, expand=True)

        # ==========================================
        # Range settings frame
        # ==========================================

        f = gui.LabelFrame(settings_frame, text="Range")
        f.pack(side=LEFT, fill=Y)
        fr = gui.Frame(f)
        fr.pack(fill=X)
        w = gui.Spinbox(fr,
                        textvariable=self.range_max_r,
                        from_=0,
                        to=255,
                        width=4)
        w.pack(side=RIGHT)
        w = gui.Spinbox(fr,
                        textvariable=self.range_min_r,
                        from_=0,
                        to=255,
                        width=4)
        w.pack(side=RIGHT)
        t = gui.Label(fr, text="Red", justify=RIGHT)
        t.pack(side=RIGHT)
        fr = gui.Frame(f)
        fr.pack(fill=X)
        w = gui.Spinbox(fr,
                        textvariable=self.range_max_g,
                        from_=0,
                        to=255,
                        width=4)
        w.pack(side=RIGHT)
        w = gui.Spinbox(fr,
                        textvariable=self.range_min_g,
                        from_=0,
                        to=255,
                        width=4)
        w.pack(side=RIGHT)
        t = gui.Label(fr, text="Green", justify=RIGHT)
        t.pack(side=RIGHT)
        fr = gui.Frame(f)
        fr.pack(fill=X)
        w = gui.Spinbox(fr,
                        textvariable=self.range_max_b,
                        from_=0,
                        to=255,
                        width=4)
        w.pack(side=RIGHT)
        w = gui.Spinbox(fr,
                        textvariable=self.range_min_b,
                        from_=0,
                        to=255,
                        width=4)
        w.pack(side=RIGHT)
        t = gui.Label(fr, text="Blue", justify=RIGHT)
        t.pack(side=RIGHT)
        w = gui.Checkbutton(f, text="Adjust Scale", variable=self.range_scale)
        w.pack()

        # ==========================================
        # Alpha settings frame
        # ==========================================

        f = gui.LabelFrame(frame, text="Alpha")
        f.pack(fill=X)
        fr = gui.Frame(f)
        fr.pack()
        gui.Radiobutton(fr, text="Preview", variable=self.alpha,
                        value=2).pack(side=LEFT, anchor=W)
        gui.Radiobutton(fr, text="Solid", variable=self.alpha,
                        value=0).pack(side=LEFT, anchor=W)
        gui.Radiobutton(fr, text="Transparent", variable=self.alpha,
                        value=1).pack(side=LEFT, anchor=W)
        gui.Radiobutton(fr,
                        textvariable=self.alpha_file,
                        variable=self.alpha,
                        command=self.set_alpha,
                        value=3).pack(side=LEFT, anchor=W)
        gui.Button(fr,
                   image=self.file_icon,
                   compound=LEFT,
                   command=self.set_file,
                   default=ACTIVE).pack(side=RIGHT)

        # ==========================================
        # Save settings frame
        # ==========================================

        save_frame = gui.Frame(frame)
        save_frame.pack(fill=Y)
        t = gui.Checkbutton(save_frame,
                            text="Save",
                            variable=self.save_settings)
        t.pack(side=LEFT)
        t = gui.Checkbutton(save_frame,
                            text="Defaults",
                            variable=self.save_defaults)
        t.pack(side=LEFT)

        # ==========================================
        # Bake button
        # ==========================================

        w = gui.Button(save_frame,
                       text="Bake",
                       image=self.cube_icon,
                       compound=LEFT,
                       command=self.bake,
                       default=ACTIVE)
        w.pack(side=LEFT, fill=BOTH, expand=True, anchor=SE, pady=5)
Exemplo n.º 6
0
def bake_sculptie():
		print "--------------------------------"
		startTime = Blender.sys.time()  #for timing purposes
		editmode  = Blender.Window.EditMode()
		if editmode: Blender.Window.EditMode(0)
		Blender.Window.WaitCursor(1)
		# prepare for bake, set centers and create bounding box
		bb = sculpty.BoundingBox()
		bb.rgb.min = sculpty.XYZ( GLOBALS['minR'].val, GLOBALS['minG'].val, GLOBALS['minB'].val )
		bb.rgb.max = sculpty.XYZ( GLOBALS['maxR'].val, GLOBALS['maxG'].val, GLOBALS['maxB'].val )
		bb.rgb.update()

		scene = Blender.Scene.GetCurrent()
		for ob in scene.objects.selected:
			if sculpty.check( ob ):
				ob.properties["ps_bake_final"]     = GLOBALS['doFinal'].val
				ob.properties["ps_bake_fill"]      = GLOBALS['doFill'].val
				ob.properties["ps_bake_scale"]     = GLOBALS['keepScale'].val
				ob.properties["ps_bake_center"]    = GLOBALS['keepCenter'].val
				ob.properties["ps_bake_clear"]     = GLOBALS['doClear'].val
				ob.properties["ps_bake_protect"]   = GLOBALS['doProtect'].val
				ob.properties["ps_bake_preview"]   = GLOBALS['protect_type_silhouette'].val == True
				ob.properties["ps_bake_min_r"]     = GLOBALS['minR'].val
				ob.properties["ps_bake_min_g"]     = GLOBALS['minG'].val
				ob.properties["ps_bake_min_b"]     = GLOBALS['minB'].val
				ob.properties["ps_bake_max_r"]     = GLOBALS['maxR'].val
				ob.properties["ps_bake_max_g"]     = GLOBALS['maxG'].val
				ob.properties["ps_bake_max_b"]     = GLOBALS['maxB'].val
				ob.properties["ps_bake_scale_rgb"] = GLOBALS['doScaleRGB'].val
				if not ob.properties["ps_bake_center"]:
					#center new
					sculpty.set_center( ob )
				bb.add( ob )
		if ob.properties["ps_bake_scale"]:
			bb = bb.normalised()
		if ob.properties["ps_bake_center"]:
			bb = bb.centered()
		# Good to go, do the bake
		success = False
		for ob in scene.objects.selected:
			if sculpty.active( ob ):
				if sculpty.bake_object( ob, bb, ob.properties["ps_bake_clear"] ):
					success = True
				for image in sculpty.map_images( ob.getData( False, True) ):
					n = Blender.sys.splitext( image.name )
					if n[0] in ["Untitled", "Sphere_map", "Torus_map", "Cylinder_map", "Plane_map", "Hemi_map", "Sphere", "Torus","Cylinder","Plane","Hemi" ]:
						image.name = ob.name
					if ob.properties["ps_bake_scale_rgb"]:
						image.properties['ps_scale_x'] /= bb.rgb.scale.x
						image.properties['ps_scale_y'] /= bb.rgb.scale.y
						image.properties['ps_scale_z'] /= bb.rgb.scale.z
					if ob.properties["ps_bake_fill"]:
						sculpty.fill_holes( image )
					if ob.properties["ps_bake_final"]:
						sculpty.finalise( image )
						if ob.properties["ps_bake_protect"]:
							if ob.properties["ps_bake_preview"]:
								sculpty.bake_preview( image )
							else:
								sculpty.clear_alpha( image )

		print "--------------------------------"
		print 'finished baking: in %.4f sec.' % ((Blender.sys.time()- startTime))
		Blender.Redraw()
		if editmode: Blender.Window.EditMode(1)
		Blender.Window.WaitCursor(0)
		if not success:
			Blender.Draw.PupBlock( "Sculptie Bake Error", ["No objects selected"] )
Exemplo n.º 7
0
    def __init__(self, master):
        self.master = master
        self.cube_icon = gui.BitmapImage(data="""#define cube_width 16
#define cube_height 16
static unsigned char cube_bits[] = {
   0x00, 0x00, 0x80, 0x03, 0x70, 0x1c, 0x8c, 0x62, 0x94, 0x53, 0x64, 0x4c,
   0xa4, 0x4b, 0x2c, 0x69, 0x34, 0x59, 0x64, 0x4d, 0xa4, 0x4b, 0x2c, 0x69,
   0x30, 0x19, 0x40, 0x05, 0x80, 0x03, 0x00, 0x00 };
""")
        self.file_icon = gui.BitmapImage(data="""#define file_open_width 16
#define file_open_height 16
static unsigned char file_open_bits[] = {
   0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0xfe, 0x01, 0x0c, 0x02, 0x08, 0x04,
   0x00, 0x04, 0xf0, 0x00, 0x08, 0x7f, 0xf8, 0x40, 0x08, 0x40, 0x08, 0x40,
   0x08, 0x40, 0x08, 0x40, 0xf8, 0x7f, 0x00, 0x00 };
""")

        # ==========================================
        # Settings
        # ==========================================

        self.keep_center = BooleanVar(self.master)
        self.keep_center.set(settings['keep_center'])
        self.keep_scale = BooleanVar(self.master)
        self.keep_scale.set(settings['keep_scale'])
        self.keep_seams = BooleanVar(self.master)
        self.keep_seams.set(settings['keep_seams'])
        self.optimize_resolution = BooleanVar(self.master)
        self.optimize_resolution.set(settings['optimize_resolution'])
        self.auto_correct = BooleanVar(self.master)
        self.auto_correct.set(settings['auto_correct'])
        self.clear = BooleanVar(self.master)
        self.clear.set(settings['clear'])
        self.fill = BooleanVar(self.master)
        self.fill.set(settings['fill'])
        self.finalise = BooleanVar(self.master)
        self.finalise.set(settings['finalise'])
        self.range_min_r = IntVar(self.master)
        self.range_min_r.set(settings['range_min'].x)
        self.range_min_g = IntVar(self.master)
        self.range_min_g.set(settings['range_min'].y)
        self.range_min_b = IntVar(self.master)
        self.range_min_b.set(settings['range_min'].z)
        self.range_max_r = IntVar(self.master)
        self.range_max_r.set(settings['range_max'].x)
        self.range_max_g = IntVar(self.master)
        self.range_max_g.set(settings['range_max'].y)
        self.range_max_b = IntVar(self.master)
        self.range_max_b.set(settings['range_max'].z)
        self.range_scale = BooleanVar(self.master)
        self.range_scale.set(settings['range_scale'])
        self.alpha = IntVar(self.master)
        self.alpha.set(settings['alpha'])
        self.alpha_filename = settings['alpha_file']
        self.alpha_file = StringVar(self.master)
        self.update_file()
        self.save_settings = BooleanVar(self.master)
        self.save_settings.set(settings['save'])
        self.save_defaults = BooleanVar(self.master)
        self.save_defaults.set(False)

        self.doBake = False
        
        # ==========================================
        # Main window frame
        # ==========================================

        top_frame = gui.Frame(master, border=4)
        top_frame.pack()
        frame = gui.LabelFrame(top_frame,
                text=LABEL,
                labelanchor=NW)
        frame.pack()
        settings_frame = gui.Frame(frame)
        settings_frame.pack(fill=X)

        # ==========================================
        # Bake settings frame
        # ==========================================

        f = gui.LabelFrame(settings_frame,
                text="Bake")
        f.pack(side=LEFT, fill=Y)
        w = gui.Checkbutton(f,
                text="Keep Center",
                variable=self.keep_center)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f,
                text="Keep Scale",
                variable=self.keep_scale)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f,
                text="Keep Seams",
                variable=self.keep_seams)
        w.pack(anchor=W, expand=True)

        # ===================================================================
        # The Optimise Resolution option only appears with multi bake objects
        #====================================================================
        self.sculptie_counter = 0
        scene = Blender.Scene.GetCurrent()

        w = gui.Checkbutton(f,
                text="Optimize Resolution",
                variable=self.optimize_resolution)
        w.pack(anchor=W, expand=True)

        for ob in scene.objects.selected:
            if sculpty.check(ob):
                self.sculptie_counter += 1
        if self.sculptie_counter != 1:
            w.configure(state=NORMAL)
        else:
            w.configure(state=DISABLED)
            self.optimize_resolution.set(False)
            

        # ===================================================================
        # enable auto correction during bake
        #====================================================================
        w = gui.Checkbutton(f,
                text="Auto correct",
                variable=self.auto_correct)
        w.pack(anchor=W, expand=True)            

        # ==========================================
        # Image settings frame
        # ==========================================

        f = gui.LabelFrame(settings_frame,
                text="Image")
        f.pack(side=LEFT, fill=Y)
        w = gui.Checkbutton(f,
                text="Clear",
                variable=self.clear)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f,
                text="Fill",
                variable=self.fill)
        w.pack(anchor=W, expand=True)
        w = gui.Checkbutton(f,
                text="Finalise",
                variable=self.finalise)
        w.pack(anchor=W, expand=True)

        # ==========================================
        # Range settings frame
        # ==========================================

        f = gui.LabelFrame(settings_frame,
                text="Range")
        f.pack(side=LEFT, fill=Y)
        fr = gui.Frame(f)
        fr.pack(fill=X)
        w = gui.Spinbox(fr,
                textvariable=self.range_max_r,
                from_=0,
                to=255,
                width=4)
        w.pack(side=RIGHT)
        w = gui.Spinbox(fr,
                textvariable=self.range_min_r,
                from_=0,
                to=255,
                width=4)
        w.pack(side=RIGHT)
        t = gui.Label(fr,
                text="Red",
                justify=RIGHT)
        t.pack(side=RIGHT)
        fr = gui.Frame(f)
        fr.pack(fill=X)
        w = gui.Spinbox(fr,
                textvariable=self.range_max_g,
                from_=0,
                to=255,
                width=4)
        w.pack(side=RIGHT)
        w = gui.Spinbox(fr,
                textvariable=self.range_min_g,
                from_=0,
                to=255,
                width=4)
        w.pack(side=RIGHT)
        t = gui.Label(fr,
                text="Green",
                justify=RIGHT)
        t.pack(side=RIGHT)
        fr = gui.Frame(f)
        fr.pack(fill=X)
        w = gui.Spinbox(fr,
                textvariable=self.range_max_b,
                from_=0,
                to=255,
                width=4)
        w.pack(side=RIGHT)
        w = gui.Spinbox(fr,
                textvariable=self.range_min_b,
                from_=0,
                to=255,
                width=4)
        w.pack(side=RIGHT)
        t = gui.Label(fr,
                text="Blue",
                justify=RIGHT)
        t.pack(side=RIGHT)
        w = gui.Checkbutton(f,
                text="Adjust Scale",
                variable=self.range_scale)
        w.pack()

        # ==========================================
        # Alpha settings frame
        # ==========================================

        f = gui.LabelFrame(frame,
                text="Alpha")
        f.pack(fill=X)
        fr = gui.Frame(f)
        fr.pack()
        gui.Radiobutton(fr,
                text="Preview",
                variable=self.alpha,
                value=2).pack(side=LEFT, anchor=W)
        gui.Radiobutton(fr,
                text="Solid",
                variable=self.alpha,
                value=0).pack(side=LEFT, anchor=W)
        gui.Radiobutton(fr,
                text="Transparent",
                variable=self.alpha,
                value=1).pack(side=LEFT, anchor=W)
        gui.Radiobutton(fr,
                textvariable=self.alpha_file,
                variable=self.alpha,
                command=self.set_alpha,
                value=3).pack(side=LEFT, anchor=W)
        gui.Button(fr,
                image=self.file_icon,
                compound=LEFT,
                command=self.set_file,
                default=ACTIVE).pack(side=RIGHT)

        # ==========================================
        # Save settings frame
        # ==========================================

        save_frame = gui.Frame(frame)
        save_frame.pack(fill=Y)
        t = gui.Checkbutton(save_frame,
                text="Save",
                variable=self.save_settings)
        t.pack(side=LEFT)
        t = gui.Checkbutton(save_frame,
                text="Defaults",
                variable=self.save_defaults)
        t.pack(side=LEFT)

        # ==========================================
        # Bake button
        # ==========================================

        w = gui.Button(save_frame,
                text="Bake",
                image=self.cube_icon,
                compound=LEFT,
                command=self.bake,
                default=ACTIVE)
        w.pack(side=LEFT, fill=BOTH, expand=True, anchor=SE, pady=5)
Exemplo n.º 8
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
Exemplo n.º 9
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