예제 #1
0
def mesh2Prim(ob, rootprim=None):
    mesh = ob.getData(False, True)
    images, textures = map_images(mesh, 'sculptie', 'UVTex')
    bb = BoundingBox(ob)
    r = ob.getMatrix().rotationPart().toQuat()
    rotation = (r[1], r[2], r[3], r[0])
    l = ob.getLocation('worldspace')
    location = XYZ(l[0], l[1], l[2])
    for i in range(len(images)):
        image = images[i]
        texture = textures[i]
        newprim = Prim(image.name)
        newprim.sculpt_map = image
        if texture:
            newtex = Texture(texture)
            newtex.offset, newtex.repeat, newtex.rotation =\
                    uv_params(mesh, image)
            newprim.textures.append(newtex)
        newprim.rotation = rotation
        newprim.size = XYZ(
            image.properties['primstar']['scale_x'] * bb.scale.x,
            image.properties['primstar']['scale_y'] * bb.scale.y,
            image.properties['primstar']['scale_z'] * bb.scale.z)

        #print "========================================================="
        linksetSize = (image.properties['primstar']['size_x'],
                       image.properties['primstar']['size_y'],
                       image.properties['primstar']['size_z'])
        objectScale = (image.properties['primstar']['scale_x'],
                       image.properties['primstar']['scale_y'],
                       image.properties['primstar']['scale_z'])
        #print "LSL: linkset size         = ", linksetSize
        #print "LSL: object scale         = ", objectScale
        #print "LSL: bbox size from image = ", linksetSize[0]/objectScale[0], linksetSize[1]/objectScale[1], linksetSize[2]/objectScale[2]
        #print "LSL: bbox size from object= ", bb.scale.x, bb.scale.y, bb.scale.z
        #print "LSL: Final size           = ", newprim.size

        newprim.location = location + XYZ(
            image.properties['primstar']['loc_x'],
            image.properties['primstar']['loc_y'],
            image.properties['primstar']['loc_z'])
        if rootprim is None:
            rootprim = newprim
        else:
            rootprim.children.append(newprim)
    return rootprim
예제 #2
0
def main():
    editmode = Blender.Window.EditMode()
    if editmode:
        Blender.Window.EditMode(0)
    scene = Blender.Scene.GetCurrent()
    Blender.Window.WaitCursor(1)
    for ob in scene.objects.selected:
        if sculpty.active(ob):
            mesh = ob.getData(False, True)
            maps = sculpty.map_images(mesh)
            if len(maps) == 1:
                mesh.sel = True
                sculpty.update_from_map(mesh, maps[0])
                mesh.update()
            else:
                Blender.Draw.PupBlock("Sculptie Reset Error", ["Can't reset joined sculpt mesh", ob.name])
    # Blender.Window.WaitCursor(0)
    Blender.Window.EditMode(editmode)
    Blender.Redraw()
예제 #3
0
def mesh2Prim(ob, rootprim=None):
    mesh = ob.getData(False, True)
    images, textures = map_images(mesh, 'sculptie', 'UVTex')
    bb = BoundingBox(ob)
    r = ob.getMatrix().rotationPart().toQuat()
    rotation = (r[1], r[2], r[3], r[0])
    l = ob.getLocation('worldspace')
    location = XYZ(l[0], l[1], l[2])
    for i in range(len(images)):
        image = images[i]
        texture = textures[i]
        newprim = Prim(image.name)
        newprim.sculpt_map = image
        if texture:
            newtex = Texture(texture)
            newtex.offset, newtex.repeat, newtex.rotation =\
                    uv_params(mesh, image)
            newprim.textures.append(newtex)
        newprim.rotation = rotation
        newprim.size = XYZ(
                image.properties['primstar']['scale_x'] * bb.scale.x,
                image.properties['primstar']['scale_y'] * bb.scale.y,
                image.properties['primstar']['scale_z'] * bb.scale.z)
         
        #print "========================================================="
        linksetSize = (image.properties['primstar']['size_x'], image.properties['primstar']['size_y'], image.properties['primstar']['size_z'])       
        objectScale = (image.properties['primstar']['scale_x'], image.properties['primstar']['scale_y'], image.properties['primstar']['scale_z'])
        #print "LSL: linkset size         = ", linksetSize
        #print "LSL: object scale         = ", objectScale
        #print "LSL: bbox size from image = ", linksetSize[0]/objectScale[0], linksetSize[1]/objectScale[1], linksetSize[2]/objectScale[2] 
        #print "LSL: bbox size from object= ", bb.scale.x, bb.scale.y, bb.scale.z
        #print "LSL: Final size           = ", newprim.size
        
        newprim.location = location + XYZ(
            image.properties['primstar']['loc_x'],
            image.properties['primstar']['loc_y'],
            image.properties['primstar']['loc_z'])
        if rootprim is None:
            rootprim = newprim
        else:
            rootprim.children.append(newprim)
    return rootprim
예제 #4
0
def main():
    editmode = Blender.Window.EditMode()
    if editmode:
        Blender.Window.EditMode(0)
    scene = Blender.Scene.GetCurrent()
    Blender.Window.WaitCursor(1)
    for ob in scene.objects.selected:
        if sculpty.active(ob):
            mesh = ob.getData(False, True)
            maps = sculpty.map_images(mesh)
            if len(maps) == 1:
                mesh.sel = True
                sculpty.update_from_map(mesh, maps[0])
                mesh.update()
            else:
                Blender.Draw.PupBlock(
                    "Sculptie Reset Error",
                    ["Can't reset joined sculpt mesh", ob.name])
    #Blender.Window.WaitCursor(0)
    Blender.Window.EditMode(editmode)
    Blender.Redraw()
예제 #5
0
def mesh2Prim( ob, rootprim = None ):
	mesh = ob.getData( False, True )
	images = sculpty.map_images( mesh )
	if images != []:
		newprim = prim( images[0].name )
		newprim.fromOb( ob )
		newprim.sculptimage = texture( images[0].name , images[0] )
		newprim.scale = ( newprim.scale[0] / images[0].properties['ps_scale_x'],
						newprim.scale[1] / images[0].properties['ps_scale_y'],
						newprim.scale[2] / images[0].properties['ps_scale_z'] )
		if rootprim == None:
			rootprim = newprim
		else:
			rootprim.children.append( newprim )
		for image in images[1:]:
			newprim = prim( image.name )
			newprim.fromOb( ob )
			newprim.sculptimage = texture( image.name , image )
			newprim.scale = ( newprim.scale[0] / images[0].properties['ps_scale_x'],
						newprim.scale[1] / images[0].properties['ps_scale_y'],
						newprim.scale[2] / images[0].properties['ps_scale_z'] )
			rootprim.children.append( newprim )
	return rootprim
예제 #6
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)))
예제 #7
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"] )